-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Resource: azurerm_virtual_hub_connection #5951
Conversation
Thanks for this PR. Due to the way the Networking API's work, the last time we looked at this it appeared that this functionality wanted splitting out into it's own virtual resource ( If so rather than nesting this within the Thanks! |
hi @tombuildsstuff , seems I misunderstood your meaning before. |
@tombuildsstuff , I've updated this PR according by your commit 6b49836 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the PR @neil-yechenwei,
i've given this a quick review and most of my comments are minor or around naming.
ForceNew: true, | ||
}, | ||
|
||
"enable_internet_security": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we change this to
"enable_internet_security": { | |
"internet_security_enabled": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
|
||
* `allow_remote_vnet_to_use_hub_vnet_gateways` - (Optional) Allow the Remote Virtual Network to transit use the Hub's Virtual Network Gateway's? Changing this forces a new resource to be created. | ||
|
||
* `enable_internet_security` - (Optional) Should Internet Security be enabled? Changing this forces a new resource to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
COuld we expand on wha internet security is a little here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
|
||
* `allow_hub_to_remote_vnet_transit` - (Optional) Allow the Virtual Hub to transit traffic via the Remote Virtual Network? Changing this forces a new resource to be created. | ||
|
||
* `allow_remote_vnet_to_use_hub_vnet_gateways` - (Optional) Allow the Remote Virtual Network to transit use the Hub's Virtual Network Gateway's? Changing this forces a new resource to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `allow_remote_vnet_to_use_hub_vnet_gateways` - (Optional) Allow the Remote Virtual Network to transit use the Hub's Virtual Network Gateway's? Changing this forces a new resource to be created. | |
* `allow_remote_vnet_to_use_hub_gateways` - (Optional) Is Remote Virtual Network traffic allowed to transit the Hub's Virtual Network Gateway's? Changing this forces a new resource to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
resourceGroup := id.ResourceGroup | ||
hubName := id.Name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to assign these to locals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
resourceGroup := id.ResourceGroup | ||
virtualHubName := id.Name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to assign these to locals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
allow_remote_vnet_to_use_hub_vnet_gateways = false | ||
enable_internet_security = true | ||
} | ||
`, template, data.RandomInteger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we define two virtual hubs for the complete test, and then have another update test where we go basic -> compelte -> basic to ensure we correctly handel multiple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
return fmt.Errorf("Virtual Hub Connection not found: %s", resourceName) | ||
} | ||
|
||
virtualHubId := rs.Primary.Attributes["virtual_hub_id"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to get the primary ID and parse it as a virtual_hub_connection id?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is getting virtual_hub_id not virtual hub connection id. so won't fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to get everything require from ParseVirtualHubConnectionID
as we do on read/delete
continue | ||
} | ||
|
||
virtualHubId := rs.Primary.Attributes["virtual_hub_id"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is getting virtual_hub_id not virtual hub connection id. so won't fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above
@katbyte , Thanks for your comments. I've updated code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the revisions @neil-yechenwei, i have left a number of formatting and style comments inline that should be adressed
azurerm/internal/services/network/resource_arm_virtual_hub_connection.go
Outdated
Show resolved
Hide resolved
azurerm/internal/services/network/resource_arm_virtual_hub_connection.go
Outdated
Show resolved
Hide resolved
azurerm/internal/services/network/resource_arm_virtual_hub_connection.go
Outdated
Show resolved
Hide resolved
azurerm/internal/services/network/resource_arm_virtual_hub_connection.go
Outdated
Show resolved
Hide resolved
return fmt.Errorf("Virtual Hub Connection not found: %s", resourceName) | ||
} | ||
|
||
virtualHubId := rs.Primary.Attributes["virtual_hub_id"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to get everything require from ParseVirtualHubConnectionID
as we do on read/delete
continue | ||
} | ||
|
||
virtualHubId := rs.Primary.Attributes["virtual_hub_id"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above
if virtualHub.VirtualHubProperties == nil { | ||
return fmt.Errorf("Error retrieving Virtual Hub %q (Resource Group %q): `properties` was nil", id.Name, resourceGroup) | ||
} | ||
if virtualHub.VirtualHubProperties.VirtualNetworkConnections == nil { | ||
return fmt.Errorf("Error retrieving Virtual Hub %q (Resource Group %q): `properties.VirtualNetworkConnections` was nil", id.Name, resourceGroup) | ||
} | ||
|
||
connections = *virtualHub.VirtualHubProperties.VirtualNetworkConnections | ||
newConnection, _ := findVirtualHubConnection(name, connections) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you moved the checks into the find function and took the vhub this would be much more clear
if virtualHub.VirtualHubProperties == nil { | |
return fmt.Errorf("Error retrieving Virtual Hub %q (Resource Group %q): `properties` was nil", id.Name, resourceGroup) | |
} | |
if virtualHub.VirtualHubProperties.VirtualNetworkConnections == nil { | |
return fmt.Errorf("Error retrieving Virtual Hub %q (Resource Group %q): `properties.VirtualNetworkConnections` was nil", id.Name, resourceGroup) | |
} | |
connections = *virtualHub.VirtualHubProperties.VirtualNetworkConnections | |
newConnection, _ := findVirtualHubConnection(name, connections) | |
newConnection, _ := findVirtualHubConnection(name, virtualHub) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
if connection.HubVirtualNetworkConnectionProperties == nil { | ||
return fmt.Errorf("Error retrieving Connection %q (Virtual Hub %q / Resource Group %q): `properties` was nil`", id.Name, virtualHubName, resourceGroup) | ||
} | ||
props := *connection.HubVirtualNetworkConnectionProperties | ||
|
||
d.Set("name", id.Name) | ||
d.Set("virtual_hub_id", virtualHub.ID) | ||
d.Set("hub_to_vitual_network_traffic_allowed", props.AllowHubToRemoteVnetTransit) | ||
d.Set("vitual_network_to_hub_gateways_traffic_allowed", props.AllowRemoteVnetToUseHubVnetGateways) | ||
d.Set("internet_security_enabled", props.EnableInternetSecurity) | ||
|
||
remoteVirtualNetworkId := "" | ||
if props.RemoteVirtualNetwork != nil && props.RemoteVirtualNetwork.ID != nil { | ||
remoteVirtualNetworkId = *props.RemoteVirtualNetwork.ID | ||
} | ||
d.Set("remote_virtual_network_id", remoteVirtualNetworkId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we be consistent with other resources
if connection.HubVirtualNetworkConnectionProperties == nil { | |
return fmt.Errorf("Error retrieving Connection %q (Virtual Hub %q / Resource Group %q): `properties` was nil`", id.Name, virtualHubName, resourceGroup) | |
} | |
props := *connection.HubVirtualNetworkConnectionProperties | |
d.Set("name", id.Name) | |
d.Set("virtual_hub_id", virtualHub.ID) | |
d.Set("hub_to_vitual_network_traffic_allowed", props.AllowHubToRemoteVnetTransit) | |
d.Set("vitual_network_to_hub_gateways_traffic_allowed", props.AllowRemoteVnetToUseHubVnetGateways) | |
d.Set("internet_security_enabled", props.EnableInternetSecurity) | |
remoteVirtualNetworkId := "" | |
if props.RemoteVirtualNetwork != nil && props.RemoteVirtualNetwork.ID != nil { | |
remoteVirtualNetworkId = *props.RemoteVirtualNetwork.ID | |
} | |
d.Set("remote_virtual_network_id", remoteVirtualNetworkId) | |
if connection.HubVirtualNetworkConnectionProperties == nil { | |
return fmt.Errorf("Error retrieving Connection %q (Virtual Hub %q / Resource Group %q): `properties` was nil`", id.Name, virtualHubName, resourceGroup) | |
} | |
d.Set("name", id.Name) | |
d.Set("virtual_hub_id", virtualHub.ID) | |
if props := connection.HubVirtualNetworkConnectionProperties; props != nil { | |
d.Set("hub_to_vitual_network_traffic_allowed", props.AllowHubToRemoteVnetTransit) | |
d.Set("vitual_network_to_hub_gateways_traffic_allowed", props.AllowRemoteVnetToUseHubVnetGateways) | |
d.Set("internet_security_enabled", props.EnableInternetSecurity) | |
remoteVirtualNetworkId := "" | |
if props.RemoteVirtualNetwork != nil && props.RemoteVirtualNetwork.ID != nil { | |
remoteVirtualNetworkId = *props.RemoteVirtualNetwork.ID | |
} | |
d.Set("remote_virtual_network_id", remoteVirtualNetworkId) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
return nil | ||
} | ||
|
||
func findVirtualHubConnection(name string, connections []network.HubVirtualNetworkConnection) (conn *network.HubVirtualNetworkConnection, index int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't notice the index used anywhere
func findVirtualHubConnection(name string, connections []network.HubVirtualNetworkConnection) (conn *network.HubVirtualNetworkConnection, index int) { | |
func findVirtualHubConnection(name string, connections []network.HubVirtualNetworkConnection) *network.HubVirtualNetworkConnection { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
conn = &connection | ||
index = i | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conn = &connection | |
index = i | |
return | |
return &connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@katbyte , I've updated code. Thanks for your comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @neil-yechenwei! LGTM now 👍
This has been released in version 2.2.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example: provider "azurerm" {
version = "~> 2.2.0"
}
# ... other configuration ... |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
This PR is to improve the code as the issue #5613 is saying.