diff --git a/azurerm/internal/services/network/ip_group_data_source.go b/azurerm/internal/services/network/ip_group_data_source.go index d148406c50ec..9efe84733fe2 100644 --- a/azurerm/internal/services/network/ip_group_data_source.go +++ b/azurerm/internal/services/network/ip_group_data_source.go @@ -12,9 +12,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func dataSourceArmIpGroup() *schema.Resource { +func dataSourceIpGroup() *schema.Resource { return &schema.Resource{ - Read: dataSourceArmIpGroupRead, + Read: dataSourceIpGroupRead, Timeouts: &schema.ResourceTimeout{ Read: schema.DefaultTimeout(5 * time.Minute), @@ -42,7 +42,7 @@ func dataSourceArmIpGroup() *schema.Resource { } } -func dataSourceArmIpGroupRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceIpGroupRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.IPGroupsClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/azurerm/internal/services/network/ip_group_resource.go b/azurerm/internal/services/network/ip_group_resource.go index 6e999c556f73..c026c96964b9 100644 --- a/azurerm/internal/services/network/ip_group_resource.go +++ b/azurerm/internal/services/network/ip_group_resource.go @@ -18,12 +18,12 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func resourceArmIpGroup() *schema.Resource { +func resourceIpGroup() *schema.Resource { return &schema.Resource{ - Create: resourceArmIpGroupCreateUpdate, - Read: resourceArmIpGroupRead, - Update: resourceArmIpGroupCreateUpdate, - Delete: resourceArmIpGroupDelete, + Create: resourceIpGroupCreateUpdate, + Read: resourceIpGroupRead, + Update: resourceIpGroupCreateUpdate, + Delete: resourceIpGroupDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { _, err := parse.IpGroupID(id) @@ -63,7 +63,7 @@ func resourceArmIpGroup() *schema.Resource { } } -func resourceArmIpGroupCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceIpGroupCreateUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.IPGroupsClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -116,10 +116,10 @@ func resourceArmIpGroupCreateUpdate(d *schema.ResourceData, meta interface{}) er d.SetId(*read.ID) - return resourceArmIpGroupRead(d, meta) + return resourceIpGroupRead(d, meta) } -func resourceArmIpGroupRead(d *schema.ResourceData, meta interface{}) error { +func resourceIpGroupRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.IPGroupsClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -156,7 +156,7 @@ func resourceArmIpGroupRead(d *schema.ResourceData, meta interface{}) error { return tags.FlattenAndSet(d, resp.Tags) } -func resourceArmIpGroupDelete(d *schema.ResourceData, meta interface{}) error { +func resourceIpGroupDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.IPGroupsClient ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/azurerm/internal/services/network/local_network_gateway_resource.go b/azurerm/internal/services/network/local_network_gateway_resource.go index ddca4b27968f..5a9e3bd0446d 100644 --- a/azurerm/internal/services/network/local_network_gateway_resource.go +++ b/azurerm/internal/services/network/local_network_gateway_resource.go @@ -15,12 +15,12 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func resourceArmLocalNetworkGateway() *schema.Resource { +func resourceLocalNetworkGateway() *schema.Resource { return &schema.Resource{ - Create: resourceArmLocalNetworkGatewayCreateUpdate, - Read: resourceArmLocalNetworkGatewayRead, - Update: resourceArmLocalNetworkGatewayCreateUpdate, - Delete: resourceArmLocalNetworkGatewayDelete, + Create: resourceLocalNetworkGatewayCreateUpdate, + Read: resourceLocalNetworkGatewayRead, + Update: resourceLocalNetworkGatewayCreateUpdate, + Delete: resourceLocalNetworkGatewayDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -93,7 +93,7 @@ func resourceArmLocalNetworkGateway() *schema.Resource { } } -func resourceArmLocalNetworkGatewayCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceLocalNetworkGatewayCreateUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.LocalNetworkGatewaysClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -168,10 +168,10 @@ func resourceArmLocalNetworkGatewayCreateUpdate(d *schema.ResourceData, meta int d.SetId(*read.ID) - return resourceArmLocalNetworkGatewayRead(d, meta) + return resourceLocalNetworkGatewayRead(d, meta) } -func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}) error { +func resourceLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.LocalNetworkGatewaysClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -213,7 +213,7 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{} return tags.FlattenAndSet(d, resp.Tags) } -func resourceArmLocalNetworkGatewayDelete(d *schema.ResourceData, meta interface{}) error { +func resourceLocalNetworkGatewayDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.LocalNetworkGatewaysClient ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/azurerm/internal/services/network/registration.go b/azurerm/internal/services/network/registration.go index 10e73fa9c01f..a6f91bd5eab3 100644 --- a/azurerm/internal/services/network/registration.go +++ b/azurerm/internal/services/network/registration.go @@ -23,7 +23,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ "azurerm_application_security_group": dataSourceApplicationSecurityGroup(), "azurerm_express_route_circuit": dataSourceExpressRouteCircuit(), - "azurerm_ip_group": dataSourceArmIpGroup(), + "azurerm_ip_group": dataSourceIpGroup(), "azurerm_nat_gateway": dataSourceArmNatGateway(), "azurerm_network_ddos_protection_plan": dataSourceNetworkDDoSProtectionPlan(), "azurerm_network_interface": dataSourceArmNetworkInterface(), @@ -35,8 +35,8 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { "azurerm_public_ip": dataSourceArmPublicIP(), "azurerm_public_ips": dataSourceArmPublicIPs(), "azurerm_public_ip_prefix": dataSourceArmPublicIpPrefix(), - "azurerm_route_filter": dataSourceArmRouteFilter(), - "azurerm_route_table": dataSourceArmRouteTable(), + "azurerm_route_filter": dataSourceRouteFilter(), + "azurerm_route_table": dataSourceRouteTable(), "azurerm_network_service_tags": dataSourceNetworkServiceTags(), "azurerm_subnet": dataSourceArmSubnet(), "azurerm_virtual_hub": dataSourceArmVirtualHub(), @@ -58,8 +58,8 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_express_route_circuit_peering": resourceExpressRouteCircuitPeering(), "azurerm_express_route_circuit": resourceExpressRouteCircuit(), "azurerm_express_route_gateway": resourceExpressRouteGateway(), - "azurerm_ip_group": resourceArmIpGroup(), - "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), + "azurerm_ip_group": resourceIpGroup(), + "azurerm_local_network_gateway": resourceLocalNetworkGateway(), "azurerm_nat_gateway": resourceArmNatGateway(), "azurerm_network_connection_monitor": resourceArmNetworkConnectionMonitor(), "azurerm_network_ddos_protection_plan": resourceArmNetworkDDoSProtectionPlan(), @@ -82,9 +82,9 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_network_security_rule": resourceArmNetworkSecurityRule(), "azurerm_network_watcher_flow_log": resourceArmNetworkWatcherFlowLog(), "azurerm_network_watcher": resourceArmNetworkWatcher(), - "azurerm_route_filter": resourceArmRouteFilter(), - "azurerm_route_table": resourceArmRouteTable(), - "azurerm_route": resourceArmRoute(), + "azurerm_route_filter": resourceRouteFilter(), + "azurerm_route_table": resourceRouteTable(), + "azurerm_route": resourceRoute(), "azurerm_virtual_hub_security_partner_provider": resourceArmVirtualHubSecurityPartnerProvider(), "azurerm_subnet_service_endpoint_storage_policy": resourceArmSubnetServiceEndpointStoragePolicy(), "azurerm_subnet_network_security_group_association": resourceArmSubnetNetworkSecurityGroupAssociation(), diff --git a/azurerm/internal/services/network/route_filter_data_source.go b/azurerm/internal/services/network/route_filter_data_source.go index 9a851c52bec2..795aebb9ce09 100644 --- a/azurerm/internal/services/network/route_filter_data_source.go +++ b/azurerm/internal/services/network/route_filter_data_source.go @@ -14,9 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func dataSourceArmRouteFilter() *schema.Resource { +func dataSourceRouteFilter() *schema.Resource { return &schema.Resource{ - Read: dataSourceArmRouteFilterRead, + Read: dataSourceRouteFilterRead, Timeouts: &schema.ResourceTimeout{ Read: schema.DefaultTimeout(5 * time.Minute), @@ -69,7 +69,7 @@ func dataSourceArmRouteFilter() *schema.Resource { } } -func dataSourceArmRouteFilterRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRouteFilterRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RouteFiltersClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/azurerm/internal/services/network/route_filter_resource.go b/azurerm/internal/services/network/route_filter_resource.go index 252313ff53db..5f3fe1c1ba18 100644 --- a/azurerm/internal/services/network/route_filter_resource.go +++ b/azurerm/internal/services/network/route_filter_resource.go @@ -19,12 +19,12 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func resourceArmRouteFilter() *schema.Resource { +func resourceRouteFilter() *schema.Resource { return &schema.Resource{ - Create: resourceArmRouteFilterCreateUpdate, - Read: resourceArmRouteFilterRead, - Update: resourceArmRouteFilterCreateUpdate, - Delete: resourceArmRouteFilterDelete, + Create: resourceRouteFilterCreateUpdate, + Read: resourceRouteFilterRead, + Update: resourceRouteFilterCreateUpdate, + Delete: resourceRouteFilterDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { _, err := parse.RouteFilterID(id) @@ -97,7 +97,7 @@ func resourceArmRouteFilter() *schema.Resource { } } -func resourceArmRouteFilterCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRouteFilterCreateUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RouteFiltersClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -151,10 +151,10 @@ func resourceArmRouteFilterCreateUpdate(d *schema.ResourceData, meta interface{} d.SetId(*read.ID) - return resourceArmRouteFilterRead(d, meta) + return resourceRouteFilterRead(d, meta) } -func resourceArmRouteFilterRead(d *schema.ResourceData, meta interface{}) error { +func resourceRouteFilterRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RouteFiltersClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -188,7 +188,7 @@ func resourceArmRouteFilterRead(d *schema.ResourceData, meta interface{}) error return tags.FlattenAndSet(d, resp.Tags) } -func resourceArmRouteFilterDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRouteFilterDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RouteFiltersClient ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/azurerm/internal/services/network/route_resource.go b/azurerm/internal/services/network/route_resource.go index f5abfb2e44d6..a8a7a5157b43 100644 --- a/azurerm/internal/services/network/route_resource.go +++ b/azurerm/internal/services/network/route_resource.go @@ -16,12 +16,12 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func resourceArmRoute() *schema.Resource { +func resourceRoute() *schema.Resource { return &schema.Resource{ - Create: resourceArmRouteCreateUpdate, - Read: resourceArmRouteRead, - Update: resourceArmRouteCreateUpdate, - Delete: resourceArmRouteDelete, + Create: resourceRouteCreateUpdate, + Read: resourceRouteRead, + Update: resourceRouteCreateUpdate, + Delete: resourceRouteDelete, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -79,7 +79,7 @@ func resourceArmRoute() *schema.Resource { } } -func resourceArmRouteCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRouteCreateUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RoutesClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -137,10 +137,10 @@ func resourceArmRouteCreateUpdate(d *schema.ResourceData, meta interface{}) erro } d.SetId(*read.ID) - return resourceArmRouteRead(d, meta) + return resourceRouteRead(d, meta) } -func resourceArmRouteRead(d *schema.ResourceData, meta interface{}) error { +func resourceRouteRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RoutesClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -175,7 +175,7 @@ func resourceArmRouteRead(d *schema.ResourceData, meta interface{}) error { return nil } -func resourceArmRouteDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRouteDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RoutesClient ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/azurerm/internal/services/network/route_table_data_source.go b/azurerm/internal/services/network/route_table_data_source.go index 87e347c1fb22..9d49be0508bd 100644 --- a/azurerm/internal/services/network/route_table_data_source.go +++ b/azurerm/internal/services/network/route_table_data_source.go @@ -14,9 +14,9 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func dataSourceArmRouteTable() *schema.Resource { +func dataSourceRouteTable() *schema.Resource { return &schema.Resource{ - Read: dataSourceArmRouteTableRead, + Read: dataSourceRouteTableRead, Timeouts: &schema.ResourceTimeout{ Read: schema.DefaultTimeout(5 * time.Minute), @@ -73,7 +73,7 @@ func dataSourceArmRouteTable() *schema.Resource { } } -func dataSourceArmRouteTableRead(d *schema.ResourceData, meta interface{}) error { +func dataSourceRouteTableRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RouteTablesClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/azurerm/internal/services/network/route_table_resource.go b/azurerm/internal/services/network/route_table_resource.go index 3187bffebab8..7016ede3185a 100644 --- a/azurerm/internal/services/network/route_table_resource.go +++ b/azurerm/internal/services/network/route_table_resource.go @@ -21,12 +21,12 @@ import ( var routeTableResourceName = "azurerm_route_table" -func resourceArmRouteTable() *schema.Resource { +func resourceRouteTable() *schema.Resource { return &schema.Resource{ - Create: resourceArmRouteTableCreateUpdate, - Read: resourceArmRouteTableRead, - Update: resourceArmRouteTableCreateUpdate, - Delete: resourceArmRouteTableDelete, + Create: resourceRouteTableCreateUpdate, + Read: resourceRouteTableRead, + Update: resourceRouteTableCreateUpdate, + Delete: resourceRouteTableDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { _, err := ParseRouteTableID(id) @@ -111,7 +111,7 @@ func resourceArmRouteTable() *schema.Resource { } } -func resourceArmRouteTableCreateUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceRouteTableCreateUpdate(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RouteTablesClient ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -166,10 +166,10 @@ func resourceArmRouteTableCreateUpdate(d *schema.ResourceData, meta interface{}) d.SetId(*read.ID) - return resourceArmRouteTableRead(d, meta) + return resourceRouteTableRead(d, meta) } -func resourceArmRouteTableRead(d *schema.ResourceData, meta interface{}) error { +func resourceRouteTableRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RouteTablesClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -208,7 +208,7 @@ func resourceArmRouteTableRead(d *schema.ResourceData, meta interface{}) error { return tags.FlattenAndSet(d, resp.Tags) } -func resourceArmRouteTableDelete(d *schema.ResourceData, meta interface{}) error { +func resourceRouteTableDelete(d *schema.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Network.RouteTablesClient ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/azurerm/internal/services/network/tests/ip_group_data_source_test.go b/azurerm/internal/services/network/tests/ip_group_data_source_test.go index a38a58f30f87..d31113b27364 100644 --- a/azurerm/internal/services/network/tests/ip_group_data_source_test.go +++ b/azurerm/internal/services/network/tests/ip_group_data_source_test.go @@ -6,49 +6,45 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check" ) -func TestAccDataSourceAzureRMIPGroup_basic(t *testing.T) { +type IPGroupDataSource struct { +} + +func TestAccDataSourceIPGroup_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_ip_group", "test") + r := IPGroupDataSource{} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIpGroupDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMIpGroup_basic(data), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(data.ResourceName, "location"), - resource.TestCheckResourceAttr(data.ResourceName, "cidrs.#", "0"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), - ), - }, + data.DataSourceTest(t, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("location").Exists(), + check.That(data.ResourceName).Key("cidrs.#").HasValue("0"), + check.That(data.ResourceName).Key("tags.%").HasValue("0"), + ), }, }) } -func TestAccDataSourceAzureRMIpGroup_complete(t *testing.T) { +func TestAccDataSourceIpGroup_complete(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_ip_group", "test") + r := IPGroupDataSource{} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIpGroupDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMIpGroup_complete(data), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(data.ResourceName, "location"), - resource.TestCheckResourceAttr(data.ResourceName, "cidrs.#", "3"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), - ), - }, + data.DataSourceTest(t, []resource.TestStep{ + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("location").Exists(), + check.That(data.ResourceName).Key("cidrs.#").HasValue("3"), + check.That(data.ResourceName).Key("tags.%").HasValue("2"), + ), }, }) } -func testAccDataSourceAzureRMIpGroup_basic(data acceptance.TestData) string { +func (IPGroupDataSource) basic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -56,10 +52,10 @@ data "azurerm_ip_group" "test" { name = azurerm_ip_group.test.name resource_group_name = azurerm_resource_group.test.name } -`, testAccAzureRMIpGroup_basic(data)) +`, IPGroupResource{}.basic(data)) } -func testAccDataSourceAzureRMIpGroup_complete(data acceptance.TestData) string { +func (IPGroupDataSource) complete(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -67,5 +63,5 @@ data "azurerm_ip_group" "test" { name = azurerm_ip_group.test.name resource_group_name = azurerm_resource_group.test.name } -`, testAccAzureRMIpGroup_complete(data)) +`, IPGroupResource{}.complete(data)) } diff --git a/azurerm/internal/services/network/tests/ip_group_resource_test.go b/azurerm/internal/services/network/tests/ip_group_resource_test.go index 1a7713f719ac..754b2c0dbbec 100644 --- a/azurerm/internal/services/network/tests/ip_group_resource_test.go +++ b/azurerm/internal/services/network/tests/ip_group_resource_test.go @@ -1,185 +1,134 @@ package tests import ( + "context" "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMIpGroup_basic(t *testing.T) { +type IPGroupResource struct { +} + +func TestAccIpGroup_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_ip_group", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIpGroupDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIpGroup_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIpGroupExists(data.ResourceName), - ), - }, - data.ImportStep(), + r := IPGroupResource{} + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMIpGroup_requiresImport(t *testing.T) { +func TestAccIpGroup_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_ip_group", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIpGroupDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIpGroup_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIpGroupExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMIpGroup_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_ip_group"), - }, + r := IPGroupResource{} + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + { + Config: r.requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_ip_group"), }, }) } -func TestAccAzureRMIpGroup_complete(t *testing.T) { +func TestAccIpGroup_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_ip_group", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIpGroupDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIpGroup_complete(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIpGroupExists(data.ResourceName), - ), - }, - data.ImportStep(), + r := IPGroupResource{} + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMIpGroup_update(t *testing.T) { +func TestAccIpGroup_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_ip_group", "test") - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMIpGroupDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMIpGroup_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIpGroupExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "cidrs.#", "0"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMIpGroup_complete(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIpGroupExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "cidrs.#", "3"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMIpGroup_completeUpdate(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIpGroupExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "cidrs.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMIpGroup_complete(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIpGroupExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "cidrs.#", "3"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMIpGroup_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIpGroupExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "cidrs.#", "0"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), - ), - }, - data.ImportStep(), + r := IPGroupResource{} + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("cidrs.#").HasValue("0"), + check.That(data.ResourceName).Key("tags.%").HasValue("0"), + ), + }, + data.ImportStep(), + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("cidrs.#").HasValue("3"), + check.That(data.ResourceName).Key("tags.%").HasValue("2"), + ), + }, + data.ImportStep(), + { + Config: r.completeUpdate(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("cidrs.#").HasValue("1"), + check.That(data.ResourceName).Key("tags.%").HasValue("2"), + ), }, + data.ImportStep(), + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("cidrs.#").HasValue("3"), + check.That(data.ResourceName).Key("tags.%").HasValue("2"), + ), + }, + data.ImportStep(), + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("cidrs.#").HasValue("0"), + check.That(data.ResourceName).Key("tags.%").HasValue("0"), + ), + }, + data.ImportStep(), }) } -func testCheckAzureRMIpGroupExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.IPGroupsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %q", resourceName) - } - - ipGroupName := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for IP Group: %q", ipGroupName) - } - - resp, err := client.Get(ctx, resourceGroup, ipGroupName, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: IP Group %q (resource group: %q) does not exist", ipGroupName, resourceGroup) - } - - return fmt.Errorf("Bad: Get on IPGroupsClient: %+v", err) - } - - return nil +func (t IPGroupResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) { + id, err := parse.IpGroupID(state.ID) + if err != nil { + return nil, err } -} - -func testCheckAzureRMIpGroupDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.IPGroupsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_ip_group" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return nil - } - return err - } - return fmt.Errorf("IP Group still exists:\n%#v", resp.IPGroupPropertiesFormat) + resp, err := clients.Network.IPGroupsClient.Get(ctx, id.ResourceGroup, id.Name, "") + if err != nil { + return nil, fmt.Errorf("reading IP Group (%s): %+v", id, err) } - return nil + return utils.Bool(resp.ID != nil), nil } -func testAccAzureRMIpGroup_basic(data acceptance.TestData) string { +func (IPGroupResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -198,8 +147,7 @@ resource "azurerm_ip_group" "test" { `, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMIpGroup_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMIpGroup_basic(data) +func (r IPGroupResource) requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -208,10 +156,10 @@ resource "azurerm_ip_group" "import" { location = azurerm_ip_group.test.location resource_group_name = azurerm_ip_group.test.resource_group_name } -`, template) +`, r.basic(data)) } -func testAccAzureRMIpGroup_complete(data acceptance.TestData) string { +func (IPGroupResource) complete(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -237,7 +185,7 @@ resource "azurerm_ip_group" "test" { `, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMIpGroup_completeUpdate(data acceptance.TestData) string { +func (IPGroupResource) completeUpdate(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} diff --git a/azurerm/internal/services/network/tests/local_network_gateway_resource_test.go b/azurerm/internal/services/network/tests/local_network_gateway_resource_test.go index acefbe73b66e..ae869e3f2aa9 100644 --- a/azurerm/internal/services/network/tests/local_network_gateway_resource_test.go +++ b/azurerm/internal/services/network/tests/local_network_gateway_resource_test.go @@ -1,6 +1,7 @@ package tests import ( + "context" "fmt" "testing" @@ -9,296 +10,240 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMLocalNetworkGateway_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") +type LocalNetworkGatewayResource struct { +} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLocalNetworkGatewayConfig_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(data.ResourceName, "address_space.0", "127.0.0.0/8"), - ), - }, - data.ImportStep(), +func TestAccLocalNetworkGateway_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") + r := LocalNetworkGatewayResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("gateway_address").HasValue("127.0.0.1"), + check.That(data.ResourceName).Key("address_space.0").HasValue("127.0.0.0/8"), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMLocalNetworkGateway_requiresImport(t *testing.T) { +func TestAccLocalNetworkGateway_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLocalNetworkGatewayConfig_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMLocalNetworkGatewayConfig_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_local_network_gateway"), - }, + r := LocalNetworkGatewayResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + { + Config: r.requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_local_network_gateway"), }, }) } -func TestAccAzureRMLocalNetworkGateway_disappears(t *testing.T) { +func TestAccLocalNetworkGateway_disappears(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLocalNetworkGatewayConfig_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(data.ResourceName, "address_space.0", "127.0.0.0/8"), - testCheckAzureRMLocalNetworkGatewayDisappears(data.ResourceName), - ), - ExpectNonEmptyPlan: true, - }, + r := LocalNetworkGatewayResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("gateway_address").HasValue("127.0.0.1"), + check.That(data.ResourceName).Key("address_space.0").HasValue("127.0.0.0/8"), + testCheckLocalNetworkGatewayDisappears(data.ResourceName), + ), + ExpectNonEmptyPlan: true, }, }) } -func TestAccAzureRMLocalNetworkGateway_tags(t *testing.T) { +func TestAccLocalNetworkGateway_tags(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLocalNetworkGatewayConfig_tags(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "acctest"), - ), - }, - data.ImportStep(), + r := LocalNetworkGatewayResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.tags(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("tags.%").HasValue("1"), + check.That(data.ResourceName).Key("tags.environment").HasValue("acctest"), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMLocalNetworkGateway_bgpSettings(t *testing.T) { +func TestAccLocalNetworkGateway_bgpSettings(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(data.ResourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.#", "1"), - ), - }, - data.ImportStep(), + r := LocalNetworkGatewayResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.bgpSettings(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("gateway_address").HasValue("127.0.0.1"), + check.That(data.ResourceName).Key("address_space.0").HasValue("127.0.0.0/8"), + check.That(data.ResourceName).Key("bgp_settings.#").HasValue("1"), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMLocalNetworkGateway_bgpSettingsDisable(t *testing.T) { +func TestAccLocalNetworkGateway_bgpSettingsDisable(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(data.ResourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.0.asn", "2468"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.0.bgp_peering_address", "10.104.1.1"), - ), - }, - { - Config: testAccAzureRMLocalNetworkGatewayConfig_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(data.ResourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.#", "0"), - ), - }, + r := LocalNetworkGatewayResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.bgpSettings(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("gateway_address").HasValue("127.0.0.1"), + check.That(data.ResourceName).Key("address_space.0").HasValue("127.0.0.0/8"), + check.That(data.ResourceName).Key("bgp_settings.#").HasValue("1"), + check.That(data.ResourceName).Key("bgp_settings.0.asn").HasValue("2468"), + check.That(data.ResourceName).Key("bgp_settings.0.bgp_peering_address").HasValue("10.104.1.1"), + ), + }, + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("gateway_address").HasValue("127.0.0.1"), + check.That(data.ResourceName).Key("address_space.0").HasValue("127.0.0.0/8"), + check.That(data.ResourceName).Key("bgp_settings.#").HasValue("0"), + ), }, }) } -func TestAccAzureRMLocalNetworkGateway_bgpSettingsEnable(t *testing.T) { +func TestAccLocalNetworkGateway_bgpSettingsEnable(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLocalNetworkGatewayConfig_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(data.ResourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.#", "0"), - ), - }, - { - Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(data.ResourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.0.asn", "2468"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.0.bgp_peering_address", "10.104.1.1"), - ), - }, + r := LocalNetworkGatewayResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("gateway_address").HasValue("127.0.0.1"), + check.That(data.ResourceName).Key("address_space.0").HasValue("127.0.0.0/8"), + check.That(data.ResourceName).Key("bgp_settings.#").HasValue("0"), + ), + }, + { + Config: r.bgpSettings(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("gateway_address").HasValue("127.0.0.1"), + check.That(data.ResourceName).Key("address_space.0").HasValue("127.0.0.0/8"), + check.That(data.ResourceName).Key("bgp_settings.#").HasValue("1"), + check.That(data.ResourceName).Key("bgp_settings.0.asn").HasValue("2468"), + check.That(data.ResourceName).Key("bgp_settings.0.bgp_peering_address").HasValue("10.104.1.1"), + ), }, }) } -func TestAccAzureRMLocalNetworkGateway_bgpSettingsComplete(t *testing.T) { +func TestAccLocalNetworkGateway_bgpSettingsComplete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettingsComplete(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(data.ResourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.0.asn", "2468"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.0.bgp_peering_address", "10.104.1.1"), - resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.0.peer_weight", "15"), - ), - }, - data.ImportStep(), + r := LocalNetworkGatewayResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.bgpSettingsComplete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("gateway_address").HasValue("127.0.0.1"), + check.That(data.ResourceName).Key("address_space.0").HasValue("127.0.0.0/8"), + check.That(data.ResourceName).Key("bgp_settings.#").HasValue("1"), + check.That(data.ResourceName).Key("bgp_settings.0.asn").HasValue("2468"), + check.That(data.ResourceName).Key("bgp_settings.0.bgp_peering_address").HasValue("10.104.1.1"), + check.That(data.ResourceName).Key("bgp_settings.0.peer_weight").HasValue("15"), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMLocalNetworkGateway_updateAddressSpace(t *testing.T) { +func TestAccLocalNetworkGateway_updateAddressSpace(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLocalNetworkGatewayConfig_multipleAddressSpace(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMLocalNetworkGatewayConfig_multipleAddressSpaceUpdated(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - ), - }, - data.ImportStep(), + r := LocalNetworkGatewayResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.multipleAddressSpace(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), }, + data.ImportStep(), + { + Config: r.multipleAddressSpaceUpdated(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), }) } -func TestAccAzureRMLocalNetworkGateway_fqdn(t *testing.T) { +func TestAccLocalNetworkGateway_fqdn(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLocalNetworkGatewayConfig_fqdn(data, "www.foo.com"), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - ), - }, - data.ImportStep(), - { - Config: testAccAzureRMLocalNetworkGatewayConfig_fqdn(data, "www.bar.com"), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), - ), - }, - data.ImportStep(), + r := LocalNetworkGatewayResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.fqdn(data, "www.foo.com"), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), }, + data.ImportStep(), + { + Config: r.fqdn(data, "www.bar.com"), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), }) } -// testCheckAzureRMLocalNetworkGatewayExists returns the resource.TestCheckFunc -// which checks whether or not the expected local network gateway exists both -// in the schema, and on Azure. -func testCheckAzureRMLocalNetworkGatewayExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - // first, check that it exists on Azure: - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.LocalNetworkGatewaysClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // then, check within the schema for the local network gateway: - res, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Local network gateway '%s' not found.", resourceName) - } - - // and finally, extract the name and the resource group: - id, err := azure.ParseAzureResourceID(res.Primary.ID) - if err != nil { - return err - } - localNetName := id.Path["localNetworkGateways"] - resGrp := id.ResourceGroup - - resp, err := client.Get(ctx, resGrp, localNetName) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Local network gateway %q (resource group %q) does not exist on Azure.", localNetName, resGrp) - } - - return fmt.Errorf("Error reading the state of local network gateway %q: %+v", localNetName, err) - } +func (t LocalNetworkGatewayResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) { + id, err := azure.ParseAzureResourceID(state.ID) + if err != nil { + return nil, err + } + name := id.Path["localNetworkGateways"] + resGroup := id.ResourceGroup - return nil + resp, err := clients.Network.LocalNetworkGatewaysClient.Get(ctx, resGroup, name) + if err != nil { + return nil, fmt.Errorf("reading Local Network Gateway (%s): %+v", id, err) } + + return utils.Bool(resp.ID != nil), nil } -func testCheckAzureRMLocalNetworkGatewayDisappears(resourceName string) resource.TestCheckFunc { +func testCheckLocalNetworkGatewayDisappears(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { // first, check that it exists on Azure: client := acceptance.AzureProvider.Meta().(*clients.Client).Network.LocalNetworkGatewaysClient @@ -334,38 +279,7 @@ func testCheckAzureRMLocalNetworkGatewayDisappears(resourceName string) resource } } -func testCheckAzureRMLocalNetworkGatewayDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.LocalNetworkGatewaysClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, res := range s.RootModule().Resources { - if res.Type != "azurerm_local_network_gateway" { - continue - } - - id, err := azure.ParseAzureResourceID(res.Primary.ID) - if err != nil { - return err - } - localNetName := id.Path["localNetworkGateways"] - resourceGroup := id.ResourceGroup - - resp, err := client.Get(ctx, resourceGroup, localNetName) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return nil - } - - return err - } - - return fmt.Errorf("Local network gateway still exists:\n%#v", resp.LocalNetworkGatewayPropertiesFormat) - } - - return nil -} - -func testAccAzureRMLocalNetworkGatewayConfig_basic(data acceptance.TestData) string { +func (LocalNetworkGatewayResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -386,8 +300,7 @@ resource "azurerm_local_network_gateway" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLocalNetworkGatewayConfig_requiresImport(data acceptance.TestData) string { - template := testAccAzureRMLocalNetworkGatewayConfig_basic(data) +func (r LocalNetworkGatewayResource) requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -398,10 +311,10 @@ resource "azurerm_local_network_gateway" "import" { gateway_address = "127.0.0.1" address_space = ["127.0.0.0/8"] } -`, template) +`, r.basic(data)) } -func testAccAzureRMLocalNetworkGatewayConfig_tags(data acceptance.TestData) string { +func (LocalNetworkGatewayResource) tags(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -426,7 +339,7 @@ resource "azurerm_local_network_gateway" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(data acceptance.TestData) string { +func (LocalNetworkGatewayResource) bgpSettings(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -452,7 +365,7 @@ resource "azurerm_local_network_gateway" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLocalNetworkGatewayConfig_bgpSettingsComplete(data acceptance.TestData) string { +func (LocalNetworkGatewayResource) bgpSettingsComplete(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -479,7 +392,7 @@ resource "azurerm_local_network_gateway" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLocalNetworkGatewayConfig_multipleAddressSpace(data acceptance.TestData) string { +func (LocalNetworkGatewayResource) multipleAddressSpace(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -500,7 +413,7 @@ resource "azurerm_local_network_gateway" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLocalNetworkGatewayConfig_multipleAddressSpaceUpdated(data acceptance.TestData) string { +func (LocalNetworkGatewayResource) multipleAddressSpaceUpdated(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -521,7 +434,7 @@ resource "azurerm_local_network_gateway" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLocalNetworkGatewayConfig_fqdn(data acceptance.TestData, fqdn string) string { +func (LocalNetworkGatewayResource) fqdn(data acceptance.TestData, fqdn string) string { return fmt.Sprintf(` provider "azurerm" { features {} diff --git a/azurerm/internal/services/network/tests/route_filter_data_source_test.go b/azurerm/internal/services/network/tests/route_filter_data_source_test.go index 10132e6e3333..79ba34f0fb18 100644 --- a/azurerm/internal/services/network/tests/route_filter_data_source_test.go +++ b/azurerm/internal/services/network/tests/route_filter_data_source_test.go @@ -6,51 +6,44 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check" ) -func TestAccDataSourceAzureRMRouteFilter_basic(t *testing.T) { +type RouteFilterDataSource struct { +} + +func TestAccDataSourceRouteFilter_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_route_filter", "test") + r := RouteFilterDataSource{} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteFilterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMRouteFilter_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteFilterExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), - ), - }, + data.DataSourceTest(t, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("route.#").HasValue("0"), + ), }, }) } -func TestAccDataSourceAzureRMRouteFilter_withRules(t *testing.T) { +func TestAccDataSourceRouteFilter_withRules(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_route_filter", "test") + r := RouteFilterDataSource{} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteFilterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMRouteFilter_withRules(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteFilterExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.access", "Allow"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.rule_type", "Community"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.communities.0", "12076:53005"), - ), - }, + data.DataSourceTest(t, []resource.TestStep{ + { + Config: r.withRules(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("rule.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.access").HasValue("Allow"), + check.That(data.ResourceName).Key("rule.0.rule_type").HasValue("Community"), + check.That(data.ResourceName).Key("rule.0.communities.0").HasValue("12076:53005"), + ), }, }) } -func testAccDataSourceAzureRMRouteFilter_basic(data acceptance.TestData) string { - r := testAccAzureRMRouteFilter_basic(data) +func (RouteFilterDataSource) basic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -58,11 +51,10 @@ data "azurerm_route_filter" "test" { name = azurerm_route_filter.test.name resource_group_name = azurerm_route_filter.test.resource_group_name } -`, r) +`, RouteFilterResource{}.basic(data)) } -func testAccDataSourceAzureRMRouteFilter_withRules(data acceptance.TestData) string { - r := testAccAzureRMRouteFilter_withRules(data) +func (RouteFilterDataSource) withRules(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -70,5 +62,5 @@ data "azurerm_route_filter" "test" { name = azurerm_route_filter.test.name resource_group_name = azurerm_route_filter.test.resource_group_name } -`, r) +`, RouteFilterResource{}.withRules(data)) } diff --git a/azurerm/internal/services/network/tests/route_filter_resource_test.go b/azurerm/internal/services/network/tests/route_filter_resource_test.go index 3204dee15024..b98087162d07 100644 --- a/azurerm/internal/services/network/tests/route_filter_resource_test.go +++ b/azurerm/internal/services/network/tests/route_filter_resource_test.go @@ -1,6 +1,7 @@ package tests import ( + "context" "fmt" "testing" @@ -8,183 +9,149 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMRouteFilter_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_route_filter", "test") +type RouteFilterResource struct { +} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteFilterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteFilter_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteFilterExists(data.ResourceName), - ), - }, - data.ImportStep(), +func TestAccRouteFilter_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_route_filter", "test") + r := RouteFilterResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMRouteFilter_requiresImport(t *testing.T) { +func TestAccRouteFilter_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_filter", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteFilterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteFilter_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteFilterExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMRouteFilter_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_route_filter"), - }, + r := RouteFilterResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + { + Config: r.requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_route_filter"), }, }) } -func TestAccAzureRMRouteFilter_complete(t *testing.T) { +func TestAccRouteFilter_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_filter", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteFilterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteFilter_complete(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteFilterExists("azurerm_route_filter.test"), - ), - }, - data.ImportStep(), + r := RouteFilterResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMRouteFilter_disappears(t *testing.T) { +func TestAccRouteFilter_disappears(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_filter", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteFilterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteFilter_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteFilterExists(data.ResourceName), - testCheckAzureRMRouteFilterDisappears(data.ResourceName), - ), - ExpectNonEmptyPlan: true, - }, + r := RouteFilterResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + testCheckRouteFilterDisappears(data.ResourceName), + ), + ExpectNonEmptyPlan: true, }, }) } -func TestAccAzureRMRouteFilter_withTags(t *testing.T) { +func TestAccRouteFilter_withTags(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_filter", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteFilterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteFilter_withTags(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteFilterExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), - ), - }, - { - Config: testAccAzureRMRouteFilter_withTagsUpdate(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteFilterExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), - ), - }, + r := RouteFilterResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.withTags(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("tags.%").HasValue("2"), + check.That(data.ResourceName).Key("tags.environment").HasValue("Production"), + check.That(data.ResourceName).Key("tags.cost_center").HasValue("MSFT"), + ), + }, + { + Config: r.withTagsUpdate(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("tags.%").HasValue("1"), + check.That(data.ResourceName).Key("tags.environment").HasValue("staging"), + ), }, }) } -func TestAccAzureRMRouteFilter_withRules(t *testing.T) { +func TestAccRouteFilter_withRules(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_filter", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteFilterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteFilter_withRules(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteFilterExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.access", "Allow"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.rule_type", "Community"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.communities.0", "12076:53005"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.communities.1", "12076:53006"), - ), - }, - { - Config: testAccAzureRMRouteFilter_withRulesUpdate(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteFilterExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.access", "Allow"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.rule_type", "Community"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.communities.0", "12076:52005"), - resource.TestCheckResourceAttr(data.ResourceName, "rule.0.communities.1", "12076:52006"), - ), - }, + r := RouteFilterResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.withRules(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("rule.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.access").HasValue("Allow"), + check.That(data.ResourceName).Key("rule.0.rule_type").HasValue("Community"), + check.That(data.ResourceName).Key("rule.0.communities.0").HasValue("12076:53005"), + check.That(data.ResourceName).Key("rule.0.communities.1").HasValue("12076:53006"), + ), + }, + { + Config: r.withRulesUpdate(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("rule.#").HasValue("1"), + check.That(data.ResourceName).Key("rule.0.access").HasValue("Allow"), + check.That(data.ResourceName).Key("rule.0.rule_type").HasValue("Community"), + check.That(data.ResourceName).Key("rule.0.communities.0").HasValue("12076:52005"), + check.That(data.ResourceName).Key("rule.0.communities.1").HasValue("12076:52006"), + ), }, }) } -func testCheckAzureRMRouteFilterExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %q", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for route filter: %q", name) - } - - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.RouteFiltersClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - resp, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Route Filter %q (resource group: %q) does not exist", name, resourceGroup) - } - - return fmt.Errorf("Bad: Get on routeFiltersClient: %+v", err) - } +func (t RouteFilterResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) { + id, err := parse.RouteFilterID(state.ID) + if err != nil { + return nil, err + } - return nil + resp, err := clients.Network.RouteFiltersClient.Get(ctx, id.ResourceGroup, id.Name, "") + if err != nil { + return nil, fmt.Errorf("reading Route Filter (%s): %+v", id, err) } + + return utils.Bool(resp.ID != nil), nil } -func testCheckAzureRMRouteFilterDisappears(resourceName string) resource.TestCheckFunc { +func testCheckRouteFilterDisappears(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -215,34 +182,7 @@ func testCheckAzureRMRouteFilterDisappears(resourceName string) resource.TestChe } } -func testCheckAzureRMRouteFilterDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.RouteFiltersClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_route_filter" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return nil - } - - return err - } - - return fmt.Errorf("Route Filter still exists:\n%#v", resp.RouteFilterPropertiesFormat) - } - - return nil -} - -func testAccAzureRMRouteFilter_basic(data acceptance.TestData) string { +func (RouteFilterResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -261,7 +201,7 @@ resource "azurerm_route_filter" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteFilter_requiresImport(data acceptance.TestData) string { +func (r RouteFilterResource) requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -270,10 +210,10 @@ resource "azurerm_route_filter" "import" { location = azurerm_route_filter.test.location resource_group_name = azurerm_route_filter.test.resource_group_name } -`, testAccAzureRMRouteFilter_basic(data)) +`, r.basic(data)) } -func testAccAzureRMRouteFilter_complete(data acceptance.TestData) string { +func (RouteFilterResource) complete(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -293,7 +233,7 @@ resource "azurerm_route_filter" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteFilter_withTags(data acceptance.TestData) string { +func (RouteFilterResource) withTags(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -317,7 +257,7 @@ resource "azurerm_route_filter" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteFilter_withTagsUpdate(data acceptance.TestData) string { +func (RouteFilterResource) withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -340,7 +280,7 @@ resource "azurerm_route_filter" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteFilter_withRules(data acceptance.TestData) string { +func (RouteFilterResource) withRules(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -366,7 +306,7 @@ resource "azurerm_route_filter" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRouteFilter_withRulesUpdate(data acceptance.TestData) string { +func (RouteFilterResource) withRulesUpdate(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} diff --git a/azurerm/internal/services/network/tests/route_resource_test.go b/azurerm/internal/services/network/tests/route_resource_test.go index 79705a2cbf10..9155b024011c 100644 --- a/azurerm/internal/services/network/tests/route_resource_test.go +++ b/azurerm/internal/services/network/tests/route_resource_test.go @@ -1,169 +1,142 @@ package tests import ( + "context" "fmt" - "net/http" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMRoute_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_route", "test") +type RouteResource struct { +} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRoute_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists("azurerm_route.test"), - ), - }, - data.ImportStep(), +func TestAccRoute_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_route", "test") + r := RouteResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMRoute_requiresImport(t *testing.T) { +func TestAccRoute_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRoute_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists(data.ResourceName), - ), - }, - { - Config: testAccAzureRMRoute_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_route"), - }, + r := RouteResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + { + Config: r.requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_route"), }, }) } -func TestAccAzureRMRoute_update(t *testing.T) { +func TestAccRoute_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRoute_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "next_hop_type", "VnetLocal"), - resource.TestCheckResourceAttr(data.ResourceName, "next_hop_in_ip_address", ""), - ), - }, - { - Config: testAccAzureRMRoute_basicAppliance(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "next_hop_type", "VirtualAppliance"), - resource.TestCheckResourceAttr(data.ResourceName, "next_hop_in_ip_address", "192.168.0.1"), - ), - }, - { - Config: testAccAzureRMRoute_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "next_hop_type", "VnetLocal"), - resource.TestCheckResourceAttr(data.ResourceName, "next_hop_in_ip_address", ""), - ), - }, + r := RouteResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("next_hop_type").HasValue("VnetLocal"), + check.That(data.ResourceName).Key("next_hop_in_ip_address").HasValue(""), + ), + }, + { + Config: r.basicAppliance(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("next_hop_type").HasValue("VirtualAppliance"), + check.That(data.ResourceName).Key("next_hop_in_ip_address").HasValue("192.168.0.1"), + ), + }, + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("next_hop_type").HasValue("VnetLocal"), + check.That(data.ResourceName).Key("next_hop_in_ip_address").HasValue(""), + ), }, }) } -func TestAccAzureRMRoute_disappears(t *testing.T) { +func TestAccRoute_disappears(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRoute_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists("azurerm_route.test"), - testCheckAzureRMRouteDisappears("azurerm_route.test"), - ), - ExpectNonEmptyPlan: true, - }, + r := RouteResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + testCheckRouteDisappears("azurerm_route.test"), + ), + ExpectNonEmptyPlan: true, }, }) } -func TestAccAzureRMRoute_multipleRoutes(t *testing.T) { +func TestAccRoute_multipleRoutes(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route", "test") + r := RouteResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRoute_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists("azurerm_route.test"), - ), - }, - - { - Config: testAccAzureRMRoute_multipleRoutes(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists("azurerm_route.test1"), - ), - }, + { + Config: r.multipleRoutes(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), }, }) } -func testCheckAzureRMRouteExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.RoutesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %q", resourceName) - } - - name := rs.Primary.Attributes["name"] - rtName := rs.Primary.Attributes["route_table_name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for route: %q", name) - } - - resp, err := client.Get(ctx, resourceGroup, rtName, name) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Route %q (resource group: %q) does not exist", name, resourceGroup) - } - return fmt.Errorf("Bad: Get on routesClient: %+v", err) - } +func (t RouteResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) { + id, err := azure.ParseAzureResourceID(state.ID) + if err != nil { + return nil, err + } + resGroup := id.ResourceGroup + rtName := id.Path["routeTables"] + routeName := id.Path["routes"] - return nil + resp, err := clients.Network.RoutesClient.Get(ctx, resGroup, rtName, routeName) + if err != nil { + return nil, fmt.Errorf("reading Route (%s): %+v", id, err) } + + return utils.Bool(resp.ID != nil), nil } -func testCheckAzureRMRouteDisappears(resourceName string) resource.TestCheckFunc { +func testCheckRouteDisappears(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).Network.RoutesClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -193,33 +166,7 @@ func testCheckAzureRMRouteDisappears(resourceName string) resource.TestCheckFunc } } -func testCheckAzureRMRouteDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.RoutesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_route" { - continue - } - - name := rs.Primary.Attributes["name"] - rtName := rs.Primary.Attributes["route_table_name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := client.Get(ctx, resourceGroup, rtName, name) - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Route still exists:\n%#v", resp.RoutePropertiesFormat) - } - } - - return nil -} - -func testAccAzureRMRoute_basic(data acceptance.TestData) string { +func (RouteResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -247,7 +194,7 @@ resource "azurerm_route" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRoute_requiresImport(data acceptance.TestData) string { +func (r RouteResource) requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s resource "azurerm_route" "import" { @@ -258,10 +205,10 @@ resource "azurerm_route" "import" { address_prefix = azurerm_route.test.address_prefix next_hop_type = azurerm_route.test.next_hop_type } -`, testAccAzureRMRoute_basic(data)) +`, r.basic(data)) } -func testAccAzureRMRoute_basicAppliance(data acceptance.TestData) string { +func (RouteResource) basicAppliance(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -290,7 +237,7 @@ resource "azurerm_route" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRoute_multipleRoutes(data acceptance.TestData) string { +func (RouteResource) multipleRoutes(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} diff --git a/azurerm/internal/services/network/tests/route_table_data_source_test.go b/azurerm/internal/services/network/tests/route_table_data_source_test.go index f728c0af0714..6fc461486921 100644 --- a/azurerm/internal/services/network/tests/route_table_data_source_test.go +++ b/azurerm/internal/services/network/tests/route_table_data_source_test.go @@ -6,76 +6,64 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check" ) -func TestAccDataSourceAzureRMRouteTable_basic(t *testing.T) { +type RouteTableDataSource struct { +} + +func TestAccDataSourceRouteTable_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_route_table", "test") + r := RouteTableDataSource{} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMRouteTable_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), - ), - }, + data.DataSourceTest(t, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("route.#").HasValue("0"), + ), }, }) } -func TestAccDataSourceAzureRMRouteTable_singleRoute(t *testing.T) { +func TestAccDataSourceRouteTable_singleRoute(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_route_table", "test") + r := RouteTableDataSource{} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMRouteTable_singleRoute(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.name", "route1"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.address_prefix", "10.1.0.0/16"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.next_hop_type", "VnetLocal"), - ), - }, + data.DataSourceTest(t, []resource.TestStep{ + { + Config: r.singleRoute(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("route.#").HasValue("1"), + check.That(data.ResourceName).Key("route.0.name").HasValue("route1"), + check.That(data.ResourceName).Key("route.0.address_prefix").HasValue("10.1.0.0/16"), + check.That(data.ResourceName).Key("route.0.next_hop_type").HasValue("VnetLocal"), + ), }, }) } -func TestAccDataSourceAzureRMRouteTable_multipleRoutes(t *testing.T) { +func TestAccDataSourceRouteTable_multipleRoutes(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_route_table", "test") + r := RouteTableDataSource{} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMRouteTable_multipleRoutes(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.name", "route1"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.address_prefix", "10.1.0.0/16"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.next_hop_type", "VnetLocal"), - resource.TestCheckResourceAttr(data.ResourceName, "route.1.name", "route2"), - resource.TestCheckResourceAttr(data.ResourceName, "route.1.address_prefix", "10.2.0.0/16"), - resource.TestCheckResourceAttr(data.ResourceName, "route.1.next_hop_type", "VnetLocal"), - ), - }, + data.DataSourceTest(t, []resource.TestStep{ + { + Config: r.multipleRoutes(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("route.#").HasValue("2"), + check.That(data.ResourceName).Key("route.0.name").HasValue("route1"), + check.That(data.ResourceName).Key("route.0.address_prefix").HasValue("10.1.0.0/16"), + check.That(data.ResourceName).Key("route.0.next_hop_type").HasValue("VnetLocal"), + check.That(data.ResourceName).Key("route.1.name").HasValue("route2"), + check.That(data.ResourceName).Key("route.1.address_prefix").HasValue("10.2.0.0/16"), + check.That(data.ResourceName).Key("route.1.next_hop_type").HasValue("VnetLocal"), + ), }, }) } -func testAccDataSourceAzureRMRouteTable_basic(data acceptance.TestData) string { - r := testAccAzureRMRouteTable_basic(data) +func (RouteTableDataSource) basic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -83,11 +71,10 @@ data "azurerm_route_table" "test" { name = azurerm_route_table.test.name resource_group_name = azurerm_route_table.test.resource_group_name } -`, r) +`, RouteTableResource{}.basic(data)) } -func testAccDataSourceAzureRMRouteTable_singleRoute(data acceptance.TestData) string { - r := testAccAzureRMRouteTable_singleRoute(data) +func (RouteTableDataSource) singleRoute(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -95,11 +82,10 @@ data "azurerm_route_table" "test" { name = azurerm_route_table.test.name resource_group_name = azurerm_route_table.test.resource_group_name } -`, r) +`, RouteTableResource{}.singleRoute(data)) } -func testAccDataSourceAzureRMRouteTable_multipleRoutes(data acceptance.TestData) string { - r := testAccAzureRMRouteTable_multipleRoutes(data) +func (RouteTableDataSource) multipleRoutes(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -107,5 +93,5 @@ data "azurerm_route_table" "test" { name = azurerm_route_table.test.name resource_group_name = azurerm_route_table.test.resource_group_name } -`, r) +`, RouteTableResource{}.multipleRoutes(data)) } diff --git a/azurerm/internal/services/network/tests/route_table_resource_test.go b/azurerm/internal/services/network/tests/route_table_resource_test.go index c8274a5181bc..d81e5a3295c8 100644 --- a/azurerm/internal/services/network/tests/route_table_resource_test.go +++ b/azurerm/internal/services/network/tests/route_table_resource_test.go @@ -1,6 +1,7 @@ package tests import ( + "context" "fmt" "testing" @@ -8,287 +9,241 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMRouteTable_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_route_table", "test") +type RouteTableResource struct { +} - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteTable_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), - ), - }, - data.ImportStep(), +func TestAccRouteTable_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") + r := RouteTableResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("disable_bgp_route_propagation").HasValue("false"), + check.That(data.ResourceName).Key("route.#").HasValue("0"), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMRouteTable_requiresImport(t *testing.T) { +func TestAccRouteTable_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_table", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteTable_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), - ), - }, - { - Config: testAccAzureRMRouteTable_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_route_table"), - }, + r := RouteTableResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("disable_bgp_route_propagation").HasValue("false"), + check.That(data.ResourceName).Key("route.#").HasValue("0"), + ), + }, + { + Config: r.requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_route_table"), }, }) } -func TestAccAzureRMRouteTable_complete(t *testing.T) { +func TestAccRouteTable_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_table", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteTable_complete(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists("azurerm_route_table.test"), - resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), - ), - }, - data.ImportStep(), + r := RouteTableResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("disable_bgp_route_propagation").HasValue("true"), + check.That(data.ResourceName).Key("route.#").HasValue("1"), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMRouteTable_update(t *testing.T) { +func TestAccRouteTable_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_table", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteTable_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists("azurerm_route_table.test"), - resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), - ), - }, - { - Config: testAccAzureRMRouteTable_basicAppliance(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists("azurerm_route_table.test"), - resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), - ), - }, - { - Config: testAccAzureRMRouteTable_complete(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists("azurerm_route_table.test"), - resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "true"), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), - ), - }, + r := RouteTableResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("disable_bgp_route_propagation").HasValue("false"), + check.That(data.ResourceName).Key("route.#").HasValue("0"), + ), + }, + { + Config: r.basicAppliance(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("disable_bgp_route_propagation").HasValue("false"), + check.That(data.ResourceName).Key("route.#").HasValue("1"), + ), + }, + { + Config: r.complete(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("disable_bgp_route_propagation").HasValue("true"), + check.That(data.ResourceName).Key("route.#").HasValue("1"), + ), }, }) } -func TestAccAzureRMRouteTable_singleRoute(t *testing.T) { +func TestAccRouteTable_singleRoute(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_table", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteTable_singleRoute(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - ), - }, - data.ImportStep(), + r := RouteTableResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.singleRoute(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), }, + data.ImportStep(), }) } -func TestAccAzureRMRouteTable_removeRoute(t *testing.T) { +func TestAccRouteTable_removeRoute(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_table", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - // This configuration includes a single explicit route block - Config: testAccAzureRMRouteTable_singleRoute(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), - ), - }, - { - // This configuration has no route blocks at all. - Config: testAccAzureRMRouteTable_noRouteBlocks(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - // The route from the first step is preserved because no - // blocks at all means "ignore existing blocks". - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), - ), - }, - { - // This configuration sets route to [] explicitly using the - // attribute syntax. - Config: testAccAzureRMRouteTable_singleRouteRemoved(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - // The route from the first step is now removed, leaving us - // with no routes at all. - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), - ), - }, + r := RouteTableResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + // This configuration includes a single explicit route block + Config: r.singleRoute(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("route.#").HasValue("1"), + ), + }, + { + // This configuration has no route blocks at all. + Config: r.noRouteBlocks(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + // The route from the first step is preserved because no + // blocks at all means "ignore existing blocks". + check.That(data.ResourceName).Key("route.#").HasValue("1"), + ), + }, + { + // This configuration sets route to [] explicitly using the + // attribute syntax. + Config: r.singleRouteRemoved(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + // The route from the first step is now removed, leaving us + // with no routes at all. + check.That(data.ResourceName).Key("route.#").HasValue("0"), + ), }, }) } -func TestAccAzureRMRouteTable_disappears(t *testing.T) { +func TestAccRouteTable_disappears(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_table", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteTable_basic(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - testCheckAzureRMRouteTableDisappears(data.ResourceName), - ), - ExpectNonEmptyPlan: true, - }, + r := RouteTableResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.basic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + testCheckRouteTableDisappears(data.ResourceName), + ), + ExpectNonEmptyPlan: true, }, }) } -func TestAccAzureRMRouteTable_withTags(t *testing.T) { +func TestAccRouteTable_withTags(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_table", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteTable_withTags(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), - ), - }, - { - Config: testAccAzureRMRouteTable_withTagsUpdate(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), - ), - }, + r := RouteTableResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.withTags(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("tags.%").HasValue("2"), + check.That(data.ResourceName).Key("tags.environment").HasValue("Production"), + check.That(data.ResourceName).Key("tags.cost_center").HasValue("MSFT"), + ), + }, + { + Config: r.withTagsUpdate(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("tags.%").HasValue("1"), + check.That(data.ResourceName).Key("tags.environment").HasValue("staging"), + ), }, }) } -func TestAccAzureRMRouteTable_multipleRoutes(t *testing.T) { +func TestAccRouteTable_multipleRoutes(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_route_table", "test") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMRouteTable_singleRoute(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.name", "route1"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.address_prefix", "10.1.0.0/16"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.next_hop_type", "VnetLocal"), - ), - }, - { - Config: testAccAzureRMRouteTable_multipleRoutes(data), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(data.ResourceName), - resource.TestCheckResourceAttr(data.ResourceName, "route.#", "2"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.name", "route1"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.address_prefix", "10.1.0.0/16"), - resource.TestCheckResourceAttr(data.ResourceName, "route.0.next_hop_type", "VnetLocal"), - resource.TestCheckResourceAttr(data.ResourceName, "route.1.name", "route2"), - resource.TestCheckResourceAttr(data.ResourceName, "route.1.address_prefix", "10.2.0.0/16"), - resource.TestCheckResourceAttr(data.ResourceName, "route.1.next_hop_type", "VnetLocal"), - ), - }, - data.ImportStep(), + r := RouteTableResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.singleRoute(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("route.#").HasValue("1"), + check.That(data.ResourceName).Key("route.0.name").HasValue("route1"), + check.That(data.ResourceName).Key("route.0.address_prefix").HasValue("10.1.0.0/16"), + check.That(data.ResourceName).Key("route.0.next_hop_type").HasValue("VnetLocal"), + ), + }, + { + Config: r.multipleRoutes(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("route.#").HasValue("2"), + check.That(data.ResourceName).Key("route.0.name").HasValue("route1"), + check.That(data.ResourceName).Key("route.0.address_prefix").HasValue("10.1.0.0/16"), + check.That(data.ResourceName).Key("route.0.next_hop_type").HasValue("VnetLocal"), + check.That(data.ResourceName).Key("route.1.name").HasValue("route2"), + check.That(data.ResourceName).Key("route.1.address_prefix").HasValue("10.2.0.0/16"), + check.That(data.ResourceName).Key("route.1.next_hop_type").HasValue("VnetLocal"), + ), }, + data.ImportStep(), }) } -func testCheckAzureRMRouteTableExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %q", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] - if !hasResourceGroup { - return fmt.Errorf("Bad: no resource group found in state for route table: %q", name) - } - - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.RouteTablesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - resp, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Route Table %q (resource group: %q) does not exist", name, resourceGroup) - } - - return fmt.Errorf("Bad: Get on routeTablesClient: %+v", err) - } +func (t RouteTableResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) { + id, err := network.ParseRouteTableID(state.ID) + if err != nil { + return nil, err + } - return nil + resp, err := clients.Network.RouteTablesClient.Get(ctx, id.ResourceGroup, id.Name, "") + if err != nil { + return nil, fmt.Errorf("reading Route Table (%s): %+v", id, err) } + + return utils.Bool(resp.ID != nil), nil } -func testCheckAzureRMRouteTableDisappears(resourceName string) resource.TestCheckFunc { +func testCheckRouteTableDisappears(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -319,34 +274,7 @@ func testCheckAzureRMRouteTableDisappears(resourceName string) resource.TestChec } } -func testCheckAzureRMRouteTableDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.RouteTablesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_route_table" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := client.Get(ctx, resourceGroup, name, "") - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return nil - } - - return err - } - - return fmt.Errorf("Route Table still exists:\n%#v", resp.RouteTablePropertiesFormat) - } - - return nil -} - -func testAccAzureRMRouteTable_basic(data acceptance.TestData) string { +func (RouteTableResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -365,7 +293,7 @@ resource "azurerm_route_table" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_requiresImport(data acceptance.TestData) string { +func (r RouteTableResource) requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -374,10 +302,10 @@ resource "azurerm_route_table" "import" { location = azurerm_route_table.test.location resource_group_name = azurerm_route_table.test.resource_group_name } -`, testAccAzureRMRouteTable_basic(data)) +`, r.basic(data)) } -func testAccAzureRMRouteTable_basicAppliance(data acceptance.TestData) string { +func (RouteTableResource) basicAppliance(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -403,7 +331,7 @@ resource "azurerm_route_table" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_complete(data acceptance.TestData) string { +func (RouteTableResource) complete(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -430,7 +358,7 @@ resource "azurerm_route_table" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_singleRoute(data acceptance.TestData) string { +func (RouteTableResource) singleRoute(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -455,7 +383,7 @@ resource "azurerm_route_table" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_noRouteBlocks(data acceptance.TestData) string { +func (RouteTableResource) noRouteBlocks(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -474,7 +402,7 @@ resource "azurerm_route_table" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_singleRouteRemoved(data acceptance.TestData) string { +func (RouteTableResource) singleRouteRemoved(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -495,7 +423,7 @@ resource "azurerm_route_table" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_multipleRoutes(data acceptance.TestData) string { +func (RouteTableResource) multipleRoutes(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -526,7 +454,7 @@ resource "azurerm_route_table" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_withTags(data acceptance.TestData) string { +func (RouteTableResource) withTags(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -556,7 +484,7 @@ resource "azurerm_route_table" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_withTagsUpdate(data acceptance.TestData) string { +func (RouteTableResource) withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {}