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

Add resources azurerm_virtual_network_gateway and azurerm_virtual_network_gateway_connection #133

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1f79d31
Add resources azurerm_virtual_network_gateway and azurerm_virtual_net…
dominik-lekse Jun 26, 2017
2087dd7
Adapt resources azurerm_virtual_network_gateway and azurerm_virtual_n…
dominik-lekse Jun 26, 2017
a236467
Applied review feedback to azurerm_virtual_network_gateway and azurer…
dominik-lekse Jun 26, 2017
ee0bbe1
Add support for latest skus in azurerm_virtual_network_gateway
dominik-lekse Jun 26, 2017
b89586f
Fixed validation of skus in azurerm_virtual_network_gateway
dominik-lekse Jun 26, 2017
2990404
Merge branch 'master' into feature/virtual-network-gateway
dominik-lekse Aug 5, 2017
c6ec4bc
Revised resources azurerm_virtual_network_gateway and azurerm_virtual…
dominik-lekse Aug 5, 2017
554046a
Fixed import tests TestAccAzureRMVirtualNetworkGateway_importBasic an…
dominik-lekse Aug 5, 2017
b4143ba
Merge branch 'master' into feature/virtual-network-gateway
dominik-lekse Sep 16, 2017
b06dd57
Fixed description of field authorization_key in documentation of reso…
dominik-lekse Sep 17, 2017
f07a31c
virtual_network_gateway_connection: Removed reading parameters which …
dominik-lekse Sep 17, 2017
0325c74
virtual_network_gateway: Removed comments on subnet deletion workaround
dominik-lekse Sep 17, 2017
1686272
Revised test for resources virtual_network_gateway and virtual_networ…
dominik-lekse Sep 17, 2017
ed51416
Merge branch 'master' into feature/virtual-network-gateway
dominik-lekse Sep 30, 2017
9739bc1
Merge branch 'master' into feature/virtual-network-gateway
dominik-lekse Oct 31, 2017
f95bf5d
azurer_virtual_network_gateway: Ignore case for subnet_id
dominik-lekse Oct 31, 2017
26b1d69
Merge branch 'master' into feature/virtual-network-gateway
dominik-lekse Jan 23, 2018
4baf7e5
Migrated resources virtual_network_gateway and virtual_network_gatewa…
dominik-lekse Jan 23, 2018
d724fd7
Migrated acceptance tests for resources virtual_network_gateway and v…
dominik-lekse Jan 24, 2018
8fcfc41
Merge branch 'master' into feature/virtual-network-gateway
dominik-lekse Jan 25, 2018
51614e0
Minor refactoring
tombuildsstuff Jan 25, 2018
d94db0f
Making the `vpn_client_configuration` a list
tombuildsstuff Jan 25, 2018
1b6ddaa
Crash protection for importing legacy resources
tombuildsstuff Jan 25, 2018
81a63b6
Refactoring to make `bgp_settings` a List
tombuildsstuff Jan 25, 2018
6b2f496
Fixing minor linting issues
tombuildsstuff Jan 25, 2018
19eb152
Working around a golint bug in the VNG acctests
tombuildsstuff Jan 25, 2018
f82fdd1
Adding validation to match the Azure Portal
tombuildsstuff Jan 25, 2018
66e4602
Adding a test covering updating the shared key
tombuildsstuff Jan 26, 2018
5046f19
Consistency in the documentation for VNG's/VNG Connections
tombuildsstuff Jan 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions azurerm/import_arm_virtual_network_gateway_connection_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package azurerm

import (
"fmt"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"testing"
Copy link
Contributor

Choose a reason for hiding this comment

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

minor could we sort the imports here?

)

func TestAccAzureRMVirtualNetworkGatewayConnection_importSiteToSite(t *testing.T) {
resourceName := "azurerm_virtual_network_gateway_connection.test"

ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMVirtualNetworkGatewayConnection_sitetosite, ri)
Copy link
Contributor

Choose a reason for hiding this comment

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

minor could we switch this over to a function returning a formatted string to match the newer resources?


resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualNetworkGatewayConnectionDestroy,
Steps: []resource.TestStep{
{
Config: config,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
32 changes: 32 additions & 0 deletions azurerm/import_arm_virtual_network_gateway_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package azurerm

import (
"fmt"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"testing"
Copy link
Contributor

Choose a reason for hiding this comment

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

minor could we sort the imports here?

)

func TestAccAzureRMVirtualNetworkGateway_importBasic(t *testing.T) {
resourceName := "azurerm_virtual_network_gateway.test"

ri := acctest.RandInt()
config := fmt.Sprintf(testAccAzureRMVirtualNetworkGateway_basic, ri)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMVirtualNetworkGatewayDestroy,
Steps: []resource.TestStep{
{
Config: config,
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
58 changes: 30 additions & 28 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,36 @@ func Provider() terraform.ResourceProvider {

"azurerm_managed_disk": resourceArmManagedDisk(),

"azurerm_key_vault": resourceArmKeyVault(),
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
"azurerm_network_interface": resourceArmNetworkInterface(),
"azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
"azurerm_network_security_rule": resourceArmNetworkSecurityRule(),
"azurerm_public_ip": resourceArmPublicIp(),
"azurerm_redis_cache": resourceArmRedisCache(),
"azurerm_route": resourceArmRoute(),
"azurerm_route_table": resourceArmRouteTable(),
"azurerm_servicebus_namespace": resourceArmServiceBusNamespace(),
"azurerm_servicebus_subscription": resourceArmServiceBusSubscription(),
"azurerm_servicebus_topic": resourceArmServiceBusTopic(),
"azurerm_sql_elasticpool": resourceArmSqlElasticPool(),
"azurerm_storage_account": resourceArmStorageAccount(),
"azurerm_storage_blob": resourceArmStorageBlob(),
"azurerm_storage_container": resourceArmStorageContainer(),
"azurerm_storage_share": resourceArmStorageShare(),
"azurerm_storage_queue": resourceArmStorageQueue(),
"azurerm_storage_table": resourceArmStorageTable(),
"azurerm_subnet": resourceArmSubnet(),
"azurerm_template_deployment": resourceArmTemplateDeployment(),
"azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(),
"azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(),
"azurerm_virtual_machine_extension": resourceArmVirtualMachineExtensions(),
"azurerm_virtual_machine": resourceArmVirtualMachine(),
"azurerm_virtual_machine_scale_set": resourceArmVirtualMachineScaleSet(),
"azurerm_virtual_network": resourceArmVirtualNetwork(),
"azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(),
"azurerm_key_vault": resourceArmKeyVault(),
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
"azurerm_network_interface": resourceArmNetworkInterface(),
"azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
"azurerm_network_security_rule": resourceArmNetworkSecurityRule(),
"azurerm_public_ip": resourceArmPublicIp(),
"azurerm_redis_cache": resourceArmRedisCache(),
"azurerm_route": resourceArmRoute(),
"azurerm_route_table": resourceArmRouteTable(),
"azurerm_servicebus_namespace": resourceArmServiceBusNamespace(),
"azurerm_servicebus_subscription": resourceArmServiceBusSubscription(),
"azurerm_servicebus_topic": resourceArmServiceBusTopic(),
"azurerm_sql_elasticpool": resourceArmSqlElasticPool(),
"azurerm_storage_account": resourceArmStorageAccount(),
"azurerm_storage_blob": resourceArmStorageBlob(),
"azurerm_storage_container": resourceArmStorageContainer(),
"azurerm_storage_share": resourceArmStorageShare(),
"azurerm_storage_queue": resourceArmStorageQueue(),
"azurerm_storage_table": resourceArmStorageTable(),
"azurerm_subnet": resourceArmSubnet(),
"azurerm_template_deployment": resourceArmTemplateDeployment(),
"azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(),
"azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(),
"azurerm_virtual_machine_extension": resourceArmVirtualMachineExtensions(),
"azurerm_virtual_machine": resourceArmVirtualMachine(),
"azurerm_virtual_machine_scale_set": resourceArmVirtualMachineScaleSet(),
"azurerm_virtual_network": resourceArmVirtualNetwork(),
"azurerm_virtual_network_gateway": resourceArmVirtualNetworkGateway(),
"azurerm_virtual_network_gateway_connection": resourceArmVirtualNetworkGatewayConnection(),
"azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(),

"azurerm_application_insights": resourceArmApplicationInsights(),

Expand Down
42 changes: 33 additions & 9 deletions azurerm/resource_arm_local_network_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"

"github.com/Azure/azure-sdk-for-go/arm/network"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
)

Expand Down Expand Up @@ -97,15 +98,10 @@ func resourceArmLocalNetworkGatewayCreate(d *schema.ResourceData, meta interface
func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}) error {
lnetClient := meta.(*ArmClient).localNetConnClient

id, err := parseAzureResourceID(d.Id())
resGroup, name, err := resourceGroupAndLocalNetworkGatewayFromId(d.Id())
if err != nil {
return err
}
name := id.Path["localNetworkGateways"]
if name == "" {
return fmt.Errorf("Cannot find 'localNetworkGateways' in '%s', make sure it is specified in the ID parameter", d.Id())
}
resGroup := id.ResourceGroup

resp, err := lnetClient.Get(resGroup, name)
if err != nil {
Expand Down Expand Up @@ -134,12 +130,10 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}
func resourceArmLocalNetworkGatewayDelete(d *schema.ResourceData, meta interface{}) error {
lnetClient := meta.(*ArmClient).localNetConnClient

id, err := parseAzureResourceID(d.Id())
resGroup, name, err := resourceGroupAndLocalNetworkGatewayFromId(d.Id())
if err != nil {
return err
}
name := id.Path["localNetworkGateways"]
resGroup := id.ResourceGroup

deleteResp, error := lnetClient.Delete(resGroup, name, make(chan struct{}))
resp := <-deleteResp
Expand All @@ -155,3 +149,33 @@ func resourceArmLocalNetworkGatewayDelete(d *schema.ResourceData, meta interface

return nil
}

func resourceGroupAndLocalNetworkGatewayFromId(localNetworkGatewayId string) (string, string, error) {
id, err := parseAzureResourceID(localNetworkGatewayId)
if err != nil {
return "", "", err
}
name := id.Path["localNetworkGateways"]
resGroup := id.ResourceGroup

return resGroup, name, nil
}

func retrieveLocalNetworkGatewayById(localNetworkGatewayId string, meta interface{}) (*network.LocalNetworkGateway, bool, error) {
lnetClient := meta.(*ArmClient).localNetConnClient

resGroup, name, err := resourceGroupAndLocalNetworkGatewayFromId(localNetworkGatewayId)
if err != nil {
return nil, false, errwrap.Wrapf("Error Getting LocalNetworkGateway Name and Group: {{err}}", err)
}

resp, err := lnetClient.Get(resGroup, name)
if err != nil {
if resp.StatusCode == http.StatusNotFound {
return nil, false, nil
}
return nil, false, fmt.Errorf("Error making Read request on Azure LocalNetworkGateway %s: %s", name, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

it'd be good to return the full error by making the second argument %+v

}

return &resp, true, nil
}
45 changes: 45 additions & 0 deletions azurerm/resource_arm_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"net/http"

"github.com/Azure/azure-sdk-for-go/arm/network"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"time"
)

var subnetResourceName = "azurerm_subnet"
Expand Down Expand Up @@ -236,5 +238,48 @@ func resourceArmSubnetDelete(d *schema.ResourceData, meta interface{}) error {
_, error := subnetClient.Delete(resGroup, vnetName, name, make(chan struct{}))
err = <-error

// After deleting a gateway subnet, we check if the subnet has been deleted and
// retry if necessary. This is necessary as a workaround for scenarios in which
// a gateway subnet is deleted immediately after its previously associated
// virtual network gateway has been deleted. Unfortunately, the Azure Management
// API does not provide information on the state, therefore we try for a
// limited period of time.
if err != nil && name == "GatewaySubnet" {
err = resourceArmSubnetRetryDeleteGatewaySubnet(subnetClient, name, vnetName, resGroup)
}

return err
}

func resourceArmSubnetRetryDeleteGatewaySubnet(subnetClient network.SubnetsClient, name string, vnetName string, resGroup string) error {
stateConf := &resource.StateChangeConf{
Pending: []string{"Deleting", "Failed"},
Target: []string{"NotFound"},
Refresh: func() (interface{}, string, error) {
resp, err := subnetClient.Get(resGroup, vnetName, name, "")

if err != nil {
if resp.StatusCode == http.StatusNotFound {
return resp, "NotFound", nil
}

return nil, "", fmt.Errorf("Error issuing read request when retrying to delete Gateway Subnet %s/%s (resource group %s): %s", vnetName, name, resGroup, err)
}

// Retry deletion of gateway subnet if provisioning state is failed
if *resp.SubnetPropertiesFormat.ProvisioningState == "Failed" {
log.Printf("[DEBUG] Retry deleting Gateway Subnet %s/%s after failed provisioning state.", vnetName, name)
subnetClient.Delete(resGroup, vnetName, name, make(chan struct{}))
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to check the result of this call? in addition - do we need to implement some kind of "max attempts" 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.

This workaround should not be relevant anymore.

}

return resp, *resp.SubnetPropertiesFormat.ProvisioningState, nil
},
PollInterval: 30 * time.Second,
Timeout: 15 * time.Minute,
}
if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Gateway Subnet %s/%s to be removed: %s", vnetName, name, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

can this last argument become %+v?

}

return nil
}
Loading