Skip to content
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

Merged
merged 5 commits into from
Mar 17, 2020

Conversation

neil-yechenwei
Copy link
Contributor

@neil-yechenwei neil-yechenwei commented Mar 2, 2020

This PR is to improve the code as the issue #5613 is saying.

@tombuildsstuff
Copy link
Contributor

hi @neil-yechenwei

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 (azurerm_virtual_hub_connection) rather than being nested within the azurerm_virtual_hub resource. There's a branch tracking this functionality pushed here however the API was broken the last time we took a look at this - would you be able to confirm if this has been fixed?

If so rather than nesting this within the azurerm_virtual_hub resource could we instead switch to using a Virtual Resource instead as in the other branch? This approach allows us to better represent the behaviour of the Networking API's.

Thanks!

@neil-yechenwei
Copy link
Contributor Author

hi @tombuildsstuff , seems I misunderstood your meaning before.
Previously I assume we should make "virtual hub connection" as separate resource like "resource_arm_virtual_network_gateway_connection.go" with independent "connection client" like "https://github.com/terraform-providers/terraform-provider-azurerm/blob/9aa32daf9a440fa94996d255e056f11edb8415d1/azurerm/internal/services/network/resource_arm_virtual_network_gateway_connection.go#L257". So I found the independent "HubVirtualNetworkConnectionClient" (https://github.com/Azure/azure-sdk-for-go/blob/090dc0ee4d8d2d60e2a9525774d967a4111a2b0c/services/network/mgmt/2019-11-01/network/hubvirtualnetworkconnections.go#L50) for virtual hub doesn't support create/update operation. According by your commit "6b49836", seems that I should still use "VirtualHubClient" to update "virtual hub connection" in independent virtual resource. Thanks for your suggestion. I will update this PR to make "virtual hub connection" as separate virtual resource following the commit 6b49836 .

@ghost ghost removed the waiting-response label Mar 4, 2020
@ghost ghost added size/XL and removed size/L labels Mar 5, 2020
@neil-yechenwei
Copy link
Contributor Author

@tombuildsstuff , I've updated this PR according by your commit 6b49836

@katbyte katbyte changed the title Add support for hub virtual network connection - virtual hub New Resource: azurerm_virtual_hub_connection Mar 5, 2020
Copy link
Collaborator

@katbyte katbyte left a 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": {
Copy link
Collaborator

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

Suggested change
"enable_internet_security": {
"internet_security_enabled": {

Copy link
Contributor Author

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.
Copy link
Collaborator

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?

Copy link
Contributor Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 97 to 98
resourceGroup := id.ResourceGroup
hubName := id.Name
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 89 to 90
resourceGroup := id.ResourceGroup
virtualHubName := id.Name
Copy link
Collaborator

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?

Copy link
Contributor Author

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)
Copy link
Collaborator

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?

Copy link
Contributor Author

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"]
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

@katbyte katbyte added this to the v2.1.0 milestone Mar 5, 2020
@neil-yechenwei neil-yechenwei requested a review from katbyte March 6, 2020 09:03
@neil-yechenwei
Copy link
Contributor Author

@katbyte , Thanks for your comments. I've updated code.

@ghost ghost removed the waiting-response label Mar 6, 2020
Copy link
Collaborator

@katbyte katbyte left a 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

return fmt.Errorf("Virtual Hub Connection not found: %s", resourceName)
}

virtualHubId := rs.Primary.Attributes["virtual_hub_id"]
Copy link
Collaborator

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"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

Comment on lines 149 to 157
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)
Copy link
Collaborator

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

Suggested change
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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 208 to 223
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)
Copy link
Collaborator

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

Suggested change
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)
}

Copy link
Contributor Author

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) {
Copy link
Collaborator

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

Suggested change
func findVirtualHubConnection(name string, connections []network.HubVirtualNetworkConnection) (conn *network.HubVirtualNetworkConnection, index int) {
func findVirtualHubConnection(name string, connections []network.HubVirtualNetworkConnection) *network.HubVirtualNetworkConnection {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines 294 to 296
conn = &connection
index = i
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
conn = &connection
index = i
return
return &connection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@neil-yechenwei neil-yechenwei requested a review from katbyte March 10, 2020 16:21
@neil-yechenwei
Copy link
Contributor Author

@katbyte , I've updated code. Thanks for your comments.

@ghost ghost removed the waiting-response label Mar 10, 2020
@tombuildsstuff tombuildsstuff removed this from the v2.1.0 milestone Mar 11, 2020
@tombuildsstuff tombuildsstuff added this to the v2.2.0 milestone Mar 11, 2020
Copy link
Collaborator

@katbyte katbyte left a 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 👍

@katbyte katbyte merged commit 27686d5 into hashicorp:master Mar 17, 2020
katbyte added a commit that referenced this pull request Mar 17, 2020
@ghost
Copy link

ghost commented Mar 19, 2020

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 ...

@ghost
Copy link

ghost commented Apr 16, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants