From c6ec4bce910c32a1a54999845d7f28d185768bf9 Mon Sep 17 00:00:00 2001 From: Dominik Lekse Date: Sat, 5 Aug 2017 18:02:38 +0200 Subject: [PATCH] Revised resources azurerm_virtual_network_gateway and azurerm_virtual_network_gateway_connection based on latest review --- azurerm/resource_arm_local_network_gateway.go | 4 +- azurerm/resource_arm_subnet.go | 2 +- .../resource_arm_virtual_network_gateway.go | 134 +++++++++++------- ..._arm_virtual_network_gateway_connection.go | 34 ++--- ...virtual_network_gateway_connection_test.go | 20 +-- ...source_arm_virtual_network_gateway_test.go | 22 +-- azurerm/test_utils.go | 2 +- .../r/virtual_network_gateway.html.markdown | 34 ++--- ...l_network_gateway_connection.html.markdown | 44 +++--- 9 files changed, 171 insertions(+), 125 deletions(-) diff --git a/azurerm/resource_arm_local_network_gateway.go b/azurerm/resource_arm_local_network_gateway.go index 133fcdf2e75e..d10d1ba6929a 100644 --- a/azurerm/resource_arm_local_network_gateway.go +++ b/azurerm/resource_arm_local_network_gateway.go @@ -171,10 +171,10 @@ func retrieveLocalNetworkGatewayById(localNetworkGatewayId string, meta interfac resp, err := lnetClient.Get(resGroup, name) if err != nil { - if resp.StatusCode == http.StatusNotFound { + if responseWasNotFound(resp.Response) { return nil, false, nil } - return nil, false, fmt.Errorf("Error making Read request on Azure LocalNetworkGateway %s: %s", name, err) + return nil, false, fmt.Errorf("Error making Read request on Azure LocalNetworkGateway %s: %+v", name, err) } return &resp, true, nil diff --git a/azurerm/resource_arm_subnet.go b/azurerm/resource_arm_subnet.go index ecbd2f228f72..743e89d06040 100644 --- a/azurerm/resource_arm_subnet.go +++ b/azurerm/resource_arm_subnet.go @@ -262,7 +262,7 @@ func resourceArmSubnetRetryDeleteGatewaySubnet(subnetClient network.SubnetsClien 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) + return nil, "", fmt.Errorf("Error issuing read request when retrying to delete Gateway Subnet %s/%s (resource group %s): %+v", vnetName, name, resGroup, err) } // Retry deletion of gateway subnet if provisioning state is failed diff --git a/azurerm/resource_arm_virtual_network_gateway.go b/azurerm/resource_arm_virtual_network_gateway.go index 1c4889a50de3..c71d0471daa1 100644 --- a/azurerm/resource_arm_virtual_network_gateway.go +++ b/azurerm/resource_arm_virtual_network_gateway.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "log" - "net/http" "time" @@ -41,22 +40,25 @@ func resourceArmVirtualNetworkGateway() *schema.Resource { "location": locationSchema(), "type": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, ValidateFunc: validation.StringInSlice([]string{ string(network.VirtualNetworkGatewayTypeExpressRoute), string(network.VirtualNetworkGatewayTypeVpn), - }, false), + }, true), ForceNew: true, }, "vpn_type": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + Default: string(network.RouteBased), + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, ValidateFunc: validation.StringInSlice([]string{ string(network.RouteBased), string(network.PolicyBased), - }, false), + }, true), ForceNew: true, }, @@ -73,8 +75,9 @@ func resourceArmVirtualNetworkGateway() *schema.Resource { }, "sku": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, ValidateFunc: validation.StringInSlice([]string{ string(network.VirtualNetworkGatewaySkuTierBasic), string(network.VirtualNetworkGatewaySkuTierStandard), @@ -83,7 +86,7 @@ func resourceArmVirtualNetworkGateway() *schema.Resource { string(network.VirtualNetworkGatewaySkuNameVpnGw1), string(network.VirtualNetworkGatewaySkuNameVpnGw2), string(network.VirtualNetworkGatewaySkuNameVpnGw3), - }, false), + }, true), }, "ip_configuration": { @@ -110,8 +113,9 @@ func resourceArmVirtualNetworkGateway() *schema.Resource { Default: string(network.Dynamic), }, "subnet_id": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validateArmVirtualNetworkGatewaySubnetId, }, "public_ip_address_id": { Type: schema.TypeString, @@ -211,7 +215,7 @@ func resourceArmVirtualNetworkGatewayCreateUpdate(d *schema.ResourceData, meta i client := meta.(*ArmClient) vnetGatewayClient := client.vnetGatewayClient - log.Printf("[INFO] preparing arguments for Azure ARM Virtual Network Gateway creation.") + log.Printf("[INFO] preparing arguments for AzureRM Virtual Network Gateway creation.") name := d.Get("name").(string) location := d.Get("location").(string) @@ -241,10 +245,10 @@ func resourceArmVirtualNetworkGatewayCreateUpdate(d *schema.ResourceData, meta i return err } if read.ID == nil { - return fmt.Errorf("Cannot read VirtualNetworkGateway %s (resource group %s) ID", name, resGroup) + return fmt.Errorf("Cannot read AzureRM Virtual Network Gateway '%s' (resource group %s) ID", name, resGroup) } - log.Printf("[DEBUG] Waiting for VirtualNetworkGateway (%s) to become available", name) + log.Printf("[DEBUG] Waiting for AzureRM Virtual Network Gateway '%s' to become available", name) stateConf := &resource.StateChangeConf{ Pending: []string{"Accepted", "Updating"}, Target: []string{"Succeeded"}, @@ -252,7 +256,7 @@ func resourceArmVirtualNetworkGatewayCreateUpdate(d *schema.ResourceData, meta i Timeout: 60 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for VirtualNetworkGateway (%s) to become available: %s", name, err) + return fmt.Errorf("Error waiting for AzureRM Virtual Network Gateway '%s' to become available: %+v", name, err) } d.SetId(*read.ID) @@ -270,44 +274,47 @@ func resourceArmVirtualNetworkGatewayRead(d *schema.ResourceData, meta interface resp, err := client.Get(resGroup, name) if err != nil { - if resp.StatusCode == http.StatusNotFound { + if responseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error making Read request on VirtualNetwork Gateway %s: %s", name, err) + return fmt.Errorf("Error making Read request on AzureRM Virtual Network Gateway %s: %+v", name, err) } - gw := *resp.VirtualNetworkGatewayPropertiesFormat - d.Set("name", resp.Name) d.Set("resource_group_name", resGroup) d.Set("location", azureRMNormalizeLocation(*resp.Location)) - d.Set("type", string(gw.GatewayType)) - d.Set("enable_bgp", gw.EnableBgp) - d.Set("active_active", gw.ActiveActive) - if string(gw.VpnType) != "" { - d.Set("vpn_type", string(gw.VpnType)) - } + if resp.VirtualNetworkGatewayPropertiesFormat != nil { + gw := *resp.VirtualNetworkGatewayPropertiesFormat - if gw.GatewayDefaultSite != nil { - d.Set("default_local_network_gateway_id", gw.GatewayDefaultSite.ID) - } + d.Set("type", string(gw.GatewayType)) + d.Set("enable_bgp", gw.EnableBgp) + d.Set("active_active", gw.ActiveActive) - if gw.Sku != nil { - d.Set("sku", string(gw.Sku.Name)) - } + if string(gw.VpnType) != "" { + d.Set("vpn_type", string(gw.VpnType)) + } - d.Set("ip_configuration", flattenArmVirtualNetworkGatewayIPConfigurations(gw.IPConfigurations)) + if gw.GatewayDefaultSite != nil { + d.Set("default_local_network_gateway_id", gw.GatewayDefaultSite.ID) + } - if gw.VpnClientConfiguration != nil { - vpnConfigFlat := flattenArmVirtualNetworkGatewayVpnClientConfig(gw.VpnClientConfiguration) - d.Set("vpn_client_configuration", schema.NewSet(hashVirtualNetworkGatewayVpnClientConfig, vpnConfigFlat)) - } + if gw.Sku != nil { + d.Set("sku", string(gw.Sku.Name)) + } - if gw.BgpSettings != nil { - bgpSettingsFlat := flattenArmVirtualNetworkGatewayBgpSettings(gw.BgpSettings) - d.Set("bgp_settings", schema.NewSet(hashVirtualNetworkGatewayBgpSettings, bgpSettingsFlat)) + d.Set("ip_configuration", flattenArmVirtualNetworkGatewayIPConfigurations(gw.IPConfigurations)) + + if gw.VpnClientConfiguration != nil { + vpnConfigFlat := flattenArmVirtualNetworkGatewayVpnClientConfig(gw.VpnClientConfiguration) + d.Set("vpn_client_configuration", schema.NewSet(hashVirtualNetworkGatewayVpnClientConfig, vpnConfigFlat)) + } + + if gw.BgpSettings != nil { + bgpSettingsFlat := flattenArmVirtualNetworkGatewayBgpSettings(gw.BgpSettings) + d.Set("bgp_settings", schema.NewSet(hashVirtualNetworkGatewayBgpSettings, bgpSettingsFlat)) + } } flattenAndSetTags(d, resp.Tags) @@ -330,7 +337,7 @@ func resourceArmVirtualNetworkGatewayDelete(d *schema.ResourceData, meta interfa return err } - log.Printf("[DEBUG] Waiting for VirtualNetworkGateway (%s) to be removed", name) + log.Printf("[DEBUG] Waiting for AzureRM Virtual Network Gateway %s to be removed", name) stateConf := &resource.StateChangeConf{ Pending: []string{"Accepted", "Deleting"}, Target: []string{"NotFound"}, @@ -338,7 +345,7 @@ func resourceArmVirtualNetworkGatewayDelete(d *schema.ResourceData, meta interfa Timeout: 15 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for VirtualNetworkGateway (%s) to be removed: %s", name, err) + return fmt.Errorf("Error waiting for AzureRM Virtual Network Gateway %s to be removed: %+v", name, err) } // Gateways are not fully cleaned up when the API indicates the delete operation @@ -353,17 +360,18 @@ func resourceArmVirtualNetworkGatewayDelete(d *schema.ResourceData, meta interfa return nil } +// TODO check if this is necessary? func virtualNetworkGatewayStateRefreshFunc(client *ArmClient, resourceGroupName string, virtualNetworkGateway string, withNotFound bool) resource.StateRefreshFunc { return func() (interface{}, string, error) { - res, err := client.vnetGatewayClient.Get(resourceGroupName, virtualNetworkGateway) + resp, err := client.vnetGatewayClient.Get(resourceGroupName, virtualNetworkGateway) if err != nil { - if withNotFound && res.StatusCode == http.StatusNotFound { - return res, "NotFound", nil + if withNotFound && responseWasNotFound(resp.Response) { + return resp, "NotFound", nil } - return nil, "", fmt.Errorf("Error issuing read request in virtualNetworkGatewayStateRefreshFunc to Azure ARM for VirtualNetworkGateway '%s' (RG: '%s'): %s", virtualNetworkGateway, resourceGroupName, err) + return nil, "", fmt.Errorf("Error making Read request on AzureRM Virtual Network Gateway %s: %+v", virtualNetworkGateway, err) } - return res, *res.VirtualNetworkGatewayPropertiesFormat.ProvisioningState, nil + return resp, *resp.VirtualNetworkGatewayPropertiesFormat.ProvisioningState, nil } } @@ -660,10 +668,36 @@ func resourceGroupAndVirtualNetworkGatewayFromId(virtualNetworkGatewayId string) return resGroup, name, nil } +func validateArmVirtualNetworkGatewaySubnetId(i interface{}, k string) (s []string, es []error) { + value, ok := i.(string) + if !ok { + es = append(es, fmt.Errorf("expected type of %s to be string", k)) + return + } + + id, err := parseAzureResourceID(value) + if err != nil { + es = append(es, fmt.Errorf("expected %s to be an Azure resource id", k)) + return + } + + subnet, ok := id.Path["subnets"] + if !ok { + es = append(es, fmt.Errorf("expected %s to reference a subnet resource", k)) + return + } + + if subnet != "GatewaySubnet" { + es = append(es, fmt.Errorf("expected %s to reference a gateway subnet with name GatewaySubnet", k)) + } + + return +} + func validateArmVirtualNetworkGatewayPolicyBasedVpnSku() schema.SchemaValidateFunc { return validation.StringInSlice([]string{ string(network.VirtualNetworkGatewaySkuTierBasic), - }, false) + }, true) } func validateArmVirtualNetworkGatewayRouteBasedVpnSku() schema.SchemaValidateFunc { @@ -674,7 +708,7 @@ func validateArmVirtualNetworkGatewayRouteBasedVpnSku() schema.SchemaValidateFun string(network.VirtualNetworkGatewaySkuNameVpnGw1), string(network.VirtualNetworkGatewaySkuNameVpnGw2), string(network.VirtualNetworkGatewaySkuNameVpnGw3), - }, false) + }, true) } func validateArmVirtualNetworkGatewayExpressRouteSku() schema.SchemaValidateFunc { @@ -682,5 +716,5 @@ func validateArmVirtualNetworkGatewayExpressRouteSku() schema.SchemaValidateFunc string(network.VirtualNetworkGatewaySkuTierStandard), string(network.VirtualNetworkGatewaySkuTierHighPerformance), string(network.VirtualNetworkGatewaySkuTierUltraPerformance), - }, false) + }, true) } diff --git a/azurerm/resource_arm_virtual_network_gateway_connection.go b/azurerm/resource_arm_virtual_network_gateway_connection.go index d38cd9d7db82..fb22aa9e7fe4 100644 --- a/azurerm/resource_arm_virtual_network_gateway_connection.go +++ b/azurerm/resource_arm_virtual_network_gateway_connection.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" "log" - "net/http" "time" ) @@ -36,13 +35,14 @@ func resourceArmVirtualNetworkGatewayConnection() *schema.Resource { }, "type": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, ValidateFunc: validation.StringInSlice([]string{ string(network.ExpressRoute), string(network.IPsec), string(network.Vnet2Vnet), - }, false), + }, true), ForceNew: true, }, @@ -103,7 +103,7 @@ func resourceArmVirtualNetworkGatewayConnectionCreateUpdate(d *schema.ResourceDa client := meta.(*ArmClient) vnetGatewayConnectionsClient := client.vnetGatewayConnectionsClient - log.Printf("[INFO] preparing arguments for Azure ARM Virtual Network Connection creation.") + log.Printf("[INFO] preparing arguments for AzureRM Virtual Network Gateway Connection creation.") name := d.Get("name").(string) location := d.Get("location").(string) @@ -128,7 +128,7 @@ func resourceArmVirtualNetworkGatewayConnectionCreateUpdate(d *schema.ResourceDa return err } - log.Printf("[DEBUG] Waiting for VirtualNetworkGatewayConnection (%s) to become available", name) + log.Printf("[DEBUG] Waiting for AzureRM Virtual Network Gateway Connection %s to become available", name) stateConf := &resource.StateChangeConf{ Pending: []string{"Accepted", "Updating"}, Target: []string{"Succeeded"}, @@ -136,7 +136,7 @@ func resourceArmVirtualNetworkGatewayConnectionCreateUpdate(d *schema.ResourceDa Timeout: 15 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for VirtualNetworkGatewayConnection (%s) to become available: %s", name, err) + return fmt.Errorf("Error waiting for AzureRM Virtual Network Gateway Connection %s to become available: %+v", name, err) } read, err := vnetGatewayConnectionsClient.Get(resGroup, name) @@ -144,7 +144,7 @@ func resourceArmVirtualNetworkGatewayConnectionCreateUpdate(d *schema.ResourceDa return err } if read.ID == nil { - return fmt.Errorf("Cannot read VirtualNetwork Gateway Connection %s (resource group %s) ID", name, resGroup) + return fmt.Errorf("Cannot read AzureRM Virtual Network Gateway Connection %s (resource group %s) ID", name, resGroup) } d.SetId(*read.ID) @@ -163,11 +163,11 @@ func resourceArmVirtualNetworkGatewayConnectionRead(d *schema.ResourceData, meta resp, err := vnetGatewayConnectionsClient.Get(resGroup, name) if err != nil { - if resp.StatusCode == http.StatusNotFound { + if responseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error making Read request on VirtualNetworkGatewayConnection %s: %s", name, err) + return fmt.Errorf("Error making Read request on AzureRM Virtual Network Gateway Connection %s: %+v", name, err) } conn := *resp.VirtualNetworkGatewayConnectionPropertiesFormat @@ -227,7 +227,7 @@ func resourceArmVirtualNetworkGatewayConnectionDelete(d *schema.ResourceData, me return errwrap.Wrapf("Error Deleting VirtualNetworkGatewayConnection {{err}}", err) } - log.Printf("[DEBUG] Waiting for VirtualNetworkGatewayConnection (%s) to be removed", name) + log.Printf("[DEBUG] Waiting for AzureRM Virtual Network Gateway Connection %s to be removed", name) stateConf := &resource.StateChangeConf{ Pending: []string{"Accepted", "Deleting"}, Target: []string{"NotFound"}, @@ -235,7 +235,7 @@ func resourceArmVirtualNetworkGatewayConnectionDelete(d *schema.ResourceData, me Timeout: 15 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { - return fmt.Errorf("Error waiting for VirtualNetworkGatewayConnection (%s) to be removed: %s", name, err) + return fmt.Errorf("Error waiting for AzureRM Virtual Network Gateway Connection %s to be removed: %+v", name, err) } d.SetId("") @@ -244,15 +244,15 @@ func resourceArmVirtualNetworkGatewayConnectionDelete(d *schema.ResourceData, me func virtualNetworkGatewayConnectionStateRefreshFunc(client *ArmClient, resourceGroupName string, virtualNetworkGatewayConnection string, withNotFound bool) resource.StateRefreshFunc { return func() (interface{}, string, error) { - res, err := client.vnetGatewayConnectionsClient.Get(resourceGroupName, virtualNetworkGatewayConnection) + resp, err := client.vnetGatewayConnectionsClient.Get(resourceGroupName, virtualNetworkGatewayConnection) if err != nil { - if withNotFound && res.StatusCode == http.StatusNotFound { - return res, "NotFound", nil + if withNotFound && responseWasNotFound(resp.Response) { + return resp, "NotFound", nil } - return nil, "", fmt.Errorf("Error issuing read request in virtualNetworkGatewayConnectionStateRefreshFunc to Azure ARM for VirtualNetworkGatewayConnection '%s' (RG: '%s'): %s", virtualNetworkGatewayConnection, resourceGroupName, err) + return nil, "", fmt.Errorf("Error making Read request on AzureRM Virtual Network Gateway Connection %s: %+v", virtualNetworkGatewayConnection, err) } - return res, *res.VirtualNetworkGatewayConnectionPropertiesFormat.ProvisioningState, nil + return resp, *resp.VirtualNetworkGatewayConnectionPropertiesFormat.ProvisioningState, nil } } diff --git a/azurerm/resource_arm_virtual_network_gateway_connection_test.go b/azurerm/resource_arm_virtual_network_gateway_connection_test.go index 986cae9fafab..b639b558e834 100644 --- a/azurerm/resource_arm_virtual_network_gateway_connection_test.go +++ b/azurerm/resource_arm_virtual_network_gateway_connection_test.go @@ -11,7 +11,7 @@ import ( func TestAccAzureRMVirtualNetworkGatewayConnection_sitetosite(t *testing.T) { ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMVirtualNetworkGatewayConnection_sitetosite, ri) + config := testAccAzureRMVirtualNetworkGatewayConnection_sitetosite(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -30,7 +30,7 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_sitetosite(t *testing.T) { func TestAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(t *testing.T) { ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet, ri) + config := testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -50,7 +50,7 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(t *testing.T) { func testCheckAzureRMVirtualNetworkGatewayConnectionExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { - name, resourceGroup, err := getArmResourceNameAndGroupByTerraformName(s, name) + name, resourceGroup, err := getArmResourceNameAndGroup(s, name) if err != nil { return err } @@ -59,7 +59,7 @@ func testCheckAzureRMVirtualNetworkGatewayConnectionExists(name string) resource resp, err := conn.Get(resourceGroup, name) if err != nil { - return fmt.Errorf("Bad: Get on vnetGatewayConnectionsClient: %s", err) + return fmt.Errorf("Bad: Get on vnetGatewayConnectionsClient: %+v", err) } if resp.StatusCode == http.StatusNotFound { @@ -95,7 +95,8 @@ func testCheckAzureRMVirtualNetworkGatewayConnectionDestroy(s *terraform.State) return nil } -var testAccAzureRMVirtualNetworkGatewayConnection_sitetosite = ` +func testAccAzureRMVirtualNetworkGatewayConnection_sitetosite(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "test-%[1]d" location = "West US" @@ -159,9 +160,11 @@ resource "azurerm_virtual_network_gateway_connection" "test" { shared_key = "4-v3ry-53cr37-1p53c-5h4r3d-k3y" } -` +`, rInt) +} -var testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet = ` +func testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "us" { name = "us-%[1]d" location = "East US" @@ -271,4 +274,5 @@ resource "azurerm_virtual_network_gateway_connection" "europe_to_us" { shared_key = "4-v3ry-53cr37-1p53c-5h4r3d-k3y" } -` +`, rInt) +} diff --git a/azurerm/resource_arm_virtual_network_gateway_test.go b/azurerm/resource_arm_virtual_network_gateway_test.go index 718c0ad98f0c..9e63c2de5177 100644 --- a/azurerm/resource_arm_virtual_network_gateway_test.go +++ b/azurerm/resource_arm_virtual_network_gateway_test.go @@ -12,7 +12,7 @@ import ( func TestAccAzureRMVirtualNetworkGateway_basic(t *testing.T) { ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMVirtualNetworkGateway_basic, ri) + config := testAccAzureRMVirtualNetworkGateway_basic(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -31,7 +31,7 @@ func TestAccAzureRMVirtualNetworkGateway_basic(t *testing.T) { func TestAccAzureRMVirtualNetworkGateway_vpnGw1(t *testing.T) { ri := acctest.RandInt() - config := fmt.Sprintf(testAccAzureRMVirtualNetworkGateway_vpnGw1, ri) + config := testAccAzureRMVirtualNetworkGateway_vpnGw1(ri) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -50,7 +50,7 @@ func TestAccAzureRMVirtualNetworkGateway_vpnGw1(t *testing.T) { func testCheckAzureRMVirtualNetworkGatewayExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { - name, resourceGroup, err := getArmResourceNameAndGroupByTerraformName(s, name) + name, resourceGroup, err := getArmResourceNameAndGroup(s, name) if err != nil { return err } @@ -59,7 +59,7 @@ func testCheckAzureRMVirtualNetworkGatewayExists(name string) resource.TestCheck resp, err := conn.Get(resourceGroup, name) if err != nil { - return fmt.Errorf("Bad: Get on vnetGatewayClient: %s", err) + return fmt.Errorf("Bad: Get on vnetGatewayClient: %+v", err) } if resp.StatusCode == http.StatusNotFound { @@ -86,7 +86,7 @@ func testCheckAzureRMVirtualNetworkGatewayDestroy(s *terraform.State) error { if err != nil { return nil } - + // TODO check if this is correct if resp.StatusCode != http.StatusNotFound { return fmt.Errorf("Virtual Network Gateway still exists:\n%#v", resp.VirtualNetworkGatewayPropertiesFormat) } @@ -95,7 +95,8 @@ func testCheckAzureRMVirtualNetworkGatewayDestroy(s *terraform.State) error { return nil } -var testAccAzureRMVirtualNetworkGateway_basic = ` +func testAccAzureRMVirtualNetworkGateway_basic(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "test-%[1]d" location = "West US" @@ -137,9 +138,11 @@ resource "azurerm_virtual_network_gateway" "test" { subnet_id = "${azurerm_subnet.test.id}" } } -` +`, rInt) +} -var testAccAzureRMVirtualNetworkGateway_vpnGw1 = ` +func testAccAzureRMVirtualNetworkGateway_vpnGw1(rInt int) string { + return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "test-%[1]d" location = "West US" @@ -181,4 +184,5 @@ resource "azurerm_virtual_network_gateway" "test" { subnet_id = "${azurerm_subnet.test.id}" } } -` +`, rInt) +} diff --git a/azurerm/test_utils.go b/azurerm/test_utils.go index c0975ee7d41f..ec3f8dcf350e 100644 --- a/azurerm/test_utils.go +++ b/azurerm/test_utils.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform/terraform" ) -func getArmResourceNameAndGroupByTerraformName(s *terraform.State, name string) (string, string, error) { +func getArmResourceNameAndGroup(s *terraform.State, name string) (string, string, error) { rs, ok := s.RootModule().Resources[name] if !ok { return "", "", fmt.Errorf("Not found: %s", name) diff --git a/website/docs/r/virtual_network_gateway.html.markdown b/website/docs/r/virtual_network_gateway.html.markdown index 7851f27b93b4..7a877ec49d3d 100644 --- a/website/docs/r/virtual_network_gateway.html.markdown +++ b/website/docs/r/virtual_network_gateway.html.markdown @@ -14,8 +14,8 @@ Creates a new virtual network gateway to establish secure, cross-premises connec ``` resource "azurerm_resource_group" "test" { - name = "test" - location = "West US" + name = "test" + location = "West US" } resource "azurerm_virtual_network" "test" { @@ -106,27 +106,27 @@ The following arguments are supported: create the virtual network gateway. * `location` - (Required) The location/region where the virtual network gateway is - created. Changing the location/region forces a new resource to be created. + located. Changing the location/region forces a new resource to be created. * `type` - (Required) The type of the virtual network gateway. Valid options are `Vpn` or `ExpressRoute`. Changing the type forces a new resource to be created. * `vpn_type` - (Optional) The routing type of the virtual network gateway. Valid - options are `RouteBased` or `PolicyBased`. By default, a route based virtual - network gateway will be created. + options are `RouteBased` or `PolicyBased`. Defaults to `RouteBased`. -* `enable_bgp` - (Optional) If true, BGP (Border Gateway Protocol) will be enabled - for this virtual network gateway. By default BGP is disabled. +* `enable_bgp` - (Optional) If `true`, BGP (Border Gateway Protocol) will be enabled + for this virtual network gateway. Defaults to `false`. -* `active_active` - (Optional) If true, an active-active virtual network gateway +* `active_active` - (Optional) If `true`, an active-active virtual network gateway will be created. An active-active gateway requires a `HighPerformance` or an - `UltraPerformance` sku. By default, an active-standby gateway will be created. + `UltraPerformance` sku. If `false`, an active-standby gateway will be created. + Defaults to `false`. * `default_local_network_gateway_id` - (Optional) The ID of the local network gateway through which outbound Internet traffic from the virtual network in which the gateway is created will be routed (*forced tunneling*). Refer to the [Azure documentation on forced tunneling](https://docs.microsoft.com/en-us/azure/vpn-gateway/vpn-gateway-forced-tunneling-rm). - By default, forced tunneling is not enabled. + If not provided, forced tunneling is disabled. * `sku` - (Required) Configuration of the size and capacity of the virtual network gateway. Valid options are `Basic`, `Standard`, `HighPerformance`, `UltraPerformance`, @@ -146,12 +146,12 @@ The following arguments are supported: The `ip_configuration` block supports: -* `name` - (Optional) A user-defined name of the IP configuration. If noted specified, - `vnetGatewayConfig` is used. +* `name` - (Optional) A user-defined name of the IP configuration. Defaults to + `vnetGatewayConfig`. * `private_ip_address_allocation` - (Optional) Defines how the private IP address of the gateways virtual interface is assigned. Valid options are `Static` or - `Dynamic`. By default dynamic allocation will be used. + `Dynamic`. Defaults to `Dynamic`. * `subnet_id` - (Required) The ID of the gateway subnet of a virtual network in which the virtual network gateway will be created. It is mandatory that @@ -184,11 +184,11 @@ The `bgp_settings` block supports: the virtual network gateway. * `peer_weight` - (Optional) The weight added to routes which have been learned - through BGP peering. Valid values can be between 0 and 100. + through BGP peering. Valid values can be between `0` and `100`. The `root_certificate` block supports: -* `name` - A user-defined name of the root certificate. +* `name` - (Required) A user-defined name of the root certificate. * `public_cert_data` - (Required) The public certificate of the root certificate authority. The certificate must be provided in Base-64 encoded X.509 format @@ -197,7 +197,7 @@ The `root_certificate` block supports: The `root_revoked_certificate` block supports: -* `name` - A user-defined name of the revoked certificate. +* `name` - (Required) A user-defined name of the revoked certificate. * `public_cert_data` - (Required) The SHA1 thumbprint of the certificate to be revoked. @@ -212,7 +212,7 @@ The following attributes are exported: * `resource_group_name` - The name of the resource group in which to create the virtual network gateway. -* `location` - The location/region where the virtual network gateway is created. +* `location` - The location/region where the virtual network gateway is located. ## Import diff --git a/website/docs/r/virtual_network_gateway_connection.html.markdown b/website/docs/r/virtual_network_gateway_connection.html.markdown index b37e7295b422..3b5cd95b85e9 100644 --- a/website/docs/r/virtual_network_gateway_connection.html.markdown +++ b/website/docs/r/virtual_network_gateway_connection.html.markdown @@ -19,8 +19,8 @@ and an on-premises VPN device and network. ``` resource "azurerm_resource_group" "test" { - name = "test" - location = "West US" + name = "test" + location = "West US" } resource "azurerm_virtual_network" "test" { @@ -211,7 +211,7 @@ The following arguments are supported: create the connection. * `location` - (Required) The location/region where the connection is - created. Changing this forces a new resource to be created. + located. Changing this forces a new resource to be created. * `type` - (Required) The type of connection. Valid options are `IPsec` (Site-to-Site), `ExpressRoute` (ExpressRoute), and `Vnet2Vnet` (VNet-to-VNet). @@ -219,32 +219,35 @@ The following arguments are supported: examples above). Changing the connection type will force a new connection to be created. -* `virtual_network_gateway_id` - (Required) The full Azure resource ID of the - virtual network gateway in which the connection will be created. Changing - the gateway forces a new resource to be created. +* `virtual_network_gateway_id` - (Required) The ID of the virtual network gateway + in which the connection will be created. Changing the gateway forces a new + resource to be created. * `authorization_key` - (Optional) The authorization key is required when creating an ExpressRoute connection to an Express Route Circuit which is contained in a different Azure subscription. This key is created by the owner of the Express Route Circuit to connect to. -* `express_route_circuit_id` - (Optional) The full Azure resource ID of the - Express Route Circuit when creating an ExpressRoute connection. The - Express Route Circuit can be in the same or in a different subscription. +* `express_route_circuit_id` - (Optional) The ID of the Express Route Circuit + when creating an ExpressRoute connection (i.e. when `type` is `ExpressRoute`). + The Express Route Circuit can be in the same or in a different subscription. -* `peer_virtual_network_gateway_id` - (Optional) The full Azure resource ID - of the peer virtual network gateway when creating a VNet-to-VNet connection. - The peer virtual network gateway can be in the same or in a different subscription. +* `peer_virtual_network_gateway_id` - (Optional) The ID of the peer virtual + network gateway when creating a VNet-to-VNet connection (i.e. when `type` + is `Vnet2Vnet`). The peer virtual network gateway can be in the same or + in a different subscription. -* `local_network_gateway_id` - (Optional) The full Azure resource ID of the - local network gateway when creating Site-to-Site connection. +* `local_network_gateway_id` - (Optional) The ID of the local network gateway + when creating Site-to-Site connection (i.e. when `type` is `IPsec`). -* `routing_weight` - (Optional) The routing weight. The default value is 10. +* `routing_weight` - (Optional) The routing weight. Defaults to `10`. -* `shared_key` - (Optional) The shared IPSec key. +* `shared_key` - (Optional) The shared IPSec key. A key must be provided if a + Site-to-Site or VNet-to-VNet connection is created whereas ExpressRoute + connections do not need a shared key. -* `enable_bgp` - (Optional) If true, BGP (Border Gateway Protocol) is enabled - for this connection. By default, BGP is disabled. +* `enable_bgp` - (Optional) If `true`, BGP (Border Gateway Protocol) is enabled + for this connection. Defaults to `false`. * `tags` - (Optional) A mapping of tags to assign to the resource. @@ -256,9 +259,10 @@ The following attributes are exported: * `name` - The name of the connection. -* `resource_group_name` - The name of the resource group in which to create the virtual network gateway connection. +* `resource_group_name` - The name of the resource group in which to create + the virtual network gateway connection. -* `location` - The location/region where the virtual network gateway connection is created. +* `location` - The location/region where the virtual network gateway connection is located. ## Import