From f4ac2bed7efe961be1994733a76dcf70b8ff87f5 Mon Sep 17 00:00:00 2001 From: Jack Batzner Date: Fri, 20 Dec 2019 13:36:34 -0600 Subject: [PATCH 001/203] Add primary & secondary connection string to DPS Shared Access Policy --- ...rce_arm_iothub_dps_shared_access_policy.go | 29 +++++++++++++++++++ ...rm_iothub_dps_shared_access_policy_test.go | 4 +++ 2 files changed, 33 insertions(+) diff --git a/azurerm/resource_arm_iothub_dps_shared_access_policy.go b/azurerm/resource_arm_iothub_dps_shared_access_policy.go index c491ccbed327..7e5a44d688ca 100644 --- a/azurerm/resource_arm_iothub_dps_shared_access_policy.go +++ b/azurerm/resource_arm_iothub_dps_shared_access_policy.go @@ -92,11 +92,23 @@ func resourceArmIotHubDPSSharedAccessPolicy() *schema.Resource { Computed: true, }, + "primary_connection_string": { + Type: schema.TypeString, + Sensitive: true, + Computed: true, + }, + "secondary_key": { Type: schema.TypeString, Sensitive: true, Computed: true, }, + + "secondary_connection_string": { + Type: schema.TypeString, + Sensitive: true, + Computed: true, + }, }, } } @@ -201,6 +213,11 @@ func resourceArmIotHubDPSSharedAccessPolicyRead(d *schema.ResourceData, meta int iothubDpsName := id.Path["provisioningServices"] keyName := id.Path["keys"] + iothubDps, err := client.Get(ctx, iothubDpsName, resourceGroup) + if err != nil { + return fmt.Errorf("Error retrieving IotHub DPS %q (Resource Group %q): %+v", iothubDpsName, resourceGroup, err) + } + accessPolicy, err := client.ListKeysForKeyName(ctx, iothubDpsName, keyName, resourceGroup) if err != nil { if utils.ResponseWasNotFound(accessPolicy.Response) { @@ -217,6 +234,14 @@ func resourceArmIotHubDPSSharedAccessPolicyRead(d *schema.ResourceData, meta int d.Set("primary_key", accessPolicy.PrimaryKey) d.Set("secondary_key", accessPolicy.SecondaryKey) + if err := d.Set("primary_connection_string", getSAPConnectionString(*iothubDps.Properties.ServiceOperationsHostName, keyName, *accessPolicy.PrimaryKey)); err != nil { + return fmt.Errorf("error setting `primary_connection_string`: %v", err) + } + + if err := d.Set("secondary_connection_string", getSAPConnectionString(*iothubDps.Properties.ServiceOperationsHostName, keyName, *accessPolicy.SecondaryKey)); err != nil { + return fmt.Errorf("error setting `secondary_connection_string`: %v", err) + } + rights := flattenDpsAccessRights(accessPolicy.Rights) d.Set("enrollment_read", rights.enrollmentRead) d.Set("enrollment_write", rights.enrollmentWrite) @@ -369,3 +394,7 @@ func flattenDpsAccessRights(r iothub.AccessRightsDescription) dpsAccessRights { return rights } + +func getSAPConnectionString(iothubDpsHostName string, keyName string, key string) string { + return fmt.Sprintf("HostName=%s;SharedAccessKeyName=%s;SharedAccessKey=%s", iothubDpsHostName, keyName, key) +} diff --git a/azurerm/resource_arm_iothub_dps_shared_access_policy_test.go b/azurerm/resource_arm_iothub_dps_shared_access_policy_test.go index ad4ab93349c1..3e7582fa8a83 100644 --- a/azurerm/resource_arm_iothub_dps_shared_access_policy_test.go +++ b/azurerm/resource_arm_iothub_dps_shared_access_policy_test.go @@ -33,6 +33,10 @@ func TestAccAzureRMIotHubDpsSharedAccessPolicy_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "registration_read", "false"), resource.TestCheckResourceAttr(resourceName, "registration_write", "false"), resource.TestCheckResourceAttr(resourceName, "service_config", "true"), + resource.TestCheckResourceAttrSet(resourceName, "primary_key"), + resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), ), }, }, From 6275c9bca32f4a19e486f37f613f142924f654f3 Mon Sep 17 00:00:00 2001 From: Jack Batzner Date: Fri, 20 Dec 2019 13:38:37 -0600 Subject: [PATCH 002/203] Update website --- website/docs/r/iothub_dps_shared_access_policy.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/docs/r/iothub_dps_shared_access_policy.html.markdown b/website/docs/r/iothub_dps_shared_access_policy.html.markdown index 0a31b8710000..2caab60a5df4 100644 --- a/website/docs/r/iothub_dps_shared_access_policy.html.markdown +++ b/website/docs/r/iothub_dps_shared_access_policy.html.markdown @@ -77,8 +77,12 @@ The following attributes are exported: * `primary_key` - The primary key used to create the authentication token. +* `primary_connection_string` - The primary connection string of the Shared Access Policy. + * `secondary_key` - The secondary key used to create the authentication token. +* `secondary_connection_string` - The secondary connection string of the Shared Access Policy. + ## Import IoT Hub Device Provisioning Service Shared Access Policies can be imported using the `resource id`, e.g. From 961d4a9c84448bfc37560c37636dae63519c2a0b Mon Sep 17 00:00:00 2001 From: Jack Batzner Date: Mon, 30 Dec 2019 07:17:55 -0600 Subject: [PATCH 003/203] nil check properties --- ...rce_arm_iothub_dps_shared_access_policy.go | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_iothub_dps_shared_access_policy.go b/azurerm/resource_arm_iothub_dps_shared_access_policy.go index 7e5a44d688ca..a4c920b58fd4 100644 --- a/azurerm/resource_arm_iothub_dps_shared_access_policy.go +++ b/azurerm/resource_arm_iothub_dps_shared_access_policy.go @@ -234,12 +234,24 @@ func resourceArmIotHubDPSSharedAccessPolicyRead(d *schema.ResourceData, meta int d.Set("primary_key", accessPolicy.PrimaryKey) d.Set("secondary_key", accessPolicy.SecondaryKey) - if err := d.Set("primary_connection_string", getSAPConnectionString(*iothubDps.Properties.ServiceOperationsHostName, keyName, *accessPolicy.PrimaryKey)); err != nil { - return fmt.Errorf("error setting `primary_connection_string`: %v", err) + if props := iothubDps.Properties; props != nil { + if hosts := props.ServiceOperationsHostName; hosts != nil { + if pKey := accessPolicy.PrimaryKey; pKey != nil { + if err := d.Set("primary_connection_string", getSAPConnectionString(*iothubDps.Properties.ServiceOperationsHostName, keyName, *accessPolicy.PrimaryKey)); err != nil { + return fmt.Errorf("error setting `primary_connection_string`: %v", err) + } + } + } } - if err := d.Set("secondary_connection_string", getSAPConnectionString(*iothubDps.Properties.ServiceOperationsHostName, keyName, *accessPolicy.SecondaryKey)); err != nil { - return fmt.Errorf("error setting `secondary_connection_string`: %v", err) + if props := iothubDps.Properties; props != nil { + if hosts := props.ServiceOperationsHostName; hosts != nil { + if sKey := accessPolicy.SecondaryKey; sKey != nil { + if err := d.Set("secondary_connection_string", getSAPConnectionString(*iothubDps.Properties.ServiceOperationsHostName, keyName, *accessPolicy.SecondaryKey)); err != nil { + return fmt.Errorf("error setting `secondary_connection_string`: %v", err) + } + } + } } rights := flattenDpsAccessRights(accessPolicy.Rights) From 54b30c39583d582f35bec954dde252161de96748 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 30 Dec 2019 20:43:14 -0600 Subject: [PATCH 004/203] Simplify logic for setting connection strings --- .../resource_arm_iothub_dps_shared_access_policy.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/azurerm/resource_arm_iothub_dps_shared_access_policy.go b/azurerm/resource_arm_iothub_dps_shared_access_policy.go index a4c920b58fd4..9888fc1d1817 100644 --- a/azurerm/resource_arm_iothub_dps_shared_access_policy.go +++ b/azurerm/resource_arm_iothub_dps_shared_access_policy.go @@ -235,19 +235,15 @@ func resourceArmIotHubDPSSharedAccessPolicyRead(d *schema.ResourceData, meta int d.Set("secondary_key", accessPolicy.SecondaryKey) if props := iothubDps.Properties; props != nil { - if hosts := props.ServiceOperationsHostName; hosts != nil { + if host := props.ServiceOperationsHostName; host != nil { if pKey := accessPolicy.PrimaryKey; pKey != nil { - if err := d.Set("primary_connection_string", getSAPConnectionString(*iothubDps.Properties.ServiceOperationsHostName, keyName, *accessPolicy.PrimaryKey)); err != nil { + if err := d.Set("primary_connection_string", getSAPConnectionString(*host, keyName, *pKey)); err != nil { return fmt.Errorf("error setting `primary_connection_string`: %v", err) } } - } - } - if props := iothubDps.Properties; props != nil { - if hosts := props.ServiceOperationsHostName; hosts != nil { if sKey := accessPolicy.SecondaryKey; sKey != nil { - if err := d.Set("secondary_connection_string", getSAPConnectionString(*iothubDps.Properties.ServiceOperationsHostName, keyName, *accessPolicy.SecondaryKey)); err != nil { + if err := d.Set("secondary_connection_string", getSAPConnectionString(*host, keyName, *sKey)); err != nil { return fmt.Errorf("error setting `secondary_connection_string`: %v", err) } } From 5e2868b2f67c8c2c19dd0e8cac61df0a56b7add6 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 14:39:55 -0800 Subject: [PATCH 005/203] Move analysis services --- azurerm/internal/services/analysisservices/registration.go | 4 +++- .../resource_arm_analysis_services_server.go | 2 +- .../resource_arm_analysis_services_server_test.go | 2 +- azurerm/provider.go | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) rename azurerm/{ => internal/services/analysisservices}/resource_arm_analysis_services_server.go (99%) rename azurerm/{ => internal/services/analysisservices}/resource_arm_analysis_services_server_test.go (99%) diff --git a/azurerm/internal/services/analysisservices/registration.go b/azurerm/internal/services/analysisservices/registration.go index a83cb61fdfc2..0686ff1a77c9 100644 --- a/azurerm/internal/services/analysisservices/registration.go +++ b/azurerm/internal/services/analysisservices/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_analysis_services_server": resourceArmAnalysisServicesServer(), + } } diff --git a/azurerm/resource_arm_analysis_services_server.go b/azurerm/internal/services/analysisservices/resource_arm_analysis_services_server.go similarity index 99% rename from azurerm/resource_arm_analysis_services_server.go rename to azurerm/internal/services/analysisservices/resource_arm_analysis_services_server.go index e246c9efce35..655fc885ede3 100644 --- a/azurerm/resource_arm_analysis_services_server.go +++ b/azurerm/internal/services/analysisservices/resource_arm_analysis_services_server.go @@ -1,4 +1,4 @@ -package azurerm +package analysisservices import ( "fmt" diff --git a/azurerm/resource_arm_analysis_services_server_test.go b/azurerm/internal/services/analysisservices/resource_arm_analysis_services_server_test.go similarity index 99% rename from azurerm/resource_arm_analysis_services_server_test.go rename to azurerm/internal/services/analysisservices/resource_arm_analysis_services_server_test.go index 53331f6e3c92..028dd0ade22c 100644 --- a/azurerm/resource_arm_analysis_services_server_test.go +++ b/azurerm/internal/services/analysisservices/resource_arm_analysis_services_server_test.go @@ -1,4 +1,4 @@ -package azurerm +package analysisservices import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index d83effdfe1b5..405b407d5066 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -120,7 +120,6 @@ func Provider() terraform.ResourceProvider { resources := map[string]*schema.Resource{ "azurerm_advanced_threat_protection": resourceArmAdvancedThreatProtection(), - "azurerm_analysis_services_server": resourceArmAnalysisServicesServer(), "azurerm_api_management": resourceArmApiManagementService(), "azurerm_api_management_api": resourceArmApiManagementApi(), "azurerm_api_management_api_operation": resourceArmApiManagementApiOperation(), From ae468418fbee65c2641dddc13afff8a3edec5807 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 14:52:00 -0800 Subject: [PATCH 006/203] apimanagement --- .../data_source_api_management.go | 2 +- .../data_source_api_management_api.go | 2 +- .../data_source_api_management_api_test.go | 2 +- .../data_source_api_management_group.go | 2 +- .../data_source_api_management_group_test.go | 2 +- .../data_source_api_management_product.go | 2 +- ...data_source_api_management_product_test.go | 2 +- .../data_source_api_management_test.go | 2 +- .../data_source_api_management_user.go | 2 +- .../data_source_api_management_user_test.go | 2 +- .../services/apimanagement/registration.go | 33 +++++++++++++++++-- .../resource_arm_api_management.go | 2 +- .../resource_arm_api_management_api.go | 2 +- ...source_arm_api_management_api_operation.go | 2 +- ...arm_api_management_api_operation_policy.go | 2 +- ...pi_management_api_operation_policy_test.go | 2 +- ...e_arm_api_management_api_operation_test.go | 2 +- .../resource_arm_api_management_api_policy.go | 5 ++- ...urce_arm_api_management_api_policy_test.go | 2 +- .../resource_arm_api_management_api_schema.go | 2 +- ...urce_arm_api_management_api_schema_test.go | 2 +- .../resource_arm_api_management_api_test.go | 2 +- ...urce_arm_api_management_api_version_set.go | 2 +- ...arm_api_management_api_version_set_test.go | 2 +- ...arm_api_management_authorization_server.go | 2 +- ...pi_management_authorization_server_test.go | 2 +- .../resource_arm_api_management_backend.go | 2 +- ...esource_arm_api_management_backend_test.go | 2 +- ...resource_arm_api_management_certificate.go | 2 +- ...rce_arm_api_management_certificate_test.go | 2 +- .../resource_arm_api_management_diagnostic.go | 2 +- ...urce_arm_api_management_diagnostic_test.go | 2 +- .../resource_arm_api_management_group.go | 2 +- .../resource_arm_api_management_group_test.go | 2 +- .../resource_arm_api_management_group_user.go | 2 +- ...urce_arm_api_management_group_user_test.go | 2 +- .../resource_arm_api_management_logger.go | 2 +- ...resource_arm_api_management_logger_test.go | 2 +- ..._api_management_openid_connect_provider.go | 2 +- ...management_openid_connect_provider_test.go | 2 +- .../resource_arm_api_management_product.go | 2 +- ...resource_arm_api_management_product_api.go | 2 +- ...rce_arm_api_management_product_api_test.go | 2 +- ...source_arm_api_management_product_group.go | 2 +- ...e_arm_api_management_product_group_test.go | 2 +- ...ource_arm_api_management_product_policy.go | 2 +- ..._arm_api_management_product_policy_test.go | 2 +- ...esource_arm_api_management_product_test.go | 2 +- .../resource_arm_api_management_property.go | 2 +- ...source_arm_api_management_property_test.go | 2 +- ...esource_arm_api_management_subscription.go | 2 +- ...ce_arm_api_management_subscription_test.go | 2 +- .../resource_arm_api_management_test.go | 2 +- .../resource_arm_api_management_user.go | 2 +- .../resource_arm_api_management_user_test.go | 2 +- azurerm/provider.go | 27 --------------- 56 files changed, 86 insertions(+), 85 deletions(-) rename azurerm/{ => internal/services/apimanagement}/data_source_api_management.go (99%) rename azurerm/{ => internal/services/apimanagement}/data_source_api_management_api.go (99%) rename azurerm/{ => internal/services/apimanagement}/data_source_api_management_api_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/data_source_api_management_group.go (99%) rename azurerm/{ => internal/services/apimanagement}/data_source_api_management_group_test.go (98%) rename azurerm/{ => internal/services/apimanagement}/data_source_api_management_product.go (99%) rename azurerm/{ => internal/services/apimanagement}/data_source_api_management_product_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/data_source_api_management_test.go (98%) rename azurerm/{ => internal/services/apimanagement}/data_source_api_management_user.go (99%) rename azurerm/{ => internal/services/apimanagement}/data_source_api_management_user_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_operation.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_operation_policy.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_operation_policy_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_operation_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_policy.go (96%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_policy_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_schema.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_schema_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_version_set.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_api_version_set_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_authorization_server.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_authorization_server_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_backend.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_backend_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_certificate.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_certificate_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_diagnostic.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_diagnostic_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_group.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_group_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_group_user.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_group_user_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_logger.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_logger_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_openid_connect_provider.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_openid_connect_provider_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_product.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_product_api.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_product_api_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_product_group.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_product_group_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_product_policy.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_product_policy_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_product_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_property.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_property_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_subscription.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_subscription_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_test.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_user.go (99%) rename azurerm/{ => internal/services/apimanagement}/resource_arm_api_management_user_test.go (99%) diff --git a/azurerm/data_source_api_management.go b/azurerm/internal/services/apimanagement/data_source_api_management.go similarity index 99% rename from azurerm/data_source_api_management.go rename to azurerm/internal/services/apimanagement/data_source_api_management.go index f8849cb37d48..f482b9cc0c90 100644 --- a/azurerm/data_source_api_management.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/data_source_api_management_api.go b/azurerm/internal/services/apimanagement/data_source_api_management_api.go similarity index 99% rename from azurerm/data_source_api_management_api.go rename to azurerm/internal/services/apimanagement/data_source_api_management_api.go index 2bc0e57f32d1..af27561c8be6 100644 --- a/azurerm/data_source_api_management_api.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management_api.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/data_source_api_management_api_test.go b/azurerm/internal/services/apimanagement/data_source_api_management_api_test.go similarity index 99% rename from azurerm/data_source_api_management_api_test.go rename to azurerm/internal/services/apimanagement/data_source_api_management_api_test.go index 701d9995486d..269e474f3682 100644 --- a/azurerm/data_source_api_management_api_test.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management_api_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/data_source_api_management_group.go b/azurerm/internal/services/apimanagement/data_source_api_management_group.go similarity index 99% rename from azurerm/data_source_api_management_group.go rename to azurerm/internal/services/apimanagement/data_source_api_management_group.go index bda645c86c14..4b21b6913998 100644 --- a/azurerm/data_source_api_management_group.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management_group.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/data_source_api_management_group_test.go b/azurerm/internal/services/apimanagement/data_source_api_management_group_test.go similarity index 98% rename from azurerm/data_source_api_management_group_test.go rename to azurerm/internal/services/apimanagement/data_source_api_management_group_test.go index b73ba9338a8b..ec3f35e824b2 100644 --- a/azurerm/data_source_api_management_group_test.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/data_source_api_management_product.go b/azurerm/internal/services/apimanagement/data_source_api_management_product.go similarity index 99% rename from azurerm/data_source_api_management_product.go rename to azurerm/internal/services/apimanagement/data_source_api_management_product.go index 1dfc92c48a33..be1558d436f8 100644 --- a/azurerm/data_source_api_management_product.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management_product.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/data_source_api_management_product_test.go b/azurerm/internal/services/apimanagement/data_source_api_management_product_test.go similarity index 99% rename from azurerm/data_source_api_management_product_test.go rename to azurerm/internal/services/apimanagement/data_source_api_management_product_test.go index 8fbdbe78aab3..8cc1fe1346b8 100644 --- a/azurerm/data_source_api_management_product_test.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management_product_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/data_source_api_management_test.go b/azurerm/internal/services/apimanagement/data_source_api_management_test.go similarity index 98% rename from azurerm/data_source_api_management_test.go rename to azurerm/internal/services/apimanagement/data_source_api_management_test.go index 8ae5acb5ca1c..afb68fb4c2a0 100644 --- a/azurerm/data_source_api_management_test.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/data_source_api_management_user.go b/azurerm/internal/services/apimanagement/data_source_api_management_user.go similarity index 99% rename from azurerm/data_source_api_management_user.go rename to azurerm/internal/services/apimanagement/data_source_api_management_user.go index 8eeacfc50c91..dae4e68bfdde 100644 --- a/azurerm/data_source_api_management_user.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management_user.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/data_source_api_management_user_test.go b/azurerm/internal/services/apimanagement/data_source_api_management_user_test.go similarity index 99% rename from azurerm/data_source_api_management_user_test.go rename to azurerm/internal/services/apimanagement/data_source_api_management_user_test.go index 36cf37500ddb..b18e2a3e727a 100644 --- a/azurerm/data_source_api_management_user_test.go +++ b/azurerm/internal/services/apimanagement/data_source_api_management_user_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/internal/services/apimanagement/registration.go b/azurerm/internal/services/apimanagement/registration.go index 54363665390f..e14db112f0ab 100644 --- a/azurerm/internal/services/apimanagement/registration.go +++ b/azurerm/internal/services/apimanagement/registration.go @@ -13,10 +13,39 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_api_management": dataSourceApiManagementService(), + "azurerm_api_management_api": dataSourceApiManagementApi(), + "azurerm_api_management_group": dataSourceApiManagementGroup(), + "azurerm_api_management_product": dataSourceApiManagementProduct(), + "azurerm_api_management_user": dataSourceArmApiManagementUser(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_api_management": resourceArmApiManagementService(), + "azurerm_api_management_api": resourceArmApiManagementApi(), + "azurerm_api_management_api_operation": resourceArmApiManagementApiOperation(), + "azurerm_api_management_api_operation_policy": resourceArmApiManagementApiOperationPolicy(), + "azurerm_api_management_api_policy": resourceArmApiManagementApiPolicy(), + "azurerm_api_management_api_schema": resourceArmApiManagementApiSchema(), + "azurerm_api_management_api_version_set": resourceArmApiManagementApiVersionSet(), + "azurerm_api_management_authorization_server": resourceArmApiManagementAuthorizationServer(), + "azurerm_api_management_backend": resourceArmApiManagementBackend(), + "azurerm_api_management_certificate": resourceArmApiManagementCertificate(), + "azurerm_api_management_diagnostic": resourceArmApiManagementDiagnostic(), + "azurerm_api_management_group": resourceArmApiManagementGroup(), + "azurerm_api_management_group_user": resourceArmApiManagementGroupUser(), + "azurerm_api_management_logger": resourceArmApiManagementLogger(), + "azurerm_api_management_openid_connect_provider": resourceArmApiManagementOpenIDConnectProvider(), + "azurerm_api_management_product": resourceArmApiManagementProduct(), + "azurerm_api_management_product_api": resourceArmApiManagementProductApi(), + "azurerm_api_management_product_group": resourceArmApiManagementProductGroup(), + "azurerm_api_management_product_policy": resourceArmApiManagementProductPolicy(), + "azurerm_api_management_property": resourceArmApiManagementProperty(), + "azurerm_api_management_subscription": resourceArmApiManagementSubscription(), + "azurerm_api_management_user": resourceArmApiManagementUser(), + } } diff --git a/azurerm/resource_arm_api_management.go b/azurerm/internal/services/apimanagement/resource_arm_api_management.go similarity index 99% rename from azurerm/resource_arm_api_management.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management.go index 1d32925267eb..b4ab08c42860 100644 --- a/azurerm/resource_arm_api_management.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api.go similarity index 99% rename from azurerm/resource_arm_api_management_api.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api.go index ff5d541d0ee0..9d6d8e5699df 100644 --- a/azurerm/resource_arm_api_management_api.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api_operation.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go similarity index 99% rename from azurerm/resource_arm_api_management_api_operation.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go index c2d632de09e9..38e7bbd2daaf 100644 --- a/azurerm/resource_arm_api_management_api_operation.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api_operation_policy.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_policy.go similarity index 99% rename from azurerm/resource_arm_api_management_api_operation_policy.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_policy.go index ef7fbe6c413a..64206fa158c4 100644 --- a/azurerm/resource_arm_api_management_api_operation_policy.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_policy.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api_operation_policy_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_policy_test.go similarity index 99% rename from azurerm/resource_arm_api_management_api_operation_policy_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_policy_test.go index 259c26c2ef14..e54ea72d5d2f 100644 --- a/azurerm/resource_arm_api_management_api_operation_policy_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api_operation_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_test.go similarity index 99% rename from azurerm/resource_arm_api_management_api_operation_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_test.go index a0a7f56cdfe8..36e95a30b957 100644 --- a/azurerm/resource_arm_api_management_api_operation_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api_policy.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_policy.go similarity index 96% rename from azurerm/resource_arm_api_management_api_policy.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_policy.go index 7b59117d6d57..25c08754eae9 100644 --- a/azurerm/resource_arm_api_management_api_policy.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_policy.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" @@ -12,7 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - apimanagementSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -46,7 +45,7 @@ func resourceArmApiManagementApiPolicy() *schema.Resource { Optional: true, Computed: true, ConflictsWith: []string{"xml_link"}, - DiffSuppressFunc: apimanagementSvc.XmlWithDotNetInterpolationsDiffSuppress, + DiffSuppressFunc: XmlWithDotNetInterpolationsDiffSuppress, }, "xml_link": { diff --git a/azurerm/resource_arm_api_management_api_policy_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_policy_test.go similarity index 99% rename from azurerm/resource_arm_api_management_api_policy_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_policy_test.go index ea2a8b66a7d9..9b53a7c64811 100644 --- a/azurerm/resource_arm_api_management_api_policy_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api_schema.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_schema.go similarity index 99% rename from azurerm/resource_arm_api_management_api_schema.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_schema.go index d44474a9e3ec..597a434d6e48 100644 --- a/azurerm/resource_arm_api_management_api_schema.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_schema.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api_schema_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_schema_test.go similarity index 99% rename from azurerm/resource_arm_api_management_api_schema_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_schema_test.go index f00c0bee4d52..b0b650f1ed0d 100644 --- a/azurerm/resource_arm_api_management_api_schema_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_schema_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_test.go similarity index 99% rename from azurerm/resource_arm_api_management_api_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_test.go index 83d14407590a..7ac4c27b8016 100644 --- a/azurerm/resource_arm_api_management_api_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api_version_set.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_version_set.go similarity index 99% rename from azurerm/resource_arm_api_management_api_version_set.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_version_set.go index 0982bdb0ac8a..144707f20d42 100644 --- a/azurerm/resource_arm_api_management_api_version_set.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_version_set.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_api_version_set_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_version_set_test.go similarity index 99% rename from azurerm/resource_arm_api_management_api_version_set_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_api_version_set_test.go index 124098e6ba5c..991bcc65019b 100644 --- a/azurerm/resource_arm_api_management_api_version_set_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_version_set_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_authorization_server.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_authorization_server.go similarity index 99% rename from azurerm/resource_arm_api_management_authorization_server.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_authorization_server.go index 7748b1c94cb4..907a85ac1ab6 100644 --- a/azurerm/resource_arm_api_management_authorization_server.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_authorization_server.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_authorization_server_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_authorization_server_test.go similarity index 99% rename from azurerm/resource_arm_api_management_authorization_server_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_authorization_server_test.go index d0af4a83770e..7dc6fa1ff9e1 100644 --- a/azurerm/resource_arm_api_management_authorization_server_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_authorization_server_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_backend.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_backend.go similarity index 99% rename from azurerm/resource_arm_api_management_backend.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_backend.go index 6a7455172639..faf8ee58de84 100644 --- a/azurerm/resource_arm_api_management_backend.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_backend.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_backend_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_backend_test.go similarity index 99% rename from azurerm/resource_arm_api_management_backend_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_backend_test.go index 75d380e4a91e..fd967626aae7 100644 --- a/azurerm/resource_arm_api_management_backend_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_backend_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_certificate.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_certificate.go similarity index 99% rename from azurerm/resource_arm_api_management_certificate.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_certificate.go index 34824f68db10..314e6896b72d 100644 --- a/azurerm/resource_arm_api_management_certificate.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_certificate.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_certificate_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_certificate_test.go similarity index 99% rename from azurerm/resource_arm_api_management_certificate_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_certificate_test.go index 86edd510d8ce..169a0dd20119 100644 --- a/azurerm/resource_arm_api_management_certificate_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_certificate_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_diagnostic.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_diagnostic.go similarity index 99% rename from azurerm/resource_arm_api_management_diagnostic.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_diagnostic.go index 1418d9278fc1..adffb9250b79 100644 --- a/azurerm/resource_arm_api_management_diagnostic.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_diagnostic.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_diagnostic_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_diagnostic_test.go similarity index 99% rename from azurerm/resource_arm_api_management_diagnostic_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_diagnostic_test.go index ebb1a4d60689..6ec31794f2f9 100644 --- a/azurerm/resource_arm_api_management_diagnostic_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_diagnostic_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_group.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_group.go similarity index 99% rename from azurerm/resource_arm_api_management_group.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_group.go index 1a8e00a3256b..3243167c729c 100644 --- a/azurerm/resource_arm_api_management_group.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_group.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_group_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_group_test.go similarity index 99% rename from azurerm/resource_arm_api_management_group_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_group_test.go index 6fb5be5f5010..710eb7f8e77b 100644 --- a/azurerm/resource_arm_api_management_group_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_group_user.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_group_user.go similarity index 99% rename from azurerm/resource_arm_api_management_group_user.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_group_user.go index aa162417c15a..2df9f01a1266 100644 --- a/azurerm/resource_arm_api_management_group_user.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_group_user.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_group_user_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_group_user_test.go similarity index 99% rename from azurerm/resource_arm_api_management_group_user_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_group_user_test.go index b7b5f394c8c7..58adbcba0cac 100644 --- a/azurerm/resource_arm_api_management_group_user_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_group_user_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_logger.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_logger.go similarity index 99% rename from azurerm/resource_arm_api_management_logger.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_logger.go index 3c86669ed3a8..bc3d24c7ebd2 100644 --- a/azurerm/resource_arm_api_management_logger.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_logger.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_logger_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_logger_test.go similarity index 99% rename from azurerm/resource_arm_api_management_logger_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_logger_test.go index 43a0f748a3a4..dee80e2b314b 100644 --- a/azurerm/resource_arm_api_management_logger_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_logger_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_openid_connect_provider.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_openid_connect_provider.go similarity index 99% rename from azurerm/resource_arm_api_management_openid_connect_provider.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_openid_connect_provider.go index cdb631f32728..09084d414629 100644 --- a/azurerm/resource_arm_api_management_openid_connect_provider.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_openid_connect_provider.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_openid_connect_provider_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_openid_connect_provider_test.go similarity index 99% rename from azurerm/resource_arm_api_management_openid_connect_provider_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_openid_connect_provider_test.go index 3d76afe91e98..cfc48b505194 100644 --- a/azurerm/resource_arm_api_management_openid_connect_provider_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_openid_connect_provider_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_product.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_product.go similarity index 99% rename from azurerm/resource_arm_api_management_product.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_product.go index 7be51d459bad..9de0ec5d9a22 100644 --- a/azurerm/resource_arm_api_management_product.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_product.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_product_api.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_api.go similarity index 99% rename from azurerm/resource_arm_api_management_product_api.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_product_api.go index bd5efb4ee892..950fda861a2f 100644 --- a/azurerm/resource_arm_api_management_product_api.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_api.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_product_api_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_api_test.go similarity index 99% rename from azurerm/resource_arm_api_management_product_api_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_product_api_test.go index b0d2fc37e258..6115331212bb 100644 --- a/azurerm/resource_arm_api_management_product_api_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_api_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_product_group.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_group.go similarity index 99% rename from azurerm/resource_arm_api_management_product_group.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_product_group.go index 026c5d1788b0..22a1398578b0 100644 --- a/azurerm/resource_arm_api_management_product_group.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_group.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_product_group_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_group_test.go similarity index 99% rename from azurerm/resource_arm_api_management_product_group_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_product_group_test.go index b76a69cf9fe6..2dec64feafb8 100644 --- a/azurerm/resource_arm_api_management_product_group_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_product_policy.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_policy.go similarity index 99% rename from azurerm/resource_arm_api_management_product_policy.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_product_policy.go index 12e971a39587..1987b3c401a0 100644 --- a/azurerm/resource_arm_api_management_product_policy.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_policy.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_product_policy_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_policy_test.go similarity index 99% rename from azurerm/resource_arm_api_management_product_policy_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_product_policy_test.go index 6ce9e99ab951..b4fe14312b8d 100644 --- a/azurerm/resource_arm_api_management_product_policy_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_product_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_test.go similarity index 99% rename from azurerm/resource_arm_api_management_product_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_product_test.go index ec462ef0a189..57a1387e645b 100644 --- a/azurerm/resource_arm_api_management_product_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_product_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_property.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_property.go similarity index 99% rename from azurerm/resource_arm_api_management_property.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_property.go index a1e3df8abd02..752b046c9e89 100644 --- a/azurerm/resource_arm_api_management_property.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_property.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_property_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_property_test.go similarity index 99% rename from azurerm/resource_arm_api_management_property_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_property_test.go index ad400ee852f1..6b75700fd85c 100644 --- a/azurerm/resource_arm_api_management_property_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_property_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_subscription.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_subscription.go similarity index 99% rename from azurerm/resource_arm_api_management_subscription.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_subscription.go index b97387a678b9..fac58fc831d3 100644 --- a/azurerm/resource_arm_api_management_subscription.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_subscription.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_subscription_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_subscription_test.go similarity index 99% rename from azurerm/resource_arm_api_management_subscription_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_subscription_test.go index 9ea07d475dd5..e7b30ef2ef8b 100644 --- a/azurerm/resource_arm_api_management_subscription_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_subscription_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_test.go similarity index 99% rename from azurerm/resource_arm_api_management_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_test.go index d00c5b7225ac..da8bd773384f 100644 --- a/azurerm/resource_arm_api_management_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_user.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_user.go similarity index 99% rename from azurerm/resource_arm_api_management_user.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_user.go index c69028d7b879..d9226ccefc6a 100644 --- a/azurerm/resource_arm_api_management_user.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_user.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/resource_arm_api_management_user_test.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_user_test.go similarity index 99% rename from azurerm/resource_arm_api_management_user_test.go rename to azurerm/internal/services/apimanagement/resource_arm_api_management_user_test.go index 7cae0a8bba17..b9b625d8fbdf 100644 --- a/azurerm/resource_arm_api_management_user_test.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_user_test.go @@ -1,4 +1,4 @@ -package azurerm +package apimanagement import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 405b407d5066..62e55cc04a53 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -9,11 +9,6 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - "azurerm_api_management": dataSourceApiManagementService(), - "azurerm_api_management_api": dataSourceApiManagementApi(), - "azurerm_api_management_group": dataSourceApiManagementGroup(), - "azurerm_api_management_product": dataSourceApiManagementProduct(), - "azurerm_api_management_user": dataSourceArmApiManagementUser(), "azurerm_app_service_plan": dataSourceAppServicePlan(), "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), "azurerm_app_service": dataSourceArmAppService(), @@ -120,28 +115,6 @@ func Provider() terraform.ResourceProvider { resources := map[string]*schema.Resource{ "azurerm_advanced_threat_protection": resourceArmAdvancedThreatProtection(), - "azurerm_api_management": resourceArmApiManagementService(), - "azurerm_api_management_api": resourceArmApiManagementApi(), - "azurerm_api_management_api_operation": resourceArmApiManagementApiOperation(), - "azurerm_api_management_api_operation_policy": resourceArmApiManagementApiOperationPolicy(), - "azurerm_api_management_api_policy": resourceArmApiManagementApiPolicy(), - "azurerm_api_management_api_schema": resourceArmApiManagementApiSchema(), - "azurerm_api_management_api_version_set": resourceArmApiManagementApiVersionSet(), - "azurerm_api_management_authorization_server": resourceArmApiManagementAuthorizationServer(), - "azurerm_api_management_backend": resourceArmApiManagementBackend(), - "azurerm_api_management_certificate": resourceArmApiManagementCertificate(), - "azurerm_api_management_diagnostic": resourceArmApiManagementDiagnostic(), - "azurerm_api_management_group": resourceArmApiManagementGroup(), - "azurerm_api_management_group_user": resourceArmApiManagementGroupUser(), - "azurerm_api_management_logger": resourceArmApiManagementLogger(), - "azurerm_api_management_openid_connect_provider": resourceArmApiManagementOpenIDConnectProvider(), - "azurerm_api_management_product": resourceArmApiManagementProduct(), - "azurerm_api_management_product_api": resourceArmApiManagementProductApi(), - "azurerm_api_management_product_group": resourceArmApiManagementProductGroup(), - "azurerm_api_management_product_policy": resourceArmApiManagementProductPolicy(), - "azurerm_api_management_property": resourceArmApiManagementProperty(), - "azurerm_api_management_subscription": resourceArmApiManagementSubscription(), - "azurerm_api_management_user": resourceArmApiManagementUser(), "azurerm_app_configuration": resourceArmAppConfiguration(), "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), "azurerm_app_service_certificate": resourceArmAppServiceCertificate(), From 00d4c3b1c07450987b986c36f47731aadb38b1a1 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 15:01:17 -0800 Subject: [PATCH 007/203] appconfiguration --- azurerm/internal/services/appconfiguration/registration.go | 4 +++- .../appconfiguration}/resource_arm_app_configuration.go | 2 +- .../appconfiguration}/resource_arm_app_configuration_test.go | 2 +- azurerm/provider.go | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) rename azurerm/{ => internal/services/appconfiguration}/resource_arm_app_configuration.go (99%) rename azurerm/{ => internal/services/appconfiguration}/resource_arm_app_configuration_test.go (99%) diff --git a/azurerm/internal/services/appconfiguration/registration.go b/azurerm/internal/services/appconfiguration/registration.go index 1ac293a1a597..31d7af75ab0d 100644 --- a/azurerm/internal/services/appconfiguration/registration.go +++ b/azurerm/internal/services/appconfiguration/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_app_configuration": resourceArmAppConfiguration(), + } } diff --git a/azurerm/resource_arm_app_configuration.go b/azurerm/internal/services/appconfiguration/resource_arm_app_configuration.go similarity index 99% rename from azurerm/resource_arm_app_configuration.go rename to azurerm/internal/services/appconfiguration/resource_arm_app_configuration.go index dbf4dbddaec5..bccb6a6c9636 100644 --- a/azurerm/resource_arm_app_configuration.go +++ b/azurerm/internal/services/appconfiguration/resource_arm_app_configuration.go @@ -1,4 +1,4 @@ -package azurerm +package appconfiguration import ( "fmt" diff --git a/azurerm/resource_arm_app_configuration_test.go b/azurerm/internal/services/appconfiguration/resource_arm_app_configuration_test.go similarity index 99% rename from azurerm/resource_arm_app_configuration_test.go rename to azurerm/internal/services/appconfiguration/resource_arm_app_configuration_test.go index 14ad33a1a11b..79a0aa7f807e 100644 --- a/azurerm/resource_arm_app_configuration_test.go +++ b/azurerm/internal/services/appconfiguration/resource_arm_app_configuration_test.go @@ -1,4 +1,4 @@ -package azurerm +package appconfiguration import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 62e55cc04a53..cf268c3aef77 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -115,7 +115,6 @@ func Provider() terraform.ResourceProvider { resources := map[string]*schema.Resource{ "azurerm_advanced_threat_protection": resourceArmAdvancedThreatProtection(), - "azurerm_app_configuration": resourceArmAppConfiguration(), "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), "azurerm_app_service_certificate": resourceArmAppServiceCertificate(), "azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(), From b913a793ce2a4518722566b24f30b59a5b8a5bbc Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 15:05:49 -0800 Subject: [PATCH 008/203] applicationinsights --- .../data_source_application_insights.go | 2 +- .../data_source_application_insights_test.go | 2 +- .../services/applicationinsights/registration.go | 11 +++++++++-- .../resource_arm_application_insights.go | 2 +- ...esource_arm_application_insights_analytics_item.go | 2 +- ...ce_arm_application_insights_analytics_item_test.go | 2 +- .../resource_arm_application_insights_api_key.go | 2 +- .../resource_arm_application_insights_api_key_test.go | 2 +- .../resource_arm_application_insights_test.go | 2 +- .../resource_arm_application_insights_webtests.go | 2 +- ...resource_arm_application_insights_webtests_test.go | 2 +- azurerm/provider.go | 5 ----- 12 files changed, 19 insertions(+), 17 deletions(-) rename azurerm/{ => internal/services/applicationinsights}/data_source_application_insights.go (98%) rename azurerm/{ => internal/services/applicationinsights}/data_source_application_insights_test.go (98%) rename azurerm/{ => internal/services/applicationinsights}/resource_arm_application_insights.go (99%) rename azurerm/{ => internal/services/applicationinsights}/resource_arm_application_insights_analytics_item.go (99%) rename azurerm/{ => internal/services/applicationinsights}/resource_arm_application_insights_analytics_item_test.go (99%) rename azurerm/{ => internal/services/applicationinsights}/resource_arm_application_insights_api_key.go (99%) rename azurerm/{ => internal/services/applicationinsights}/resource_arm_application_insights_api_key_test.go (99%) rename azurerm/{ => internal/services/applicationinsights}/resource_arm_application_insights_test.go (99%) rename azurerm/{ => internal/services/applicationinsights}/resource_arm_application_insights_webtests.go (99%) rename azurerm/{ => internal/services/applicationinsights}/resource_arm_application_insights_webtests_test.go (99%) diff --git a/azurerm/data_source_application_insights.go b/azurerm/internal/services/applicationinsights/data_source_application_insights.go similarity index 98% rename from azurerm/data_source_application_insights.go rename to azurerm/internal/services/applicationinsights/data_source_application_insights.go index 742d187fc851..3d0909018966 100644 --- a/azurerm/data_source_application_insights.go +++ b/azurerm/internal/services/applicationinsights/data_source_application_insights.go @@ -1,4 +1,4 @@ -package azurerm +package applicationinsights import ( "fmt" diff --git a/azurerm/data_source_application_insights_test.go b/azurerm/internal/services/applicationinsights/data_source_application_insights_test.go similarity index 98% rename from azurerm/data_source_application_insights_test.go rename to azurerm/internal/services/applicationinsights/data_source_application_insights_test.go index deb516f68bab..0385682ae869 100644 --- a/azurerm/data_source_application_insights_test.go +++ b/azurerm/internal/services/applicationinsights/data_source_application_insights_test.go @@ -1,4 +1,4 @@ -package azurerm +package applicationinsights import ( "fmt" diff --git a/azurerm/internal/services/applicationinsights/registration.go b/azurerm/internal/services/applicationinsights/registration.go index 818964758a61..786526aec753 100644 --- a/azurerm/internal/services/applicationinsights/registration.go +++ b/azurerm/internal/services/applicationinsights/registration.go @@ -13,10 +13,17 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_application_insights": dataSourceArmApplicationInsights(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_application_insights_api_key": resourceArmApplicationInsightsAPIKey(), + "azurerm_application_insights": resourceArmApplicationInsights(), + "azurerm_application_insights_analytics_item": resourceArmApplicationInsightsAnalyticsItem(), + "azurerm_application_insights_web_test": resourceArmApplicationInsightsWebTests(), + } } diff --git a/azurerm/resource_arm_application_insights.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go similarity index 99% rename from azurerm/resource_arm_application_insights.go rename to azurerm/internal/services/applicationinsights/resource_arm_application_insights.go index 31d42b12cfab..1b415eaff967 100644 --- a/azurerm/resource_arm_application_insights.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go @@ -1,4 +1,4 @@ -package azurerm +package applicationinsights import ( "fmt" diff --git a/azurerm/resource_arm_application_insights_analytics_item.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item.go similarity index 99% rename from azurerm/resource_arm_application_insights_analytics_item.go rename to azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item.go index 05713528c226..e1c0a17e7002 100644 --- a/azurerm/resource_arm_application_insights_analytics_item.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item.go @@ -1,4 +1,4 @@ -package azurerm +package applicationinsights import ( "fmt" diff --git a/azurerm/resource_arm_application_insights_analytics_item_test.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item_test.go similarity index 99% rename from azurerm/resource_arm_application_insights_analytics_item_test.go rename to azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item_test.go index 180a9703bdba..f8ad114f2b3c 100644 --- a/azurerm/resource_arm_application_insights_analytics_item_test.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item_test.go @@ -1,4 +1,4 @@ -package azurerm +package applicationinsights import ( "fmt" diff --git a/azurerm/resource_arm_application_insights_api_key.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_api_key.go similarity index 99% rename from azurerm/resource_arm_application_insights_api_key.go rename to azurerm/internal/services/applicationinsights/resource_arm_application_insights_api_key.go index 29de95cb525f..38f3bb7514c2 100644 --- a/azurerm/resource_arm_application_insights_api_key.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_api_key.go @@ -1,4 +1,4 @@ -package azurerm +package applicationinsights import ( "fmt" diff --git a/azurerm/resource_arm_application_insights_api_key_test.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_api_key_test.go similarity index 99% rename from azurerm/resource_arm_application_insights_api_key_test.go rename to azurerm/internal/services/applicationinsights/resource_arm_application_insights_api_key_test.go index 57a25672cef1..cf7a4f4eea24 100644 --- a/azurerm/resource_arm_application_insights_api_key_test.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_api_key_test.go @@ -1,4 +1,4 @@ -package azurerm +package applicationinsights import ( "fmt" diff --git a/azurerm/resource_arm_application_insights_test.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_test.go similarity index 99% rename from azurerm/resource_arm_application_insights_test.go rename to azurerm/internal/services/applicationinsights/resource_arm_application_insights_test.go index ae3e10df88ef..927dccea1fe9 100644 --- a/azurerm/resource_arm_application_insights_test.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_test.go @@ -1,4 +1,4 @@ -package azurerm +package applicationinsights import ( "fmt" diff --git a/azurerm/resource_arm_application_insights_webtests.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_webtests.go similarity index 99% rename from azurerm/resource_arm_application_insights_webtests.go rename to azurerm/internal/services/applicationinsights/resource_arm_application_insights_webtests.go index a2bd1bc9d8dc..9fe1917f5f61 100644 --- a/azurerm/resource_arm_application_insights_webtests.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_webtests.go @@ -1,4 +1,4 @@ -package azurerm +package applicationinsights import ( "fmt" diff --git a/azurerm/resource_arm_application_insights_webtests_test.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_webtests_test.go similarity index 99% rename from azurerm/resource_arm_application_insights_webtests_test.go rename to azurerm/internal/services/applicationinsights/resource_arm_application_insights_webtests_test.go index 322622ee6784..e340fab13a41 100644 --- a/azurerm/resource_arm_application_insights_webtests_test.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_webtests_test.go @@ -1,4 +1,4 @@ -package azurerm +package applicationinsights import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index cf268c3aef77..29855f5f64e5 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -13,7 +13,6 @@ func Provider() terraform.ResourceProvider { "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), "azurerm_app_service": dataSourceArmAppService(), "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), - "azurerm_application_insights": dataSourceArmApplicationInsights(), "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), "azurerm_automation_account": dataSourceArmAutomationAccount(), "azurerm_automation_variable_bool": dataSourceArmAutomationVariableBool(), @@ -125,10 +124,6 @@ func Provider() terraform.ResourceProvider { "azurerm_app_service_virtual_network_swift_connection": resourceArmAppServiceVirtualNetworkSwiftConnection(), "azurerm_app_service": resourceArmAppService(), "azurerm_application_gateway": resourceArmApplicationGateway(), - "azurerm_application_insights_api_key": resourceArmApplicationInsightsAPIKey(), - "azurerm_application_insights": resourceArmApplicationInsights(), - "azurerm_application_insights_analytics_item": resourceArmApplicationInsightsAnalyticsItem(), - "azurerm_application_insights_web_test": resourceArmApplicationInsightsWebTests(), "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), "azurerm_automation_account": resourceArmAutomationAccount(), "azurerm_automation_certificate": resourceArmAutomationCertificate(), From 11f846803b0243f830ea36d24d1e80c338fbad22 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 15:16:01 -0800 Subject: [PATCH 009/203] authorization --- .../authorization}/data_source_role_definition.go | 5 ++--- .../authorization}/data_source_role_definition_test.go | 2 +- azurerm/internal/services/authorization/registration.go | 9 +++++++-- .../authorization}/resource_arm_role_assignment.go | 2 +- .../authorization}/resource_arm_role_assignment_test.go | 2 +- .../authorization}/resource_arm_role_definition.go | 2 +- .../authorization}/resource_arm_role_definition_test.go | 2 +- azurerm/provider.go | 3 --- 8 files changed, 14 insertions(+), 13 deletions(-) rename azurerm/{ => internal/services/authorization}/data_source_role_definition.go (99%) rename azurerm/{ => internal/services/authorization}/data_source_role_definition_test.go (99%) rename azurerm/{ => internal/services/authorization}/resource_arm_role_assignment.go (99%) rename azurerm/{ => internal/services/authorization}/resource_arm_role_assignment_test.go (99%) rename azurerm/{ => internal/services/authorization}/resource_arm_role_definition.go (99%) rename azurerm/{ => internal/services/authorization}/resource_arm_role_definition_test.go (99%) diff --git a/azurerm/data_source_role_definition.go b/azurerm/internal/services/authorization/data_source_role_definition.go similarity index 99% rename from azurerm/data_source_role_definition.go rename to azurerm/internal/services/authorization/data_source_role_definition.go index 129c99bddea4..7e696618c3e6 100644 --- a/azurerm/data_source_role_definition.go +++ b/azurerm/internal/services/authorization/data_source_role_definition.go @@ -1,15 +1,14 @@ -package azurerm +package authorization import ( "fmt" "time" "github.com/Azure/azure-sdk-for-go/services/preview/authorization/mgmt/2018-09-01-preview/authorization" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) func dataSourceArmRoleDefinition() *schema.Resource { diff --git a/azurerm/data_source_role_definition_test.go b/azurerm/internal/services/authorization/data_source_role_definition_test.go similarity index 99% rename from azurerm/data_source_role_definition_test.go rename to azurerm/internal/services/authorization/data_source_role_definition_test.go index 19aff9baa0b4..60a6374694c2 100644 --- a/azurerm/data_source_role_definition_test.go +++ b/azurerm/internal/services/authorization/data_source_role_definition_test.go @@ -1,4 +1,4 @@ -package azurerm +package authorization import ( "fmt" diff --git a/azurerm/internal/services/authorization/registration.go b/azurerm/internal/services/authorization/registration.go index 56687aa0d5bd..4191d118e700 100644 --- a/azurerm/internal/services/authorization/registration.go +++ b/azurerm/internal/services/authorization/registration.go @@ -13,10 +13,15 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_role_definition": dataSourceArmRoleDefinition(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_role_assignment": resourceArmRoleAssignment(), + "azurerm_role_definition": resourceArmRoleDefinition(), + } } diff --git a/azurerm/resource_arm_role_assignment.go b/azurerm/internal/services/authorization/resource_arm_role_assignment.go similarity index 99% rename from azurerm/resource_arm_role_assignment.go rename to azurerm/internal/services/authorization/resource_arm_role_assignment.go index f4a8ca764459..7afbdb0edc2c 100644 --- a/azurerm/resource_arm_role_assignment.go +++ b/azurerm/internal/services/authorization/resource_arm_role_assignment.go @@ -1,4 +1,4 @@ -package azurerm +package authorization import ( "fmt" diff --git a/azurerm/resource_arm_role_assignment_test.go b/azurerm/internal/services/authorization/resource_arm_role_assignment_test.go similarity index 99% rename from azurerm/resource_arm_role_assignment_test.go rename to azurerm/internal/services/authorization/resource_arm_role_assignment_test.go index 2ddeec2a0706..a4441775df82 100644 --- a/azurerm/resource_arm_role_assignment_test.go +++ b/azurerm/internal/services/authorization/resource_arm_role_assignment_test.go @@ -1,4 +1,4 @@ -package azurerm +package authorization import ( "fmt" diff --git a/azurerm/resource_arm_role_definition.go b/azurerm/internal/services/authorization/resource_arm_role_definition.go similarity index 99% rename from azurerm/resource_arm_role_definition.go rename to azurerm/internal/services/authorization/resource_arm_role_definition.go index 46d46a7f86c5..2d7f608326e1 100644 --- a/azurerm/resource_arm_role_definition.go +++ b/azurerm/internal/services/authorization/resource_arm_role_definition.go @@ -1,4 +1,4 @@ -package azurerm +package authorization import ( "fmt" diff --git a/azurerm/resource_arm_role_definition_test.go b/azurerm/internal/services/authorization/resource_arm_role_definition_test.go similarity index 99% rename from azurerm/resource_arm_role_definition_test.go rename to azurerm/internal/services/authorization/resource_arm_role_definition_test.go index 5e816c8d5223..c8457544ca8c 100644 --- a/azurerm/resource_arm_role_definition_test.go +++ b/azurerm/internal/services/authorization/resource_arm_role_definition_test.go @@ -1,4 +1,4 @@ -package azurerm +package authorization import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 29855f5f64e5..d387020d2931 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -84,7 +84,6 @@ func Provider() terraform.ResourceProvider { "azurerm_redis_cache": dataSourceArmRedisCache(), "azurerm_resources": dataSourceArmResources(), "azurerm_resource_group": dataSourceArmResourceGroup(), - "azurerm_role_definition": dataSourceArmRoleDefinition(), "azurerm_route_table": dataSourceArmRouteTable(), "azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(), "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), @@ -367,8 +366,6 @@ func Provider() terraform.ResourceProvider { "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), "azurerm_relay_namespace": resourceArmRelayNamespace(), "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_role_assignment": resourceArmRoleAssignment(), - "azurerm_role_definition": resourceArmRoleDefinition(), "azurerm_route_table": resourceArmRouteTable(), "azurerm_route": resourceArmRoute(), "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), From 20d4c07fae8996ea7758a8cf20b2d5e19b3bcb52 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 15:29:30 -0800 Subject: [PATCH 010/203] automation --- .../automation}/automation_variable.go | 2 +- .../automation}/automation_variable_test.go | 2 +- .../data_source_automation_account.go | 2 +- .../data_source_automation_account_test.go | 2 +- .../data_source_automation_variable_bool.go | 2 +- ...ta_source_automation_variable_bool_test.go | 2 +- ...ata_source_automation_variable_datetime.go | 2 +- ...ource_automation_variable_datetime_test.go | 2 +- .../data_source_automation_variable_int.go | 2 +- ...ata_source_automation_variable_int_test.go | 2 +- .../data_source_automation_variable_string.go | 2 +- ..._source_automation_variable_string_test.go | 2 +- .../services/automation/registration.go | 24 +++++++++++++++++-- .../resource_arm_automation_account.go | 2 +- .../resource_arm_automation_account_test.go | 2 +- .../resource_arm_automation_certificate.go | 2 +- ...esource_arm_automation_certificate_test.go | 2 +- .../resource_arm_automation_credential.go | 2 +- ...resource_arm_automation_credential_test.go | 2 +- ...source_arm_automation_dsc_configuration.go | 2 +- ...e_arm_automation_dsc_configuration_test.go | 2 +- ...ce_arm_automation_dsc_nodeconfiguration.go | 2 +- ...m_automation_dsc_nodeconfiguration_test.go | 2 +- .../resource_arm_automation_job_schedule.go | 2 +- ...source_arm_automation_job_schedule_test.go | 2 +- .../resource_arm_automation_module.go | 2 +- .../resource_arm_automation_module_test.go | 2 +- .../resource_arm_automation_runbook.go | 2 +- .../resource_arm_automation_runbook_test.go | 2 +- .../resource_arm_automation_schedule.go | 2 +- .../resource_arm_automation_schedule_test.go | 2 +- .../resource_arm_automation_variable_bool.go | 2 +- ...ource_arm_automation_variable_bool_test.go | 2 +- ...source_arm_automation_variable_datetime.go | 2 +- ...e_arm_automation_variable_datetime_test.go | 2 +- .../resource_arm_automation_variable_int.go | 2 +- ...source_arm_automation_variable_int_test.go | 2 +- ...resource_arm_automation_variable_string.go | 2 +- ...rce_arm_automation_variable_string_test.go | 2 +- azurerm/provider.go | 18 -------------- 40 files changed, 60 insertions(+), 58 deletions(-) rename azurerm/{ => internal/services/automation}/automation_variable.go (99%) rename azurerm/{ => internal/services/automation}/automation_variable_test.go (99%) rename azurerm/{ => internal/services/automation}/data_source_automation_account.go (99%) rename azurerm/{ => internal/services/automation}/data_source_automation_account_test.go (98%) rename azurerm/{ => internal/services/automation}/data_source_automation_variable_bool.go (96%) rename azurerm/{ => internal/services/automation}/data_source_automation_variable_bool_test.go (98%) rename azurerm/{ => internal/services/automation}/data_source_automation_variable_datetime.go (96%) rename azurerm/{ => internal/services/automation}/data_source_automation_variable_datetime_test.go (98%) rename azurerm/{ => internal/services/automation}/data_source_automation_variable_int.go (96%) rename azurerm/{ => internal/services/automation}/data_source_automation_variable_int_test.go (98%) rename azurerm/{ => internal/services/automation}/data_source_automation_variable_string.go (96%) rename azurerm/{ => internal/services/automation}/data_source_automation_variable_string_test.go (98%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_account.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_account_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_certificate.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_certificate_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_credential.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_credential_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_dsc_configuration.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_dsc_configuration_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_dsc_nodeconfiguration.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_dsc_nodeconfiguration_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_job_schedule.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_job_schedule_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_module.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_module_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_runbook.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_runbook_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_schedule.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_schedule_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_variable_bool.go (98%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_variable_bool_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_variable_datetime.go (98%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_variable_datetime_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_variable_int.go (98%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_variable_int_test.go (99%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_variable_string.go (98%) rename azurerm/{ => internal/services/automation}/resource_arm_automation_variable_string_test.go (99%) diff --git a/azurerm/automation_variable.go b/azurerm/internal/services/automation/automation_variable.go similarity index 99% rename from azurerm/automation_variable.go rename to azurerm/internal/services/automation/automation_variable.go index 2a3ada9e85ea..3f71144455a7 100644 --- a/azurerm/automation_variable.go +++ b/azurerm/internal/services/automation/automation_variable.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/automation_variable_test.go b/azurerm/internal/services/automation/automation_variable_test.go similarity index 99% rename from azurerm/automation_variable_test.go rename to azurerm/internal/services/automation/automation_variable_test.go index aabfe4d3ec18..de4a146e22af 100644 --- a/azurerm/automation_variable_test.go +++ b/azurerm/internal/services/automation/automation_variable_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/data_source_automation_account.go b/azurerm/internal/services/automation/data_source_automation_account.go similarity index 99% rename from azurerm/data_source_automation_account.go rename to azurerm/internal/services/automation/data_source_automation_account.go index 3ca4b83e0285..c0888c251337 100644 --- a/azurerm/data_source_automation_account.go +++ b/azurerm/internal/services/automation/data_source_automation_account.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/data_source_automation_account_test.go b/azurerm/internal/services/automation/data_source_automation_account_test.go similarity index 98% rename from azurerm/data_source_automation_account_test.go rename to azurerm/internal/services/automation/data_source_automation_account_test.go index e960c347df9c..38ecc22c7a1f 100644 --- a/azurerm/data_source_automation_account_test.go +++ b/azurerm/internal/services/automation/data_source_automation_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/data_source_automation_variable_bool.go b/azurerm/internal/services/automation/data_source_automation_variable_bool.go similarity index 96% rename from azurerm/data_source_automation_variable_bool.go rename to azurerm/internal/services/automation/data_source_automation_variable_bool.go index 15eb13c02a95..7a4d8b3cfd87 100644 --- a/azurerm/data_source_automation_variable_bool.go +++ b/azurerm/internal/services/automation/data_source_automation_variable_bool.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "time" diff --git a/azurerm/data_source_automation_variable_bool_test.go b/azurerm/internal/services/automation/data_source_automation_variable_bool_test.go similarity index 98% rename from azurerm/data_source_automation_variable_bool_test.go rename to azurerm/internal/services/automation/data_source_automation_variable_bool_test.go index b72230047246..50d786fc2cca 100644 --- a/azurerm/data_source_automation_variable_bool_test.go +++ b/azurerm/internal/services/automation/data_source_automation_variable_bool_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/data_source_automation_variable_datetime.go b/azurerm/internal/services/automation/data_source_automation_variable_datetime.go similarity index 96% rename from azurerm/data_source_automation_variable_datetime.go rename to azurerm/internal/services/automation/data_source_automation_variable_datetime.go index d850ecbeac92..ecb2ef72fba6 100644 --- a/azurerm/data_source_automation_variable_datetime.go +++ b/azurerm/internal/services/automation/data_source_automation_variable_datetime.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "time" diff --git a/azurerm/data_source_automation_variable_datetime_test.go b/azurerm/internal/services/automation/data_source_automation_variable_datetime_test.go similarity index 98% rename from azurerm/data_source_automation_variable_datetime_test.go rename to azurerm/internal/services/automation/data_source_automation_variable_datetime_test.go index 6c5b15c2afda..f2aa15df1109 100644 --- a/azurerm/data_source_automation_variable_datetime_test.go +++ b/azurerm/internal/services/automation/data_source_automation_variable_datetime_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/data_source_automation_variable_int.go b/azurerm/internal/services/automation/data_source_automation_variable_int.go similarity index 96% rename from azurerm/data_source_automation_variable_int.go rename to azurerm/internal/services/automation/data_source_automation_variable_int.go index cc394a375be1..a8e1ededd64d 100644 --- a/azurerm/data_source_automation_variable_int.go +++ b/azurerm/internal/services/automation/data_source_automation_variable_int.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "time" diff --git a/azurerm/data_source_automation_variable_int_test.go b/azurerm/internal/services/automation/data_source_automation_variable_int_test.go similarity index 98% rename from azurerm/data_source_automation_variable_int_test.go rename to azurerm/internal/services/automation/data_source_automation_variable_int_test.go index 673462c95cec..137ca7de9ea2 100644 --- a/azurerm/data_source_automation_variable_int_test.go +++ b/azurerm/internal/services/automation/data_source_automation_variable_int_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/data_source_automation_variable_string.go b/azurerm/internal/services/automation/data_source_automation_variable_string.go similarity index 96% rename from azurerm/data_source_automation_variable_string.go rename to azurerm/internal/services/automation/data_source_automation_variable_string.go index 63212feadc64..90a1c78d3ac7 100644 --- a/azurerm/data_source_automation_variable_string.go +++ b/azurerm/internal/services/automation/data_source_automation_variable_string.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "time" diff --git a/azurerm/data_source_automation_variable_string_test.go b/azurerm/internal/services/automation/data_source_automation_variable_string_test.go similarity index 98% rename from azurerm/data_source_automation_variable_string_test.go rename to azurerm/internal/services/automation/data_source_automation_variable_string_test.go index f138ba19ed31..967ca94bc477 100644 --- a/azurerm/data_source_automation_variable_string_test.go +++ b/azurerm/internal/services/automation/data_source_automation_variable_string_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/internal/services/automation/registration.go b/azurerm/internal/services/automation/registration.go index 33595d728252..26bc8d7ddf13 100644 --- a/azurerm/internal/services/automation/registration.go +++ b/azurerm/internal/services/automation/registration.go @@ -13,10 +13,30 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_automation_account": dataSourceArmAutomationAccount(), + "azurerm_automation_variable_bool": dataSourceArmAutomationVariableBool(), + "azurerm_automation_variable_datetime": dataSourceArmAutomationVariableDateTime(), + "azurerm_automation_variable_int": dataSourceArmAutomationVariableInt(), + "azurerm_automation_variable_string": dataSourceArmAutomationVariableString(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_automation_account": resourceArmAutomationAccount(), + "azurerm_automation_certificate": resourceArmAutomationCertificate(), + "azurerm_automation_credential": resourceArmAutomationCredential(), + "azurerm_automation_dsc_configuration": resourceArmAutomationDscConfiguration(), + "azurerm_automation_dsc_nodeconfiguration": resourceArmAutomationDscNodeConfiguration(), + "azurerm_automation_job_schedule": resourceArmAutomationJobSchedule(), + "azurerm_automation_module": resourceArmAutomationModule(), + "azurerm_automation_runbook": resourceArmAutomationRunbook(), + "azurerm_automation_schedule": resourceArmAutomationSchedule(), + "azurerm_automation_variable_bool": resourceArmAutomationVariableBool(), + "azurerm_automation_variable_datetime": resourceArmAutomationVariableDateTime(), + "azurerm_automation_variable_int": resourceArmAutomationVariableInt(), + "azurerm_automation_variable_string": resourceArmAutomationVariableString(), + } } diff --git a/azurerm/resource_arm_automation_account.go b/azurerm/internal/services/automation/resource_arm_automation_account.go similarity index 99% rename from azurerm/resource_arm_automation_account.go rename to azurerm/internal/services/automation/resource_arm_automation_account.go index 7d9346dd2039..bc04ffee144b 100644 --- a/azurerm/resource_arm_automation_account.go +++ b/azurerm/internal/services/automation/resource_arm_automation_account.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_account_test.go b/azurerm/internal/services/automation/resource_arm_automation_account_test.go similarity index 99% rename from azurerm/resource_arm_automation_account_test.go rename to azurerm/internal/services/automation/resource_arm_automation_account_test.go index bd07c25e058a..65d7df7d8e37 100644 --- a/azurerm/resource_arm_automation_account_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_certificate.go b/azurerm/internal/services/automation/resource_arm_automation_certificate.go similarity index 99% rename from azurerm/resource_arm_automation_certificate.go rename to azurerm/internal/services/automation/resource_arm_automation_certificate.go index 59d665c825db..4f0ede91db12 100644 --- a/azurerm/resource_arm_automation_certificate.go +++ b/azurerm/internal/services/automation/resource_arm_automation_certificate.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_certificate_test.go b/azurerm/internal/services/automation/resource_arm_automation_certificate_test.go similarity index 99% rename from azurerm/resource_arm_automation_certificate_test.go rename to azurerm/internal/services/automation/resource_arm_automation_certificate_test.go index fc3ed7170055..9796c4c7a952 100644 --- a/azurerm/resource_arm_automation_certificate_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_certificate_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "encoding/base64" diff --git a/azurerm/resource_arm_automation_credential.go b/azurerm/internal/services/automation/resource_arm_automation_credential.go similarity index 99% rename from azurerm/resource_arm_automation_credential.go rename to azurerm/internal/services/automation/resource_arm_automation_credential.go index 9ae6bc76c699..9e79dfd27ff9 100644 --- a/azurerm/resource_arm_automation_credential.go +++ b/azurerm/internal/services/automation/resource_arm_automation_credential.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_credential_test.go b/azurerm/internal/services/automation/resource_arm_automation_credential_test.go similarity index 99% rename from azurerm/resource_arm_automation_credential_test.go rename to azurerm/internal/services/automation/resource_arm_automation_credential_test.go index 694ce497df80..0ac1307f800b 100644 --- a/azurerm/resource_arm_automation_credential_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_credential_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_dsc_configuration.go b/azurerm/internal/services/automation/resource_arm_automation_dsc_configuration.go similarity index 99% rename from azurerm/resource_arm_automation_dsc_configuration.go rename to azurerm/internal/services/automation/resource_arm_automation_dsc_configuration.go index 46358282ade8..6061c3d94167 100644 --- a/azurerm/resource_arm_automation_dsc_configuration.go +++ b/azurerm/internal/services/automation/resource_arm_automation_dsc_configuration.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "bytes" diff --git a/azurerm/resource_arm_automation_dsc_configuration_test.go b/azurerm/internal/services/automation/resource_arm_automation_dsc_configuration_test.go similarity index 99% rename from azurerm/resource_arm_automation_dsc_configuration_test.go rename to azurerm/internal/services/automation/resource_arm_automation_dsc_configuration_test.go index 931f130f94d6..372173bb7fa5 100644 --- a/azurerm/resource_arm_automation_dsc_configuration_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_dsc_configuration_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_dsc_nodeconfiguration.go b/azurerm/internal/services/automation/resource_arm_automation_dsc_nodeconfiguration.go similarity index 99% rename from azurerm/resource_arm_automation_dsc_nodeconfiguration.go rename to azurerm/internal/services/automation/resource_arm_automation_dsc_nodeconfiguration.go index 0a34bb2b6fe9..d7967caf5100 100644 --- a/azurerm/resource_arm_automation_dsc_nodeconfiguration.go +++ b/azurerm/internal/services/automation/resource_arm_automation_dsc_nodeconfiguration.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_dsc_nodeconfiguration_test.go b/azurerm/internal/services/automation/resource_arm_automation_dsc_nodeconfiguration_test.go similarity index 99% rename from azurerm/resource_arm_automation_dsc_nodeconfiguration_test.go rename to azurerm/internal/services/automation/resource_arm_automation_dsc_nodeconfiguration_test.go index c62625a84930..6e87fe0949ff 100644 --- a/azurerm/resource_arm_automation_dsc_nodeconfiguration_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_dsc_nodeconfiguration_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_job_schedule.go b/azurerm/internal/services/automation/resource_arm_automation_job_schedule.go similarity index 99% rename from azurerm/resource_arm_automation_job_schedule.go rename to azurerm/internal/services/automation/resource_arm_automation_job_schedule.go index 564da8593410..469de5a3e372 100644 --- a/azurerm/resource_arm_automation_job_schedule.go +++ b/azurerm/internal/services/automation/resource_arm_automation_job_schedule.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_job_schedule_test.go b/azurerm/internal/services/automation/resource_arm_automation_job_schedule_test.go similarity index 99% rename from azurerm/resource_arm_automation_job_schedule_test.go rename to azurerm/internal/services/automation/resource_arm_automation_job_schedule_test.go index 117fa9ad074c..d90d2eef3a27 100644 --- a/azurerm/resource_arm_automation_job_schedule_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_job_schedule_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_module.go b/azurerm/internal/services/automation/resource_arm_automation_module.go similarity index 99% rename from azurerm/resource_arm_automation_module.go rename to azurerm/internal/services/automation/resource_arm_automation_module.go index 3dce3896a51d..b1f84eadd1f1 100644 --- a/azurerm/resource_arm_automation_module.go +++ b/azurerm/internal/services/automation/resource_arm_automation_module.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_module_test.go b/azurerm/internal/services/automation/resource_arm_automation_module_test.go similarity index 99% rename from azurerm/resource_arm_automation_module_test.go rename to azurerm/internal/services/automation/resource_arm_automation_module_test.go index aa31b9f8997c..b1f51c7f15b5 100644 --- a/azurerm/resource_arm_automation_module_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_module_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_runbook.go b/azurerm/internal/services/automation/resource_arm_automation_runbook.go similarity index 99% rename from azurerm/resource_arm_automation_runbook.go rename to azurerm/internal/services/automation/resource_arm_automation_runbook.go index 99fb3b1f2d88..25c01f9f48d8 100644 --- a/azurerm/resource_arm_automation_runbook.go +++ b/azurerm/internal/services/automation/resource_arm_automation_runbook.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "bytes" diff --git a/azurerm/resource_arm_automation_runbook_test.go b/azurerm/internal/services/automation/resource_arm_automation_runbook_test.go similarity index 99% rename from azurerm/resource_arm_automation_runbook_test.go rename to azurerm/internal/services/automation/resource_arm_automation_runbook_test.go index 38fe86f22361..9b76f4b26390 100644 --- a/azurerm/resource_arm_automation_runbook_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_runbook_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_schedule.go b/azurerm/internal/services/automation/resource_arm_automation_schedule.go similarity index 99% rename from azurerm/resource_arm_automation_schedule.go rename to azurerm/internal/services/automation/resource_arm_automation_schedule.go index d4ea557e8736..10ba5a3b6c6a 100644 --- a/azurerm/resource_arm_automation_schedule.go +++ b/azurerm/internal/services/automation/resource_arm_automation_schedule.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_schedule_test.go b/azurerm/internal/services/automation/resource_arm_automation_schedule_test.go similarity index 99% rename from azurerm/resource_arm_automation_schedule_test.go rename to azurerm/internal/services/automation/resource_arm_automation_schedule_test.go index e45bdc88315f..facfe47b2156 100644 --- a/azurerm/resource_arm_automation_schedule_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_schedule_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_variable_bool.go b/azurerm/internal/services/automation/resource_arm_automation_variable_bool.go similarity index 98% rename from azurerm/resource_arm_automation_variable_bool.go rename to azurerm/internal/services/automation/resource_arm_automation_variable_bool.go index c9f61a8e8c42..c93a02c16f7b 100644 --- a/azurerm/resource_arm_automation_variable_bool.go +++ b/azurerm/internal/services/automation/resource_arm_automation_variable_bool.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "time" diff --git a/azurerm/resource_arm_automation_variable_bool_test.go b/azurerm/internal/services/automation/resource_arm_automation_variable_bool_test.go similarity index 99% rename from azurerm/resource_arm_automation_variable_bool_test.go rename to azurerm/internal/services/automation/resource_arm_automation_variable_bool_test.go index 53d69219e07f..59e634dc6abc 100644 --- a/azurerm/resource_arm_automation_variable_bool_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_variable_bool_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_variable_datetime.go b/azurerm/internal/services/automation/resource_arm_automation_variable_datetime.go similarity index 98% rename from azurerm/resource_arm_automation_variable_datetime.go rename to azurerm/internal/services/automation/resource_arm_automation_variable_datetime.go index 4440797bd9cc..80b76aca33e6 100644 --- a/azurerm/resource_arm_automation_variable_datetime.go +++ b/azurerm/internal/services/automation/resource_arm_automation_variable_datetime.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "time" diff --git a/azurerm/resource_arm_automation_variable_datetime_test.go b/azurerm/internal/services/automation/resource_arm_automation_variable_datetime_test.go similarity index 99% rename from azurerm/resource_arm_automation_variable_datetime_test.go rename to azurerm/internal/services/automation/resource_arm_automation_variable_datetime_test.go index ad30dbc31873..879afa665c5f 100644 --- a/azurerm/resource_arm_automation_variable_datetime_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_variable_datetime_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_variable_int.go b/azurerm/internal/services/automation/resource_arm_automation_variable_int.go similarity index 98% rename from azurerm/resource_arm_automation_variable_int.go rename to azurerm/internal/services/automation/resource_arm_automation_variable_int.go index f9d7838935f3..3a843dacf7b7 100644 --- a/azurerm/resource_arm_automation_variable_int.go +++ b/azurerm/internal/services/automation/resource_arm_automation_variable_int.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "time" diff --git a/azurerm/resource_arm_automation_variable_int_test.go b/azurerm/internal/services/automation/resource_arm_automation_variable_int_test.go similarity index 99% rename from azurerm/resource_arm_automation_variable_int_test.go rename to azurerm/internal/services/automation/resource_arm_automation_variable_int_test.go index 14f9c2be1187..90878dd6b1ce 100644 --- a/azurerm/resource_arm_automation_variable_int_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_variable_int_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/resource_arm_automation_variable_string.go b/azurerm/internal/services/automation/resource_arm_automation_variable_string.go similarity index 98% rename from azurerm/resource_arm_automation_variable_string.go rename to azurerm/internal/services/automation/resource_arm_automation_variable_string.go index 0b79eec90d91..d1ef937bad57 100644 --- a/azurerm/resource_arm_automation_variable_string.go +++ b/azurerm/internal/services/automation/resource_arm_automation_variable_string.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "time" diff --git a/azurerm/resource_arm_automation_variable_string_test.go b/azurerm/internal/services/automation/resource_arm_automation_variable_string_test.go similarity index 99% rename from azurerm/resource_arm_automation_variable_string_test.go rename to azurerm/internal/services/automation/resource_arm_automation_variable_string_test.go index 470ca280ebf2..3d5d88814b63 100644 --- a/azurerm/resource_arm_automation_variable_string_test.go +++ b/azurerm/internal/services/automation/resource_arm_automation_variable_string_test.go @@ -1,4 +1,4 @@ -package azurerm +package automation import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index d387020d2931..287b56c2613d 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -14,11 +14,6 @@ func Provider() terraform.ResourceProvider { "azurerm_app_service": dataSourceArmAppService(), "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_automation_account": dataSourceArmAutomationAccount(), - "azurerm_automation_variable_bool": dataSourceArmAutomationVariableBool(), - "azurerm_automation_variable_datetime": dataSourceArmAutomationVariableDateTime(), - "azurerm_automation_variable_int": dataSourceArmAutomationVariableInt(), - "azurerm_automation_variable_string": dataSourceArmAutomationVariableString(), "azurerm_availability_set": dataSourceArmAvailabilitySet(), "azurerm_azuread_application": dataSourceArmAzureADApplication(), "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), @@ -124,19 +119,6 @@ func Provider() terraform.ResourceProvider { "azurerm_app_service": resourceArmAppService(), "azurerm_application_gateway": resourceArmApplicationGateway(), "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), - "azurerm_automation_account": resourceArmAutomationAccount(), - "azurerm_automation_certificate": resourceArmAutomationCertificate(), - "azurerm_automation_credential": resourceArmAutomationCredential(), - "azurerm_automation_dsc_configuration": resourceArmAutomationDscConfiguration(), - "azurerm_automation_dsc_nodeconfiguration": resourceArmAutomationDscNodeConfiguration(), - "azurerm_automation_job_schedule": resourceArmAutomationJobSchedule(), - "azurerm_automation_module": resourceArmAutomationModule(), - "azurerm_automation_runbook": resourceArmAutomationRunbook(), - "azurerm_automation_schedule": resourceArmAutomationSchedule(), - "azurerm_automation_variable_bool": resourceArmAutomationVariableBool(), - "azurerm_automation_variable_datetime": resourceArmAutomationVariableDateTime(), - "azurerm_automation_variable_int": resourceArmAutomationVariableInt(), - "azurerm_automation_variable_string": resourceArmAutomationVariableString(), "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), "azurerm_availability_set": resourceArmAvailabilitySet(), "azurerm_azuread_application": resourceArmActiveDirectoryApplication(), From 15753bd317421f61c040a27b7e4e3acdcdecb33b Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 15:34:52 -0800 Subject: [PATCH 011/203] batch --- .../services/batch}/data_source_batch_account.go | 2 +- .../batch}/data_source_batch_account_test.go | 2 +- .../batch}/data_source_batch_certificate.go | 2 +- .../batch}/data_source_batch_certificate_test.go | 2 +- .../services/batch}/data_source_batch_pool.go | 2 +- .../services/batch}/data_source_batch_pool_test.go | 2 +- azurerm/internal/services/batch/registration.go | 13 +++++++++++-- .../services/batch}/resource_arm_batch_account.go | 2 +- .../batch}/resource_arm_batch_account_test.go | 2 +- .../batch}/resource_arm_batch_application.go | 2 +- .../batch}/resource_arm_batch_application_test.go | 2 +- .../batch}/resource_arm_batch_certificate.go | 2 +- .../batch}/resource_arm_batch_certificate_test.go | 2 +- .../services/batch}/resource_arm_batch_pool.go | 2 +- .../services/batch}/resource_arm_batch_pool_test.go | 2 +- azurerm/provider.go | 7 ------- 16 files changed, 25 insertions(+), 23 deletions(-) rename azurerm/{ => internal/services/batch}/data_source_batch_account.go (99%) rename azurerm/{ => internal/services/batch}/data_source_batch_account_test.go (99%) rename azurerm/{ => internal/services/batch}/data_source_batch_certificate.go (99%) rename azurerm/{ => internal/services/batch}/data_source_batch_certificate_test.go (99%) rename azurerm/{ => internal/services/batch}/data_source_batch_pool.go (99%) rename azurerm/{ => internal/services/batch}/data_source_batch_pool_test.go (99%) rename azurerm/{ => internal/services/batch}/resource_arm_batch_account.go (99%) rename azurerm/{ => internal/services/batch}/resource_arm_batch_account_test.go (99%) rename azurerm/{ => internal/services/batch}/resource_arm_batch_application.go (99%) rename azurerm/{ => internal/services/batch}/resource_arm_batch_application_test.go (99%) rename azurerm/{ => internal/services/batch}/resource_arm_batch_certificate.go (99%) rename azurerm/{ => internal/services/batch}/resource_arm_batch_certificate_test.go (99%) rename azurerm/{ => internal/services/batch}/resource_arm_batch_pool.go (99%) rename azurerm/{ => internal/services/batch}/resource_arm_batch_pool_test.go (99%) diff --git a/azurerm/data_source_batch_account.go b/azurerm/internal/services/batch/data_source_batch_account.go similarity index 99% rename from azurerm/data_source_batch_account.go rename to azurerm/internal/services/batch/data_source_batch_account.go index 68ce8b0244ed..016e9f193087 100644 --- a/azurerm/data_source_batch_account.go +++ b/azurerm/internal/services/batch/data_source_batch_account.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/data_source_batch_account_test.go b/azurerm/internal/services/batch/data_source_batch_account_test.go similarity index 99% rename from azurerm/data_source_batch_account_test.go rename to azurerm/internal/services/batch/data_source_batch_account_test.go index a09d4eaee51b..7048fa582f75 100644 --- a/azurerm/data_source_batch_account_test.go +++ b/azurerm/internal/services/batch/data_source_batch_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/data_source_batch_certificate.go b/azurerm/internal/services/batch/data_source_batch_certificate.go similarity index 99% rename from azurerm/data_source_batch_certificate.go rename to azurerm/internal/services/batch/data_source_batch_certificate.go index 6246b96956d3..0bda0eb71435 100644 --- a/azurerm/data_source_batch_certificate.go +++ b/azurerm/internal/services/batch/data_source_batch_certificate.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/data_source_batch_certificate_test.go b/azurerm/internal/services/batch/data_source_batch_certificate_test.go similarity index 99% rename from azurerm/data_source_batch_certificate_test.go rename to azurerm/internal/services/batch/data_source_batch_certificate_test.go index 70361fab40bd..ca4f00f1dee8 100644 --- a/azurerm/data_source_batch_certificate_test.go +++ b/azurerm/internal/services/batch/data_source_batch_certificate_test.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/data_source_batch_pool.go b/azurerm/internal/services/batch/data_source_batch_pool.go similarity index 99% rename from azurerm/data_source_batch_pool.go rename to azurerm/internal/services/batch/data_source_batch_pool.go index b2207252d052..11a64c51ddff 100644 --- a/azurerm/data_source_batch_pool.go +++ b/azurerm/internal/services/batch/data_source_batch_pool.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/data_source_batch_pool_test.go b/azurerm/internal/services/batch/data_source_batch_pool_test.go similarity index 99% rename from azurerm/data_source_batch_pool_test.go rename to azurerm/internal/services/batch/data_source_batch_pool_test.go index b418bb6a9380..417950997faf 100644 --- a/azurerm/data_source_batch_pool_test.go +++ b/azurerm/internal/services/batch/data_source_batch_pool_test.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/internal/services/batch/registration.go b/azurerm/internal/services/batch/registration.go index 30a25b1590a8..d809279924bb 100644 --- a/azurerm/internal/services/batch/registration.go +++ b/azurerm/internal/services/batch/registration.go @@ -13,10 +13,19 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_batch_account": dataSourceArmBatchAccount(), + "azurerm_batch_certificate": dataSourceArmBatchCertificate(), + "azurerm_batch_pool": dataSourceArmBatchPool(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_batch_account": resourceArmBatchAccount(), + "azurerm_batch_application": resourceArmBatchApplication(), + "azurerm_batch_certificate": resourceArmBatchCertificate(), + "azurerm_batch_pool": resourceArmBatchPool(), + } } diff --git a/azurerm/resource_arm_batch_account.go b/azurerm/internal/services/batch/resource_arm_batch_account.go similarity index 99% rename from azurerm/resource_arm_batch_account.go rename to azurerm/internal/services/batch/resource_arm_batch_account.go index 38921f855bb0..46f437a3c8b9 100644 --- a/azurerm/resource_arm_batch_account.go +++ b/azurerm/internal/services/batch/resource_arm_batch_account.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/resource_arm_batch_account_test.go b/azurerm/internal/services/batch/resource_arm_batch_account_test.go similarity index 99% rename from azurerm/resource_arm_batch_account_test.go rename to azurerm/internal/services/batch/resource_arm_batch_account_test.go index 22efee76879d..3aa1b96873ff 100644 --- a/azurerm/resource_arm_batch_account_test.go +++ b/azurerm/internal/services/batch/resource_arm_batch_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/resource_arm_batch_application.go b/azurerm/internal/services/batch/resource_arm_batch_application.go similarity index 99% rename from azurerm/resource_arm_batch_application.go rename to azurerm/internal/services/batch/resource_arm_batch_application.go index 12cf55537ce0..5b29b32e927a 100644 --- a/azurerm/resource_arm_batch_application.go +++ b/azurerm/internal/services/batch/resource_arm_batch_application.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/resource_arm_batch_application_test.go b/azurerm/internal/services/batch/resource_arm_batch_application_test.go similarity index 99% rename from azurerm/resource_arm_batch_application_test.go rename to azurerm/internal/services/batch/resource_arm_batch_application_test.go index 54fc4c99fb93..e845d74cfaf8 100644 --- a/azurerm/resource_arm_batch_application_test.go +++ b/azurerm/internal/services/batch/resource_arm_batch_application_test.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/resource_arm_batch_certificate.go b/azurerm/internal/services/batch/resource_arm_batch_certificate.go similarity index 99% rename from azurerm/resource_arm_batch_certificate.go rename to azurerm/internal/services/batch/resource_arm_batch_certificate.go index d5b8d9ef4ab0..43629793dafe 100644 --- a/azurerm/resource_arm_batch_certificate.go +++ b/azurerm/internal/services/batch/resource_arm_batch_certificate.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/resource_arm_batch_certificate_test.go b/azurerm/internal/services/batch/resource_arm_batch_certificate_test.go similarity index 99% rename from azurerm/resource_arm_batch_certificate_test.go rename to azurerm/internal/services/batch/resource_arm_batch_certificate_test.go index bc36c0ca94ed..2124c6a1dcee 100644 --- a/azurerm/resource_arm_batch_certificate_test.go +++ b/azurerm/internal/services/batch/resource_arm_batch_certificate_test.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/resource_arm_batch_pool.go b/azurerm/internal/services/batch/resource_arm_batch_pool.go similarity index 99% rename from azurerm/resource_arm_batch_pool.go rename to azurerm/internal/services/batch/resource_arm_batch_pool.go index 1b4f139ed769..45e4d40213c9 100644 --- a/azurerm/resource_arm_batch_pool.go +++ b/azurerm/internal/services/batch/resource_arm_batch_pool.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "context" diff --git a/azurerm/resource_arm_batch_pool_test.go b/azurerm/internal/services/batch/resource_arm_batch_pool_test.go similarity index 99% rename from azurerm/resource_arm_batch_pool_test.go rename to azurerm/internal/services/batch/resource_arm_batch_pool_test.go index fbca4dc2da81..15bb90a9ae3e 100644 --- a/azurerm/resource_arm_batch_pool_test.go +++ b/azurerm/internal/services/batch/resource_arm_batch_pool_test.go @@ -1,4 +1,4 @@ -package azurerm +package batch import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 287b56c2613d..86da2908a6f6 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -17,9 +17,6 @@ func Provider() terraform.ResourceProvider { "azurerm_availability_set": dataSourceArmAvailabilitySet(), "azurerm_azuread_application": dataSourceArmAzureADApplication(), "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), - "azurerm_batch_account": dataSourceArmBatchAccount(), - "azurerm_batch_certificate": dataSourceArmBatchCertificate(), - "azurerm_batch_pool": dataSourceArmBatchPool(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_cdn_profile": dataSourceArmCdnProfile(), "azurerm_client_config": dataSourceArmClientConfig(), @@ -130,16 +127,12 @@ func Provider() terraform.ResourceProvider { "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_batch_account": resourceArmBatchAccount(), - "azurerm_batch_application": resourceArmBatchApplication(), - "azurerm_batch_certificate": resourceArmBatchCertificate(), "azurerm_bot_channel_email": resourceArmBotChannelEmail(), "azurerm_bot_channel_slack": resourceArmBotChannelSlack(), "azurerm_bot_channel_ms_teams": resourceArmBotChannelMsTeams(), "azurerm_bot_channels_registration": resourceArmBotChannelsRegistration(), "azurerm_bot_connection": resourceArmBotConnection(), "azurerm_bot_web_app": resourceArmBotWebApp(), - "azurerm_batch_pool": resourceArmBatchPool(), "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), "azurerm_cdn_profile": resourceArmCdnProfile(), "azurerm_cognitive_account": resourceArmCognitiveAccount(), From b93df7cbe5ac8a7efe96c3d70d1a76e47ecffc03 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 15:37:49 -0800 Subject: [PATCH 012/203] bot --- azurerm/internal/services/bot/registration.go | 9 ++++++++- .../services/bot}/resource_arm_bot_channel_email.go | 2 +- .../services/bot}/resource_arm_bot_channel_email_test.go | 2 +- .../services/bot}/resource_arm_bot_channel_ms_teams.go | 2 +- .../bot}/resource_arm_bot_channel_ms_teams_test.go | 2 +- .../services/bot}/resource_arm_bot_channel_slack.go | 2 +- .../services/bot}/resource_arm_bot_channel_slack_test.go | 2 +- .../bot}/resource_arm_bot_channels_registration.go | 2 +- .../bot}/resource_arm_bot_channels_registration_test.go | 2 +- .../services/bot}/resource_arm_bot_connection.go | 2 +- .../services/bot}/resource_arm_bot_connection_test.go | 2 +- .../services/bot}/resource_arm_bot_web_app.go | 2 +- .../services/bot}/resource_arm_bot_web_app_test.go | 2 +- azurerm/provider.go | 6 ------ 14 files changed, 20 insertions(+), 19 deletions(-) rename azurerm/{ => internal/services/bot}/resource_arm_bot_channel_email.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_channel_email_test.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_channel_ms_teams.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_channel_ms_teams_test.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_channel_slack.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_channel_slack_test.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_channels_registration.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_channels_registration_test.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_connection.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_connection_test.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_web_app.go (99%) rename azurerm/{ => internal/services/bot}/resource_arm_bot_web_app_test.go (99%) diff --git a/azurerm/internal/services/bot/registration.go b/azurerm/internal/services/bot/registration.go index 07e31689c526..a0eadf437cad 100644 --- a/azurerm/internal/services/bot/registration.go +++ b/azurerm/internal/services/bot/registration.go @@ -18,5 +18,12 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_bot_channel_email": resourceArmBotChannelEmail(), + "azurerm_bot_channel_slack": resourceArmBotChannelSlack(), + "azurerm_bot_channel_ms_teams": resourceArmBotChannelMsTeams(), + "azurerm_bot_channels_registration": resourceArmBotChannelsRegistration(), + "azurerm_bot_connection": resourceArmBotConnection(), + "azurerm_bot_web_app": resourceArmBotWebApp(), + } } diff --git a/azurerm/resource_arm_bot_channel_email.go b/azurerm/internal/services/bot/resource_arm_bot_channel_email.go similarity index 99% rename from azurerm/resource_arm_bot_channel_email.go rename to azurerm/internal/services/bot/resource_arm_bot_channel_email.go index ca15eada7164..bdb492fed33b 100644 --- a/azurerm/resource_arm_bot_channel_email.go +++ b/azurerm/internal/services/bot/resource_arm_bot_channel_email.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_channel_email_test.go b/azurerm/internal/services/bot/resource_arm_bot_channel_email_test.go similarity index 99% rename from azurerm/resource_arm_bot_channel_email_test.go rename to azurerm/internal/services/bot/resource_arm_bot_channel_email_test.go index a93c7a4be9bf..1b581bd496cf 100644 --- a/azurerm/resource_arm_bot_channel_email_test.go +++ b/azurerm/internal/services/bot/resource_arm_bot_channel_email_test.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_channel_ms_teams.go b/azurerm/internal/services/bot/resource_arm_bot_channel_ms_teams.go similarity index 99% rename from azurerm/resource_arm_bot_channel_ms_teams.go rename to azurerm/internal/services/bot/resource_arm_bot_channel_ms_teams.go index d5e771d34509..99560ca49662 100644 --- a/azurerm/resource_arm_bot_channel_ms_teams.go +++ b/azurerm/internal/services/bot/resource_arm_bot_channel_ms_teams.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_channel_ms_teams_test.go b/azurerm/internal/services/bot/resource_arm_bot_channel_ms_teams_test.go similarity index 99% rename from azurerm/resource_arm_bot_channel_ms_teams_test.go rename to azurerm/internal/services/bot/resource_arm_bot_channel_ms_teams_test.go index cea5d51726ad..86f8ba565513 100644 --- a/azurerm/resource_arm_bot_channel_ms_teams_test.go +++ b/azurerm/internal/services/bot/resource_arm_bot_channel_ms_teams_test.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_channel_slack.go b/azurerm/internal/services/bot/resource_arm_bot_channel_slack.go similarity index 99% rename from azurerm/resource_arm_bot_channel_slack.go rename to azurerm/internal/services/bot/resource_arm_bot_channel_slack.go index 8e09b8c0370e..7209d7b23652 100644 --- a/azurerm/resource_arm_bot_channel_slack.go +++ b/azurerm/internal/services/bot/resource_arm_bot_channel_slack.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_channel_slack_test.go b/azurerm/internal/services/bot/resource_arm_bot_channel_slack_test.go similarity index 99% rename from azurerm/resource_arm_bot_channel_slack_test.go rename to azurerm/internal/services/bot/resource_arm_bot_channel_slack_test.go index 0d0b90269224..96ccefdfcd25 100644 --- a/azurerm/resource_arm_bot_channel_slack_test.go +++ b/azurerm/internal/services/bot/resource_arm_bot_channel_slack_test.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_channels_registration.go b/azurerm/internal/services/bot/resource_arm_bot_channels_registration.go similarity index 99% rename from azurerm/resource_arm_bot_channels_registration.go rename to azurerm/internal/services/bot/resource_arm_bot_channels_registration.go index 962bdfe96fa2..f4250e169a4b 100644 --- a/azurerm/resource_arm_bot_channels_registration.go +++ b/azurerm/internal/services/bot/resource_arm_bot_channels_registration.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_channels_registration_test.go b/azurerm/internal/services/bot/resource_arm_bot_channels_registration_test.go similarity index 99% rename from azurerm/resource_arm_bot_channels_registration_test.go rename to azurerm/internal/services/bot/resource_arm_bot_channels_registration_test.go index 459b80d2d66d..85465bb843b0 100644 --- a/azurerm/resource_arm_bot_channels_registration_test.go +++ b/azurerm/internal/services/bot/resource_arm_bot_channels_registration_test.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_connection.go b/azurerm/internal/services/bot/resource_arm_bot_connection.go similarity index 99% rename from azurerm/resource_arm_bot_connection.go rename to azurerm/internal/services/bot/resource_arm_bot_connection.go index 80d0e7c0a431..681d0ae94636 100644 --- a/azurerm/resource_arm_bot_connection.go +++ b/azurerm/internal/services/bot/resource_arm_bot_connection.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_connection_test.go b/azurerm/internal/services/bot/resource_arm_bot_connection_test.go similarity index 99% rename from azurerm/resource_arm_bot_connection_test.go rename to azurerm/internal/services/bot/resource_arm_bot_connection_test.go index bc346de92302..2f206140ec26 100644 --- a/azurerm/resource_arm_bot_connection_test.go +++ b/azurerm/internal/services/bot/resource_arm_bot_connection_test.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_web_app.go b/azurerm/internal/services/bot/resource_arm_bot_web_app.go similarity index 99% rename from azurerm/resource_arm_bot_web_app.go rename to azurerm/internal/services/bot/resource_arm_bot_web_app.go index ec8e9991e398..f70d10ebd1fa 100644 --- a/azurerm/resource_arm_bot_web_app.go +++ b/azurerm/internal/services/bot/resource_arm_bot_web_app.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/resource_arm_bot_web_app_test.go b/azurerm/internal/services/bot/resource_arm_bot_web_app_test.go similarity index 99% rename from azurerm/resource_arm_bot_web_app_test.go rename to azurerm/internal/services/bot/resource_arm_bot_web_app_test.go index 9a80180c2731..c21439414bf5 100644 --- a/azurerm/resource_arm_bot_web_app_test.go +++ b/azurerm/internal/services/bot/resource_arm_bot_web_app_test.go @@ -1,4 +1,4 @@ -package azurerm +package bot import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 86da2908a6f6..288e69cf0c13 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -127,12 +127,6 @@ func Provider() terraform.ResourceProvider { "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_bot_channel_email": resourceArmBotChannelEmail(), - "azurerm_bot_channel_slack": resourceArmBotChannelSlack(), - "azurerm_bot_channel_ms_teams": resourceArmBotChannelMsTeams(), - "azurerm_bot_channels_registration": resourceArmBotChannelsRegistration(), - "azurerm_bot_connection": resourceArmBotConnection(), - "azurerm_bot_web_app": resourceArmBotWebApp(), "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), "azurerm_cdn_profile": resourceArmCdnProfile(), "azurerm_cognitive_account": resourceArmCognitiveAccount(), From 2611c08641eca358f45a0b1b977298b733b8752e Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 15:41:13 -0800 Subject: [PATCH 013/203] cdn --- .../services/cdn}/data_source_cdn_profile.go | 2 +- .../services/cdn}/data_source_cdn_profile_test.go | 11 ++++++----- azurerm/internal/services/cdn/registration.go | 9 +++++++-- .../services/cdn}/resource_arm_cdn_endpoint.go | 2 +- .../services/cdn}/resource_arm_cdn_endpoint_test.go | 2 +- .../services/cdn}/resource_arm_cdn_profile.go | 2 +- .../services/cdn}/resource_arm_cdn_profile_test.go | 2 +- azurerm/provider.go | 3 --- 8 files changed, 18 insertions(+), 15 deletions(-) rename azurerm/{ => internal/services/cdn}/data_source_cdn_profile.go (99%) rename azurerm/{ => internal/services/cdn}/data_source_cdn_profile_test.go (89%) rename azurerm/{ => internal/services/cdn}/resource_arm_cdn_endpoint.go (99%) rename azurerm/{ => internal/services/cdn}/resource_arm_cdn_endpoint_test.go (99%) rename azurerm/{ => internal/services/cdn}/resource_arm_cdn_profile.go (99%) rename azurerm/{ => internal/services/cdn}/resource_arm_cdn_profile_test.go (99%) diff --git a/azurerm/data_source_cdn_profile.go b/azurerm/internal/services/cdn/data_source_cdn_profile.go similarity index 99% rename from azurerm/data_source_cdn_profile.go rename to azurerm/internal/services/cdn/data_source_cdn_profile.go index e318362f41a9..1607cf9ac854 100644 --- a/azurerm/data_source_cdn_profile.go +++ b/azurerm/internal/services/cdn/data_source_cdn_profile.go @@ -1,4 +1,4 @@ -package azurerm +package cdn import ( "fmt" diff --git a/azurerm/data_source_cdn_profile_test.go b/azurerm/internal/services/cdn/data_source_cdn_profile_test.go similarity index 89% rename from azurerm/data_source_cdn_profile_test.go rename to azurerm/internal/services/cdn/data_source_cdn_profile_test.go index 4409257aec18..514e52be9d53 100644 --- a/azurerm/data_source_cdn_profile_test.go +++ b/azurerm/internal/services/cdn/data_source_cdn_profile_test.go @@ -1,7 +1,8 @@ -package azurerm +package cdn import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -17,12 +18,12 @@ func TestAccDataSourceAzureRMCdnProfile_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCdnProfileDestroy, + CheckDestroy: azurerm.testCheckAzureRMCdnProfileDestroy, Steps: []resource.TestStep{ { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists("data.azurerm_cdn_profile.test"), + azurerm.testCheckAzureRMCdnProfileExists("data.azurerm_cdn_profile.test"), ), }, }, @@ -38,12 +39,12 @@ func TestAccDataSourceAzureRMCdnProfile_withTags(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCdnProfileDestroy, + CheckDestroy: azurerm.testCheckAzureRMCdnProfileDestroy, Steps: []resource.TestStep{ { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists(resourceName), + azurerm.testCheckAzureRMCdnProfileExists(resourceName), resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), diff --git a/azurerm/internal/services/cdn/registration.go b/azurerm/internal/services/cdn/registration.go index cb5a9b68a4fb..eca44985f086 100644 --- a/azurerm/internal/services/cdn/registration.go +++ b/azurerm/internal/services/cdn/registration.go @@ -13,10 +13,15 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_cdn_profile": dataSourceArmCdnProfile(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), + "azurerm_cdn_profile": resourceArmCdnProfile(), + } } diff --git a/azurerm/resource_arm_cdn_endpoint.go b/azurerm/internal/services/cdn/resource_arm_cdn_endpoint.go similarity index 99% rename from azurerm/resource_arm_cdn_endpoint.go rename to azurerm/internal/services/cdn/resource_arm_cdn_endpoint.go index 4e20847b64b4..5b51f6b6114e 100644 --- a/azurerm/resource_arm_cdn_endpoint.go +++ b/azurerm/internal/services/cdn/resource_arm_cdn_endpoint.go @@ -1,4 +1,4 @@ -package azurerm +package cdn import ( "fmt" diff --git a/azurerm/resource_arm_cdn_endpoint_test.go b/azurerm/internal/services/cdn/resource_arm_cdn_endpoint_test.go similarity index 99% rename from azurerm/resource_arm_cdn_endpoint_test.go rename to azurerm/internal/services/cdn/resource_arm_cdn_endpoint_test.go index b5a850b09934..9c3b089ca613 100644 --- a/azurerm/resource_arm_cdn_endpoint_test.go +++ b/azurerm/internal/services/cdn/resource_arm_cdn_endpoint_test.go @@ -1,4 +1,4 @@ -package azurerm +package cdn import ( "fmt" diff --git a/azurerm/resource_arm_cdn_profile.go b/azurerm/internal/services/cdn/resource_arm_cdn_profile.go similarity index 99% rename from azurerm/resource_arm_cdn_profile.go rename to azurerm/internal/services/cdn/resource_arm_cdn_profile.go index 7b619010ffe9..6b602dcfbf64 100644 --- a/azurerm/resource_arm_cdn_profile.go +++ b/azurerm/internal/services/cdn/resource_arm_cdn_profile.go @@ -1,4 +1,4 @@ -package azurerm +package cdn import ( "fmt" diff --git a/azurerm/resource_arm_cdn_profile_test.go b/azurerm/internal/services/cdn/resource_arm_cdn_profile_test.go similarity index 99% rename from azurerm/resource_arm_cdn_profile_test.go rename to azurerm/internal/services/cdn/resource_arm_cdn_profile_test.go index 63ea9bd24a8b..ddea386b1c14 100644 --- a/azurerm/resource_arm_cdn_profile_test.go +++ b/azurerm/internal/services/cdn/resource_arm_cdn_profile_test.go @@ -1,4 +1,4 @@ -package azurerm +package cdn import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 288e69cf0c13..c1a5b4c34631 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -18,7 +18,6 @@ func Provider() terraform.ResourceProvider { "azurerm_azuread_application": dataSourceArmAzureADApplication(), "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_cdn_profile": dataSourceArmCdnProfile(), "azurerm_client_config": dataSourceArmClientConfig(), "azurerm_kubernetes_service_versions": dataSourceArmKubernetesServiceVersions(), "azurerm_container_registry": dataSourceArmContainerRegistry(), @@ -127,8 +126,6 @@ func Provider() terraform.ResourceProvider { "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_cdn_endpoint": resourceArmCdnEndpoint(), - "azurerm_cdn_profile": resourceArmCdnProfile(), "azurerm_cognitive_account": resourceArmCognitiveAccount(), "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_container_group": resourceArmContainerGroup(), From d912e25dcfcb5cc855f27175039bf2085715f9b0 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 15:45:19 -0800 Subject: [PATCH 014/203] cognitive --- azurerm/internal/services/cognitive/registration.go | 4 +++- .../services/cognitive}/resource_arm_cognitive_account.go | 2 +- .../cognitive}/resource_arm_cognitive_account_test.go | 2 +- azurerm/provider.go | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) rename azurerm/{ => internal/services/cognitive}/resource_arm_cognitive_account.go (99%) rename azurerm/{ => internal/services/cognitive}/resource_arm_cognitive_account_test.go (99%) diff --git a/azurerm/internal/services/cognitive/registration.go b/azurerm/internal/services/cognitive/registration.go index 75828a5487b8..c21c58384d65 100644 --- a/azurerm/internal/services/cognitive/registration.go +++ b/azurerm/internal/services/cognitive/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_cognitive_account": resourceArmCognitiveAccount(), + } } diff --git a/azurerm/resource_arm_cognitive_account.go b/azurerm/internal/services/cognitive/resource_arm_cognitive_account.go similarity index 99% rename from azurerm/resource_arm_cognitive_account.go rename to azurerm/internal/services/cognitive/resource_arm_cognitive_account.go index 76986d235158..44eb1950f9d8 100644 --- a/azurerm/resource_arm_cognitive_account.go +++ b/azurerm/internal/services/cognitive/resource_arm_cognitive_account.go @@ -1,4 +1,4 @@ -package azurerm +package cognitive import ( "fmt" diff --git a/azurerm/resource_arm_cognitive_account_test.go b/azurerm/internal/services/cognitive/resource_arm_cognitive_account_test.go similarity index 99% rename from azurerm/resource_arm_cognitive_account_test.go rename to azurerm/internal/services/cognitive/resource_arm_cognitive_account_test.go index 2e5adcfbb10a..5820cc754295 100644 --- a/azurerm/resource_arm_cognitive_account_test.go +++ b/azurerm/internal/services/cognitive/resource_arm_cognitive_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package cognitive import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index c1a5b4c34631..958db7a8c1f4 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -126,7 +126,6 @@ func Provider() terraform.ResourceProvider { "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_cognitive_account": resourceArmCognitiveAccount(), "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_container_group": resourceArmContainerGroup(), "azurerm_container_registry_webhook": resourceArmContainerRegistryWebhook(), From 826ceb2926fdf49f507dee9fcd4a38ad7b7d0103 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:14:05 -0800 Subject: [PATCH 015/203] compute --- .../compute}/data_source_availability_set.go | 2 +- .../data_source_availability_set_test.go | 2 +- .../compute}/data_source_managed_disk.go | 2 +- .../compute}/data_source_managed_disk_test.go | 2 +- .../compute}/data_source_shared_image.go | 2 +- .../data_source_shared_image_gallery.go | 2 +- .../data_source_shared_image_gallery_test.go | 2 +- .../compute}/data_source_shared_image_test.go | 2 +- .../data_source_shared_image_version.go | 2 +- .../data_source_shared_image_version_test.go | 2 +- .../services/compute}/data_source_snapshot.go | 2 +- .../compute}/data_source_snapshot_test.go | 2 +- .../services/compute}/encryption_settings.go | 2 +- .../internal/services/compute/registration.go | 29 ++++- .../compute}/resource_arm_availability_set.go | 2 +- .../resource_arm_availability_set_test.go | 2 +- ...rce_arm_linux_virtual_machine_scale_set.go | 101 +++++++++--------- ...nux_virtual_machine_scale_set_auth_test.go | 2 +- ...irtual_machine_scale_set_disk_data_test.go | 2 +- ..._virtual_machine_scale_set_disk_os_test.go | 2 +- ...virtual_machine_scale_set_identity_test.go | 2 +- ...x_virtual_machine_scale_set_images_test.go | 2 +- ..._virtual_machine_scale_set_network_test.go | 2 +- ...ux_virtual_machine_scale_set_other_test.go | 2 +- ..._virtual_machine_scale_set_scaling_test.go | 2 +- ...rm_linux_virtual_machine_scale_set_test.go | 2 +- .../compute}/resource_arm_managed_disk.go | 2 +- .../resource_arm_managed_disk_test.go | 6 +- .../compute}/resource_arm_snapshot.go | 2 +- .../compute}/resource_arm_snapshot_test.go | 2 +- .../compute}/resource_arm_virtual_machine.go | 2 +- ...rm_virtual_machine_data_disk_attachment.go | 2 +- ...rtual_machine_data_disk_attachment_test.go | 2 +- .../resource_arm_virtual_machine_extension.go | 2 +- ...urce_arm_virtual_machine_extension_test.go | 2 +- ..._arm_virtual_machine_managed_disks_test.go | 2 +- .../resource_arm_virtual_machine_scale_set.go | 2 +- ...arm_virtual_machine_scale_set_extension.go | 15 ++- ...irtual_machine_scale_set_extension_test.go | 3 +- ...arm_virtual_machine_scale_set_migration.go | 2 +- ...urce_arm_virtual_machine_scale_set_test.go | 4 +- .../resource_arm_virtual_machine_test.go | 2 +- ...rm_virtual_machine_unmanaged_disks_test.go | 2 +- ...e_arm_windows_virtual_machine_scale_set.go | 93 ++++++++-------- ...ows_virtual_machine_scale_set_auth_test.go | 2 +- ...irtual_machine_scale_set_disk_data_test.go | 2 +- ..._virtual_machine_scale_set_disk_os_test.go | 2 +- ...virtual_machine_scale_set_identity_test.go | 2 +- ...s_virtual_machine_scale_set_images_test.go | 2 +- ..._virtual_machine_scale_set_network_test.go | 2 +- ...ws_virtual_machine_scale_set_other_test.go | 2 +- ..._virtual_machine_scale_set_scaling_test.go | 2 +- ..._windows_virtual_machine_scale_set_test.go | 2 +- azurerm/provider.go | 21 ---- azurerm/resource_arm_metric_alertrule_test.go | 3 +- ...ource_arm_monitor_metric_alertrule_test.go | 3 +- 56 files changed, 186 insertions(+), 184 deletions(-) rename azurerm/{ => internal/services/compute}/data_source_availability_set.go (99%) rename azurerm/{ => internal/services/compute}/data_source_availability_set_test.go (99%) rename azurerm/{ => internal/services/compute}/data_source_managed_disk.go (99%) rename azurerm/{ => internal/services/compute}/data_source_managed_disk_test.go (99%) rename azurerm/{ => internal/services/compute}/data_source_shared_image.go (99%) rename azurerm/{ => internal/services/compute}/data_source_shared_image_gallery.go (99%) rename azurerm/{ => internal/services/compute}/data_source_shared_image_gallery_test.go (99%) rename azurerm/{ => internal/services/compute}/data_source_shared_image_test.go (99%) rename azurerm/{ => internal/services/compute}/data_source_shared_image_version.go (99%) rename azurerm/{ => internal/services/compute}/data_source_shared_image_version_test.go (99%) rename azurerm/{ => internal/services/compute}/data_source_snapshot.go (99%) rename azurerm/{ => internal/services/compute}/data_source_snapshot_test.go (99%) rename azurerm/{ => internal/services/compute}/encryption_settings.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_availability_set.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_availability_set_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_linux_virtual_machine_scale_set.go (88%) rename azurerm/{ => internal/services/compute}/resource_arm_linux_virtual_machine_scale_set_auth_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_linux_virtual_machine_scale_set_identity_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_linux_virtual_machine_scale_set_images_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_linux_virtual_machine_scale_set_network_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_linux_virtual_machine_scale_set_other_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_linux_virtual_machine_scale_set_scaling_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_linux_virtual_machine_scale_set_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_managed_disk.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_managed_disk_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_snapshot.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_snapshot_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_data_disk_attachment.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_data_disk_attachment_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_extension.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_extension_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_managed_disks_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_scale_set.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_scale_set_extension.go (95%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_scale_set_extension_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_scale_set_migration.go (98%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_scale_set_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_virtual_machine_unmanaged_disks_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_windows_virtual_machine_scale_set.go (90%) rename azurerm/{ => internal/services/compute}/resource_arm_windows_virtual_machine_scale_set_auth_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_windows_virtual_machine_scale_set_identity_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_windows_virtual_machine_scale_set_images_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_windows_virtual_machine_scale_set_network_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_windows_virtual_machine_scale_set_other_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_windows_virtual_machine_scale_set_scaling_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_windows_virtual_machine_scale_set_test.go (99%) diff --git a/azurerm/data_source_availability_set.go b/azurerm/internal/services/compute/data_source_availability_set.go similarity index 99% rename from azurerm/data_source_availability_set.go rename to azurerm/internal/services/compute/data_source_availability_set.go index 3b1e6bc66770..48c712db80af 100644 --- a/azurerm/data_source_availability_set.go +++ b/azurerm/internal/services/compute/data_source_availability_set.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_availability_set_test.go b/azurerm/internal/services/compute/data_source_availability_set_test.go similarity index 99% rename from azurerm/data_source_availability_set_test.go rename to azurerm/internal/services/compute/data_source_availability_set_test.go index 90ae261500dd..2e35be08c95c 100644 --- a/azurerm/data_source_availability_set_test.go +++ b/azurerm/internal/services/compute/data_source_availability_set_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_managed_disk.go b/azurerm/internal/services/compute/data_source_managed_disk.go similarity index 99% rename from azurerm/data_source_managed_disk.go rename to azurerm/internal/services/compute/data_source_managed_disk.go index 048b1bd1cadc..bf3d6ff3aedb 100644 --- a/azurerm/data_source_managed_disk.go +++ b/azurerm/internal/services/compute/data_source_managed_disk.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_managed_disk_test.go b/azurerm/internal/services/compute/data_source_managed_disk_test.go similarity index 99% rename from azurerm/data_source_managed_disk_test.go rename to azurerm/internal/services/compute/data_source_managed_disk_test.go index 329565cdeaa4..cafd141e878d 100644 --- a/azurerm/data_source_managed_disk_test.go +++ b/azurerm/internal/services/compute/data_source_managed_disk_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_shared_image.go b/azurerm/internal/services/compute/data_source_shared_image.go similarity index 99% rename from azurerm/data_source_shared_image.go rename to azurerm/internal/services/compute/data_source_shared_image.go index f9c8ad0c3acf..633c5e6d46db 100644 --- a/azurerm/data_source_shared_image.go +++ b/azurerm/internal/services/compute/data_source_shared_image.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_shared_image_gallery.go b/azurerm/internal/services/compute/data_source_shared_image_gallery.go similarity index 99% rename from azurerm/data_source_shared_image_gallery.go rename to azurerm/internal/services/compute/data_source_shared_image_gallery.go index 1e0ea1e68a01..81e62f27b5e2 100644 --- a/azurerm/data_source_shared_image_gallery.go +++ b/azurerm/internal/services/compute/data_source_shared_image_gallery.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_shared_image_gallery_test.go b/azurerm/internal/services/compute/data_source_shared_image_gallery_test.go similarity index 99% rename from azurerm/data_source_shared_image_gallery_test.go rename to azurerm/internal/services/compute/data_source_shared_image_gallery_test.go index 8c62a3da8277..f9e54b988e14 100644 --- a/azurerm/data_source_shared_image_gallery_test.go +++ b/azurerm/internal/services/compute/data_source_shared_image_gallery_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_shared_image_test.go b/azurerm/internal/services/compute/data_source_shared_image_test.go similarity index 99% rename from azurerm/data_source_shared_image_test.go rename to azurerm/internal/services/compute/data_source_shared_image_test.go index ef06cc85b1fe..86959c898e16 100644 --- a/azurerm/data_source_shared_image_test.go +++ b/azurerm/internal/services/compute/data_source_shared_image_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_shared_image_version.go b/azurerm/internal/services/compute/data_source_shared_image_version.go similarity index 99% rename from azurerm/data_source_shared_image_version.go rename to azurerm/internal/services/compute/data_source_shared_image_version.go index f68f4cedf889..57aefc02a18e 100644 --- a/azurerm/data_source_shared_image_version.go +++ b/azurerm/internal/services/compute/data_source_shared_image_version.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_shared_image_version_test.go b/azurerm/internal/services/compute/data_source_shared_image_version_test.go similarity index 99% rename from azurerm/data_source_shared_image_version_test.go rename to azurerm/internal/services/compute/data_source_shared_image_version_test.go index 8f5312513c19..ce0212dc8998 100644 --- a/azurerm/data_source_shared_image_version_test.go +++ b/azurerm/internal/services/compute/data_source_shared_image_version_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_snapshot.go b/azurerm/internal/services/compute/data_source_snapshot.go similarity index 99% rename from azurerm/data_source_snapshot.go rename to azurerm/internal/services/compute/data_source_snapshot.go index 662140525dcb..0a99ed611d37 100644 --- a/azurerm/data_source_snapshot.go +++ b/azurerm/internal/services/compute/data_source_snapshot.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_snapshot_test.go b/azurerm/internal/services/compute/data_source_snapshot_test.go similarity index 99% rename from azurerm/data_source_snapshot_test.go rename to azurerm/internal/services/compute/data_source_snapshot_test.go index 1c32033ca795..97b169392772 100644 --- a/azurerm/data_source_snapshot_test.go +++ b/azurerm/internal/services/compute/data_source_snapshot_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/encryption_settings.go b/azurerm/internal/services/compute/encryption_settings.go similarity index 99% rename from azurerm/encryption_settings.go rename to azurerm/internal/services/compute/encryption_settings.go index 71fb057b7fda..df3dbc3a7542 100644 --- a/azurerm/encryption_settings.go +++ b/azurerm/internal/services/compute/encryption_settings.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" diff --git a/azurerm/internal/services/compute/registration.go b/azurerm/internal/services/compute/registration.go index 89613dc1793c..a87acf3aa145 100644 --- a/azurerm/internal/services/compute/registration.go +++ b/azurerm/internal/services/compute/registration.go @@ -2,6 +2,7 @@ package compute import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) type Registration struct{} @@ -13,10 +14,34 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_availability_set": dataSourceArmAvailabilitySet(), + "azurerm_managed_disk": dataSourceArmManagedDisk(), + "azurerm_shared_image_gallery": dataSourceArmSharedImageGallery(), + "azurerm_shared_image_version": dataSourceArmSharedImageVersion(), + "azurerm_shared_image": dataSourceArmSharedImage(), + "azurerm_snapshot": dataSourceArmSnapshot(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + resources := map[string]*schema.Resource{ + "azurerm_availability_set": resourceArmAvailabilitySet(), + "azurerm_managed_disk": resourceArmManagedDisk(), + "azurerm_snapshot": resourceArmSnapshot(), + "azurerm_virtual_machine_data_disk_attachment": resourceArmVirtualMachineDataDiskAttachment(), + "azurerm_virtual_machine_extension": resourceArmVirtualMachineExtensions(), + "azurerm_virtual_machine_scale_set": resourceArmVirtualMachineScaleSet(), + "azurerm_virtual_machine": resourceArmVirtualMachine(), + } + + // 2.0 resources + if features.SupportsTwoPointZeroResources() { + resources["azurerm_linux_virtual_machine_scale_set"] = resourceArmLinuxVirtualMachineScaleSet() + resources["azurerm_virtual_machine_scale_set_extension"] = resourceArmVirtualMachineScaleSetExtension() + resources["azurerm_windows_virtual_machine_scale_set"] = resourceArmWindowsVirtualMachineScaleSet() + } + + return resources } diff --git a/azurerm/resource_arm_availability_set.go b/azurerm/internal/services/compute/resource_arm_availability_set.go similarity index 99% rename from azurerm/resource_arm_availability_set.go rename to azurerm/internal/services/compute/resource_arm_availability_set.go index 0aa100caf499..e570c83b5a53 100644 --- a/azurerm/resource_arm_availability_set.go +++ b/azurerm/internal/services/compute/resource_arm_availability_set.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_availability_set_test.go b/azurerm/internal/services/compute/resource_arm_availability_set_test.go similarity index 99% rename from azurerm/resource_arm_availability_set_test.go rename to azurerm/internal/services/compute/resource_arm_availability_set_test.go index 558606a5f53f..4a309a218325 100644 --- a/azurerm/resource_arm_availability_set_test.go +++ b/azurerm/internal/services/compute/resource_arm_availability_set_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_linux_virtual_machine_scale_set.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set.go similarity index 88% rename from azurerm/resource_arm_linux_virtual_machine_scale_set.go rename to azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set.go index ed9645a66b87..f372c789a146 100644 --- a/azurerm/resource_arm_linux_virtual_machine_scale_set.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - computeSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/base64" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" @@ -30,7 +29,7 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource { Delete: resourceArmLinuxVirtualMachineScaleSetDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := computeSvc.ParseVirtualMachineScaleSetID(id) + _, err := ParseVirtualMachineScaleSetID(id) // TODO: (prior to Beta) look up the VM & confirm this is a Linux VMSS return err }), @@ -50,7 +49,7 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: computeSvc.ValidateLinuxName, + ValidateFunc: ValidateLinuxName, }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -65,9 +64,9 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource { ValidateFunc: validate.NoEmptyStrings, }, - "network_interface": computeSvc.VirtualMachineScaleSetNetworkInterfaceSchema(), + "network_interface": VirtualMachineScaleSetNetworkInterfaceSchema(), - "os_disk": computeSvc.VirtualMachineScaleSetOSDiskSchema(), + "os_disk": VirtualMachineScaleSetOSDiskSchema(), "instances": { Type: schema.TypeInt, @@ -82,7 +81,7 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource { }, // Optional - "additional_capabilities": computeSvc.VirtualMachineScaleSetAdditionalCapabilitiesSchema(), + "additional_capabilities": VirtualMachineScaleSetAdditionalCapabilitiesSchema(), "admin_password": { Type: schema.TypeString, @@ -91,11 +90,11 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource { Sensitive: true, }, - "admin_ssh_key": computeSvc.SSHKeysSchema(), + "admin_ssh_key": SSHKeysSchema(), - "automatic_os_upgrade_policy": computeSvc.VirtualMachineScaleSetAutomatedOSUpgradePolicySchema(), + "automatic_os_upgrade_policy": VirtualMachineScaleSetAutomatedOSUpgradePolicySchema(), - "boot_diagnostics": computeSvc.VirtualMachineScaleSetBootDiagnosticsSchema(), + "boot_diagnostics": VirtualMachineScaleSetBootDiagnosticsSchema(), "computer_name_prefix": { Type: schema.TypeString, @@ -106,12 +105,12 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource { ForceNew: true, // note: whilst the portal says 1-15 characters it seems to mirror the rules for the vm name // (e.g. 1-15 for Windows, 1-63 for Linux) - ValidateFunc: computeSvc.ValidateLinuxName, + ValidateFunc: ValidateLinuxName, }, "custom_data": base64.OptionalSchema(), - "data_disk": computeSvc.VirtualMachineScaleSetDataDiskSchema(), + "data_disk": VirtualMachineScaleSetDataDiskSchema(), "disable_password_authentication": { Type: schema.TypeBool, @@ -143,7 +142,7 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource { ValidateFunc: azure.ValidateResourceID, }, - "identity": computeSvc.VirtualMachineScaleSetIdentitySchema(), + "identity": VirtualMachineScaleSetIdentitySchema(), "max_bid_price": { Type: schema.TypeFloat, @@ -157,7 +156,7 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource { Default: true, }, - "plan": computeSvc.PlanSchema(), + "plan": PlanSchema(), "priority": { Type: schema.TypeString, @@ -186,7 +185,7 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource { DiffSuppressFunc: suppress.CaseDifference, }, - "rolling_upgrade_policy": computeSvc.VirtualMachineScaleSetRollingUpgradePolicySchema(), + "rolling_upgrade_policy": VirtualMachineScaleSetRollingUpgradePolicySchema(), "secret": { Type: schema.TypeList, @@ -232,7 +231,7 @@ func resourceArmLinuxVirtualMachineScaleSet() *schema.Resource { ValidateFunc: azure.ValidateResourceID, }, - "source_image_reference": computeSvc.VirtualMachineScaleSetSourceImageReferenceSchema(), + "source_image_reference": VirtualMachineScaleSetSourceImageReferenceSchema(), "tags": tags.Schema(), @@ -297,48 +296,48 @@ func resourceArmLinuxVirtualMachineScaleSetCreate(d *schema.ResourceData, meta i t := d.Get("tags").(map[string]interface{}) additionalCapabilitiesRaw := d.Get("additional_capabilities").([]interface{}) - additionalCapabilities := computeSvc.ExpandVirtualMachineScaleSetAdditionalCapabilities(additionalCapabilitiesRaw) + additionalCapabilities := ExpandVirtualMachineScaleSetAdditionalCapabilities(additionalCapabilitiesRaw) bootDiagnosticsRaw := d.Get("boot_diagnostics").([]interface{}) - bootDiagnostics := computeSvc.ExpandVirtualMachineScaleSetBootDiagnostics(bootDiagnosticsRaw) + bootDiagnostics := ExpandVirtualMachineScaleSetBootDiagnostics(bootDiagnosticsRaw) dataDisksRaw := d.Get("data_disk").([]interface{}) - dataDisks := computeSvc.ExpandVirtualMachineScaleSetDataDisk(dataDisksRaw) + dataDisks := ExpandVirtualMachineScaleSetDataDisk(dataDisksRaw) identityRaw := d.Get("identity").([]interface{}) - identity, err := computeSvc.ExpandVirtualMachineScaleSetIdentity(identityRaw) + identity, err := ExpandVirtualMachineScaleSetIdentity(identityRaw) if err != nil { return fmt.Errorf("Error expanding `identity`: %+v", err) } networkInterfacesRaw := d.Get("network_interface").([]interface{}) - networkInterfaces, err := computeSvc.ExpandVirtualMachineScaleSetNetworkInterface(networkInterfacesRaw) + networkInterfaces, err := ExpandVirtualMachineScaleSetNetworkInterface(networkInterfacesRaw) if err != nil { return fmt.Errorf("Error expanding `network_interface`: %+v", err) } osDiskRaw := d.Get("os_disk").([]interface{}) - osDisk := computeSvc.ExpandVirtualMachineScaleSetOSDisk(osDiskRaw, compute.Linux) + osDisk := ExpandVirtualMachineScaleSetOSDisk(osDiskRaw, compute.Linux) planRaw := d.Get("plan").([]interface{}) - plan := computeSvc.ExpandPlan(planRaw) + plan := ExpandPlan(planRaw) sourceImageReferenceRaw := d.Get("source_image_reference").([]interface{}) sourceImageId := d.Get("source_image_id").(string) - sourceImageReference, err := computeSvc.ExpandVirtualMachineScaleSetSourceImageReference(sourceImageReferenceRaw, sourceImageId) + sourceImageReference, err := ExpandVirtualMachineScaleSetSourceImageReference(sourceImageReferenceRaw, sourceImageId) if err != nil { return err } sshKeysRaw := d.Get("admin_ssh_key").(*schema.Set).List() - sshKeys := computeSvc.ExpandSSHKeys(sshKeysRaw) + sshKeys := ExpandSSHKeys(sshKeysRaw) healthProbeId := d.Get("health_probe_id").(string) upgradeMode := compute.UpgradeMode(d.Get("upgrade_mode").(string)) automaticOSUpgradePolicyRaw := d.Get("automatic_os_upgrade_policy").([]interface{}) - automaticOSUpgradePolicy := computeSvc.ExpandVirtualMachineScaleSetAutomaticUpgradePolicy(automaticOSUpgradePolicyRaw) + automaticOSUpgradePolicy := ExpandVirtualMachineScaleSetAutomaticUpgradePolicy(automaticOSUpgradePolicyRaw) rollingUpgradePolicyRaw := d.Get("rolling_upgrade_policy").([]interface{}) - rollingUpgradePolicy := computeSvc.ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingUpgradePolicyRaw) + rollingUpgradePolicy := ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingUpgradePolicyRaw) if upgradeMode != compute.Manual && healthProbeId == "" { return fmt.Errorf("`healthProbeId` must be set when `upgrade_mode` is set to %q", string(upgradeMode)) @@ -512,7 +511,7 @@ func resourceArmLinuxVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta i ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := computeSvc.ParseVirtualMachineScaleSetID(d.Id()) + id, err := ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } @@ -543,12 +542,12 @@ func resourceArmLinuxVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta i if d.HasChange("automatic_os_upgrade_policy") { automaticRaw := d.Get("automatic_os_upgrade_policy").([]interface{}) - upgradePolicy.AutomaticOSUpgradePolicy = computeSvc.ExpandVirtualMachineScaleSetAutomaticUpgradePolicy(automaticRaw) + upgradePolicy.AutomaticOSUpgradePolicy = ExpandVirtualMachineScaleSetAutomaticUpgradePolicy(automaticRaw) } if d.HasChange("rolling_upgrade_policy") { rollingRaw := d.Get("rolling_upgrade_policy").([]interface{}) - upgradePolicy.RollingUpgradePolicy = computeSvc.ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingRaw) + upgradePolicy.RollingUpgradePolicy = ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingRaw) } updateProps.UpgradePolicy = &upgradePolicy @@ -577,7 +576,7 @@ func resourceArmLinuxVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta i if d.HasChange("admin_ssh_key") { sshKeysRaw := d.Get("admin_ssh_key").(*schema.Set).List() - sshKeys := computeSvc.ExpandSSHKeys(sshKeysRaw) + sshKeys := ExpandSSHKeys(sshKeysRaw) linuxConfig.SSH = &compute.SSHConfiguration{ PublicKeys: &sshKeys, } @@ -619,18 +618,18 @@ func resourceArmLinuxVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta i if d.HasChange("data_disk") { dataDisksRaw := d.Get("data_disk").([]interface{}) - storageProfile.DataDisks = computeSvc.ExpandVirtualMachineScaleSetDataDisk(dataDisksRaw) + storageProfile.DataDisks = ExpandVirtualMachineScaleSetDataDisk(dataDisksRaw) } if d.HasChange("os_disk") { osDiskRaw := d.Get("os_disk").([]interface{}) - storageProfile.OsDisk = computeSvc.ExpandVirtualMachineScaleSetOSDiskUpdate(osDiskRaw) + storageProfile.OsDisk = ExpandVirtualMachineScaleSetOSDiskUpdate(osDiskRaw) } if d.HasChange("source_image_id") || d.HasChange("source_image_reference") { sourceImageReferenceRaw := d.Get("source_image_reference").([]interface{}) sourceImageId := d.Get("source_image_id").(string) - sourceImageReference, err := computeSvc.ExpandVirtualMachineScaleSetSourceImageReference(sourceImageReferenceRaw, sourceImageId) + sourceImageReference, err := ExpandVirtualMachineScaleSetSourceImageReference(sourceImageReferenceRaw, sourceImageId) if err != nil { return err } @@ -643,7 +642,7 @@ func resourceArmLinuxVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta i if d.HasChange("network_interface") { networkInterfacesRaw := d.Get("network_interface").([]interface{}) - networkInterfaces, err := computeSvc.ExpandVirtualMachineScaleSetNetworkInterfaceUpdate(networkInterfacesRaw) + networkInterfaces, err := ExpandVirtualMachineScaleSetNetworkInterfaceUpdate(networkInterfacesRaw) if err != nil { return fmt.Errorf("Error expanding `network_interface`: %+v", err) } @@ -660,12 +659,12 @@ func resourceArmLinuxVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta i updateInstances = true bootDiagnosticsRaw := d.Get("boot_diagnostics").([]interface{}) - updateProps.VirtualMachineProfile.DiagnosticsProfile = computeSvc.ExpandVirtualMachineScaleSetBootDiagnostics(bootDiagnosticsRaw) + updateProps.VirtualMachineProfile.DiagnosticsProfile = ExpandVirtualMachineScaleSetBootDiagnostics(bootDiagnosticsRaw) } if d.HasChange("identity") { identityRaw := d.Get("identity").([]interface{}) - identity, err := computeSvc.ExpandVirtualMachineScaleSetIdentity(identityRaw) + identity, err := ExpandVirtualMachineScaleSetIdentity(identityRaw) if err != nil { return fmt.Errorf("Error expanding `identity`: %+v", err) } @@ -675,7 +674,7 @@ func resourceArmLinuxVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta i if d.HasChange("plan") { planRaw := d.Get("plan").([]interface{}) - update.Plan = computeSvc.ExpandPlan(planRaw) + update.Plan = ExpandPlan(planRaw) } if d.HasChange("sku") || d.HasChange("instances") { @@ -789,7 +788,7 @@ func resourceArmLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta int ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := computeSvc.ParseVirtualMachineScaleSetID(d.Id()) + id, err := ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } @@ -822,11 +821,11 @@ func resourceArmLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta int d.Set("instances", instances) d.Set("sku", skuName) - if err := d.Set("identity", computeSvc.FlattenVirtualMachineScaleSetIdentity(resp.Identity)); err != nil { + if err := d.Set("identity", FlattenVirtualMachineScaleSetIdentity(resp.Identity)); err != nil { return fmt.Errorf("Error setting `identity`: %+v", err) } - if err := d.Set("plan", computeSvc.FlattenPlan(resp.Plan)); err != nil { + if err := d.Set("plan", FlattenPlan(resp.Plan)); err != nil { return fmt.Errorf("Error setting `plan`: %+v", err) } @@ -835,7 +834,7 @@ func resourceArmLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta int } props := *resp.VirtualMachineScaleSetProperties - if err := d.Set("additional_capabilities", computeSvc.FlattenVirtualMachineScaleSetAdditionalCapabilities(props.AdditionalCapabilities)); err != nil { + if err := d.Set("additional_capabilities", FlattenVirtualMachineScaleSetAdditionalCapabilities(props.AdditionalCapabilities)); err != nil { return fmt.Errorf("Error setting `additional_capabilities`: %+v", props.AdditionalCapabilities) } @@ -851,7 +850,7 @@ func resourceArmLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta int d.Set("zone_balance", props.ZoneBalance) if profile := props.VirtualMachineProfile; profile != nil { - if err := d.Set("boot_diagnostics", computeSvc.FlattenVirtualMachineScaleSetBootDiagnostics(profile.DiagnosticsProfile)); err != nil { + if err := d.Set("boot_diagnostics", FlattenVirtualMachineScaleSetBootDiagnostics(profile.DiagnosticsProfile)); err != nil { return fmt.Errorf("Error setting `boot_diagnostics`: %+v", err) } @@ -866,15 +865,15 @@ func resourceArmLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta int d.Set("priority", string(profile.Priority)) if storageProfile := profile.StorageProfile; storageProfile != nil { - if err := d.Set("os_disk", computeSvc.FlattenVirtualMachineScaleSetOSDisk(storageProfile.OsDisk)); err != nil { + if err := d.Set("os_disk", FlattenVirtualMachineScaleSetOSDisk(storageProfile.OsDisk)); err != nil { return fmt.Errorf("Error setting `os_disk`: %+v", err) } - if err := d.Set("data_disk", computeSvc.FlattenVirtualMachineScaleSetDataDisk(storageProfile.DataDisks)); err != nil { + if err := d.Set("data_disk", FlattenVirtualMachineScaleSetDataDisk(storageProfile.DataDisks)); err != nil { return fmt.Errorf("Error setting `data_disk`: %+v", err) } - if err := d.Set("source_image_reference", computeSvc.FlattenVirtualMachineScaleSetSourceImageReference(storageProfile.ImageReference)); err != nil { + if err := d.Set("source_image_reference", FlattenVirtualMachineScaleSetSourceImageReference(storageProfile.ImageReference)); err != nil { return fmt.Errorf("Error setting `source_image_reference`: %+v", err) } @@ -894,7 +893,7 @@ func resourceArmLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta int d.Set("disable_password_authentication", linux.DisablePasswordAuthentication) d.Set("provision_vm_agent", linux.ProvisionVMAgent) - flattenedSshKeys, err := computeSvc.FlattenSSHKeys(linux.SSH) + flattenedSshKeys, err := FlattenSSHKeys(linux.SSH) if err != nil { return fmt.Errorf("Error flattening `admin_ssh_key`: %+v", err) } @@ -909,7 +908,7 @@ func resourceArmLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta int } if nwProfile := profile.NetworkProfile; nwProfile != nil { - flattenedNics := computeSvc.FlattenVirtualMachineScaleSetNetworkInterface(nwProfile.NetworkInterfaceConfigurations) + flattenedNics := FlattenVirtualMachineScaleSetNetworkInterface(nwProfile.NetworkInterfaceConfigurations) if err := d.Set("network_interface", flattenedNics); err != nil { return fmt.Errorf("Error setting `network_interface`: %+v", err) } @@ -925,12 +924,12 @@ func resourceArmLinuxVirtualMachineScaleSetRead(d *schema.ResourceData, meta int if policy := props.UpgradePolicy; policy != nil { d.Set("upgrade_mode", string(policy.Mode)) - flattenedAutomatic := computeSvc.FlattenVirtualMachineScaleSetAutomaticOSUpgradePolicy(policy.AutomaticOSUpgradePolicy) + flattenedAutomatic := FlattenVirtualMachineScaleSetAutomaticOSUpgradePolicy(policy.AutomaticOSUpgradePolicy) if err := d.Set("automatic_os_upgrade_policy", flattenedAutomatic); err != nil { return fmt.Errorf("Error setting `automatic_os_upgrade_policy`: %+v", err) } - flattenedRolling := computeSvc.FlattenVirtualMachineScaleSetRollingUpgradePolicy(policy.RollingUpgradePolicy) + flattenedRolling := FlattenVirtualMachineScaleSetRollingUpgradePolicy(policy.RollingUpgradePolicy) if err := d.Set("rolling_upgrade_policy", flattenedRolling); err != nil { return fmt.Errorf("Error setting `rolling_upgrade_policy`: %+v", err) } @@ -948,7 +947,7 @@ func resourceArmLinuxVirtualMachineScaleSetDelete(d *schema.ResourceData, meta i ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := computeSvc.ParseVirtualMachineScaleSetID(d.Id()) + id, err := ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_linux_virtual_machine_scale_set_auth_test.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_auth_test.go similarity index 99% rename from azurerm/resource_arm_linux_virtual_machine_scale_set_auth_test.go rename to azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_auth_test.go index 48c867633755..6e6f93bab9e1 100644 --- a/azurerm/resource_arm_linux_virtual_machine_scale_set_auth_test.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_auth_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go similarity index 99% rename from azurerm/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go rename to azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go index d9cb86f23f22..5277a1a932ba 100644 --- a/azurerm/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go similarity index 99% rename from azurerm/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go rename to azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go index cc5e94a88568..8730226ee153 100644 --- a/azurerm/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_linux_virtual_machine_scale_set_identity_test.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_identity_test.go similarity index 99% rename from azurerm/resource_arm_linux_virtual_machine_scale_set_identity_test.go rename to azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_identity_test.go index cc3d286cb67c..331913d45561 100644 --- a/azurerm/resource_arm_linux_virtual_machine_scale_set_identity_test.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_identity_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_linux_virtual_machine_scale_set_images_test.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_images_test.go similarity index 99% rename from azurerm/resource_arm_linux_virtual_machine_scale_set_images_test.go rename to azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_images_test.go index 9a9a1c248bc0..a628719b7e27 100644 --- a/azurerm/resource_arm_linux_virtual_machine_scale_set_images_test.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_images_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_linux_virtual_machine_scale_set_network_test.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_network_test.go similarity index 99% rename from azurerm/resource_arm_linux_virtual_machine_scale_set_network_test.go rename to azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_network_test.go index 20a1db82134b..a4617b566fd2 100644 --- a/azurerm/resource_arm_linux_virtual_machine_scale_set_network_test.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_network_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_linux_virtual_machine_scale_set_other_test.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_other_test.go similarity index 99% rename from azurerm/resource_arm_linux_virtual_machine_scale_set_other_test.go rename to azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_other_test.go index 6262ce2039eb..9ec36e3dbe60 100644 --- a/azurerm/resource_arm_linux_virtual_machine_scale_set_other_test.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_other_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_linux_virtual_machine_scale_set_scaling_test.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_scaling_test.go similarity index 99% rename from azurerm/resource_arm_linux_virtual_machine_scale_set_scaling_test.go rename to azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_scaling_test.go index 4ab2fa20bae6..d948ad12a446 100644 --- a/azurerm/resource_arm_linux_virtual_machine_scale_set_scaling_test.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_scaling_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_linux_virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_test.go similarity index 99% rename from azurerm/resource_arm_linux_virtual_machine_scale_set_test.go rename to azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_test.go index 3094bae32eb6..88b011f52fd4 100644 --- a/azurerm/resource_arm_linux_virtual_machine_scale_set_test.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_managed_disk.go b/azurerm/internal/services/compute/resource_arm_managed_disk.go similarity index 99% rename from azurerm/resource_arm_managed_disk.go rename to azurerm/internal/services/compute/resource_arm_managed_disk.go index 490600d31b08..55baffd4599d 100644 --- a/azurerm/resource_arm_managed_disk.go +++ b/azurerm/internal/services/compute/resource_arm_managed_disk.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_managed_disk_test.go b/azurerm/internal/services/compute/resource_arm_managed_disk_test.go similarity index 99% rename from azurerm/resource_arm_managed_disk_test.go rename to azurerm/internal/services/compute/resource_arm_managed_disk_test.go index 660b0a017787..da23f7e4ada2 100644 --- a/azurerm/resource_arm_managed_disk_test.go +++ b/azurerm/internal/services/compute/resource_arm_managed_disk_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" @@ -105,11 +105,11 @@ func TestAccAzureRMManagedDisk_import(t *testing.T) { Steps: []resource.TestStep{ { //need to create a vm and then delete it so we can use the vhd to test import - Config: testAccAzureRMVirtualMachine_basicLinuxMachine(ri, location), + Config: compute2.testAccAzureRMVirtualMachine_basicLinuxMachine(ri, location), Destroy: false, ExpectNonEmptyPlan: true, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + compute2.testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), testDeleteAzureRMVirtualMachine("azurerm_virtual_machine.test"), ), }, diff --git a/azurerm/resource_arm_snapshot.go b/azurerm/internal/services/compute/resource_arm_snapshot.go similarity index 99% rename from azurerm/resource_arm_snapshot.go rename to azurerm/internal/services/compute/resource_arm_snapshot.go index f3a483537bac..f7cf2d0291d2 100644 --- a/azurerm/resource_arm_snapshot.go +++ b/azurerm/internal/services/compute/resource_arm_snapshot.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_snapshot_test.go b/azurerm/internal/services/compute/resource_arm_snapshot_test.go similarity index 99% rename from azurerm/resource_arm_snapshot_test.go rename to azurerm/internal/services/compute/resource_arm_snapshot_test.go index f4bcb58b4206..7ba7b9e990cc 100644 --- a/azurerm/resource_arm_snapshot_test.go +++ b/azurerm/internal/services/compute/resource_arm_snapshot_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_virtual_machine.go b/azurerm/internal/services/compute/resource_arm_virtual_machine.go similarity index 99% rename from azurerm/resource_arm_virtual_machine.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine.go index 4397a60596e5..18ae8e0ac2aa 100644 --- a/azurerm/resource_arm_virtual_machine.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "bytes" diff --git a/azurerm/resource_arm_virtual_machine_data_disk_attachment.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_data_disk_attachment.go similarity index 99% rename from azurerm/resource_arm_virtual_machine_data_disk_attachment.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_data_disk_attachment.go index 87c4e3026e99..43830dc789f7 100644 --- a/azurerm/resource_arm_virtual_machine_data_disk_attachment.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_data_disk_attachment.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_virtual_machine_data_disk_attachment_test.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_data_disk_attachment_test.go similarity index 99% rename from azurerm/resource_arm_virtual_machine_data_disk_attachment_test.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_data_disk_attachment_test.go index 324b617bae3f..3b0eadb2577d 100644 --- a/azurerm/resource_arm_virtual_machine_data_disk_attachment_test.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_data_disk_attachment_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_virtual_machine_extension.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_extension.go similarity index 99% rename from azurerm/resource_arm_virtual_machine_extension.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_extension.go index 6be0102c08f0..bd008c0f2291 100644 --- a/azurerm/resource_arm_virtual_machine_extension.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_extension.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_virtual_machine_extension_test.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_extension_test.go similarity index 99% rename from azurerm/resource_arm_virtual_machine_extension_test.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_extension_test.go index 8360c1a960ff..5e7efd4296ff 100644 --- a/azurerm/resource_arm_virtual_machine_extension_test.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_extension_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_virtual_machine_managed_disks_test.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_managed_disks_test.go similarity index 99% rename from azurerm/resource_arm_virtual_machine_managed_disks_test.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_managed_disks_test.go index b9453ff1a800..019892d5dc6a 100644 --- a/azurerm/resource_arm_virtual_machine_managed_disks_test.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_managed_disks_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_virtual_machine_scale_set.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set.go similarity index 99% rename from azurerm/resource_arm_virtual_machine_scale_set.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set.go index b5699b8b9c94..186f4b70b3aa 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "bytes" diff --git a/azurerm/resource_arm_virtual_machine_scale_set_extension.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension.go similarity index 95% rename from azurerm/resource_arm_virtual_machine_scale_set_extension.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension.go index e2e781fd3de5..8d8ab73c0426 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set_extension.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - computeSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -30,7 +29,7 @@ func resourceArmVirtualMachineScaleSetExtension() *schema.Resource { Delete: resourceArmVirtualMachineScaleSetExtensionDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := computeSvc.ParseVirtualMachineScaleSetExtensionID(id) + _, err := ParseVirtualMachineScaleSetExtensionID(id) return err }), @@ -53,7 +52,7 @@ func resourceArmVirtualMachineScaleSetExtension() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: computeSvc.ValidateScaleSetResourceID, + ValidateFunc: ValidateScaleSetResourceID, }, "publisher": { @@ -119,7 +118,7 @@ func resourceArmVirtualMachineScaleSetExtensionCreate(d *schema.ResourceData, me defer cancel() name := d.Get("name").(string) - virtualMachineScaleSetId, err := computeSvc.ParseVirtualMachineScaleSetID(d.Get("virtual_machine_scale_set_id").(string)) + virtualMachineScaleSetId, err := ParseVirtualMachineScaleSetID(d.Get("virtual_machine_scale_set_id").(string)) if err != nil { return err } @@ -199,7 +198,7 @@ func resourceArmVirtualMachineScaleSetExtensionUpdate(d *schema.ResourceData, me ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := computeSvc.ParseVirtualMachineScaleSetExtensionID(d.Id()) + id, err := ParseVirtualMachineScaleSetExtensionID(d.Id()) if err != nil { return err } @@ -279,7 +278,7 @@ func resourceArmVirtualMachineScaleSetExtensionRead(d *schema.ResourceData, meta ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := computeSvc.ParseVirtualMachineScaleSetExtensionID(d.Id()) + id, err := ParseVirtualMachineScaleSetExtensionID(d.Id()) if err != nil { return err } @@ -339,7 +338,7 @@ func resourceArmVirtualMachineScaleSetExtensionDelete(d *schema.ResourceData, me ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := computeSvc.ParseVirtualMachineScaleSetExtensionID(d.Id()) + id, err := ParseVirtualMachineScaleSetExtensionID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_virtual_machine_scale_set_extension_test.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension_test.go similarity index 99% rename from azurerm/resource_arm_virtual_machine_scale_set_extension_test.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension_test.go index 95b69bdf2627..f14489841e83 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set_extension_test.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" @@ -12,7 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - computeSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" ) func TestAccAzureRMVirtualMachineScaleSetExtension_basicLinux(t *testing.T) { diff --git a/azurerm/resource_arm_virtual_machine_scale_set_migration.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_migration.go similarity index 98% rename from azurerm/resource_arm_virtual_machine_scale_set_migration.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_migration.go index 8bbefbde683b..48cb409fca5b 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set_migration.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_migration.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "context" diff --git a/azurerm/resource_arm_virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_test.go similarity index 99% rename from azurerm/resource_arm_virtual_machine_scale_set_test.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_test.go index 5530e585fbb8..339a0920ea00 100644 --- a/azurerm/resource_arm_virtual_machine_scale_set_test.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" @@ -703,7 +703,7 @@ func TestAccAzureRMVirtualMachineScaleSet_customImage(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, acceptance.Location()), + estGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, acceptance.Location()), ), }, { diff --git a/azurerm/resource_arm_virtual_machine_test.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_test.go similarity index 99% rename from azurerm/resource_arm_virtual_machine_test.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_test.go index c10579018b5b..5a5e78ed5a5f 100644 --- a/azurerm/resource_arm_virtual_machine_test.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_unmanaged_disks_test.go similarity index 99% rename from azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go rename to azurerm/internal/services/compute/resource_arm_virtual_machine_unmanaged_disks_test.go index e80226e1a849..5ff37fa1215f 100644 --- a/azurerm/resource_arm_virtual_machine_unmanaged_disks_test.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_unmanaged_disks_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_windows_virtual_machine_scale_set.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set.go similarity index 90% rename from azurerm/resource_arm_windows_virtual_machine_scale_set.go rename to azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set.go index dad0d00c70d2..ed91987ee563 100644 --- a/azurerm/resource_arm_windows_virtual_machine_scale_set.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - computeSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/base64" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" @@ -30,7 +29,7 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource { Delete: resourceArmWindowsVirtualMachineScaleSetDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := computeSvc.ParseVirtualMachineScaleSetID(id) + _, err := ParseVirtualMachineScaleSetID(id) // TODO: (prior to Beta) look up the VM & confirm this is a Windows VMSS return err }), @@ -50,7 +49,7 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: computeSvc.ValidateWindowsName, + ValidateFunc: ValidateWindowsName, }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -73,9 +72,9 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource { ValidateFunc: validate.NoEmptyStrings, }, - "network_interface": computeSvc.VirtualMachineScaleSetNetworkInterfaceSchema(), + "network_interface": VirtualMachineScaleSetNetworkInterfaceSchema(), - "os_disk": computeSvc.VirtualMachineScaleSetOSDiskSchema(), + "os_disk": VirtualMachineScaleSetOSDiskSchema(), "instances": { Type: schema.TypeInt, @@ -90,7 +89,7 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource { }, // Optional - "additional_capabilities": computeSvc.VirtualMachineScaleSetAdditionalCapabilitiesSchema(), + "additional_capabilities": VirtualMachineScaleSetAdditionalCapabilitiesSchema(), "additional_unattend_config": { Type: schema.TypeList, @@ -121,9 +120,9 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource { }, }, - "automatic_os_upgrade_policy": computeSvc.VirtualMachineScaleSetAutomatedOSUpgradePolicySchema(), + "automatic_os_upgrade_policy": VirtualMachineScaleSetAutomatedOSUpgradePolicySchema(), - "boot_diagnostics": computeSvc.VirtualMachineScaleSetBootDiagnosticsSchema(), + "boot_diagnostics": VirtualMachineScaleSetBootDiagnosticsSchema(), "computer_name_prefix": { Type: schema.TypeString, @@ -134,12 +133,12 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource { ForceNew: true, // note: whilst the portal says 1-15 characters it seems to mirror the rules for the vm name // (e.g. 1-15 for Windows, 1-63 for Windows) - ValidateFunc: computeSvc.ValidateWindowsName, + ValidateFunc: ValidateWindowsName, }, "custom_data": base64.OptionalSchema(), - "data_disk": computeSvc.VirtualMachineScaleSetDataDiskSchema(), + "data_disk": VirtualMachineScaleSetDataDiskSchema(), "do_not_run_extensions_on_overprovisioned_machines": { Type: schema.TypeBool, @@ -171,7 +170,7 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource { ValidateFunc: azure.ValidateResourceID, }, - "identity": computeSvc.VirtualMachineScaleSetIdentitySchema(), + "identity": VirtualMachineScaleSetIdentitySchema(), "license_type": { Type: schema.TypeString, @@ -195,7 +194,7 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource { Default: true, }, - "plan": computeSvc.PlanSchema(), + "plan": PlanSchema(), "priority": { Type: schema.TypeString, @@ -224,7 +223,7 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource { DiffSuppressFunc: suppress.CaseDifference, }, - "rolling_upgrade_policy": computeSvc.VirtualMachineScaleSetRollingUpgradePolicySchema(), + "rolling_upgrade_policy": VirtualMachineScaleSetRollingUpgradePolicySchema(), "secret": { Type: schema.TypeList, @@ -272,7 +271,7 @@ func resourceArmWindowsVirtualMachineScaleSet() *schema.Resource { ValidateFunc: azure.ValidateResourceID, }, - "source_image_reference": computeSvc.VirtualMachineScaleSetSourceImageReferenceSchema(), + "source_image_reference": VirtualMachineScaleSetSourceImageReferenceSchema(), "tags": tags.Schema(), @@ -373,38 +372,38 @@ func resourceArmWindowsVirtualMachineScaleSetCreate(d *schema.ResourceData, meta t := d.Get("tags").(map[string]interface{}) additionalCapabilitiesRaw := d.Get("additional_capabilities").([]interface{}) - additionalCapabilities := computeSvc.ExpandVirtualMachineScaleSetAdditionalCapabilities(additionalCapabilitiesRaw) + additionalCapabilities := ExpandVirtualMachineScaleSetAdditionalCapabilities(additionalCapabilitiesRaw) additionalUnattendConfigRaw := d.Get("additional_unattend_config").([]interface{}) additionalUnattendConfig := expandWindowsVirtualMachineScaleSetAdditionalUnattendConfig(additionalUnattendConfigRaw) bootDiagnosticsRaw := d.Get("boot_diagnostics").([]interface{}) - bootDiagnostics := computeSvc.ExpandVirtualMachineScaleSetBootDiagnostics(bootDiagnosticsRaw) + bootDiagnostics := ExpandVirtualMachineScaleSetBootDiagnostics(bootDiagnosticsRaw) dataDisksRaw := d.Get("data_disk").([]interface{}) - dataDisks := computeSvc.ExpandVirtualMachineScaleSetDataDisk(dataDisksRaw) + dataDisks := ExpandVirtualMachineScaleSetDataDisk(dataDisksRaw) identityRaw := d.Get("identity").([]interface{}) - identity, err := computeSvc.ExpandVirtualMachineScaleSetIdentity(identityRaw) + identity, err := ExpandVirtualMachineScaleSetIdentity(identityRaw) if err != nil { return fmt.Errorf("Error expanding `identity`: %+v", err) } networkInterfacesRaw := d.Get("network_interface").([]interface{}) - networkInterfaces, err := computeSvc.ExpandVirtualMachineScaleSetNetworkInterface(networkInterfacesRaw) + networkInterfaces, err := ExpandVirtualMachineScaleSetNetworkInterface(networkInterfacesRaw) if err != nil { return fmt.Errorf("Error expanding `network_interface`: %+v", err) } osDiskRaw := d.Get("os_disk").([]interface{}) - osDisk := computeSvc.ExpandVirtualMachineScaleSetOSDisk(osDiskRaw, compute.Windows) + osDisk := ExpandVirtualMachineScaleSetOSDisk(osDiskRaw, compute.Windows) planRaw := d.Get("plan").([]interface{}) - plan := computeSvc.ExpandPlan(planRaw) + plan := ExpandPlan(planRaw) sourceImageReferenceRaw := d.Get("source_image_reference").([]interface{}) sourceImageId := d.Get("source_image_id").(string) - sourceImageReference, err := computeSvc.ExpandVirtualMachineScaleSetSourceImageReference(sourceImageReferenceRaw, sourceImageId) + sourceImageReference, err := ExpandVirtualMachineScaleSetSourceImageReference(sourceImageReferenceRaw, sourceImageId) if err != nil { return err } @@ -412,9 +411,9 @@ func resourceArmWindowsVirtualMachineScaleSetCreate(d *schema.ResourceData, meta healthProbeId := d.Get("health_probe_id").(string) upgradeMode := compute.UpgradeMode(d.Get("upgrade_mode").(string)) automaticOSUpgradePolicyRaw := d.Get("automatic_os_upgrade_policy").([]interface{}) - automaticOSUpgradePolicy := computeSvc.ExpandVirtualMachineScaleSetAutomaticUpgradePolicy(automaticOSUpgradePolicyRaw) + automaticOSUpgradePolicy := ExpandVirtualMachineScaleSetAutomaticUpgradePolicy(automaticOSUpgradePolicyRaw) rollingUpgradePolicyRaw := d.Get("rolling_upgrade_policy").([]interface{}) - rollingUpgradePolicy := computeSvc.ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingUpgradePolicyRaw) + rollingUpgradePolicy := ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingUpgradePolicyRaw) if upgradeMode != compute.Manual && healthProbeId == "" { return fmt.Errorf("`healthProbeId` must be set when `upgrade_mode` is set to %q", string(upgradeMode)) @@ -598,7 +597,7 @@ func resourceArmWindowsVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := computeSvc.ParseVirtualMachineScaleSetID(d.Id()) + id, err := ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } @@ -630,12 +629,12 @@ func resourceArmWindowsVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta if d.HasChange("automatic_os_upgrade_policy") { automaticRaw := d.Get("automatic_os_upgrade_policy").([]interface{}) - upgradePolicy.AutomaticOSUpgradePolicy = computeSvc.ExpandVirtualMachineScaleSetAutomaticUpgradePolicy(automaticRaw) + upgradePolicy.AutomaticOSUpgradePolicy = ExpandVirtualMachineScaleSetAutomaticUpgradePolicy(automaticRaw) } if d.HasChange("rolling_upgrade_policy") { rollingRaw := d.Get("rolling_upgrade_policy").([]interface{}) - upgradePolicy.RollingUpgradePolicy = computeSvc.ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingRaw) + upgradePolicy.RollingUpgradePolicy = ExpandVirtualMachineScaleSetRollingUpgradePolicy(rollingRaw) } updateProps.UpgradePolicy = &upgradePolicy @@ -710,18 +709,18 @@ func resourceArmWindowsVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta if d.HasChange("data_disk") { dataDisksRaw := d.Get("data_disk").([]interface{}) - storageProfile.DataDisks = computeSvc.ExpandVirtualMachineScaleSetDataDisk(dataDisksRaw) + storageProfile.DataDisks = ExpandVirtualMachineScaleSetDataDisk(dataDisksRaw) } if d.HasChange("os_disk") { osDiskRaw := d.Get("os_disk").([]interface{}) - storageProfile.OsDisk = computeSvc.ExpandVirtualMachineScaleSetOSDiskUpdate(osDiskRaw) + storageProfile.OsDisk = ExpandVirtualMachineScaleSetOSDiskUpdate(osDiskRaw) } if d.HasChange("source_image_id") || d.HasChange("source_image_reference") { sourceImageReferenceRaw := d.Get("source_image_reference").([]interface{}) sourceImageId := d.Get("source_image_id").(string) - sourceImageReference, err := computeSvc.ExpandVirtualMachineScaleSetSourceImageReference(sourceImageReferenceRaw, sourceImageId) + sourceImageReference, err := ExpandVirtualMachineScaleSetSourceImageReference(sourceImageReferenceRaw, sourceImageId) if err != nil { return err } @@ -734,7 +733,7 @@ func resourceArmWindowsVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta if d.HasChange("network_interface") { networkInterfacesRaw := d.Get("network_interface").([]interface{}) - networkInterfaces, err := computeSvc.ExpandVirtualMachineScaleSetNetworkInterfaceUpdate(networkInterfacesRaw) + networkInterfaces, err := ExpandVirtualMachineScaleSetNetworkInterfaceUpdate(networkInterfacesRaw) if err != nil { return fmt.Errorf("Error expanding `network_interface`: %+v", err) } @@ -751,12 +750,12 @@ func resourceArmWindowsVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta updateInstances = true bootDiagnosticsRaw := d.Get("boot_diagnostics").([]interface{}) - updateProps.VirtualMachineProfile.DiagnosticsProfile = computeSvc.ExpandVirtualMachineScaleSetBootDiagnostics(bootDiagnosticsRaw) + updateProps.VirtualMachineProfile.DiagnosticsProfile = ExpandVirtualMachineScaleSetBootDiagnostics(bootDiagnosticsRaw) } if d.HasChange("identity") { identityRaw := d.Get("identity").([]interface{}) - identity, err := computeSvc.ExpandVirtualMachineScaleSetIdentity(identityRaw) + identity, err := ExpandVirtualMachineScaleSetIdentity(identityRaw) if err != nil { return fmt.Errorf("Error expanding `identity`: %+v", err) } @@ -766,7 +765,7 @@ func resourceArmWindowsVirtualMachineScaleSetUpdate(d *schema.ResourceData, meta if d.HasChange("plan") { planRaw := d.Get("plan").([]interface{}) - update.Plan = computeSvc.ExpandPlan(planRaw) + update.Plan = ExpandPlan(planRaw) } if d.HasChange("sku") || d.HasChange("instances") { @@ -880,7 +879,7 @@ func resourceArmWindowsVirtualMachineScaleSetRead(d *schema.ResourceData, meta i ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := computeSvc.ParseVirtualMachineScaleSetID(d.Id()) + id, err := ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } @@ -913,11 +912,11 @@ func resourceArmWindowsVirtualMachineScaleSetRead(d *schema.ResourceData, meta i d.Set("instances", instances) d.Set("sku", skuName) - if err := d.Set("identity", computeSvc.FlattenVirtualMachineScaleSetIdentity(resp.Identity)); err != nil { + if err := d.Set("identity", FlattenVirtualMachineScaleSetIdentity(resp.Identity)); err != nil { return fmt.Errorf("Error setting `identity`: %+v", err) } - if err := d.Set("plan", computeSvc.FlattenPlan(resp.Plan)); err != nil { + if err := d.Set("plan", FlattenPlan(resp.Plan)); err != nil { return fmt.Errorf("Error setting `plan`: %+v", err) } @@ -926,7 +925,7 @@ func resourceArmWindowsVirtualMachineScaleSetRead(d *schema.ResourceData, meta i } props := *resp.VirtualMachineScaleSetProperties - if err := d.Set("additional_capabilities", computeSvc.FlattenVirtualMachineScaleSetAdditionalCapabilities(props.AdditionalCapabilities)); err != nil { + if err := d.Set("additional_capabilities", FlattenVirtualMachineScaleSetAdditionalCapabilities(props.AdditionalCapabilities)); err != nil { return fmt.Errorf("Error setting `additional_capabilities`: %+v", props.AdditionalCapabilities) } @@ -946,19 +945,19 @@ func resourceArmWindowsVirtualMachineScaleSetRead(d *schema.ResourceData, meta i upgradeMode = policy.Mode d.Set("upgrade_mode", string(policy.Mode)) - flattenedAutomatic := computeSvc.FlattenVirtualMachineScaleSetAutomaticOSUpgradePolicy(policy.AutomaticOSUpgradePolicy) + flattenedAutomatic := FlattenVirtualMachineScaleSetAutomaticOSUpgradePolicy(policy.AutomaticOSUpgradePolicy) if err := d.Set("automatic_os_upgrade_policy", flattenedAutomatic); err != nil { return fmt.Errorf("Error setting `automatic_os_upgrade_policy`: %+v", err) } - flattenedRolling := computeSvc.FlattenVirtualMachineScaleSetRollingUpgradePolicy(policy.RollingUpgradePolicy) + flattenedRolling := FlattenVirtualMachineScaleSetRollingUpgradePolicy(policy.RollingUpgradePolicy) if err := d.Set("rolling_upgrade_policy", flattenedRolling); err != nil { return fmt.Errorf("Error setting `rolling_upgrade_policy`: %+v", err) } } if profile := props.VirtualMachineProfile; profile != nil { - if err := d.Set("boot_diagnostics", computeSvc.FlattenVirtualMachineScaleSetBootDiagnostics(profile.DiagnosticsProfile)); err != nil { + if err := d.Set("boot_diagnostics", FlattenVirtualMachineScaleSetBootDiagnostics(profile.DiagnosticsProfile)); err != nil { return fmt.Errorf("Error setting `boot_diagnostics`: %+v", err) } @@ -974,15 +973,15 @@ func resourceArmWindowsVirtualMachineScaleSetRead(d *schema.ResourceData, meta i d.Set("priority", string(profile.Priority)) if storageProfile := profile.StorageProfile; storageProfile != nil { - if err := d.Set("os_disk", computeSvc.FlattenVirtualMachineScaleSetOSDisk(storageProfile.OsDisk)); err != nil { + if err := d.Set("os_disk", FlattenVirtualMachineScaleSetOSDisk(storageProfile.OsDisk)); err != nil { return fmt.Errorf("Error setting `os_disk`: %+v", err) } - if err := d.Set("data_disk", computeSvc.FlattenVirtualMachineScaleSetDataDisk(storageProfile.DataDisks)); err != nil { + if err := d.Set("data_disk", FlattenVirtualMachineScaleSetDataDisk(storageProfile.DataDisks)); err != nil { return fmt.Errorf("Error setting `data_disk`: %+v", err) } - if err := d.Set("source_image_reference", computeSvc.FlattenVirtualMachineScaleSetSourceImageReference(storageProfile.ImageReference)); err != nil { + if err := d.Set("source_image_reference", FlattenVirtualMachineScaleSetSourceImageReference(storageProfile.ImageReference)); err != nil { return fmt.Errorf("Error setting `source_image_reference`: %+v", err) } @@ -1029,7 +1028,7 @@ func resourceArmWindowsVirtualMachineScaleSetRead(d *schema.ResourceData, meta i } if nwProfile := profile.NetworkProfile; nwProfile != nil { - flattenedNics := computeSvc.FlattenVirtualMachineScaleSetNetworkInterface(nwProfile.NetworkInterfaceConfigurations) + flattenedNics := FlattenVirtualMachineScaleSetNetworkInterface(nwProfile.NetworkInterfaceConfigurations) if err := d.Set("network_interface", flattenedNics); err != nil { return fmt.Errorf("Error setting `network_interface`: %+v", err) } @@ -1054,7 +1053,7 @@ func resourceArmWindowsVirtualMachineScaleSetDelete(d *schema.ResourceData, meta ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := computeSvc.ParseVirtualMachineScaleSetID(d.Id()) + id, err := ParseVirtualMachineScaleSetID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_windows_virtual_machine_scale_set_auth_test.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_auth_test.go similarity index 99% rename from azurerm/resource_arm_windows_virtual_machine_scale_set_auth_test.go rename to azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_auth_test.go index d12faae0225b..1471bd25c8f5 100644 --- a/azurerm/resource_arm_windows_virtual_machine_scale_set_auth_test.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_auth_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go similarity index 99% rename from azurerm/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go rename to azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go index 81000e8605f7..079abf6ed00b 100644 --- a/azurerm/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go similarity index 99% rename from azurerm/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go rename to azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go index e8b5001de28e..4b374cd233e4 100644 --- a/azurerm/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_windows_virtual_machine_scale_set_identity_test.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_identity_test.go similarity index 99% rename from azurerm/resource_arm_windows_virtual_machine_scale_set_identity_test.go rename to azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_identity_test.go index 20098fdb64d8..f0e9f08f9a14 100644 --- a/azurerm/resource_arm_windows_virtual_machine_scale_set_identity_test.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_identity_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_windows_virtual_machine_scale_set_images_test.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_images_test.go similarity index 99% rename from azurerm/resource_arm_windows_virtual_machine_scale_set_images_test.go rename to azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_images_test.go index 2324bf61752c..d748a56cafbf 100644 --- a/azurerm/resource_arm_windows_virtual_machine_scale_set_images_test.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_images_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_windows_virtual_machine_scale_set_network_test.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_network_test.go similarity index 99% rename from azurerm/resource_arm_windows_virtual_machine_scale_set_network_test.go rename to azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_network_test.go index ba83bb5802cf..4914237e81fb 100644 --- a/azurerm/resource_arm_windows_virtual_machine_scale_set_network_test.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_network_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_windows_virtual_machine_scale_set_other_test.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_other_test.go similarity index 99% rename from azurerm/resource_arm_windows_virtual_machine_scale_set_other_test.go rename to azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_other_test.go index 22d263fcb7d5..f380e7400ff0 100644 --- a/azurerm/resource_arm_windows_virtual_machine_scale_set_other_test.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_other_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_windows_virtual_machine_scale_set_scaling_test.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_scaling_test.go similarity index 99% rename from azurerm/resource_arm_windows_virtual_machine_scale_set_scaling_test.go rename to azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_scaling_test.go index c2ca11cbadf9..52a121cd671f 100644 --- a/azurerm/resource_arm_windows_virtual_machine_scale_set_scaling_test.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_scaling_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_windows_virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_test.go similarity index 99% rename from azurerm/resource_arm_windows_virtual_machine_scale_set_test.go rename to azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_test.go index ed8a260dc0e5..3b89cf061f2d 100644 --- a/azurerm/resource_arm_windows_virtual_machine_scale_set_test.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 958db7a8c1f4..911dcf1b252b 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -3,7 +3,6 @@ package azurerm import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider" ) @@ -14,7 +13,6 @@ func Provider() terraform.ResourceProvider { "azurerm_app_service": dataSourceArmAppService(), "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_availability_set": dataSourceArmAvailabilitySet(), "azurerm_azuread_application": dataSourceArmAzureADApplication(), "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), @@ -43,7 +41,6 @@ func Provider() terraform.ResourceProvider { "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), "azurerm_log_analytics_workspace": dataSourceLogAnalyticsWorkspace(), "azurerm_logic_app_workflow": dataSourceArmLogicAppWorkflow(), - "azurerm_managed_disk": dataSourceArmManagedDisk(), "azurerm_management_group": dataSourceArmManagementGroup(), "azurerm_monitor_action_group": dataSourceArmMonitorActionGroup(), "azurerm_monitor_diagnostic_categories": dataSourceArmMonitorDiagnosticCategories(), @@ -79,10 +76,6 @@ func Provider() terraform.ResourceProvider { "azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(), "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), "azurerm_servicebus_namespace_authorization_rule": dataSourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_shared_image_gallery": dataSourceArmSharedImageGallery(), - "azurerm_shared_image_version": dataSourceArmSharedImageVersion(), - "azurerm_shared_image": dataSourceArmSharedImage(), - "azurerm_snapshot": dataSourceArmSnapshot(), "azurerm_sql_server": dataSourceSqlServer(), "azurerm_sql_database": dataSourceSqlDatabase(), "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), @@ -116,7 +109,6 @@ func Provider() terraform.ResourceProvider { "azurerm_application_gateway": resourceArmApplicationGateway(), "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_availability_set": resourceArmAvailabilitySet(), "azurerm_azuread_application": resourceArmActiveDirectoryApplication(), "azurerm_azuread_service_principal_password": resourceArmActiveDirectoryServicePrincipalPassword(), "azurerm_azuread_service_principal": resourceArmActiveDirectoryServicePrincipal(), @@ -245,7 +237,6 @@ func Provider() terraform.ResourceProvider { "azurerm_logic_app_trigger_http_request": resourceArmLogicAppTriggerHttpRequest(), "azurerm_logic_app_trigger_recurrence": resourceArmLogicAppTriggerRecurrence(), "azurerm_logic_app_workflow": resourceArmLogicAppWorkflow(), - "azurerm_managed_disk": resourceArmManagedDisk(), "azurerm_management_group": resourceArmManagementGroup(), "azurerm_management_lock": resourceArmManagementLock(), "azurerm_maps_account": resourceArmMapsAccount(), @@ -358,7 +349,6 @@ func Provider() terraform.ResourceProvider { "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), - "azurerm_snapshot": resourceArmSnapshot(), "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), "azurerm_sql_database": resourceArmSqlDatabase(), "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), @@ -397,10 +387,6 @@ func Provider() terraform.ResourceProvider { "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), "azurerm_user_assigned_identity": resourceArmUserAssignedIdentity(), "azurerm_virtual_hub": resourceArmVirtualHub(), - "azurerm_virtual_machine_data_disk_attachment": resourceArmVirtualMachineDataDiskAttachment(), - "azurerm_virtual_machine_extension": resourceArmVirtualMachineExtensions(), - "azurerm_virtual_machine_scale_set": resourceArmVirtualMachineScaleSet(), - "azurerm_virtual_machine": resourceArmVirtualMachine(), "azurerm_virtual_network_gateway_connection": resourceArmVirtualNetworkGatewayConnection(), "azurerm_virtual_network_gateway": resourceArmVirtualNetworkGateway(), "azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(), @@ -411,12 +397,5 @@ func Provider() terraform.ResourceProvider { "azurerm_web_application_firewall_policy": resourceArmWebApplicationFirewallPolicy(), } - // 2.0 resources - if features.SupportsTwoPointZeroResources() { - resources["azurerm_linux_virtual_machine_scale_set"] = resourceArmLinuxVirtualMachineScaleSet() - resources["azurerm_virtual_machine_scale_set_extension"] = resourceArmVirtualMachineScaleSetExtension() - resources["azurerm_windows_virtual_machine_scale_set"] = resourceArmWindowsVirtualMachineScaleSet() - } - return provider.AzureProvider(dataSources, resources) } diff --git a/azurerm/resource_arm_metric_alertrule_test.go b/azurerm/resource_arm_metric_alertrule_test.go index b2e1bef5d9bd..de6c8a6fc3b2 100644 --- a/azurerm/resource_arm_metric_alertrule_test.go +++ b/azurerm/resource_arm_metric_alertrule_test.go @@ -2,6 +2,7 @@ package azurerm import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -216,7 +217,7 @@ func testCheckAzureRMMetricAlertRuleDestroy(s *terraform.State) error { } func testAccAzureRMMetricAlertRule_virtualMachineCpu(rInt int, location string, enabled bool) string { - template := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt, location) + template := compute.testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt, location) return fmt.Sprintf(` %s diff --git a/azurerm/resource_arm_monitor_metric_alertrule_test.go b/azurerm/resource_arm_monitor_metric_alertrule_test.go index 07c2f6c71d25..4afffa47f5c4 100644 --- a/azurerm/resource_arm_monitor_metric_alertrule_test.go +++ b/azurerm/resource_arm_monitor_metric_alertrule_test.go @@ -2,6 +2,7 @@ package azurerm import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -216,7 +217,7 @@ func testCheckAzureRMMonitorMetricAlertRuleDestroy(s *terraform.State) error { } func testAccAzureRMMonitorMetricAlertRule_virtualMachineCpu(rInt int, location string, enabled bool) string { - template := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt, location) + template := compute.testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt, location) return fmt.Sprintf(` %s From 381c4c883e5e142e3e6e4458fd4c648be8d19e59 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:32:25 -0800 Subject: [PATCH 016/203] containers --- .../data_source_container_registry.go | 2 +- .../data_source_container_registry_test.go | 2 +- .../data_source_kubernetes_cluster.go | 2 +- .../data_source_kubernetes_cluster_test.go | 2 +- .../data_source_kubernetes_service_version.go | 2 +- ..._source_kubernetes_service_version_test.go | 2 +- .../services/containers/registration.go | 15 ++++++++-- .../resource_arm_container_group.go | 2 +- .../resource_arm_container_group_test.go | 2 +- .../resource_arm_container_registry.go | 2 +- ...resource_arm_container_registry_migrate.go | 2 +- ...rce_arm_container_registry_migrate_test.go | 2 +- .../resource_arm_container_registry_test.go | 2 +- ...resource_arm_container_registry_webhook.go | 2 +- ...rce_arm_container_registry_webhook_test.go | 2 +- .../resource_arm_container_service.go | 2 +- .../resource_arm_container_service_test.go | 2 +- .../resource_arm_kubernetes_cluster.go | 29 +++++++++---------- ...urce_arm_kubernetes_cluster_addons_test.go | 2 +- ...source_arm_kubernetes_cluster_auth_test.go | 2 +- ...urce_arm_kubernetes_cluster_legacy_test.go | 2 +- ...rce_arm_kubernetes_cluster_network_test.go | 2 +- ...source_arm_kubernetes_cluster_node_pool.go | 15 +++++----- ...e_arm_kubernetes_cluster_node_pool_test.go | 7 ++--- ...ource_arm_kubernetes_cluster_other_test.go | 2 +- ...rce_arm_kubernetes_cluster_scaling_test.go | 2 +- .../resource_arm_kubernetes_cluster_test.go | 2 +- azurerm/provider.go | 9 ------ 28 files changed, 60 insertions(+), 61 deletions(-) rename azurerm/{ => internal/services/containers}/data_source_container_registry.go (99%) rename azurerm/{ => internal/services/containers}/data_source_container_registry_test.go (98%) rename azurerm/{ => internal/services/containers}/data_source_kubernetes_cluster.go (99%) rename azurerm/{ => internal/services/containers}/data_source_kubernetes_cluster_test.go (99%) rename azurerm/{ => internal/services/containers}/data_source_kubernetes_service_version.go (99%) rename azurerm/{ => internal/services/containers}/data_source_kubernetes_service_version_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_container_group.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_container_group_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_container_registry.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_container_registry_migrate.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_container_registry_migrate_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_container_registry_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_container_registry_webhook.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_container_registry_webhook_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_container_service.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_container_service_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_kubernetes_cluster.go (98%) rename azurerm/{ => internal/services/containers}/resource_arm_kubernetes_cluster_addons_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_kubernetes_cluster_auth_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_kubernetes_cluster_legacy_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_kubernetes_cluster_network_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_kubernetes_cluster_node_pool.go (97%) rename azurerm/{ => internal/services/containers}/resource_arm_kubernetes_cluster_node_pool_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_kubernetes_cluster_other_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_kubernetes_cluster_scaling_test.go (99%) rename azurerm/{ => internal/services/containers}/resource_arm_kubernetes_cluster_test.go (99%) diff --git a/azurerm/data_source_container_registry.go b/azurerm/internal/services/containers/data_source_container_registry.go similarity index 99% rename from azurerm/data_source_container_registry.go rename to azurerm/internal/services/containers/data_source_container_registry.go index 3793a6fc4521..d2bfdf96bc8c 100644 --- a/azurerm/data_source_container_registry.go +++ b/azurerm/internal/services/containers/data_source_container_registry.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/data_source_container_registry_test.go b/azurerm/internal/services/containers/data_source_container_registry_test.go similarity index 98% rename from azurerm/data_source_container_registry_test.go rename to azurerm/internal/services/containers/data_source_container_registry_test.go index 5cd915dd0558..3488b7f2fa57 100644 --- a/azurerm/data_source_container_registry_test.go +++ b/azurerm/internal/services/containers/data_source_container_registry_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/data_source_kubernetes_cluster.go b/azurerm/internal/services/containers/data_source_kubernetes_cluster.go similarity index 99% rename from azurerm/data_source_kubernetes_cluster.go rename to azurerm/internal/services/containers/data_source_kubernetes_cluster.go index 01336a6a81b4..f7d490245587 100644 --- a/azurerm/data_source_kubernetes_cluster.go +++ b/azurerm/internal/services/containers/data_source_kubernetes_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/data_source_kubernetes_cluster_test.go b/azurerm/internal/services/containers/data_source_kubernetes_cluster_test.go similarity index 99% rename from azurerm/data_source_kubernetes_cluster_test.go rename to azurerm/internal/services/containers/data_source_kubernetes_cluster_test.go index ad0c29ae5a41..ea3c09749d6a 100644 --- a/azurerm/data_source_kubernetes_cluster_test.go +++ b/azurerm/internal/services/containers/data_source_kubernetes_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/data_source_kubernetes_service_version.go b/azurerm/internal/services/containers/data_source_kubernetes_service_version.go similarity index 99% rename from azurerm/data_source_kubernetes_service_version.go rename to azurerm/internal/services/containers/data_source_kubernetes_service_version.go index 66b3d575ebd0..0dbd0f78a45d 100644 --- a/azurerm/data_source_kubernetes_service_version.go +++ b/azurerm/internal/services/containers/data_source_kubernetes_service_version.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/data_source_kubernetes_service_version_test.go b/azurerm/internal/services/containers/data_source_kubernetes_service_version_test.go similarity index 99% rename from azurerm/data_source_kubernetes_service_version_test.go rename to azurerm/internal/services/containers/data_source_kubernetes_service_version_test.go index b81b40fbe69e..dbf0ba5741ac 100644 --- a/azurerm/data_source_kubernetes_service_version_test.go +++ b/azurerm/internal/services/containers/data_source_kubernetes_service_version_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/internal/services/containers/registration.go b/azurerm/internal/services/containers/registration.go index 726079b35e89..c89b5302c6e1 100644 --- a/azurerm/internal/services/containers/registration.go +++ b/azurerm/internal/services/containers/registration.go @@ -13,10 +13,21 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_kubernetes_service_versions": dataSourceArmKubernetesServiceVersions(), + "azurerm_container_registry": dataSourceArmContainerRegistry(), + "azurerm_kubernetes_cluster": dataSourceArmKubernetesCluster(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_container_group": resourceArmContainerGroup(), + "azurerm_container_registry_webhook": resourceArmContainerRegistryWebhook(), + "azurerm_container_registry": resourceArmContainerRegistry(), + "azurerm_container_service": resourceArmContainerService(), + "azurerm_kubernetes_cluster": resourceArmKubernetesCluster(), + "azurerm_kubernetes_cluster_node_pool": resourceArmKubernetesClusterNodePool(), + } } diff --git a/azurerm/resource_arm_container_group.go b/azurerm/internal/services/containers/resource_arm_container_group.go similarity index 99% rename from azurerm/resource_arm_container_group.go rename to azurerm/internal/services/containers/resource_arm_container_group.go index dfe8d832379f..56d90d32f6f4 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/internal/services/containers/resource_arm_container_group.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "bytes" diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/internal/services/containers/resource_arm_container_group_test.go similarity index 99% rename from azurerm/resource_arm_container_group_test.go rename to azurerm/internal/services/containers/resource_arm_container_group_test.go index d2a06e568a24..b9953c77048f 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/internal/services/containers/resource_arm_container_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_container_registry.go b/azurerm/internal/services/containers/resource_arm_container_registry.go similarity index 99% rename from azurerm/resource_arm_container_registry.go rename to azurerm/internal/services/containers/resource_arm_container_registry.go index 5de04cf547bb..53b4f91d6236 100644 --- a/azurerm/resource_arm_container_registry.go +++ b/azurerm/internal/services/containers/resource_arm_container_registry.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_container_registry_migrate.go b/azurerm/internal/services/containers/resource_arm_container_registry_migrate.go similarity index 99% rename from azurerm/resource_arm_container_registry_migrate.go rename to azurerm/internal/services/containers/resource_arm_container_registry_migrate.go index 3db54c52584b..631356ac1472 100644 --- a/azurerm/resource_arm_container_registry_migrate.go +++ b/azurerm/internal/services/containers/resource_arm_container_registry_migrate.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "context" diff --git a/azurerm/resource_arm_container_registry_migrate_test.go b/azurerm/internal/services/containers/resource_arm_container_registry_migrate_test.go similarity index 99% rename from azurerm/resource_arm_container_registry_migrate_test.go rename to azurerm/internal/services/containers/resource_arm_container_registry_migrate_test.go index e53dfca05c0b..ec24047dc9b0 100644 --- a/azurerm/resource_arm_container_registry_migrate_test.go +++ b/azurerm/internal/services/containers/resource_arm_container_registry_migrate_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "context" diff --git a/azurerm/resource_arm_container_registry_test.go b/azurerm/internal/services/containers/resource_arm_container_registry_test.go similarity index 99% rename from azurerm/resource_arm_container_registry_test.go rename to azurerm/internal/services/containers/resource_arm_container_registry_test.go index 8f8c80910d67..fc76dac2e989 100644 --- a/azurerm/resource_arm_container_registry_test.go +++ b/azurerm/internal/services/containers/resource_arm_container_registry_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_container_registry_webhook.go b/azurerm/internal/services/containers/resource_arm_container_registry_webhook.go similarity index 99% rename from azurerm/resource_arm_container_registry_webhook.go rename to azurerm/internal/services/containers/resource_arm_container_registry_webhook.go index 4dbd2545f69c..8805b0ca8248 100644 --- a/azurerm/resource_arm_container_registry_webhook.go +++ b/azurerm/internal/services/containers/resource_arm_container_registry_webhook.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_container_registry_webhook_test.go b/azurerm/internal/services/containers/resource_arm_container_registry_webhook_test.go similarity index 99% rename from azurerm/resource_arm_container_registry_webhook_test.go rename to azurerm/internal/services/containers/resource_arm_container_registry_webhook_test.go index e518362015ba..052d82cfe94f 100644 --- a/azurerm/resource_arm_container_registry_webhook_test.go +++ b/azurerm/internal/services/containers/resource_arm_container_registry_webhook_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_container_service.go b/azurerm/internal/services/containers/resource_arm_container_service.go similarity index 99% rename from azurerm/resource_arm_container_service.go rename to azurerm/internal/services/containers/resource_arm_container_service.go index 93e19873b103..b1a733ead174 100644 --- a/azurerm/resource_arm_container_service.go +++ b/azurerm/internal/services/containers/resource_arm_container_service.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "bytes" diff --git a/azurerm/resource_arm_container_service_test.go b/azurerm/internal/services/containers/resource_arm_container_service_test.go similarity index 99% rename from azurerm/resource_arm_container_service_test.go rename to azurerm/internal/services/containers/resource_arm_container_service_test.go index 008fbcf72e3c..c98bb5279c68 100644 --- a/azurerm/resource_arm_container_service_test.go +++ b/azurerm/internal/services/containers/resource_arm_container_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_kubernetes_cluster.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go similarity index 98% rename from azurerm/resource_arm_kubernetes_cluster.go rename to azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go index d4df82bc311c..49fc14c782c0 100644 --- a/azurerm/resource_arm_kubernetes_cluster.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" @@ -16,7 +16,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -31,7 +30,7 @@ func resourceArmKubernetesCluster() *schema.Resource { Delete: resourceArmKubernetesClusterDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := containers.ParseKubernetesClusterID(id) + _, err := ParseKubernetesClusterID(id) return err }), @@ -109,7 +108,7 @@ func resourceArmKubernetesCluster() *schema.Resource { ValidateFunc: validate.NoEmptyStrings, }, - "default_node_pool": containers.SchemaDefaultNodePool(), + "default_node_pool": SchemaDefaultNodePool(), // TODO: remove in 2.0 "agent_pool_profile": { @@ -261,7 +260,7 @@ func resourceArmKubernetesCluster() *schema.Resource { }, // Optional - "addon_profile": containers.SchemaKubernetesAddOnProfiles(), + "addon_profile": SchemaKubernetesAddOnProfiles(), "api_server_authorized_ip_ranges": { Type: schema.TypeSet, @@ -638,7 +637,7 @@ func resourceArmKubernetesClusterCreate(d *schema.ResourceData, meta interface{} linuxProfileRaw := d.Get("linux_profile").([]interface{}) linuxProfile := expandKubernetesClusterLinuxProfile(linuxProfileRaw) - agentProfiles, err := containers.ExpandDefaultNodePool(d) + agentProfiles, err := ExpandDefaultNodePool(d) if err != nil { return fmt.Errorf("Error expanding `default_node_pool`: %+v", err) } @@ -655,7 +654,7 @@ func resourceArmKubernetesClusterCreate(d *schema.ResourceData, meta interface{} } addOnProfilesRaw := d.Get("addon_profile").([]interface{}) - addonProfiles := containers.ExpandKubernetesAddOnProfiles(addOnProfilesRaw) + addonProfiles := ExpandKubernetesAddOnProfiles(addOnProfilesRaw) networkProfileRaw := d.Get("network_profile").([]interface{}) networkProfile := expandKubernetesClusterNetworkProfile(networkProfileRaw) @@ -747,7 +746,7 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{} log.Printf("[INFO] preparing arguments for Managed Kubernetes Cluster update.") - id, err := containers.ParseKubernetesClusterID(d.Id()) + id, err := ParseKubernetesClusterID(d.Id()) if err != nil { return err } @@ -795,7 +794,7 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{} if d.HasChange("addon_profile") { updateCluster = true addOnProfilesRaw := d.Get("addon_profile").([]interface{}) - addonProfiles := containers.ExpandKubernetesAddOnProfiles(addOnProfilesRaw) + addonProfiles := ExpandKubernetesAddOnProfiles(addOnProfilesRaw) existing.ManagedClusterProperties.AddonProfiles = addonProfiles } @@ -873,7 +872,7 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{} if d.HasChange("default_node_pool") || d.HasChange("agent_pool_profile") { log.Printf("[DEBUG] Updating of Default Node Pool..") - agentProfiles, err := containers.ExpandDefaultNodePool(d) + agentProfiles, err := ExpandDefaultNodePool(d) if err != nil { return fmt.Errorf("Error expanding `default_node_pool`: %+v", err) } @@ -889,7 +888,7 @@ func resourceArmKubernetesClusterUpdate(d *schema.ResourceData, meta interface{} agentProfiles = &agentProfilesLegacy } - agentProfile := containers.ConvertDefaultNodePoolToAgentPool(agentProfiles) + agentProfile := ConvertDefaultNodePoolToAgentPool(agentProfiles) agentPool, err := nodePoolsClient.CreateOrUpdate(ctx, resourceGroup, name, *agentProfile.Name, agentProfile) if err != nil { return fmt.Errorf("Error updating Default Node Pool %q (Resource Group %q): %+v", name, resourceGroup, err) @@ -937,7 +936,7 @@ func resourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{}) ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := containers.ParseKubernetesClusterID(d.Id()) + id, err := ParseKubernetesClusterID(d.Id()) if err != nil { return err } @@ -982,7 +981,7 @@ func resourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{}) d.Set("private_link_enabled", accessProfile.EnablePrivateCluster) } - addonProfiles := containers.FlattenKubernetesAddOnProfiles(props.AddonProfiles) + addonProfiles := FlattenKubernetesAddOnProfiles(props.AddonProfiles) if err := d.Set("addon_profile", addonProfiles); err != nil { return fmt.Errorf("Error setting `addon_profile`: %+v", err) } @@ -993,7 +992,7 @@ func resourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Error setting `agent_pool_profile`: %+v", err) } - flattenedDefaultNodePool, err := containers.FlattenDefaultNodePool(props.AgentPoolProfiles, d) + flattenedDefaultNodePool, err := FlattenDefaultNodePool(props.AgentPoolProfiles, d) if err != nil { return fmt.Errorf("Error flattening `default_node_pool`: %+v", err) } @@ -1062,7 +1061,7 @@ func resourceArmKubernetesClusterDelete(d *schema.ResourceData, meta interface{} ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := containers.ParseKubernetesClusterID(d.Id()) + id, err := ParseKubernetesClusterID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_kubernetes_cluster_addons_test.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_addons_test.go similarity index 99% rename from azurerm/resource_arm_kubernetes_cluster_addons_test.go rename to azurerm/internal/services/containers/resource_arm_kubernetes_cluster_addons_test.go index fcf1fd2c792d..4651b3317b0b 100644 --- a/azurerm/resource_arm_kubernetes_cluster_addons_test.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_addons_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_kubernetes_cluster_auth_test.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_auth_test.go similarity index 99% rename from azurerm/resource_arm_kubernetes_cluster_auth_test.go rename to azurerm/internal/services/containers/resource_arm_kubernetes_cluster_auth_test.go index 44a765924a10..463f6149819e 100644 --- a/azurerm/resource_arm_kubernetes_cluster_auth_test.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_auth_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_kubernetes_cluster_legacy_test.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_legacy_test.go similarity index 99% rename from azurerm/resource_arm_kubernetes_cluster_legacy_test.go rename to azurerm/internal/services/containers/resource_arm_kubernetes_cluster_legacy_test.go index 9d12434993f5..67e080589bef 100644 --- a/azurerm/resource_arm_kubernetes_cluster_legacy_test.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_legacy_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_kubernetes_cluster_network_test.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_network_test.go similarity index 99% rename from azurerm/resource_arm_kubernetes_cluster_network_test.go rename to azurerm/internal/services/containers/resource_arm_kubernetes_cluster_network_test.go index af92033e0d97..60d0fc1b1206 100644 --- a/azurerm/resource_arm_kubernetes_cluster_network_test.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_network_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_kubernetes_cluster_node_pool.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go similarity index 97% rename from azurerm/resource_arm_kubernetes_cluster_node_pool.go rename to azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go index 9ef7172b4957..320d91304ef8 100644 --- a/azurerm/resource_arm_kubernetes_cluster_node_pool.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" @@ -13,7 +13,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -27,7 +26,7 @@ func resourceArmKubernetesClusterNodePool() *schema.Resource { Delete: resourceArmKubernetesClusterNodePoolDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := containers.ParseKubernetesNodePoolID(id) + _, err := ParseKubernetesNodePoolID(id) return err }), @@ -46,7 +45,7 @@ func resourceArmKubernetesClusterNodePool() *schema.Resource { ValidateFunc: validate.KubernetesAgentPoolName, }, - "kubernetes_cluster_id": containers.KubernetesClusterIDSchema(), + "kubernetes_cluster_id": KubernetesClusterIDSchema(), "node_count": { Type: schema.TypeInt, @@ -141,7 +140,7 @@ func resourceArmKubernetesClusterNodePoolCreate(d *schema.ResourceData, meta int ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - kubernetesClusterId, err := containers.ParseKubernetesClusterID(d.Get("kubernetes_cluster_id").(string)) + kubernetesClusterId, err := ParseKubernetesClusterID(d.Get("kubernetes_cluster_id").(string)) if err != nil { return err } @@ -288,7 +287,7 @@ func resourceArmKubernetesClusterNodePoolUpdate(d *schema.ResourceData, meta int ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := containers.ParseKubernetesNodePoolID(d.Id()) + id, err := ParseKubernetesNodePoolID(d.Id()) if err != nil { return err } @@ -401,7 +400,7 @@ func resourceArmKubernetesClusterNodePoolRead(d *schema.ResourceData, meta inter ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := containers.ParseKubernetesNodePoolID(d.Id()) + id, err := ParseKubernetesNodePoolID(d.Id()) if err != nil { return err } @@ -489,7 +488,7 @@ func resourceArmKubernetesClusterNodePoolDelete(d *schema.ResourceData, meta int ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := containers.ParseKubernetesNodePoolID(d.Id()) + id, err := ParseKubernetesNodePoolID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_kubernetes_cluster_node_pool_test.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool_test.go similarity index 99% rename from azurerm/resource_arm_kubernetes_cluster_node_pool_test.go rename to azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool_test.go index 3347a2864ac5..93f92f197479 100644 --- a/azurerm/resource_arm_kubernetes_cluster_node_pool_test.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" @@ -13,7 +13,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers" ) func testAccAzureRMKubernetesClusterNodePool_autoScale(t *testing.T) { @@ -624,7 +623,7 @@ func testCheckAzureRMKubernetesClusterNodePoolDestroy(s *terraform.State) error name := rs.Primary.Attributes["name"] kubernetesClusterId := rs.Primary.Attributes["kubernetes_cluster_id"] - parsedK8sId, err := containers.ParseKubernetesClusterID(kubernetesClusterId) + parsedK8sId, err := ParseKubernetesClusterID(kubernetesClusterId) if err != nil { return fmt.Errorf("Error parsing kubernetes cluster id: %+v", err) } @@ -655,7 +654,7 @@ func testCheckAzureRMKubernetesNodePoolExists(resourceName string) resource.Test name := rs.Primary.Attributes["name"] kubernetesClusterId := rs.Primary.Attributes["kubernetes_cluster_id"] - parsedK8sId, err := containers.ParseKubernetesClusterID(kubernetesClusterId) + parsedK8sId, err := ParseKubernetesClusterID(kubernetesClusterId) if err != nil { return fmt.Errorf("Error parsing kubernetes cluster id: %+v", err) } diff --git a/azurerm/resource_arm_kubernetes_cluster_other_test.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_other_test.go similarity index 99% rename from azurerm/resource_arm_kubernetes_cluster_other_test.go rename to azurerm/internal/services/containers/resource_arm_kubernetes_cluster_other_test.go index 19de649160fe..b466b36c1532 100644 --- a/azurerm/resource_arm_kubernetes_cluster_other_test.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_other_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_kubernetes_cluster_scaling_test.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_scaling_test.go similarity index 99% rename from azurerm/resource_arm_kubernetes_cluster_scaling_test.go rename to azurerm/internal/services/containers/resource_arm_kubernetes_cluster_scaling_test.go index 4563755a9423..b3677d07255d 100644 --- a/azurerm/resource_arm_kubernetes_cluster_scaling_test.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_scaling_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/resource_arm_kubernetes_cluster_test.go b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_test.go similarity index 99% rename from azurerm/resource_arm_kubernetes_cluster_test.go rename to azurerm/internal/services/containers/resource_arm_kubernetes_cluster_test.go index df6d9bb5e323..5a8edbea85dd 100644 --- a/azurerm/resource_arm_kubernetes_cluster_test.go +++ b/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package containers import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 911dcf1b252b..88adcfdedd27 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -17,8 +17,6 @@ func Provider() terraform.ResourceProvider { "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_kubernetes_service_versions": dataSourceArmKubernetesServiceVersions(), - "azurerm_container_registry": dataSourceArmContainerRegistry(), "azurerm_cosmosdb_account": dataSourceArmCosmosDbAccount(), "azurerm_data_factory": dataSourceArmDataFactory(), "azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(), @@ -36,7 +34,6 @@ func Provider() terraform.ResourceProvider { "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), "azurerm_key_vault": dataSourceArmKeyVault(), - "azurerm_kubernetes_cluster": dataSourceArmKubernetesCluster(), "azurerm_lb": dataSourceArmLoadBalancer(), "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), "azurerm_log_analytics_workspace": dataSourceLogAnalyticsWorkspace(), @@ -119,10 +116,6 @@ func Provider() terraform.ResourceProvider { "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), "azurerm_bastion_host": resourceArmBastionHost(), "azurerm_connection_monitor": resourceArmConnectionMonitor(), - "azurerm_container_group": resourceArmContainerGroup(), - "azurerm_container_registry_webhook": resourceArmContainerRegistryWebhook(), - "azurerm_container_registry": resourceArmContainerRegistry(), - "azurerm_container_service": resourceArmContainerService(), "azurerm_cosmosdb_account": resourceArmCosmosDbAccount(), "azurerm_cosmosdb_cassandra_keyspace": resourceArmCosmosDbCassandraKeyspace(), "azurerm_cosmosdb_mongo_collection": resourceArmCosmosDbMongoCollection(), @@ -214,8 +207,6 @@ func Provider() terraform.ResourceProvider { "azurerm_key_vault_key": resourceArmKeyVaultKey(), "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), "azurerm_key_vault": resourceArmKeyVault(), - "azurerm_kubernetes_cluster": resourceArmKubernetesCluster(), - "azurerm_kubernetes_cluster_node_pool": resourceArmKubernetesClusterNodePool(), "azurerm_kusto_cluster": resourceArmKustoCluster(), "azurerm_kusto_database": resourceArmKustoDatabase(), "azurerm_kusto_eventhub_data_connection": resourceArmKustoEventHubDataConnection(), From de4a8d771b76bb3ba36157a5fd9cea364688f720 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:38:08 -0800 Subject: [PATCH 017/203] cosmos --- .../cosmos}/data_source_cosmos_db_account.go | 2 +- .../cosmos}/data_source_cosmos_db_account_test.go | 2 +- azurerm/internal/services/cosmos/registration.go | 13 +++++++++++-- .../cosmos}/resource_arm_cosmosdb_account.go | 2 +- .../resource_arm_cosmosdb_account_failover_test.go | 2 +- .../cosmos}/resource_arm_cosmosdb_account_test.go | 2 +- .../resource_arm_cosmosdb_cassandra_keyspace.go | 2 +- ...resource_arm_cosmosdb_cassandra_keyspace_test.go | 2 +- .../resource_arm_cosmosdb_mongo_collection.go | 2 +- .../resource_arm_cosmosdb_mongo_collection_test.go | 2 +- .../cosmos}/resource_arm_cosmosdb_mongo_database.go | 2 +- .../resource_arm_cosmosdb_mongo_database_test.go | 2 +- .../cosmos}/resource_arm_cosmosdb_sql_container.go | 2 +- .../resource_arm_cosmosdb_sql_container_test.go | 2 +- .../cosmos}/resource_arm_cosmosdb_sql_database.go | 2 +- .../resource_arm_cosmosdb_sql_database_test.go | 2 +- .../services/cosmos}/resource_arm_cosmosdb_table.go | 2 +- .../cosmos}/resource_arm_cosmosdb_table_test.go | 2 +- azurerm/provider.go | 8 -------- 19 files changed, 28 insertions(+), 27 deletions(-) rename azurerm/{ => internal/services/cosmos}/data_source_cosmos_db_account.go (99%) rename azurerm/{ => internal/services/cosmos}/data_source_cosmos_db_account_test.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_account.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_account_failover_test.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_account_test.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_cassandra_keyspace.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_cassandra_keyspace_test.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_mongo_collection.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_mongo_collection_test.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_mongo_database.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_mongo_database_test.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_sql_container.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_sql_container_test.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_sql_database.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_sql_database_test.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_table.go (99%) rename azurerm/{ => internal/services/cosmos}/resource_arm_cosmosdb_table_test.go (99%) diff --git a/azurerm/data_source_cosmos_db_account.go b/azurerm/internal/services/cosmos/data_source_cosmos_db_account.go similarity index 99% rename from azurerm/data_source_cosmos_db_account.go rename to azurerm/internal/services/cosmos/data_source_cosmos_db_account.go index 5bd044022df7..43ddda9aa929 100644 --- a/azurerm/data_source_cosmos_db_account.go +++ b/azurerm/internal/services/cosmos/data_source_cosmos_db_account.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/data_source_cosmos_db_account_test.go b/azurerm/internal/services/cosmos/data_source_cosmos_db_account_test.go similarity index 99% rename from azurerm/data_source_cosmos_db_account_test.go rename to azurerm/internal/services/cosmos/data_source_cosmos_db_account_test.go index 032f818fed40..e5b9b3d06d19 100644 --- a/azurerm/data_source_cosmos_db_account_test.go +++ b/azurerm/internal/services/cosmos/data_source_cosmos_db_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/internal/services/cosmos/registration.go b/azurerm/internal/services/cosmos/registration.go index e31c018cd467..ee333431573f 100644 --- a/azurerm/internal/services/cosmos/registration.go +++ b/azurerm/internal/services/cosmos/registration.go @@ -13,10 +13,19 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_cosmosdb_account": dataSourceArmCosmosDbAccount(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_cosmosdb_account": resourceArmCosmosDbAccount(), + "azurerm_cosmosdb_cassandra_keyspace": resourceArmCosmosDbCassandraKeyspace(), + "azurerm_cosmosdb_mongo_collection": resourceArmCosmosDbMongoCollection(), + "azurerm_cosmosdb_mongo_database": resourceArmCosmosDbMongoDatabase(), + "azurerm_cosmosdb_sql_container": resourceArmCosmosDbSQLContainer(), + "azurerm_cosmosdb_sql_database": resourceArmCosmosDbSQLDatabase(), + "azurerm_cosmosdb_table": resourceArmCosmosDbTable()} } diff --git a/azurerm/resource_arm_cosmosdb_account.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_account.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_account.go index 0d047d9b4da6..56c2f9032acc 100644 --- a/azurerm/resource_arm_cosmosdb_account.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "bytes" diff --git a/azurerm/resource_arm_cosmosdb_account_failover_test.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_failover_test.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_account_failover_test.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_failover_test.go index 9ce7651a7f88..6743b1aa4f2a 100644 --- a/azurerm/resource_arm_cosmosdb_account_failover_test.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_failover_test.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_account_test.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_test.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_account_test.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_test.go index 38cd77ce2e83..2892c1a42f6e 100644 --- a/azurerm/resource_arm_cosmosdb_account_test.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_cassandra_keyspace.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_cassandra_keyspace.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_cassandra_keyspace.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_cassandra_keyspace.go index a6b3caa66553..d9c9e6afaa29 100644 --- a/azurerm/resource_arm_cosmosdb_cassandra_keyspace.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_cassandra_keyspace.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_cassandra_keyspace_test.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_cassandra_keyspace_test.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_cassandra_keyspace_test.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_cassandra_keyspace_test.go index 11ed6cf8aa93..2c2dc3dc6499 100644 --- a/azurerm/resource_arm_cosmosdb_cassandra_keyspace_test.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_cassandra_keyspace_test.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_mongo_collection.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_mongo_collection.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection.go index 94157443e3ba..0cbc3e4f73a8 100644 --- a/azurerm/resource_arm_cosmosdb_mongo_collection.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_mongo_collection_test.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection_test.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_mongo_collection_test.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection_test.go index 1679845a9ea2..1b6177f57001 100644 --- a/azurerm/resource_arm_cosmosdb_mongo_collection_test.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection_test.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_mongo_database.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_database.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_mongo_database.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_database.go index 0067c03a5ad0..e2a91af46967 100644 --- a/azurerm/resource_arm_cosmosdb_mongo_database.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_database.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_mongo_database_test.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_database_test.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_mongo_database_test.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_database_test.go index cc3a1350bf81..3bfa31658f60 100644 --- a/azurerm/resource_arm_cosmosdb_mongo_database_test.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_database_test.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_sql_container.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_container.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_sql_container.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_container.go index a0c283c37b48..1f8db7e30414 100644 --- a/azurerm/resource_arm_cosmosdb_sql_container.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_container.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_sql_container_test.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_container_test.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_sql_container_test.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_container_test.go index b7bcb6f8d81a..59b0ee621449 100644 --- a/azurerm/resource_arm_cosmosdb_sql_container_test.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_container_test.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_sql_database.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_database.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_sql_database.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_database.go index 72b91648f74b..cc2809e9ce50 100644 --- a/azurerm/resource_arm_cosmosdb_sql_database.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_database.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_sql_database_test.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_database_test.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_sql_database_test.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_database_test.go index dbd87d5a8c84..7646fc2cf7f9 100644 --- a/azurerm/resource_arm_cosmosdb_sql_database_test.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_database_test.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_table.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_table.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_table.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_table.go index 76487d774aae..19b5d6f1783a 100644 --- a/azurerm/resource_arm_cosmosdb_table.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_table.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/resource_arm_cosmosdb_table_test.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_table_test.go similarity index 99% rename from azurerm/resource_arm_cosmosdb_table_test.go rename to azurerm/internal/services/cosmos/resource_arm_cosmosdb_table_test.go index 7d1e7550316a..1a5e8f9b8aca 100644 --- a/azurerm/resource_arm_cosmosdb_table_test.go +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_table_test.go @@ -1,4 +1,4 @@ -package azurerm +package cosmos import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 88adcfdedd27..3b1eeea97b15 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -17,7 +17,6 @@ func Provider() terraform.ResourceProvider { "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_cosmosdb_account": dataSourceArmCosmosDbAccount(), "azurerm_data_factory": dataSourceArmDataFactory(), "azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(), "azurerm_dev_test_lab": dataSourceArmDevTestLab(), @@ -116,13 +115,6 @@ func Provider() terraform.ResourceProvider { "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), "azurerm_bastion_host": resourceArmBastionHost(), "azurerm_connection_monitor": resourceArmConnectionMonitor(), - "azurerm_cosmosdb_account": resourceArmCosmosDbAccount(), - "azurerm_cosmosdb_cassandra_keyspace": resourceArmCosmosDbCassandraKeyspace(), - "azurerm_cosmosdb_mongo_collection": resourceArmCosmosDbMongoCollection(), - "azurerm_cosmosdb_mongo_database": resourceArmCosmosDbMongoDatabase(), - "azurerm_cosmosdb_sql_container": resourceArmCosmosDbSQLContainer(), - "azurerm_cosmosdb_sql_database": resourceArmCosmosDbSQLDatabase(), - "azurerm_cosmosdb_table": resourceArmCosmosDbTable(), "azurerm_dashboard": resourceArmDashboard(), "azurerm_data_factory": resourceArmDataFactory(), "azurerm_data_factory_dataset_mysql": resourceArmDataFactoryDatasetMySQL(), From 03ff18250ce45860ddae8e2275305d85914a5268 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:40:21 -0800 Subject: [PATCH 018/203] databricks --- azurerm/internal/services/databricks/registration.go | 4 +++- .../services/databricks}/resource_arm_databricks_workspace.go | 2 +- .../databricks}/resource_arm_databricks_workspace_test.go | 2 +- azurerm/provider.go | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) rename azurerm/{ => internal/services/databricks}/resource_arm_databricks_workspace.go (99%) rename azurerm/{ => internal/services/databricks}/resource_arm_databricks_workspace_test.go (99%) diff --git a/azurerm/internal/services/databricks/registration.go b/azurerm/internal/services/databricks/registration.go index 099849e11d03..e68248aed3a2 100644 --- a/azurerm/internal/services/databricks/registration.go +++ b/azurerm/internal/services/databricks/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_databricks_workspace": resourceArmDatabricksWorkspace(), + } } diff --git a/azurerm/resource_arm_databricks_workspace.go b/azurerm/internal/services/databricks/resource_arm_databricks_workspace.go similarity index 99% rename from azurerm/resource_arm_databricks_workspace.go rename to azurerm/internal/services/databricks/resource_arm_databricks_workspace.go index 6f5a47b91cba..22afad1ff207 100644 --- a/azurerm/resource_arm_databricks_workspace.go +++ b/azurerm/internal/services/databricks/resource_arm_databricks_workspace.go @@ -1,4 +1,4 @@ -package azurerm +package databricks import ( "fmt" diff --git a/azurerm/resource_arm_databricks_workspace_test.go b/azurerm/internal/services/databricks/resource_arm_databricks_workspace_test.go similarity index 99% rename from azurerm/resource_arm_databricks_workspace_test.go rename to azurerm/internal/services/databricks/resource_arm_databricks_workspace_test.go index 6eeb7a2075c6..5be6ac19924e 100644 --- a/azurerm/resource_arm_databricks_workspace_test.go +++ b/azurerm/internal/services/databricks/resource_arm_databricks_workspace_test.go @@ -1,4 +1,4 @@ -package azurerm +package databricks import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 3b1eeea97b15..77dfdeebdb60 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -132,7 +132,6 @@ func Provider() terraform.ResourceProvider { "azurerm_data_lake_store_file": resourceArmDataLakeStoreFile(), "azurerm_data_lake_store_firewall_rule": resourceArmDataLakeStoreFirewallRule(), "azurerm_data_lake_store": resourceArmDataLakeStore(), - "azurerm_databricks_workspace": resourceArmDatabricksWorkspace(), "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), "azurerm_dev_test_lab": resourceArmDevTestLab(), "azurerm_dev_test_schedule": resourceArmDevTestLabSchedules(), From 2e998cb4b2f61fb665572ad3eccb0d32937a9df1 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:47:43 -0800 Subject: [PATCH 019/203] datafactory --- .../services/datafactory}/data_factory.go | 2 +- .../services/datafactory}/data_factory_test.go | 2 +- .../datafactory}/data_source_data_factory.go | 2 +- .../data_source_data_factory_test.go | 2 +- .../services/datafactory/registration.go | 18 ++++++++++++++++-- .../datafactory}/resource_arm_data_factory.go | 2 +- .../resource_arm_data_factory_dataset_mysql.go | 2 +- ...urce_arm_data_factory_dataset_mysql_test.go | 2 +- ...urce_arm_data_factory_dataset_postgresql.go | 2 +- ...arm_data_factory_dataset_postgresql_test.go | 2 +- ...rm_data_factory_dataset_sql_server_table.go | 2 +- ...ta_factory_dataset_sql_server_table_test.go | 2 +- ...data_factory_integration_runtime_managed.go | 2 +- ...factory_integration_runtime_managed_test.go | 2 +- ...ry_linked_service_data_lake_storage_gen2.go | 2 +- ...nked_service_data_lake_storage_gen2_test.go | 2 +- ...ce_arm_data_factory_linked_service_mysql.go | 2 +- ...m_data_factory_linked_service_mysql_test.go | 2 +- ...m_data_factory_linked_service_postgresql.go | 2 +- ...a_factory_linked_service_postgresql_test.go | 2 +- ...m_data_factory_linked_service_sql_server.go | 2 +- ...a_factory_linked_service_sql_server_test.go | 2 +- .../resource_arm_data_factory_pipeline.go | 2 +- .../resource_arm_data_factory_pipeline_test.go | 2 +- .../resource_arm_data_factory_test.go | 2 +- ...source_arm_data_factory_trigger_schedule.go | 2 +- ...e_arm_data_factory_trigger_schedule_test.go | 2 +- azurerm/provider.go | 12 ------------ 28 files changed, 42 insertions(+), 40 deletions(-) rename azurerm/{ => internal/services/datafactory}/data_factory.go (99%) rename azurerm/{ => internal/services/datafactory}/data_factory_test.go (98%) rename azurerm/{ => internal/services/datafactory}/data_source_data_factory.go (99%) rename azurerm/{ => internal/services/datafactory}/data_source_data_factory_test.go (98%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_dataset_mysql.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_dataset_mysql_test.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_dataset_postgresql.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_dataset_postgresql_test.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_dataset_sql_server_table.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_dataset_sql_server_table_test.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_integration_runtime_managed.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_integration_runtime_managed_test.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_linked_service_data_lake_storage_gen2.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_linked_service_mysql.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_linked_service_mysql_test.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_linked_service_postgresql.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_linked_service_postgresql_test.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_linked_service_sql_server.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_linked_service_sql_server_test.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_pipeline.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_pipeline_test.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_test.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_trigger_schedule.go (99%) rename azurerm/{ => internal/services/datafactory}/resource_arm_data_factory_trigger_schedule_test.go (99%) diff --git a/azurerm/data_factory.go b/azurerm/internal/services/datafactory/data_factory.go similarity index 99% rename from azurerm/data_factory.go rename to azurerm/internal/services/datafactory/data_factory.go index c3602ed6e824..7b440aa37838 100644 --- a/azurerm/data_factory.go +++ b/azurerm/internal/services/datafactory/data_factory.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/data_factory_test.go b/azurerm/internal/services/datafactory/data_factory_test.go similarity index 98% rename from azurerm/data_factory_test.go rename to azurerm/internal/services/datafactory/data_factory_test.go index 1424fe672118..74966406cdf8 100644 --- a/azurerm/data_factory_test.go +++ b/azurerm/internal/services/datafactory/data_factory_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import "testing" diff --git a/azurerm/data_source_data_factory.go b/azurerm/internal/services/datafactory/data_source_data_factory.go similarity index 99% rename from azurerm/data_source_data_factory.go rename to azurerm/internal/services/datafactory/data_source_data_factory.go index a216c59b15d0..6c265010a33a 100644 --- a/azurerm/data_source_data_factory.go +++ b/azurerm/internal/services/datafactory/data_source_data_factory.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/data_source_data_factory_test.go b/azurerm/internal/services/datafactory/data_source_data_factory_test.go similarity index 98% rename from azurerm/data_source_data_factory_test.go rename to azurerm/internal/services/datafactory/data_source_data_factory_test.go index ce03e0275c88..9e0da6328bc1 100644 --- a/azurerm/data_source_data_factory_test.go +++ b/azurerm/internal/services/datafactory/data_source_data_factory_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/internal/services/datafactory/registration.go b/azurerm/internal/services/datafactory/registration.go index cf219da909ba..a47d4dd56da7 100644 --- a/azurerm/internal/services/datafactory/registration.go +++ b/azurerm/internal/services/datafactory/registration.go @@ -13,10 +13,24 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_data_factory": dataSourceArmDataFactory(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_data_factory": resourceArmDataFactory(), + "azurerm_data_factory_dataset_mysql": resourceArmDataFactoryDatasetMySQL(), + "azurerm_data_factory_dataset_postgresql": resourceArmDataFactoryDatasetPostgreSQL(), + "azurerm_data_factory_dataset_sql_server_table": resourceArmDataFactoryDatasetSQLServerTable(), + "azurerm_data_factory_integration_runtime_managed": resourceArmDataFactoryIntegrationRuntimeManaged(), + "azurerm_data_factory_linked_service_data_lake_storage_gen2": resourceArmDataFactoryLinkedServiceDataLakeStorageGen2(), + "azurerm_data_factory_linked_service_mysql": resourceArmDataFactoryLinkedServiceMySQL(), + "azurerm_data_factory_linked_service_postgresql": resourceArmDataFactoryLinkedServicePostgreSQL(), + "azurerm_data_factory_linked_service_sql_server": resourceArmDataFactoryLinkedServiceSQLServer(), + "azurerm_data_factory_pipeline": resourceArmDataFactoryPipeline(), + "azurerm_data_factory_trigger_schedule": resourceArmDataFactoryTriggerSchedule(), + } } diff --git a/azurerm/resource_arm_data_factory.go b/azurerm/internal/services/datafactory/resource_arm_data_factory.go similarity index 99% rename from azurerm/resource_arm_data_factory.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory.go index 62c33e218cc3..2dd3da69ea3b 100644 --- a/azurerm/resource_arm_data_factory.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_dataset_mysql.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_mysql.go similarity index 99% rename from azurerm/resource_arm_data_factory_dataset_mysql.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_mysql.go index d218d3fec247..758eada940b4 100644 --- a/azurerm/resource_arm_data_factory_dataset_mysql.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_mysql.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_dataset_mysql_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_mysql_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_dataset_mysql_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_mysql_test.go index 56dadfab58af..973ac055ad9b 100644 --- a/azurerm/resource_arm_data_factory_dataset_mysql_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_mysql_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_dataset_postgresql.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_postgresql.go similarity index 99% rename from azurerm/resource_arm_data_factory_dataset_postgresql.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_postgresql.go index e81431210291..5700b574e0cd 100644 --- a/azurerm/resource_arm_data_factory_dataset_postgresql.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_postgresql.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_dataset_postgresql_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_postgresql_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_dataset_postgresql_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_postgresql_test.go index 94d0272b2b4c..f92352873672 100644 --- a/azurerm/resource_arm_data_factory_dataset_postgresql_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_postgresql_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_dataset_sql_server_table.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_sql_server_table.go similarity index 99% rename from azurerm/resource_arm_data_factory_dataset_sql_server_table.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_sql_server_table.go index 4786c990af51..7e9377caceba 100644 --- a/azurerm/resource_arm_data_factory_dataset_sql_server_table.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_sql_server_table.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_dataset_sql_server_table_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_sql_server_table_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_dataset_sql_server_table_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_sql_server_table_test.go index da3abd50147d..db8875e34e8b 100644 --- a/azurerm/resource_arm_data_factory_dataset_sql_server_table_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_sql_server_table_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_integration_runtime_managed.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_integration_runtime_managed.go similarity index 99% rename from azurerm/resource_arm_data_factory_integration_runtime_managed.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_integration_runtime_managed.go index d100b6ff4862..23fe868998b1 100644 --- a/azurerm/resource_arm_data_factory_integration_runtime_managed.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_integration_runtime_managed.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_integration_runtime_managed_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_integration_runtime_managed_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_integration_runtime_managed_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_integration_runtime_managed_test.go index 068df41cf448..d98a2838d085 100644 --- a/azurerm/resource_arm_data_factory_integration_runtime_managed_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_integration_runtime_managed_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_linked_service_data_lake_storage_gen2.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_data_lake_storage_gen2.go similarity index 99% rename from azurerm/resource_arm_data_factory_linked_service_data_lake_storage_gen2.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_data_lake_storage_gen2.go index 82e3aff5c9dd..acc8b92db081 100644 --- a/azurerm/resource_arm_data_factory_linked_service_data_lake_storage_gen2.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_data_lake_storage_gen2.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go index df688de1d846..fbe32791b560 100644 --- a/azurerm/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_linked_service_mysql.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_mysql.go similarity index 99% rename from azurerm/resource_arm_data_factory_linked_service_mysql.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_mysql.go index 2538f8678d8e..82d82e878bd4 100644 --- a/azurerm/resource_arm_data_factory_linked_service_mysql.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_mysql.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_linked_service_mysql_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_mysql_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_linked_service_mysql_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_mysql_test.go index bb2b61e417b2..7c1f0ec46177 100644 --- a/azurerm/resource_arm_data_factory_linked_service_mysql_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_mysql_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_linked_service_postgresql.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_postgresql.go similarity index 99% rename from azurerm/resource_arm_data_factory_linked_service_postgresql.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_postgresql.go index e3826ee02a9d..ea4f9d3fdab0 100644 --- a/azurerm/resource_arm_data_factory_linked_service_postgresql.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_postgresql.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_linked_service_postgresql_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_postgresql_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_linked_service_postgresql_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_postgresql_test.go index acfd4b8cf5ee..a8254f1a1c7e 100644 --- a/azurerm/resource_arm_data_factory_linked_service_postgresql_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_postgresql_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_linked_service_sql_server.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_sql_server.go similarity index 99% rename from azurerm/resource_arm_data_factory_linked_service_sql_server.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_sql_server.go index 1aaeb9dc0fad..7f7287409dff 100644 --- a/azurerm/resource_arm_data_factory_linked_service_sql_server.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_sql_server.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_linked_service_sql_server_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_sql_server_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_linked_service_sql_server_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_sql_server_test.go index 76a46b7f240a..ee1688f4ca4f 100644 --- a/azurerm/resource_arm_data_factory_linked_service_sql_server_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_sql_server_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_pipeline.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_pipeline.go similarity index 99% rename from azurerm/resource_arm_data_factory_pipeline.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_pipeline.go index 87875b03341d..36903c5c36aa 100644 --- a/azurerm/resource_arm_data_factory_pipeline.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_pipeline.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_pipeline_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_pipeline_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_pipeline_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_pipeline_test.go index 8451cea9e037..0b05c983e3de 100644 --- a/azurerm/resource_arm_data_factory_pipeline_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_pipeline_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_test.go index b2aadd4e0309..672f0d6b4b84 100644 --- a/azurerm/resource_arm_data_factory_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_trigger_schedule.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule.go similarity index 99% rename from azurerm/resource_arm_data_factory_trigger_schedule.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule.go index d2542d5f0090..791615bc9873 100644 --- a/azurerm/resource_arm_data_factory_trigger_schedule.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/resource_arm_data_factory_trigger_schedule_test.go b/azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule_test.go similarity index 99% rename from azurerm/resource_arm_data_factory_trigger_schedule_test.go rename to azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule_test.go index b71f96d67691..6adcc428442f 100644 --- a/azurerm/resource_arm_data_factory_trigger_schedule_test.go +++ b/azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule_test.go @@ -1,4 +1,4 @@ -package azurerm +package datafactory import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 77dfdeebdb60..11c2f584e281 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -17,7 +17,6 @@ func Provider() terraform.ResourceProvider { "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_data_factory": dataSourceArmDataFactory(), "azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(), "azurerm_dev_test_lab": dataSourceArmDevTestLab(), "azurerm_dev_test_virtual_network": dataSourceArmDevTestVirtualNetwork(), @@ -116,17 +115,6 @@ func Provider() terraform.ResourceProvider { "azurerm_bastion_host": resourceArmBastionHost(), "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_dashboard": resourceArmDashboard(), - "azurerm_data_factory": resourceArmDataFactory(), - "azurerm_data_factory_dataset_mysql": resourceArmDataFactoryDatasetMySQL(), - "azurerm_data_factory_dataset_postgresql": resourceArmDataFactoryDatasetPostgreSQL(), - "azurerm_data_factory_dataset_sql_server_table": resourceArmDataFactoryDatasetSQLServerTable(), - "azurerm_data_factory_integration_runtime_managed": resourceArmDataFactoryIntegrationRuntimeManaged(), - "azurerm_data_factory_linked_service_data_lake_storage_gen2": resourceArmDataFactoryLinkedServiceDataLakeStorageGen2(), - "azurerm_data_factory_linked_service_mysql": resourceArmDataFactoryLinkedServiceMySQL(), - "azurerm_data_factory_linked_service_postgresql": resourceArmDataFactoryLinkedServicePostgreSQL(), - "azurerm_data_factory_linked_service_sql_server": resourceArmDataFactoryLinkedServiceSQLServer(), - "azurerm_data_factory_pipeline": resourceArmDataFactoryPipeline(), - "azurerm_data_factory_trigger_schedule": resourceArmDataFactoryTriggerSchedule(), "azurerm_data_lake_analytics_account": resourceArmDataLakeAnalyticsAccount(), "azurerm_data_lake_analytics_firewall_rule": resourceArmDataLakeAnalyticsFirewallRule(), "azurerm_data_lake_store_file": resourceArmDataLakeStoreFile(), From ea5459408b99c0265218eea63572777f338c99d7 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:50:33 -0800 Subject: [PATCH 020/203] datalake --- .../services/datalake}/data_source_data_lake_store.go | 2 +- .../datalake}/data_source_data_lake_store_test.go | 5 +++-- azurerm/internal/services/datalake/registration.go | 10 ++++++++-- .../resource_arm_data_lake_analytics_account.go | 2 +- .../resource_arm_data_lake_analytics_account_test.go | 2 +- .../resource_arm_data_lake_analytics_firewall_rule.go | 2 +- ...ource_arm_data_lake_analytics_firewall_rule_test.go | 2 +- .../services/datalake}/resource_arm_data_lake_store.go | 2 +- .../datalake}/resource_arm_data_lake_store_file.go | 2 +- .../resource_arm_data_lake_store_file_migration.go | 2 +- ...resource_arm_data_lake_store_file_migration_test.go | 2 +- .../resource_arm_data_lake_store_file_test.go | 2 +- .../resource_arm_data_lake_store_firewall_rule.go | 2 +- .../resource_arm_data_lake_store_firewall_rule_test.go | 2 +- .../datalake}/resource_arm_data_lake_store_test.go | 2 +- azurerm/provider.go | 6 ------ 16 files changed, 24 insertions(+), 23 deletions(-) rename azurerm/{ => internal/services/datalake}/data_source_data_lake_store.go (99%) rename azurerm/{ => internal/services/datalake}/data_source_data_lake_store_test.go (95%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_analytics_account.go (99%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_analytics_account_test.go (99%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_analytics_firewall_rule.go (99%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_analytics_firewall_rule_test.go (99%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_store.go (99%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_store_file.go (99%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_store_file_migration.go (98%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_store_file_migration_test.go (99%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_store_file_test.go (99%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_store_firewall_rule.go (99%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_store_firewall_rule_test.go (99%) rename azurerm/{ => internal/services/datalake}/resource_arm_data_lake_store_test.go (99%) diff --git a/azurerm/data_source_data_lake_store.go b/azurerm/internal/services/datalake/data_source_data_lake_store.go similarity index 99% rename from azurerm/data_source_data_lake_store.go rename to azurerm/internal/services/datalake/data_source_data_lake_store.go index a6bb6f7f656d..50984d1360b4 100644 --- a/azurerm/data_source_data_lake_store.go +++ b/azurerm/internal/services/datalake/data_source_data_lake_store.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/data_source_data_lake_store_test.go b/azurerm/internal/services/datalake/data_source_data_lake_store_test.go similarity index 95% rename from azurerm/data_source_data_lake_store_test.go rename to azurerm/internal/services/datalake/data_source_data_lake_store_test.go index 8fa2b9c72006..d2a3e96553ce 100644 --- a/azurerm/data_source_data_lake_store_test.go +++ b/azurerm/internal/services/datalake/data_source_data_lake_store_test.go @@ -1,7 +1,8 @@ -package azurerm +package datalake import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" @@ -23,7 +24,7 @@ func TestAccDataSourceAzureRMDataLakeStore_basic(t *testing.T) { { Config: testAccDataSourceDataLakeStore_basic(rInt, rs, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(dataSourceName), + azurerm.testCheckAzureRMDataLakeStoreExists(dataSourceName), resource.TestCheckResourceAttr(dataSourceName, "tier", "Consumption"), ), }, diff --git a/azurerm/internal/services/datalake/registration.go b/azurerm/internal/services/datalake/registration.go index c1b0b93ff542..94983780bea3 100644 --- a/azurerm/internal/services/datalake/registration.go +++ b/azurerm/internal/services/datalake/registration.go @@ -13,10 +13,16 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount()} } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_data_lake_analytics_account": resourceArmDataLakeAnalyticsAccount(), + "azurerm_data_lake_analytics_firewall_rule": resourceArmDataLakeAnalyticsFirewallRule(), + "azurerm_data_lake_store_file": resourceArmDataLakeStoreFile(), + "azurerm_data_lake_store_firewall_rule": resourceArmDataLakeStoreFirewallRule(), + "azurerm_data_lake_store": resourceArmDataLakeStore()} } diff --git a/azurerm/resource_arm_data_lake_analytics_account.go b/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_account.go similarity index 99% rename from azurerm/resource_arm_data_lake_analytics_account.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_analytics_account.go index e0488c80c294..2018471a879d 100644 --- a/azurerm/resource_arm_data_lake_analytics_account.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_account.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/resource_arm_data_lake_analytics_account_test.go b/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_account_test.go similarity index 99% rename from azurerm/resource_arm_data_lake_analytics_account_test.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_analytics_account_test.go index 58a7b992441c..1c930a25de0e 100644 --- a/azurerm/resource_arm_data_lake_analytics_account_test.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/resource_arm_data_lake_analytics_firewall_rule.go b/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_firewall_rule.go similarity index 99% rename from azurerm/resource_arm_data_lake_analytics_firewall_rule.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_analytics_firewall_rule.go index b6d44d184050..521736e7bfd3 100644 --- a/azurerm/resource_arm_data_lake_analytics_firewall_rule.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_firewall_rule.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/resource_arm_data_lake_analytics_firewall_rule_test.go b/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_firewall_rule_test.go similarity index 99% rename from azurerm/resource_arm_data_lake_analytics_firewall_rule_test.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_analytics_firewall_rule_test.go index d7b3c36ebc24..d20e7b8bf4a4 100644 --- a/azurerm/resource_arm_data_lake_analytics_firewall_rule_test.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_firewall_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/resource_arm_data_lake_store.go b/azurerm/internal/services/datalake/resource_arm_data_lake_store.go similarity index 99% rename from azurerm/resource_arm_data_lake_store.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_store.go index 258968b9c066..bf8bad644cdd 100644 --- a/azurerm/resource_arm_data_lake_store.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_store.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/resource_arm_data_lake_store_file.go b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file.go similarity index 99% rename from azurerm/resource_arm_data_lake_store_file.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_store_file.go index 0c4e411ff0d8..a484037b5f8c 100644 --- a/azurerm/resource_arm_data_lake_store_file.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "bytes" diff --git a/azurerm/resource_arm_data_lake_store_file_migration.go b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration.go similarity index 98% rename from azurerm/resource_arm_data_lake_store_file_migration.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration.go index 2cc80e726edc..465fa2c19211 100644 --- a/azurerm/resource_arm_data_lake_store_file_migration.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/resource_arm_data_lake_store_file_migration_test.go b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration_test.go similarity index 99% rename from azurerm/resource_arm_data_lake_store_file_migration_test.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration_test.go index 92df25d568b5..05e8d1a4d733 100644 --- a/azurerm/resource_arm_data_lake_store_file_migration_test.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration_test.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "context" diff --git a/azurerm/resource_arm_data_lake_store_file_test.go b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_test.go similarity index 99% rename from azurerm/resource_arm_data_lake_store_file_test.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_store_file_test.go index 37b6829f890b..0fb8f59aa36f 100644 --- a/azurerm/resource_arm_data_lake_store_file_test.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_test.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/resource_arm_data_lake_store_firewall_rule.go b/azurerm/internal/services/datalake/resource_arm_data_lake_store_firewall_rule.go similarity index 99% rename from azurerm/resource_arm_data_lake_store_firewall_rule.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_store_firewall_rule.go index 0d43fdd50005..59753c8f31d1 100644 --- a/azurerm/resource_arm_data_lake_store_firewall_rule.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_store_firewall_rule.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/resource_arm_data_lake_store_firewall_rule_test.go b/azurerm/internal/services/datalake/resource_arm_data_lake_store_firewall_rule_test.go similarity index 99% rename from azurerm/resource_arm_data_lake_store_firewall_rule_test.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_store_firewall_rule_test.go index b64b528f86c0..e1f35ac10035 100644 --- a/azurerm/resource_arm_data_lake_store_firewall_rule_test.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_store_firewall_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/resource_arm_data_lake_store_test.go b/azurerm/internal/services/datalake/resource_arm_data_lake_store_test.go similarity index 99% rename from azurerm/resource_arm_data_lake_store_test.go rename to azurerm/internal/services/datalake/resource_arm_data_lake_store_test.go index af0f8cece582..5a63b9e65261 100644 --- a/azurerm/resource_arm_data_lake_store_test.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_store_test.go @@ -1,4 +1,4 @@ -package azurerm +package datalake import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 11c2f584e281..2fd93ce58817 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -17,7 +17,6 @@ func Provider() terraform.ResourceProvider { "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(), "azurerm_dev_test_lab": dataSourceArmDevTestLab(), "azurerm_dev_test_virtual_network": dataSourceArmDevTestVirtualNetwork(), "azurerm_dns_zone": dataSourceArmDnsZone(), @@ -115,11 +114,6 @@ func Provider() terraform.ResourceProvider { "azurerm_bastion_host": resourceArmBastionHost(), "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_dashboard": resourceArmDashboard(), - "azurerm_data_lake_analytics_account": resourceArmDataLakeAnalyticsAccount(), - "azurerm_data_lake_analytics_firewall_rule": resourceArmDataLakeAnalyticsFirewallRule(), - "azurerm_data_lake_store_file": resourceArmDataLakeStoreFile(), - "azurerm_data_lake_store_firewall_rule": resourceArmDataLakeStoreFirewallRule(), - "azurerm_data_lake_store": resourceArmDataLakeStore(), "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), "azurerm_dev_test_lab": resourceArmDevTestLab(), "azurerm_dev_test_schedule": resourceArmDevTestLabSchedules(), From d9ddcc644c68a093815d0febab9063a285ff84cc Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:53:43 -0800 Subject: [PATCH 021/203] devspace --- azurerm/internal/services/devspace/registration.go | 4 +++- .../services/devspace}/resource_arm_devspace_controller.go | 2 +- .../devspace}/resource_arm_devspace_controller_test.go | 2 +- azurerm/provider.go | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) rename azurerm/{ => internal/services/devspace}/resource_arm_devspace_controller.go (99%) rename azurerm/{ => internal/services/devspace}/resource_arm_devspace_controller_test.go (99%) diff --git a/azurerm/internal/services/devspace/registration.go b/azurerm/internal/services/devspace/registration.go index 51ca32130112..c40664b9c07f 100644 --- a/azurerm/internal/services/devspace/registration.go +++ b/azurerm/internal/services/devspace/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_devspace_controller": resourceArmDevSpaceController(), + } } diff --git a/azurerm/resource_arm_devspace_controller.go b/azurerm/internal/services/devspace/resource_arm_devspace_controller.go similarity index 99% rename from azurerm/resource_arm_devspace_controller.go rename to azurerm/internal/services/devspace/resource_arm_devspace_controller.go index 3c7b43a41887..013ceef12878 100644 --- a/azurerm/resource_arm_devspace_controller.go +++ b/azurerm/internal/services/devspace/resource_arm_devspace_controller.go @@ -1,4 +1,4 @@ -package azurerm +package devspace import ( "fmt" diff --git a/azurerm/resource_arm_devspace_controller_test.go b/azurerm/internal/services/devspace/resource_arm_devspace_controller_test.go similarity index 99% rename from azurerm/resource_arm_devspace_controller_test.go rename to azurerm/internal/services/devspace/resource_arm_devspace_controller_test.go index 00803d24c083..b10fdc6687b6 100644 --- a/azurerm/resource_arm_devspace_controller_test.go +++ b/azurerm/internal/services/devspace/resource_arm_devspace_controller_test.go @@ -1,4 +1,4 @@ -package azurerm +package devspace import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 2fd93ce58817..17c2679d7e3e 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -121,7 +121,6 @@ func Provider() terraform.ResourceProvider { "azurerm_dev_test_policy": resourceArmDevTestPolicy(), "azurerm_dev_test_virtual_network": resourceArmDevTestVirtualNetwork(), "azurerm_dev_test_windows_virtual_machine": resourceArmDevTestWindowsVirtualMachine(), - "azurerm_devspace_controller": resourceArmDevSpaceController(), "azurerm_dns_a_record": resourceArmDnsARecord(), "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), "azurerm_dns_caa_record": resourceArmDnsCaaRecord(), From 4af58d717b4d660166b9b64036093f656c94314f Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:55:42 -0800 Subject: [PATCH 022/203] devtestlabs --- .../devtestlabs}/data_source_dev_test_lab.go | 2 +- .../devtestlabs}/data_source_dev_test_lab_test.go | 2 +- .../data_source_dev_test_virtual_network.go | 2 +- .../data_source_dev_test_virtual_network_test.go | 2 +- .../internal/services/devtestlabs/registration.go | 12 ++++++++++-- .../devtestlabs}/resource_arm_dev_test_lab.go | 2 +- .../resource_arm_dev_test_lab_schedule.go | 2 +- .../resource_arm_dev_test_lab_schedule_test.go | 2 +- .../devtestlabs}/resource_arm_dev_test_lab_test.go | 2 +- .../resource_arm_dev_test_linux_virtual_machine.go | 2 +- ...source_arm_dev_test_linux_virtual_machine_test.go | 2 +- .../devtestlabs}/resource_arm_dev_test_policy.go | 2 +- .../resource_arm_dev_test_policy_test.go | 2 +- .../resource_arm_dev_test_virtual_network.go | 2 +- .../resource_arm_dev_test_virtual_network_test.go | 2 +- .../resource_arm_dev_test_windows_virtual_machine.go | 2 +- ...urce_arm_dev_test_windows_virtual_machine_test.go | 2 +- azurerm/provider.go | 8 -------- 18 files changed, 26 insertions(+), 26 deletions(-) rename azurerm/{ => internal/services/devtestlabs}/data_source_dev_test_lab.go (99%) rename azurerm/{ => internal/services/devtestlabs}/data_source_dev_test_lab_test.go (99%) rename azurerm/{ => internal/services/devtestlabs}/data_source_dev_test_virtual_network.go (99%) rename azurerm/{ => internal/services/devtestlabs}/data_source_dev_test_virtual_network_test.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_lab.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_lab_schedule.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_lab_schedule_test.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_lab_test.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_linux_virtual_machine.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_linux_virtual_machine_test.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_policy.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_policy_test.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_virtual_network.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_virtual_network_test.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_windows_virtual_machine.go (99%) rename azurerm/{ => internal/services/devtestlabs}/resource_arm_dev_test_windows_virtual_machine_test.go (99%) diff --git a/azurerm/data_source_dev_test_lab.go b/azurerm/internal/services/devtestlabs/data_source_dev_test_lab.go similarity index 99% rename from azurerm/data_source_dev_test_lab.go rename to azurerm/internal/services/devtestlabs/data_source_dev_test_lab.go index d097329a0d0a..8a5d63b93cc8 100644 --- a/azurerm/data_source_dev_test_lab.go +++ b/azurerm/internal/services/devtestlabs/data_source_dev_test_lab.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/data_source_dev_test_lab_test.go b/azurerm/internal/services/devtestlabs/data_source_dev_test_lab_test.go similarity index 99% rename from azurerm/data_source_dev_test_lab_test.go rename to azurerm/internal/services/devtestlabs/data_source_dev_test_lab_test.go index ebd68869af4f..707e87275696 100644 --- a/azurerm/data_source_dev_test_lab_test.go +++ b/azurerm/internal/services/devtestlabs/data_source_dev_test_lab_test.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/data_source_dev_test_virtual_network.go b/azurerm/internal/services/devtestlabs/data_source_dev_test_virtual_network.go similarity index 99% rename from azurerm/data_source_dev_test_virtual_network.go rename to azurerm/internal/services/devtestlabs/data_source_dev_test_virtual_network.go index 0e847e48aaf1..6cf1c943ce0e 100644 --- a/azurerm/data_source_dev_test_virtual_network.go +++ b/azurerm/internal/services/devtestlabs/data_source_dev_test_virtual_network.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/data_source_dev_test_virtual_network_test.go b/azurerm/internal/services/devtestlabs/data_source_dev_test_virtual_network_test.go similarity index 99% rename from azurerm/data_source_dev_test_virtual_network_test.go rename to azurerm/internal/services/devtestlabs/data_source_dev_test_virtual_network_test.go index bf0787ac1376..03994fc6f493 100644 --- a/azurerm/data_source_dev_test_virtual_network_test.go +++ b/azurerm/internal/services/devtestlabs/data_source_dev_test_virtual_network_test.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/internal/services/devtestlabs/registration.go b/azurerm/internal/services/devtestlabs/registration.go index 6da718ef176f..c726d8eee79d 100644 --- a/azurerm/internal/services/devtestlabs/registration.go +++ b/azurerm/internal/services/devtestlabs/registration.go @@ -13,10 +13,18 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_dev_test_lab": dataSourceArmDevTestLab(), + "azurerm_dev_test_virtual_network": dataSourceArmDevTestVirtualNetwork()} } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_dev_test_lab": resourceArmDevTestLab(), + "azurerm_dev_test_schedule": resourceArmDevTestLabSchedules(), + "azurerm_dev_test_linux_virtual_machine": resourceArmDevTestLinuxVirtualMachine(), + "azurerm_dev_test_policy": resourceArmDevTestPolicy(), + "azurerm_dev_test_virtual_network": resourceArmDevTestVirtualNetwork(), + "azurerm_dev_test_windows_virtual_machine": resourceArmDevTestWindowsVirtualMachine()} } diff --git a/azurerm/resource_arm_dev_test_lab.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab.go similarity index 99% rename from azurerm/resource_arm_dev_test_lab.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab.go index 8b65a3494ebd..3e84ac773759 100644 --- a/azurerm/resource_arm_dev_test_lab.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_lab_schedule.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_schedule.go similarity index 99% rename from azurerm/resource_arm_dev_test_lab_schedule.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_schedule.go index 9a793ae66cfe..cd40a4a0e0ca 100644 --- a/azurerm/resource_arm_dev_test_lab_schedule.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_schedule.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_lab_schedule_test.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_schedule_test.go similarity index 99% rename from azurerm/resource_arm_dev_test_lab_schedule_test.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_schedule_test.go index e93603e37dd5..2ebe5f975869 100644 --- a/azurerm/resource_arm_dev_test_lab_schedule_test.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_schedule_test.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_lab_test.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_test.go similarity index 99% rename from azurerm/resource_arm_dev_test_lab_test.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_test.go index cf2e41e86d7c..167ad4485dfb 100644 --- a/azurerm/resource_arm_dev_test_lab_test.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_test.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_linux_virtual_machine.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_linux_virtual_machine.go similarity index 99% rename from azurerm/resource_arm_dev_test_linux_virtual_machine.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_linux_virtual_machine.go index 3d686e2415f0..69240d90ff86 100644 --- a/azurerm/resource_arm_dev_test_linux_virtual_machine.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_linux_virtual_machine.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_linux_virtual_machine_test.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_linux_virtual_machine_test.go similarity index 99% rename from azurerm/resource_arm_dev_test_linux_virtual_machine_test.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_linux_virtual_machine_test.go index 09f37eab1eea..10dfb3813c53 100644 --- a/azurerm/resource_arm_dev_test_linux_virtual_machine_test.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_linux_virtual_machine_test.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_policy.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_policy.go similarity index 99% rename from azurerm/resource_arm_dev_test_policy.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_policy.go index c3cf74e20acc..6ebe383c8eeb 100644 --- a/azurerm/resource_arm_dev_test_policy.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_policy.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_policy_test.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_policy_test.go similarity index 99% rename from azurerm/resource_arm_dev_test_policy_test.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_policy_test.go index 631d130d5e67..b126e67d3a8a 100644 --- a/azurerm/resource_arm_dev_test_policy_test.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_virtual_network.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network.go similarity index 99% rename from azurerm/resource_arm_dev_test_virtual_network.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network.go index a0dfdfeeb3a8..1d9b06927fce 100644 --- a/azurerm/resource_arm_dev_test_virtual_network.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_virtual_network_test.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network_test.go similarity index 99% rename from azurerm/resource_arm_dev_test_virtual_network_test.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network_test.go index 44d246a7a5fe..2a43fdae1123 100644 --- a/azurerm/resource_arm_dev_test_virtual_network_test.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network_test.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_windows_virtual_machine.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_windows_virtual_machine.go similarity index 99% rename from azurerm/resource_arm_dev_test_windows_virtual_machine.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_windows_virtual_machine.go index 61963e93d9a6..d1ae49cd5f4c 100644 --- a/azurerm/resource_arm_dev_test_windows_virtual_machine.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_windows_virtual_machine.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/resource_arm_dev_test_windows_virtual_machine_test.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_windows_virtual_machine_test.go similarity index 99% rename from azurerm/resource_arm_dev_test_windows_virtual_machine_test.go rename to azurerm/internal/services/devtestlabs/resource_arm_dev_test_windows_virtual_machine_test.go index c50e88e4c84b..c401a05b80e3 100644 --- a/azurerm/resource_arm_dev_test_windows_virtual_machine_test.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_windows_virtual_machine_test.go @@ -1,4 +1,4 @@ -package azurerm +package devtestlabs import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 17c2679d7e3e..04205ab7e8b2 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -17,8 +17,6 @@ func Provider() terraform.ResourceProvider { "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_dev_test_lab": dataSourceArmDevTestLab(), - "azurerm_dev_test_virtual_network": dataSourceArmDevTestVirtualNetwork(), "azurerm_dns_zone": dataSourceArmDnsZone(), "azurerm_eventhub_namespace": dataSourceEventHubNamespace(), "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), @@ -115,12 +113,6 @@ func Provider() terraform.ResourceProvider { "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_dashboard": resourceArmDashboard(), "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), - "azurerm_dev_test_lab": resourceArmDevTestLab(), - "azurerm_dev_test_schedule": resourceArmDevTestLabSchedules(), - "azurerm_dev_test_linux_virtual_machine": resourceArmDevTestLinuxVirtualMachine(), - "azurerm_dev_test_policy": resourceArmDevTestPolicy(), - "azurerm_dev_test_virtual_network": resourceArmDevTestVirtualNetwork(), - "azurerm_dev_test_windows_virtual_machine": resourceArmDevTestWindowsVirtualMachine(), "azurerm_dns_a_record": resourceArmDnsARecord(), "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), "azurerm_dns_caa_record": resourceArmDnsCaaRecord(), From 878dfc1d2e93ce8e11c71983b15d999901601ca7 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:57:04 -0800 Subject: [PATCH 023/203] dns --- .../services/dns}/data_source_dns_zone.go | 2 +- .../dns}/data_source_dns_zone_test.go | 9 +-- azurerm/internal/services/dns/registration.go | 16 ++++- .../dns}/resource_arm_dns_a_record.go | 2 +- .../dns}/resource_arm_dns_a_record_test.go | 2 +- .../dns}/resource_arm_dns_aaaa_record.go | 2 +- .../dns}/resource_arm_dns_aaaa_record_test.go | 2 +- .../dns}/resource_arm_dns_caa_record.go | 2 +- .../dns}/resource_arm_dns_caa_record_test.go | 2 +- .../dns}/resource_arm_dns_cname_record.go | 2 +- .../resource_arm_dns_cname_record_test.go | 2 +- .../dns}/resource_arm_dns_mx_record.go | 2 +- .../dns}/resource_arm_dns_mx_record_test.go | 2 +- .../dns}/resource_arm_dns_ns_record.go | 2 +- .../dns}/resource_arm_dns_ns_record_test.go | 2 +- .../dns}/resource_arm_dns_ptr_record.go | 2 +- .../dns}/resource_arm_dns_ptr_record_test.go | 2 +- .../dns}/resource_arm_dns_srv_record.go | 2 +- .../dns}/resource_arm_dns_srv_record_test.go | 2 +- .../dns}/resource_arm_dns_txt_record.go | 2 +- .../dns}/resource_arm_dns_txt_record_test.go | 2 +- .../services/dns}/resource_arm_dns_zone.go | 2 +- .../dns}/resource_arm_dns_zone_test.go | 2 +- azurerm/provider.go | 61 ++++++++----------- 24 files changed, 65 insertions(+), 63 deletions(-) rename azurerm/{ => internal/services/dns}/data_source_dns_zone.go (99%) rename azurerm/{ => internal/services/dns}/data_source_dns_zone_test.go (93%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_a_record.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_a_record_test.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_aaaa_record.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_aaaa_record_test.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_caa_record.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_caa_record_test.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_cname_record.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_cname_record_test.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_mx_record.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_mx_record_test.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_ns_record.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_ns_record_test.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_ptr_record.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_ptr_record_test.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_srv_record.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_srv_record_test.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_txt_record.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_txt_record_test.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_zone.go (99%) rename azurerm/{ => internal/services/dns}/resource_arm_dns_zone_test.go (99%) diff --git a/azurerm/data_source_dns_zone.go b/azurerm/internal/services/dns/data_source_dns_zone.go similarity index 99% rename from azurerm/data_source_dns_zone.go rename to azurerm/internal/services/dns/data_source_dns_zone.go index eede48318372..79f38a81fc4b 100644 --- a/azurerm/data_source_dns_zone.go +++ b/azurerm/internal/services/dns/data_source_dns_zone.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "context" diff --git a/azurerm/data_source_dns_zone_test.go b/azurerm/internal/services/dns/data_source_dns_zone_test.go similarity index 93% rename from azurerm/data_source_dns_zone_test.go rename to azurerm/internal/services/dns/data_source_dns_zone_test.go index b9d8a3fe6982..c2acf460985e 100644 --- a/azurerm/data_source_dns_zone_test.go +++ b/azurerm/internal/services/dns/data_source_dns_zone_test.go @@ -1,7 +1,8 @@ -package azurerm +package dns import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -17,7 +18,7 @@ func TestAccDataSourceAzureRMDNSZone_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDnsZoneDestroy, + CheckDestroy: azurerm.testCheckAzureRMDnsZoneDestroy, Steps: []resource.TestStep{ { Config: testAccDataSourceDNSZone_basic(rInt, location), @@ -37,7 +38,7 @@ func TestAccDataSourceAzureRMDNSZone_tags(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDnsZoneDestroy, + CheckDestroy: azurerm.testCheckAzureRMDnsZoneDestroy, Steps: []resource.TestStep{ { Config: testAccDataSourceDNSZone_tags(rInt, location), @@ -59,7 +60,7 @@ func TestAccDataSourceAzureRMDNSZone_withoutResourceGroupName(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDnsZoneDestroy, + CheckDestroy: azurerm.testCheckAzureRMDnsZoneDestroy, Steps: []resource.TestStep{ { Config: testAccDataSourceDNSZone_onlyName(rInt, location, resourceGroupName), diff --git a/azurerm/internal/services/dns/registration.go b/azurerm/internal/services/dns/registration.go index 07d0b3e6aecf..aa274777e79e 100644 --- a/azurerm/internal/services/dns/registration.go +++ b/azurerm/internal/services/dns/registration.go @@ -13,10 +13,22 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_dns_zone": dataSourceArmDnsZone(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_dns_a_record": resourceArmDnsARecord(), + "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), + "azurerm_dns_caa_record": resourceArmDnsCaaRecord(), + "azurerm_dns_cname_record": resourceArmDnsCNameRecord(), + "azurerm_dns_mx_record": resourceArmDnsMxRecord(), + "azurerm_dns_ns_record": resourceArmDnsNsRecord(), + "azurerm_dns_ptr_record": resourceArmDnsPtrRecord(), + "azurerm_dns_srv_record": resourceArmDnsSrvRecord(), + "azurerm_dns_txt_record": resourceArmDnsTxtRecord(), + "azurerm_dns_zone": resourceArmDnsZone(),} } diff --git a/azurerm/resource_arm_dns_a_record.go b/azurerm/internal/services/dns/resource_arm_dns_a_record.go similarity index 99% rename from azurerm/resource_arm_dns_a_record.go rename to azurerm/internal/services/dns/resource_arm_dns_a_record.go index 6800fa3a6fff..a7a919eb49d2 100644 --- a/azurerm/resource_arm_dns_a_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_a_record.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_a_record_test.go b/azurerm/internal/services/dns/resource_arm_dns_a_record_test.go similarity index 99% rename from azurerm/resource_arm_dns_a_record_test.go rename to azurerm/internal/services/dns/resource_arm_dns_a_record_test.go index 14204371de00..1ab4c2fa7571 100644 --- a/azurerm/resource_arm_dns_a_record_test.go +++ b/azurerm/internal/services/dns/resource_arm_dns_a_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_aaaa_record.go b/azurerm/internal/services/dns/resource_arm_dns_aaaa_record.go similarity index 99% rename from azurerm/resource_arm_dns_aaaa_record.go rename to azurerm/internal/services/dns/resource_arm_dns_aaaa_record.go index f193b684cc72..32097cc2ab0a 100644 --- a/azurerm/resource_arm_dns_aaaa_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_aaaa_record.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_aaaa_record_test.go b/azurerm/internal/services/dns/resource_arm_dns_aaaa_record_test.go similarity index 99% rename from azurerm/resource_arm_dns_aaaa_record_test.go rename to azurerm/internal/services/dns/resource_arm_dns_aaaa_record_test.go index 4091bfcff8ab..867a90d3d991 100644 --- a/azurerm/resource_arm_dns_aaaa_record_test.go +++ b/azurerm/internal/services/dns/resource_arm_dns_aaaa_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_caa_record.go b/azurerm/internal/services/dns/resource_arm_dns_caa_record.go similarity index 99% rename from azurerm/resource_arm_dns_caa_record.go rename to azurerm/internal/services/dns/resource_arm_dns_caa_record.go index 60301abaa033..65db838855bb 100644 --- a/azurerm/resource_arm_dns_caa_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_caa_record.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "bytes" diff --git a/azurerm/resource_arm_dns_caa_record_test.go b/azurerm/internal/services/dns/resource_arm_dns_caa_record_test.go similarity index 99% rename from azurerm/resource_arm_dns_caa_record_test.go rename to azurerm/internal/services/dns/resource_arm_dns_caa_record_test.go index 8321c1e00b8b..a50ce58cfccb 100644 --- a/azurerm/resource_arm_dns_caa_record_test.go +++ b/azurerm/internal/services/dns/resource_arm_dns_caa_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_cname_record.go b/azurerm/internal/services/dns/resource_arm_dns_cname_record.go similarity index 99% rename from azurerm/resource_arm_dns_cname_record.go rename to azurerm/internal/services/dns/resource_arm_dns_cname_record.go index 2ee51ad703f9..715bdc968812 100644 --- a/azurerm/resource_arm_dns_cname_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_cname_record.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_cname_record_test.go b/azurerm/internal/services/dns/resource_arm_dns_cname_record_test.go similarity index 99% rename from azurerm/resource_arm_dns_cname_record_test.go rename to azurerm/internal/services/dns/resource_arm_dns_cname_record_test.go index e13dcd877dd3..80d70f5a00c9 100644 --- a/azurerm/resource_arm_dns_cname_record_test.go +++ b/azurerm/internal/services/dns/resource_arm_dns_cname_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_mx_record.go b/azurerm/internal/services/dns/resource_arm_dns_mx_record.go similarity index 99% rename from azurerm/resource_arm_dns_mx_record.go rename to azurerm/internal/services/dns/resource_arm_dns_mx_record.go index 87427333d5a5..42f29f95d987 100644 --- a/azurerm/resource_arm_dns_mx_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_mx_record.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "bytes" diff --git a/azurerm/resource_arm_dns_mx_record_test.go b/azurerm/internal/services/dns/resource_arm_dns_mx_record_test.go similarity index 99% rename from azurerm/resource_arm_dns_mx_record_test.go rename to azurerm/internal/services/dns/resource_arm_dns_mx_record_test.go index a9df62001037..3315571e379b 100644 --- a/azurerm/resource_arm_dns_mx_record_test.go +++ b/azurerm/internal/services/dns/resource_arm_dns_mx_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_ns_record.go b/azurerm/internal/services/dns/resource_arm_dns_ns_record.go similarity index 99% rename from azurerm/resource_arm_dns_ns_record.go rename to azurerm/internal/services/dns/resource_arm_dns_ns_record.go index 1576d365966f..a1d5e37a85cb 100644 --- a/azurerm/resource_arm_dns_ns_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_ns_record.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_ns_record_test.go b/azurerm/internal/services/dns/resource_arm_dns_ns_record_test.go similarity index 99% rename from azurerm/resource_arm_dns_ns_record_test.go rename to azurerm/internal/services/dns/resource_arm_dns_ns_record_test.go index e3b6d5cccc14..e95c37c63f3a 100644 --- a/azurerm/resource_arm_dns_ns_record_test.go +++ b/azurerm/internal/services/dns/resource_arm_dns_ns_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_ptr_record.go b/azurerm/internal/services/dns/resource_arm_dns_ptr_record.go similarity index 99% rename from azurerm/resource_arm_dns_ptr_record.go rename to azurerm/internal/services/dns/resource_arm_dns_ptr_record.go index 3c6caccc8522..25272c1c2dd5 100644 --- a/azurerm/resource_arm_dns_ptr_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_ptr_record.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_ptr_record_test.go b/azurerm/internal/services/dns/resource_arm_dns_ptr_record_test.go similarity index 99% rename from azurerm/resource_arm_dns_ptr_record_test.go rename to azurerm/internal/services/dns/resource_arm_dns_ptr_record_test.go index f5e8fe0d2c05..b35b26ad15a7 100644 --- a/azurerm/resource_arm_dns_ptr_record_test.go +++ b/azurerm/internal/services/dns/resource_arm_dns_ptr_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_srv_record.go b/azurerm/internal/services/dns/resource_arm_dns_srv_record.go similarity index 99% rename from azurerm/resource_arm_dns_srv_record.go rename to azurerm/internal/services/dns/resource_arm_dns_srv_record.go index 9b73a8337337..d6f7749e3758 100644 --- a/azurerm/resource_arm_dns_srv_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_srv_record.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "bytes" diff --git a/azurerm/resource_arm_dns_srv_record_test.go b/azurerm/internal/services/dns/resource_arm_dns_srv_record_test.go similarity index 99% rename from azurerm/resource_arm_dns_srv_record_test.go rename to azurerm/internal/services/dns/resource_arm_dns_srv_record_test.go index 59ad1c10c668..29ab0d042d1c 100644 --- a/azurerm/resource_arm_dns_srv_record_test.go +++ b/azurerm/internal/services/dns/resource_arm_dns_srv_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_txt_record.go b/azurerm/internal/services/dns/resource_arm_dns_txt_record.go similarity index 99% rename from azurerm/resource_arm_dns_txt_record.go rename to azurerm/internal/services/dns/resource_arm_dns_txt_record.go index d5dd12894b5f..abf1e2eaae9c 100644 --- a/azurerm/resource_arm_dns_txt_record.go +++ b/azurerm/internal/services/dns/resource_arm_dns_txt_record.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_txt_record_test.go b/azurerm/internal/services/dns/resource_arm_dns_txt_record_test.go similarity index 99% rename from azurerm/resource_arm_dns_txt_record_test.go rename to azurerm/internal/services/dns/resource_arm_dns_txt_record_test.go index 4ac07c3ccf3b..58d4a7310eda 100644 --- a/azurerm/resource_arm_dns_txt_record_test.go +++ b/azurerm/internal/services/dns/resource_arm_dns_txt_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_zone.go b/azurerm/internal/services/dns/resource_arm_dns_zone.go similarity index 99% rename from azurerm/resource_arm_dns_zone.go rename to azurerm/internal/services/dns/resource_arm_dns_zone.go index cb05b5bc0893..8cbc72e5a3b8 100644 --- a/azurerm/resource_arm_dns_zone.go +++ b/azurerm/internal/services/dns/resource_arm_dns_zone.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/resource_arm_dns_zone_test.go b/azurerm/internal/services/dns/resource_arm_dns_zone_test.go similarity index 99% rename from azurerm/resource_arm_dns_zone_test.go rename to azurerm/internal/services/dns/resource_arm_dns_zone_test.go index ddd635b863a5..6a007cf03411 100644 --- a/azurerm/resource_arm_dns_zone_test.go +++ b/azurerm/internal/services/dns/resource_arm_dns_zone_test.go @@ -1,4 +1,4 @@ -package azurerm +package dns import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 04205ab7e8b2..b47c0b8eeb7b 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -8,22 +8,21 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - "azurerm_app_service_plan": dataSourceAppServicePlan(), - "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), - "azurerm_app_service": dataSourceArmAppService(), - "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), - "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_azuread_application": dataSourceArmAzureADApplication(), - "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), - "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_dns_zone": dataSourceArmDnsZone(), - "azurerm_eventhub_namespace": dataSourceEventHubNamespace(), - "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), - "azurerm_firewall": dataSourceArmFirewall(), - "azurerm_image": dataSourceArmImage(), - "azurerm_hdinsight_cluster": dataSourceArmHDInsightSparkCluster(), - "azurerm_healthcare_service": dataSourceArmHealthcareService(), + "azurerm_app_service_plan": dataSourceAppServicePlan(), + "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), + "azurerm_app_service": dataSourceArmAppService(), + "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), + "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), + "azurerm_azuread_application": dataSourceArmAzureADApplication(), + "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), + "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), + "azurerm_client_config": dataSourceArmClientConfig(), + "azurerm_eventhub_namespace": dataSourceEventHubNamespace(), + "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), + "azurerm_firewall": dataSourceArmFirewall(), + "azurerm_image": dataSourceArmImage(), + "azurerm_hdinsight_cluster": dataSourceArmHDInsightSparkCluster(), + "azurerm_healthcare_service": dataSourceArmHealthcareService(), "azurerm_maps_account": dataSourceArmMapsAccount(), "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), @@ -108,26 +107,16 @@ func Provider() terraform.ResourceProvider { "azurerm_backup_policy_file_share": resourceArmBackupProtectionPolicyFileShare(), "azurerm_backup_protected_file_share": resourceArmBackupProtectedFileShare(), "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), - "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), - "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_connection_monitor": resourceArmConnectionMonitor(), - "azurerm_dashboard": resourceArmDashboard(), - "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), - "azurerm_dns_a_record": resourceArmDnsARecord(), - "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), - "azurerm_dns_caa_record": resourceArmDnsCaaRecord(), - "azurerm_dns_cname_record": resourceArmDnsCNameRecord(), - "azurerm_dns_mx_record": resourceArmDnsMxRecord(), - "azurerm_dns_ns_record": resourceArmDnsNsRecord(), - "azurerm_dns_ptr_record": resourceArmDnsPtrRecord(), - "azurerm_dns_srv_record": resourceArmDnsSrvRecord(), - "azurerm_dns_txt_record": resourceArmDnsTxtRecord(), - "azurerm_dns_zone": resourceArmDnsZone(), - "azurerm_eventgrid_domain": resourceArmEventGridDomain(), - "azurerm_eventgrid_event_subscription": resourceArmEventGridEventSubscription(), - "azurerm_eventgrid_topic": resourceArmEventGridTopic(), - "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), - "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), + "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), + "azurerm_bastion_host": resourceArmBastionHost(), + "azurerm_connection_monitor": resourceArmConnectionMonitor(), + "azurerm_dashboard": resourceArmDashboard(), + "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), + "azurerm_eventgrid_domain": resourceArmEventGridDomain(), + "azurerm_eventgrid_event_subscription": resourceArmEventGridEventSubscription(), + "azurerm_eventgrid_topic": resourceArmEventGridTopic(), + "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), + "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), "azurerm_eventhub_namespace_authorization_rule": resourceArmEventHubNamespaceAuthorizationRule(), "azurerm_eventhub_namespace_disaster_recovery_config": resourceArmEventHubNamespaceDisasterRecoveryConfig(), "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), From 018ddc70de2e2788ac6e04a30448d4ed5790cb09 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:58:00 -0800 Subject: [PATCH 024/203] dns-final --- azurerm/internal/services/dns/registration.go | 22 ++++---- azurerm/provider.go | 50 +++++++++---------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/azurerm/internal/services/dns/registration.go b/azurerm/internal/services/dns/registration.go index aa274777e79e..1935a8f57175 100644 --- a/azurerm/internal/services/dns/registration.go +++ b/azurerm/internal/services/dns/registration.go @@ -14,21 +14,21 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_dns_zone": dataSourceArmDnsZone(), + "azurerm_dns_zone": dataSourceArmDnsZone(), } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_dns_a_record": resourceArmDnsARecord(), - "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), - "azurerm_dns_caa_record": resourceArmDnsCaaRecord(), - "azurerm_dns_cname_record": resourceArmDnsCNameRecord(), - "azurerm_dns_mx_record": resourceArmDnsMxRecord(), - "azurerm_dns_ns_record": resourceArmDnsNsRecord(), - "azurerm_dns_ptr_record": resourceArmDnsPtrRecord(), - "azurerm_dns_srv_record": resourceArmDnsSrvRecord(), - "azurerm_dns_txt_record": resourceArmDnsTxtRecord(), - "azurerm_dns_zone": resourceArmDnsZone(),} + "azurerm_dns_a_record": resourceArmDnsARecord(), + "azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(), + "azurerm_dns_caa_record": resourceArmDnsCaaRecord(), + "azurerm_dns_cname_record": resourceArmDnsCNameRecord(), + "azurerm_dns_mx_record": resourceArmDnsMxRecord(), + "azurerm_dns_ns_record": resourceArmDnsNsRecord(), + "azurerm_dns_ptr_record": resourceArmDnsPtrRecord(), + "azurerm_dns_srv_record": resourceArmDnsSrvRecord(), + "azurerm_dns_txt_record": resourceArmDnsTxtRecord(), + "azurerm_dns_zone": resourceArmDnsZone()} } diff --git a/azurerm/provider.go b/azurerm/provider.go index b47c0b8eeb7b..914867893afc 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -8,21 +8,21 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - "azurerm_app_service_plan": dataSourceAppServicePlan(), - "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), - "azurerm_app_service": dataSourceArmAppService(), - "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), - "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_azuread_application": dataSourceArmAzureADApplication(), - "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), - "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_eventhub_namespace": dataSourceEventHubNamespace(), - "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), - "azurerm_firewall": dataSourceArmFirewall(), - "azurerm_image": dataSourceArmImage(), - "azurerm_hdinsight_cluster": dataSourceArmHDInsightSparkCluster(), - "azurerm_healthcare_service": dataSourceArmHealthcareService(), + "azurerm_app_service_plan": dataSourceAppServicePlan(), + "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), + "azurerm_app_service": dataSourceArmAppService(), + "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), + "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), + "azurerm_azuread_application": dataSourceArmAzureADApplication(), + "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), + "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), + "azurerm_client_config": dataSourceArmClientConfig(), + "azurerm_eventhub_namespace": dataSourceEventHubNamespace(), + "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), + "azurerm_firewall": dataSourceArmFirewall(), + "azurerm_image": dataSourceArmImage(), + "azurerm_hdinsight_cluster": dataSourceArmHDInsightSparkCluster(), + "azurerm_healthcare_service": dataSourceArmHealthcareService(), "azurerm_maps_account": dataSourceArmMapsAccount(), "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), @@ -107,16 +107,16 @@ func Provider() terraform.ResourceProvider { "azurerm_backup_policy_file_share": resourceArmBackupProtectionPolicyFileShare(), "azurerm_backup_protected_file_share": resourceArmBackupProtectedFileShare(), "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), - "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), - "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_connection_monitor": resourceArmConnectionMonitor(), - "azurerm_dashboard": resourceArmDashboard(), - "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), - "azurerm_eventgrid_domain": resourceArmEventGridDomain(), - "azurerm_eventgrid_event_subscription": resourceArmEventGridEventSubscription(), - "azurerm_eventgrid_topic": resourceArmEventGridTopic(), - "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), - "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), + "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), + "azurerm_bastion_host": resourceArmBastionHost(), + "azurerm_connection_monitor": resourceArmConnectionMonitor(), + "azurerm_dashboard": resourceArmDashboard(), + "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), + "azurerm_eventgrid_domain": resourceArmEventGridDomain(), + "azurerm_eventgrid_event_subscription": resourceArmEventGridEventSubscription(), + "azurerm_eventgrid_topic": resourceArmEventGridTopic(), + "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), + "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), "azurerm_eventhub_namespace_authorization_rule": resourceArmEventHubNamespaceAuthorizationRule(), "azurerm_eventhub_namespace_disaster_recovery_config": resourceArmEventHubNamespaceDisasterRecoveryConfig(), "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), From b039ee2852be988f8bac8fe978911d8a2977b61b Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 16:59:41 -0800 Subject: [PATCH 025/203] eventgrid --- azurerm/internal/services/eventgrid/registration.go | 5 ++++- .../services/eventgrid}/resource_arm_eventgrid_domain.go | 2 +- .../eventgrid}/resource_arm_eventgrid_domain_test.go | 2 +- .../eventgrid}/resource_arm_eventgrid_event_subscription.go | 2 +- .../resource_arm_eventgrid_event_subscription_test.go | 2 +- .../services/eventgrid}/resource_arm_eventgrid_topic.go | 2 +- .../services/eventgrid}/resource_arm_eventgrid_topic_test.go | 2 +- azurerm/provider.go | 3 --- 8 files changed, 10 insertions(+), 10 deletions(-) rename azurerm/{ => internal/services/eventgrid}/resource_arm_eventgrid_domain.go (99%) rename azurerm/{ => internal/services/eventgrid}/resource_arm_eventgrid_domain_test.go (99%) rename azurerm/{ => internal/services/eventgrid}/resource_arm_eventgrid_event_subscription.go (99%) rename azurerm/{ => internal/services/eventgrid}/resource_arm_eventgrid_event_subscription_test.go (99%) rename azurerm/{ => internal/services/eventgrid}/resource_arm_eventgrid_topic.go (99%) rename azurerm/{ => internal/services/eventgrid}/resource_arm_eventgrid_topic_test.go (99%) diff --git a/azurerm/internal/services/eventgrid/registration.go b/azurerm/internal/services/eventgrid/registration.go index 167684455331..b12c789885d4 100644 --- a/azurerm/internal/services/eventgrid/registration.go +++ b/azurerm/internal/services/eventgrid/registration.go @@ -18,5 +18,8 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_eventgrid_domain": resourceArmEventGridDomain(), + "azurerm_eventgrid_event_subscription": resourceArmEventGridEventSubscription(), + "azurerm_eventgrid_topic": resourceArmEventGridTopic()} } diff --git a/azurerm/resource_arm_eventgrid_domain.go b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_domain.go similarity index 99% rename from azurerm/resource_arm_eventgrid_domain.go rename to azurerm/internal/services/eventgrid/resource_arm_eventgrid_domain.go index e66740c063cd..6330b171cf83 100644 --- a/azurerm/resource_arm_eventgrid_domain.go +++ b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_domain.go @@ -1,4 +1,4 @@ -package azurerm +package eventgrid import ( "fmt" diff --git a/azurerm/resource_arm_eventgrid_domain_test.go b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_domain_test.go similarity index 99% rename from azurerm/resource_arm_eventgrid_domain_test.go rename to azurerm/internal/services/eventgrid/resource_arm_eventgrid_domain_test.go index 55b9321b69ba..2e2aa2b83991 100644 --- a/azurerm/resource_arm_eventgrid_domain_test.go +++ b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_domain_test.go @@ -1,4 +1,4 @@ -package azurerm +package eventgrid import ( "fmt" diff --git a/azurerm/resource_arm_eventgrid_event_subscription.go b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription.go similarity index 99% rename from azurerm/resource_arm_eventgrid_event_subscription.go rename to azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription.go index 515dd0a1fa8b..90ff1a68d455 100644 --- a/azurerm/resource_arm_eventgrid_event_subscription.go +++ b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription.go @@ -1,4 +1,4 @@ -package azurerm +package eventgrid import ( "fmt" diff --git a/azurerm/resource_arm_eventgrid_event_subscription_test.go b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription_test.go similarity index 99% rename from azurerm/resource_arm_eventgrid_event_subscription_test.go rename to azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription_test.go index e066b3d35cc1..cbdc77d7e354 100644 --- a/azurerm/resource_arm_eventgrid_event_subscription_test.go +++ b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription_test.go @@ -1,4 +1,4 @@ -package azurerm +package eventgrid import ( "fmt" diff --git a/azurerm/resource_arm_eventgrid_topic.go b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_topic.go similarity index 99% rename from azurerm/resource_arm_eventgrid_topic.go rename to azurerm/internal/services/eventgrid/resource_arm_eventgrid_topic.go index 301a1810d034..40ff6c46b8ea 100644 --- a/azurerm/resource_arm_eventgrid_topic.go +++ b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_topic.go @@ -1,4 +1,4 @@ -package azurerm +package eventgrid import ( "fmt" diff --git a/azurerm/resource_arm_eventgrid_topic_test.go b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_topic_test.go similarity index 99% rename from azurerm/resource_arm_eventgrid_topic_test.go rename to azurerm/internal/services/eventgrid/resource_arm_eventgrid_topic_test.go index 58b4e0a9d1aa..17c737fd5765 100644 --- a/azurerm/resource_arm_eventgrid_topic_test.go +++ b/azurerm/internal/services/eventgrid/resource_arm_eventgrid_topic_test.go @@ -1,4 +1,4 @@ -package azurerm +package eventgrid import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 914867893afc..d821f5b7b9e5 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -112,9 +112,6 @@ func Provider() terraform.ResourceProvider { "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_dashboard": resourceArmDashboard(), "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), - "azurerm_eventgrid_domain": resourceArmEventGridDomain(), - "azurerm_eventgrid_event_subscription": resourceArmEventGridEventSubscription(), - "azurerm_eventgrid_topic": resourceArmEventGridTopic(), "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), "azurerm_eventhub_namespace_authorization_rule": resourceArmEventHubNamespaceAuthorizationRule(), From b66b97b62ec4c40fc8a6473a017a63fe666e9657 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:02:11 -0800 Subject: [PATCH 026/203] eventhub --- .../eventhub}/data_source_eventhub_namespace.go | 2 +- .../eventhub}/data_source_eventhub_namespace_test.go | 2 +- azurerm/internal/services/eventhub/registration.go | 12 ++++++++++-- .../services/eventhub}/resource_arm_eventhub.go | 2 +- .../resource_arm_eventhub_authorization_rule.go | 2 +- .../resource_arm_eventhub_authorization_rule_test.go | 2 +- .../resource_arm_eventhub_consumer_group.go | 2 +- .../resource_arm_eventhub_consumer_group_test.go | 2 +- .../eventhub}/resource_arm_eventhub_namespace.go | 2 +- ...urce_arm_eventhub_namespace_authorization_rule.go | 2 +- ...arm_eventhub_namespace_authorization_rule_test.go | 2 +- ...rm_eventhub_namespace_disaster_recovery_config.go | 2 +- ...enthub_namespace_disaster_recovery_config_test.go | 2 +- .../resource_arm_eventhub_namespace_test.go | 2 +- .../services/eventhub}/resource_arm_eventhub_test.go | 2 +- azurerm/provider.go | 7 ------- 16 files changed, 24 insertions(+), 23 deletions(-) rename azurerm/{ => internal/services/eventhub}/data_source_eventhub_namespace.go (99%) rename azurerm/{ => internal/services/eventhub}/data_source_eventhub_namespace_test.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_authorization_rule.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_authorization_rule_test.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_consumer_group.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_consumer_group_test.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_namespace.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_namespace_authorization_rule.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_namespace_authorization_rule_test.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_namespace_disaster_recovery_config.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_namespace_disaster_recovery_config_test.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_namespace_test.go (99%) rename azurerm/{ => internal/services/eventhub}/resource_arm_eventhub_test.go (99%) diff --git a/azurerm/data_source_eventhub_namespace.go b/azurerm/internal/services/eventhub/data_source_eventhub_namespace.go similarity index 99% rename from azurerm/data_source_eventhub_namespace.go rename to azurerm/internal/services/eventhub/data_source_eventhub_namespace.go index 9dc2e30d15c5..10577064105a 100644 --- a/azurerm/data_source_eventhub_namespace.go +++ b/azurerm/internal/services/eventhub/data_source_eventhub_namespace.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/data_source_eventhub_namespace_test.go b/azurerm/internal/services/eventhub/data_source_eventhub_namespace_test.go similarity index 99% rename from azurerm/data_source_eventhub_namespace_test.go rename to azurerm/internal/services/eventhub/data_source_eventhub_namespace_test.go index 54101f72dfc6..a7f69e2ab7eb 100644 --- a/azurerm/data_source_eventhub_namespace_test.go +++ b/azurerm/internal/services/eventhub/data_source_eventhub_namespace_test.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/internal/services/eventhub/registration.go b/azurerm/internal/services/eventhub/registration.go index bfeaa8486270..508b5a8bbfaf 100644 --- a/azurerm/internal/services/eventhub/registration.go +++ b/azurerm/internal/services/eventhub/registration.go @@ -13,10 +13,18 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_eventhub_namespace": dataSourceEventHubNamespace(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), + "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), + "azurerm_eventhub_namespace_authorization_rule": resourceArmEventHubNamespaceAuthorizationRule(), + "azurerm_eventhub_namespace_disaster_recovery_config": resourceArmEventHubNamespaceDisasterRecoveryConfig(), + "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), + "azurerm_eventhub": resourceArmEventHub()} } diff --git a/azurerm/resource_arm_eventhub.go b/azurerm/internal/services/eventhub/resource_arm_eventhub.go similarity index 99% rename from azurerm/resource_arm_eventhub.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub.go index fce5c3b70886..504604bb2618 100644 --- a/azurerm/resource_arm_eventhub.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/resource_arm_eventhub_authorization_rule.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule.go similarity index 99% rename from azurerm/resource_arm_eventhub_authorization_rule.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule.go index 13893a23ddc5..6c96f669d2a8 100644 --- a/azurerm/resource_arm_eventhub_authorization_rule.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/resource_arm_eventhub_authorization_rule_test.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule_test.go similarity index 99% rename from azurerm/resource_arm_eventhub_authorization_rule_test.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule_test.go index c78b7c4cc468..3900818828f8 100644 --- a/azurerm/resource_arm_eventhub_authorization_rule_test.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/resource_arm_eventhub_consumer_group.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group.go similarity index 99% rename from azurerm/resource_arm_eventhub_consumer_group.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group.go index b41c17a8838a..fc616306dfb5 100644 --- a/azurerm/resource_arm_eventhub_consumer_group.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/resource_arm_eventhub_consumer_group_test.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group_test.go similarity index 99% rename from azurerm/resource_arm_eventhub_consumer_group_test.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group_test.go index aa3183da50fc..2e3162d92856 100644 --- a/azurerm/resource_arm_eventhub_consumer_group_test.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/resource_arm_eventhub_namespace.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace.go similarity index 99% rename from azurerm/resource_arm_eventhub_namespace.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_namespace.go index 9cdf776ebcb2..53ea63e992eb 100644 --- a/azurerm/resource_arm_eventhub_namespace.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "context" diff --git a/azurerm/resource_arm_eventhub_namespace_authorization_rule.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule.go similarity index 99% rename from azurerm/resource_arm_eventhub_namespace_authorization_rule.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule.go index f8dff45d26dd..662320cb9b97 100644 --- a/azurerm/resource_arm_eventhub_namespace_authorization_rule.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule_test.go similarity index 99% rename from azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule_test.go index c9418e29d446..27d6075ff11e 100644 --- a/azurerm/resource_arm_eventhub_namespace_authorization_rule_test.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/resource_arm_eventhub_namespace_disaster_recovery_config.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_disaster_recovery_config.go similarity index 99% rename from azurerm/resource_arm_eventhub_namespace_disaster_recovery_config.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_disaster_recovery_config.go index 2aea5915d564..76ffa953d771 100644 --- a/azurerm/resource_arm_eventhub_namespace_disaster_recovery_config.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_disaster_recovery_config.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "context" diff --git a/azurerm/resource_arm_eventhub_namespace_disaster_recovery_config_test.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_disaster_recovery_config_test.go similarity index 99% rename from azurerm/resource_arm_eventhub_namespace_disaster_recovery_config_test.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_disaster_recovery_config_test.go index 4af9ad3e7ef7..8f07e2beb3f7 100644 --- a/azurerm/resource_arm_eventhub_namespace_disaster_recovery_config_test.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_disaster_recovery_config_test.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/resource_arm_eventhub_namespace_test.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_test.go similarity index 99% rename from azurerm/resource_arm_eventhub_namespace_test.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_test.go index 4abaec63af4a..f47a19679e75 100644 --- a/azurerm/resource_arm_eventhub_namespace_test.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_test.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/resource_arm_eventhub_test.go b/azurerm/internal/services/eventhub/resource_arm_eventhub_test.go similarity index 99% rename from azurerm/resource_arm_eventhub_test.go rename to azurerm/internal/services/eventhub/resource_arm_eventhub_test.go index b0ec315ba373..63cb17d9f0fa 100644 --- a/azurerm/resource_arm_eventhub_test.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub_test.go @@ -1,4 +1,4 @@ -package azurerm +package eventhub import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index d821f5b7b9e5..a738eb93539f 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -17,7 +17,6 @@ func Provider() terraform.ResourceProvider { "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_eventhub_namespace": dataSourceEventHubNamespace(), "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), "azurerm_firewall": dataSourceArmFirewall(), "azurerm_image": dataSourceArmImage(), @@ -112,12 +111,6 @@ func Provider() terraform.ResourceProvider { "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_dashboard": resourceArmDashboard(), "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), - "azurerm_eventhub_authorization_rule": resourceArmEventHubAuthorizationRule(), - "azurerm_eventhub_consumer_group": resourceArmEventHubConsumerGroup(), - "azurerm_eventhub_namespace_authorization_rule": resourceArmEventHubNamespaceAuthorizationRule(), - "azurerm_eventhub_namespace_disaster_recovery_config": resourceArmEventHubNamespaceDisasterRecoveryConfig(), - "azurerm_eventhub_namespace": resourceArmEventHubNamespace(), - "azurerm_eventhub": resourceArmEventHub(), "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), From 7359c49b116fe06778e7afd00e49be8fa9e277e8 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:04:31 -0800 Subject: [PATCH 027/203] frontdoor --- .../services/frontdoor/registration.go | 4 ++- .../frontdoor}/resource_arm_front_door.go | 25 +++++++++---------- ...resource_arm_front_door_firewall_policy.go | 9 +++---- ...rce_arm_front_door_firewall_policy_test.go | 2 +- .../resource_arm_front_door_test.go | 2 +- azurerm/provider.go | 2 -- 6 files changed, 21 insertions(+), 23 deletions(-) rename azurerm/{ => internal/services/frontdoor}/resource_arm_front_door.go (98%) rename azurerm/{ => internal/services/frontdoor}/resource_arm_front_door_firewall_policy.go (98%) rename azurerm/{ => internal/services/frontdoor}/resource_arm_front_door_firewall_policy_test.go (99%) rename azurerm/{ => internal/services/frontdoor}/resource_arm_front_door_test.go (99%) diff --git a/azurerm/internal/services/frontdoor/registration.go b/azurerm/internal/services/frontdoor/registration.go index 9a0f12f0e463..57231cd3b9c0 100644 --- a/azurerm/internal/services/frontdoor/registration.go +++ b/azurerm/internal/services/frontdoor/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_frontdoor": resourceArmFrontDoor(), + "azurerm_frontdoor_firewall_policy": resourceArmFrontDoorFirewallPolicy()} } diff --git a/azurerm/resource_arm_front_door.go b/azurerm/internal/services/frontdoor/resource_arm_front_door.go similarity index 98% rename from azurerm/resource_arm_front_door.go rename to azurerm/internal/services/frontdoor/resource_arm_front_door.go index 1016ad8839e7..3e382e256d59 100644 --- a/azurerm/resource_arm_front_door.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door.go @@ -1,4 +1,4 @@ -package azurerm +package frontdoor import ( "fmt" @@ -13,7 +13,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - afd "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/frontdoor" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -42,7 +41,7 @@ func resourceArmFrontDoor() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: afd.ValidateFrontDoorName, + ValidateFunc: ValidateFrontDoorName, }, "cname": { @@ -83,7 +82,7 @@ func resourceArmFrontDoor() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: afd.ValidateBackendPoolRoutingRuleName, + ValidateFunc: ValidateBackendPoolRoutingRuleName, }, "enabled": { Type: schema.TypeBool, @@ -171,7 +170,7 @@ func resourceArmFrontDoor() *schema.Resource { "backend_pool_name": { Type: schema.TypeString, Required: true, - ValidateFunc: afd.ValidateBackendPoolRoutingRuleName, + ValidateFunc: ValidateBackendPoolRoutingRuleName, }, "cache_use_dynamic_compression": { Type: schema.TypeBool, @@ -221,7 +220,7 @@ func resourceArmFrontDoor() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: afd.ValidateBackendPoolRoutingRuleName, + ValidateFunc: ValidateBackendPoolRoutingRuleName, }, "sample_size": { Type: schema.TypeInt, @@ -255,7 +254,7 @@ func resourceArmFrontDoor() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: afd.ValidateBackendPoolRoutingRuleName, + ValidateFunc: ValidateBackendPoolRoutingRuleName, }, "path": { Type: schema.TypeString, @@ -337,7 +336,7 @@ func resourceArmFrontDoor() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: afd.ValidateBackendPoolRoutingRuleName, + ValidateFunc: ValidateBackendPoolRoutingRuleName, }, "health_probe_name": { Type: schema.TypeString, @@ -364,7 +363,7 @@ func resourceArmFrontDoor() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: afd.ValidateBackendPoolRoutingRuleName, + ValidateFunc: ValidateBackendPoolRoutingRuleName, }, "host_name": { Type: schema.TypeString, @@ -436,7 +435,7 @@ func resourceArmFrontDoor() *schema.Resource { }, CustomizeDiff: func(d *schema.ResourceDiff, v interface{}) error { - if err := afd.ValidateFrontdoorSettings(d); err != nil { + if err := ValidateFrontdoorSettings(d); err != nil { return fmt.Errorf("Error creating Front Door %q (Resource Group %q): %+v", d.Get("name").(string), d.Get("resource_group_name").(string), err) } @@ -534,8 +533,8 @@ func resourceArmFrontDoorCreateUpdate(d *schema.ResourceData, meta interface{}) if provisioningState := properties.CustomHTTPSProvisioningState; provisioningState != "" { // Check to see if we are going to change the CustomHTTPSProvisioningState, if so check to // see if its current state is configurable, if not return an error... - if customHttpsProvisioningEnabled != afd.NormalizeCustomHTTPSProvisioningStateToBool(provisioningState) { - if err := afd.IsFrontDoorFrontendEndpointConfigurable(provisioningState, customHttpsProvisioningEnabled, frontendEndpointName, resourceGroup); err != nil { + if customHttpsProvisioningEnabled != NormalizeCustomHTTPSProvisioningStateToBool(provisioningState) { + if err := IsFrontDoorFrontendEndpointConfigurable(provisioningState, customHttpsProvisioningEnabled, frontendEndpointName, resourceGroup); err != nil { return err } } @@ -1338,7 +1337,7 @@ func flattenArmFrontDoorRoutingRule(input *[]frontdoor.RoutingRule) []interface{ } brc := properties.RouteConfiguration - if routeConfigType := afd.GetFrontDoorBasicRouteConfigurationType(brc.(interface{})); routeConfigType != "" { + if routeConfigType := GetFrontDoorBasicRouteConfigurationType(brc.(interface{})); routeConfigType != "" { rc := make([]interface{}, 0) c := make(map[string]interface{}) diff --git a/azurerm/resource_arm_front_door_firewall_policy.go b/azurerm/internal/services/frontdoor/resource_arm_front_door_firewall_policy.go similarity index 98% rename from azurerm/resource_arm_front_door_firewall_policy.go rename to azurerm/internal/services/frontdoor/resource_arm_front_door_firewall_policy.go index 327f520760a6..d5530e36938f 100644 --- a/azurerm/resource_arm_front_door_firewall_policy.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door_firewall_policy.go @@ -1,4 +1,4 @@ -package azurerm +package frontdoor import ( "fmt" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - afd "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/frontdoor" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -87,7 +86,7 @@ func resourceArmFrontDoorFirewallPolicy() *schema.Resource { "custom_block_response_body": { Type: schema.TypeString, Optional: true, - ValidateFunc: afd.ValidateCustomBlockResponseBody, + ValidateFunc: ValidateCustomBlockResponseBody, }, "custom_rule": { @@ -437,7 +436,7 @@ func resourceArmFrontDoorFirewallPolicyRead(d *schema.ResourceData, meta interfa return fmt.Errorf("Error flattening `managed_rule`: %+v", err) } - if err := d.Set("frontend_endpoint_ids", afd.FlattenFrontendEndpointLinkSlice(properties.FrontendEndpointLinks)); err != nil { + if err := d.Set("frontend_endpoint_ids", FlattenFrontendEndpointLinkSlice(properties.FrontendEndpointLinks)); err != nil { return fmt.Errorf("Error flattening `frontend_endpoint_ids`: %+v", err) } } @@ -695,7 +694,7 @@ func flattenArmFrontDoorFirewallMatchConditions(condition *[]frontdoor.MatchCond output["match_variable"] = string(c.MatchVariable) output["operator"] = string(c.Operator) output["match_values"] = utils.FlattenStringSlice(c.MatchValue) - output["transforms"] = afd.FlattenTransformSlice(c.Transforms) + output["transforms"] = FlattenTransformSlice(c.Transforms) if v := c.Selector; v != nil { output["selector"] = *v diff --git a/azurerm/resource_arm_front_door_firewall_policy_test.go b/azurerm/internal/services/frontdoor/resource_arm_front_door_firewall_policy_test.go similarity index 99% rename from azurerm/resource_arm_front_door_firewall_policy_test.go rename to azurerm/internal/services/frontdoor/resource_arm_front_door_firewall_policy_test.go index 04abf19e0490..cabccf6bf82f 100644 --- a/azurerm/resource_arm_front_door_firewall_policy_test.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door_firewall_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package frontdoor import ( "fmt" diff --git a/azurerm/resource_arm_front_door_test.go b/azurerm/internal/services/frontdoor/resource_arm_front_door_test.go similarity index 99% rename from azurerm/resource_arm_front_door_test.go rename to azurerm/internal/services/frontdoor/resource_arm_front_door_test.go index de1361646e5e..0e6f096cd737 100644 --- a/azurerm/resource_arm_front_door_test.go +++ b/azurerm/internal/services/frontdoor/resource_arm_front_door_test.go @@ -1,4 +1,4 @@ -package azurerm +package frontdoor import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index a738eb93539f..479b99c7d17c 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -118,8 +118,6 @@ func Provider() terraform.ResourceProvider { "azurerm_firewall_nat_rule_collection": resourceArmFirewallNatRuleCollection(), "azurerm_firewall_network_rule_collection": resourceArmFirewallNetworkRuleCollection(), "azurerm_firewall": resourceArmFirewall(), - "azurerm_frontdoor": resourceArmFrontDoor(), - "azurerm_frontdoor_firewall_policy": resourceArmFrontDoorFirewallPolicy(), "azurerm_function_app": resourceArmFunctionApp(), "azurerm_hdinsight_hadoop_cluster": resourceArmHDInsightHadoopCluster(), "azurerm_hdinsight_hbase_cluster": resourceArmHDInsightHBaseCluster(), From 4247c439963df9eea26bfba221d7e734c5d6a5aa Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:14:37 -0800 Subject: [PATCH 028/203] hdinsight --- .../graph}/data_source_azuread_application.go | 2 +- .../graph}/data_source_azuread_application_test.go | 2 +- .../data_source_azuread_service_principal.go | 2 +- .../data_source_azuread_service_principal_test.go | 2 +- azurerm/internal/services/graph/registration.go | 9 +++++++-- .../graph}/resource_arm_azuread_application.go | 2 +- .../resource_arm_azuread_application_test.go | 2 +- .../resource_arm_azuread_service_principal.go | 2 +- ...ource_arm_azuread_service_principal_password.go | 2 +- ..._arm_azuread_service_principal_password_test.go | 2 +- .../resource_arm_azuread_service_principal_test.go | 2 +- .../services/hdinsight}/common_hdinsight.go | 2 +- .../services/hdinsight}/common_hdinsight_test.go | 2 +- .../hdinsight}/data_source_hdinsight_cluster.go | 2 +- .../data_source_hdinsight_cluster_test.go | 2 +- .../internal/services/hdinsight/registration.go | 14 ++++++++++++-- .../resource_arm_hdinsight_hadoop_cluster.go | 2 +- .../resource_arm_hdinsight_hadoop_cluster_test.go | 2 +- .../resource_arm_hdinsight_hbase_cluster.go | 2 +- .../resource_arm_hdinsight_hbase_cluster_test.go | 2 +- ...urce_arm_hdinsight_interactive_query_cluster.go | 2 +- ...arm_hdinsight_interactive_query_cluster_test.go | 2 +- .../resource_arm_hdinsight_kafka_cluster.go | 2 +- .../resource_arm_hdinsight_kafka_cluster_test.go | 2 +- .../resource_arm_hdinsight_ml_services_cluster.go | 2 +- ...ource_arm_hdinsight_ml_services_cluster_test.go | 2 +- .../resource_arm_hdinsight_rserver_cluster.go | 2 +- .../resource_arm_hdinsight_rserver_cluster_test.go | 2 +- .../resource_arm_hdinsight_spark_cluster.go | 2 +- .../resource_arm_hdinsight_spark_cluster_test.go | 2 +- .../resource_arm_hdinsight_storm_cluster.go | 2 +- .../resource_arm_hdinsight_storm_cluster_test.go | 2 +- azurerm/provider.go | 14 -------------- 33 files changed, 49 insertions(+), 48 deletions(-) rename azurerm/{ => internal/services/graph}/data_source_azuread_application.go (99%) rename azurerm/{ => internal/services/graph}/data_source_azuread_application_test.go (99%) rename azurerm/{ => internal/services/graph}/data_source_azuread_service_principal.go (99%) rename azurerm/{ => internal/services/graph}/data_source_azuread_service_principal_test.go (99%) rename azurerm/{ => internal/services/graph}/resource_arm_azuread_application.go (99%) rename azurerm/{ => internal/services/graph}/resource_arm_azuread_application_test.go (99%) rename azurerm/{ => internal/services/graph}/resource_arm_azuread_service_principal.go (99%) rename azurerm/{ => internal/services/graph}/resource_arm_azuread_service_principal_password.go (99%) rename azurerm/{ => internal/services/graph}/resource_arm_azuread_service_principal_password_test.go (99%) rename azurerm/{ => internal/services/graph}/resource_arm_azuread_service_principal_test.go (99%) rename azurerm/{ => internal/services/hdinsight}/common_hdinsight.go (99%) rename azurerm/{ => internal/services/hdinsight}/common_hdinsight_test.go (99%) rename azurerm/{ => internal/services/hdinsight}/data_source_hdinsight_cluster.go (99%) rename azurerm/{ => internal/services/hdinsight}/data_source_hdinsight_cluster_test.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_hadoop_cluster.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_hadoop_cluster_test.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_hbase_cluster.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_hbase_cluster_test.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_interactive_query_cluster.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_interactive_query_cluster_test.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_kafka_cluster.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_kafka_cluster_test.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_ml_services_cluster.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_ml_services_cluster_test.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_rserver_cluster.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_rserver_cluster_test.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_spark_cluster.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_spark_cluster_test.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_storm_cluster.go (99%) rename azurerm/{ => internal/services/hdinsight}/resource_arm_hdinsight_storm_cluster_test.go (99%) diff --git a/azurerm/data_source_azuread_application.go b/azurerm/internal/services/graph/data_source_azuread_application.go similarity index 99% rename from azurerm/data_source_azuread_application.go rename to azurerm/internal/services/graph/data_source_azuread_application.go index 8c2f94d8da83..870b51b2c928 100644 --- a/azurerm/data_source_azuread_application.go +++ b/azurerm/internal/services/graph/data_source_azuread_application.go @@ -1,4 +1,4 @@ -package azurerm +package graph import ( "fmt" diff --git a/azurerm/data_source_azuread_application_test.go b/azurerm/internal/services/graph/data_source_azuread_application_test.go similarity index 99% rename from azurerm/data_source_azuread_application_test.go rename to azurerm/internal/services/graph/data_source_azuread_application_test.go index 1524c9e3217e..765938873e02 100644 --- a/azurerm/data_source_azuread_application_test.go +++ b/azurerm/internal/services/graph/data_source_azuread_application_test.go @@ -1,4 +1,4 @@ -package azurerm +package graph import ( "fmt" diff --git a/azurerm/data_source_azuread_service_principal.go b/azurerm/internal/services/graph/data_source_azuread_service_principal.go similarity index 99% rename from azurerm/data_source_azuread_service_principal.go rename to azurerm/internal/services/graph/data_source_azuread_service_principal.go index 5de6d3108504..fa054e83bb9f 100644 --- a/azurerm/data_source_azuread_service_principal.go +++ b/azurerm/internal/services/graph/data_source_azuread_service_principal.go @@ -1,4 +1,4 @@ -package azurerm +package graph import ( "fmt" diff --git a/azurerm/data_source_azuread_service_principal_test.go b/azurerm/internal/services/graph/data_source_azuread_service_principal_test.go similarity index 99% rename from azurerm/data_source_azuread_service_principal_test.go rename to azurerm/internal/services/graph/data_source_azuread_service_principal_test.go index 21db5699e6b3..704c58185617 100644 --- a/azurerm/data_source_azuread_service_principal_test.go +++ b/azurerm/internal/services/graph/data_source_azuread_service_principal_test.go @@ -1,4 +1,4 @@ -package azurerm +package graph import ( "fmt" diff --git a/azurerm/internal/services/graph/registration.go b/azurerm/internal/services/graph/registration.go index cf0f0bbe5673..1db0f8b85692 100644 --- a/azurerm/internal/services/graph/registration.go +++ b/azurerm/internal/services/graph/registration.go @@ -13,10 +13,15 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_azuread_application": dataSourceArmAzureADApplication(), + "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal()} } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_azuread_application": resourceArmActiveDirectoryApplication(), + "azurerm_azuread_service_principal_password": resourceArmActiveDirectoryServicePrincipalPassword(), + "azurerm_azuread_service_principal": resourceArmActiveDirectoryServicePrincipal()} } diff --git a/azurerm/resource_arm_azuread_application.go b/azurerm/internal/services/graph/resource_arm_azuread_application.go similarity index 99% rename from azurerm/resource_arm_azuread_application.go rename to azurerm/internal/services/graph/resource_arm_azuread_application.go index 0bca9a43919d..46a82d002b06 100644 --- a/azurerm/resource_arm_azuread_application.go +++ b/azurerm/internal/services/graph/resource_arm_azuread_application.go @@ -1,4 +1,4 @@ -package azurerm +package graph import ( "fmt" diff --git a/azurerm/resource_arm_azuread_application_test.go b/azurerm/internal/services/graph/resource_arm_azuread_application_test.go similarity index 99% rename from azurerm/resource_arm_azuread_application_test.go rename to azurerm/internal/services/graph/resource_arm_azuread_application_test.go index 10a66a228c21..53e7ff1356bd 100644 --- a/azurerm/resource_arm_azuread_application_test.go +++ b/azurerm/internal/services/graph/resource_arm_azuread_application_test.go @@ -1,4 +1,4 @@ -package azurerm +package graph import ( "fmt" diff --git a/azurerm/resource_arm_azuread_service_principal.go b/azurerm/internal/services/graph/resource_arm_azuread_service_principal.go similarity index 99% rename from azurerm/resource_arm_azuread_service_principal.go rename to azurerm/internal/services/graph/resource_arm_azuread_service_principal.go index e6eb128641af..7f00756957ce 100644 --- a/azurerm/resource_arm_azuread_service_principal.go +++ b/azurerm/internal/services/graph/resource_arm_azuread_service_principal.go @@ -1,4 +1,4 @@ -package azurerm +package graph import ( "fmt" diff --git a/azurerm/resource_arm_azuread_service_principal_password.go b/azurerm/internal/services/graph/resource_arm_azuread_service_principal_password.go similarity index 99% rename from azurerm/resource_arm_azuread_service_principal_password.go rename to azurerm/internal/services/graph/resource_arm_azuread_service_principal_password.go index 7c1f103c419b..7ef4c9ef3844 100644 --- a/azurerm/resource_arm_azuread_service_principal_password.go +++ b/azurerm/internal/services/graph/resource_arm_azuread_service_principal_password.go @@ -1,4 +1,4 @@ -package azurerm +package graph import ( "fmt" diff --git a/azurerm/resource_arm_azuread_service_principal_password_test.go b/azurerm/internal/services/graph/resource_arm_azuread_service_principal_password_test.go similarity index 99% rename from azurerm/resource_arm_azuread_service_principal_password_test.go rename to azurerm/internal/services/graph/resource_arm_azuread_service_principal_password_test.go index eb3b74246ae8..743b73adeca6 100644 --- a/azurerm/resource_arm_azuread_service_principal_password_test.go +++ b/azurerm/internal/services/graph/resource_arm_azuread_service_principal_password_test.go @@ -1,4 +1,4 @@ -package azurerm +package graph import ( "fmt" diff --git a/azurerm/resource_arm_azuread_service_principal_test.go b/azurerm/internal/services/graph/resource_arm_azuread_service_principal_test.go similarity index 99% rename from azurerm/resource_arm_azuread_service_principal_test.go rename to azurerm/internal/services/graph/resource_arm_azuread_service_principal_test.go index 20d5188c0ab7..af4a88e10c82 100644 --- a/azurerm/resource_arm_azuread_service_principal_test.go +++ b/azurerm/internal/services/graph/resource_arm_azuread_service_principal_test.go @@ -1,4 +1,4 @@ -package azurerm +package graph import ( "fmt" diff --git a/azurerm/common_hdinsight.go b/azurerm/internal/services/hdinsight/common_hdinsight.go similarity index 99% rename from azurerm/common_hdinsight.go rename to azurerm/internal/services/hdinsight/common_hdinsight.go index f6cc06d0b442..67f111884114 100644 --- a/azurerm/common_hdinsight.go +++ b/azurerm/internal/services/hdinsight/common_hdinsight.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "context" diff --git a/azurerm/common_hdinsight_test.go b/azurerm/internal/services/hdinsight/common_hdinsight_test.go similarity index 99% rename from azurerm/common_hdinsight_test.go rename to azurerm/internal/services/hdinsight/common_hdinsight_test.go index aaec0b754b5b..78160267018c 100644 --- a/azurerm/common_hdinsight_test.go +++ b/azurerm/internal/services/hdinsight/common_hdinsight_test.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/data_source_hdinsight_cluster.go b/azurerm/internal/services/hdinsight/data_source_hdinsight_cluster.go similarity index 99% rename from azurerm/data_source_hdinsight_cluster.go rename to azurerm/internal/services/hdinsight/data_source_hdinsight_cluster.go index e95235d9d168..6b4f6bfa33a7 100644 --- a/azurerm/data_source_hdinsight_cluster.go +++ b/azurerm/internal/services/hdinsight/data_source_hdinsight_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/data_source_hdinsight_cluster_test.go b/azurerm/internal/services/hdinsight/data_source_hdinsight_cluster_test.go similarity index 99% rename from azurerm/data_source_hdinsight_cluster_test.go rename to azurerm/internal/services/hdinsight/data_source_hdinsight_cluster_test.go index b630a2e14ab9..1bf50986cd25 100644 --- a/azurerm/data_source_hdinsight_cluster_test.go +++ b/azurerm/internal/services/hdinsight/data_source_hdinsight_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/internal/services/hdinsight/registration.go b/azurerm/internal/services/hdinsight/registration.go index f997efa9372e..7dade4b97802 100644 --- a/azurerm/internal/services/hdinsight/registration.go +++ b/azurerm/internal/services/hdinsight/registration.go @@ -13,10 +13,20 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_hdinsight_cluster": dataSourceArmHDInsightSparkCluster(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_hdinsight_hadoop_cluster": resourceArmHDInsightHadoopCluster(), + "azurerm_hdinsight_hbase_cluster": resourceArmHDInsightHBaseCluster(), + "azurerm_hdinsight_interactive_query_cluster": resourceArmHDInsightInteractiveQueryCluster(), + "azurerm_hdinsight_kafka_cluster": resourceArmHDInsightKafkaCluster(), + "azurerm_hdinsight_ml_services_cluster": resourceArmHDInsightMLServicesCluster(), + "azurerm_hdinsight_rserver_cluster": resourceArmHDInsightRServerCluster(), + "azurerm_hdinsight_spark_cluster": resourceArmHDInsightSparkCluster(), + "azurerm_hdinsight_storm_cluster": resourceArmHDInsightStormCluster()} } diff --git a/azurerm/resource_arm_hdinsight_hadoop_cluster.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hadoop_cluster.go similarity index 99% rename from azurerm/resource_arm_hdinsight_hadoop_cluster.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_hadoop_cluster.go index bc134ee358e9..7579c477c887 100644 --- a/azurerm/resource_arm_hdinsight_hadoop_cluster.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hadoop_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "context" diff --git a/azurerm/resource_arm_hdinsight_hadoop_cluster_test.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hadoop_cluster_test.go similarity index 99% rename from azurerm/resource_arm_hdinsight_hadoop_cluster_test.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_hadoop_cluster_test.go index da8fbc3e9f7d..ac4b233cd901 100644 --- a/azurerm/resource_arm_hdinsight_hadoop_cluster_test.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hadoop_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_hbase_cluster.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hbase_cluster.go similarity index 99% rename from azurerm/resource_arm_hdinsight_hbase_cluster.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_hbase_cluster.go index b5e2084f7e11..c791d08da058 100644 --- a/azurerm/resource_arm_hdinsight_hbase_cluster.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hbase_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_hbase_cluster_test.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hbase_cluster_test.go similarity index 99% rename from azurerm/resource_arm_hdinsight_hbase_cluster_test.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_hbase_cluster_test.go index c2c516aadafd..d7f7b42cf93c 100644 --- a/azurerm/resource_arm_hdinsight_hbase_cluster_test.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hbase_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_interactive_query_cluster.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_interactive_query_cluster.go similarity index 99% rename from azurerm/resource_arm_hdinsight_interactive_query_cluster.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_interactive_query_cluster.go index 4ed8d365fe54..1345687b77c6 100644 --- a/azurerm/resource_arm_hdinsight_interactive_query_cluster.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_interactive_query_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_interactive_query_cluster_test.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_interactive_query_cluster_test.go similarity index 99% rename from azurerm/resource_arm_hdinsight_interactive_query_cluster_test.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_interactive_query_cluster_test.go index 13b1886c9b2d..dc76dd69c6a9 100644 --- a/azurerm/resource_arm_hdinsight_interactive_query_cluster_test.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_interactive_query_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_kafka_cluster.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_kafka_cluster.go similarity index 99% rename from azurerm/resource_arm_hdinsight_kafka_cluster.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_kafka_cluster.go index e0633f1a21f9..9509eb03d737 100644 --- a/azurerm/resource_arm_hdinsight_kafka_cluster.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_kafka_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_kafka_cluster_test.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_kafka_cluster_test.go similarity index 99% rename from azurerm/resource_arm_hdinsight_kafka_cluster_test.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_kafka_cluster_test.go index 30bc331434bf..0d4f87738b73 100644 --- a/azurerm/resource_arm_hdinsight_kafka_cluster_test.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_kafka_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_ml_services_cluster.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_ml_services_cluster.go similarity index 99% rename from azurerm/resource_arm_hdinsight_ml_services_cluster.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_ml_services_cluster.go index a8366c2f1c84..4a14b5cced58 100644 --- a/azurerm/resource_arm_hdinsight_ml_services_cluster.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_ml_services_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_ml_services_cluster_test.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_ml_services_cluster_test.go similarity index 99% rename from azurerm/resource_arm_hdinsight_ml_services_cluster_test.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_ml_services_cluster_test.go index 4a93b9be54ba..437b0f584943 100644 --- a/azurerm/resource_arm_hdinsight_ml_services_cluster_test.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_ml_services_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_rserver_cluster.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_rserver_cluster.go similarity index 99% rename from azurerm/resource_arm_hdinsight_rserver_cluster.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_rserver_cluster.go index 8e2c4837aa7d..4f23e02b25eb 100644 --- a/azurerm/resource_arm_hdinsight_rserver_cluster.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_rserver_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_rserver_cluster_test.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_rserver_cluster_test.go similarity index 99% rename from azurerm/resource_arm_hdinsight_rserver_cluster_test.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_rserver_cluster_test.go index 4210a87b3065..00ebcc3c103f 100644 --- a/azurerm/resource_arm_hdinsight_rserver_cluster_test.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_rserver_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_spark_cluster.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_spark_cluster.go similarity index 99% rename from azurerm/resource_arm_hdinsight_spark_cluster.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_spark_cluster.go index 6700517f5ff2..b917330842df 100644 --- a/azurerm/resource_arm_hdinsight_spark_cluster.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_spark_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_spark_cluster_test.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_spark_cluster_test.go similarity index 99% rename from azurerm/resource_arm_hdinsight_spark_cluster_test.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_spark_cluster_test.go index 163d131ded66..a31cc5281a70 100644 --- a/azurerm/resource_arm_hdinsight_spark_cluster_test.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_spark_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_storm_cluster.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_storm_cluster.go similarity index 99% rename from azurerm/resource_arm_hdinsight_storm_cluster.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_storm_cluster.go index 9910742e9605..973760780452 100644 --- a/azurerm/resource_arm_hdinsight_storm_cluster.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_storm_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/resource_arm_hdinsight_storm_cluster_test.go b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_storm_cluster_test.go similarity index 99% rename from azurerm/resource_arm_hdinsight_storm_cluster_test.go rename to azurerm/internal/services/hdinsight/resource_arm_hdinsight_storm_cluster_test.go index 5abf123e18cf..dce011bd476d 100644 --- a/azurerm/resource_arm_hdinsight_storm_cluster_test.go +++ b/azurerm/internal/services/hdinsight/resource_arm_hdinsight_storm_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package hdinsight import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 479b99c7d17c..c924bd5f06ac 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -13,14 +13,11 @@ func Provider() terraform.ResourceProvider { "azurerm_app_service": dataSourceArmAppService(), "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_azuread_application": dataSourceArmAzureADApplication(), - "azurerm_azuread_service_principal": dataSourceArmActiveDirectoryServicePrincipal(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), "azurerm_firewall": dataSourceArmFirewall(), "azurerm_image": dataSourceArmImage(), - "azurerm_hdinsight_cluster": dataSourceArmHDInsightSparkCluster(), "azurerm_healthcare_service": dataSourceArmHealthcareService(), "azurerm_maps_account": dataSourceArmMapsAccount(), "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), @@ -99,9 +96,6 @@ func Provider() terraform.ResourceProvider { "azurerm_application_gateway": resourceArmApplicationGateway(), "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_azuread_application": resourceArmActiveDirectoryApplication(), - "azurerm_azuread_service_principal_password": resourceArmActiveDirectoryServicePrincipalPassword(), - "azurerm_azuread_service_principal": resourceArmActiveDirectoryServicePrincipal(), "azurerm_backup_container_storage_account": resourceArmBackupProtectionContainerStorageAccount(), "azurerm_backup_policy_file_share": resourceArmBackupProtectionPolicyFileShare(), "azurerm_backup_protected_file_share": resourceArmBackupProtectedFileShare(), @@ -119,14 +113,6 @@ func Provider() terraform.ResourceProvider { "azurerm_firewall_network_rule_collection": resourceArmFirewallNetworkRuleCollection(), "azurerm_firewall": resourceArmFirewall(), "azurerm_function_app": resourceArmFunctionApp(), - "azurerm_hdinsight_hadoop_cluster": resourceArmHDInsightHadoopCluster(), - "azurerm_hdinsight_hbase_cluster": resourceArmHDInsightHBaseCluster(), - "azurerm_hdinsight_interactive_query_cluster": resourceArmHDInsightInteractiveQueryCluster(), - "azurerm_hdinsight_kafka_cluster": resourceArmHDInsightKafkaCluster(), - "azurerm_hdinsight_ml_services_cluster": resourceArmHDInsightMLServicesCluster(), - "azurerm_hdinsight_rserver_cluster": resourceArmHDInsightRServerCluster(), - "azurerm_hdinsight_spark_cluster": resourceArmHDInsightSparkCluster(), - "azurerm_hdinsight_storm_cluster": resourceArmHDInsightStormCluster(), "azurerm_healthcare_service": resourceArmHealthcareService(), "azurerm_image": resourceArmImage(), "azurerm_iot_dps": resourceArmIotDPS(), From de6ef7b98bde3f6994717e86288378c374079903 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:17:19 -0800 Subject: [PATCH 029/203] healthcare --- .../healthcare}/data_source_healthcare_service.go | 2 +- .../healthcare}/data_source_healthcare_service_test.go | 2 +- azurerm/internal/services/healthcare/registration.go | 8 ++++++-- .../healthcare}/resource_arm_healthcare_service.go | 2 +- .../healthcare}/resource_arm_healthcare_service_test.go | 2 +- azurerm/provider.go | 2 -- 6 files changed, 10 insertions(+), 8 deletions(-) rename azurerm/{ => internal/services/healthcare}/data_source_healthcare_service.go (99%) rename azurerm/{ => internal/services/healthcare}/data_source_healthcare_service_test.go (98%) rename azurerm/{ => internal/services/healthcare}/resource_arm_healthcare_service.go (99%) rename azurerm/{ => internal/services/healthcare}/resource_arm_healthcare_service_test.go (99%) diff --git a/azurerm/data_source_healthcare_service.go b/azurerm/internal/services/healthcare/data_source_healthcare_service.go similarity index 99% rename from azurerm/data_source_healthcare_service.go rename to azurerm/internal/services/healthcare/data_source_healthcare_service.go index 6a1f92b08fc9..bd8c2c93e0d1 100644 --- a/azurerm/data_source_healthcare_service.go +++ b/azurerm/internal/services/healthcare/data_source_healthcare_service.go @@ -1,4 +1,4 @@ -package azurerm +package healthcare import ( "fmt" diff --git a/azurerm/data_source_healthcare_service_test.go b/azurerm/internal/services/healthcare/data_source_healthcare_service_test.go similarity index 98% rename from azurerm/data_source_healthcare_service_test.go rename to azurerm/internal/services/healthcare/data_source_healthcare_service_test.go index c021d5cdf821..b1270b4baad7 100644 --- a/azurerm/data_source_healthcare_service_test.go +++ b/azurerm/internal/services/healthcare/data_source_healthcare_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package healthcare import ( "fmt" diff --git a/azurerm/internal/services/healthcare/registration.go b/azurerm/internal/services/healthcare/registration.go index 160053b5c243..19171d82ada9 100644 --- a/azurerm/internal/services/healthcare/registration.go +++ b/azurerm/internal/services/healthcare/registration.go @@ -13,10 +13,14 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_healthcare_service": dataSourceArmHealthcareService(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_healthcare_service": resourceArmHealthcareService(), + } } diff --git a/azurerm/resource_arm_healthcare_service.go b/azurerm/internal/services/healthcare/resource_arm_healthcare_service.go similarity index 99% rename from azurerm/resource_arm_healthcare_service.go rename to azurerm/internal/services/healthcare/resource_arm_healthcare_service.go index d677aa9ee5f9..56cc25e228e3 100644 --- a/azurerm/resource_arm_healthcare_service.go +++ b/azurerm/internal/services/healthcare/resource_arm_healthcare_service.go @@ -1,4 +1,4 @@ -package azurerm +package healthcare import ( "fmt" diff --git a/azurerm/resource_arm_healthcare_service_test.go b/azurerm/internal/services/healthcare/resource_arm_healthcare_service_test.go similarity index 99% rename from azurerm/resource_arm_healthcare_service_test.go rename to azurerm/internal/services/healthcare/resource_arm_healthcare_service_test.go index 1ba84bbaa2ed..664c1e9b7819 100644 --- a/azurerm/resource_arm_healthcare_service_test.go +++ b/azurerm/internal/services/healthcare/resource_arm_healthcare_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package healthcare import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index c924bd5f06ac..1a44d713152c 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -18,7 +18,6 @@ func Provider() terraform.ResourceProvider { "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), "azurerm_firewall": dataSourceArmFirewall(), "azurerm_image": dataSourceArmImage(), - "azurerm_healthcare_service": dataSourceArmHealthcareService(), "azurerm_maps_account": dataSourceArmMapsAccount(), "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), @@ -113,7 +112,6 @@ func Provider() terraform.ResourceProvider { "azurerm_firewall_network_rule_collection": resourceArmFirewallNetworkRuleCollection(), "azurerm_firewall": resourceArmFirewall(), "azurerm_function_app": resourceArmFunctionApp(), - "azurerm_healthcare_service": resourceArmHealthcareService(), "azurerm_image": resourceArmImage(), "azurerm_iot_dps": resourceArmIotDPS(), "azurerm_iot_dps_certificate": resourceArmIotDPSCertificate(), From 181924370953c2c4c8ed5113d86668222a190939 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:22:10 -0800 Subject: [PATCH 030/203] iothub --- azurerm/internal/services/iothub/registration.go | 16 +++++++++++++++- .../services/iothub}/resource_arm_iot_dps.go | 2 +- .../iothub}/resource_arm_iot_dps_certificate.go | 2 +- .../resource_arm_iot_dps_certificate_test.go | 2 +- .../iothub}/resource_arm_iot_dps_test.go | 2 +- .../services/iothub}/resource_arm_iothub.go | 12 ++++++------ .../resource_arm_iothub_consumer_group.go | 2 +- .../resource_arm_iothub_consumer_group_test.go | 2 +- .../services/iothub}/resource_arm_iothub_dps.go | 2 +- .../resource_arm_iothub_dps_certificate.go | 2 +- .../resource_arm_iothub_dps_certificate_test.go | 2 +- ...source_arm_iothub_dps_shared_access_policy.go | 10 +++++----- ...e_arm_iothub_dps_shared_access_policy_test.go | 2 +- .../iothub}/resource_arm_iothub_dps_test.go | 2 +- .../resource_arm_iothub_endpoint_eventhub.go | 10 +++++----- ...resource_arm_iothub_endpoint_eventhub_test.go | 2 +- ...ource_arm_iothub_endpoint_servicebus_queue.go | 10 +++++----- ..._arm_iothub_endpoint_servicebus_queue_test.go | 2 +- ...ource_arm_iothub_endpoint_servicebus_topic.go | 10 +++++----- ..._arm_iothub_endpoint_servicebus_topic_test.go | 2 +- ...urce_arm_iothub_endpoint_storage_container.go | 10 +++++----- ...arm_iothub_endpoint_storage_container_test.go | 2 +- .../resource_arm_iothub_fallback_route.go | 10 +++++----- .../resource_arm_iothub_fallback_route_test.go | 2 +- .../iothub}/resource_arm_iothub_route.go | 10 +++++----- .../iothub}/resource_arm_iothub_route_test.go | 2 +- .../resource_arm_iothub_shared_access_policy.go | 10 +++++----- ...ource_arm_iothub_shared_access_policy_test.go | 2 +- .../services/iothub}/resource_arm_iothub_test.go | 2 +- azurerm/provider.go | 14 -------------- azurerm/resource_arm_storage_account.go | 5 +++-- 31 files changed, 83 insertions(+), 82 deletions(-) rename azurerm/{ => internal/services/iothub}/resource_arm_iot_dps.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iot_dps_certificate.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iot_dps_certificate_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iot_dps_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_consumer_group.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_consumer_group_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_dps.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_dps_certificate.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_dps_certificate_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_dps_shared_access_policy.go (98%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_dps_shared_access_policy_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_dps_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_endpoint_eventhub.go (97%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_endpoint_eventhub_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_endpoint_servicebus_queue.go (97%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_endpoint_servicebus_queue_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_endpoint_servicebus_topic.go (97%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_endpoint_servicebus_topic_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_endpoint_storage_container.go (97%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_endpoint_storage_container_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_fallback_route.go (96%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_fallback_route_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_route.go (97%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_route_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_shared_access_policy.go (98%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_shared_access_policy_test.go (99%) rename azurerm/{ => internal/services/iothub}/resource_arm_iothub_test.go (99%) diff --git a/azurerm/internal/services/iothub/registration.go b/azurerm/internal/services/iothub/registration.go index a1bd4d0a1aeb..1af7d49fa0d5 100644 --- a/azurerm/internal/services/iothub/registration.go +++ b/azurerm/internal/services/iothub/registration.go @@ -18,5 +18,19 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_iot_dps": resourceArmIotDPS(), + "azurerm_iot_dps_certificate": resourceArmIotDPSCertificate(), + "azurerm_iothub_dps": resourceArmIotHubDPS(), + "azurerm_iothub_dps_certificate": resourceArmIotHubDPSCertificate(), + "azurerm_iothub_dps_shared_access_policy": resourceArmIotHubDPSSharedAccessPolicy(), + "azurerm_iothub_consumer_group": resourceArmIotHubConsumerGroup(), + "azurerm_iothub": resourceArmIotHub(), + "azurerm_iothub_fallback_route": resourceArmIotHubFallbackRoute(), + "azurerm_iothub_route": resourceArmIotHubRoute(), + "azurerm_iothub_endpoint_eventhub": resourceArmIotHubEndpointEventHub(), + "azurerm_iothub_endpoint_servicebus_queue": resourceArmIotHubEndpointServiceBusQueue(), + "azurerm_iothub_endpoint_servicebus_topic": resourceArmIotHubEndpointServiceBusTopic(), + "azurerm_iothub_endpoint_storage_container": resourceArmIotHubEndpointStorageContainer(), + "azurerm_iothub_shared_access_policy": resourceArmIotHubSharedAccessPolicy()} } diff --git a/azurerm/resource_arm_iot_dps.go b/azurerm/internal/services/iothub/resource_arm_iot_dps.go similarity index 99% rename from azurerm/resource_arm_iot_dps.go rename to azurerm/internal/services/iothub/resource_arm_iot_dps.go index 29782c8881d2..c6d401a86c35 100644 --- a/azurerm/resource_arm_iot_dps.go +++ b/azurerm/internal/services/iothub/resource_arm_iot_dps.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "context" diff --git a/azurerm/resource_arm_iot_dps_certificate.go b/azurerm/internal/services/iothub/resource_arm_iot_dps_certificate.go similarity index 99% rename from azurerm/resource_arm_iot_dps_certificate.go rename to azurerm/internal/services/iothub/resource_arm_iot_dps_certificate.go index 34835677c9a9..82ca1d1f2cde 100644 --- a/azurerm/resource_arm_iot_dps_certificate.go +++ b/azurerm/internal/services/iothub/resource_arm_iot_dps_certificate.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iot_dps_certificate_test.go b/azurerm/internal/services/iothub/resource_arm_iot_dps_certificate_test.go similarity index 99% rename from azurerm/resource_arm_iot_dps_certificate_test.go rename to azurerm/internal/services/iothub/resource_arm_iot_dps_certificate_test.go index 025a0a027acf..b1597915ec69 100644 --- a/azurerm/resource_arm_iot_dps_certificate_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iot_dps_certificate_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iot_dps_test.go b/azurerm/internal/services/iothub/resource_arm_iot_dps_test.go similarity index 99% rename from azurerm/resource_arm_iot_dps_test.go rename to azurerm/internal/services/iothub/resource_arm_iot_dps_test.go index d6542e29e55c..2ddd83b1a558 100644 --- a/azurerm/resource_arm_iot_dps_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iot_dps_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub.go b/azurerm/internal/services/iothub/resource_arm_iothub.go similarity index 99% rename from azurerm/resource_arm_iothub.go rename to azurerm/internal/services/iothub/resource_arm_iothub.go index ead69888cd3f..dbd2c9c1205d 100644 --- a/azurerm/resource_arm_iothub.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "context" @@ -26,7 +26,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -var iothubResourceName = "azurerm_iothub" +var IothubResourceName = "azurerm_iothub" func suppressIfTypeIsNot(t string) schema.SchemaDiffSuppressFunc { return func(k, old, new string, d *schema.ResourceData) bool { @@ -438,8 +438,8 @@ func resourceArmIotHubCreateUpdate(d *schema.ResourceData, meta interface{}) err name := d.Get("name").(string) resourceGroup := d.Get("resource_group_name").(string) - locks.ByName(name, iothubResourceName) - defer locks.UnlockByName(name, iothubResourceName) + locks.ByName(name, IothubResourceName) + defer locks.UnlockByName(name, IothubResourceName) if features.ShouldResourcesBeImported() && d.IsNewResource() { existing, err := client.Get(ctx, resourceGroup, name) @@ -634,8 +634,8 @@ func resourceArmIotHubDelete(d *schema.ResourceData, meta interface{}) error { name := id.Path["IotHubs"] resourceGroup := id.ResourceGroup - locks.ByName(name, iothubResourceName) - defer locks.UnlockByName(name, iothubResourceName) + locks.ByName(name, IothubResourceName) + defer locks.UnlockByName(name, IothubResourceName) future, err := client.Delete(ctx, resourceGroup, name) if err != nil { diff --git a/azurerm/resource_arm_iothub_consumer_group.go b/azurerm/internal/services/iothub/resource_arm_iothub_consumer_group.go similarity index 99% rename from azurerm/resource_arm_iothub_consumer_group.go rename to azurerm/internal/services/iothub/resource_arm_iothub_consumer_group.go index 2744d47e51e6..709c914bd105 100644 --- a/azurerm/resource_arm_iothub_consumer_group.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_consumer_group.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_consumer_group_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_consumer_group_test.go similarity index 99% rename from azurerm/resource_arm_iothub_consumer_group_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_consumer_group_test.go index 94ae3eafae6d..79cd21ffb9d1 100644 --- a/azurerm/resource_arm_iothub_consumer_group_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_consumer_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_dps.go b/azurerm/internal/services/iothub/resource_arm_iothub_dps.go similarity index 99% rename from azurerm/resource_arm_iothub_dps.go rename to azurerm/internal/services/iothub/resource_arm_iothub_dps.go index f3fa481765d2..9c43017114ef 100644 --- a/azurerm/resource_arm_iothub_dps.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_dps.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "context" diff --git a/azurerm/resource_arm_iothub_dps_certificate.go b/azurerm/internal/services/iothub/resource_arm_iothub_dps_certificate.go similarity index 99% rename from azurerm/resource_arm_iothub_dps_certificate.go rename to azurerm/internal/services/iothub/resource_arm_iothub_dps_certificate.go index 1acc196dfd7a..7c0f650839c5 100644 --- a/azurerm/resource_arm_iothub_dps_certificate.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_dps_certificate.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_dps_certificate_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_dps_certificate_test.go similarity index 99% rename from azurerm/resource_arm_iothub_dps_certificate_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_dps_certificate_test.go index fc79c910d91f..8951948e5be2 100644 --- a/azurerm/resource_arm_iothub_dps_certificate_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_dps_certificate_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_dps_shared_access_policy.go b/azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy.go similarity index 98% rename from azurerm/resource_arm_iothub_dps_shared_access_policy.go rename to azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy.go index 9888fc1d1817..324e3421e3a0 100644 --- a/azurerm/resource_arm_iothub_dps_shared_access_policy.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" @@ -121,8 +121,8 @@ func resourceArmIotHubDPSSharedAccessPolicyCreateUpdate(d *schema.ResourceData, iothubDpsName := d.Get("iothub_dps_name").(string) resourceGroup := d.Get("resource_group_name").(string) - locks.ByName(iothubDpsName, iothubResourceName) - defer locks.UnlockByName(iothubDpsName, iothubResourceName) + locks.ByName(iothubDpsName, IothubResourceName) + defer locks.UnlockByName(iothubDpsName, IothubResourceName) iothubDps, err := client.Get(ctx, iothubDpsName, resourceGroup) if err != nil { @@ -274,8 +274,8 @@ func resourceArmIotHubDPSSharedAccessPolicyDelete(d *schema.ResourceData, meta i iothubDpsName := id.Path["provisioningServices"] keyName := id.Path["keys"] - locks.ByName(iothubDpsName, iothubResourceName) - defer locks.UnlockByName(iothubDpsName, iothubResourceName) + locks.ByName(iothubDpsName, IothubResourceName) + defer locks.UnlockByName(iothubDpsName, IothubResourceName) iothubDps, err := client.Get(ctx, iothubDpsName, resourceGroup) if err != nil { diff --git a/azurerm/resource_arm_iothub_dps_shared_access_policy_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy_test.go similarity index 99% rename from azurerm/resource_arm_iothub_dps_shared_access_policy_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy_test.go index 3e7582fa8a83..a1717bdf8cb5 100644 --- a/azurerm/resource_arm_iothub_dps_shared_access_policy_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_dps_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_dps_test.go similarity index 99% rename from azurerm/resource_arm_iothub_dps_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_dps_test.go index 4ff895ef267c..e73987f44e1e 100644 --- a/azurerm/resource_arm_iothub_dps_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_dps_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_endpoint_eventhub.go b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_eventhub.go similarity index 97% rename from azurerm/resource_arm_iothub_endpoint_eventhub.go rename to azurerm/internal/services/iothub/resource_arm_iothub_endpoint_eventhub.go index d9cd01e5336f..4418204d86ac 100644 --- a/azurerm/resource_arm_iothub_endpoint_eventhub.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_eventhub.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" @@ -77,8 +77,8 @@ func resourceArmIotHubEndpointEventHubCreateUpdate(d *schema.ResourceData, meta iothubName := d.Get("iothub_name").(string) resourceGroup := d.Get("resource_group_name").(string) - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { @@ -204,8 +204,8 @@ func resourceArmIotHubEndpointEventHubDelete(d *schema.ResourceData, meta interf iothubName := parsedIothubEndpointId.Path["IotHubs"] endpointName := parsedIothubEndpointId.Path["Endpoints"] - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { diff --git a/azurerm/resource_arm_iothub_endpoint_eventhub_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_eventhub_test.go similarity index 99% rename from azurerm/resource_arm_iothub_endpoint_eventhub_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_endpoint_eventhub_test.go index a44c944ff76b..414533270b55 100644 --- a/azurerm/resource_arm_iothub_endpoint_eventhub_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_eventhub_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_endpoint_servicebus_queue.go b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_queue.go similarity index 97% rename from azurerm/resource_arm_iothub_endpoint_servicebus_queue.go rename to azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_queue.go index 4c8fc89c058e..9f63cf370392 100644 --- a/azurerm/resource_arm_iothub_endpoint_servicebus_queue.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_queue.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" @@ -78,8 +78,8 @@ func resourceArmIotHubEndpointServiceBusQueueCreateUpdate(d *schema.ResourceData iothubName := d.Get("iothub_name").(string) resourceGroup := d.Get("resource_group_name").(string) - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { @@ -207,8 +207,8 @@ func resourceArmIotHubEndpointServiceBusQueueDelete(d *schema.ResourceData, meta iothubName := parsedIothubEndpointId.Path["IotHubs"] endpointName := parsedIothubEndpointId.Path["Endpoints"] - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { diff --git a/azurerm/resource_arm_iothub_endpoint_servicebus_queue_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_queue_test.go similarity index 99% rename from azurerm/resource_arm_iothub_endpoint_servicebus_queue_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_queue_test.go index 150647ed90f0..3e79f0e6a742 100644 --- a/azurerm/resource_arm_iothub_endpoint_servicebus_queue_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_queue_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_endpoint_servicebus_topic.go b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_topic.go similarity index 97% rename from azurerm/resource_arm_iothub_endpoint_servicebus_topic.go rename to azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_topic.go index 2ec8dd1f8ce0..ecd2a8d750ba 100644 --- a/azurerm/resource_arm_iothub_endpoint_servicebus_topic.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_topic.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" @@ -78,8 +78,8 @@ func resourceArmIotHubEndpointServiceBusTopicCreateUpdate(d *schema.ResourceData iothubName := d.Get("iothub_name").(string) resourceGroup := d.Get("resource_group_name").(string) - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { @@ -207,8 +207,8 @@ func resourceArmIotHubEndpointServiceBusTopicDelete(d *schema.ResourceData, meta iothubName := parsedIothubEndpointId.Path["IotHubs"] endpointName := parsedIothubEndpointId.Path["Endpoints"] - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { diff --git a/azurerm/resource_arm_iothub_endpoint_servicebus_topic_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_topic_test.go similarity index 99% rename from azurerm/resource_arm_iothub_endpoint_servicebus_topic_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_topic_test.go index 6da28f09f1e0..0f663c7bc9dc 100644 --- a/azurerm/resource_arm_iothub_endpoint_servicebus_topic_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_topic_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_endpoint_storage_container.go b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_storage_container.go similarity index 97% rename from azurerm/resource_arm_iothub_endpoint_storage_container.go rename to azurerm/internal/services/iothub/resource_arm_iothub_endpoint_storage_container.go index 5cb8c95e6060..b25ab7f4c558 100644 --- a/azurerm/resource_arm_iothub_endpoint_storage_container.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_storage_container.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" @@ -113,8 +113,8 @@ func resourceArmIotHubEndpointStorageContainerCreateUpdate(d *schema.ResourceDat iothubName := d.Get("iothub_name").(string) resourceGroup := d.Get("resource_group_name").(string) - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { @@ -259,8 +259,8 @@ func resourceArmIotHubEndpointStorageContainerDelete(d *schema.ResourceData, met iothubName := parsedIothubEndpointId.Path["IotHubs"] endpointName := parsedIothubEndpointId.Path["Endpoints"] - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { diff --git a/azurerm/resource_arm_iothub_endpoint_storage_container_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_storage_container_test.go similarity index 99% rename from azurerm/resource_arm_iothub_endpoint_storage_container_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_endpoint_storage_container_test.go index 781066b840e4..58f55cdff048 100644 --- a/azurerm/resource_arm_iothub_endpoint_storage_container_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_storage_container_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_fallback_route.go b/azurerm/internal/services/iothub/resource_arm_iothub_fallback_route.go similarity index 96% rename from azurerm/resource_arm_iothub_fallback_route.go rename to azurerm/internal/services/iothub/resource_arm_iothub_fallback_route.go index e5835c8c3afa..29d695888048 100644 --- a/azurerm/resource_arm_iothub_fallback_route.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_fallback_route.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" @@ -78,8 +78,8 @@ func resourceArmIotHubFallbackRouteCreateUpdate(d *schema.ResourceData, meta int iothubName := d.Get("iothub_name").(string) resourceGroup := d.Get("resource_group_name").(string) - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { @@ -170,8 +170,8 @@ func resourceArmIotHubFallbackRouteDelete(d *schema.ResourceData, meta interface resourceGroup := parsedIothubRouteId.ResourceGroup iothubName := parsedIothubRouteId.Path["IotHubs"] - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { diff --git a/azurerm/resource_arm_iothub_fallback_route_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_fallback_route_test.go similarity index 99% rename from azurerm/resource_arm_iothub_fallback_route_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_fallback_route_test.go index 0baa75b48a31..aabc4a76f707 100644 --- a/azurerm/resource_arm_iothub_fallback_route_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_fallback_route_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_route.go b/azurerm/internal/services/iothub/resource_arm_iothub_route.go similarity index 97% rename from azurerm/resource_arm_iothub_route.go rename to azurerm/internal/services/iothub/resource_arm_iothub_route.go index d1c7828e7be1..749a0d961a56 100644 --- a/azurerm/resource_arm_iothub_route.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_route.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" @@ -99,8 +99,8 @@ func resourceArmIotHubRouteCreateUpdate(d *schema.ResourceData, meta interface{} iothubName := d.Get("iothub_name").(string) resourceGroup := d.Get("resource_group_name").(string) - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { @@ -235,8 +235,8 @@ func resourceArmIotHubRouteDelete(d *schema.ResourceData, meta interface{}) erro iothubName := parsedIothubRouteId.Path["IotHubs"] routeName := parsedIothubRouteId.Path["Routes"] - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { diff --git a/azurerm/resource_arm_iothub_route_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_route_test.go similarity index 99% rename from azurerm/resource_arm_iothub_route_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_route_test.go index 56494d4aee3b..ca388827912d 100644 --- a/azurerm/resource_arm_iothub_route_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_route_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_shared_access_policy.go b/azurerm/internal/services/iothub/resource_arm_iothub_shared_access_policy.go similarity index 98% rename from azurerm/resource_arm_iothub_shared_access_policy.go rename to azurerm/internal/services/iothub/resource_arm_iothub_shared_access_policy.go index aff8d9729ddc..e3c69a0c613c 100644 --- a/azurerm/resource_arm_iothub_shared_access_policy.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_shared_access_policy.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" @@ -137,8 +137,8 @@ func resourceArmIotHubSharedAccessPolicyCreateUpdate(d *schema.ResourceData, met iothubName := d.Get("iothub_name").(string) resourceGroup := d.Get("resource_group_name").(string) - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { @@ -268,8 +268,8 @@ func resourceArmIotHubSharedAccessPolicyDelete(d *schema.ResourceData, meta inte iothubName := parsedIothubSAPId.Path["IotHubs"] keyName := parsedIothubSAPId.Path["IotHubKeys"] - locks.ByName(iothubName, iothubResourceName) - defer locks.UnlockByName(iothubName, iothubResourceName) + locks.ByName(iothubName, IothubResourceName) + defer locks.UnlockByName(iothubName, IothubResourceName) iothub, err := client.Get(ctx, resourceGroup, iothubName) if err != nil { diff --git a/azurerm/resource_arm_iothub_shared_access_policy_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_shared_access_policy_test.go similarity index 99% rename from azurerm/resource_arm_iothub_shared_access_policy_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_shared_access_policy_test.go index 281e0d5e9edc..0c974e9e3ab0 100644 --- a/azurerm/resource_arm_iothub_shared_access_policy_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_shared_access_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/resource_arm_iothub_test.go b/azurerm/internal/services/iothub/resource_arm_iothub_test.go similarity index 99% rename from azurerm/resource_arm_iothub_test.go rename to azurerm/internal/services/iothub/resource_arm_iothub_test.go index 82e479683834..c113071e6794 100644 --- a/azurerm/resource_arm_iothub_test.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_test.go @@ -1,4 +1,4 @@ -package azurerm +package iothub import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 1a44d713152c..69d2b3a31392 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -113,20 +113,6 @@ func Provider() terraform.ResourceProvider { "azurerm_firewall": resourceArmFirewall(), "azurerm_function_app": resourceArmFunctionApp(), "azurerm_image": resourceArmImage(), - "azurerm_iot_dps": resourceArmIotDPS(), - "azurerm_iot_dps_certificate": resourceArmIotDPSCertificate(), - "azurerm_iothub_dps": resourceArmIotHubDPS(), - "azurerm_iothub_dps_certificate": resourceArmIotHubDPSCertificate(), - "azurerm_iothub_dps_shared_access_policy": resourceArmIotHubDPSSharedAccessPolicy(), - "azurerm_iothub_consumer_group": resourceArmIotHubConsumerGroup(), - "azurerm_iothub": resourceArmIotHub(), - "azurerm_iothub_fallback_route": resourceArmIotHubFallbackRoute(), - "azurerm_iothub_route": resourceArmIotHubRoute(), - "azurerm_iothub_endpoint_eventhub": resourceArmIotHubEndpointEventHub(), - "azurerm_iothub_endpoint_servicebus_queue": resourceArmIotHubEndpointServiceBusQueue(), - "azurerm_iothub_endpoint_servicebus_topic": resourceArmIotHubEndpointServiceBusTopic(), - "azurerm_iothub_endpoint_storage_container": resourceArmIotHubEndpointStorageContainer(), - "azurerm_iothub_shared_access_policy": resourceArmIotHubSharedAccessPolicy(), "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), "azurerm_key_vault_key": resourceArmKeyVaultKey(), diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/resource_arm_storage_account.go index 999f960c766e..f68acd884561 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/resource_arm_storage_account.go @@ -2,6 +2,7 @@ package azurerm import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub" "log" "net/http" "regexp" @@ -842,8 +843,8 @@ func resourceArmStorageAccountUpdate(d *schema.ResourceData, meta interface{}) e storageAccountName := id.Path["storageAccounts"] resourceGroupName := id.ResourceGroup - locks.ByName(storageAccountName, iothubResourceName) - defer locks.UnlockByName(storageAccountName, iothubResourceName) + locks.ByName(storageAccountName, iothub.IothubResourceName) + defer locks.UnlockByName(storageAccountName, iothub.IothubResourceName) accountTier := d.Get("account_tier").(string) replicationType := d.Get("account_replication_type").(string) From 3c88faaaee5a8222c860e240fb2b9198c9a0e3d5 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:30:34 -0800 Subject: [PATCH 031/203] kusot --- .../services/kusto}/resource_arm_kusto_cluster.go | 2 +- .../services/kusto}/resource_arm_kusto_cluster_test.go | 2 +- .../services/kusto}/resource_arm_kusto_database.go | 2 +- .../services/kusto}/resource_arm_kusto_database_test.go | 2 +- .../kusto}/resource_arm_kusto_eventhub_data_connection.go | 2 +- .../kusto}/resource_arm_kusto_eventhub_data_connection_test.go | 2 +- azurerm/provider.go | 3 --- 7 files changed, 6 insertions(+), 9 deletions(-) rename azurerm/{ => internal/services/kusto}/resource_arm_kusto_cluster.go (99%) rename azurerm/{ => internal/services/kusto}/resource_arm_kusto_cluster_test.go (99%) rename azurerm/{ => internal/services/kusto}/resource_arm_kusto_database.go (99%) rename azurerm/{ => internal/services/kusto}/resource_arm_kusto_database_test.go (99%) rename azurerm/{ => internal/services/kusto}/resource_arm_kusto_eventhub_data_connection.go (99%) rename azurerm/{ => internal/services/kusto}/resource_arm_kusto_eventhub_data_connection_test.go (99%) diff --git a/azurerm/resource_arm_kusto_cluster.go b/azurerm/internal/services/kusto/resource_arm_kusto_cluster.go similarity index 99% rename from azurerm/resource_arm_kusto_cluster.go rename to azurerm/internal/services/kusto/resource_arm_kusto_cluster.go index ab76069ab498..9dd4c0e4589a 100644 --- a/azurerm/resource_arm_kusto_cluster.go +++ b/azurerm/internal/services/kusto/resource_arm_kusto_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package kusto import ( "fmt" diff --git a/azurerm/resource_arm_kusto_cluster_test.go b/azurerm/internal/services/kusto/resource_arm_kusto_cluster_test.go similarity index 99% rename from azurerm/resource_arm_kusto_cluster_test.go rename to azurerm/internal/services/kusto/resource_arm_kusto_cluster_test.go index b1d1f644582d..baf04dc18538 100644 --- a/azurerm/resource_arm_kusto_cluster_test.go +++ b/azurerm/internal/services/kusto/resource_arm_kusto_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package kusto import ( "fmt" diff --git a/azurerm/resource_arm_kusto_database.go b/azurerm/internal/services/kusto/resource_arm_kusto_database.go similarity index 99% rename from azurerm/resource_arm_kusto_database.go rename to azurerm/internal/services/kusto/resource_arm_kusto_database.go index c62636329aa5..c6b47aaf8cff 100644 --- a/azurerm/resource_arm_kusto_database.go +++ b/azurerm/internal/services/kusto/resource_arm_kusto_database.go @@ -1,4 +1,4 @@ -package azurerm +package kusto import ( "fmt" diff --git a/azurerm/resource_arm_kusto_database_test.go b/azurerm/internal/services/kusto/resource_arm_kusto_database_test.go similarity index 99% rename from azurerm/resource_arm_kusto_database_test.go rename to azurerm/internal/services/kusto/resource_arm_kusto_database_test.go index d39cdcf480b5..b37d5d608212 100644 --- a/azurerm/resource_arm_kusto_database_test.go +++ b/azurerm/internal/services/kusto/resource_arm_kusto_database_test.go @@ -1,4 +1,4 @@ -package azurerm +package kusto import ( "fmt" diff --git a/azurerm/resource_arm_kusto_eventhub_data_connection.go b/azurerm/internal/services/kusto/resource_arm_kusto_eventhub_data_connection.go similarity index 99% rename from azurerm/resource_arm_kusto_eventhub_data_connection.go rename to azurerm/internal/services/kusto/resource_arm_kusto_eventhub_data_connection.go index 8a0d1e394035..74d1b4f1fe54 100644 --- a/azurerm/resource_arm_kusto_eventhub_data_connection.go +++ b/azurerm/internal/services/kusto/resource_arm_kusto_eventhub_data_connection.go @@ -1,4 +1,4 @@ -package azurerm +package kusto import ( "fmt" diff --git a/azurerm/resource_arm_kusto_eventhub_data_connection_test.go b/azurerm/internal/services/kusto/resource_arm_kusto_eventhub_data_connection_test.go similarity index 99% rename from azurerm/resource_arm_kusto_eventhub_data_connection_test.go rename to azurerm/internal/services/kusto/resource_arm_kusto_eventhub_data_connection_test.go index 6b6cb5a3343f..ba0841e93f50 100644 --- a/azurerm/resource_arm_kusto_eventhub_data_connection_test.go +++ b/azurerm/internal/services/kusto/resource_arm_kusto_eventhub_data_connection_test.go @@ -1,4 +1,4 @@ -package azurerm +package kusto import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 69d2b3a31392..0d24efbc91d9 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -118,9 +118,6 @@ func Provider() terraform.ResourceProvider { "azurerm_key_vault_key": resourceArmKeyVaultKey(), "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), "azurerm_key_vault": resourceArmKeyVault(), - "azurerm_kusto_cluster": resourceArmKustoCluster(), - "azurerm_kusto_database": resourceArmKustoDatabase(), - "azurerm_kusto_eventhub_data_connection": resourceArmKustoEventHubDataConnection(), "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), From d374836fc0da07319d32ee765936875dae253763 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:33:23 -0800 Subject: [PATCH 032/203] loganalytics --- .../loganalytics}/data_source_log_analytics_workspace.go | 2 +- .../data_source_log_analytics_workspace_test.go | 4 ++-- azurerm/internal/services/loganalytics/registration.go | 9 +++++++-- .../resource_arm_log_analytics_linked_service.go | 2 +- .../resource_arm_log_analytics_linked_service_test.go | 2 +- .../loganalytics}/resource_arm_log_analytics_solution.go | 2 +- .../resource_arm_log_analytics_solution_test.go | 2 +- .../resource_arm_log_analytics_workspace.go | 2 +- ...esource_arm_log_analytics_workspace_linked_service.go | 2 +- ...ce_arm_log_analytics_workspace_linked_service_test.go | 2 +- .../resource_arm_log_analytics_workspace_test.go | 2 +- azurerm/provider.go | 5 ----- 12 files changed, 18 insertions(+), 18 deletions(-) rename azurerm/{ => internal/services/loganalytics}/data_source_log_analytics_workspace.go (99%) rename azurerm/{ => internal/services/loganalytics}/data_source_log_analytics_workspace_test.go (94%) rename azurerm/{ => internal/services/loganalytics}/resource_arm_log_analytics_linked_service.go (99%) rename azurerm/{ => internal/services/loganalytics}/resource_arm_log_analytics_linked_service_test.go (99%) rename azurerm/{ => internal/services/loganalytics}/resource_arm_log_analytics_solution.go (99%) rename azurerm/{ => internal/services/loganalytics}/resource_arm_log_analytics_solution_test.go (99%) rename azurerm/{ => internal/services/loganalytics}/resource_arm_log_analytics_workspace.go (99%) rename azurerm/{ => internal/services/loganalytics}/resource_arm_log_analytics_workspace_linked_service.go (99%) rename azurerm/{ => internal/services/loganalytics}/resource_arm_log_analytics_workspace_linked_service_test.go (99%) rename azurerm/{ => internal/services/loganalytics}/resource_arm_log_analytics_workspace_test.go (99%) diff --git a/azurerm/data_source_log_analytics_workspace.go b/azurerm/internal/services/loganalytics/data_source_log_analytics_workspace.go similarity index 99% rename from azurerm/data_source_log_analytics_workspace.go rename to azurerm/internal/services/loganalytics/data_source_log_analytics_workspace.go index 772554539299..346b6fa38818 100644 --- a/azurerm/data_source_log_analytics_workspace.go +++ b/azurerm/internal/services/loganalytics/data_source_log_analytics_workspace.go @@ -1,4 +1,4 @@ -package azurerm +package loganalytics import ( "fmt" diff --git a/azurerm/data_source_log_analytics_workspace_test.go b/azurerm/internal/services/loganalytics/data_source_log_analytics_workspace_test.go similarity index 94% rename from azurerm/data_source_log_analytics_workspace_test.go rename to azurerm/internal/services/loganalytics/data_source_log_analytics_workspace_test.go index 65eedf47eed0..9e777e753231 100644 --- a/azurerm/data_source_log_analytics_workspace_test.go +++ b/azurerm/internal/services/loganalytics/data_source_log_analytics_workspace_test.go @@ -1,4 +1,4 @@ -package azurerm +package loganalytics import ( "fmt" @@ -17,7 +17,7 @@ func TestAccDataSourceAzureRMLogAnalyticsWorkspace_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountDestroy, + CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy, Steps: []resource.TestStep{ { Config: config, diff --git a/azurerm/internal/services/loganalytics/registration.go b/azurerm/internal/services/loganalytics/registration.go index b0f1e684395a..b9f4a802cb32 100644 --- a/azurerm/internal/services/loganalytics/registration.go +++ b/azurerm/internal/services/loganalytics/registration.go @@ -13,10 +13,15 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_log_analytics_workspace": dataSourceLogAnalyticsWorkspace()} } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), + "azurerm_log_analytics_linked_service": resourceArmLogAnalyticsLinkedService(), + "azurerm_log_analytics_workspace_linked_service": resourceArmLogAnalyticsWorkspaceLinkedService(), + "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace()} } diff --git a/azurerm/resource_arm_log_analytics_linked_service.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go similarity index 99% rename from azurerm/resource_arm_log_analytics_linked_service.go rename to azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go index bb43298f3c69..5266d80dc57d 100644 --- a/azurerm/resource_arm_log_analytics_linked_service.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go @@ -1,4 +1,4 @@ -package azurerm +package loganalytics import ( "fmt" diff --git a/azurerm/resource_arm_log_analytics_linked_service_test.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service_test.go similarity index 99% rename from azurerm/resource_arm_log_analytics_linked_service_test.go rename to azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service_test.go index 87c723a57eee..7031dc832809 100644 --- a/azurerm/resource_arm_log_analytics_linked_service_test.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package loganalytics import ( "fmt" diff --git a/azurerm/resource_arm_log_analytics_solution.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution.go similarity index 99% rename from azurerm/resource_arm_log_analytics_solution.go rename to azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution.go index ab64a7748ab7..5fca6cdaa9ca 100644 --- a/azurerm/resource_arm_log_analytics_solution.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution.go @@ -1,4 +1,4 @@ -package azurerm +package loganalytics import ( "fmt" diff --git a/azurerm/resource_arm_log_analytics_solution_test.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution_test.go similarity index 99% rename from azurerm/resource_arm_log_analytics_solution_test.go rename to azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution_test.go index 5f7ec8903617..634450f04d22 100644 --- a/azurerm/resource_arm_log_analytics_solution_test.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution_test.go @@ -1,4 +1,4 @@ -package azurerm +package loganalytics import ( "fmt" diff --git a/azurerm/resource_arm_log_analytics_workspace.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace.go similarity index 99% rename from azurerm/resource_arm_log_analytics_workspace.go rename to azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace.go index e43a7fae0d35..a1021d78adb0 100644 --- a/azurerm/resource_arm_log_analytics_workspace.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace.go @@ -1,4 +1,4 @@ -package azurerm +package loganalytics import ( "fmt" diff --git a/azurerm/resource_arm_log_analytics_workspace_linked_service.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go similarity index 99% rename from azurerm/resource_arm_log_analytics_workspace_linked_service.go rename to azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go index 54d76a3b53dc..ee061834b634 100644 --- a/azurerm/resource_arm_log_analytics_workspace_linked_service.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go @@ -1,4 +1,4 @@ -package azurerm +package loganalytics import ( "fmt" diff --git a/azurerm/resource_arm_log_analytics_workspace_linked_service_test.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service_test.go similarity index 99% rename from azurerm/resource_arm_log_analytics_workspace_linked_service_test.go rename to azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service_test.go index 209b60f62b30..226b11261d51 100644 --- a/azurerm/resource_arm_log_analytics_workspace_linked_service_test.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package loganalytics import ( "fmt" diff --git a/azurerm/resource_arm_log_analytics_workspace_test.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_test.go similarity index 99% rename from azurerm/resource_arm_log_analytics_workspace_test.go rename to azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_test.go index a2b006f24c82..2e58a2408473 100644 --- a/azurerm/resource_arm_log_analytics_workspace_test.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_test.go @@ -1,4 +1,4 @@ -package azurerm +package loganalytics import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 0d24efbc91d9..dd820e902820 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -25,7 +25,6 @@ func Provider() terraform.ResourceProvider { "azurerm_key_vault": dataSourceArmKeyVault(), "azurerm_lb": dataSourceArmLoadBalancer(), "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), - "azurerm_log_analytics_workspace": dataSourceLogAnalyticsWorkspace(), "azurerm_logic_app_workflow": dataSourceArmLogicAppWorkflow(), "azurerm_management_group": dataSourceArmManagementGroup(), "azurerm_monitor_action_group": dataSourceArmMonitorActionGroup(), @@ -126,10 +125,6 @@ func Provider() terraform.ResourceProvider { "azurerm_lb_rule": resourceArmLoadBalancerRule(), "azurerm_lb": resourceArmLoadBalancer(), "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), - "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), - "azurerm_log_analytics_linked_service": resourceArmLogAnalyticsLinkedService(), - "azurerm_log_analytics_workspace_linked_service": resourceArmLogAnalyticsWorkspaceLinkedService(), - "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace(), "azurerm_logic_app_action_custom": resourceArmLogicAppActionCustom(), "azurerm_logic_app_action_http": resourceArmLogicAppActionHTTP(), "azurerm_logic_app_trigger_custom": resourceArmLogicAppTriggerCustom(), From 166b05cafc9ff7516b701f2cb9b716ee0034b79d Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:37:50 -0800 Subject: [PATCH 033/203] logic --- .../logic}/data_source_logic_app_workflow.go | 2 +- .../logic}/data_source_logic_app_workflow_test.go | 2 +- azurerm/{ => internal/services/logic}/logic_apps.go | 2 +- .../{ => internal/services/logic}/logic_apps_test.go | 2 +- azurerm/internal/services/logic/registration.go | 12 ++++++++++-- .../logic}/resource_arm_logic_app_action_custom.go | 2 +- .../resource_arm_logic_app_action_custom_test.go | 2 +- .../logic}/resource_arm_logic_app_action_http.go | 2 +- .../resource_arm_logic_app_action_http_test.go | 2 +- .../logic}/resource_arm_logic_app_trigger_custom.go | 2 +- .../resource_arm_logic_app_trigger_custom_test.go | 2 +- .../resource_arm_logic_app_trigger_http_request.go | 2 +- ...source_arm_logic_app_trigger_http_request_test.go | 2 +- .../resource_arm_logic_app_trigger_recurrence.go | 2 +- ...resource_arm_logic_app_trigger_recurrence_test.go | 2 +- .../logic}/resource_arm_logic_app_workflow.go | 2 +- .../logic}/resource_arm_logic_app_workflow_test.go | 2 +- azurerm/provider.go | 7 ------- 18 files changed, 26 insertions(+), 25 deletions(-) rename azurerm/{ => internal/services/logic}/data_source_logic_app_workflow.go (99%) rename azurerm/{ => internal/services/logic}/data_source_logic_app_workflow_test.go (99%) rename azurerm/{ => internal/services/logic}/logic_apps.go (99%) rename azurerm/{ => internal/services/logic}/logic_apps_test.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_action_custom.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_action_custom_test.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_action_http.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_action_http_test.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_trigger_custom.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_trigger_custom_test.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_trigger_http_request.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_trigger_http_request_test.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_trigger_recurrence.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_trigger_recurrence_test.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_workflow.go (99%) rename azurerm/{ => internal/services/logic}/resource_arm_logic_app_workflow_test.go (99%) diff --git a/azurerm/data_source_logic_app_workflow.go b/azurerm/internal/services/logic/data_source_logic_app_workflow.go similarity index 99% rename from azurerm/data_source_logic_app_workflow.go rename to azurerm/internal/services/logic/data_source_logic_app_workflow.go index 4fb0c7ab75da..31670d25b6e7 100644 --- a/azurerm/data_source_logic_app_workflow.go +++ b/azurerm/internal/services/logic/data_source_logic_app_workflow.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/data_source_logic_app_workflow_test.go b/azurerm/internal/services/logic/data_source_logic_app_workflow_test.go similarity index 99% rename from azurerm/data_source_logic_app_workflow_test.go rename to azurerm/internal/services/logic/data_source_logic_app_workflow_test.go index 48de331c6bdb..c44e7552eeb3 100644 --- a/azurerm/data_source_logic_app_workflow_test.go +++ b/azurerm/internal/services/logic/data_source_logic_app_workflow_test.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/logic_apps.go b/azurerm/internal/services/logic/logic_apps.go similarity index 99% rename from azurerm/logic_apps.go rename to azurerm/internal/services/logic/logic_apps.go index 54176adca70e..419d93a917ec 100644 --- a/azurerm/logic_apps.go +++ b/azurerm/internal/services/logic/logic_apps.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/logic_apps_test.go b/azurerm/internal/services/logic/logic_apps_test.go similarity index 99% rename from azurerm/logic_apps_test.go rename to azurerm/internal/services/logic/logic_apps_test.go index 386109adf3e7..c44ff757ee5b 100644 --- a/azurerm/logic_apps_test.go +++ b/azurerm/internal/services/logic/logic_apps_test.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/internal/services/logic/registration.go b/azurerm/internal/services/logic/registration.go index 35231ab62520..87508d474c8a 100644 --- a/azurerm/internal/services/logic/registration.go +++ b/azurerm/internal/services/logic/registration.go @@ -13,10 +13,18 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_logic_app_workflow": dataSourceArmLogicAppWorkflow(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_logic_app_action_custom": resourceArmLogicAppActionCustom(), + "azurerm_logic_app_action_http": resourceArmLogicAppActionHTTP(), + "azurerm_logic_app_trigger_custom": resourceArmLogicAppTriggerCustom(), + "azurerm_logic_app_trigger_http_request": resourceArmLogicAppTriggerHttpRequest(), + "azurerm_logic_app_trigger_recurrence": resourceArmLogicAppTriggerRecurrence(), + "azurerm_logic_app_workflow": resourceArmLogicAppWorkflow()} } diff --git a/azurerm/resource_arm_logic_app_action_custom.go b/azurerm/internal/services/logic/resource_arm_logic_app_action_custom.go similarity index 99% rename from azurerm/resource_arm_logic_app_action_custom.go rename to azurerm/internal/services/logic/resource_arm_logic_app_action_custom.go index 071e77b8ba6e..b28223f83724 100644 --- a/azurerm/resource_arm_logic_app_action_custom.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_action_custom.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "encoding/json" diff --git a/azurerm/resource_arm_logic_app_action_custom_test.go b/azurerm/internal/services/logic/resource_arm_logic_app_action_custom_test.go similarity index 99% rename from azurerm/resource_arm_logic_app_action_custom_test.go rename to azurerm/internal/services/logic/resource_arm_logic_app_action_custom_test.go index 15a4a360332b..26a3c68edd39 100644 --- a/azurerm/resource_arm_logic_app_action_custom_test.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_action_custom_test.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/resource_arm_logic_app_action_http.go b/azurerm/internal/services/logic/resource_arm_logic_app_action_http.go similarity index 99% rename from azurerm/resource_arm_logic_app_action_http.go rename to azurerm/internal/services/logic/resource_arm_logic_app_action_http.go index b37faacd4412..ff6b2263d8da 100644 --- a/azurerm/resource_arm_logic_app_action_http.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_action_http.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/resource_arm_logic_app_action_http_test.go b/azurerm/internal/services/logic/resource_arm_logic_app_action_http_test.go similarity index 99% rename from azurerm/resource_arm_logic_app_action_http_test.go rename to azurerm/internal/services/logic/resource_arm_logic_app_action_http_test.go index a920fc16f414..628afe4628b1 100644 --- a/azurerm/resource_arm_logic_app_action_http_test.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_action_http_test.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/resource_arm_logic_app_trigger_custom.go b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_custom.go similarity index 99% rename from azurerm/resource_arm_logic_app_trigger_custom.go rename to azurerm/internal/services/logic/resource_arm_logic_app_trigger_custom.go index c87c26a4cfe9..3a6a8048495e 100644 --- a/azurerm/resource_arm_logic_app_trigger_custom.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_custom.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "encoding/json" diff --git a/azurerm/resource_arm_logic_app_trigger_custom_test.go b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_custom_test.go similarity index 99% rename from azurerm/resource_arm_logic_app_trigger_custom_test.go rename to azurerm/internal/services/logic/resource_arm_logic_app_trigger_custom_test.go index 81397f9a779c..a72e85e472c2 100644 --- a/azurerm/resource_arm_logic_app_trigger_custom_test.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_custom_test.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/resource_arm_logic_app_trigger_http_request.go b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_http_request.go similarity index 99% rename from azurerm/resource_arm_logic_app_trigger_http_request.go rename to azurerm/internal/services/logic/resource_arm_logic_app_trigger_http_request.go index ace8dcf63b67..52b4bf3ae5e4 100644 --- a/azurerm/resource_arm_logic_app_trigger_http_request.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_http_request.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "encoding/json" diff --git a/azurerm/resource_arm_logic_app_trigger_http_request_test.go b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_http_request_test.go similarity index 99% rename from azurerm/resource_arm_logic_app_trigger_http_request_test.go rename to azurerm/internal/services/logic/resource_arm_logic_app_trigger_http_request_test.go index 3d4435976f77..a805119dfbfc 100644 --- a/azurerm/resource_arm_logic_app_trigger_http_request_test.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_http_request_test.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/resource_arm_logic_app_trigger_recurrence.go b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go similarity index 99% rename from azurerm/resource_arm_logic_app_trigger_recurrence.go rename to azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go index 5decafb37e96..673852349632 100644 --- a/azurerm/resource_arm_logic_app_trigger_recurrence.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/resource_arm_logic_app_trigger_recurrence_test.go b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence_test.go similarity index 99% rename from azurerm/resource_arm_logic_app_trigger_recurrence_test.go rename to azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence_test.go index 20228f84fe04..dcd908dfa151 100644 --- a/azurerm/resource_arm_logic_app_trigger_recurrence_test.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence_test.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/resource_arm_logic_app_workflow.go b/azurerm/internal/services/logic/resource_arm_logic_app_workflow.go similarity index 99% rename from azurerm/resource_arm_logic_app_workflow.go rename to azurerm/internal/services/logic/resource_arm_logic_app_workflow.go index 7463e4b2c6d0..4cb9f25a8f09 100644 --- a/azurerm/resource_arm_logic_app_workflow.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_workflow.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/resource_arm_logic_app_workflow_test.go b/azurerm/internal/services/logic/resource_arm_logic_app_workflow_test.go similarity index 99% rename from azurerm/resource_arm_logic_app_workflow_test.go rename to azurerm/internal/services/logic/resource_arm_logic_app_workflow_test.go index 6e01626058f1..0efce3d4385d 100644 --- a/azurerm/resource_arm_logic_app_workflow_test.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_workflow_test.go @@ -1,4 +1,4 @@ -package azurerm +package logic import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index dd820e902820..3d82385f205b 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -25,7 +25,6 @@ func Provider() terraform.ResourceProvider { "azurerm_key_vault": dataSourceArmKeyVault(), "azurerm_lb": dataSourceArmLoadBalancer(), "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), - "azurerm_logic_app_workflow": dataSourceArmLogicAppWorkflow(), "azurerm_management_group": dataSourceArmManagementGroup(), "azurerm_monitor_action_group": dataSourceArmMonitorActionGroup(), "azurerm_monitor_diagnostic_categories": dataSourceArmMonitorDiagnosticCategories(), @@ -125,12 +124,6 @@ func Provider() terraform.ResourceProvider { "azurerm_lb_rule": resourceArmLoadBalancerRule(), "azurerm_lb": resourceArmLoadBalancer(), "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), - "azurerm_logic_app_action_custom": resourceArmLogicAppActionCustom(), - "azurerm_logic_app_action_http": resourceArmLogicAppActionHTTP(), - "azurerm_logic_app_trigger_custom": resourceArmLogicAppTriggerCustom(), - "azurerm_logic_app_trigger_http_request": resourceArmLogicAppTriggerHttpRequest(), - "azurerm_logic_app_trigger_recurrence": resourceArmLogicAppTriggerRecurrence(), - "azurerm_logic_app_workflow": resourceArmLogicAppWorkflow(), "azurerm_management_group": resourceArmManagementGroup(), "azurerm_management_lock": resourceArmManagementLock(), "azurerm_maps_account": resourceArmMapsAccount(), From 7b125a65159d1b6a3e0ecfe49da526d72773069b Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:40:36 -0800 Subject: [PATCH 034/203] managementgroup --- .../managementgroup}/data_source_management_group.go | 2 +- .../managementgroup}/data_source_management_group_test.go | 2 +- azurerm/internal/services/managementgroup/registration.go | 8 ++++++-- .../managementgroup}/resource_arm_management_group.go | 2 +- .../resource_arm_management_group_test.go | 2 +- azurerm/provider.go | 2 -- 6 files changed, 10 insertions(+), 8 deletions(-) rename azurerm/{ => internal/services/managementgroup}/data_source_management_group.go (99%) rename azurerm/{ => internal/services/managementgroup}/data_source_management_group_test.go (97%) rename azurerm/{ => internal/services/managementgroup}/resource_arm_management_group.go (99%) rename azurerm/{ => internal/services/managementgroup}/resource_arm_management_group_test.go (99%) diff --git a/azurerm/data_source_management_group.go b/azurerm/internal/services/managementgroup/data_source_management_group.go similarity index 99% rename from azurerm/data_source_management_group.go rename to azurerm/internal/services/managementgroup/data_source_management_group.go index 15aaaf71f1fb..3858a965fccc 100644 --- a/azurerm/data_source_management_group.go +++ b/azurerm/internal/services/managementgroup/data_source_management_group.go @@ -1,4 +1,4 @@ -package azurerm +package managementgroup import ( "fmt" diff --git a/azurerm/data_source_management_group_test.go b/azurerm/internal/services/managementgroup/data_source_management_group_test.go similarity index 97% rename from azurerm/data_source_management_group_test.go rename to azurerm/internal/services/managementgroup/data_source_management_group_test.go index 88b09dc82933..a74af54b7e00 100644 --- a/azurerm/data_source_management_group_test.go +++ b/azurerm/internal/services/managementgroup/data_source_management_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package managementgroup import ( "fmt" diff --git a/azurerm/internal/services/managementgroup/registration.go b/azurerm/internal/services/managementgroup/registration.go index c98d22874819..5c8b5f8b62bb 100644 --- a/azurerm/internal/services/managementgroup/registration.go +++ b/azurerm/internal/services/managementgroup/registration.go @@ -13,10 +13,14 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_management_group": dataSourceArmManagementGroup(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_management_group": resourceArmManagementGroup(), + } } diff --git a/azurerm/resource_arm_management_group.go b/azurerm/internal/services/managementgroup/resource_arm_management_group.go similarity index 99% rename from azurerm/resource_arm_management_group.go rename to azurerm/internal/services/managementgroup/resource_arm_management_group.go index eebd2ad1710b..18ed1c728f2c 100644 --- a/azurerm/resource_arm_management_group.go +++ b/azurerm/internal/services/managementgroup/resource_arm_management_group.go @@ -1,4 +1,4 @@ -package azurerm +package managementgroup import ( "fmt" diff --git a/azurerm/resource_arm_management_group_test.go b/azurerm/internal/services/managementgroup/resource_arm_management_group_test.go similarity index 99% rename from azurerm/resource_arm_management_group_test.go rename to azurerm/internal/services/managementgroup/resource_arm_management_group_test.go index a7f809da48fe..bb285e6103f5 100644 --- a/azurerm/resource_arm_management_group_test.go +++ b/azurerm/internal/services/managementgroup/resource_arm_management_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package managementgroup import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 3d82385f205b..f9d100ad99e1 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -25,7 +25,6 @@ func Provider() terraform.ResourceProvider { "azurerm_key_vault": dataSourceArmKeyVault(), "azurerm_lb": dataSourceArmLoadBalancer(), "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), - "azurerm_management_group": dataSourceArmManagementGroup(), "azurerm_monitor_action_group": dataSourceArmMonitorActionGroup(), "azurerm_monitor_diagnostic_categories": dataSourceArmMonitorDiagnosticCategories(), "azurerm_monitor_log_profile": dataSourceArmMonitorLogProfile(), @@ -124,7 +123,6 @@ func Provider() terraform.ResourceProvider { "azurerm_lb_rule": resourceArmLoadBalancerRule(), "azurerm_lb": resourceArmLoadBalancer(), "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), - "azurerm_management_group": resourceArmManagementGroup(), "azurerm_management_lock": resourceArmManagementLock(), "azurerm_maps_account": resourceArmMapsAccount(), "azurerm_mariadb_configuration": resourceArmMariaDbConfiguration(), From c7d45822ce121edbbfa3c2c86d65289e07798c52 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:43:05 -0800 Subject: [PATCH 035/203] maps --- .../services/maps}/data_source_maps_account.go | 5 ++--- .../services/maps}/data_source_maps_account_test.go | 2 +- azurerm/internal/services/maps/registration.go | 8 ++++++-- .../services/maps}/resource_arm_maps_account.go | 5 ++--- .../services/maps}/resource_arm_maps_account_test.go | 2 +- azurerm/provider.go | 2 -- 6 files changed, 12 insertions(+), 12 deletions(-) rename azurerm/{ => internal/services/maps}/data_source_maps_account.go (94%) rename azurerm/{ => internal/services/maps}/data_source_maps_account_test.go (99%) rename azurerm/{ => internal/services/maps}/resource_arm_maps_account.go (97%) rename azurerm/{ => internal/services/maps}/resource_arm_maps_account_test.go (99%) diff --git a/azurerm/data_source_maps_account.go b/azurerm/internal/services/maps/data_source_maps_account.go similarity index 94% rename from azurerm/data_source_maps_account.go rename to azurerm/internal/services/maps/data_source_maps_account.go index adacbc568882..507a8edc6136 100644 --- a/azurerm/data_source_maps_account.go +++ b/azurerm/internal/services/maps/data_source_maps_account.go @@ -1,4 +1,4 @@ -package azurerm +package maps import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/maps" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -25,7 +24,7 @@ func dataSourceArmMapsAccount() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: maps.ValidateName(), + ValidateFunc: ValidateName(), }, "resource_group_name": azure.SchemaResourceGroupName(), diff --git a/azurerm/data_source_maps_account_test.go b/azurerm/internal/services/maps/data_source_maps_account_test.go similarity index 99% rename from azurerm/data_source_maps_account_test.go rename to azurerm/internal/services/maps/data_source_maps_account_test.go index 87577a3bbdc5..1c54695188c6 100644 --- a/azurerm/data_source_maps_account_test.go +++ b/azurerm/internal/services/maps/data_source_maps_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package maps import ( "fmt" diff --git a/azurerm/internal/services/maps/registration.go b/azurerm/internal/services/maps/registration.go index 014db7484554..fa18db129f2c 100644 --- a/azurerm/internal/services/maps/registration.go +++ b/azurerm/internal/services/maps/registration.go @@ -13,10 +13,14 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_maps_account": dataSourceArmMapsAccount(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_maps_account": resourceArmMapsAccount(), + } } diff --git a/azurerm/resource_arm_maps_account.go b/azurerm/internal/services/maps/resource_arm_maps_account.go similarity index 97% rename from azurerm/resource_arm_maps_account.go rename to azurerm/internal/services/maps/resource_arm_maps_account.go index 42e7ba323587..7dd463362963 100644 --- a/azurerm/resource_arm_maps_account.go +++ b/azurerm/internal/services/maps/resource_arm_maps_account.go @@ -1,4 +1,4 @@ -package azurerm +package maps import ( "fmt" @@ -12,7 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - mapsint "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/maps" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -40,7 +39,7 @@ func resourceArmMapsAccount() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: mapsint.ValidateName(), + ValidateFunc: ValidateName(), }, "resource_group_name": azure.SchemaResourceGroupName(), diff --git a/azurerm/resource_arm_maps_account_test.go b/azurerm/internal/services/maps/resource_arm_maps_account_test.go similarity index 99% rename from azurerm/resource_arm_maps_account_test.go rename to azurerm/internal/services/maps/resource_arm_maps_account_test.go index 958c6cf67539..77b7559a3a46 100644 --- a/azurerm/resource_arm_maps_account_test.go +++ b/azurerm/internal/services/maps/resource_arm_maps_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package maps import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index f9d100ad99e1..e1a321ef24a2 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -18,7 +18,6 @@ func Provider() terraform.ResourceProvider { "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), "azurerm_firewall": dataSourceArmFirewall(), "azurerm_image": dataSourceArmImage(), - "azurerm_maps_account": dataSourceArmMapsAccount(), "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), @@ -124,7 +123,6 @@ func Provider() terraform.ResourceProvider { "azurerm_lb": resourceArmLoadBalancer(), "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_maps_account": resourceArmMapsAccount(), "azurerm_mariadb_configuration": resourceArmMariaDbConfiguration(), "azurerm_mariadb_database": resourceArmMariaDbDatabase(), "azurerm_mariadb_firewall_rule": resourceArmMariaDBFirewallRule(), From 6f119890a9c9e18a16d7a55f739bafa90b6bc620 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:44:46 -0800 Subject: [PATCH 036/203] mariadb --- azurerm/internal/services/mariadb/registration.go | 7 ++++++- .../mariadb}/resource_arm_mariadb_configuration.go | 2 +- .../mariadb}/resource_arm_mariadb_configuration_test.go | 2 +- .../services/mariadb}/resource_arm_mariadb_database.go | 2 +- .../mariadb}/resource_arm_mariadb_database_test.go | 2 +- .../mariadb}/resource_arm_mariadb_firewall_rule.go | 2 +- .../mariadb}/resource_arm_mariadb_firewall_rule_test.go | 2 +- .../services/mariadb}/resource_arm_mariadb_server.go | 2 +- .../services/mariadb}/resource_arm_mariadb_server_test.go | 2 +- .../mariadb}/resource_arm_mariadb_virtual_network_rule.go | 2 +- .../resource_arm_mariadb_virtual_network_rule_test.go | 2 +- azurerm/provider.go | 5 ----- 12 files changed, 16 insertions(+), 16 deletions(-) rename azurerm/{ => internal/services/mariadb}/resource_arm_mariadb_configuration.go (99%) rename azurerm/{ => internal/services/mariadb}/resource_arm_mariadb_configuration_test.go (99%) rename azurerm/{ => internal/services/mariadb}/resource_arm_mariadb_database.go (99%) rename azurerm/{ => internal/services/mariadb}/resource_arm_mariadb_database_test.go (99%) rename azurerm/{ => internal/services/mariadb}/resource_arm_mariadb_firewall_rule.go (99%) rename azurerm/{ => internal/services/mariadb}/resource_arm_mariadb_firewall_rule_test.go (99%) rename azurerm/{ => internal/services/mariadb}/resource_arm_mariadb_server.go (99%) rename azurerm/{ => internal/services/mariadb}/resource_arm_mariadb_server_test.go (99%) rename azurerm/{ => internal/services/mariadb}/resource_arm_mariadb_virtual_network_rule.go (99%) rename azurerm/{ => internal/services/mariadb}/resource_arm_mariadb_virtual_network_rule_test.go (99%) diff --git a/azurerm/internal/services/mariadb/registration.go b/azurerm/internal/services/mariadb/registration.go index b924ecc1c7bf..56fcaf38d2fc 100644 --- a/azurerm/internal/services/mariadb/registration.go +++ b/azurerm/internal/services/mariadb/registration.go @@ -18,5 +18,10 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_mariadb_configuration": resourceArmMariaDbConfiguration(), + "azurerm_mariadb_database": resourceArmMariaDbDatabase(), + "azurerm_mariadb_firewall_rule": resourceArmMariaDBFirewallRule(), + "azurerm_mariadb_server": resourceArmMariaDbServer(), + "azurerm_mariadb_virtual_network_rule": resourceArmMariaDbVirtualNetworkRule()} } diff --git a/azurerm/resource_arm_mariadb_configuration.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_configuration.go similarity index 99% rename from azurerm/resource_arm_mariadb_configuration.go rename to azurerm/internal/services/mariadb/resource_arm_mariadb_configuration.go index d742d04ce0fa..c109c0896f65 100644 --- a/azurerm/resource_arm_mariadb_configuration.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_configuration.go @@ -1,4 +1,4 @@ -package azurerm +package mariadb import ( "fmt" diff --git a/azurerm/resource_arm_mariadb_configuration_test.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_configuration_test.go similarity index 99% rename from azurerm/resource_arm_mariadb_configuration_test.go rename to azurerm/internal/services/mariadb/resource_arm_mariadb_configuration_test.go index 5e34aae03dcd..f53d54cfe515 100644 --- a/azurerm/resource_arm_mariadb_configuration_test.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_configuration_test.go @@ -1,4 +1,4 @@ -package azurerm +package mariadb import ( "fmt" diff --git a/azurerm/resource_arm_mariadb_database.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_database.go similarity index 99% rename from azurerm/resource_arm_mariadb_database.go rename to azurerm/internal/services/mariadb/resource_arm_mariadb_database.go index 54274cfc2e06..21c5ee6e2ff4 100644 --- a/azurerm/resource_arm_mariadb_database.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_database.go @@ -1,4 +1,4 @@ -package azurerm +package mariadb import ( "fmt" diff --git a/azurerm/resource_arm_mariadb_database_test.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_database_test.go similarity index 99% rename from azurerm/resource_arm_mariadb_database_test.go rename to azurerm/internal/services/mariadb/resource_arm_mariadb_database_test.go index 828c3095e094..291590af7605 100644 --- a/azurerm/resource_arm_mariadb_database_test.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_database_test.go @@ -1,4 +1,4 @@ -package azurerm +package mariadb import ( "fmt" diff --git a/azurerm/resource_arm_mariadb_firewall_rule.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_firewall_rule.go similarity index 99% rename from azurerm/resource_arm_mariadb_firewall_rule.go rename to azurerm/internal/services/mariadb/resource_arm_mariadb_firewall_rule.go index f86023107cea..60c2217c04ff 100644 --- a/azurerm/resource_arm_mariadb_firewall_rule.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_firewall_rule.go @@ -1,4 +1,4 @@ -package azurerm +package mariadb import ( "fmt" diff --git a/azurerm/resource_arm_mariadb_firewall_rule_test.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_firewall_rule_test.go similarity index 99% rename from azurerm/resource_arm_mariadb_firewall_rule_test.go rename to azurerm/internal/services/mariadb/resource_arm_mariadb_firewall_rule_test.go index add408ac01f1..8cc4d57cf13a 100644 --- a/azurerm/resource_arm_mariadb_firewall_rule_test.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_firewall_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package mariadb import ( "fmt" diff --git a/azurerm/resource_arm_mariadb_server.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_server.go similarity index 99% rename from azurerm/resource_arm_mariadb_server.go rename to azurerm/internal/services/mariadb/resource_arm_mariadb_server.go index 936c284e5876..684c43f8818b 100644 --- a/azurerm/resource_arm_mariadb_server.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_server.go @@ -1,4 +1,4 @@ -package azurerm +package mariadb import ( "fmt" diff --git a/azurerm/resource_arm_mariadb_server_test.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_server_test.go similarity index 99% rename from azurerm/resource_arm_mariadb_server_test.go rename to azurerm/internal/services/mariadb/resource_arm_mariadb_server_test.go index 7ff54ee7df81..d0430170d3ec 100644 --- a/azurerm/resource_arm_mariadb_server_test.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_server_test.go @@ -1,4 +1,4 @@ -package azurerm +package mariadb import ( "fmt" diff --git a/azurerm/resource_arm_mariadb_virtual_network_rule.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_virtual_network_rule.go similarity index 99% rename from azurerm/resource_arm_mariadb_virtual_network_rule.go rename to azurerm/internal/services/mariadb/resource_arm_mariadb_virtual_network_rule.go index a6c52ce7b28d..5bdef59510b0 100644 --- a/azurerm/resource_arm_mariadb_virtual_network_rule.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_virtual_network_rule.go @@ -1,4 +1,4 @@ -package azurerm +package mariadb import ( "context" diff --git a/azurerm/resource_arm_mariadb_virtual_network_rule_test.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_virtual_network_rule_test.go similarity index 99% rename from azurerm/resource_arm_mariadb_virtual_network_rule_test.go rename to azurerm/internal/services/mariadb/resource_arm_mariadb_virtual_network_rule_test.go index 57edee191929..e1465cdbb6a2 100644 --- a/azurerm/resource_arm_mariadb_virtual_network_rule_test.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_virtual_network_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package mariadb import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index e1a321ef24a2..974e029779bc 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -123,11 +123,6 @@ func Provider() terraform.ResourceProvider { "azurerm_lb": resourceArmLoadBalancer(), "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_mariadb_configuration": resourceArmMariaDbConfiguration(), - "azurerm_mariadb_database": resourceArmMariaDbDatabase(), - "azurerm_mariadb_firewall_rule": resourceArmMariaDBFirewallRule(), - "azurerm_mariadb_server": resourceArmMariaDbServer(), - "azurerm_mariadb_virtual_network_rule": resourceArmMariaDbVirtualNetworkRule(), "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), "azurerm_media_services_account": resourceArmMediaServicesAccount(), "azurerm_metric_alertrule": resourceArmMetricAlertRule(), From e63eb77a1102b25e49df40bab7899b3825b1d642 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:46:25 -0800 Subject: [PATCH 037/203] media --- azurerm/internal/services/media/registration.go | 4 +++- .../services/media}/resource_arm_media_services_account.go | 2 +- .../media}/resource_arm_media_services_account_test.go | 2 +- azurerm/provider.go | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) rename azurerm/{ => internal/services/media}/resource_arm_media_services_account.go (99%) rename azurerm/{ => internal/services/media}/resource_arm_media_services_account_test.go (99%) diff --git a/azurerm/internal/services/media/registration.go b/azurerm/internal/services/media/registration.go index 84446154de0b..fb3b61f54ba9 100644 --- a/azurerm/internal/services/media/registration.go +++ b/azurerm/internal/services/media/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_media_services_account": resourceArmMediaServicesAccount(), + } } diff --git a/azurerm/resource_arm_media_services_account.go b/azurerm/internal/services/media/resource_arm_media_services_account.go similarity index 99% rename from azurerm/resource_arm_media_services_account.go rename to azurerm/internal/services/media/resource_arm_media_services_account.go index a6d03915a062..0840d9e20661 100644 --- a/azurerm/resource_arm_media_services_account.go +++ b/azurerm/internal/services/media/resource_arm_media_services_account.go @@ -1,4 +1,4 @@ -package azurerm +package media import ( "fmt" diff --git a/azurerm/resource_arm_media_services_account_test.go b/azurerm/internal/services/media/resource_arm_media_services_account_test.go similarity index 99% rename from azurerm/resource_arm_media_services_account_test.go rename to azurerm/internal/services/media/resource_arm_media_services_account_test.go index 8372e134aa83..3cc9c052ad3e 100644 --- a/azurerm/resource_arm_media_services_account_test.go +++ b/azurerm/internal/services/media/resource_arm_media_services_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package media import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 974e029779bc..b2a19e1f0b28 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -124,7 +124,6 @@ func Provider() terraform.ResourceProvider { "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), "azurerm_management_lock": resourceArmManagementLock(), "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), - "azurerm_media_services_account": resourceArmMediaServicesAccount(), "azurerm_metric_alertrule": resourceArmMetricAlertRule(), "azurerm_monitor_autoscale_setting": resourceArmMonitorAutoScaleSetting(), "azurerm_monitor_action_group": resourceArmMonitorActionGroup(), From f2877f67cad58c1720488f1f321874fecd2d0488 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:50:56 -0800 Subject: [PATCH 038/203] monitor --- .../monitor}/data_source_monitor_action_group.go | 2 +- .../data_source_monitor_action_group_test.go | 2 +- .../data_source_monitor_diagnostic_categories.go | 2 +- ...a_source_monitor_diagnostic_categories_test.go | 2 +- .../monitor}/data_source_monitor_log_profile.go | 2 +- .../data_source_monitor_log_profile_test.go | 2 +- azurerm/internal/services/monitor/registration.go | 15 +++++++++++++-- .../monitor}/resource_arm_metric_alertrule.go | 2 +- .../resource_arm_metric_alertrule_test.go | 5 +++-- .../monitor}/resource_arm_monitor_action_group.go | 2 +- .../resource_arm_monitor_action_group_test.go | 2 +- .../resource_arm_monitor_activity_log_alert.go | 2 +- ...esource_arm_monitor_activity_log_alert_test.go | 2 +- .../resource_arm_monitor_autoscale_setting.go | 2 +- ...resource_arm_monitor_autoscale_setting_test.go | 2 +- .../resource_arm_monitor_diagnostic_setting.go | 2 +- ...esource_arm_monitor_diagnostic_setting_test.go | 2 +- .../monitor}/resource_arm_monitor_log_profile.go | 2 +- .../resource_arm_monitor_log_profile_test.go | 2 +- .../monitor}/resource_arm_monitor_metric_alert.go | 2 +- .../resource_arm_monitor_metric_alert_test.go | 2 +- .../resource_arm_monitor_metric_alertrule.go | 2 +- .../resource_arm_monitor_metric_alertrule_test.go | 4 ++-- azurerm/provider.go | 11 ----------- azurerm/resource_arm_signalr_service_test.go | 7 ++++--- 25 files changed, 42 insertions(+), 40 deletions(-) rename azurerm/{ => internal/services/monitor}/data_source_monitor_action_group.go (99%) rename azurerm/{ => internal/services/monitor}/data_source_monitor_action_group_test.go (99%) rename azurerm/{ => internal/services/monitor}/data_source_monitor_diagnostic_categories.go (99%) rename azurerm/{ => internal/services/monitor}/data_source_monitor_diagnostic_categories_test.go (99%) rename azurerm/{ => internal/services/monitor}/data_source_monitor_log_profile.go (99%) rename azurerm/{ => internal/services/monitor}/data_source_monitor_log_profile_test.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_metric_alertrule.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_metric_alertrule_test.go (98%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_action_group.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_action_group_test.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_activity_log_alert.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_activity_log_alert_test.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_autoscale_setting.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_autoscale_setting_test.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_diagnostic_setting.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_diagnostic_setting_test.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_log_profile.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_log_profile_test.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_metric_alert.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_metric_alert_test.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_metric_alertrule.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_monitor_metric_alertrule_test.go (99%) diff --git a/azurerm/data_source_monitor_action_group.go b/azurerm/internal/services/monitor/data_source_monitor_action_group.go similarity index 99% rename from azurerm/data_source_monitor_action_group.go rename to azurerm/internal/services/monitor/data_source_monitor_action_group.go index 7de421fdd4a4..d2e94af3bb82 100644 --- a/azurerm/data_source_monitor_action_group.go +++ b/azurerm/internal/services/monitor/data_source_monitor_action_group.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/data_source_monitor_action_group_test.go b/azurerm/internal/services/monitor/data_source_monitor_action_group_test.go similarity index 99% rename from azurerm/data_source_monitor_action_group_test.go rename to azurerm/internal/services/monitor/data_source_monitor_action_group_test.go index 3816cb1b8d2d..28cf1bb8cfbf 100644 --- a/azurerm/data_source_monitor_action_group_test.go +++ b/azurerm/internal/services/monitor/data_source_monitor_action_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/data_source_monitor_diagnostic_categories.go b/azurerm/internal/services/monitor/data_source_monitor_diagnostic_categories.go similarity index 99% rename from azurerm/data_source_monitor_diagnostic_categories.go rename to azurerm/internal/services/monitor/data_source_monitor_diagnostic_categories.go index 72e3c6d111d1..bbb2df4aff87 100644 --- a/azurerm/data_source_monitor_diagnostic_categories.go +++ b/azurerm/internal/services/monitor/data_source_monitor_diagnostic_categories.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/data_source_monitor_diagnostic_categories_test.go b/azurerm/internal/services/monitor/data_source_monitor_diagnostic_categories_test.go similarity index 99% rename from azurerm/data_source_monitor_diagnostic_categories_test.go rename to azurerm/internal/services/monitor/data_source_monitor_diagnostic_categories_test.go index 03f2b4bfde1c..6db8a54e630b 100644 --- a/azurerm/data_source_monitor_diagnostic_categories_test.go +++ b/azurerm/internal/services/monitor/data_source_monitor_diagnostic_categories_test.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/data_source_monitor_log_profile.go b/azurerm/internal/services/monitor/data_source_monitor_log_profile.go similarity index 99% rename from azurerm/data_source_monitor_log_profile.go rename to azurerm/internal/services/monitor/data_source_monitor_log_profile.go index e22196c9c15d..4ae2b2a40dbc 100644 --- a/azurerm/data_source_monitor_log_profile.go +++ b/azurerm/internal/services/monitor/data_source_monitor_log_profile.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/data_source_monitor_log_profile_test.go b/azurerm/internal/services/monitor/data_source_monitor_log_profile_test.go similarity index 99% rename from azurerm/data_source_monitor_log_profile_test.go rename to azurerm/internal/services/monitor/data_source_monitor_log_profile_test.go index aaf843df81a9..951e3c562688 100644 --- a/azurerm/data_source_monitor_log_profile_test.go +++ b/azurerm/internal/services/monitor/data_source_monitor_log_profile_test.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/internal/services/monitor/registration.go b/azurerm/internal/services/monitor/registration.go index b241f5d9003a..e04dcda74c9e 100644 --- a/azurerm/internal/services/monitor/registration.go +++ b/azurerm/internal/services/monitor/registration.go @@ -13,10 +13,21 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_monitor_action_group": dataSourceArmMonitorActionGroup(), + "azurerm_monitor_diagnostic_categories": dataSourceArmMonitorDiagnosticCategories(), + "azurerm_monitor_log_profile": dataSourceArmMonitorLogProfile()} } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_metric_alertrule": resourceArmMetricAlertRule(), + "azurerm_monitor_autoscale_setting": resourceArmMonitorAutoScaleSetting(), + "azurerm_monitor_action_group": resourceArmMonitorActionGroup(), + "azurerm_monitor_activity_log_alert": resourceArmMonitorActivityLogAlert(), + "azurerm_monitor_diagnostic_setting": resourceArmMonitorDiagnosticSetting(), + "azurerm_monitor_log_profile": resourceArmMonitorLogProfile(), + "azurerm_monitor_metric_alert": resourceArmMonitorMetricAlert(), + "azurerm_monitor_metric_alertrule": resourceArmMonitorMetricAlertRule()} } diff --git a/azurerm/resource_arm_metric_alertrule.go b/azurerm/internal/services/monitor/resource_arm_metric_alertrule.go similarity index 99% rename from azurerm/resource_arm_metric_alertrule.go rename to azurerm/internal/services/monitor/resource_arm_metric_alertrule.go index bbc691028140..847ad62d70bc 100644 --- a/azurerm/resource_arm_metric_alertrule.go +++ b/azurerm/internal/services/monitor/resource_arm_metric_alertrule.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_metric_alertrule_test.go b/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go similarity index 98% rename from azurerm/resource_arm_metric_alertrule_test.go rename to azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go index de6c8a6fc3b2..0473f9badead 100644 --- a/azurerm/resource_arm_metric_alertrule_test.go +++ b/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go @@ -1,7 +1,8 @@ -package azurerm +package monitor import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "testing" @@ -297,7 +298,7 @@ resource "azurerm_metric_alertrule" "import" { } func testAccAzureRMMetricAlertRule_sqlDatabaseStorage(rInt int, location string) string { - basicSqlServerDatabase := testAccAzureRMSqlDatabase_basic(rInt, location) + basicSqlServerDatabase := azurerm.testAccAzureRMSqlDatabase_basic(rInt, location) return fmt.Sprintf(` %s diff --git a/azurerm/resource_arm_monitor_action_group.go b/azurerm/internal/services/monitor/resource_arm_monitor_action_group.go similarity index 99% rename from azurerm/resource_arm_monitor_action_group.go rename to azurerm/internal/services/monitor/resource_arm_monitor_action_group.go index d19d7c2d212f..326370c08c55 100644 --- a/azurerm/resource_arm_monitor_action_group.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_action_group.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_monitor_action_group_test.go b/azurerm/internal/services/monitor/resource_arm_monitor_action_group_test.go similarity index 99% rename from azurerm/resource_arm_monitor_action_group_test.go rename to azurerm/internal/services/monitor/resource_arm_monitor_action_group_test.go index a9fa7e5aba95..2d32deb55dea 100644 --- a/azurerm/resource_arm_monitor_action_group_test.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_action_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_monitor_activity_log_alert.go b/azurerm/internal/services/monitor/resource_arm_monitor_activity_log_alert.go similarity index 99% rename from azurerm/resource_arm_monitor_activity_log_alert.go rename to azurerm/internal/services/monitor/resource_arm_monitor_activity_log_alert.go index 13cacca264b8..7b00c5bf3d17 100644 --- a/azurerm/resource_arm_monitor_activity_log_alert.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_activity_log_alert.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "bytes" diff --git a/azurerm/resource_arm_monitor_activity_log_alert_test.go b/azurerm/internal/services/monitor/resource_arm_monitor_activity_log_alert_test.go similarity index 99% rename from azurerm/resource_arm_monitor_activity_log_alert_test.go rename to azurerm/internal/services/monitor/resource_arm_monitor_activity_log_alert_test.go index c90576bdfbb7..aafbfcd15f33 100644 --- a/azurerm/resource_arm_monitor_activity_log_alert_test.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_activity_log_alert_test.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_monitor_autoscale_setting.go b/azurerm/internal/services/monitor/resource_arm_monitor_autoscale_setting.go similarity index 99% rename from azurerm/resource_arm_monitor_autoscale_setting.go rename to azurerm/internal/services/monitor/resource_arm_monitor_autoscale_setting.go index 4c2f30dae6a0..15702121148e 100644 --- a/azurerm/resource_arm_monitor_autoscale_setting.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_autoscale_setting.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_monitor_autoscale_setting_test.go b/azurerm/internal/services/monitor/resource_arm_monitor_autoscale_setting_test.go similarity index 99% rename from azurerm/resource_arm_monitor_autoscale_setting_test.go rename to azurerm/internal/services/monitor/resource_arm_monitor_autoscale_setting_test.go index 9ce503fcc75c..b2b1c10774af 100644 --- a/azurerm/resource_arm_monitor_autoscale_setting_test.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_autoscale_setting_test.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_monitor_diagnostic_setting.go b/azurerm/internal/services/monitor/resource_arm_monitor_diagnostic_setting.go similarity index 99% rename from azurerm/resource_arm_monitor_diagnostic_setting.go rename to azurerm/internal/services/monitor/resource_arm_monitor_diagnostic_setting.go index a2e1b7f58b00..265487e81f32 100644 --- a/azurerm/resource_arm_monitor_diagnostic_setting.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_diagnostic_setting.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "context" diff --git a/azurerm/resource_arm_monitor_diagnostic_setting_test.go b/azurerm/internal/services/monitor/resource_arm_monitor_diagnostic_setting_test.go similarity index 99% rename from azurerm/resource_arm_monitor_diagnostic_setting_test.go rename to azurerm/internal/services/monitor/resource_arm_monitor_diagnostic_setting_test.go index 3c94d5a14774..0c57bc0739db 100644 --- a/azurerm/resource_arm_monitor_diagnostic_setting_test.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_diagnostic_setting_test.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_monitor_log_profile.go b/azurerm/internal/services/monitor/resource_arm_monitor_log_profile.go similarity index 99% rename from azurerm/resource_arm_monitor_log_profile.go rename to azurerm/internal/services/monitor/resource_arm_monitor_log_profile.go index fe2212402aa5..d11be4017942 100644 --- a/azurerm/resource_arm_monitor_log_profile.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_log_profile.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "context" diff --git a/azurerm/resource_arm_monitor_log_profile_test.go b/azurerm/internal/services/monitor/resource_arm_monitor_log_profile_test.go similarity index 99% rename from azurerm/resource_arm_monitor_log_profile_test.go rename to azurerm/internal/services/monitor/resource_arm_monitor_log_profile_test.go index 4a639ce5073f..9bb07c198af1 100644 --- a/azurerm/resource_arm_monitor_log_profile_test.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_log_profile_test.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_monitor_metric_alert.go b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert.go similarity index 99% rename from azurerm/resource_arm_monitor_metric_alert.go rename to azurerm/internal/services/monitor/resource_arm_monitor_metric_alert.go index e094cd05a202..4ea7208374b0 100644 --- a/azurerm/resource_arm_monitor_metric_alert.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "bytes" diff --git a/azurerm/resource_arm_monitor_metric_alert_test.go b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert_test.go similarity index 99% rename from azurerm/resource_arm_monitor_metric_alert_test.go rename to azurerm/internal/services/monitor/resource_arm_monitor_metric_alert_test.go index a0f51cedd558..e949dcd62e17 100644 --- a/azurerm/resource_arm_monitor_metric_alert_test.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert_test.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_monitor_metric_alertrule.go b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule.go similarity index 99% rename from azurerm/resource_arm_monitor_metric_alertrule.go rename to azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule.go index 853ba6f6660a..7e1f6889064d 100644 --- a/azurerm/resource_arm_monitor_metric_alertrule.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_monitor_metric_alertrule_test.go b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule_test.go similarity index 99% rename from azurerm/resource_arm_monitor_metric_alertrule_test.go rename to azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule_test.go index 4afffa47f5c4..f6cd4894c7ff 100644 --- a/azurerm/resource_arm_monitor_metric_alertrule_test.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule_test.go @@ -1,8 +1,7 @@ -package azurerm +package monitor import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -11,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) diff --git a/azurerm/provider.go b/azurerm/provider.go index b2a19e1f0b28..e16d3deee941 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -24,9 +24,6 @@ func Provider() terraform.ResourceProvider { "azurerm_key_vault": dataSourceArmKeyVault(), "azurerm_lb": dataSourceArmLoadBalancer(), "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), - "azurerm_monitor_action_group": dataSourceArmMonitorActionGroup(), - "azurerm_monitor_diagnostic_categories": dataSourceArmMonitorDiagnosticCategories(), - "azurerm_monitor_log_profile": dataSourceArmMonitorLogProfile(), "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), "azurerm_nat_gateway": dataSourceArmNatGateway(), "azurerm_netapp_account": dataSourceArmNetAppAccount(), @@ -124,14 +121,6 @@ func Provider() terraform.ResourceProvider { "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), "azurerm_management_lock": resourceArmManagementLock(), "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), - "azurerm_metric_alertrule": resourceArmMetricAlertRule(), - "azurerm_monitor_autoscale_setting": resourceArmMonitorAutoScaleSetting(), - "azurerm_monitor_action_group": resourceArmMonitorActionGroup(), - "azurerm_monitor_activity_log_alert": resourceArmMonitorActivityLogAlert(), - "azurerm_monitor_diagnostic_setting": resourceArmMonitorDiagnosticSetting(), - "azurerm_monitor_log_profile": resourceArmMonitorLogProfile(), - "azurerm_monitor_metric_alert": resourceArmMonitorMetricAlert(), - "azurerm_monitor_metric_alertrule": resourceArmMonitorMetricAlertRule(), "azurerm_mssql_elasticpool": resourceArmMsSqlElasticPool(), "azurerm_mssql_database_vulnerability_assessment_rule_baseline": resourceArmMssqlDatabaseVulnerabilityAssessmentRuleBaseline(), "azurerm_mssql_server_security_alert_policy": resourceArmMssqlServerSecurityAlertPolicy(), diff --git a/azurerm/resource_arm_signalr_service_test.go b/azurerm/resource_arm_signalr_service_test.go index 0205060c71f4..d9ddfb6c3c80 100644 --- a/azurerm/resource_arm_signalr_service_test.go +++ b/azurerm/resource_arm_signalr_service_test.go @@ -2,6 +2,7 @@ package azurerm import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/monitor" "net/http" "testing" @@ -162,7 +163,7 @@ func TestAccAzureRMSignalRService_skuUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMonitorMetricAlertDestroy, + CheckDestroy: monitor.testCheckAzureRMMonitorMetricAlertDestroy, Steps: []resource.TestStep{ { Config: freeConfig, @@ -226,7 +227,7 @@ func TestAccAzureRMSignalRService_capacityUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMonitorMetricAlertDestroy, + CheckDestroy: monitor.testCheckAzureRMMonitorMetricAlertDestroy, Steps: []resource.TestStep{ { Config: standardConfig, @@ -290,7 +291,7 @@ func TestAccAzureRMSignalRService_skuAndCapacityUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMonitorMetricAlertDestroy, + CheckDestroy: monitor.testCheckAzureRMMonitorMetricAlertDestroy, Steps: []resource.TestStep{ { Config: freeConfig, From 022c43272654d1db10bff2e39d6d0afd9e35eb59 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 17:54:42 -0800 Subject: [PATCH 039/203] msi --- .../services/msi}/data_source_user_assigned_identity.go | 2 +- .../msi}/data_source_user_assigned_identity_test.go | 2 +- azurerm/internal/services/msi/registration.go | 8 ++++++-- .../services/msi}/resource_arm_user_assigned_identity.go | 2 +- .../msi}/resource_arm_user_assigned_identity_test.go | 2 +- azurerm/provider.go | 2 -- 6 files changed, 10 insertions(+), 8 deletions(-) rename azurerm/{ => internal/services/msi}/data_source_user_assigned_identity.go (99%) rename azurerm/{ => internal/services/msi}/data_source_user_assigned_identity_test.go (99%) rename azurerm/{ => internal/services/msi}/resource_arm_user_assigned_identity.go (99%) rename azurerm/{ => internal/services/msi}/resource_arm_user_assigned_identity_test.go (99%) diff --git a/azurerm/data_source_user_assigned_identity.go b/azurerm/internal/services/msi/data_source_user_assigned_identity.go similarity index 99% rename from azurerm/data_source_user_assigned_identity.go rename to azurerm/internal/services/msi/data_source_user_assigned_identity.go index f2e208a6a821..a5d2bd849c9e 100644 --- a/azurerm/data_source_user_assigned_identity.go +++ b/azurerm/internal/services/msi/data_source_user_assigned_identity.go @@ -1,4 +1,4 @@ -package azurerm +package msi import ( "fmt" diff --git a/azurerm/data_source_user_assigned_identity_test.go b/azurerm/internal/services/msi/data_source_user_assigned_identity_test.go similarity index 99% rename from azurerm/data_source_user_assigned_identity_test.go rename to azurerm/internal/services/msi/data_source_user_assigned_identity_test.go index f7926794c2e0..a890aa30de20 100644 --- a/azurerm/data_source_user_assigned_identity_test.go +++ b/azurerm/internal/services/msi/data_source_user_assigned_identity_test.go @@ -1,4 +1,4 @@ -package azurerm +package msi import ( "fmt" diff --git a/azurerm/internal/services/msi/registration.go b/azurerm/internal/services/msi/registration.go index 686497074a4c..1e4a3df1a3d0 100644 --- a/azurerm/internal/services/msi/registration.go +++ b/azurerm/internal/services/msi/registration.go @@ -15,10 +15,14 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_user_assigned_identity": dataSourceArmUserAssignedIdentity(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_user_assigned_identity": resourceArmUserAssignedIdentity(), + } } diff --git a/azurerm/resource_arm_user_assigned_identity.go b/azurerm/internal/services/msi/resource_arm_user_assigned_identity.go similarity index 99% rename from azurerm/resource_arm_user_assigned_identity.go rename to azurerm/internal/services/msi/resource_arm_user_assigned_identity.go index f6499d2eb123..2c76c5dca9f2 100644 --- a/azurerm/resource_arm_user_assigned_identity.go +++ b/azurerm/internal/services/msi/resource_arm_user_assigned_identity.go @@ -1,4 +1,4 @@ -package azurerm +package msi import ( "fmt" diff --git a/azurerm/resource_arm_user_assigned_identity_test.go b/azurerm/internal/services/msi/resource_arm_user_assigned_identity_test.go similarity index 99% rename from azurerm/resource_arm_user_assigned_identity_test.go rename to azurerm/internal/services/msi/resource_arm_user_assigned_identity_test.go index 3a8d54218deb..1aa19d34f07f 100644 --- a/azurerm/resource_arm_user_assigned_identity_test.go +++ b/azurerm/internal/services/msi/resource_arm_user_assigned_identity_test.go @@ -1,4 +1,4 @@ -package azurerm +package msi import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index e16d3deee941..cac3e319dc19 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -66,7 +66,6 @@ func Provider() terraform.ResourceProvider { "azurerm_subscription": dataSourceArmSubscription(), "azurerm_subscriptions": dataSourceArmSubscriptions(), "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), - "azurerm_user_assigned_identity": dataSourceArmUserAssignedIdentity(), "azurerm_virtual_hub": dataSourceArmVirtualHub(), "azurerm_virtual_machine": dataSourceArmVirtualMachine(), "azurerm_virtual_network_gateway": dataSourceArmVirtualNetworkGateway(), @@ -251,7 +250,6 @@ func Provider() terraform.ResourceProvider { "azurerm_template_deployment": resourceArmTemplateDeployment(), "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), - "azurerm_user_assigned_identity": resourceArmUserAssignedIdentity(), "azurerm_virtual_hub": resourceArmVirtualHub(), "azurerm_virtual_network_gateway_connection": resourceArmVirtualNetworkGatewayConnection(), "azurerm_virtual_network_gateway": resourceArmVirtualNetworkGateway(), From c54d4e811a1233024b28ad4a8a8a09b9a517822c Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 18:02:45 -0800 Subject: [PATCH 040/203] mysql --- azurerm/internal/services/mysql/registration.go | 7 ++++++- .../services/mysql}/resource_arm_mysql_configuration.go | 2 +- .../mysql}/resource_arm_mysql_configuration_test.go | 2 +- .../services/mysql}/resource_arm_mysql_database.go | 2 +- .../services/mysql}/resource_arm_mysql_database_test.go | 2 +- .../services/mysql}/resource_arm_mysql_firewall_rule.go | 2 +- .../mysql}/resource_arm_mysql_firewall_rule_test.go | 2 +- .../services/mysql}/resource_arm_mysql_server.go | 2 +- .../services/mysql}/resource_arm_mysql_server_test.go | 2 +- .../mysql}/resource_arm_mysql_virtual_network_rule.go | 2 +- .../mysql}/resource_arm_mysql_virtual_network_rule_test.go | 2 +- azurerm/provider.go | 5 ----- 12 files changed, 16 insertions(+), 16 deletions(-) rename azurerm/{ => internal/services/mysql}/resource_arm_mysql_configuration.go (99%) rename azurerm/{ => internal/services/mysql}/resource_arm_mysql_configuration_test.go (99%) rename azurerm/{ => internal/services/mysql}/resource_arm_mysql_database.go (99%) rename azurerm/{ => internal/services/mysql}/resource_arm_mysql_database_test.go (99%) rename azurerm/{ => internal/services/mysql}/resource_arm_mysql_firewall_rule.go (99%) rename azurerm/{ => internal/services/mysql}/resource_arm_mysql_firewall_rule_test.go (99%) rename azurerm/{ => internal/services/mysql}/resource_arm_mysql_server.go (99%) rename azurerm/{ => internal/services/mysql}/resource_arm_mysql_server_test.go (99%) rename azurerm/{ => internal/services/mysql}/resource_arm_mysql_virtual_network_rule.go (99%) rename azurerm/{ => internal/services/mysql}/resource_arm_mysql_virtual_network_rule_test.go (99%) diff --git a/azurerm/internal/services/mysql/registration.go b/azurerm/internal/services/mysql/registration.go index c1c680392434..5e145d34c4d7 100644 --- a/azurerm/internal/services/mysql/registration.go +++ b/azurerm/internal/services/mysql/registration.go @@ -18,5 +18,10 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_mysql_configuration": resourceArmMySQLConfiguration(), + "azurerm_mysql_database": resourceArmMySqlDatabase(), + "azurerm_mysql_firewall_rule": resourceArmMySqlFirewallRule(), + "azurerm_mysql_server": resourceArmMySqlServer(), + "azurerm_mysql_virtual_network_rule": resourceArmMySqlVirtualNetworkRule()} } diff --git a/azurerm/resource_arm_mysql_configuration.go b/azurerm/internal/services/mysql/resource_arm_mysql_configuration.go similarity index 99% rename from azurerm/resource_arm_mysql_configuration.go rename to azurerm/internal/services/mysql/resource_arm_mysql_configuration.go index 190b3535f616..7b0744e7d22d 100644 --- a/azurerm/resource_arm_mysql_configuration.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_configuration.go @@ -1,4 +1,4 @@ -package azurerm +package mysql import ( "fmt" diff --git a/azurerm/resource_arm_mysql_configuration_test.go b/azurerm/internal/services/mysql/resource_arm_mysql_configuration_test.go similarity index 99% rename from azurerm/resource_arm_mysql_configuration_test.go rename to azurerm/internal/services/mysql/resource_arm_mysql_configuration_test.go index 6d610742a7f5..f6d2fe367adc 100644 --- a/azurerm/resource_arm_mysql_configuration_test.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_configuration_test.go @@ -1,4 +1,4 @@ -package azurerm +package mysql import ( "fmt" diff --git a/azurerm/resource_arm_mysql_database.go b/azurerm/internal/services/mysql/resource_arm_mysql_database.go similarity index 99% rename from azurerm/resource_arm_mysql_database.go rename to azurerm/internal/services/mysql/resource_arm_mysql_database.go index 6b69f697d47c..f1f96e5ad6b8 100644 --- a/azurerm/resource_arm_mysql_database.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_database.go @@ -1,4 +1,4 @@ -package azurerm +package mysql import ( "fmt" diff --git a/azurerm/resource_arm_mysql_database_test.go b/azurerm/internal/services/mysql/resource_arm_mysql_database_test.go similarity index 99% rename from azurerm/resource_arm_mysql_database_test.go rename to azurerm/internal/services/mysql/resource_arm_mysql_database_test.go index e5fc00f27b02..5a5cf2ac8236 100644 --- a/azurerm/resource_arm_mysql_database_test.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_database_test.go @@ -1,4 +1,4 @@ -package azurerm +package mysql import ( "fmt" diff --git a/azurerm/resource_arm_mysql_firewall_rule.go b/azurerm/internal/services/mysql/resource_arm_mysql_firewall_rule.go similarity index 99% rename from azurerm/resource_arm_mysql_firewall_rule.go rename to azurerm/internal/services/mysql/resource_arm_mysql_firewall_rule.go index 7b17814bec43..cc21cf9c0f48 100644 --- a/azurerm/resource_arm_mysql_firewall_rule.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_firewall_rule.go @@ -1,4 +1,4 @@ -package azurerm +package mysql import ( "fmt" diff --git a/azurerm/resource_arm_mysql_firewall_rule_test.go b/azurerm/internal/services/mysql/resource_arm_mysql_firewall_rule_test.go similarity index 99% rename from azurerm/resource_arm_mysql_firewall_rule_test.go rename to azurerm/internal/services/mysql/resource_arm_mysql_firewall_rule_test.go index 2d41cd470352..ead0c6aef8b2 100644 --- a/azurerm/resource_arm_mysql_firewall_rule_test.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_firewall_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package mysql import ( "fmt" diff --git a/azurerm/resource_arm_mysql_server.go b/azurerm/internal/services/mysql/resource_arm_mysql_server.go similarity index 99% rename from azurerm/resource_arm_mysql_server.go rename to azurerm/internal/services/mysql/resource_arm_mysql_server.go index da24bbac855f..743a63c379cc 100644 --- a/azurerm/resource_arm_mysql_server.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_server.go @@ -1,4 +1,4 @@ -package azurerm +package mysql import ( "fmt" diff --git a/azurerm/resource_arm_mysql_server_test.go b/azurerm/internal/services/mysql/resource_arm_mysql_server_test.go similarity index 99% rename from azurerm/resource_arm_mysql_server_test.go rename to azurerm/internal/services/mysql/resource_arm_mysql_server_test.go index 14cd592f6be6..5bd17e8dd238 100644 --- a/azurerm/resource_arm_mysql_server_test.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_server_test.go @@ -1,4 +1,4 @@ -package azurerm +package mysql import ( "fmt" diff --git a/azurerm/resource_arm_mysql_virtual_network_rule.go b/azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule.go similarity index 99% rename from azurerm/resource_arm_mysql_virtual_network_rule.go rename to azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule.go index 5e2806a28f95..5512b43b92fa 100644 --- a/azurerm/resource_arm_mysql_virtual_network_rule.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule.go @@ -1,4 +1,4 @@ -package azurerm +package mysql import ( "context" diff --git a/azurerm/resource_arm_mysql_virtual_network_rule_test.go b/azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule_test.go similarity index 99% rename from azurerm/resource_arm_mysql_virtual_network_rule_test.go rename to azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule_test.go index c74bf58c86bf..318428607aff 100644 --- a/azurerm/resource_arm_mysql_virtual_network_rule_test.go +++ b/azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package mysql import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index cac3e319dc19..9b8c6a5410dc 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -124,11 +124,6 @@ func Provider() terraform.ResourceProvider { "azurerm_mssql_database_vulnerability_assessment_rule_baseline": resourceArmMssqlDatabaseVulnerabilityAssessmentRuleBaseline(), "azurerm_mssql_server_security_alert_policy": resourceArmMssqlServerSecurityAlertPolicy(), "azurerm_mssql_server_vulnerability_assessment": resourceArmMssqlServerVulnerabilityAssessment(), - "azurerm_mysql_configuration": resourceArmMySQLConfiguration(), - "azurerm_mysql_database": resourceArmMySqlDatabase(), - "azurerm_mysql_firewall_rule": resourceArmMySqlFirewallRule(), - "azurerm_mysql_server": resourceArmMySqlServer(), - "azurerm_mysql_virtual_network_rule": resourceArmMySqlVirtualNetworkRule(), "azurerm_nat_gateway": resourceArmNatGateway(), "azurerm_network_connection_monitor": resourceArmNetworkConnectionMonitor(), "azurerm_network_ddos_protection_plan": resourceArmNetworkDDoSProtectionPlan(), From 7baaaa223db48ca0273d8c138c72ff3ce3d380f1 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 18:05:38 -0800 Subject: [PATCH 041/203] netapp --- .../services/netapp}/data_source_netapp_account.go | 5 ++--- .../netapp}/data_source_netapp_account_test.go | 2 +- .../services/netapp}/data_source_netapp_pool.go | 7 +++---- .../services/netapp}/data_source_netapp_pool_test.go | 2 +- .../services/netapp}/data_source_netapp_volume.go | 9 ++++----- .../netapp}/data_source_netapp_volume_test.go | 2 +- azurerm/internal/services/netapp/registration.go | 10 ++++++++-- .../services/netapp}/resource_arm_netapp_account.go | 5 ++--- .../netapp}/resource_arm_netapp_account_test.go | 5 +++-- .../services/netapp}/resource_arm_netapp_pool.go | 7 +++---- .../services/netapp}/resource_arm_netapp_pool_test.go | 2 +- .../services/netapp}/resource_arm_netapp_volume.go | 11 +++++------ .../netapp}/resource_arm_netapp_volume_test.go | 2 +- azurerm/provider.go | 6 ------ 14 files changed, 35 insertions(+), 40 deletions(-) rename azurerm/{ => internal/services/netapp}/data_source_netapp_account.go (91%) rename azurerm/{ => internal/services/netapp}/data_source_netapp_account_test.go (98%) rename azurerm/{ => internal/services/netapp}/data_source_netapp_pool.go (91%) rename azurerm/{ => internal/services/netapp}/data_source_netapp_pool_test.go (98%) rename azurerm/{ => internal/services/netapp}/data_source_netapp_volume.go (91%) rename azurerm/{ => internal/services/netapp}/data_source_netapp_volume_test.go (98%) rename azurerm/{ => internal/services/netapp}/resource_arm_netapp_account.go (97%) rename azurerm/{ => internal/services/netapp}/resource_arm_netapp_account_test.go (98%) rename azurerm/{ => internal/services/netapp}/resource_arm_netapp_pool.go (97%) rename azurerm/{ => internal/services/netapp}/resource_arm_netapp_pool_test.go (99%) rename azurerm/{ => internal/services/netapp}/resource_arm_netapp_volume.go (97%) rename azurerm/{ => internal/services/netapp}/resource_arm_netapp_volume_test.go (99%) diff --git a/azurerm/data_source_netapp_account.go b/azurerm/internal/services/netapp/data_source_netapp_account.go similarity index 91% rename from azurerm/data_source_netapp_account.go rename to azurerm/internal/services/netapp/data_source_netapp_account.go index e9f286c7bd06..983fa777b296 100644 --- a/azurerm/data_source_netapp_account.go +++ b/azurerm/internal/services/netapp/data_source_netapp_account.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - aznetapp "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -24,7 +23,7 @@ func dataSourceArmNetAppAccount() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: aznetapp.ValidateNetAppAccountName, + ValidateFunc: ValidateNetAppAccountName, }, "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), diff --git a/azurerm/data_source_netapp_account_test.go b/azurerm/internal/services/netapp/data_source_netapp_account_test.go similarity index 98% rename from azurerm/data_source_netapp_account_test.go rename to azurerm/internal/services/netapp/data_source_netapp_account_test.go index 47db4825b3ad..39b144a4dd55 100644 --- a/azurerm/data_source_netapp_account_test.go +++ b/azurerm/internal/services/netapp/data_source_netapp_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "fmt" diff --git a/azurerm/data_source_netapp_pool.go b/azurerm/internal/services/netapp/data_source_netapp_pool.go similarity index 91% rename from azurerm/data_source_netapp_pool.go rename to azurerm/internal/services/netapp/data_source_netapp_pool.go index c0fe60b97802..11b59e2e4e22 100644 --- a/azurerm/data_source_netapp_pool.go +++ b/azurerm/internal/services/netapp/data_source_netapp_pool.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - aznetapp "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -24,7 +23,7 @@ func dataSourceArmNetAppPool() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: aznetapp.ValidateNetAppPoolName, + ValidateFunc: ValidateNetAppPoolName, }, "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), @@ -34,7 +33,7 @@ func dataSourceArmNetAppPool() *schema.Resource { "account_name": { Type: schema.TypeString, Required: true, - ValidateFunc: aznetapp.ValidateNetAppAccountName, + ValidateFunc: ValidateNetAppAccountName, }, "service_level": { diff --git a/azurerm/data_source_netapp_pool_test.go b/azurerm/internal/services/netapp/data_source_netapp_pool_test.go similarity index 98% rename from azurerm/data_source_netapp_pool_test.go rename to azurerm/internal/services/netapp/data_source_netapp_pool_test.go index d1f0fa44c76d..6f0b842d82b4 100644 --- a/azurerm/data_source_netapp_pool_test.go +++ b/azurerm/internal/services/netapp/data_source_netapp_pool_test.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "fmt" diff --git a/azurerm/data_source_netapp_volume.go b/azurerm/internal/services/netapp/data_source_netapp_volume.go similarity index 91% rename from azurerm/data_source_netapp_volume.go rename to azurerm/internal/services/netapp/data_source_netapp_volume.go index 62a534197d17..5a55474e19bf 100644 --- a/azurerm/data_source_netapp_volume.go +++ b/azurerm/internal/services/netapp/data_source_netapp_volume.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - aznetapp "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -24,7 +23,7 @@ func dataSourceArmNetAppVolume() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: aznetapp.ValidateNetAppPoolName, + ValidateFunc: ValidateNetAppPoolName, }, "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), @@ -34,13 +33,13 @@ func dataSourceArmNetAppVolume() *schema.Resource { "account_name": { Type: schema.TypeString, Required: true, - ValidateFunc: aznetapp.ValidateNetAppAccountName, + ValidateFunc: ValidateNetAppAccountName, }, "pool_name": { Type: schema.TypeString, Required: true, - ValidateFunc: aznetapp.ValidateNetAppPoolName, + ValidateFunc: ValidateNetAppPoolName, }, "volume_path": { diff --git a/azurerm/data_source_netapp_volume_test.go b/azurerm/internal/services/netapp/data_source_netapp_volume_test.go similarity index 98% rename from azurerm/data_source_netapp_volume_test.go rename to azurerm/internal/services/netapp/data_source_netapp_volume_test.go index fb3d5c54c9c1..508e7cc7bfc6 100644 --- a/azurerm/data_source_netapp_volume_test.go +++ b/azurerm/internal/services/netapp/data_source_netapp_volume_test.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "fmt" diff --git a/azurerm/internal/services/netapp/registration.go b/azurerm/internal/services/netapp/registration.go index 2abc79cd545c..e432adbd1453 100644 --- a/azurerm/internal/services/netapp/registration.go +++ b/azurerm/internal/services/netapp/registration.go @@ -13,10 +13,16 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_netapp_account": dataSourceArmNetAppAccount(), + "azurerm_netapp_pool": dataSourceArmNetAppPool(), + "azurerm_netapp_volume": dataSourceArmNetAppVolume()} } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_netapp_account": resourceArmNetAppAccount(), + "azurerm_netapp_pool": resourceArmNetAppPool(), + "azurerm_netapp_volume": resourceArmNetAppVolume()} } diff --git a/azurerm/resource_arm_netapp_account.go b/azurerm/internal/services/netapp/resource_arm_netapp_account.go similarity index 97% rename from azurerm/resource_arm_netapp_account.go rename to azurerm/internal/services/netapp/resource_arm_netapp_account.go index 98940bfc73eb..154cda165f80 100644 --- a/azurerm/resource_arm_netapp_account.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_account.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "fmt" @@ -16,7 +16,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - aznetapp "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -44,7 +43,7 @@ func resourceArmNetAppAccount() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznetapp.ValidateNetAppAccountName, + ValidateFunc: ValidateNetAppAccountName, }, "resource_group_name": azure.SchemaResourceGroupName(), diff --git a/azurerm/resource_arm_netapp_account_test.go b/azurerm/internal/services/netapp/resource_arm_netapp_account_test.go similarity index 98% rename from azurerm/resource_arm_netapp_account_test.go rename to azurerm/internal/services/netapp/resource_arm_netapp_account_test.go index b3af7ec993b8..ab7fda711ea4 100644 --- a/azurerm/resource_arm_netapp_account_test.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_account_test.go @@ -1,7 +1,8 @@ -package azurerm +package netapp import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -25,7 +26,7 @@ func TestAccAzureRMNetAppAccount(t *testing.T) { "update": testAccAzureRMNetAppAccount_update, }, "DataSource": { - "basic": testAccDataSourceAzureRMNetAppAccount_basic, + "basic": azurerm.testAccDataSourceAzureRMNetAppAccount_basic, }, } diff --git a/azurerm/resource_arm_netapp_pool.go b/azurerm/internal/services/netapp/resource_arm_netapp_pool.go similarity index 97% rename from azurerm/resource_arm_netapp_pool.go rename to azurerm/internal/services/netapp/resource_arm_netapp_pool.go index 213ce8594c01..753cd6d10c95 100644 --- a/azurerm/resource_arm_netapp_pool.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_pool.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "context" @@ -15,7 +15,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - aznetapp "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -43,7 +42,7 @@ func resourceArmNetAppPool() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznetapp.ValidateNetAppPoolName, + ValidateFunc: ValidateNetAppPoolName, }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -54,7 +53,7 @@ func resourceArmNetAppPool() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznetapp.ValidateNetAppAccountName, + ValidateFunc: ValidateNetAppAccountName, }, "service_level": { diff --git a/azurerm/resource_arm_netapp_pool_test.go b/azurerm/internal/services/netapp/resource_arm_netapp_pool_test.go similarity index 99% rename from azurerm/resource_arm_netapp_pool_test.go rename to azurerm/internal/services/netapp/resource_arm_netapp_pool_test.go index 62d4b3437dab..09cb17a3c409 100644 --- a/azurerm/resource_arm_netapp_pool_test.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_pool_test.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "fmt" diff --git a/azurerm/resource_arm_netapp_volume.go b/azurerm/internal/services/netapp/resource_arm_netapp_volume.go similarity index 97% rename from azurerm/resource_arm_netapp_volume.go rename to azurerm/internal/services/netapp/resource_arm_netapp_volume.go index d136b71d333e..8de4776a528f 100644 --- a/azurerm/resource_arm_netapp_volume.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_volume.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "context" @@ -17,7 +17,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - aznetapp "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -45,7 +44,7 @@ func resourceArmNetAppVolume() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznetapp.ValidateNetAppVolumeName, + ValidateFunc: ValidateNetAppVolumeName, }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -56,21 +55,21 @@ func resourceArmNetAppVolume() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznetapp.ValidateNetAppAccountName, + ValidateFunc: ValidateNetAppAccountName, }, "pool_name": { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznetapp.ValidateNetAppPoolName, + ValidateFunc: ValidateNetAppPoolName, }, "volume_path": { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznetapp.ValidateNetAppVolumeVolumePath, + ValidateFunc: ValidateNetAppVolumeVolumePath, }, "service_level": { diff --git a/azurerm/resource_arm_netapp_volume_test.go b/azurerm/internal/services/netapp/resource_arm_netapp_volume_test.go similarity index 99% rename from azurerm/resource_arm_netapp_volume_test.go rename to azurerm/internal/services/netapp/resource_arm_netapp_volume_test.go index 84a71b9300c4..27fc71336ef9 100644 --- a/azurerm/resource_arm_netapp_volume_test.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_volume_test.go @@ -1,4 +1,4 @@ -package azurerm +package netapp import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 9b8c6a5410dc..b3775928ba7f 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -26,9 +26,6 @@ func Provider() terraform.ResourceProvider { "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), "azurerm_nat_gateway": dataSourceArmNatGateway(), - "azurerm_netapp_account": dataSourceArmNetAppAccount(), - "azurerm_netapp_pool": dataSourceArmNetAppPool(), - "azurerm_netapp_volume": dataSourceArmNetAppVolume(), "azurerm_network_ddos_protection_plan": dataSourceNetworkDDoSProtectionPlan(), "azurerm_network_interface": dataSourceArmNetworkInterface(), "azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(), @@ -138,9 +135,6 @@ func Provider() terraform.ResourceProvider { "azurerm_network_security_rule": resourceArmNetworkSecurityRule(), "azurerm_network_watcher_flow_log": resourceArmNetworkWatcherFlowLog(), "azurerm_network_watcher": resourceArmNetworkWatcher(), - "azurerm_netapp_account": resourceArmNetAppAccount(), - "azurerm_netapp_pool": resourceArmNetAppPool(), - "azurerm_netapp_volume": resourceArmNetAppVolume(), "azurerm_notification_hub_authorization_rule": resourceArmNotificationHubAuthorizationRule(), "azurerm_notification_hub_namespace": resourceArmNotificationHubNamespace(), "azurerm_notification_hub": resourceArmNotificationHub(), From fa14bafcf485589f6d6986aeaf2408b305cec27a Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Thu, 19 Dec 2019 18:33:06 -0800 Subject: [PATCH 042/203] network --- .../services/network}/data_source_firewall.go | 2 +- .../network}/data_source_firewall_test.go | 2 +- .../network}/data_source_nat_gateway.go | 5 +- .../network}/data_source_nat_gateway_test.go | 2 +- ...ata_source_network_ddos_protection_plan.go | 2 +- ...ource_network_ddos_protection_plan_test.go | 2 +- .../network}/data_source_network_interface.go | 2 +- .../data_source_network_interface_test.go | 2 +- .../data_source_network_security_group.go | 2 +- ...data_source_network_security_group_test.go | 2 +- .../network}/data_source_network_watcher.go | 2 +- .../data_source_network_watcher_test.go | 2 +- .../network}/data_source_route_table.go | 2 +- .../network}/data_source_route_table_test.go | 2 +- .../services/network}/data_source_subnet.go | 2 +- .../network}/data_source_subnet_test.go | 2 +- .../network}/data_source_virtual_hub.go | 5 +- .../network}/data_source_virtual_hub_test.go | 2 +- .../network}/data_source_virtual_machine.go | 2 +- .../data_source_virtual_machine_test.go | 2 +- .../network}/data_source_virtual_network.go | 2 +- .../data_source_virtual_network_gateway.go | 2 +- ...urce_virtual_network_gateway_connection.go | 2 +- ...virtual_network_gateway_connection_test.go | 2 +- ...ata_source_virtual_network_gateway_test.go | 2 +- .../data_source_virtual_network_test.go | 2 +- .../services/network}/deprecated.go | 2 +- .../internal/services/network/registration.go | 54 +++- .../resource_arm_ddos_protection_plan.go | 12 +- .../resource_arm_ddos_protection_plan_test.go | 2 +- .../network}/resource_arm_firewall.go | 26 +- ...rm_firewall_application_rule_collection.go | 2 +- ...rewall_application_rule_collection_test.go | 2 +- ...source_arm_firewall_nat_rule_collection.go | 2 +- ...e_arm_firewall_nat_rule_collection_test.go | 2 +- ...ce_arm_firewall_network_rule_collection.go | 2 +- ...m_firewall_network_rule_collection_test.go | 2 +- .../network}/resource_arm_firewall_test.go | 2 +- .../resource_arm_local_network_gateway.go | 2 +- ...resource_arm_local_network_gateway_test.go | 2 +- .../network}/resource_arm_nat_gateway.go | 5 +- .../network}/resource_arm_nat_gateway_test.go | 2 +- ...resource_arm_network_connection_monitor.go | 2 +- ...rce_arm_network_connection_monitor_test.go | 2 +- ...source_arm_network_ddos_protection_plan.go | 12 +- ...e_arm_network_ddos_protection_plan_test.go | 2 +- .../resource_arm_network_interface.go | 28 +- ...terface_application_gateway_association.go | 2 +- ...ce_application_gateway_association_test.go | 2 +- ..._application_security_group_association.go | 2 +- ...ication_security_group_association_test.go | 2 +- ...erface_backend_address_pool_association.go | 2 +- ...e_backend_address_pool_association_test.go | 2 +- ..._network_interface_nat_rule_association.go | 2 +- ...ork_interface_nat_rule_association_test.go | 2 +- .../resource_arm_network_interface_test.go | 2 +- .../resource_arm_network_packet_capture.go | 2 +- ...esource_arm_network_packet_capture_test.go | 2 +- .../network}/resource_arm_network_profile.go | 22 +- .../resource_arm_network_profile_test.go | 2 +- .../resource_arm_network_security_group.go | 9 +- ...esource_arm_network_security_group_test.go | 2 +- .../resource_arm_network_security_rule.go | 2 +- ...resource_arm_network_security_rule_test.go | 2 +- .../network}/resource_arm_network_watcher.go | 2 +- .../resource_arm_network_watcher_flow_log.go | 2 +- ...ource_arm_network_watcher_flow_log_test.go | 2 +- .../resource_arm_network_watcher_test.go | 2 +- .../services/network}/resource_arm_route.go | 2 +- .../network}/resource_arm_route_table.go | 9 +- .../network}/resource_arm_route_table_test.go | 2 +- .../network}/resource_arm_route_test.go | 2 +- .../services/network}/resource_arm_subnet.go | 25 +- ...urce_arm_subnet_nat_gateway_association.go | 14 +- ...arm_subnet_nat_gateway_association_test.go | 2 +- ...bnet_network_security_group_association.go | 23 +- ...network_security_group_association_test.go | 2 +- ...urce_arm_subnet_route_table_association.go | 15 +- ...arm_subnet_route_table_association_test.go | 2 +- .../network}/resource_arm_subnet_test.go | 2 +- .../network}/resource_arm_virtual_hub.go | 9 +- .../network}/resource_arm_virtual_hub_test.go | 2 +- .../network}/resource_arm_virtual_network.go | 12 +- .../resource_arm_virtual_network_gateway.go | 2 +- ..._arm_virtual_network_gateway_connection.go | 2 +- ...virtual_network_gateway_connection_test.go | 2 +- ...source_arm_virtual_network_gateway_test.go | 2 +- .../resource_arm_virtual_network_peering.go | 2 +- ...source_arm_virtual_network_peering_test.go | 2 +- .../resource_arm_virtual_network_test.go | 2 +- .../network}/resource_arm_virtual_wan.go | 7 +- .../network}/resource_arm_virtual_wan_test.go | 2 +- .../network}/resource_arm_vpn_gateway.go | 9 +- .../network}/resource_arm_vpn_gateway_test.go | 2 +- .../resource_arm_vpn_server_configuration.go | 7 +- ...ource_arm_vpn_server_configuration_test.go | 2 +- ...rce_arm_web_application_firewall_policy.go | 2 +- ...rm_web_application_firewall_policy_test.go | 2 +- azurerm/provider.go | 244 +++++++----------- ...app_service_virtual_network_association.go | 17 +- azurerm/resource_arm_key_vault.go | 13 +- azurerm/resource_arm_redis_cache.go | 17 +- azurerm/resource_arm_storage_account.go | 5 +- 103 files changed, 377 insertions(+), 383 deletions(-) rename azurerm/{ => internal/services/network}/data_source_firewall.go (99%) rename azurerm/{ => internal/services/network}/data_source_firewall_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_nat_gateway.go (95%) rename azurerm/{ => internal/services/network}/data_source_nat_gateway_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_network_ddos_protection_plan.go (99%) rename azurerm/{ => internal/services/network}/data_source_network_ddos_protection_plan_test.go (98%) rename azurerm/{ => internal/services/network}/data_source_network_interface.go (99%) rename azurerm/{ => internal/services/network}/data_source_network_interface_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_network_security_group.go (99%) rename azurerm/{ => internal/services/network}/data_source_network_security_group_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_network_watcher.go (99%) rename azurerm/{ => internal/services/network}/data_source_network_watcher_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_route_table.go (99%) rename azurerm/{ => internal/services/network}/data_source_route_table_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_subnet.go (99%) rename azurerm/{ => internal/services/network}/data_source_subnet_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_virtual_hub.go (93%) rename azurerm/{ => internal/services/network}/data_source_virtual_hub_test.go (98%) rename azurerm/{ => internal/services/network}/data_source_virtual_machine.go (99%) rename azurerm/{ => internal/services/network}/data_source_virtual_machine_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_virtual_network.go (99%) rename azurerm/{ => internal/services/network}/data_source_virtual_network_gateway.go (99%) rename azurerm/{ => internal/services/network}/data_source_virtual_network_gateway_connection.go (99%) rename azurerm/{ => internal/services/network}/data_source_virtual_network_gateway_connection_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_virtual_network_gateway_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_virtual_network_test.go (99%) rename azurerm/{ => internal/services/network}/deprecated.go (97%) rename azurerm/{ => internal/services/network}/resource_arm_ddos_protection_plan.go (96%) rename azurerm/{ => internal/services/network}/resource_arm_ddos_protection_plan_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_firewall.go (94%) rename azurerm/{ => internal/services/network}/resource_arm_firewall_application_rule_collection.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_firewall_application_rule_collection_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_firewall_nat_rule_collection.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_firewall_nat_rule_collection_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_firewall_network_rule_collection.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_firewall_network_rule_collection_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_firewall_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_local_network_gateway.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_local_network_gateway_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_nat_gateway.go (98%) rename azurerm/{ => internal/services/network}/resource_arm_nat_gateway_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_connection_monitor.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_connection_monitor_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_ddos_protection_plan.go (96%) rename azurerm/{ => internal/services/network}/resource_arm_network_ddos_protection_plan_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_interface.go (96%) rename azurerm/{ => internal/services/network}/resource_arm_network_interface_application_gateway_association.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_interface_application_gateway_association_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_interface_application_security_group_association.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_interface_application_security_group_association_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_interface_backend_address_pool_association.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_interface_backend_address_pool_association_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_interface_nat_rule_association.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_interface_nat_rule_association_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_interface_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_packet_capture.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_packet_capture_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_profile.go (95%) rename azurerm/{ => internal/services/network}/resource_arm_network_profile_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_security_group.go (98%) rename azurerm/{ => internal/services/network}/resource_arm_network_security_group_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_security_rule.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_security_rule_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_watcher.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_watcher_flow_log.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_watcher_flow_log_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_network_watcher_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_route.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_route_table.go (97%) rename azurerm/{ => internal/services/network}/resource_arm_route_table_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_route_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_subnet.go (95%) rename azurerm/{ => internal/services/network}/resource_arm_subnet_nat_gateway_association.go (95%) rename azurerm/{ => internal/services/network}/resource_arm_subnet_nat_gateway_association_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_subnet_network_security_group_association.go (91%) rename azurerm/{ => internal/services/network}/resource_arm_subnet_network_security_group_association_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_subnet_route_table_association.go (94%) rename azurerm/{ => internal/services/network}/resource_arm_subnet_route_table_association_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_subnet_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_hub.go (96%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_hub_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_network.go (97%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_network_gateway.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_network_gateway_connection.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_network_gateway_connection_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_network_gateway_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_network_peering.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_network_peering_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_network_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_wan.go (97%) rename azurerm/{ => internal/services/network}/resource_arm_virtual_wan_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_vpn_gateway.go (97%) rename azurerm/{ => internal/services/network}/resource_arm_vpn_gateway_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_vpn_server_configuration.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_vpn_server_configuration_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_web_application_firewall_policy.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_web_application_firewall_policy_test.go (99%) diff --git a/azurerm/data_source_firewall.go b/azurerm/internal/services/network/data_source_firewall.go similarity index 99% rename from azurerm/data_source_firewall.go rename to azurerm/internal/services/network/data_source_firewall.go index 4a69f655916d..63a8308d9ad0 100644 --- a/azurerm/data_source_firewall.go +++ b/azurerm/internal/services/network/data_source_firewall.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_firewall_test.go b/azurerm/internal/services/network/data_source_firewall_test.go similarity index 99% rename from azurerm/data_source_firewall_test.go rename to azurerm/internal/services/network/data_source_firewall_test.go index 7ab4315c442d..067f6b9098e6 100644 --- a/azurerm/data_source_firewall_test.go +++ b/azurerm/internal/services/network/data_source_firewall_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_nat_gateway.go b/azurerm/internal/services/network/data_source_nat_gateway.go similarity index 95% rename from azurerm/data_source_nat_gateway.go rename to azurerm/internal/services/network/data_source_nat_gateway.go index adb55f10f540..2b9445e36b96 100644 --- a/azurerm/data_source_nat_gateway.go +++ b/azurerm/internal/services/network/data_source_nat_gateway.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "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/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -24,7 +23,7 @@ func dataSourceArmNatGateway() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: network.ValidateNatGatewayName, + ValidateFunc: ValidateNatGatewayName, }, "location": azure.SchemaLocationForDataSource(), diff --git a/azurerm/data_source_nat_gateway_test.go b/azurerm/internal/services/network/data_source_nat_gateway_test.go similarity index 99% rename from azurerm/data_source_nat_gateway_test.go rename to azurerm/internal/services/network/data_source_nat_gateway_test.go index 9067723b3fa4..f856984e0788 100644 --- a/azurerm/data_source_nat_gateway_test.go +++ b/azurerm/internal/services/network/data_source_nat_gateway_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_network_ddos_protection_plan.go b/azurerm/internal/services/network/data_source_network_ddos_protection_plan.go similarity index 99% rename from azurerm/data_source_network_ddos_protection_plan.go rename to azurerm/internal/services/network/data_source_network_ddos_protection_plan.go index 6f9475ae72b8..5c9089e15f27 100644 --- a/azurerm/data_source_network_ddos_protection_plan.go +++ b/azurerm/internal/services/network/data_source_network_ddos_protection_plan.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_network_ddos_protection_plan_test.go b/azurerm/internal/services/network/data_source_network_ddos_protection_plan_test.go similarity index 98% rename from azurerm/data_source_network_ddos_protection_plan_test.go rename to azurerm/internal/services/network/data_source_network_ddos_protection_plan_test.go index 73fa9f48aace..90f696e1f5c0 100644 --- a/azurerm/data_source_network_ddos_protection_plan_test.go +++ b/azurerm/internal/services/network/data_source_network_ddos_protection_plan_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_network_interface.go b/azurerm/internal/services/network/data_source_network_interface.go similarity index 99% rename from azurerm/data_source_network_interface.go rename to azurerm/internal/services/network/data_source_network_interface.go index e03a7f747fc3..7e934893da4e 100644 --- a/azurerm/data_source_network_interface.go +++ b/azurerm/internal/services/network/data_source_network_interface.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_network_interface_test.go b/azurerm/internal/services/network/data_source_network_interface_test.go similarity index 99% rename from azurerm/data_source_network_interface_test.go rename to azurerm/internal/services/network/data_source_network_interface_test.go index 279d6bbcd2fe..2e59d846ab99 100644 --- a/azurerm/data_source_network_interface_test.go +++ b/azurerm/internal/services/network/data_source_network_interface_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_network_security_group.go b/azurerm/internal/services/network/data_source_network_security_group.go similarity index 99% rename from azurerm/data_source_network_security_group.go rename to azurerm/internal/services/network/data_source_network_security_group.go index 938dfd34db5e..b2d9f09c9d31 100644 --- a/azurerm/data_source_network_security_group.go +++ b/azurerm/internal/services/network/data_source_network_security_group.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_network_security_group_test.go b/azurerm/internal/services/network/data_source_network_security_group_test.go similarity index 99% rename from azurerm/data_source_network_security_group_test.go rename to azurerm/internal/services/network/data_source_network_security_group_test.go index 8e37d9455b0c..0bdb82319294 100644 --- a/azurerm/data_source_network_security_group_test.go +++ b/azurerm/internal/services/network/data_source_network_security_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_network_watcher.go b/azurerm/internal/services/network/data_source_network_watcher.go similarity index 99% rename from azurerm/data_source_network_watcher.go rename to azurerm/internal/services/network/data_source_network_watcher.go index 93b00f2c555b..36a0e1b36c8d 100644 --- a/azurerm/data_source_network_watcher.go +++ b/azurerm/internal/services/network/data_source_network_watcher.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_network_watcher_test.go b/azurerm/internal/services/network/data_source_network_watcher_test.go similarity index 99% rename from azurerm/data_source_network_watcher_test.go rename to azurerm/internal/services/network/data_source_network_watcher_test.go index fba6f055790d..524278f1af3d 100644 --- a/azurerm/data_source_network_watcher_test.go +++ b/azurerm/internal/services/network/data_source_network_watcher_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_route_table.go b/azurerm/internal/services/network/data_source_route_table.go similarity index 99% rename from azurerm/data_source_route_table.go rename to azurerm/internal/services/network/data_source_route_table.go index f997f1c7c5a1..5e0b5ca9fb18 100644 --- a/azurerm/data_source_route_table.go +++ b/azurerm/internal/services/network/data_source_route_table.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_route_table_test.go b/azurerm/internal/services/network/data_source_route_table_test.go similarity index 99% rename from azurerm/data_source_route_table_test.go rename to azurerm/internal/services/network/data_source_route_table_test.go index 7569c4547e76..564ee5708f96 100644 --- a/azurerm/data_source_route_table_test.go +++ b/azurerm/internal/services/network/data_source_route_table_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_subnet.go b/azurerm/internal/services/network/data_source_subnet.go similarity index 99% rename from azurerm/data_source_subnet.go rename to azurerm/internal/services/network/data_source_subnet.go index 206cd224b0b8..f5c33e264caf 100644 --- a/azurerm/data_source_subnet.go +++ b/azurerm/internal/services/network/data_source_subnet.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_subnet_test.go b/azurerm/internal/services/network/data_source_subnet_test.go similarity index 99% rename from azurerm/data_source_subnet_test.go rename to azurerm/internal/services/network/data_source_subnet_test.go index 324d269c36ee..b0b245fc2654 100644 --- a/azurerm/data_source_subnet_test.go +++ b/azurerm/internal/services/network/data_source_subnet_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_virtual_hub.go b/azurerm/internal/services/network/data_source_virtual_hub.go similarity index 93% rename from azurerm/data_source_virtual_hub.go rename to azurerm/internal/services/network/data_source_virtual_hub.go index 34da4f230001..024227463b94 100644 --- a/azurerm/data_source_virtual_hub.go +++ b/azurerm/internal/services/network/data_source_virtual_hub.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - aznetwork "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -25,7 +24,7 @@ func dataSourceArmVirtualHub() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: aznetwork.ValidateVirtualHubName, + ValidateFunc: ValidateVirtualHubName, }, "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), diff --git a/azurerm/data_source_virtual_hub_test.go b/azurerm/internal/services/network/data_source_virtual_hub_test.go similarity index 98% rename from azurerm/data_source_virtual_hub_test.go rename to azurerm/internal/services/network/data_source_virtual_hub_test.go index 3eb01ac7349d..5cccc5921623 100644 --- a/azurerm/data_source_virtual_hub_test.go +++ b/azurerm/internal/services/network/data_source_virtual_hub_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_virtual_machine.go b/azurerm/internal/services/network/data_source_virtual_machine.go similarity index 99% rename from azurerm/data_source_virtual_machine.go rename to azurerm/internal/services/network/data_source_virtual_machine.go index a8401fd32a34..dac846aca2c5 100644 --- a/azurerm/data_source_virtual_machine.go +++ b/azurerm/internal/services/network/data_source_virtual_machine.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_virtual_machine_test.go b/azurerm/internal/services/network/data_source_virtual_machine_test.go similarity index 99% rename from azurerm/data_source_virtual_machine_test.go rename to azurerm/internal/services/network/data_source_virtual_machine_test.go index 033f274bd213..4a8a3f6a3a03 100644 --- a/azurerm/data_source_virtual_machine_test.go +++ b/azurerm/internal/services/network/data_source_virtual_machine_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_virtual_network.go b/azurerm/internal/services/network/data_source_virtual_network.go similarity index 99% rename from azurerm/data_source_virtual_network.go rename to azurerm/internal/services/network/data_source_virtual_network.go index f8ea25ac60f7..38ec3493b37d 100644 --- a/azurerm/data_source_virtual_network.go +++ b/azurerm/internal/services/network/data_source_virtual_network.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_virtual_network_gateway.go b/azurerm/internal/services/network/data_source_virtual_network_gateway.go similarity index 99% rename from azurerm/data_source_virtual_network_gateway.go rename to azurerm/internal/services/network/data_source_virtual_network_gateway.go index 9b874481cf8b..f9203c7b9f57 100644 --- a/azurerm/data_source_virtual_network_gateway.go +++ b/azurerm/internal/services/network/data_source_virtual_network_gateway.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_virtual_network_gateway_connection.go b/azurerm/internal/services/network/data_source_virtual_network_gateway_connection.go similarity index 99% rename from azurerm/data_source_virtual_network_gateway_connection.go rename to azurerm/internal/services/network/data_source_virtual_network_gateway_connection.go index 49e079de8f07..2a57f5ead942 100644 --- a/azurerm/data_source_virtual_network_gateway_connection.go +++ b/azurerm/internal/services/network/data_source_virtual_network_gateway_connection.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_virtual_network_gateway_connection_test.go b/azurerm/internal/services/network/data_source_virtual_network_gateway_connection_test.go similarity index 99% rename from azurerm/data_source_virtual_network_gateway_connection_test.go rename to azurerm/internal/services/network/data_source_virtual_network_gateway_connection_test.go index c8daf6a35b37..107eb0ef11e3 100644 --- a/azurerm/data_source_virtual_network_gateway_connection_test.go +++ b/azurerm/internal/services/network/data_source_virtual_network_gateway_connection_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_virtual_network_gateway_test.go b/azurerm/internal/services/network/data_source_virtual_network_gateway_test.go similarity index 99% rename from azurerm/data_source_virtual_network_gateway_test.go rename to azurerm/internal/services/network/data_source_virtual_network_gateway_test.go index 1956643f0d4f..f2809a54ad5f 100644 --- a/azurerm/data_source_virtual_network_gateway_test.go +++ b/azurerm/internal/services/network/data_source_virtual_network_gateway_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_virtual_network_test.go b/azurerm/internal/services/network/data_source_virtual_network_test.go similarity index 99% rename from azurerm/data_source_virtual_network_test.go rename to azurerm/internal/services/network/data_source_virtual_network_test.go index 6312edd74014..95bc6633ae4c 100644 --- a/azurerm/data_source_virtual_network_test.go +++ b/azurerm/internal/services/network/data_source_virtual_network_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/deprecated.go b/azurerm/internal/services/network/deprecated.go similarity index 97% rename from azurerm/deprecated.go rename to azurerm/internal/services/network/deprecated.go index a2f7fe5233d8..1fc000e39150 100644 --- a/azurerm/deprecated.go +++ b/azurerm/internal/services/network/deprecated.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/internal/services/network/registration.go b/azurerm/internal/services/network/registration.go index 93eed1d2595f..8ef4096fd29e 100644 --- a/azurerm/internal/services/network/registration.go +++ b/azurerm/internal/services/network/registration.go @@ -13,10 +13,60 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_firewall": dataSourceArmFirewall(), + "azurerm_nat_gateway": dataSourceArmNatGateway(), + "azurerm_network_ddos_protection_plan": dataSourceNetworkDDoSProtectionPlan(), + "azurerm_network_interface": dataSourceArmNetworkInterface(), + "azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(), + "azurerm_network_watcher": dataSourceArmNetworkWatcher(), + "azurerm_route_table": dataSourceArmRouteTable(), + "azurerm_subnet": dataSourceArmSubnet(), + "azurerm_virtual_hub": dataSourceArmVirtualHub(), + "azurerm_virtual_machine": dataSourceArmVirtualMachine(), + "azurerm_virtual_network_gateway": dataSourceArmVirtualNetworkGateway(), + "azurerm_virtual_network_gateway_connection": dataSourceArmVirtualNetworkGatewayConnection(), + "azurerm_virtual_network": dataSourceArmVirtualNetwork(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), + "azurerm_firewall_application_rule_collection": resourceArmFirewallApplicationRuleCollection(), + "azurerm_firewall_nat_rule_collection": resourceArmFirewallNatRuleCollection(), + "azurerm_firewall_network_rule_collection": resourceArmFirewallNetworkRuleCollection(), + "azurerm_firewall": resourceArmFirewall(), + "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), + "azurerm_nat_gateway": resourceArmNatGateway(), + "azurerm_network_connection_monitor": resourceArmNetworkConnectionMonitor(), + "azurerm_network_ddos_protection_plan": resourceArmNetworkDDoSProtectionPlan(), + "azurerm_network_interface": resourceArmNetworkInterface(), + "azurerm_network_interface_application_gateway_backend_address_pool_association": resourceArmNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation(), + "azurerm_network_interface_application_security_group_association": resourceArmNetworkInterfaceApplicationSecurityGroupAssociation(), + "azurerm_network_interface_backend_address_pool_association": resourceArmNetworkInterfaceBackendAddressPoolAssociation(), + "azurerm_network_interface_nat_rule_association": resourceArmNetworkInterfaceNatRuleAssociation(), + "azurerm_network_packet_capture": resourceArmNetworkPacketCapture(), + "azurerm_network_profile": resourceArmNetworkProfile(), + "azurerm_network_security_group": resourceArmNetworkSecurityGroup(), + "azurerm_network_security_rule": resourceArmNetworkSecurityRule(), + "azurerm_network_watcher_flow_log": resourceArmNetworkWatcherFlowLog(), + "azurerm_network_watcher": resourceArmNetworkWatcher(), + "azurerm_route_table": resourceArmRouteTable(), + "azurerm_route": resourceArmRoute(), + "azurerm_subnet_network_security_group_association": resourceArmSubnetNetworkSecurityGroupAssociation(), + "azurerm_subnet_route_table_association": resourceArmSubnetRouteTableAssociation(), + "azurerm_subnet_nat_gateway_association": resourceArmSubnetNatGatewayAssociation(), + "azurerm_subnet": resourceArmSubnet(), + "azurerm_virtual_hub": resourceArmVirtualHub(), + "azurerm_virtual_network_gateway_connection": resourceArmVirtualNetworkGatewayConnection(), + "azurerm_virtual_network_gateway": resourceArmVirtualNetworkGateway(), + "azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(), + "azurerm_virtual_network": resourceArmVirtualNetwork(), + "azurerm_virtual_wan": resourceArmVirtualWan(), + "azurerm_vpn_gateway": resourceArmVPNGateway(), + "azurerm_vpn_server_configuration": resourceArmVPNServerConfiguration(), + "azurerm_web_application_firewall_policy": resourceArmWebApplicationFirewallPolicy(), + } } diff --git a/azurerm/resource_arm_ddos_protection_plan.go b/azurerm/internal/services/network/resource_arm_ddos_protection_plan.go similarity index 96% rename from azurerm/resource_arm_ddos_protection_plan.go rename to azurerm/internal/services/network/resource_arm_ddos_protection_plan.go index f556f4c069f9..29edffb05e50 100644 --- a/azurerm/resource_arm_ddos_protection_plan.go +++ b/azurerm/internal/services/network/resource_arm_ddos_protection_plan.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -101,8 +101,8 @@ func resourceArmDDoSProtectionPlanCreateUpdate(d *schema.ResourceData, meta inte locks.ByName(name, azureDDoSProtectionPlanResourceName) defer locks.UnlockByName(name, azureDDoSProtectionPlanResourceName) - locks.MultipleByName(vnetsToLock, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnetsToLock, virtualNetworkResourceName) + locks.MultipleByName(vnetsToLock, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(vnetsToLock, VirtualNetworkResourceName) parameters := network.DdosProtectionPlan{ Location: &location, @@ -202,8 +202,8 @@ func resourceArmDDoSProtectionPlanDelete(d *schema.ResourceData, meta interface{ locks.ByName(name, azureDDoSProtectionPlanResourceName) defer locks.UnlockByName(name, azureDDoSProtectionPlanResourceName) - locks.MultipleByName(vnetsToLock, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnetsToLock, virtualNetworkResourceName) + locks.MultipleByName(vnetsToLock, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(vnetsToLock, VirtualNetworkResourceName) future, err := client.Delete(ctx, resourceGroup, name) if err != nil { @@ -229,7 +229,7 @@ func extractVnetNames(d *schema.ResourceData) (*[]string, error) { vnetName := vnetResourceID.Path["virtualNetworks"] - if !sliceContainsValue(vnetNames, vnetName) { + if !SliceContainsValue(vnetNames, vnetName) { vnetNames = append(vnetNames, vnetName) } } diff --git a/azurerm/resource_arm_ddos_protection_plan_test.go b/azurerm/internal/services/network/resource_arm_ddos_protection_plan_test.go similarity index 99% rename from azurerm/resource_arm_ddos_protection_plan_test.go rename to azurerm/internal/services/network/resource_arm_ddos_protection_plan_test.go index 73a7d2e9e558..dbc8fd26ffa8 100644 --- a/azurerm/resource_arm_ddos_protection_plan_test.go +++ b/azurerm/internal/services/network/resource_arm_ddos_protection_plan_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_firewall.go b/azurerm/internal/services/network/resource_arm_firewall.go similarity index 94% rename from azurerm/resource_arm_firewall.go rename to azurerm/internal/services/network/resource_arm_firewall.go index b8d47b6c9cc8..1a705c476ab9 100644 --- a/azurerm/resource_arm_firewall.go +++ b/azurerm/internal/services/network/resource_arm_firewall.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -132,11 +132,11 @@ func resourceArmFirewallCreateUpdate(d *schema.ResourceData, meta interface{}) e locks.ByName(name, azureFirewallResourceName) defer locks.UnlockByName(name, azureFirewallResourceName) - locks.MultipleByName(vnetToLock, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnetToLock, virtualNetworkResourceName) + locks.MultipleByName(vnetToLock, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(vnetToLock, VirtualNetworkResourceName) - locks.MultipleByName(subnetToLock, subnetResourceName) - defer locks.UnlockMultipleByName(subnetToLock, subnetResourceName) + locks.MultipleByName(subnetToLock, SubnetResourceName) + defer locks.UnlockMultipleByName(subnetToLock, SubnetResourceName) parameters := network.AzureFirewall{ Location: &location, @@ -267,12 +267,12 @@ func resourceArmFirewallDelete(d *schema.ResourceData, meta interface{}) error { } subnetName := parsedSubnetId.Path["subnets"] - if !sliceContainsValue(subnetNamesToLock, subnetName) { + if !SliceContainsValue(subnetNamesToLock, subnetName) { subnetNamesToLock = append(subnetNamesToLock, subnetName) } virtualNetworkName := parsedSubnetId.Path["virtualNetworks"] - if !sliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { + if !SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { virtualNetworkNamesToLock = append(virtualNetworkNamesToLock, virtualNetworkName) } } @@ -282,11 +282,11 @@ func resourceArmFirewallDelete(d *schema.ResourceData, meta interface{}) error { locks.ByName(name, azureFirewallResourceName) defer locks.UnlockByName(name, azureFirewallResourceName) - locks.MultipleByName(&virtualNetworkNamesToLock, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(&virtualNetworkNamesToLock, virtualNetworkResourceName) + locks.MultipleByName(&virtualNetworkNamesToLock, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(&virtualNetworkNamesToLock, VirtualNetworkResourceName) - locks.MultipleByName(&subnetNamesToLock, subnetResourceName) - defer locks.UnlockMultipleByName(&subnetNamesToLock, subnetResourceName) + locks.MultipleByName(&subnetNamesToLock, SubnetResourceName) + defer locks.UnlockMultipleByName(&subnetNamesToLock, SubnetResourceName) future, err := client.Delete(ctx, resourceGroup, name) if err != nil { @@ -338,11 +338,11 @@ func expandArmFirewallIPConfigurations(d *schema.ResourceData) (*[]network.Azure subnetName := subnetID.Path["subnets"] virtualNetworkName := subnetID.Path["virtualNetworks"] - if !sliceContainsValue(subnetNamesToLock, subnetName) { + if !SliceContainsValue(subnetNamesToLock, subnetName) { subnetNamesToLock = append(subnetNamesToLock, subnetName) } - if !sliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { + if !SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { virtualNetworkNamesToLock = append(virtualNetworkNamesToLock, virtualNetworkName) } diff --git a/azurerm/resource_arm_firewall_application_rule_collection.go b/azurerm/internal/services/network/resource_arm_firewall_application_rule_collection.go similarity index 99% rename from azurerm/resource_arm_firewall_application_rule_collection.go rename to azurerm/internal/services/network/resource_arm_firewall_application_rule_collection.go index 7cd71443a3a5..ed9828c04d07 100644 --- a/azurerm/resource_arm_firewall_application_rule_collection.go +++ b/azurerm/internal/services/network/resource_arm_firewall_application_rule_collection.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_firewall_application_rule_collection_test.go b/azurerm/internal/services/network/resource_arm_firewall_application_rule_collection_test.go similarity index 99% rename from azurerm/resource_arm_firewall_application_rule_collection_test.go rename to azurerm/internal/services/network/resource_arm_firewall_application_rule_collection_test.go index 63a70b1ddef9..9c483e1689ac 100644 --- a/azurerm/resource_arm_firewall_application_rule_collection_test.go +++ b/azurerm/internal/services/network/resource_arm_firewall_application_rule_collection_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_firewall_nat_rule_collection.go b/azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection.go similarity index 99% rename from azurerm/resource_arm_firewall_nat_rule_collection.go rename to azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection.go index 7bd36566fb99..c66b583adc05 100644 --- a/azurerm/resource_arm_firewall_nat_rule_collection.go +++ b/azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_firewall_nat_rule_collection_test.go b/azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection_test.go similarity index 99% rename from azurerm/resource_arm_firewall_nat_rule_collection_test.go rename to azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection_test.go index 56be3d885bd3..d1783530aba6 100644 --- a/azurerm/resource_arm_firewall_nat_rule_collection_test.go +++ b/azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_firewall_network_rule_collection.go b/azurerm/internal/services/network/resource_arm_firewall_network_rule_collection.go similarity index 99% rename from azurerm/resource_arm_firewall_network_rule_collection.go rename to azurerm/internal/services/network/resource_arm_firewall_network_rule_collection.go index be78fa503fe1..94152cbba0a9 100644 --- a/azurerm/resource_arm_firewall_network_rule_collection.go +++ b/azurerm/internal/services/network/resource_arm_firewall_network_rule_collection.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_firewall_network_rule_collection_test.go b/azurerm/internal/services/network/resource_arm_firewall_network_rule_collection_test.go similarity index 99% rename from azurerm/resource_arm_firewall_network_rule_collection_test.go rename to azurerm/internal/services/network/resource_arm_firewall_network_rule_collection_test.go index a85fb91e7cc2..d070995c97bd 100644 --- a/azurerm/resource_arm_firewall_network_rule_collection_test.go +++ b/azurerm/internal/services/network/resource_arm_firewall_network_rule_collection_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_firewall_test.go b/azurerm/internal/services/network/resource_arm_firewall_test.go similarity index 99% rename from azurerm/resource_arm_firewall_test.go rename to azurerm/internal/services/network/resource_arm_firewall_test.go index 8d9927db5930..71598089231f 100644 --- a/azurerm/resource_arm_firewall_test.go +++ b/azurerm/internal/services/network/resource_arm_firewall_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_local_network_gateway.go b/azurerm/internal/services/network/resource_arm_local_network_gateway.go similarity index 99% rename from azurerm/resource_arm_local_network_gateway.go rename to azurerm/internal/services/network/resource_arm_local_network_gateway.go index 88adaf3f18b6..fd83da21c8fc 100644 --- a/azurerm/resource_arm_local_network_gateway.go +++ b/azurerm/internal/services/network/resource_arm_local_network_gateway.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_local_network_gateway_test.go b/azurerm/internal/services/network/resource_arm_local_network_gateway_test.go similarity index 99% rename from azurerm/resource_arm_local_network_gateway_test.go rename to azurerm/internal/services/network/resource_arm_local_network_gateway_test.go index 415d3e0c326c..4448b49a170c 100644 --- a/azurerm/resource_arm_local_network_gateway_test.go +++ b/azurerm/internal/services/network/resource_arm_local_network_gateway_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_nat_gateway.go b/azurerm/internal/services/network/resource_arm_nat_gateway.go similarity index 98% rename from azurerm/resource_arm_nat_gateway.go rename to azurerm/internal/services/network/resource_arm_nat_gateway.go index ff98b1c4f12b..573065b5087c 100644 --- a/azurerm/resource_arm_nat_gateway.go +++ b/azurerm/internal/services/network/resource_arm_nat_gateway.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -13,7 +13,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -44,7 +43,7 @@ func resourceArmNatGateway() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznet.ValidateNatGatewayName, + ValidateFunc: ValidateNatGatewayName, }, "location": azure.SchemaLocation(), diff --git a/azurerm/resource_arm_nat_gateway_test.go b/azurerm/internal/services/network/resource_arm_nat_gateway_test.go similarity index 99% rename from azurerm/resource_arm_nat_gateway_test.go rename to azurerm/internal/services/network/resource_arm_nat_gateway_test.go index ddd56a793bfa..e5f9ce38d3a7 100644 --- a/azurerm/resource_arm_nat_gateway_test.go +++ b/azurerm/internal/services/network/resource_arm_nat_gateway_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_connection_monitor.go b/azurerm/internal/services/network/resource_arm_network_connection_monitor.go similarity index 99% rename from azurerm/resource_arm_network_connection_monitor.go rename to azurerm/internal/services/network/resource_arm_network_connection_monitor.go index 7f96e734780b..bd9136372f2e 100644 --- a/azurerm/resource_arm_network_connection_monitor.go +++ b/azurerm/internal/services/network/resource_arm_network_connection_monitor.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_connection_monitor_test.go b/azurerm/internal/services/network/resource_arm_network_connection_monitor_test.go similarity index 99% rename from azurerm/resource_arm_network_connection_monitor_test.go rename to azurerm/internal/services/network/resource_arm_network_connection_monitor_test.go index f3835f97acfb..b10c4b64b7fa 100644 --- a/azurerm/resource_arm_network_connection_monitor_test.go +++ b/azurerm/internal/services/network/resource_arm_network_connection_monitor_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_ddos_protection_plan.go b/azurerm/internal/services/network/resource_arm_network_ddos_protection_plan.go similarity index 96% rename from azurerm/resource_arm_network_ddos_protection_plan.go rename to azurerm/internal/services/network/resource_arm_network_ddos_protection_plan.go index 2e0caa5a1d2e..f8c8b7131d43 100644 --- a/azurerm/resource_arm_network_ddos_protection_plan.go +++ b/azurerm/internal/services/network/resource_arm_network_ddos_protection_plan.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -95,8 +95,8 @@ func resourceArmNetworkDDoSProtectionPlanCreateUpdate(d *schema.ResourceData, me locks.ByName(name, azureNetworkDDoSProtectionPlanResourceName) defer locks.UnlockByName(name, azureNetworkDDoSProtectionPlanResourceName) - locks.MultipleByName(vnetsToLock, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnetsToLock, virtualNetworkResourceName) + locks.MultipleByName(vnetsToLock, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(vnetsToLock, VirtualNetworkResourceName) parameters := network.DdosProtectionPlan{ Location: &location, @@ -196,8 +196,8 @@ func resourceArmNetworkDDoSProtectionPlanDelete(d *schema.ResourceData, meta int locks.ByName(name, azureNetworkDDoSProtectionPlanResourceName) defer locks.UnlockByName(name, azureNetworkDDoSProtectionPlanResourceName) - locks.MultipleByName(vnetsToLock, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnetsToLock, virtualNetworkResourceName) + locks.MultipleByName(vnetsToLock, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(vnetsToLock, VirtualNetworkResourceName) future, err := client.Delete(ctx, resourceGroup, name) if err != nil { @@ -223,7 +223,7 @@ func expandArmNetworkDDoSProtectionPlanVnetNames(d *schema.ResourceData) (*[]str vnetName := vnetResourceID.Path["virtualNetworks"] - if !sliceContainsValue(vnetNames, vnetName) { + if !SliceContainsValue(vnetNames, vnetName) { vnetNames = append(vnetNames, vnetName) } } diff --git a/azurerm/resource_arm_network_ddos_protection_plan_test.go b/azurerm/internal/services/network/resource_arm_network_ddos_protection_plan_test.go similarity index 99% rename from azurerm/resource_arm_network_ddos_protection_plan_test.go rename to azurerm/internal/services/network/resource_arm_network_ddos_protection_plan_test.go index a8157184098d..3d8d649fa87d 100644 --- a/azurerm/resource_arm_network_ddos_protection_plan_test.go +++ b/azurerm/internal/services/network/resource_arm_network_ddos_protection_plan_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_interface.go b/azurerm/internal/services/network/resource_arm_network_interface.go similarity index 96% rename from azurerm/resource_arm_network_interface.go rename to azurerm/internal/services/network/resource_arm_network_interface.go index 8a648537a133..5655e5db7bbd 100644 --- a/azurerm/resource_arm_network_interface.go +++ b/azurerm/internal/services/network/resource_arm_network_interface.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -338,11 +338,11 @@ func resourceArmNetworkInterfaceCreateUpdate(d *schema.ResourceData, meta interf return fmt.Errorf("Error Building list of Network Interface IP Configurations: %+v", sgErr) } - locks.MultipleByName(subnetnToLock, subnetResourceName) - defer locks.UnlockMultipleByName(subnetnToLock, subnetResourceName) + locks.MultipleByName(subnetnToLock, SubnetResourceName) + defer locks.UnlockMultipleByName(subnetnToLock, SubnetResourceName) - locks.MultipleByName(vnnToLock, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnnToLock, virtualNetworkResourceName) + locks.MultipleByName(vnnToLock, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(vnnToLock, VirtualNetworkResourceName) if len(ipConfigs) > 0 { properties.IPConfigurations = &ipConfigs @@ -507,22 +507,22 @@ func resourceArmNetworkInterfaceDelete(d *schema.ResourceData, meta interface{}) return err2 } subnetName := subnetId.Path["subnets"] - if !sliceContainsValue(subnetNamesToLock, subnetName) { + if !SliceContainsValue(subnetNamesToLock, subnetName) { subnetNamesToLock = append(subnetNamesToLock, subnetName) } virtualNetworkName := subnetId.Path["virtualNetworks"] - if !sliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { + if !SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { virtualNetworkNamesToLock = append(virtualNetworkNamesToLock, virtualNetworkName) } } } - locks.MultipleByName(&subnetNamesToLock, subnetResourceName) - defer locks.UnlockMultipleByName(&subnetNamesToLock, subnetResourceName) + locks.MultipleByName(&subnetNamesToLock, SubnetResourceName) + defer locks.UnlockMultipleByName(&subnetNamesToLock, SubnetResourceName) - locks.MultipleByName(&virtualNetworkNamesToLock, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(&virtualNetworkNamesToLock, virtualNetworkResourceName) + locks.MultipleByName(&virtualNetworkNamesToLock, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(&virtualNetworkNamesToLock, VirtualNetworkResourceName) future, err := client.Delete(ctx, resGroup, name) if err != nil { @@ -640,11 +640,11 @@ func expandAzureRmNetworkInterfaceIpConfigurations(d *schema.ResourceData) ([]ne subnetName := subnetId.Path["subnets"] virtualNetworkName := subnetId.Path["virtualNetworks"] - if !sliceContainsValue(subnetNamesToLock, subnetName) { + if !SliceContainsValue(subnetNamesToLock, subnetName) { subnetNamesToLock = append(subnetNamesToLock, subnetName) } - if !sliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { + if !SliceContainsValue(virtualNetworkNamesToLock, virtualNetworkName) { virtualNetworkNamesToLock = append(virtualNetworkNamesToLock, virtualNetworkName) } } @@ -751,7 +751,7 @@ func expandAzureRmNetworkInterfaceIpConfigurations(d *schema.ResourceData) ([]ne return ipConfigs, &subnetNamesToLock, &virtualNetworkNamesToLock, nil } -func sliceContainsValue(input []string, value string) bool { +func SliceContainsValue(input []string, value string) bool { for _, v := range input { if v == value { return true diff --git a/azurerm/resource_arm_network_interface_application_gateway_association.go b/azurerm/internal/services/network/resource_arm_network_interface_application_gateway_association.go similarity index 99% rename from azurerm/resource_arm_network_interface_application_gateway_association.go rename to azurerm/internal/services/network/resource_arm_network_interface_application_gateway_association.go index 5fc2bb5dd732..2e0c67bc1bfe 100644 --- a/azurerm/resource_arm_network_interface_application_gateway_association.go +++ b/azurerm/internal/services/network/resource_arm_network_interface_application_gateway_association.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_interface_application_gateway_association_test.go b/azurerm/internal/services/network/resource_arm_network_interface_application_gateway_association_test.go similarity index 99% rename from azurerm/resource_arm_network_interface_application_gateway_association_test.go rename to azurerm/internal/services/network/resource_arm_network_interface_application_gateway_association_test.go index 5ad7444b3353..8885ca152f4b 100644 --- a/azurerm/resource_arm_network_interface_application_gateway_association_test.go +++ b/azurerm/internal/services/network/resource_arm_network_interface_application_gateway_association_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_interface_application_security_group_association.go b/azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association.go similarity index 99% rename from azurerm/resource_arm_network_interface_application_security_group_association.go rename to azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association.go index 3a9c2175ae1e..783c24a98556 100644 --- a/azurerm/resource_arm_network_interface_application_security_group_association.go +++ b/azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_interface_application_security_group_association_test.go b/azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association_test.go similarity index 99% rename from azurerm/resource_arm_network_interface_application_security_group_association_test.go rename to azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association_test.go index 7cd49d99f055..80868d466f11 100644 --- a/azurerm/resource_arm_network_interface_application_security_group_association_test.go +++ b/azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_interface_backend_address_pool_association.go b/azurerm/internal/services/network/resource_arm_network_interface_backend_address_pool_association.go similarity index 99% rename from azurerm/resource_arm_network_interface_backend_address_pool_association.go rename to azurerm/internal/services/network/resource_arm_network_interface_backend_address_pool_association.go index 483b3130826a..f84fa9d0fcca 100644 --- a/azurerm/resource_arm_network_interface_backend_address_pool_association.go +++ b/azurerm/internal/services/network/resource_arm_network_interface_backend_address_pool_association.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_interface_backend_address_pool_association_test.go b/azurerm/internal/services/network/resource_arm_network_interface_backend_address_pool_association_test.go similarity index 99% rename from azurerm/resource_arm_network_interface_backend_address_pool_association_test.go rename to azurerm/internal/services/network/resource_arm_network_interface_backend_address_pool_association_test.go index 6ac3ecc4d527..954d0ce12d03 100644 --- a/azurerm/resource_arm_network_interface_backend_address_pool_association_test.go +++ b/azurerm/internal/services/network/resource_arm_network_interface_backend_address_pool_association_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_interface_nat_rule_association.go b/azurerm/internal/services/network/resource_arm_network_interface_nat_rule_association.go similarity index 99% rename from azurerm/resource_arm_network_interface_nat_rule_association.go rename to azurerm/internal/services/network/resource_arm_network_interface_nat_rule_association.go index 3dc12a0c0c8f..94ad0de91be4 100644 --- a/azurerm/resource_arm_network_interface_nat_rule_association.go +++ b/azurerm/internal/services/network/resource_arm_network_interface_nat_rule_association.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_interface_nat_rule_association_test.go b/azurerm/internal/services/network/resource_arm_network_interface_nat_rule_association_test.go similarity index 99% rename from azurerm/resource_arm_network_interface_nat_rule_association_test.go rename to azurerm/internal/services/network/resource_arm_network_interface_nat_rule_association_test.go index 51ed5fe65a43..0cb6e10f1de7 100644 --- a/azurerm/resource_arm_network_interface_nat_rule_association_test.go +++ b/azurerm/internal/services/network/resource_arm_network_interface_nat_rule_association_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_interface_test.go b/azurerm/internal/services/network/resource_arm_network_interface_test.go similarity index 99% rename from azurerm/resource_arm_network_interface_test.go rename to azurerm/internal/services/network/resource_arm_network_interface_test.go index 638c3a990195..ea9d0884a8ca 100644 --- a/azurerm/resource_arm_network_interface_test.go +++ b/azurerm/internal/services/network/resource_arm_network_interface_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_packet_capture.go b/azurerm/internal/services/network/resource_arm_network_packet_capture.go similarity index 99% rename from azurerm/resource_arm_network_packet_capture.go rename to azurerm/internal/services/network/resource_arm_network_packet_capture.go index fa39d58fa318..ed55a3834ba3 100644 --- a/azurerm/resource_arm_network_packet_capture.go +++ b/azurerm/internal/services/network/resource_arm_network_packet_capture.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_packet_capture_test.go b/azurerm/internal/services/network/resource_arm_network_packet_capture_test.go similarity index 99% rename from azurerm/resource_arm_network_packet_capture_test.go rename to azurerm/internal/services/network/resource_arm_network_packet_capture_test.go index c6f3c6d1dc6c..c057195a61fd 100644 --- a/azurerm/resource_arm_network_packet_capture_test.go +++ b/azurerm/internal/services/network/resource_arm_network_packet_capture_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_profile.go b/azurerm/internal/services/network/resource_arm_network_profile.go similarity index 95% rename from azurerm/resource_arm_network_profile.go rename to azurerm/internal/services/network/resource_arm_network_profile.go index b89feb6409aa..4c4896870941 100644 --- a/azurerm/resource_arm_network_profile.go +++ b/azurerm/internal/services/network/resource_arm_network_profile.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -134,11 +134,11 @@ func resourceArmNetworkProfileCreateUpdate(d *schema.ResourceData, meta interfac locks.ByName(name, azureNetworkProfileResourceName) defer locks.UnlockByName(name, azureNetworkProfileResourceName) - locks.MultipleByName(vnetsToLock, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnetsToLock, virtualNetworkResourceName) + locks.MultipleByName(vnetsToLock, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(vnetsToLock, VirtualNetworkResourceName) - locks.MultipleByName(subnetsToLock, subnetResourceName) - defer locks.UnlockMultipleByName(subnetsToLock, subnetResourceName) + locks.MultipleByName(subnetsToLock, SubnetResourceName) + defer locks.UnlockMultipleByName(subnetsToLock, SubnetResourceName) parameters := network.Profile{ Location: &location, @@ -241,11 +241,11 @@ func resourceArmNetworkProfileDelete(d *schema.ResourceData, meta interface{}) e locks.ByName(name, azureNetworkProfileResourceName) defer locks.UnlockByName(name, azureNetworkProfileResourceName) - locks.MultipleByName(vnetsToLock, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(vnetsToLock, virtualNetworkResourceName) + locks.MultipleByName(vnetsToLock, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(vnetsToLock, VirtualNetworkResourceName) - locks.MultipleByName(subnetsToLock, subnetResourceName) - defer locks.UnlockMultipleByName(subnetsToLock, subnetResourceName) + locks.MultipleByName(subnetsToLock, SubnetResourceName) + defer locks.UnlockMultipleByName(subnetsToLock, SubnetResourceName) if _, err = client.Delete(ctx, resourceGroup, name); err != nil { return fmt.Errorf("Error deleting Network Profile %q (Resource Group %q): %+v", name, resourceGroup, err) @@ -315,11 +315,11 @@ func expandNetworkProfileVirtualNetworkSubnetNames(d *schema.ResourceData) (*[]s subnetName := subnetResourceID.Path["subnets"] vnetName := subnetResourceID.Path["virtualNetworks"] - if !sliceContainsValue(subnetNames, subnetName) { + if !SliceContainsValue(subnetNames, subnetName) { subnetNames = append(subnetNames, subnetName) } - if !sliceContainsValue(vnetNames, vnetName) { + if !SliceContainsValue(vnetNames, vnetName) { vnetNames = append(vnetNames, vnetName) } } diff --git a/azurerm/resource_arm_network_profile_test.go b/azurerm/internal/services/network/resource_arm_network_profile_test.go similarity index 99% rename from azurerm/resource_arm_network_profile_test.go rename to azurerm/internal/services/network/resource_arm_network_profile_test.go index 1b694ae4e247..f6d74dbade57 100644 --- a/azurerm/resource_arm_network_profile_test.go +++ b/azurerm/internal/services/network/resource_arm_network_profile_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_security_group.go b/azurerm/internal/services/network/resource_arm_network_security_group.go similarity index 98% rename from azurerm/resource_arm_network_security_group.go rename to azurerm/internal/services/network/resource_arm_network_security_group.go index 6bb7a73a1daa..b444ce2037fc 100644 --- a/azurerm/resource_arm_network_security_group.go +++ b/azurerm/internal/services/network/resource_arm_network_security_group.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -15,7 +15,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" - networkSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -32,7 +31,7 @@ func resourceArmNetworkSecurityGroup() *schema.Resource { Delete: resourceArmNetworkSecurityGroupDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := networkSvc.ParseNetworkSecurityGroupID(id) + _, err := ParseNetworkSecurityGroupID(id) return err }), @@ -248,7 +247,7 @@ func resourceArmNetworkSecurityGroupRead(d *schema.ResourceData, meta interface{ ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParseNetworkSecurityGroupID(d.Id()) + id, err := ParseNetworkSecurityGroupID(d.Id()) if err != nil { return err } @@ -283,7 +282,7 @@ func resourceArmNetworkSecurityGroupDelete(d *schema.ResourceData, meta interfac ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParseNetworkSecurityGroupID(d.Id()) + id, err := ParseNetworkSecurityGroupID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_network_security_group_test.go b/azurerm/internal/services/network/resource_arm_network_security_group_test.go similarity index 99% rename from azurerm/resource_arm_network_security_group_test.go rename to azurerm/internal/services/network/resource_arm_network_security_group_test.go index 94db22dcd207..6a2e42f9871f 100644 --- a/azurerm/resource_arm_network_security_group_test.go +++ b/azurerm/internal/services/network/resource_arm_network_security_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_security_rule.go b/azurerm/internal/services/network/resource_arm_network_security_rule.go similarity index 99% rename from azurerm/resource_arm_network_security_rule.go rename to azurerm/internal/services/network/resource_arm_network_security_rule.go index db7c8fd42ba0..8ca6e1a092ad 100644 --- a/azurerm/resource_arm_network_security_rule.go +++ b/azurerm/internal/services/network/resource_arm_network_security_rule.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_security_rule_test.go b/azurerm/internal/services/network/resource_arm_network_security_rule_test.go similarity index 99% rename from azurerm/resource_arm_network_security_rule_test.go rename to azurerm/internal/services/network/resource_arm_network_security_rule_test.go index 02c9545c8891..cbfb69c9fd4f 100644 --- a/azurerm/resource_arm_network_security_rule_test.go +++ b/azurerm/internal/services/network/resource_arm_network_security_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_watcher.go b/azurerm/internal/services/network/resource_arm_network_watcher.go similarity index 99% rename from azurerm/resource_arm_network_watcher.go rename to azurerm/internal/services/network/resource_arm_network_watcher.go index da35fce4c0c4..4225676433e9 100644 --- a/azurerm/resource_arm_network_watcher.go +++ b/azurerm/internal/services/network/resource_arm_network_watcher.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_watcher_flow_log.go b/azurerm/internal/services/network/resource_arm_network_watcher_flow_log.go similarity index 99% rename from azurerm/resource_arm_network_watcher_flow_log.go rename to azurerm/internal/services/network/resource_arm_network_watcher_flow_log.go index 380cf057e0d6..9e0e4f819d51 100644 --- a/azurerm/resource_arm_network_watcher_flow_log.go +++ b/azurerm/internal/services/network/resource_arm_network_watcher_flow_log.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_watcher_flow_log_test.go b/azurerm/internal/services/network/resource_arm_network_watcher_flow_log_test.go similarity index 99% rename from azurerm/resource_arm_network_watcher_flow_log_test.go rename to azurerm/internal/services/network/resource_arm_network_watcher_flow_log_test.go index be79177cc4ae..343e6c0ad7b6 100644 --- a/azurerm/resource_arm_network_watcher_flow_log_test.go +++ b/azurerm/internal/services/network/resource_arm_network_watcher_flow_log_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_network_watcher_test.go b/azurerm/internal/services/network/resource_arm_network_watcher_test.go similarity index 99% rename from azurerm/resource_arm_network_watcher_test.go rename to azurerm/internal/services/network/resource_arm_network_watcher_test.go index 404b922d9e35..371730507fa5 100644 --- a/azurerm/resource_arm_network_watcher_test.go +++ b/azurerm/internal/services/network/resource_arm_network_watcher_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_route.go b/azurerm/internal/services/network/resource_arm_route.go similarity index 99% rename from azurerm/resource_arm_route.go rename to azurerm/internal/services/network/resource_arm_route.go index e882f70d9e00..b3fd38cb5f22 100644 --- a/azurerm/resource_arm_route.go +++ b/azurerm/internal/services/network/resource_arm_route.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_route_table.go b/azurerm/internal/services/network/resource_arm_route_table.go similarity index 97% rename from azurerm/resource_arm_route_table.go rename to azurerm/internal/services/network/resource_arm_route_table.go index 6a455ef20094..ca7b38863d14 100644 --- a/azurerm/resource_arm_route_table.go +++ b/azurerm/internal/services/network/resource_arm_route_table.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -15,7 +15,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - networkSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -32,7 +31,7 @@ func resourceArmRouteTable() *schema.Resource { Delete: resourceArmRouteTableDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := networkSvc.ParseRouteTableID(id) + _, err := ParseRouteTableID(id) return err }), @@ -177,7 +176,7 @@ func resourceArmRouteTableRead(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParseRouteTableID(d.Id()) + id, err := ParseRouteTableID(d.Id()) if err != nil { return err } @@ -216,7 +215,7 @@ func resourceArmRouteTableDelete(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParseRouteTableID(d.Id()) + id, err := ParseRouteTableID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_route_table_test.go b/azurerm/internal/services/network/resource_arm_route_table_test.go similarity index 99% rename from azurerm/resource_arm_route_table_test.go rename to azurerm/internal/services/network/resource_arm_route_table_test.go index f2cf69cd246f..c21c42fc841a 100644 --- a/azurerm/resource_arm_route_table_test.go +++ b/azurerm/internal/services/network/resource_arm_route_table_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_route_test.go b/azurerm/internal/services/network/resource_arm_route_test.go similarity index 99% rename from azurerm/resource_arm_route_test.go rename to azurerm/internal/services/network/resource_arm_route_test.go index 5d2dcc499c98..d7f1dfb70109 100644 --- a/azurerm/resource_arm_route_test.go +++ b/azurerm/internal/services/network/resource_arm_route_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_subnet.go b/azurerm/internal/services/network/resource_arm_subnet.go similarity index 95% rename from azurerm/resource_arm_subnet.go rename to azurerm/internal/services/network/resource_arm_subnet.go index 95cea5ff1b79..0445168cd54e 100644 --- a/azurerm/resource_arm_subnet.go +++ b/azurerm/internal/services/network/resource_arm_subnet.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -14,12 +14,11 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" - networksvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -var subnetResourceName = "azurerm_subnet" +var SubnetResourceName = "azurerm_subnet" func resourceArmSubnet() *schema.Resource { return &schema.Resource{ @@ -182,8 +181,8 @@ func resourceArmSubnetCreateUpdate(d *schema.ResourceData, meta interface{}) err addressPrefix := d.Get("address_prefix").(string) - locks.ByName(vnetName, virtualNetworkResourceName) - defer locks.UnlockByName(vnetName, virtualNetworkResourceName) + locks.ByName(vnetName, VirtualNetworkResourceName) + defer locks.UnlockByName(vnetName, VirtualNetworkResourceName) properties := network.SubnetPropertiesFormat{ AddressPrefix: &addressPrefix, @@ -204,7 +203,7 @@ func resourceArmSubnetCreateUpdate(d *schema.ResourceData, meta interface{}) err ID: &nsgId, } - parsedNsgId, err := networksvc.ParseNetworkSecurityGroupID(nsgId) + parsedNsgId, err := ParseNetworkSecurityGroupID(nsgId) if err != nil { return err } @@ -221,7 +220,7 @@ func resourceArmSubnetCreateUpdate(d *schema.ResourceData, meta interface{}) err ID: &rtId, } - parsedRouteTableId, err := networksvc.ParseRouteTableID(rtId) + parsedRouteTableId, err := ParseRouteTableID(rtId) if err != nil { return err } @@ -373,7 +372,7 @@ func resourceArmSubnetDelete(d *schema.ResourceData, meta interface{}) error { if v, ok := d.GetOk("network_security_group_id"); ok { networkSecurityGroupId := v.(string) - parsedNetworkSecurityGroupId, err2 := networksvc.ParseNetworkSecurityGroupID(networkSecurityGroupId) + parsedNetworkSecurityGroupId, err2 := ParseNetworkSecurityGroupID(networkSecurityGroupId) if err2 != nil { return err2 } @@ -384,7 +383,7 @@ func resourceArmSubnetDelete(d *schema.ResourceData, meta interface{}) error { if v, ok := d.GetOk("route_table_id"); ok { rtId := v.(string) - parsedRouteTableId, err2 := networksvc.ParseRouteTableID(rtId) + parsedRouteTableId, err2 := ParseRouteTableID(rtId) if err2 != nil { return err2 } @@ -393,11 +392,11 @@ func resourceArmSubnetDelete(d *schema.ResourceData, meta interface{}) error { defer locks.UnlockByName(parsedRouteTableId.Name, routeTableResourceName) } - locks.ByName(vnetName, virtualNetworkResourceName) - defer locks.UnlockByName(vnetName, virtualNetworkResourceName) + locks.ByName(vnetName, VirtualNetworkResourceName) + defer locks.UnlockByName(vnetName, VirtualNetworkResourceName) - locks.ByName(name, subnetResourceName) - defer locks.UnlockByName(name, subnetResourceName) + locks.ByName(name, SubnetResourceName) + defer locks.UnlockByName(name, SubnetResourceName) future, err := client.Delete(ctx, resGroup, vnetName, name) if err != nil { diff --git a/azurerm/resource_arm_subnet_nat_gateway_association.go b/azurerm/internal/services/network/resource_arm_subnet_nat_gateway_association.go similarity index 95% rename from azurerm/resource_arm_subnet_nat_gateway_association.go rename to azurerm/internal/services/network/resource_arm_subnet_nat_gateway_association.go index 75d942f3956a..229e4fa31433 100644 --- a/azurerm/resource_arm_subnet_nat_gateway_association.go +++ b/azurerm/internal/services/network/resource_arm_subnet_nat_gateway_association.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -75,10 +75,10 @@ func resourceArmSubnetNatGatewayAssociationCreate(d *schema.ResourceData, meta i locks.ByName(gatewayName, natGatewayResourceName) defer locks.UnlockByName(gatewayName, natGatewayResourceName) - locks.ByName(virtualNetworkName, virtualNetworkResourceName) - defer locks.UnlockByName(virtualNetworkName, virtualNetworkResourceName) - locks.ByName(subnetName, subnetResourceName) - defer locks.UnlockByName(subnetName, subnetResourceName) + locks.ByName(virtualNetworkName, VirtualNetworkResourceName) + defer locks.UnlockByName(virtualNetworkName, VirtualNetworkResourceName) + locks.ByName(subnetName, SubnetResourceName) + defer locks.UnlockByName(subnetName, SubnetResourceName) subnet, err := client.Get(ctx, resourceGroup, virtualNetworkName, subnetName, "") if err != nil { @@ -200,8 +200,8 @@ func resourceArmSubnetNatGatewayAssociationDelete(d *schema.ResourceData, meta i gatewayName := parsedGatewayId.Path["natGateways"] locks.ByName(gatewayName, natGatewayResourceName) defer locks.UnlockByName(gatewayName, natGatewayResourceName) - locks.ByName(virtualNetworkName, virtualNetworkResourceName) - defer locks.UnlockByName(virtualNetworkName, virtualNetworkResourceName) + locks.ByName(virtualNetworkName, VirtualNetworkResourceName) + defer locks.UnlockByName(virtualNetworkName, VirtualNetworkResourceName) // ensure we get the latest state subnet, err = client.Get(ctx, resourceGroup, virtualNetworkName, subnetName, "") diff --git a/azurerm/resource_arm_subnet_nat_gateway_association_test.go b/azurerm/internal/services/network/resource_arm_subnet_nat_gateway_association_test.go similarity index 99% rename from azurerm/resource_arm_subnet_nat_gateway_association_test.go rename to azurerm/internal/services/network/resource_arm_subnet_nat_gateway_association_test.go index 8069ea633c66..e5aec432bdb0 100644 --- a/azurerm/resource_arm_subnet_nat_gateway_association_test.go +++ b/azurerm/internal/services/network/resource_arm_subnet_nat_gateway_association_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_subnet_network_security_group_association.go b/azurerm/internal/services/network/resource_arm_subnet_network_security_group_association.go similarity index 91% rename from azurerm/resource_arm_subnet_network_security_group_association.go rename to azurerm/internal/services/network/resource_arm_subnet_network_security_group_association.go index d5fd47474518..ad8c463779e1 100644 --- a/azurerm/resource_arm_subnet_network_security_group_association.go +++ b/azurerm/internal/services/network/resource_arm_subnet_network_security_group_association.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -12,7 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" - networkSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -66,7 +65,7 @@ func resourceArmSubnetNetworkSecurityGroupAssociationCreate(d *schema.ResourceDa return err } - parsedNetworkSecurityGroupId, err := networkSvc.ParseNetworkSecurityGroupID(networkSecurityGroupId) + parsedNetworkSecurityGroupId, err := ParseNetworkSecurityGroupID(networkSecurityGroupId) if err != nil { return err } @@ -78,11 +77,11 @@ func resourceArmSubnetNetworkSecurityGroupAssociationCreate(d *schema.ResourceDa virtualNetworkName := parsedSubnetId.Path["virtualNetworks"] resourceGroup := parsedSubnetId.ResourceGroup - locks.ByName(subnetName, subnetResourceName) - defer locks.UnlockByName(subnetName, subnetResourceName) + locks.ByName(subnetName, SubnetResourceName) + defer locks.UnlockByName(subnetName, SubnetResourceName) - locks.ByName(virtualNetworkName, virtualNetworkResourceName) - defer locks.UnlockByName(virtualNetworkName, virtualNetworkResourceName) + locks.ByName(virtualNetworkName, VirtualNetworkResourceName) + defer locks.UnlockByName(virtualNetworkName, VirtualNetworkResourceName) subnet, err := client.Get(ctx, resourceGroup, virtualNetworkName, subnetName, "") if err != nil { @@ -204,7 +203,7 @@ func resourceArmSubnetNetworkSecurityGroupAssociationDelete(d *schema.ResourceDa } // once we have the network security group id to lock on, lock on that - parsedNetworkSecurityGroupId, err := networkSvc.ParseNetworkSecurityGroupID(*props.NetworkSecurityGroup.ID) + parsedNetworkSecurityGroupId, err := ParseNetworkSecurityGroupID(*props.NetworkSecurityGroup.ID) if err != nil { return err } @@ -212,11 +211,11 @@ func resourceArmSubnetNetworkSecurityGroupAssociationDelete(d *schema.ResourceDa locks.ByName(parsedNetworkSecurityGroupId.Name, networkSecurityGroupResourceName) defer locks.UnlockByName(parsedNetworkSecurityGroupId.Name, networkSecurityGroupResourceName) - locks.ByName(virtualNetworkName, virtualNetworkResourceName) - defer locks.UnlockByName(virtualNetworkName, virtualNetworkResourceName) + locks.ByName(virtualNetworkName, VirtualNetworkResourceName) + defer locks.UnlockByName(virtualNetworkName, VirtualNetworkResourceName) - locks.ByName(subnetName, subnetResourceName) - defer locks.UnlockByName(subnetName, subnetResourceName) + locks.ByName(subnetName, SubnetResourceName) + defer locks.UnlockByName(subnetName, SubnetResourceName) // then re-retrieve it to ensure we've got the latest state read, err = client.Get(ctx, resourceGroup, virtualNetworkName, subnetName, "") diff --git a/azurerm/resource_arm_subnet_network_security_group_association_test.go b/azurerm/internal/services/network/resource_arm_subnet_network_security_group_association_test.go similarity index 99% rename from azurerm/resource_arm_subnet_network_security_group_association_test.go rename to azurerm/internal/services/network/resource_arm_subnet_network_security_group_association_test.go index f3fbe0a7ec5d..0bfd42b33e89 100644 --- a/azurerm/resource_arm_subnet_network_security_group_association_test.go +++ b/azurerm/internal/services/network/resource_arm_subnet_network_security_group_association_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_subnet_route_table_association.go b/azurerm/internal/services/network/resource_arm_subnet_route_table_association.go similarity index 94% rename from azurerm/resource_arm_subnet_route_table_association.go rename to azurerm/internal/services/network/resource_arm_subnet_route_table_association.go index 2e9c432bd812..c2e4f42c216a 100644 --- a/azurerm/resource_arm_subnet_route_table_association.go +++ b/azurerm/internal/services/network/resource_arm_subnet_route_table_association.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -12,7 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" - networkSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -66,7 +65,7 @@ func resourceArmSubnetRouteTableAssociationCreate(d *schema.ResourceData, meta i return err } - parsedRouteTableId, err := networkSvc.ParseRouteTableID(routeTableId) + parsedRouteTableId, err := ParseRouteTableID(routeTableId) if err != nil { return err } @@ -78,8 +77,8 @@ func resourceArmSubnetRouteTableAssociationCreate(d *schema.ResourceData, meta i virtualNetworkName := parsedSubnetId.Path["virtualNetworks"] resourceGroup := parsedSubnetId.ResourceGroup - locks.ByName(virtualNetworkName, virtualNetworkResourceName) - defer locks.UnlockByName(virtualNetworkName, virtualNetworkResourceName) + locks.ByName(virtualNetworkName, VirtualNetworkResourceName) + defer locks.UnlockByName(virtualNetworkName, VirtualNetworkResourceName) subnet, err := client.Get(ctx, resourceGroup, virtualNetworkName, subnetName, "") if err != nil { @@ -201,7 +200,7 @@ func resourceArmSubnetRouteTableAssociationDelete(d *schema.ResourceData, meta i } // once we have the route table id to lock on, lock on that - parsedRouteTableId, err := networkSvc.ParseRouteTableID(*props.RouteTable.ID) + parsedRouteTableId, err := ParseRouteTableID(*props.RouteTable.ID) if err != nil { return err } @@ -209,8 +208,8 @@ func resourceArmSubnetRouteTableAssociationDelete(d *schema.ResourceData, meta i locks.ByName(parsedRouteTableId.Name, routeTableResourceName) defer locks.UnlockByName(parsedRouteTableId.Name, routeTableResourceName) - locks.ByName(virtualNetworkName, virtualNetworkResourceName) - defer locks.UnlockByName(virtualNetworkName, virtualNetworkResourceName) + locks.ByName(virtualNetworkName, VirtualNetworkResourceName) + defer locks.UnlockByName(virtualNetworkName, VirtualNetworkResourceName) // then re-retrieve it to ensure we've got the latest state read, err = client.Get(ctx, resourceGroup, virtualNetworkName, subnetName, "") diff --git a/azurerm/resource_arm_subnet_route_table_association_test.go b/azurerm/internal/services/network/resource_arm_subnet_route_table_association_test.go similarity index 99% rename from azurerm/resource_arm_subnet_route_table_association_test.go rename to azurerm/internal/services/network/resource_arm_subnet_route_table_association_test.go index 5e603c24fa8a..fbe97c24f9fc 100644 --- a/azurerm/resource_arm_subnet_route_table_association_test.go +++ b/azurerm/internal/services/network/resource_arm_subnet_route_table_association_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_subnet_test.go b/azurerm/internal/services/network/resource_arm_subnet_test.go similarity index 99% rename from azurerm/resource_arm_subnet_test.go rename to azurerm/internal/services/network/resource_arm_subnet_test.go index d38c48159b48..54729a0124fc 100644 --- a/azurerm/resource_arm_subnet_test.go +++ b/azurerm/internal/services/network/resource_arm_subnet_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_virtual_hub.go b/azurerm/internal/services/network/resource_arm_virtual_hub.go similarity index 96% rename from azurerm/resource_arm_virtual_hub.go rename to azurerm/internal/services/network/resource_arm_virtual_hub.go index 15c7a9dab195..2986f3186279 100644 --- a/azurerm/resource_arm_virtual_hub.go +++ b/azurerm/internal/services/network/resource_arm_virtual_hub.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" - aznetwork "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -45,7 +44,7 @@ func resourceArmVirtualHub() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznetwork.ValidateVirtualHubName, + ValidateFunc: ValidateVirtualHubName, }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -159,7 +158,7 @@ func resourceArmVirtualHubRead(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := aznetwork.ParseVirtualHubID(d.Id()) + id, err := ParseVirtualHubID(d.Id()) if err != nil { return err } @@ -201,7 +200,7 @@ func resourceArmVirtualHubDelete(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := aznetwork.ParseVirtualHubID(d.Id()) + id, err := ParseVirtualHubID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_virtual_hub_test.go b/azurerm/internal/services/network/resource_arm_virtual_hub_test.go similarity index 99% rename from azurerm/resource_arm_virtual_hub_test.go rename to azurerm/internal/services/network/resource_arm_virtual_hub_test.go index b2b6aaee62cb..7a069591b37b 100644 --- a/azurerm/resource_arm_virtual_hub_test.go +++ b/azurerm/internal/services/network/resource_arm_virtual_hub_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_virtual_network.go b/azurerm/internal/services/network/resource_arm_virtual_network.go similarity index 97% rename from azurerm/resource_arm_virtual_network.go rename to azurerm/internal/services/network/resource_arm_virtual_network.go index 888c697f9bce..f90e79f1b1a8 100644 --- a/azurerm/resource_arm_virtual_network.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "bytes" @@ -23,7 +23,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -var virtualNetworkResourceName = "azurerm_virtual_network" +var VirtualNetworkResourceName = "azurerm_virtual_network" func resourceArmVirtualNetwork() *schema.Resource { return &schema.Resource{ @@ -178,7 +178,7 @@ func resourceArmVirtualNetworkCreateUpdate(d *schema.ResourceData, meta interfac networkSecurityGroupName := parsedNsgID.Path["networkSecurityGroups"] - if !sliceContainsValue(networkSecurityGroupNames, networkSecurityGroupName) { + if !SliceContainsValue(networkSecurityGroupNames, networkSecurityGroupName) { networkSecurityGroupNames = append(networkSecurityGroupNames, networkSecurityGroupName) } } @@ -274,8 +274,8 @@ func resourceArmVirtualNetworkDelete(d *schema.ResourceData, meta interface{}) e return fmt.Errorf("Error parsing Network Security Group ID's: %+v", err) } - locks.MultipleByName(&nsgNames, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(&nsgNames, virtualNetworkResourceName) + locks.MultipleByName(&nsgNames, VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(&nsgNames, VirtualNetworkResourceName) future, err := client.Delete(ctx, resGroup, name) if err != nil { @@ -480,7 +480,7 @@ func expandAzureRmVirtualNetworkVirtualNetworkSecurityGroupNames(d *schema.Resou networkSecurityGroupName := parsedNsgID.Path["networkSecurityGroups"] - if !sliceContainsValue(nsgNames, networkSecurityGroupName) { + if !SliceContainsValue(nsgNames, networkSecurityGroupName) { nsgNames = append(nsgNames, networkSecurityGroupName) } } diff --git a/azurerm/resource_arm_virtual_network_gateway.go b/azurerm/internal/services/network/resource_arm_virtual_network_gateway.go similarity index 99% rename from azurerm/resource_arm_virtual_network_gateway.go rename to azurerm/internal/services/network/resource_arm_virtual_network_gateway.go index 5817b327535a..823d48b0c571 100644 --- a/azurerm/resource_arm_virtual_network_gateway.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network_gateway.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "bytes" diff --git a/azurerm/resource_arm_virtual_network_gateway_connection.go b/azurerm/internal/services/network/resource_arm_virtual_network_gateway_connection.go similarity index 99% rename from azurerm/resource_arm_virtual_network_gateway_connection.go rename to azurerm/internal/services/network/resource_arm_virtual_network_gateway_connection.go index ed4e4bcf3686..d62689b306ba 100644 --- a/azurerm/resource_arm_virtual_network_gateway_connection.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network_gateway_connection.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_virtual_network_gateway_connection_test.go b/azurerm/internal/services/network/resource_arm_virtual_network_gateway_connection_test.go similarity index 99% rename from azurerm/resource_arm_virtual_network_gateway_connection_test.go rename to azurerm/internal/services/network/resource_arm_virtual_network_gateway_connection_test.go index c0585b988dc2..3f1213c4eb0a 100644 --- a/azurerm/resource_arm_virtual_network_gateway_connection_test.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network_gateway_connection_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_virtual_network_gateway_test.go b/azurerm/internal/services/network/resource_arm_virtual_network_gateway_test.go similarity index 99% rename from azurerm/resource_arm_virtual_network_gateway_test.go rename to azurerm/internal/services/network/resource_arm_virtual_network_gateway_test.go index 05d2e742a86b..9514b264f7d6 100644 --- a/azurerm/resource_arm_virtual_network_gateway_test.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network_gateway_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_virtual_network_peering.go b/azurerm/internal/services/network/resource_arm_virtual_network_peering.go similarity index 99% rename from azurerm/resource_arm_virtual_network_peering.go rename to azurerm/internal/services/network/resource_arm_virtual_network_peering.go index af95a58477dc..43f796abd089 100644 --- a/azurerm/resource_arm_virtual_network_peering.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network_peering.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_virtual_network_peering_test.go b/azurerm/internal/services/network/resource_arm_virtual_network_peering_test.go similarity index 99% rename from azurerm/resource_arm_virtual_network_peering_test.go rename to azurerm/internal/services/network/resource_arm_virtual_network_peering_test.go index 131cfdca7b14..e9f4e2fa1b21 100644 --- a/azurerm/resource_arm_virtual_network_peering_test.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network_peering_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_virtual_network_test.go b/azurerm/internal/services/network/resource_arm_virtual_network_test.go similarity index 99% rename from azurerm/resource_arm_virtual_network_test.go rename to azurerm/internal/services/network/resource_arm_virtual_network_test.go index cffe37dbe567..7dbb97caf088 100644 --- a/azurerm/resource_arm_virtual_network_test.go +++ b/azurerm/internal/services/network/resource_arm_virtual_network_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_virtual_wan.go b/azurerm/internal/services/network/resource_arm_virtual_wan.go similarity index 97% rename from azurerm/resource_arm_virtual_wan.go rename to azurerm/internal/services/network/resource_arm_virtual_wan.go index 82659cab486d..13aca8ff6fc3 100644 --- a/azurerm/resource_arm_virtual_wan.go +++ b/azurerm/internal/services/network/resource_arm_virtual_wan.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - networkSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -159,7 +158,7 @@ func resourceArmVirtualWanRead(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParseVirtualWanID(d.Id()) + id, err := ParseVirtualWanID(d.Id()) if err != nil { return err } @@ -196,7 +195,7 @@ func resourceArmVirtualWanDelete(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParseVirtualWanID(d.Id()) + id, err := ParseVirtualWanID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_virtual_wan_test.go b/azurerm/internal/services/network/resource_arm_virtual_wan_test.go similarity index 99% rename from azurerm/resource_arm_virtual_wan_test.go rename to azurerm/internal/services/network/resource_arm_virtual_wan_test.go index e5cbfb209789..f346e51b8c26 100644 --- a/azurerm/resource_arm_virtual_wan_test.go +++ b/azurerm/internal/services/network/resource_arm_virtual_wan_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_vpn_gateway.go b/azurerm/internal/services/network/resource_arm_vpn_gateway.go similarity index 97% rename from azurerm/resource_arm_vpn_gateway.go rename to azurerm/internal/services/network/resource_arm_vpn_gateway.go index a90c7e6cf715..16a6b60e2282 100644 --- a/azurerm/resource_arm_vpn_gateway.go +++ b/azurerm/internal/services/network/resource_arm_vpn_gateway.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "context" @@ -16,7 +16,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - networkSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -54,7 +53,7 @@ func resourceArmVPNGateway() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: networkSvc.ValidateVirtualHubID, + ValidateFunc: ValidateVirtualHubID, }, "bgp_settings": { @@ -179,7 +178,7 @@ func resourceArmVPNGatewayRead(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParseVPNGatewayID(d.Id()) + id, err := ParseVPNGatewayID(d.Id()) if err != nil { return err } @@ -227,7 +226,7 @@ func resourceArmVPNGatewayDelete(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParseVPNGatewayID(d.Id()) + id, err := ParseVPNGatewayID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_vpn_gateway_test.go b/azurerm/internal/services/network/resource_arm_vpn_gateway_test.go similarity index 99% rename from azurerm/resource_arm_vpn_gateway_test.go rename to azurerm/internal/services/network/resource_arm_vpn_gateway_test.go index 3207aa4a3b26..89c7dedbe5ab 100644 --- a/azurerm/resource_arm_vpn_gateway_test.go +++ b/azurerm/internal/services/network/resource_arm_vpn_gateway_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_vpn_server_configuration.go b/azurerm/internal/services/network/resource_arm_vpn_server_configuration.go similarity index 99% rename from azurerm/resource_arm_vpn_server_configuration.go rename to azurerm/internal/services/network/resource_arm_vpn_server_configuration.go index 696c1310fbfc..fe227943e501 100644 --- a/azurerm/resource_arm_vpn_server_configuration.go +++ b/azurerm/internal/services/network/resource_arm_vpn_server_configuration.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -13,7 +13,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - networkSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -433,7 +432,7 @@ func resourceArmVPNServerConfigurationRead(d *schema.ResourceData, meta interfac ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParseVpnServerConfigurationID(d.Id()) + id, err := ParseVpnServerConfigurationID(d.Id()) if err != nil { return err } @@ -506,7 +505,7 @@ func resourceArmVPNServerConfigurationDelete(d *schema.ResourceData, meta interf ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParseVpnServerConfigurationID(d.Id()) + id, err := ParseVpnServerConfigurationID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_vpn_server_configuration_test.go b/azurerm/internal/services/network/resource_arm_vpn_server_configuration_test.go similarity index 99% rename from azurerm/resource_arm_vpn_server_configuration_test.go rename to azurerm/internal/services/network/resource_arm_vpn_server_configuration_test.go index 1e626611538c..85dd5496a74d 100644 --- a/azurerm/resource_arm_vpn_server_configuration_test.go +++ b/azurerm/internal/services/network/resource_arm_vpn_server_configuration_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_web_application_firewall_policy.go b/azurerm/internal/services/network/resource_arm_web_application_firewall_policy.go similarity index 99% rename from azurerm/resource_arm_web_application_firewall_policy.go rename to azurerm/internal/services/network/resource_arm_web_application_firewall_policy.go index aa2ce5bbe21c..07c01acc10aa 100644 --- a/azurerm/resource_arm_web_application_firewall_policy.go +++ b/azurerm/internal/services/network/resource_arm_web_application_firewall_policy.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_web_application_firewall_policy_test.go b/azurerm/internal/services/network/resource_arm_web_application_firewall_policy_test.go similarity index 99% rename from azurerm/resource_arm_web_application_firewall_policy_test.go rename to azurerm/internal/services/network/resource_arm_web_application_firewall_policy_test.go index 674cd82a8175..d87ea3e9b6ce 100644 --- a/azurerm/resource_arm_web_application_firewall_policy_test.go +++ b/azurerm/internal/services/network/resource_arm_web_application_firewall_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index b3775928ba7f..4c624b5f91ea 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -16,7 +16,6 @@ func Provider() terraform.ResourceProvider { "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), - "azurerm_firewall": dataSourceArmFirewall(), "azurerm_image": dataSourceArmImage(), "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), @@ -25,11 +24,6 @@ func Provider() terraform.ResourceProvider { "azurerm_lb": dataSourceArmLoadBalancer(), "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), - "azurerm_nat_gateway": dataSourceArmNatGateway(), - "azurerm_network_ddos_protection_plan": dataSourceNetworkDDoSProtectionPlan(), - "azurerm_network_interface": dataSourceArmNetworkInterface(), - "azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(), - "azurerm_network_watcher": dataSourceArmNetworkWatcher(), "azurerm_notification_hub_namespace": dataSourceNotificationHubNamespace(), "azurerm_notification_hub": dataSourceNotificationHub(), "azurerm_platform_image": dataSourceArmPlatformImage(), @@ -48,7 +42,6 @@ func Provider() terraform.ResourceProvider { "azurerm_redis_cache": dataSourceArmRedisCache(), "azurerm_resources": dataSourceArmResources(), "azurerm_resource_group": dataSourceArmResourceGroup(), - "azurerm_route_table": dataSourceArmRouteTable(), "azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(), "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), "azurerm_servicebus_namespace_authorization_rule": dataSourceArmServiceBusNamespaceAuthorizationRule(), @@ -59,15 +52,9 @@ func Provider() terraform.ResourceProvider { "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), "azurerm_storage_account": dataSourceArmStorageAccount(), "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), - "azurerm_subnet": dataSourceArmSubnet(), "azurerm_subscription": dataSourceArmSubscription(), "azurerm_subscriptions": dataSourceArmSubscriptions(), "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), - "azurerm_virtual_hub": dataSourceArmVirtualHub(), - "azurerm_virtual_machine": dataSourceArmVirtualMachine(), - "azurerm_virtual_network_gateway": dataSourceArmVirtualNetworkGateway(), - "azurerm_virtual_network_gateway_connection": dataSourceArmVirtualNetworkGatewayConnection(), - "azurerm_virtual_network": dataSourceArmVirtualNetwork(), } resources := map[string]*schema.Resource{ @@ -92,14 +79,9 @@ func Provider() terraform.ResourceProvider { "azurerm_bastion_host": resourceArmBastionHost(), "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_dashboard": resourceArmDashboard(), - "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), - "azurerm_firewall_application_rule_collection": resourceArmFirewallApplicationRuleCollection(), - "azurerm_firewall_nat_rule_collection": resourceArmFirewallNatRuleCollection(), - "azurerm_firewall_network_rule_collection": resourceArmFirewallNetworkRuleCollection(), - "azurerm_firewall": resourceArmFirewall(), "azurerm_function_app": resourceArmFunctionApp(), "azurerm_image": resourceArmImage(), "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), @@ -114,140 +96,110 @@ func Provider() terraform.ResourceProvider { "azurerm_lb_outbound_rule": resourceArmLoadBalancerOutboundRule(), "azurerm_lb_rule": resourceArmLoadBalancerRule(), "azurerm_lb": resourceArmLoadBalancer(), - "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), "azurerm_management_lock": resourceArmManagementLock(), "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), "azurerm_mssql_elasticpool": resourceArmMsSqlElasticPool(), "azurerm_mssql_database_vulnerability_assessment_rule_baseline": resourceArmMssqlDatabaseVulnerabilityAssessmentRuleBaseline(), "azurerm_mssql_server_security_alert_policy": resourceArmMssqlServerSecurityAlertPolicy(), "azurerm_mssql_server_vulnerability_assessment": resourceArmMssqlServerVulnerabilityAssessment(), - "azurerm_nat_gateway": resourceArmNatGateway(), - "azurerm_network_connection_monitor": resourceArmNetworkConnectionMonitor(), - "azurerm_network_ddos_protection_plan": resourceArmNetworkDDoSProtectionPlan(), - "azurerm_network_interface": resourceArmNetworkInterface(), - "azurerm_network_interface_application_gateway_backend_address_pool_association": resourceArmNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation(), - "azurerm_network_interface_application_security_group_association": resourceArmNetworkInterfaceApplicationSecurityGroupAssociation(), - "azurerm_network_interface_backend_address_pool_association": resourceArmNetworkInterfaceBackendAddressPoolAssociation(), - "azurerm_network_interface_nat_rule_association": resourceArmNetworkInterfaceNatRuleAssociation(), - "azurerm_network_packet_capture": resourceArmNetworkPacketCapture(), - "azurerm_network_profile": resourceArmNetworkProfile(), - "azurerm_network_security_group": resourceArmNetworkSecurityGroup(), - "azurerm_network_security_rule": resourceArmNetworkSecurityRule(), - "azurerm_network_watcher_flow_log": resourceArmNetworkWatcherFlowLog(), - "azurerm_network_watcher": resourceArmNetworkWatcher(), - "azurerm_notification_hub_authorization_rule": resourceArmNotificationHubAuthorizationRule(), - "azurerm_notification_hub_namespace": resourceArmNotificationHubNamespace(), - "azurerm_notification_hub": resourceArmNotificationHub(), - "azurerm_packet_capture": resourceArmPacketCapture(), - "azurerm_policy_assignment": resourceArmPolicyAssignment(), - "azurerm_policy_definition": resourceArmPolicyDefinition(), - "azurerm_policy_set_definition": resourceArmPolicySetDefinition(), - "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), - "azurerm_postgresql_configuration": resourceArmPostgreSQLConfiguration(), - "azurerm_postgresql_database": resourceArmPostgreSQLDatabase(), - "azurerm_postgresql_firewall_rule": resourceArmPostgreSQLFirewallRule(), - "azurerm_postgresql_server": resourceArmPostgreSQLServer(), - "azurerm_postgresql_virtual_network_rule": resourceArmPostgreSQLVirtualNetworkRule(), - "azurerm_private_dns_zone": resourceArmPrivateDnsZone(), - "azurerm_private_dns_a_record": resourceArmPrivateDnsARecord(), - "azurerm_private_dns_aaaa_record": resourceArmPrivateDnsAaaaRecord(), - "azurerm_private_dns_cname_record": resourceArmPrivateDnsCNameRecord(), - "azurerm_private_dns_mx_record": resourceArmPrivateDnsMxRecord(), - "azurerm_private_dns_ptr_record": resourceArmPrivateDnsPtrRecord(), - "azurerm_private_dns_srv_record": resourceArmPrivateDnsSrvRecord(), - "azurerm_private_dns_zone_virtual_network_link": resourceArmPrivateDnsZoneVirtualNetworkLink(), - "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), - "azurerm_private_endpoint": resourceArmPrivateEndpoint(), - "azurerm_private_link_service": resourceArmPrivateLinkService(), - "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), - "azurerm_public_ip": resourceArmPublicIp(), - "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), - "azurerm_recovery_network_mapping": resourceArmRecoveryServicesNetworkMapping(), - "azurerm_recovery_replicated_vm": resourceArmRecoveryServicesReplicatedVm(), - "azurerm_recovery_services_fabric": resourceArmRecoveryServicesFabric(), - "azurerm_recovery_services_protected_vm": resourceArmRecoveryServicesProtectedVm(), - "azurerm_recovery_services_protection_container": resourceArmRecoveryServicesProtectionContainer(), - "azurerm_recovery_services_protection_container_mapping": resourceArmRecoveryServicesProtectionContainerMapping(), - "azurerm_recovery_services_protection_policy_vm": resourceArmRecoveryServicesProtectionPolicyVm(), - "azurerm_recovery_services_replication_policy": resourceArmRecoveryServicesReplicationPolicy(), - "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), - "azurerm_redis_cache": resourceArmRedisCache(), - "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), - "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), - "azurerm_relay_namespace": resourceArmRelayNamespace(), - "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_route_table": resourceArmRouteTable(), - "azurerm_route": resourceArmRoute(), - "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), - "azurerm_scheduler_job": resourceArmSchedulerJob(), - "azurerm_search_service": resourceArmSearchService(), - "azurerm_security_center_contact": resourceArmSecurityCenterContact(), - "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), - "azurerm_security_center_workspace": resourceArmSecurityCenterWorkspace(), - "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), - "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), - "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), - "azurerm_servicebus_queue": resourceArmServiceBusQueue(), - "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), - "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), - "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), - "azurerm_servicebus_topic": resourceArmServiceBusTopic(), - "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), - "azurerm_shared_image_version": resourceArmSharedImageVersion(), - "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_signalr_service": resourceArmSignalRService(), - "azurerm_site_recovery_fabric": resourceArmSiteRecoveryFabric(), - "azurerm_site_recovery_network_mapping": resourceArmSiteRecoveryNetworkMapping(), - "azurerm_site_recovery_protection_container": resourceArmSiteRecoveryProtectionContainer(), - "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), - "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), - "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), - "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), - "azurerm_sql_database": resourceArmSqlDatabase(), - "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), - "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), - "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), - "azurerm_sql_server": resourceArmSqlServer(), - "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), - "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_storage_table_entity": resourceArmStorageTableEntity(), - "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), - "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), - "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), - "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), - "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), - "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), - "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), - "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), - "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), - "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), - "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), - "azurerm_subnet_network_security_group_association": resourceArmSubnetNetworkSecurityGroupAssociation(), - "azurerm_subnet_route_table_association": resourceArmSubnetRouteTableAssociation(), - "azurerm_subnet_nat_gateway_association": resourceArmSubnetNatGatewayAssociation(), - "azurerm_subnet": resourceArmSubnet(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), - "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), - "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), - "azurerm_virtual_hub": resourceArmVirtualHub(), - "azurerm_virtual_network_gateway_connection": resourceArmVirtualNetworkGatewayConnection(), - "azurerm_virtual_network_gateway": resourceArmVirtualNetworkGateway(), - "azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(), - "azurerm_virtual_network": resourceArmVirtualNetwork(), - "azurerm_virtual_wan": resourceArmVirtualWan(), - "azurerm_vpn_gateway": resourceArmVPNGateway(), - "azurerm_vpn_server_configuration": resourceArmVPNServerConfiguration(), - "azurerm_web_application_firewall_policy": resourceArmWebApplicationFirewallPolicy(), + "azurerm_notification_hub_authorization_rule": resourceArmNotificationHubAuthorizationRule(), + "azurerm_notification_hub_namespace": resourceArmNotificationHubNamespace(), + "azurerm_notification_hub": resourceArmNotificationHub(), + "azurerm_packet_capture": resourceArmPacketCapture(), + "azurerm_policy_assignment": resourceArmPolicyAssignment(), + "azurerm_policy_definition": resourceArmPolicyDefinition(), + "azurerm_policy_set_definition": resourceArmPolicySetDefinition(), + "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), + "azurerm_postgresql_configuration": resourceArmPostgreSQLConfiguration(), + "azurerm_postgresql_database": resourceArmPostgreSQLDatabase(), + "azurerm_postgresql_firewall_rule": resourceArmPostgreSQLFirewallRule(), + "azurerm_postgresql_server": resourceArmPostgreSQLServer(), + "azurerm_postgresql_virtual_network_rule": resourceArmPostgreSQLVirtualNetworkRule(), + "azurerm_private_dns_zone": resourceArmPrivateDnsZone(), + "azurerm_private_dns_a_record": resourceArmPrivateDnsARecord(), + "azurerm_private_dns_aaaa_record": resourceArmPrivateDnsAaaaRecord(), + "azurerm_private_dns_cname_record": resourceArmPrivateDnsCNameRecord(), + "azurerm_private_dns_mx_record": resourceArmPrivateDnsMxRecord(), + "azurerm_private_dns_ptr_record": resourceArmPrivateDnsPtrRecord(), + "azurerm_private_dns_srv_record": resourceArmPrivateDnsSrvRecord(), + "azurerm_private_dns_zone_virtual_network_link": resourceArmPrivateDnsZoneVirtualNetworkLink(), + "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), + "azurerm_private_endpoint": resourceArmPrivateEndpoint(), + "azurerm_private_link_service": resourceArmPrivateLinkService(), + "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), + "azurerm_public_ip": resourceArmPublicIp(), + "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), + "azurerm_recovery_network_mapping": resourceArmRecoveryServicesNetworkMapping(), + "azurerm_recovery_replicated_vm": resourceArmRecoveryServicesReplicatedVm(), + "azurerm_recovery_services_fabric": resourceArmRecoveryServicesFabric(), + "azurerm_recovery_services_protected_vm": resourceArmRecoveryServicesProtectedVm(), + "azurerm_recovery_services_protection_container": resourceArmRecoveryServicesProtectionContainer(), + "azurerm_recovery_services_protection_container_mapping": resourceArmRecoveryServicesProtectionContainerMapping(), + "azurerm_recovery_services_protection_policy_vm": resourceArmRecoveryServicesProtectionPolicyVm(), + "azurerm_recovery_services_replication_policy": resourceArmRecoveryServicesReplicationPolicy(), + "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), + "azurerm_redis_cache": resourceArmRedisCache(), + "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), + "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), + "azurerm_relay_namespace": resourceArmRelayNamespace(), + "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), + "azurerm_scheduler_job": resourceArmSchedulerJob(), + "azurerm_search_service": resourceArmSearchService(), + "azurerm_security_center_contact": resourceArmSecurityCenterContact(), + "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), + "azurerm_security_center_workspace": resourceArmSecurityCenterWorkspace(), + "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), + "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), + "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), + "azurerm_servicebus_queue": resourceArmServiceBusQueue(), + "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), + "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), + "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), + "azurerm_servicebus_topic": resourceArmServiceBusTopic(), + "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), + "azurerm_shared_image_version": resourceArmSharedImageVersion(), + "azurerm_shared_image": resourceArmSharedImage(), + "azurerm_signalr_service": resourceArmSignalRService(), + "azurerm_site_recovery_fabric": resourceArmSiteRecoveryFabric(), + "azurerm_site_recovery_network_mapping": resourceArmSiteRecoveryNetworkMapping(), + "azurerm_site_recovery_protection_container": resourceArmSiteRecoveryProtectionContainer(), + "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), + "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), + "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), + "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), + "azurerm_sql_database": resourceArmSqlDatabase(), + "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), + "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), + "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), + "azurerm_sql_server": resourceArmSqlServer(), + "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), + "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_storage_table_entity": resourceArmStorageTableEntity(), + "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), + "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), + "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), + "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), + "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), + "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), + "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), + "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), + "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), + "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), + "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), + "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), } return provider.AzureProvider(dataSources, resources) diff --git a/azurerm/resource_arm_app_service_virtual_network_association.go b/azurerm/resource_arm_app_service_virtual_network_association.go index 329c00fe701a..08a78d32a5ad 100644 --- a/azurerm/resource_arm_app_service_virtual_network_association.go +++ b/azurerm/resource_arm_app_service_virtual_network_association.go @@ -2,6 +2,7 @@ package azurerm import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "time" "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web" @@ -65,11 +66,11 @@ func resourceArmAppServiceVirtualNetworkSwiftConnectionCreateUpdate(d *schema.Re subnetName := subnetID.Path["subnets"] virtualNetworkName := subnetID.Path["virtualNetworks"] - locks.ByName(virtualNetworkName, virtualNetworkResourceName) - defer locks.UnlockByName(virtualNetworkName, virtualNetworkResourceName) + locks.ByName(virtualNetworkName, network.VirtualNetworkResourceName) + defer locks.UnlockByName(virtualNetworkName, network.VirtualNetworkResourceName) - locks.ByName(subnetName, subnetResourceName) - defer locks.UnlockByName(subnetName, subnetResourceName) + locks.ByName(subnetName, network.SubnetResourceName) + defer locks.UnlockByName(subnetName, network.SubnetResourceName) exists, err := client.Get(ctx, resourceGroup, name) if err != nil { @@ -158,11 +159,11 @@ func resourceArmAppServiceVirtualNetworkSwiftConnectionDelete(d *schema.Resource subnetName := subnetID.Path["subnets"] virtualNetworkName := subnetID.Path["virtualNetworks"] - locks.ByName(virtualNetworkName, virtualNetworkResourceName) - defer locks.UnlockByName(virtualNetworkName, virtualNetworkResourceName) + locks.ByName(virtualNetworkName, network.VirtualNetworkResourceName) + defer locks.UnlockByName(virtualNetworkName, network.VirtualNetworkResourceName) - locks.ByName(subnetName, subnetResourceName) - defer locks.UnlockByName(subnetName, subnetResourceName) + locks.ByName(subnetName, network.SubnetResourceName) + defer locks.UnlockByName(subnetName, network.SubnetResourceName) read, err := client.GetSwiftVirtualNetworkConnection(ctx, resourceGroup, name) if err != nil { diff --git a/azurerm/resource_arm_key_vault.go b/azurerm/resource_arm_key_vault.go index 44230050cc81..523023c66d70 100644 --- a/azurerm/resource_arm_key_vault.go +++ b/azurerm/resource_arm_key_vault.go @@ -2,6 +2,7 @@ package azurerm import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "log" "net/http" "regexp" @@ -289,13 +290,13 @@ func resourceArmKeyVaultCreateUpdate(d *schema.ResourceData, meta interface{}) e } virtualNetworkName := id.Path["virtualNetworks"] - if !sliceContainsValue(virtualNetworkNames, virtualNetworkName) { + if !network.SliceContainsValue(virtualNetworkNames, virtualNetworkName) { virtualNetworkNames = append(virtualNetworkNames, virtualNetworkName) } } - locks.MultipleByName(&virtualNetworkNames, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(&virtualNetworkNames, virtualNetworkResourceName) + locks.MultipleByName(&virtualNetworkNames, network.VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(&virtualNetworkNames, network.VirtualNetworkResourceName) if _, err = client.CreateOrUpdate(ctx, resourceGroup, name, parameters); err != nil { return fmt.Errorf("Error updating Key Vault %q (Resource Group %q): %+v", name, resourceGroup, err) @@ -441,7 +442,7 @@ func resourceArmKeyVaultDelete(d *schema.ResourceData, meta interface{}) error { } virtualNetworkName := id.Path["virtualNetworks"] - if !sliceContainsValue(virtualNetworkNames, virtualNetworkName) { + if !network.SliceContainsValue(virtualNetworkNames, virtualNetworkName) { virtualNetworkNames = append(virtualNetworkNames, virtualNetworkName) } } @@ -449,8 +450,8 @@ func resourceArmKeyVaultDelete(d *schema.ResourceData, meta interface{}) error { } } - locks.MultipleByName(&virtualNetworkNames, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(&virtualNetworkNames, virtualNetworkResourceName) + locks.MultipleByName(&virtualNetworkNames, network.VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(&virtualNetworkNames, network.VirtualNetworkResourceName) resp, err := client.Delete(ctx, resourceGroup, name) if err != nil { diff --git a/azurerm/resource_arm_redis_cache.go b/azurerm/resource_arm_redis_cache.go index 31800f910f26..a272263f51fb 100644 --- a/azurerm/resource_arm_redis_cache.go +++ b/azurerm/resource_arm_redis_cache.go @@ -3,6 +3,7 @@ package azurerm import ( "context" "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "log" "net/http" "strconv" @@ -334,11 +335,11 @@ func resourceArmRedisCacheCreate(d *schema.ResourceData, meta interface{}) error subnetName := parsed.Path["subnets"] virtualNetworkName := parsed.Path["virtualNetworks"] - locks.ByName(virtualNetworkName, virtualNetworkResourceName) - defer locks.UnlockByName(virtualNetworkName, virtualNetworkResourceName) + locks.ByName(virtualNetworkName, network.VirtualNetworkResourceName) + defer locks.UnlockByName(virtualNetworkName, network.VirtualNetworkResourceName) - locks.ByName(subnetName, subnetResourceName) - defer locks.UnlockByName(subnetName, subnetResourceName) + locks.ByName(subnetName, network.SubnetResourceName) + defer locks.UnlockByName(subnetName, network.SubnetResourceName) parameters.SubnetID = utils.String(v.(string)) } @@ -603,11 +604,11 @@ func resourceArmRedisCacheDelete(d *schema.ResourceData, meta interface{}) error subnetName := parsed.Path["subnets"] virtualNetworkName := parsed.Path["virtualNetworks"] - locks.ByName(virtualNetworkName, virtualNetworkResourceName) - defer locks.UnlockByName(virtualNetworkName, virtualNetworkResourceName) + locks.ByName(virtualNetworkName, network.VirtualNetworkResourceName) + defer locks.UnlockByName(virtualNetworkName, network.VirtualNetworkResourceName) - locks.ByName(subnetName, subnetResourceName) - defer locks.UnlockByName(subnetName, subnetResourceName) + locks.ByName(subnetName, network.SubnetResourceName) + defer locks.UnlockByName(subnetName, network.SubnetResourceName) } future, err := client.Delete(ctx, resGroup, name) if err != nil { diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/resource_arm_storage_account.go index f68acd884561..fcf696edf4eb 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/resource_arm_storage_account.go @@ -3,6 +3,7 @@ package azurerm import ( "fmt" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "log" "net/http" "regexp" @@ -1308,8 +1309,8 @@ func resourceArmStorageAccountDelete(d *schema.ResourceData, meta interface{}) e } } - locks.MultipleByName(&virtualNetworkNames, virtualNetworkResourceName) - defer locks.UnlockMultipleByName(&virtualNetworkNames, virtualNetworkResourceName) + locks.MultipleByName(&virtualNetworkNames, network.VirtualNetworkResourceName) + defer locks.UnlockMultipleByName(&virtualNetworkNames, network.VirtualNetworkResourceName) resp, err := client.Delete(ctx, resourceGroup, name) if err != nil { From e246bc65cc592c48bf34b271696cf038a429b31e Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 18:43:49 -0800 Subject: [PATCH 043/203] notificationhub --- .../notificationhub}/data_source_notification_hub.go | 2 +- .../data_source_notification_hub_namespace.go | 2 +- .../data_source_notification_hub_namespace_test.go | 2 +- .../data_source_notification_hub_test.go | 2 +- .../internal/services/notificationhub/registration.go | 11 +++++++++-- .../notificationhub}/resource_arm_notification_hub.go | 2 +- ...esource_arm_notification_hub_authorization_rule.go | 2 +- ...ce_arm_notification_hub_authorization_rule_test.go | 2 +- .../resource_arm_notification_hub_namespace.go | 2 +- .../resource_arm_notification_hub_namespace_test.go | 2 +- .../resource_arm_notification_hub_test.go | 2 +- azurerm/provider.go | 5 ----- 12 files changed, 19 insertions(+), 17 deletions(-) rename azurerm/{ => internal/services/notificationhub}/data_source_notification_hub.go (99%) rename azurerm/{ => internal/services/notificationhub}/data_source_notification_hub_namespace.go (99%) rename azurerm/{ => internal/services/notificationhub}/data_source_notification_hub_namespace_test.go (98%) rename azurerm/{ => internal/services/notificationhub}/data_source_notification_hub_test.go (98%) rename azurerm/{ => internal/services/notificationhub}/resource_arm_notification_hub.go (99%) rename azurerm/{ => internal/services/notificationhub}/resource_arm_notification_hub_authorization_rule.go (99%) rename azurerm/{ => internal/services/notificationhub}/resource_arm_notification_hub_authorization_rule_test.go (99%) rename azurerm/{ => internal/services/notificationhub}/resource_arm_notification_hub_namespace.go (99%) rename azurerm/{ => internal/services/notificationhub}/resource_arm_notification_hub_namespace_test.go (99%) rename azurerm/{ => internal/services/notificationhub}/resource_arm_notification_hub_test.go (99%) diff --git a/azurerm/data_source_notification_hub.go b/azurerm/internal/services/notificationhub/data_source_notification_hub.go similarity index 99% rename from azurerm/data_source_notification_hub.go rename to azurerm/internal/services/notificationhub/data_source_notification_hub.go index d82ab3ce6960..5201572add81 100644 --- a/azurerm/data_source_notification_hub.go +++ b/azurerm/internal/services/notificationhub/data_source_notification_hub.go @@ -1,4 +1,4 @@ -package azurerm +package notificationhub import ( "fmt" diff --git a/azurerm/data_source_notification_hub_namespace.go b/azurerm/internal/services/notificationhub/data_source_notification_hub_namespace.go similarity index 99% rename from azurerm/data_source_notification_hub_namespace.go rename to azurerm/internal/services/notificationhub/data_source_notification_hub_namespace.go index a276bcf456fb..dd6a018279ee 100644 --- a/azurerm/data_source_notification_hub_namespace.go +++ b/azurerm/internal/services/notificationhub/data_source_notification_hub_namespace.go @@ -1,4 +1,4 @@ -package azurerm +package notificationhub import ( "fmt" diff --git a/azurerm/data_source_notification_hub_namespace_test.go b/azurerm/internal/services/notificationhub/data_source_notification_hub_namespace_test.go similarity index 98% rename from azurerm/data_source_notification_hub_namespace_test.go rename to azurerm/internal/services/notificationhub/data_source_notification_hub_namespace_test.go index da2ed7a582bb..3909e5c57174 100644 --- a/azurerm/data_source_notification_hub_namespace_test.go +++ b/azurerm/internal/services/notificationhub/data_source_notification_hub_namespace_test.go @@ -1,4 +1,4 @@ -package azurerm +package notificationhub import ( "fmt" diff --git a/azurerm/data_source_notification_hub_test.go b/azurerm/internal/services/notificationhub/data_source_notification_hub_test.go similarity index 98% rename from azurerm/data_source_notification_hub_test.go rename to azurerm/internal/services/notificationhub/data_source_notification_hub_test.go index 89851b49f253..c4600438757e 100644 --- a/azurerm/data_source_notification_hub_test.go +++ b/azurerm/internal/services/notificationhub/data_source_notification_hub_test.go @@ -1,4 +1,4 @@ -package azurerm +package notificationhub import ( "fmt" diff --git a/azurerm/internal/services/notificationhub/registration.go b/azurerm/internal/services/notificationhub/registration.go index a7cfed9b20d9..0d5cf5c6db60 100644 --- a/azurerm/internal/services/notificationhub/registration.go +++ b/azurerm/internal/services/notificationhub/registration.go @@ -13,10 +13,17 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_notification_hub_namespace": dataSourceNotificationHubNamespace(), + "azurerm_notification_hub": dataSourceNotificationHub(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_notification_hub_authorization_rule": resourceArmNotificationHubAuthorizationRule(), + "azurerm_notification_hub_namespace": resourceArmNotificationHubNamespace(), + "azurerm_notification_hub": resourceArmNotificationHub(), + } } diff --git a/azurerm/resource_arm_notification_hub.go b/azurerm/internal/services/notificationhub/resource_arm_notification_hub.go similarity index 99% rename from azurerm/resource_arm_notification_hub.go rename to azurerm/internal/services/notificationhub/resource_arm_notification_hub.go index 470feb706e8c..9088a0dd6026 100644 --- a/azurerm/resource_arm_notification_hub.go +++ b/azurerm/internal/services/notificationhub/resource_arm_notification_hub.go @@ -1,4 +1,4 @@ -package azurerm +package notificationhub import ( "context" diff --git a/azurerm/resource_arm_notification_hub_authorization_rule.go b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_authorization_rule.go similarity index 99% rename from azurerm/resource_arm_notification_hub_authorization_rule.go rename to azurerm/internal/services/notificationhub/resource_arm_notification_hub_authorization_rule.go index 9d59257ffbd6..f5260f095a1b 100644 --- a/azurerm/resource_arm_notification_hub_authorization_rule.go +++ b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_authorization_rule.go @@ -1,4 +1,4 @@ -package azurerm +package notificationhub import ( "fmt" diff --git a/azurerm/resource_arm_notification_hub_authorization_rule_test.go b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_authorization_rule_test.go similarity index 99% rename from azurerm/resource_arm_notification_hub_authorization_rule_test.go rename to azurerm/internal/services/notificationhub/resource_arm_notification_hub_authorization_rule_test.go index 7c7dad0a0809..81a4cfb7fdbf 100644 --- a/azurerm/resource_arm_notification_hub_authorization_rule_test.go +++ b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_authorization_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package notificationhub import ( "fmt" diff --git a/azurerm/resource_arm_notification_hub_namespace.go b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go similarity index 99% rename from azurerm/resource_arm_notification_hub_namespace.go rename to azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go index 5b4474b18649..1cff9fd3e75c 100644 --- a/azurerm/resource_arm_notification_hub_namespace.go +++ b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace.go @@ -1,4 +1,4 @@ -package azurerm +package notificationhub import ( "context" diff --git a/azurerm/resource_arm_notification_hub_namespace_test.go b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace_test.go similarity index 99% rename from azurerm/resource_arm_notification_hub_namespace_test.go rename to azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace_test.go index d99af2d2f3a6..bd14c6f402c1 100644 --- a/azurerm/resource_arm_notification_hub_namespace_test.go +++ b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace_test.go @@ -1,4 +1,4 @@ -package azurerm +package notificationhub import ( "fmt" diff --git a/azurerm/resource_arm_notification_hub_test.go b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_test.go similarity index 99% rename from azurerm/resource_arm_notification_hub_test.go rename to azurerm/internal/services/notificationhub/resource_arm_notification_hub_test.go index 8cfc22d43c6a..5f2a35abb6d7 100644 --- a/azurerm/resource_arm_notification_hub_test.go +++ b/azurerm/internal/services/notificationhub/resource_arm_notification_hub_test.go @@ -1,4 +1,4 @@ -package azurerm +package notificationhub import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 4c624b5f91ea..8ae2e1528c77 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -24,8 +24,6 @@ func Provider() terraform.ResourceProvider { "azurerm_lb": dataSourceArmLoadBalancer(), "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), - "azurerm_notification_hub_namespace": dataSourceNotificationHubNamespace(), - "azurerm_notification_hub": dataSourceNotificationHub(), "azurerm_platform_image": dataSourceArmPlatformImage(), "azurerm_policy_definition": dataSourceArmPolicyDefinition(), "azurerm_postgresql_server": dataSourcePostgreSqlServer(), @@ -102,9 +100,6 @@ func Provider() terraform.ResourceProvider { "azurerm_mssql_database_vulnerability_assessment_rule_baseline": resourceArmMssqlDatabaseVulnerabilityAssessmentRuleBaseline(), "azurerm_mssql_server_security_alert_policy": resourceArmMssqlServerSecurityAlertPolicy(), "azurerm_mssql_server_vulnerability_assessment": resourceArmMssqlServerVulnerabilityAssessment(), - "azurerm_notification_hub_authorization_rule": resourceArmNotificationHubAuthorizationRule(), - "azurerm_notification_hub_namespace": resourceArmNotificationHubNamespace(), - "azurerm_notification_hub": resourceArmNotificationHub(), "azurerm_packet_capture": resourceArmPacketCapture(), "azurerm_policy_assignment": resourceArmPolicyAssignment(), "azurerm_policy_definition": resourceArmPolicyDefinition(), From 7b815cef14c13b9e407bf14a366d98b901a748ca Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 18:45:43 -0800 Subject: [PATCH 044/203] policy --- .../services/policy}/data_source_policy_definition.go | 2 +- .../policy}/data_source_policy_definition_test.go | 2 +- azurerm/internal/services/policy/registration.go | 10 ++++++++-- .../services/policy}/resource_arm_policy_assignment.go | 2 +- .../policy}/resource_arm_policy_assignment_test.go | 2 +- .../services/policy}/resource_arm_policy_definition.go | 2 +- .../policy}/resource_arm_policy_definition_test.go | 2 +- .../policy}/resource_arm_policy_set_definition.go | 2 +- .../policy}/resource_arm_policy_set_definition_test.go | 2 +- azurerm/provider.go | 4 ---- 10 files changed, 16 insertions(+), 14 deletions(-) rename azurerm/{ => internal/services/policy}/data_source_policy_definition.go (99%) rename azurerm/{ => internal/services/policy}/data_source_policy_definition_test.go (99%) rename azurerm/{ => internal/services/policy}/resource_arm_policy_assignment.go (99%) rename azurerm/{ => internal/services/policy}/resource_arm_policy_assignment_test.go (99%) rename azurerm/{ => internal/services/policy}/resource_arm_policy_definition.go (99%) rename azurerm/{ => internal/services/policy}/resource_arm_policy_definition_test.go (99%) rename azurerm/{ => internal/services/policy}/resource_arm_policy_set_definition.go (99%) rename azurerm/{ => internal/services/policy}/resource_arm_policy_set_definition_test.go (99%) diff --git a/azurerm/data_source_policy_definition.go b/azurerm/internal/services/policy/data_source_policy_definition.go similarity index 99% rename from azurerm/data_source_policy_definition.go rename to azurerm/internal/services/policy/data_source_policy_definition.go index c07f9f4814fd..f93561c0e05b 100644 --- a/azurerm/data_source_policy_definition.go +++ b/azurerm/internal/services/policy/data_source_policy_definition.go @@ -1,4 +1,4 @@ -package azurerm +package policy import ( "fmt" diff --git a/azurerm/data_source_policy_definition_test.go b/azurerm/internal/services/policy/data_source_policy_definition_test.go similarity index 99% rename from azurerm/data_source_policy_definition_test.go rename to azurerm/internal/services/policy/data_source_policy_definition_test.go index 4ba02d436646..e68725a332cb 100644 --- a/azurerm/data_source_policy_definition_test.go +++ b/azurerm/internal/services/policy/data_source_policy_definition_test.go @@ -1,4 +1,4 @@ -package azurerm +package policy import ( "fmt" diff --git a/azurerm/internal/services/policy/registration.go b/azurerm/internal/services/policy/registration.go index b6a1856fe3d1..1b78e8373411 100644 --- a/azurerm/internal/services/policy/registration.go +++ b/azurerm/internal/services/policy/registration.go @@ -13,10 +13,16 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_policy_definition": dataSourceArmPolicyDefinition(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_policy_assignment": resourceArmPolicyAssignment(), + "azurerm_policy_definition": resourceArmPolicyDefinition(), + "azurerm_policy_set_definition": resourceArmPolicySetDefinition(), + } } diff --git a/azurerm/resource_arm_policy_assignment.go b/azurerm/internal/services/policy/resource_arm_policy_assignment.go similarity index 99% rename from azurerm/resource_arm_policy_assignment.go rename to azurerm/internal/services/policy/resource_arm_policy_assignment.go index 0f913357bcbb..58b79d3f4c73 100644 --- a/azurerm/resource_arm_policy_assignment.go +++ b/azurerm/internal/services/policy/resource_arm_policy_assignment.go @@ -1,4 +1,4 @@ -package azurerm +package policy import ( "context" diff --git a/azurerm/resource_arm_policy_assignment_test.go b/azurerm/internal/services/policy/resource_arm_policy_assignment_test.go similarity index 99% rename from azurerm/resource_arm_policy_assignment_test.go rename to azurerm/internal/services/policy/resource_arm_policy_assignment_test.go index fc180289b0ee..3598bf3c9ec7 100644 --- a/azurerm/resource_arm_policy_assignment_test.go +++ b/azurerm/internal/services/policy/resource_arm_policy_assignment_test.go @@ -1,4 +1,4 @@ -package azurerm +package policy import ( "fmt" diff --git a/azurerm/resource_arm_policy_definition.go b/azurerm/internal/services/policy/resource_arm_policy_definition.go similarity index 99% rename from azurerm/resource_arm_policy_definition.go rename to azurerm/internal/services/policy/resource_arm_policy_definition.go index c38f44e75ddd..f6e7050c21c1 100644 --- a/azurerm/resource_arm_policy_definition.go +++ b/azurerm/internal/services/policy/resource_arm_policy_definition.go @@ -1,4 +1,4 @@ -package azurerm +package policy import ( "context" diff --git a/azurerm/resource_arm_policy_definition_test.go b/azurerm/internal/services/policy/resource_arm_policy_definition_test.go similarity index 99% rename from azurerm/resource_arm_policy_definition_test.go rename to azurerm/internal/services/policy/resource_arm_policy_definition_test.go index fe88cfc3e9d7..644f337de7a7 100644 --- a/azurerm/resource_arm_policy_definition_test.go +++ b/azurerm/internal/services/policy/resource_arm_policy_definition_test.go @@ -1,4 +1,4 @@ -package azurerm +package policy import ( "fmt" diff --git a/azurerm/resource_arm_policy_set_definition.go b/azurerm/internal/services/policy/resource_arm_policy_set_definition.go similarity index 99% rename from azurerm/resource_arm_policy_set_definition.go rename to azurerm/internal/services/policy/resource_arm_policy_set_definition.go index fc476a59d49c..44c8260ffc0a 100644 --- a/azurerm/resource_arm_policy_set_definition.go +++ b/azurerm/internal/services/policy/resource_arm_policy_set_definition.go @@ -1,4 +1,4 @@ -package azurerm +package policy import ( "context" diff --git a/azurerm/resource_arm_policy_set_definition_test.go b/azurerm/internal/services/policy/resource_arm_policy_set_definition_test.go similarity index 99% rename from azurerm/resource_arm_policy_set_definition_test.go rename to azurerm/internal/services/policy/resource_arm_policy_set_definition_test.go index 0d80fb2fbf44..2cda395c9610 100644 --- a/azurerm/resource_arm_policy_set_definition_test.go +++ b/azurerm/internal/services/policy/resource_arm_policy_set_definition_test.go @@ -1,4 +1,4 @@ -package azurerm +package policy import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 8ae2e1528c77..0518aeae280a 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -25,7 +25,6 @@ func Provider() terraform.ResourceProvider { "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), "azurerm_platform_image": dataSourceArmPlatformImage(), - "azurerm_policy_definition": dataSourceArmPolicyDefinition(), "azurerm_postgresql_server": dataSourcePostgreSqlServer(), "azurerm_private_link_endpoint_connection": dataSourceArmPrivateLinkEndpointConnection(), "azurerm_private_endpoint_connection": dataSourceArmPrivateEndpointConnection(), @@ -101,9 +100,6 @@ func Provider() terraform.ResourceProvider { "azurerm_mssql_server_security_alert_policy": resourceArmMssqlServerSecurityAlertPolicy(), "azurerm_mssql_server_vulnerability_assessment": resourceArmMssqlServerVulnerabilityAssessment(), "azurerm_packet_capture": resourceArmPacketCapture(), - "azurerm_policy_assignment": resourceArmPolicyAssignment(), - "azurerm_policy_definition": resourceArmPolicyDefinition(), - "azurerm_policy_set_definition": resourceArmPolicySetDefinition(), "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), "azurerm_postgresql_configuration": resourceArmPostgreSQLConfiguration(), "azurerm_postgresql_database": resourceArmPostgreSQLDatabase(), From 2d71fe3a4e8cfe61495b291aec75b5ab1a5ef722 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 18:47:30 -0800 Subject: [PATCH 045/203] postgres --- .../data_source_postgresql_server.go | 2 +- .../data_source_postgresql_server_test.go | 2 +- .../services/postgres/registration.go | 12 +- .../resource_arm_postgresql_configuration.go | 2 +- ...ource_arm_postgresql_configuration_test.go | 2 +- .../resource_arm_postgresql_database.go | 2 +- .../resource_arm_postgresql_database_test.go | 2 +- .../resource_arm_postgresql_firewall_rule.go | 2 +- ...ource_arm_postgresql_firewall_rule_test.go | 2 +- .../resource_arm_postgresql_server.go | 2 +- .../resource_arm_postgresql_server_test.go | 2 +- ...rce_arm_postgresql_virtual_network_rule.go | 2 +- ...rm_postgresql_virtual_network_rule_test.go | 2 +- azurerm/provider.go | 212 +++++++++--------- 14 files changed, 126 insertions(+), 122 deletions(-) rename azurerm/{ => internal/services/postgres}/data_source_postgresql_server.go (99%) rename azurerm/{ => internal/services/postgres}/data_source_postgresql_server_test.go (98%) rename azurerm/{ => internal/services/postgres}/resource_arm_postgresql_configuration.go (99%) rename azurerm/{ => internal/services/postgres}/resource_arm_postgresql_configuration_test.go (99%) rename azurerm/{ => internal/services/postgres}/resource_arm_postgresql_database.go (99%) rename azurerm/{ => internal/services/postgres}/resource_arm_postgresql_database_test.go (99%) rename azurerm/{ => internal/services/postgres}/resource_arm_postgresql_firewall_rule.go (99%) rename azurerm/{ => internal/services/postgres}/resource_arm_postgresql_firewall_rule_test.go (99%) rename azurerm/{ => internal/services/postgres}/resource_arm_postgresql_server.go (99%) rename azurerm/{ => internal/services/postgres}/resource_arm_postgresql_server_test.go (99%) rename azurerm/{ => internal/services/postgres}/resource_arm_postgresql_virtual_network_rule.go (99%) rename azurerm/{ => internal/services/postgres}/resource_arm_postgresql_virtual_network_rule_test.go (99%) diff --git a/azurerm/data_source_postgresql_server.go b/azurerm/internal/services/postgres/data_source_postgresql_server.go similarity index 99% rename from azurerm/data_source_postgresql_server.go rename to azurerm/internal/services/postgres/data_source_postgresql_server.go index 80523fed3b7a..859ccebd7d9f 100644 --- a/azurerm/data_source_postgresql_server.go +++ b/azurerm/internal/services/postgres/data_source_postgresql_server.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/data_source_postgresql_server_test.go b/azurerm/internal/services/postgres/data_source_postgresql_server_test.go similarity index 98% rename from azurerm/data_source_postgresql_server_test.go rename to azurerm/internal/services/postgres/data_source_postgresql_server_test.go index d673fb04642e..a96eb825e1f0 100644 --- a/azurerm/data_source_postgresql_server_test.go +++ b/azurerm/internal/services/postgres/data_source_postgresql_server_test.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/internal/services/postgres/registration.go b/azurerm/internal/services/postgres/registration.go index 320d78ff9864..9c107fd25189 100644 --- a/azurerm/internal/services/postgres/registration.go +++ b/azurerm/internal/services/postgres/registration.go @@ -13,10 +13,18 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_postgresql_server": dataSourcePostgreSqlServer(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_postgresql_configuration": resourceArmPostgreSQLConfiguration(), + "azurerm_postgresql_database": resourceArmPostgreSQLDatabase(), + "azurerm_postgresql_firewall_rule": resourceArmPostgreSQLFirewallRule(), + "azurerm_postgresql_server": resourceArmPostgreSQLServer(), + "azurerm_postgresql_virtual_network_rule": resourceArmPostgreSQLVirtualNetworkRule(), + } } diff --git a/azurerm/resource_arm_postgresql_configuration.go b/azurerm/internal/services/postgres/resource_arm_postgresql_configuration.go similarity index 99% rename from azurerm/resource_arm_postgresql_configuration.go rename to azurerm/internal/services/postgres/resource_arm_postgresql_configuration.go index 680e6ec59138..2b1a44c6c814 100644 --- a/azurerm/resource_arm_postgresql_configuration.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_configuration.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/resource_arm_postgresql_configuration_test.go b/azurerm/internal/services/postgres/resource_arm_postgresql_configuration_test.go similarity index 99% rename from azurerm/resource_arm_postgresql_configuration_test.go rename to azurerm/internal/services/postgres/resource_arm_postgresql_configuration_test.go index a334a5da4112..c1ebbb9b79a5 100644 --- a/azurerm/resource_arm_postgresql_configuration_test.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_configuration_test.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/resource_arm_postgresql_database.go b/azurerm/internal/services/postgres/resource_arm_postgresql_database.go similarity index 99% rename from azurerm/resource_arm_postgresql_database.go rename to azurerm/internal/services/postgres/resource_arm_postgresql_database.go index dd4b1f8167b9..8bf61154da4a 100644 --- a/azurerm/resource_arm_postgresql_database.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_database.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/resource_arm_postgresql_database_test.go b/azurerm/internal/services/postgres/resource_arm_postgresql_database_test.go similarity index 99% rename from azurerm/resource_arm_postgresql_database_test.go rename to azurerm/internal/services/postgres/resource_arm_postgresql_database_test.go index 501e9f1de424..0fb2631ff966 100644 --- a/azurerm/resource_arm_postgresql_database_test.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_database_test.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/resource_arm_postgresql_firewall_rule.go b/azurerm/internal/services/postgres/resource_arm_postgresql_firewall_rule.go similarity index 99% rename from azurerm/resource_arm_postgresql_firewall_rule.go rename to azurerm/internal/services/postgres/resource_arm_postgresql_firewall_rule.go index 12626aa12d58..da0b55b31c64 100644 --- a/azurerm/resource_arm_postgresql_firewall_rule.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_firewall_rule.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/resource_arm_postgresql_firewall_rule_test.go b/azurerm/internal/services/postgres/resource_arm_postgresql_firewall_rule_test.go similarity index 99% rename from azurerm/resource_arm_postgresql_firewall_rule_test.go rename to azurerm/internal/services/postgres/resource_arm_postgresql_firewall_rule_test.go index b981277094ca..6c9bea10c710 100644 --- a/azurerm/resource_arm_postgresql_firewall_rule_test.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_firewall_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/resource_arm_postgresql_server.go b/azurerm/internal/services/postgres/resource_arm_postgresql_server.go similarity index 99% rename from azurerm/resource_arm_postgresql_server.go rename to azurerm/internal/services/postgres/resource_arm_postgresql_server.go index ca58b85e28ff..0a42f24364be 100644 --- a/azurerm/resource_arm_postgresql_server.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_server.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/resource_arm_postgresql_server_test.go b/azurerm/internal/services/postgres/resource_arm_postgresql_server_test.go similarity index 99% rename from azurerm/resource_arm_postgresql_server_test.go rename to azurerm/internal/services/postgres/resource_arm_postgresql_server_test.go index 9b82e3942846..e592c3c870bc 100644 --- a/azurerm/resource_arm_postgresql_server_test.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_server_test.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/resource_arm_postgresql_virtual_network_rule.go b/azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule.go similarity index 99% rename from azurerm/resource_arm_postgresql_virtual_network_rule.go rename to azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule.go index 63231b11f2f2..613d9c34e409 100644 --- a/azurerm/resource_arm_postgresql_virtual_network_rule.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "context" diff --git a/azurerm/resource_arm_postgresql_virtual_network_rule_test.go b/azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule_test.go similarity index 99% rename from azurerm/resource_arm_postgresql_virtual_network_rule_test.go rename to azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule_test.go index 3a0bc3d4ff78..082f5762aa65 100644 --- a/azurerm/resource_arm_postgresql_virtual_network_rule_test.go +++ b/azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package postgres import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 0518aeae280a..e4ff6ccba8f4 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -8,24 +8,24 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - "azurerm_app_service_plan": dataSourceAppServicePlan(), - "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), - "azurerm_app_service": dataSourceArmAppService(), - "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), - "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), - "azurerm_image": dataSourceArmImage(), - "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), - "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), - "azurerm_key_vault": dataSourceArmKeyVault(), - "azurerm_lb": dataSourceArmLoadBalancer(), - "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), - "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), - "azurerm_platform_image": dataSourceArmPlatformImage(), - "azurerm_postgresql_server": dataSourcePostgreSqlServer(), + "azurerm_app_service_plan": dataSourceAppServicePlan(), + "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), + "azurerm_app_service": dataSourceArmAppService(), + "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), + "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), + "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), + "azurerm_client_config": dataSourceArmClientConfig(), + "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), + "azurerm_image": dataSourceArmImage(), + "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), + "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), + "azurerm_key_vault": dataSourceArmKeyVault(), + "azurerm_lb": dataSourceArmLoadBalancer(), + "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), + "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), + "azurerm_platform_image": dataSourceArmPlatformImage(), + "azurerm_private_link_endpoint_connection": dataSourceArmPrivateLinkEndpointConnection(), "azurerm_private_endpoint_connection": dataSourceArmPrivateEndpointConnection(), "azurerm_private_link_service": dataSourceArmPrivateLinkService(), @@ -101,96 +101,92 @@ func Provider() terraform.ResourceProvider { "azurerm_mssql_server_vulnerability_assessment": resourceArmMssqlServerVulnerabilityAssessment(), "azurerm_packet_capture": resourceArmPacketCapture(), "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), - "azurerm_postgresql_configuration": resourceArmPostgreSQLConfiguration(), - "azurerm_postgresql_database": resourceArmPostgreSQLDatabase(), - "azurerm_postgresql_firewall_rule": resourceArmPostgreSQLFirewallRule(), - "azurerm_postgresql_server": resourceArmPostgreSQLServer(), - "azurerm_postgresql_virtual_network_rule": resourceArmPostgreSQLVirtualNetworkRule(), - "azurerm_private_dns_zone": resourceArmPrivateDnsZone(), - "azurerm_private_dns_a_record": resourceArmPrivateDnsARecord(), - "azurerm_private_dns_aaaa_record": resourceArmPrivateDnsAaaaRecord(), - "azurerm_private_dns_cname_record": resourceArmPrivateDnsCNameRecord(), - "azurerm_private_dns_mx_record": resourceArmPrivateDnsMxRecord(), - "azurerm_private_dns_ptr_record": resourceArmPrivateDnsPtrRecord(), - "azurerm_private_dns_srv_record": resourceArmPrivateDnsSrvRecord(), - "azurerm_private_dns_zone_virtual_network_link": resourceArmPrivateDnsZoneVirtualNetworkLink(), - "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), - "azurerm_private_endpoint": resourceArmPrivateEndpoint(), - "azurerm_private_link_service": resourceArmPrivateLinkService(), - "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), - "azurerm_public_ip": resourceArmPublicIp(), - "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), - "azurerm_recovery_network_mapping": resourceArmRecoveryServicesNetworkMapping(), - "azurerm_recovery_replicated_vm": resourceArmRecoveryServicesReplicatedVm(), - "azurerm_recovery_services_fabric": resourceArmRecoveryServicesFabric(), - "azurerm_recovery_services_protected_vm": resourceArmRecoveryServicesProtectedVm(), - "azurerm_recovery_services_protection_container": resourceArmRecoveryServicesProtectionContainer(), - "azurerm_recovery_services_protection_container_mapping": resourceArmRecoveryServicesProtectionContainerMapping(), - "azurerm_recovery_services_protection_policy_vm": resourceArmRecoveryServicesProtectionPolicyVm(), - "azurerm_recovery_services_replication_policy": resourceArmRecoveryServicesReplicationPolicy(), - "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), - "azurerm_redis_cache": resourceArmRedisCache(), - "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), - "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), - "azurerm_relay_namespace": resourceArmRelayNamespace(), - "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), - "azurerm_scheduler_job": resourceArmSchedulerJob(), - "azurerm_search_service": resourceArmSearchService(), - "azurerm_security_center_contact": resourceArmSecurityCenterContact(), - "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), - "azurerm_security_center_workspace": resourceArmSecurityCenterWorkspace(), - "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), - "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), - "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), - "azurerm_servicebus_queue": resourceArmServiceBusQueue(), - "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), - "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), - "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), - "azurerm_servicebus_topic": resourceArmServiceBusTopic(), - "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), - "azurerm_shared_image_version": resourceArmSharedImageVersion(), - "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_signalr_service": resourceArmSignalRService(), - "azurerm_site_recovery_fabric": resourceArmSiteRecoveryFabric(), - "azurerm_site_recovery_network_mapping": resourceArmSiteRecoveryNetworkMapping(), - "azurerm_site_recovery_protection_container": resourceArmSiteRecoveryProtectionContainer(), - "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), - "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), - "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), - "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), - "azurerm_sql_database": resourceArmSqlDatabase(), - "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), - "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), - "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), - "azurerm_sql_server": resourceArmSqlServer(), - "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), - "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_storage_table_entity": resourceArmStorageTableEntity(), - "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), - "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), - "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), - "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), - "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), - "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), - "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), - "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), - "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), - "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), - "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), - "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), - "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), + + "azurerm_private_dns_zone": resourceArmPrivateDnsZone(), + "azurerm_private_dns_a_record": resourceArmPrivateDnsARecord(), + "azurerm_private_dns_aaaa_record": resourceArmPrivateDnsAaaaRecord(), + "azurerm_private_dns_cname_record": resourceArmPrivateDnsCNameRecord(), + "azurerm_private_dns_mx_record": resourceArmPrivateDnsMxRecord(), + "azurerm_private_dns_ptr_record": resourceArmPrivateDnsPtrRecord(), + "azurerm_private_dns_srv_record": resourceArmPrivateDnsSrvRecord(), + "azurerm_private_dns_zone_virtual_network_link": resourceArmPrivateDnsZoneVirtualNetworkLink(), + "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), + "azurerm_private_endpoint": resourceArmPrivateEndpoint(), + "azurerm_private_link_service": resourceArmPrivateLinkService(), + "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), + "azurerm_public_ip": resourceArmPublicIp(), + "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), + "azurerm_recovery_network_mapping": resourceArmRecoveryServicesNetworkMapping(), + "azurerm_recovery_replicated_vm": resourceArmRecoveryServicesReplicatedVm(), + "azurerm_recovery_services_fabric": resourceArmRecoveryServicesFabric(), + "azurerm_recovery_services_protected_vm": resourceArmRecoveryServicesProtectedVm(), + "azurerm_recovery_services_protection_container": resourceArmRecoveryServicesProtectionContainer(), + "azurerm_recovery_services_protection_container_mapping": resourceArmRecoveryServicesProtectionContainerMapping(), + "azurerm_recovery_services_protection_policy_vm": resourceArmRecoveryServicesProtectionPolicyVm(), + "azurerm_recovery_services_replication_policy": resourceArmRecoveryServicesReplicationPolicy(), + "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), + "azurerm_redis_cache": resourceArmRedisCache(), + "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), + "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), + "azurerm_relay_namespace": resourceArmRelayNamespace(), + "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), + "azurerm_scheduler_job": resourceArmSchedulerJob(), + "azurerm_search_service": resourceArmSearchService(), + "azurerm_security_center_contact": resourceArmSecurityCenterContact(), + "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), + "azurerm_security_center_workspace": resourceArmSecurityCenterWorkspace(), + "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), + "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), + "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), + "azurerm_servicebus_queue": resourceArmServiceBusQueue(), + "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), + "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), + "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), + "azurerm_servicebus_topic": resourceArmServiceBusTopic(), + "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), + "azurerm_shared_image_version": resourceArmSharedImageVersion(), + "azurerm_shared_image": resourceArmSharedImage(), + "azurerm_signalr_service": resourceArmSignalRService(), + "azurerm_site_recovery_fabric": resourceArmSiteRecoveryFabric(), + "azurerm_site_recovery_network_mapping": resourceArmSiteRecoveryNetworkMapping(), + "azurerm_site_recovery_protection_container": resourceArmSiteRecoveryProtectionContainer(), + "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), + "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), + "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), + "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), + "azurerm_sql_database": resourceArmSqlDatabase(), + "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), + "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), + "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), + "azurerm_sql_server": resourceArmSqlServer(), + "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), + "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_storage_table_entity": resourceArmStorageTableEntity(), + "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), + "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), + "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), + "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), + "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), + "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), + "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), + "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), + "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), + "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), + "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), + "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), } return provider.AzureProvider(dataSources, resources) From d0411d5862d71eb7b2d5a7bf2e06301503cb79e2 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 18:48:54 -0800 Subject: [PATCH 046/203] privatedns --- .../services/privatedns/registration.go | 11 +- .../resource_arm_private_dns_a_record.go | 2 +- .../resource_arm_private_dns_a_record_test.go | 2 +- .../resource_arm_private_dns_aaaa_record.go | 2 +- ...source_arm_private_dns_aaaa_record_test.go | 2 +- .../resource_arm_private_dns_cname_record.go | 2 +- ...ource_arm_private_dns_cname_record_test.go | 2 +- .../resource_arm_private_dns_mx_record.go | 2 +- ...resource_arm_private_dns_mx_record_test.go | 2 +- .../resource_arm_private_dns_ptr_record.go | 2 +- ...esource_arm_private_dns_ptr_record_test.go | 2 +- .../resource_arm_private_dns_srv_record.go | 2 +- ...esource_arm_private_dns_srv_record_test.go | 2 +- .../resource_arm_private_dns_zone.go | 2 +- .../resource_arm_private_dns_zone_test.go | 2 +- ...m_private_dns_zone_virtual_network_link.go | 2 +- ...vate_dns_zone_virtual_network_link_test.go | 2 +- azurerm/provider.go | 163 +++++++++--------- 18 files changed, 103 insertions(+), 103 deletions(-) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_a_record.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_a_record_test.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_aaaa_record.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_aaaa_record_test.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_cname_record.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_cname_record_test.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_mx_record.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_mx_record_test.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_ptr_record.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_ptr_record_test.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_srv_record.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_srv_record_test.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_zone.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_zone_test.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_zone_virtual_network_link.go (99%) rename azurerm/{ => internal/services/privatedns}/resource_arm_private_dns_zone_virtual_network_link_test.go (99%) diff --git a/azurerm/internal/services/privatedns/registration.go b/azurerm/internal/services/privatedns/registration.go index d884c92cd246..40421d979b0f 100644 --- a/azurerm/internal/services/privatedns/registration.go +++ b/azurerm/internal/services/privatedns/registration.go @@ -18,5 +18,14 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_private_dns_zone": resourceArmPrivateDnsZone(), + "azurerm_private_dns_a_record": resourceArmPrivateDnsARecord(), + "azurerm_private_dns_aaaa_record": resourceArmPrivateDnsAaaaRecord(), + "azurerm_private_dns_cname_record": resourceArmPrivateDnsCNameRecord(), + "azurerm_private_dns_mx_record": resourceArmPrivateDnsMxRecord(), + "azurerm_private_dns_ptr_record": resourceArmPrivateDnsPtrRecord(), + "azurerm_private_dns_srv_record": resourceArmPrivateDnsSrvRecord(), + "azurerm_private_dns_zone_virtual_network_link": resourceArmPrivateDnsZoneVirtualNetworkLink(), + } } diff --git a/azurerm/resource_arm_private_dns_a_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_a_record.go similarity index 99% rename from azurerm/resource_arm_private_dns_a_record.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_a_record.go index beb25c932bb7..b85f444d9510 100644 --- a/azurerm/resource_arm_private_dns_a_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_a_record.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_a_record_test.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_a_record_test.go similarity index 99% rename from azurerm/resource_arm_private_dns_a_record_test.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_a_record_test.go index b7e1654f44f9..d4c9092adb8d 100644 --- a/azurerm/resource_arm_private_dns_a_record_test.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_a_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_aaaa_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record.go similarity index 99% rename from azurerm/resource_arm_private_dns_aaaa_record.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record.go index ba6b98eb6f84..932ccee4fdfc 100644 --- a/azurerm/resource_arm_private_dns_aaaa_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_aaaa_record_test.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record_test.go similarity index 99% rename from azurerm/resource_arm_private_dns_aaaa_record_test.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record_test.go index e1b02de4c6bd..a23e86f06a31 100644 --- a/azurerm/resource_arm_private_dns_aaaa_record_test.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_cname_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record.go similarity index 99% rename from azurerm/resource_arm_private_dns_cname_record.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record.go index 24a4ee90ea14..8a4a32cc39ec 100644 --- a/azurerm/resource_arm_private_dns_cname_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_cname_record_test.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record_test.go similarity index 99% rename from azurerm/resource_arm_private_dns_cname_record_test.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record_test.go index 137ec0531d30..66533d992c33 100644 --- a/azurerm/resource_arm_private_dns_cname_record_test.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_mx_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record.go similarity index 99% rename from azurerm/resource_arm_private_dns_mx_record.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record.go index 1da618056511..35f1ce6bf25b 100644 --- a/azurerm/resource_arm_private_dns_mx_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_mx_record_test.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record_test.go similarity index 99% rename from azurerm/resource_arm_private_dns_mx_record_test.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record_test.go index 865769ff3e18..5628bda6ecce 100644 --- a/azurerm/resource_arm_private_dns_mx_record_test.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_ptr_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record.go similarity index 99% rename from azurerm/resource_arm_private_dns_ptr_record.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record.go index 7f20a25e68db..e3541d6e1c36 100644 --- a/azurerm/resource_arm_private_dns_ptr_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_ptr_record_test.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record_test.go similarity index 99% rename from azurerm/resource_arm_private_dns_ptr_record_test.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record_test.go index e7a2cd0cbd2c..5e8aede1cb23 100644 --- a/azurerm/resource_arm_private_dns_ptr_record_test.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_srv_record.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record.go similarity index 99% rename from azurerm/resource_arm_private_dns_srv_record.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record.go index 9b099d01f246..758710d794d7 100644 --- a/azurerm/resource_arm_private_dns_srv_record.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_srv_record_test.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record_test.go similarity index 99% rename from azurerm/resource_arm_private_dns_srv_record_test.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record_test.go index 0f7dc9e4cca3..bf7a85faee81 100644 --- a/azurerm/resource_arm_private_dns_srv_record_test.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record_test.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_zone.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_zone.go similarity index 99% rename from azurerm/resource_arm_private_dns_zone.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_zone.go index fc4bc2a639e6..2ee4738c5cc0 100644 --- a/azurerm/resource_arm_private_dns_zone.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_zone.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_zone_test.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_zone_test.go similarity index 99% rename from azurerm/resource_arm_private_dns_zone_test.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_zone_test.go index d4681e9b629c..c657da7ef0ca 100644 --- a/azurerm/resource_arm_private_dns_zone_test.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_zone_test.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_zone_virtual_network_link.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_zone_virtual_network_link.go similarity index 99% rename from azurerm/resource_arm_private_dns_zone_virtual_network_link.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_zone_virtual_network_link.go index 4bf2bd97777c..401109035262 100644 --- a/azurerm/resource_arm_private_dns_zone_virtual_network_link.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_zone_virtual_network_link.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/resource_arm_private_dns_zone_virtual_network_link_test.go b/azurerm/internal/services/privatedns/resource_arm_private_dns_zone_virtual_network_link_test.go similarity index 99% rename from azurerm/resource_arm_private_dns_zone_virtual_network_link_test.go rename to azurerm/internal/services/privatedns/resource_arm_private_dns_zone_virtual_network_link_test.go index ac2a7ca4d21b..fb67b5bbed31 100644 --- a/azurerm/resource_arm_private_dns_zone_virtual_network_link_test.go +++ b/azurerm/internal/services/privatedns/resource_arm_private_dns_zone_virtual_network_link_test.go @@ -1,4 +1,4 @@ -package azurerm +package privatedns import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index e4ff6ccba8f4..a0375e37aaa2 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -101,92 +101,83 @@ func Provider() terraform.ResourceProvider { "azurerm_mssql_server_vulnerability_assessment": resourceArmMssqlServerVulnerabilityAssessment(), "azurerm_packet_capture": resourceArmPacketCapture(), "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), - - "azurerm_private_dns_zone": resourceArmPrivateDnsZone(), - "azurerm_private_dns_a_record": resourceArmPrivateDnsARecord(), - "azurerm_private_dns_aaaa_record": resourceArmPrivateDnsAaaaRecord(), - "azurerm_private_dns_cname_record": resourceArmPrivateDnsCNameRecord(), - "azurerm_private_dns_mx_record": resourceArmPrivateDnsMxRecord(), - "azurerm_private_dns_ptr_record": resourceArmPrivateDnsPtrRecord(), - "azurerm_private_dns_srv_record": resourceArmPrivateDnsSrvRecord(), - "azurerm_private_dns_zone_virtual_network_link": resourceArmPrivateDnsZoneVirtualNetworkLink(), - "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), - "azurerm_private_endpoint": resourceArmPrivateEndpoint(), - "azurerm_private_link_service": resourceArmPrivateLinkService(), - "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), - "azurerm_public_ip": resourceArmPublicIp(), - "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), - "azurerm_recovery_network_mapping": resourceArmRecoveryServicesNetworkMapping(), - "azurerm_recovery_replicated_vm": resourceArmRecoveryServicesReplicatedVm(), - "azurerm_recovery_services_fabric": resourceArmRecoveryServicesFabric(), - "azurerm_recovery_services_protected_vm": resourceArmRecoveryServicesProtectedVm(), - "azurerm_recovery_services_protection_container": resourceArmRecoveryServicesProtectionContainer(), - "azurerm_recovery_services_protection_container_mapping": resourceArmRecoveryServicesProtectionContainerMapping(), - "azurerm_recovery_services_protection_policy_vm": resourceArmRecoveryServicesProtectionPolicyVm(), - "azurerm_recovery_services_replication_policy": resourceArmRecoveryServicesReplicationPolicy(), - "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), - "azurerm_redis_cache": resourceArmRedisCache(), - "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), - "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), - "azurerm_relay_namespace": resourceArmRelayNamespace(), - "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), - "azurerm_scheduler_job": resourceArmSchedulerJob(), - "azurerm_search_service": resourceArmSearchService(), - "azurerm_security_center_contact": resourceArmSecurityCenterContact(), - "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), - "azurerm_security_center_workspace": resourceArmSecurityCenterWorkspace(), - "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), - "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), - "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), - "azurerm_servicebus_queue": resourceArmServiceBusQueue(), - "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), - "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), - "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), - "azurerm_servicebus_topic": resourceArmServiceBusTopic(), - "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), - "azurerm_shared_image_version": resourceArmSharedImageVersion(), - "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_signalr_service": resourceArmSignalRService(), - "azurerm_site_recovery_fabric": resourceArmSiteRecoveryFabric(), - "azurerm_site_recovery_network_mapping": resourceArmSiteRecoveryNetworkMapping(), - "azurerm_site_recovery_protection_container": resourceArmSiteRecoveryProtectionContainer(), - "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), - "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), - "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), - "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), - "azurerm_sql_database": resourceArmSqlDatabase(), - "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), - "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), - "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), - "azurerm_sql_server": resourceArmSqlServer(), - "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), - "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_storage_table_entity": resourceArmStorageTableEntity(), - "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), - "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), - "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), - "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), - "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), - "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), - "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), - "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), - "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), - "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), - "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), - "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), - "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), + "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), + "azurerm_private_endpoint": resourceArmPrivateEndpoint(), + "azurerm_private_link_service": resourceArmPrivateLinkService(), + "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), + "azurerm_public_ip": resourceArmPublicIp(), + "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), + "azurerm_recovery_network_mapping": resourceArmRecoveryServicesNetworkMapping(), + "azurerm_recovery_replicated_vm": resourceArmRecoveryServicesReplicatedVm(), + "azurerm_recovery_services_fabric": resourceArmRecoveryServicesFabric(), + "azurerm_recovery_services_protected_vm": resourceArmRecoveryServicesProtectedVm(), + "azurerm_recovery_services_protection_container": resourceArmRecoveryServicesProtectionContainer(), + "azurerm_recovery_services_protection_container_mapping": resourceArmRecoveryServicesProtectionContainerMapping(), + "azurerm_recovery_services_protection_policy_vm": resourceArmRecoveryServicesProtectionPolicyVm(), + "azurerm_recovery_services_replication_policy": resourceArmRecoveryServicesReplicationPolicy(), + "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), + "azurerm_redis_cache": resourceArmRedisCache(), + "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), + "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), + "azurerm_relay_namespace": resourceArmRelayNamespace(), + "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), + "azurerm_scheduler_job": resourceArmSchedulerJob(), + "azurerm_search_service": resourceArmSearchService(), + "azurerm_security_center_contact": resourceArmSecurityCenterContact(), + "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), + "azurerm_security_center_workspace": resourceArmSecurityCenterWorkspace(), + "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), + "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), + "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), + "azurerm_servicebus_queue": resourceArmServiceBusQueue(), + "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), + "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), + "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), + "azurerm_servicebus_topic": resourceArmServiceBusTopic(), + "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), + "azurerm_shared_image_version": resourceArmSharedImageVersion(), + "azurerm_shared_image": resourceArmSharedImage(), + "azurerm_signalr_service": resourceArmSignalRService(), + "azurerm_site_recovery_fabric": resourceArmSiteRecoveryFabric(), + "azurerm_site_recovery_network_mapping": resourceArmSiteRecoveryNetworkMapping(), + "azurerm_site_recovery_protection_container": resourceArmSiteRecoveryProtectionContainer(), + "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), + "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), + "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), + "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), + "azurerm_sql_database": resourceArmSqlDatabase(), + "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), + "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), + "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), + "azurerm_sql_server": resourceArmSqlServer(), + "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), + "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_storage_table_entity": resourceArmStorageTableEntity(), + "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), + "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), + "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), + "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), + "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), + "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), + "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), + "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), + "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), + "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), + "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), + "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), } return provider.AzureProvider(dataSources, resources) From 77fdecb51f2ff3e241b35b0cc8da877a4e80e6cd Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 18:58:17 -0800 Subject: [PATCH 047/203] recoveryservices --- ..._recovery_services_protection_policy_vm.go | 2 +- ...very_services_protection_policy_vm_test.go | 2 +- .../data_source_recovery_services_vault.go | 2 +- ...ata_source_recovery_services_vault_test.go | 2 +- .../services/recoveryservices/registration.go | 28 +++++++++++++-- ...ce_arm_backup_container_storage_account.go | 2 +- ...m_backup_container_storage_account_test.go | 2 +- .../resource_arm_backup_policy_file_share.go | 2 +- ...ource_arm_backup_policy_file_share_test.go | 2 +- .../resource_arm_backup_policy_vm.go | 2 +- .../resource_arm_backup_policy_vm_test.go | 2 +- ...esource_arm_backup_protected_file_share.go | 5 +-- ...ce_arm_backup_protected_file_share_test.go | 2 +- .../resource_arm_backup_protected_vm.go | 2 +- .../resource_arm_backup_protected_vm_test.go | 2 +- .../resource_arm_recovery_services_fabric.go | 2 +- ...ource_arm_recovery_services_fabric_test.go | 2 +- ...e_arm_recovery_services_network_mapping.go | 2 +- ..._recovery_services_network_mapping_test.go | 2 +- ...urce_arm_recovery_services_protected_vm.go | 2 +- ...arm_recovery_services_protected_vm_test.go | 2 +- ..._recovery_services_protection_container.go | 2 +- ...y_services_protection_container_mapping.go | 2 +- ...vices_protection_container_mapping_test.go | 2 +- ...very_services_protection_container_test.go | 2 +- ..._recovery_services_protection_policy_vm.go | 2 +- ...very_services_protection_policy_vm_test.go | 2 +- ...rce_arm_recovery_services_replicated_vm.go | 2 +- ...rm_recovery_services_replicated_vm_test.go | 2 +- ...rm_recovery_services_replication_policy.go | 2 +- ...covery_services_replication_policy_test.go | 2 +- .../resource_arm_recovery_services_vault.go | 2 +- ...source_arm_recovery_services_vault_test.go | 2 +- .../resource_arm_site_recovery_fabric.go | 2 +- .../resource_arm_site_recovery_fabric_test.go | 2 +- ...ource_arm_site_recovery_network_mapping.go | 2 +- ..._arm_site_recovery_network_mapping_test.go | 2 +- ..._arm_site_recovery_protection_container.go | 2 +- ...e_recovery_protection_container_mapping.go | 2 +- ...overy_protection_container_mapping_test.go | 2 +- ...site_recovery_protection_container_test.go | 2 +- ...esource_arm_site_recovery_replicated_vm.go | 2 +- ...ce_arm_site_recovery_replicated_vm_test.go | 2 +- ...ce_arm_site_recovery_replication_policy.go | 2 +- ...m_site_recovery_replication_policy_test.go | 2 +- .../internal/services/storage/validation.go | 29 ++++++++++++++++ .../services/storage/validation_test.go | 34 +++++++++++++++++++ azurerm/provider.go | 22 ------------ azurerm/resource_arm_storage_share.go | 26 +------------- .../resource_arm_storage_share_migration.go | 3 +- azurerm/resource_arm_storage_share_test.go | 29 ---------------- 51 files changed, 138 insertions(+), 124 deletions(-) rename azurerm/{ => internal/services/recoveryservices}/data_source_recovery_services_protection_policy_vm.go (98%) rename azurerm/{ => internal/services/recoveryservices}/data_source_recovery_services_protection_policy_vm_test.go (98%) rename azurerm/{ => internal/services/recoveryservices}/data_source_recovery_services_vault.go (98%) rename azurerm/{ => internal/services/recoveryservices}/data_source_recovery_services_vault_test.go (98%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_backup_container_storage_account.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_backup_container_storage_account_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_backup_policy_file_share.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_backup_policy_file_share_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_backup_policy_vm.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_backup_policy_vm_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_backup_protected_file_share.go (98%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_backup_protected_file_share_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_backup_protected_vm.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_backup_protected_vm_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_fabric.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_fabric_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_network_mapping.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_network_mapping_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_protected_vm.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_protected_vm_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_protection_container.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_protection_container_mapping.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_protection_container_mapping_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_protection_container_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_protection_policy_vm.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_protection_policy_vm_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_replicated_vm.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_replicated_vm_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_replication_policy.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_replication_policy_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_vault.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_recovery_services_vault_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_fabric.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_fabric_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_network_mapping.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_network_mapping_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_protection_container.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_protection_container_mapping.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_protection_container_mapping_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_protection_container_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_replicated_vm.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_replicated_vm_test.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_replication_policy.go (99%) rename azurerm/{ => internal/services/recoveryservices}/resource_arm_site_recovery_replication_policy_test.go (99%) create mode 100644 azurerm/internal/services/storage/validation.go create mode 100644 azurerm/internal/services/storage/validation_test.go diff --git a/azurerm/data_source_recovery_services_protection_policy_vm.go b/azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm.go similarity index 98% rename from azurerm/data_source_recovery_services_protection_policy_vm.go rename to azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm.go index 14827607fd7a..585423819eb1 100644 --- a/azurerm/data_source_recovery_services_protection_policy_vm.go +++ b/azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/data_source_recovery_services_protection_policy_vm_test.go b/azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm_test.go similarity index 98% rename from azurerm/data_source_recovery_services_protection_policy_vm_test.go rename to azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm_test.go index 94a1d7f4d535..c2678cf3a60b 100644 --- a/azurerm/data_source_recovery_services_protection_policy_vm_test.go +++ b/azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/data_source_recovery_services_vault.go b/azurerm/internal/services/recoveryservices/data_source_recovery_services_vault.go similarity index 98% rename from azurerm/data_source_recovery_services_vault.go rename to azurerm/internal/services/recoveryservices/data_source_recovery_services_vault.go index b4aeb4787eaf..4363355de5e0 100644 --- a/azurerm/data_source_recovery_services_vault.go +++ b/azurerm/internal/services/recoveryservices/data_source_recovery_services_vault.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/data_source_recovery_services_vault_test.go b/azurerm/internal/services/recoveryservices/data_source_recovery_services_vault_test.go similarity index 98% rename from azurerm/data_source_recovery_services_vault_test.go rename to azurerm/internal/services/recoveryservices/data_source_recovery_services_vault_test.go index 5c3b47047ba7..7d8e08f3ea16 100644 --- a/azurerm/data_source_recovery_services_vault_test.go +++ b/azurerm/internal/services/recoveryservices/data_source_recovery_services_vault_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/internal/services/recoveryservices/registration.go b/azurerm/internal/services/recoveryservices/registration.go index 06e1aa207915..a650aca1df6a 100644 --- a/azurerm/internal/services/recoveryservices/registration.go +++ b/azurerm/internal/services/recoveryservices/registration.go @@ -13,10 +13,34 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_recovery_services_vault": dataSourceArmRecoveryServicesVault(), + "azurerm_recovery_services_protection_policy_vm": dataSourceArmRecoveryServicesProtectionPolicyVm(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_recovery_network_mapping": resourceArmRecoveryServicesNetworkMapping(), + "azurerm_recovery_replicated_vm": resourceArmRecoveryServicesReplicatedVm(), + "azurerm_recovery_services_fabric": resourceArmRecoveryServicesFabric(), + "azurerm_recovery_services_protected_vm": resourceArmRecoveryServicesProtectedVm(), + "azurerm_recovery_services_protection_container": resourceArmRecoveryServicesProtectionContainer(), + "azurerm_recovery_services_protection_container_mapping": resourceArmRecoveryServicesProtectionContainerMapping(), + "azurerm_recovery_services_protection_policy_vm": resourceArmRecoveryServicesProtectionPolicyVm(), + "azurerm_recovery_services_replication_policy": resourceArmRecoveryServicesReplicationPolicy(), + "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), + "azurerm_site_recovery_fabric": resourceArmSiteRecoveryFabric(), + "azurerm_site_recovery_network_mapping": resourceArmSiteRecoveryNetworkMapping(), + "azurerm_site_recovery_protection_container": resourceArmSiteRecoveryProtectionContainer(), + "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), + "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), + "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), + "azurerm_backup_container_storage_account": resourceArmBackupProtectionContainerStorageAccount(), + "azurerm_backup_policy_file_share": resourceArmBackupProtectionPolicyFileShare(), + "azurerm_backup_protected_file_share": resourceArmBackupProtectedFileShare(), + "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), + "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), + } } diff --git a/azurerm/resource_arm_backup_container_storage_account.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_container_storage_account.go similarity index 99% rename from azurerm/resource_arm_backup_container_storage_account.go rename to azurerm/internal/services/recoveryservices/resource_arm_backup_container_storage_account.go index c45bc84fbac0..41ce7f4f444b 100644 --- a/azurerm/resource_arm_backup_container_storage_account.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_container_storage_account.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "context" diff --git a/azurerm/resource_arm_backup_container_storage_account_test.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_container_storage_account_test.go similarity index 99% rename from azurerm/resource_arm_backup_container_storage_account_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_backup_container_storage_account_test.go index a3999755e531..691e56e36b8e 100644 --- a/azurerm/resource_arm_backup_container_storage_account_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_container_storage_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_backup_policy_file_share.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share.go similarity index 99% rename from azurerm/resource_arm_backup_policy_file_share.go rename to azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share.go index d43b7986b7c7..335d9c1346e2 100644 --- a/azurerm/resource_arm_backup_policy_file_share.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "context" diff --git a/azurerm/resource_arm_backup_policy_file_share_test.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share_test.go similarity index 99% rename from azurerm/resource_arm_backup_policy_file_share_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share_test.go index 731496ad4319..9c46e43e45c5 100644 --- a/azurerm/resource_arm_backup_policy_file_share_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_backup_policy_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm.go similarity index 99% rename from azurerm/resource_arm_backup_policy_vm.go rename to azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm.go index 23240bdc93da..70c5b7491de1 100644 --- a/azurerm/resource_arm_backup_policy_vm.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "context" diff --git a/azurerm/resource_arm_backup_policy_vm_test.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm_test.go similarity index 99% rename from azurerm/resource_arm_backup_policy_vm_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm_test.go index 74f8a6f62be1..2cdae67211fd 100644 --- a/azurerm/resource_arm_backup_policy_vm_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_backup_protected_file_share.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go similarity index 98% rename from azurerm/resource_arm_backup_protected_file_share.go rename to azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go index 97ab7aba6172..adffec0ab457 100644 --- a/azurerm/resource_arm_backup_protected_file_share.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "context" @@ -14,6 +14,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -58,7 +59,7 @@ func resourceArmBackupProtectedFileShare() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageShareName, + ValidateFunc: storage.ValidateArmStorageShareName, }, "backup_policy_id": { diff --git a/azurerm/resource_arm_backup_protected_file_share_test.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share_test.go similarity index 99% rename from azurerm/resource_arm_backup_protected_file_share_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share_test.go index d16310b643c9..849063daad2f 100644 --- a/azurerm/resource_arm_backup_protected_file_share_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_backup_protected_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm.go similarity index 99% rename from azurerm/resource_arm_backup_protected_vm.go rename to azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm.go index 5199448ae5dc..233ad772852a 100644 --- a/azurerm/resource_arm_backup_protected_vm.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "context" diff --git a/azurerm/resource_arm_backup_protected_vm_test.go b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm_test.go similarity index 99% rename from azurerm/resource_arm_backup_protected_vm_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm_test.go index 3c186b076549..532943eab0bc 100644 --- a/azurerm/resource_arm_backup_protected_vm_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_fabric.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric.go similarity index 99% rename from azurerm/resource_arm_recovery_services_fabric.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric.go index 20a6ab31d02c..a0d9b8370b1a 100644 --- a/azurerm/resource_arm_recovery_services_fabric.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_fabric_test.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric_test.go similarity index 99% rename from azurerm/resource_arm_recovery_services_fabric_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric_test.go index 748e773ea9f6..ea0d1a446895 100644 --- a/azurerm/resource_arm_recovery_services_fabric_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_network_mapping.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping.go similarity index 99% rename from azurerm/resource_arm_recovery_services_network_mapping.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping.go index 03e959f90cf9..bd4df6b68f46 100644 --- a/azurerm/resource_arm_recovery_services_network_mapping.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_network_mapping_test.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping_test.go similarity index 99% rename from azurerm/resource_arm_recovery_services_network_mapping_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping_test.go index c4ad9aeed268..6d7371e53519 100644 --- a/azurerm/resource_arm_recovery_services_network_mapping_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_protected_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm.go similarity index 99% rename from azurerm/resource_arm_recovery_services_protected_vm.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm.go index 429df25ec19f..5fefe166dbeb 100644 --- a/azurerm/resource_arm_recovery_services_protected_vm.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "context" diff --git a/azurerm/resource_arm_recovery_services_protected_vm_test.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm_test.go similarity index 99% rename from azurerm/resource_arm_recovery_services_protected_vm_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm_test.go index 95ad5c9c343c..41861ca7830d 100644 --- a/azurerm/resource_arm_recovery_services_protected_vm_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_protection_container.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container.go similarity index 99% rename from azurerm/resource_arm_recovery_services_protection_container.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container.go index bef182c88114..ebc27bf6468d 100644 --- a/azurerm/resource_arm_recovery_services_protection_container.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_protection_container_mapping.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping.go similarity index 99% rename from azurerm/resource_arm_recovery_services_protection_container_mapping.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping.go index 3dee63bd67b5..7d6dc12c2260 100644 --- a/azurerm/resource_arm_recovery_services_protection_container_mapping.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_protection_container_mapping_test.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping_test.go similarity index 99% rename from azurerm/resource_arm_recovery_services_protection_container_mapping_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping_test.go index 1e39dfb23b68..ef090b3f6d71 100644 --- a/azurerm/resource_arm_recovery_services_protection_container_mapping_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_protection_container_test.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_test.go similarity index 99% rename from azurerm/resource_arm_recovery_services_protection_container_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_test.go index b9c4be3b044c..bee0ef0930d5 100644 --- a/azurerm/resource_arm_recovery_services_protection_container_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_protection_policy_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm.go similarity index 99% rename from azurerm/resource_arm_recovery_services_protection_policy_vm.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm.go index a9716b697061..5f0aea03a2dd 100644 --- a/azurerm/resource_arm_recovery_services_protection_policy_vm.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "context" diff --git a/azurerm/resource_arm_recovery_services_protection_policy_vm_test.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm_test.go similarity index 99% rename from azurerm/resource_arm_recovery_services_protection_policy_vm_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm_test.go index dd0b37f68a8e..f9b27a6ba5b3 100644 --- a/azurerm/resource_arm_recovery_services_protection_policy_vm_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_replicated_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm.go similarity index 99% rename from azurerm/resource_arm_recovery_services_replicated_vm.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm.go index d581ef6e96c5..44c1316aa777 100644 --- a/azurerm/resource_arm_recovery_services_replicated_vm.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "bytes" diff --git a/azurerm/resource_arm_recovery_services_replicated_vm_test.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm_test.go similarity index 99% rename from azurerm/resource_arm_recovery_services_replicated_vm_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm_test.go index 3ce86f96450f..d04b28684004 100644 --- a/azurerm/resource_arm_recovery_services_replicated_vm_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_replication_policy.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy.go similarity index 99% rename from azurerm/resource_arm_recovery_services_replication_policy.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy.go index d56217632ec3..7e270398e3aa 100644 --- a/azurerm/resource_arm_recovery_services_replication_policy.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_replication_policy_test.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy_test.go similarity index 99% rename from azurerm/resource_arm_recovery_services_replication_policy_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy_test.go index 2d670abd6771..289e3e9be16b 100644 --- a/azurerm/resource_arm_recovery_services_replication_policy_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_vault.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_vault.go similarity index 99% rename from azurerm/resource_arm_recovery_services_vault.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_vault.go index 20d5b454260b..11e96a8ec989 100644 --- a/azurerm/resource_arm_recovery_services_vault.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_vault.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_recovery_services_vault_test.go b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_vault_test.go similarity index 99% rename from azurerm/resource_arm_recovery_services_vault_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_recovery_services_vault_test.go index 93d2063eaad4..01acf72c4328 100644 --- a/azurerm/resource_arm_recovery_services_vault_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_vault_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_fabric.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_fabric.go similarity index 99% rename from azurerm/resource_arm_site_recovery_fabric.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_fabric.go index 473fa641107f..b5b1b4311013 100644 --- a/azurerm/resource_arm_site_recovery_fabric.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_fabric.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_fabric_test.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_fabric_test.go similarity index 99% rename from azurerm/resource_arm_site_recovery_fabric_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_fabric_test.go index 434c0d1e1396..5ea01cdff8e2 100644 --- a/azurerm/resource_arm_site_recovery_fabric_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_fabric_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_network_mapping.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping.go similarity index 99% rename from azurerm/resource_arm_site_recovery_network_mapping.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping.go index 71db42bd13a9..81486ba266ee 100644 --- a/azurerm/resource_arm_site_recovery_network_mapping.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_network_mapping_test.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping_test.go similarity index 99% rename from azurerm/resource_arm_site_recovery_network_mapping_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping_test.go index 31f5036fa009..8564422e9f1a 100644 --- a/azurerm/resource_arm_site_recovery_network_mapping_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_protection_container.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container.go similarity index 99% rename from azurerm/resource_arm_site_recovery_protection_container.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container.go index eb3d6abef282..6bfffc4178d3 100644 --- a/azurerm/resource_arm_site_recovery_protection_container.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_protection_container_mapping.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_mapping.go similarity index 99% rename from azurerm/resource_arm_site_recovery_protection_container_mapping.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_mapping.go index 430ca48f5ca1..6dbd54ab695b 100644 --- a/azurerm/resource_arm_site_recovery_protection_container_mapping.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_mapping.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_protection_container_mapping_test.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_mapping_test.go similarity index 99% rename from azurerm/resource_arm_site_recovery_protection_container_mapping_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_mapping_test.go index e782f4e21348..875f8551f9e5 100644 --- a/azurerm/resource_arm_site_recovery_protection_container_mapping_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_mapping_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_protection_container_test.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_test.go similarity index 99% rename from azurerm/resource_arm_site_recovery_protection_container_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_test.go index 4474c4e26565..c13df2a239e8 100644 --- a/azurerm/resource_arm_site_recovery_protection_container_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_replicated_vm.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replicated_vm.go similarity index 99% rename from azurerm/resource_arm_site_recovery_replicated_vm.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replicated_vm.go index 61d2fd89856d..6f702f503496 100644 --- a/azurerm/resource_arm_site_recovery_replicated_vm.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replicated_vm.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "bytes" diff --git a/azurerm/resource_arm_site_recovery_replicated_vm_test.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replicated_vm_test.go similarity index 99% rename from azurerm/resource_arm_site_recovery_replicated_vm_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replicated_vm_test.go index 339df23db902..dcbb91aeb5ef 100644 --- a/azurerm/resource_arm_site_recovery_replicated_vm_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replicated_vm_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_replication_policy.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replication_policy.go similarity index 99% rename from azurerm/resource_arm_site_recovery_replication_policy.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replication_policy.go index 1553c9bede24..786132c8e42b 100644 --- a/azurerm/resource_arm_site_recovery_replication_policy.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replication_policy.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/resource_arm_site_recovery_replication_policy_test.go b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replication_policy_test.go similarity index 99% rename from azurerm/resource_arm_site_recovery_replication_policy_test.go rename to azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replication_policy_test.go index 99377dc9866d..11a6cfc745ad 100644 --- a/azurerm/resource_arm_site_recovery_replication_policy_test.go +++ b/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replication_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package recoveryservices import ( "fmt" diff --git a/azurerm/internal/services/storage/validation.go b/azurerm/internal/services/storage/validation.go new file mode 100644 index 000000000000..3076e5d5eaf7 --- /dev/null +++ b/azurerm/internal/services/storage/validation.go @@ -0,0 +1,29 @@ +package storage + +import ( + "fmt" + "regexp" +) + +// Following the naming convention as laid out in the docs https://msdn.microsoft.com/library/azure/dn167011.aspx +func ValidateArmStorageShareName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "only lowercase alphanumeric characters and hyphens allowed in %q: %q", + k, value)) + } + if len(value) < 3 || len(value) > 63 { + errors = append(errors, fmt.Errorf( + "%q must be between 3 and 63 characters: %q", k, value)) + } + if regexp.MustCompile(`^-`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "%q cannot begin with a hyphen: %q", k, value)) + } + if regexp.MustCompile(`[-]{2,}`).MatchString(value) { + errors = append(errors, fmt.Errorf( + "%q does not allow consecutive hyphens: %q", k, value)) + } + return warnings, errors +} diff --git a/azurerm/internal/services/storage/validation_test.go b/azurerm/internal/services/storage/validation_test.go new file mode 100644 index 000000000000..5bfcf02b09a4 --- /dev/null +++ b/azurerm/internal/services/storage/validation_test.go @@ -0,0 +1,34 @@ +package storage + +import ( + "strings" + "testing" +) + +func TestValidateArmStorageShareName(t *testing.T) { + validNames := []string{ + "valid-name", + "valid02-name", + } + for _, v := range validNames { + _, errors := ValidateArmStorageShareName(v, "name") + if len(errors) != 0 { + t.Fatalf("%q should be a valid Share Name: %q", v, errors) + } + } + + invalidNames := []string{ + "InvalidName1", + "-invalidname1", + "invalid_name", + "invalid!", + "double-hyphen--invalid", + "ww", + strings.Repeat("w", 65), + } + for _, v := range invalidNames { + if _, errors := ValidateArmStorageShareName(v, "name"); len(errors) == 0 { + t.Fatalf("%q should be an invalid Share Name", v) + } + } +} diff --git a/azurerm/provider.go b/azurerm/provider.go index a0375e37aaa2..502f754ab2f1 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -34,8 +34,6 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip": dataSourceArmPublicIP(), "azurerm_public_ips": dataSourceArmPublicIPs(), "azurerm_public_ip_prefix": dataSourceArmPublicIpPrefix(), - "azurerm_recovery_services_vault": dataSourceArmRecoveryServicesVault(), - "azurerm_recovery_services_protection_policy_vm": dataSourceArmRecoveryServicesProtectionPolicyVm(), "azurerm_redis_cache": dataSourceArmRedisCache(), "azurerm_resources": dataSourceArmResources(), "azurerm_resource_group": dataSourceArmResourceGroup(), @@ -68,11 +66,6 @@ func Provider() terraform.ResourceProvider { "azurerm_application_gateway": resourceArmApplicationGateway(), "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_backup_container_storage_account": resourceArmBackupProtectionContainerStorageAccount(), - "azurerm_backup_policy_file_share": resourceArmBackupProtectionPolicyFileShare(), - "azurerm_backup_protected_file_share": resourceArmBackupProtectedFileShare(), - "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), - "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), "azurerm_bastion_host": resourceArmBastionHost(), "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_dashboard": resourceArmDashboard(), @@ -107,15 +100,6 @@ func Provider() terraform.ResourceProvider { "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), "azurerm_public_ip": resourceArmPublicIp(), "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), - "azurerm_recovery_network_mapping": resourceArmRecoveryServicesNetworkMapping(), - "azurerm_recovery_replicated_vm": resourceArmRecoveryServicesReplicatedVm(), - "azurerm_recovery_services_fabric": resourceArmRecoveryServicesFabric(), - "azurerm_recovery_services_protected_vm": resourceArmRecoveryServicesProtectedVm(), - "azurerm_recovery_services_protection_container": resourceArmRecoveryServicesProtectionContainer(), - "azurerm_recovery_services_protection_container_mapping": resourceArmRecoveryServicesProtectionContainerMapping(), - "azurerm_recovery_services_protection_policy_vm": resourceArmRecoveryServicesProtectionPolicyVm(), - "azurerm_recovery_services_replication_policy": resourceArmRecoveryServicesReplicationPolicy(), - "azurerm_recovery_services_vault": resourceArmRecoveryServicesVault(), "azurerm_redis_cache": resourceArmRedisCache(), "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), @@ -140,12 +124,6 @@ func Provider() terraform.ResourceProvider { "azurerm_shared_image_version": resourceArmSharedImageVersion(), "azurerm_shared_image": resourceArmSharedImage(), "azurerm_signalr_service": resourceArmSignalRService(), - "azurerm_site_recovery_fabric": resourceArmSiteRecoveryFabric(), - "azurerm_site_recovery_network_mapping": resourceArmSiteRecoveryNetworkMapping(), - "azurerm_site_recovery_protection_container": resourceArmSiteRecoveryProtectionContainer(), - "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), - "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), - "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), "azurerm_sql_database": resourceArmSqlDatabase(), "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), diff --git a/azurerm/resource_arm_storage_share.go b/azurerm/resource_arm_storage_share.go index ad2974914577..0b882638a61b 100644 --- a/azurerm/resource_arm_storage_share.go +++ b/azurerm/resource_arm_storage_share.go @@ -3,7 +3,6 @@ package azurerm import ( "fmt" "log" - "regexp" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -55,7 +54,7 @@ func resourceArmStorageShare() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageShareName, + ValidateFunc: storage.ValidateArmStorageShareName, }, "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), @@ -375,26 +374,3 @@ func flattenStorageShareACLs(input shares.GetACLResult) []interface{} { return result } - -// Following the naming convention as laid out in the docs https://msdn.microsoft.com/library/azure/dn167011.aspx -func validateArmStorageShareName(v interface{}, k string) (warnings []string, errors []error) { - value := v.(string) - if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) { - errors = append(errors, fmt.Errorf( - "only lowercase alphanumeric characters and hyphens allowed in %q: %q", - k, value)) - } - if len(value) < 3 || len(value) > 63 { - errors = append(errors, fmt.Errorf( - "%q must be between 3 and 63 characters: %q", k, value)) - } - if regexp.MustCompile(`^-`).MatchString(value) { - errors = append(errors, fmt.Errorf( - "%q cannot begin with a hyphen: %q", k, value)) - } - if regexp.MustCompile(`[-]{2,}`).MatchString(value) { - errors = append(errors, fmt.Errorf( - "%q does not allow consecutive hyphens: %q", k, value)) - } - return warnings, errors -} diff --git a/azurerm/resource_arm_storage_share_migration.go b/azurerm/resource_arm_storage_share_migration.go index 91beb62779b3..471c9f232578 100644 --- a/azurerm/resource_arm_storage_share_migration.go +++ b/azurerm/resource_arm_storage_share_migration.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/shares" ) @@ -20,7 +21,7 @@ func resourceStorageShareStateResourceV0V1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageShareName, + ValidateFunc: storage.ValidateArmStorageShareName, }, "resource_group_name": azure.SchemaResourceGroupName(), "storage_account_name": { diff --git a/azurerm/resource_arm_storage_share_test.go b/azurerm/resource_arm_storage_share_test.go index 4e7f91f6b25e..22af48d1719f 100644 --- a/azurerm/resource_arm_storage_share_test.go +++ b/azurerm/resource_arm_storage_share_test.go @@ -450,32 +450,3 @@ resource "azurerm_storage_account" "test" { } `, rInt, location, rString) } - -func TestValidateArmStorageShareName(t *testing.T) { - validNames := []string{ - "valid-name", - "valid02-name", - } - for _, v := range validNames { - _, errors := validateArmStorageShareName(v, "name") - if len(errors) != 0 { - t.Fatalf("%q should be a valid Share Name: %q", v, errors) - } - } - - invalidNames := []string{ - "InvalidName1", - "-invalidname1", - "invalid_name", - "invalid!", - "double-hyphen--invalid", - "ww", - strings.Repeat("w", 65), - } - for _, v := range invalidNames { - _, errors := validateArmStorageShareName(v, "name") - if len(errors) == 0 { - t.Fatalf("%q should be an invalid Share Name", v) - } - } -} From 6eea2493a1151b78748feb07a8173d05e2a0fa2d Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 18:59:53 -0800 Subject: [PATCH 048/203] redis --- .../redis}/data_source_redis_cache.go | 2 +- .../redis}/data_source_redis_cache_test.go | 2 +- .../internal/services/redis/registration.go | 9 +++-- .../redis}/resource_arm_redis_cache.go | 2 +- .../redis}/resource_arm_redis_cache_test.go | 2 +- .../resource_arm_redis_firewall_rule.go | 2 +- .../resource_arm_redis_firewall_rule_test.go | 2 +- azurerm/provider.go | 34 +++++++++---------- 8 files changed, 29 insertions(+), 26 deletions(-) rename azurerm/{ => internal/services/redis}/data_source_redis_cache.go (99%) rename azurerm/{ => internal/services/redis}/data_source_redis_cache_test.go (99%) rename azurerm/{ => internal/services/redis}/resource_arm_redis_cache.go (99%) rename azurerm/{ => internal/services/redis}/resource_arm_redis_cache_test.go (99%) rename azurerm/{ => internal/services/redis}/resource_arm_redis_firewall_rule.go (99%) rename azurerm/{ => internal/services/redis}/resource_arm_redis_firewall_rule_test.go (99%) diff --git a/azurerm/data_source_redis_cache.go b/azurerm/internal/services/redis/data_source_redis_cache.go similarity index 99% rename from azurerm/data_source_redis_cache.go rename to azurerm/internal/services/redis/data_source_redis_cache.go index ac86504387cb..13acf329f525 100644 --- a/azurerm/data_source_redis_cache.go +++ b/azurerm/internal/services/redis/data_source_redis_cache.go @@ -1,4 +1,4 @@ -package azurerm +package redis import ( "fmt" diff --git a/azurerm/data_source_redis_cache_test.go b/azurerm/internal/services/redis/data_source_redis_cache_test.go similarity index 99% rename from azurerm/data_source_redis_cache_test.go rename to azurerm/internal/services/redis/data_source_redis_cache_test.go index 3e75af2507a4..55c801789b00 100644 --- a/azurerm/data_source_redis_cache_test.go +++ b/azurerm/internal/services/redis/data_source_redis_cache_test.go @@ -1,4 +1,4 @@ -package azurerm +package redis import ( "fmt" diff --git a/azurerm/internal/services/redis/registration.go b/azurerm/internal/services/redis/registration.go index 4baa62cc54f3..1876b6453918 100644 --- a/azurerm/internal/services/redis/registration.go +++ b/azurerm/internal/services/redis/registration.go @@ -13,10 +13,15 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_redis_cache": dataSourceArmRedisCache(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_redis_cache": resourceArmRedisCache(), + "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), + } } diff --git a/azurerm/resource_arm_redis_cache.go b/azurerm/internal/services/redis/resource_arm_redis_cache.go similarity index 99% rename from azurerm/resource_arm_redis_cache.go rename to azurerm/internal/services/redis/resource_arm_redis_cache.go index a272263f51fb..f4eb7061d047 100644 --- a/azurerm/resource_arm_redis_cache.go +++ b/azurerm/internal/services/redis/resource_arm_redis_cache.go @@ -1,4 +1,4 @@ -package azurerm +package redis import ( "context" diff --git a/azurerm/resource_arm_redis_cache_test.go b/azurerm/internal/services/redis/resource_arm_redis_cache_test.go similarity index 99% rename from azurerm/resource_arm_redis_cache_test.go rename to azurerm/internal/services/redis/resource_arm_redis_cache_test.go index 619001f59f58..cd8f88adf6c6 100644 --- a/azurerm/resource_arm_redis_cache_test.go +++ b/azurerm/internal/services/redis/resource_arm_redis_cache_test.go @@ -1,4 +1,4 @@ -package azurerm +package redis import ( "fmt" diff --git a/azurerm/resource_arm_redis_firewall_rule.go b/azurerm/internal/services/redis/resource_arm_redis_firewall_rule.go similarity index 99% rename from azurerm/resource_arm_redis_firewall_rule.go rename to azurerm/internal/services/redis/resource_arm_redis_firewall_rule.go index 5cdaa5cc7bac..617b42041a49 100644 --- a/azurerm/resource_arm_redis_firewall_rule.go +++ b/azurerm/internal/services/redis/resource_arm_redis_firewall_rule.go @@ -1,4 +1,4 @@ -package azurerm +package redis import ( "fmt" diff --git a/azurerm/resource_arm_redis_firewall_rule_test.go b/azurerm/internal/services/redis/resource_arm_redis_firewall_rule_test.go similarity index 99% rename from azurerm/resource_arm_redis_firewall_rule_test.go rename to azurerm/internal/services/redis/resource_arm_redis_firewall_rule_test.go index afd560aaab3c..6d3cea5908d9 100644 --- a/azurerm/resource_arm_redis_firewall_rule_test.go +++ b/azurerm/internal/services/redis/resource_arm_redis_firewall_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package redis import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 502f754ab2f1..eb1704165d7a 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -34,22 +34,22 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip": dataSourceArmPublicIP(), "azurerm_public_ips": dataSourceArmPublicIPs(), "azurerm_public_ip_prefix": dataSourceArmPublicIpPrefix(), - "azurerm_redis_cache": dataSourceArmRedisCache(), - "azurerm_resources": dataSourceArmResources(), - "azurerm_resource_group": dataSourceArmResourceGroup(), - "azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(), - "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), - "azurerm_servicebus_namespace_authorization_rule": dataSourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_sql_server": dataSourceSqlServer(), - "azurerm_sql_database": dataSourceSqlDatabase(), - "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), - "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), - "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), - "azurerm_storage_account": dataSourceArmStorageAccount(), - "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), - "azurerm_subscription": dataSourceArmSubscription(), - "azurerm_subscriptions": dataSourceArmSubscriptions(), - "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), + + "azurerm_resources": dataSourceArmResources(), + "azurerm_resource_group": dataSourceArmResourceGroup(), + "azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(), + "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), + "azurerm_servicebus_namespace_authorization_rule": dataSourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_sql_server": dataSourceSqlServer(), + "azurerm_sql_database": dataSourceSqlDatabase(), + "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), + "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), + "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), + "azurerm_storage_account": dataSourceArmStorageAccount(), + "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), + "azurerm_subscription": dataSourceArmSubscription(), + "azurerm_subscriptions": dataSourceArmSubscriptions(), + "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), } resources := map[string]*schema.Resource{ @@ -100,8 +100,6 @@ func Provider() terraform.ResourceProvider { "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), "azurerm_public_ip": resourceArmPublicIp(), "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), - "azurerm_redis_cache": resourceArmRedisCache(), - "azurerm_redis_firewall_rule": resourceArmRedisFirewallRule(), "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), "azurerm_relay_namespace": resourceArmRelayNamespace(), "azurerm_resource_group": resourceArmResourceGroup(), From 378ac2821fb87f5aa0d9c75e3e364d252325bf06 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:01:15 -0800 Subject: [PATCH 049/203] relay --- .../internal/services/relay/registration.go | 5 +- .../resource_arm_relay_hybrid_connection.go | 2 +- ...source_arm_relay_hybrid_connection_test.go | 2 +- .../relay}/resource_arm_relay_namespace.go | 2 +- .../resource_arm_relay_namespace_test.go | 2 +- azurerm/provider.go | 68 +++++++++---------- 6 files changed, 40 insertions(+), 41 deletions(-) rename azurerm/{ => internal/services/relay}/resource_arm_relay_hybrid_connection.go (99%) rename azurerm/{ => internal/services/relay}/resource_arm_relay_hybrid_connection_test.go (99%) rename azurerm/{ => internal/services/relay}/resource_arm_relay_namespace.go (99%) rename azurerm/{ => internal/services/relay}/resource_arm_relay_namespace_test.go (99%) diff --git a/azurerm/internal/services/relay/registration.go b/azurerm/internal/services/relay/registration.go index f0cd295cc633..d5692c8dca53 100644 --- a/azurerm/internal/services/relay/registration.go +++ b/azurerm/internal/services/relay/registration.go @@ -18,5 +18,8 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), + "azurerm_relay_namespace": resourceArmRelayNamespace(), + } } diff --git a/azurerm/resource_arm_relay_hybrid_connection.go b/azurerm/internal/services/relay/resource_arm_relay_hybrid_connection.go similarity index 99% rename from azurerm/resource_arm_relay_hybrid_connection.go rename to azurerm/internal/services/relay/resource_arm_relay_hybrid_connection.go index d3a1d3e613bc..c9e39e03f2d7 100644 --- a/azurerm/resource_arm_relay_hybrid_connection.go +++ b/azurerm/internal/services/relay/resource_arm_relay_hybrid_connection.go @@ -1,4 +1,4 @@ -package azurerm +package relay import ( "context" diff --git a/azurerm/resource_arm_relay_hybrid_connection_test.go b/azurerm/internal/services/relay/resource_arm_relay_hybrid_connection_test.go similarity index 99% rename from azurerm/resource_arm_relay_hybrid_connection_test.go rename to azurerm/internal/services/relay/resource_arm_relay_hybrid_connection_test.go index 4dd16602291f..b43d63e8ee63 100644 --- a/azurerm/resource_arm_relay_hybrid_connection_test.go +++ b/azurerm/internal/services/relay/resource_arm_relay_hybrid_connection_test.go @@ -1,4 +1,4 @@ -package azurerm +package relay import ( "fmt" diff --git a/azurerm/resource_arm_relay_namespace.go b/azurerm/internal/services/relay/resource_arm_relay_namespace.go similarity index 99% rename from azurerm/resource_arm_relay_namespace.go rename to azurerm/internal/services/relay/resource_arm_relay_namespace.go index fe6dd821e65a..3890a8d03ce6 100644 --- a/azurerm/resource_arm_relay_namespace.go +++ b/azurerm/internal/services/relay/resource_arm_relay_namespace.go @@ -1,4 +1,4 @@ -package azurerm +package relay import ( "context" diff --git a/azurerm/resource_arm_relay_namespace_test.go b/azurerm/internal/services/relay/resource_arm_relay_namespace_test.go similarity index 99% rename from azurerm/resource_arm_relay_namespace_test.go rename to azurerm/internal/services/relay/resource_arm_relay_namespace_test.go index d2f27e13e215..3a71cf0a9b27 100644 --- a/azurerm/resource_arm_relay_namespace_test.go +++ b/azurerm/internal/services/relay/resource_arm_relay_namespace_test.go @@ -1,4 +1,4 @@ -package azurerm +package relay import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index eb1704165d7a..2a050629c084 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -8,24 +8,23 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - "azurerm_app_service_plan": dataSourceAppServicePlan(), - "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), - "azurerm_app_service": dataSourceArmAppService(), - "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), - "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), - "azurerm_image": dataSourceArmImage(), - "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), - "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), - "azurerm_key_vault": dataSourceArmKeyVault(), - "azurerm_lb": dataSourceArmLoadBalancer(), - "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), - "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), - "azurerm_platform_image": dataSourceArmPlatformImage(), - + "azurerm_app_service_plan": dataSourceAppServicePlan(), + "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), + "azurerm_app_service": dataSourceArmAppService(), + "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), + "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), + "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), + "azurerm_client_config": dataSourceArmClientConfig(), + "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), + "azurerm_image": dataSourceArmImage(), + "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), + "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), + "azurerm_key_vault": dataSourceArmKeyVault(), + "azurerm_lb": dataSourceArmLoadBalancer(), + "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), + "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), + "azurerm_platform_image": dataSourceArmPlatformImage(), "azurerm_private_link_endpoint_connection": dataSourceArmPrivateLinkEndpointConnection(), "azurerm_private_endpoint_connection": dataSourceArmPrivateEndpointConnection(), "azurerm_private_link_service": dataSourceArmPrivateLinkService(), @@ -34,22 +33,21 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip": dataSourceArmPublicIP(), "azurerm_public_ips": dataSourceArmPublicIPs(), "azurerm_public_ip_prefix": dataSourceArmPublicIpPrefix(), - - "azurerm_resources": dataSourceArmResources(), - "azurerm_resource_group": dataSourceArmResourceGroup(), - "azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(), - "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), - "azurerm_servicebus_namespace_authorization_rule": dataSourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_sql_server": dataSourceSqlServer(), - "azurerm_sql_database": dataSourceSqlDatabase(), - "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), - "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), - "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), - "azurerm_storage_account": dataSourceArmStorageAccount(), - "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), - "azurerm_subscription": dataSourceArmSubscription(), - "azurerm_subscriptions": dataSourceArmSubscriptions(), - "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), + "azurerm_resources": dataSourceArmResources(), + "azurerm_resource_group": dataSourceArmResourceGroup(), + "azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(), + "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), + "azurerm_servicebus_namespace_authorization_rule": dataSourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_sql_server": dataSourceSqlServer(), + "azurerm_sql_database": dataSourceSqlDatabase(), + "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), + "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), + "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), + "azurerm_storage_account": dataSourceArmStorageAccount(), + "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), + "azurerm_subscription": dataSourceArmSubscription(), + "azurerm_subscriptions": dataSourceArmSubscriptions(), + "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), } resources := map[string]*schema.Resource{ @@ -100,8 +98,6 @@ func Provider() terraform.ResourceProvider { "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), "azurerm_public_ip": resourceArmPublicIp(), "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), - "azurerm_relay_hybrid_connection": resourceArmHybridConnection(), - "azurerm_relay_namespace": resourceArmRelayNamespace(), "azurerm_resource_group": resourceArmResourceGroup(), "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), "azurerm_scheduler_job": resourceArmSchedulerJob(), From 606491ebcf8e3f80048c4ff7c6fdbfc623bb76a8 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:03:15 -0800 Subject: [PATCH 050/203] scheduler --- .../data_source_scheduler_job_collection.go | 2 +- ...ta_source_scheduler_job_collection_test.go | 2 +- .../services/scheduler/registration.go | 9 ++++-- .../scheduler}/resource_arm_scheduler_job.go | 2 +- .../resource_arm_scheduler_job_collection.go | 2 +- ...ource_arm_scheduler_job_collection_test.go | 2 +- .../resource_arm_scheduler_job_test.go | 2 +- azurerm/provider.go | 28 +++++++++---------- 8 files changed, 26 insertions(+), 23 deletions(-) rename azurerm/{ => internal/services/scheduler}/data_source_scheduler_job_collection.go (99%) rename azurerm/{ => internal/services/scheduler}/data_source_scheduler_job_collection_test.go (99%) rename azurerm/{ => internal/services/scheduler}/resource_arm_scheduler_job.go (99%) rename azurerm/{ => internal/services/scheduler}/resource_arm_scheduler_job_collection.go (99%) rename azurerm/{ => internal/services/scheduler}/resource_arm_scheduler_job_collection_test.go (99%) rename azurerm/{ => internal/services/scheduler}/resource_arm_scheduler_job_test.go (99%) diff --git a/azurerm/data_source_scheduler_job_collection.go b/azurerm/internal/services/scheduler/data_source_scheduler_job_collection.go similarity index 99% rename from azurerm/data_source_scheduler_job_collection.go rename to azurerm/internal/services/scheduler/data_source_scheduler_job_collection.go index 38c49390a267..51235aea12c5 100644 --- a/azurerm/data_source_scheduler_job_collection.go +++ b/azurerm/internal/services/scheduler/data_source_scheduler_job_collection.go @@ -1,4 +1,4 @@ -package azurerm +package scheduler import ( "fmt" diff --git a/azurerm/data_source_scheduler_job_collection_test.go b/azurerm/internal/services/scheduler/data_source_scheduler_job_collection_test.go similarity index 99% rename from azurerm/data_source_scheduler_job_collection_test.go rename to azurerm/internal/services/scheduler/data_source_scheduler_job_collection_test.go index 37a1501086d5..16a536978463 100644 --- a/azurerm/data_source_scheduler_job_collection_test.go +++ b/azurerm/internal/services/scheduler/data_source_scheduler_job_collection_test.go @@ -1,4 +1,4 @@ -package azurerm +package scheduler import ( "fmt" diff --git a/azurerm/internal/services/scheduler/registration.go b/azurerm/internal/services/scheduler/registration.go index fdd4e71cb79e..45c6f742dc79 100644 --- a/azurerm/internal/services/scheduler/registration.go +++ b/azurerm/internal/services/scheduler/registration.go @@ -13,10 +13,15 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), + "azurerm_scheduler_job": resourceArmSchedulerJob(), + } } diff --git a/azurerm/resource_arm_scheduler_job.go b/azurerm/internal/services/scheduler/resource_arm_scheduler_job.go similarity index 99% rename from azurerm/resource_arm_scheduler_job.go rename to azurerm/internal/services/scheduler/resource_arm_scheduler_job.go index 0febe4961b98..5f14b71b14a3 100644 --- a/azurerm/resource_arm_scheduler_job.go +++ b/azurerm/internal/services/scheduler/resource_arm_scheduler_job.go @@ -1,6 +1,6 @@ // nolint: megacheck // entire automation SDK has been depreciated in v21.3 in favor of logic apps, an entirely different service. -package azurerm +package scheduler import ( "bytes" diff --git a/azurerm/resource_arm_scheduler_job_collection.go b/azurerm/internal/services/scheduler/resource_arm_scheduler_job_collection.go similarity index 99% rename from azurerm/resource_arm_scheduler_job_collection.go rename to azurerm/internal/services/scheduler/resource_arm_scheduler_job_collection.go index bf95d94e7f0a..76f45a12b794 100644 --- a/azurerm/resource_arm_scheduler_job_collection.go +++ b/azurerm/internal/services/scheduler/resource_arm_scheduler_job_collection.go @@ -1,6 +1,6 @@ // nolint: megacheck // entire automation SDK has been depreciated in v21.3 in favor of logic apps, an entirely different service. -package azurerm +package scheduler import ( "fmt" diff --git a/azurerm/resource_arm_scheduler_job_collection_test.go b/azurerm/internal/services/scheduler/resource_arm_scheduler_job_collection_test.go similarity index 99% rename from azurerm/resource_arm_scheduler_job_collection_test.go rename to azurerm/internal/services/scheduler/resource_arm_scheduler_job_collection_test.go index c125b0ab51d1..b30d6a8a2b76 100644 --- a/azurerm/resource_arm_scheduler_job_collection_test.go +++ b/azurerm/internal/services/scheduler/resource_arm_scheduler_job_collection_test.go @@ -1,6 +1,6 @@ // nolint: megacheck // entire automation SDK has been depreciated in v21.3 in favor of logic apps, an entirely different service. -package azurerm +package scheduler import ( "fmt" diff --git a/azurerm/resource_arm_scheduler_job_test.go b/azurerm/internal/services/scheduler/resource_arm_scheduler_job_test.go similarity index 99% rename from azurerm/resource_arm_scheduler_job_test.go rename to azurerm/internal/services/scheduler/resource_arm_scheduler_job_test.go index a84c4a14d59f..0b35e2c36870 100644 --- a/azurerm/resource_arm_scheduler_job_test.go +++ b/azurerm/internal/services/scheduler/resource_arm_scheduler_job_test.go @@ -1,6 +1,6 @@ // nolint: megacheck // entire automation SDK has been depreciated in v21.3 in favor of logic apps, an entirely different service. -package azurerm +package scheduler import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 2a050629c084..b9d62df7f638 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -35,19 +35,19 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip_prefix": dataSourceArmPublicIpPrefix(), "azurerm_resources": dataSourceArmResources(), "azurerm_resource_group": dataSourceArmResourceGroup(), - "azurerm_scheduler_job_collection": dataSourceArmSchedulerJobCollection(), - "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), - "azurerm_servicebus_namespace_authorization_rule": dataSourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_sql_server": dataSourceSqlServer(), - "azurerm_sql_database": dataSourceSqlDatabase(), - "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), - "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), - "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), - "azurerm_storage_account": dataSourceArmStorageAccount(), - "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), - "azurerm_subscription": dataSourceArmSubscription(), - "azurerm_subscriptions": dataSourceArmSubscriptions(), - "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), + + "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), + "azurerm_servicebus_namespace_authorization_rule": dataSourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_sql_server": dataSourceSqlServer(), + "azurerm_sql_database": dataSourceSqlDatabase(), + "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), + "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), + "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), + "azurerm_storage_account": dataSourceArmStorageAccount(), + "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), + "azurerm_subscription": dataSourceArmSubscription(), + "azurerm_subscriptions": dataSourceArmSubscriptions(), + "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), } resources := map[string]*schema.Resource{ @@ -99,8 +99,6 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip": resourceArmPublicIp(), "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_scheduler_job_collection": resourceArmSchedulerJobCollection(), - "azurerm_scheduler_job": resourceArmSchedulerJob(), "azurerm_search_service": resourceArmSearchService(), "azurerm_security_center_contact": resourceArmSecurityCenterContact(), "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), From 1170b718f0fb674f854ee6f5dd040fe744d08f0b Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:05:15 -0800 Subject: [PATCH 051/203] search --- .../internal/services/search/registration.go | 4 +- .../search}/resource_arm_search_service.go | 2 +- .../resource_arm_search_service_test.go | 2 +- azurerm/provider.go | 98 +++++++++---------- 4 files changed, 54 insertions(+), 52 deletions(-) rename azurerm/{ => internal/services/search}/resource_arm_search_service.go (99%) rename azurerm/{ => internal/services/search}/resource_arm_search_service_test.go (99%) diff --git a/azurerm/internal/services/search/registration.go b/azurerm/internal/services/search/registration.go index e5b1eca31c7f..8d943980f593 100644 --- a/azurerm/internal/services/search/registration.go +++ b/azurerm/internal/services/search/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_search_service": resourceArmSearchService(), + } } diff --git a/azurerm/resource_arm_search_service.go b/azurerm/internal/services/search/resource_arm_search_service.go similarity index 99% rename from azurerm/resource_arm_search_service.go rename to azurerm/internal/services/search/resource_arm_search_service.go index c5391712a3d5..275332265e19 100644 --- a/azurerm/resource_arm_search_service.go +++ b/azurerm/internal/services/search/resource_arm_search_service.go @@ -1,4 +1,4 @@ -package azurerm +package search import ( "fmt" diff --git a/azurerm/resource_arm_search_service_test.go b/azurerm/internal/services/search/resource_arm_search_service_test.go similarity index 99% rename from azurerm/resource_arm_search_service_test.go rename to azurerm/internal/services/search/resource_arm_search_service_test.go index 21fd41fe69cb..469fcbd56de6 100644 --- a/azurerm/resource_arm_search_service_test.go +++ b/azurerm/internal/services/search/resource_arm_search_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package search import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index b9d62df7f638..150011e60f6d 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -99,55 +99,55 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip": resourceArmPublicIp(), "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_search_service": resourceArmSearchService(), - "azurerm_security_center_contact": resourceArmSecurityCenterContact(), - "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), - "azurerm_security_center_workspace": resourceArmSecurityCenterWorkspace(), - "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), - "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), - "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), - "azurerm_servicebus_queue": resourceArmServiceBusQueue(), - "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), - "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), - "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), - "azurerm_servicebus_topic": resourceArmServiceBusTopic(), - "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), - "azurerm_shared_image_version": resourceArmSharedImageVersion(), - "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_signalr_service": resourceArmSignalRService(), - "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), - "azurerm_sql_database": resourceArmSqlDatabase(), - "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), - "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), - "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), - "azurerm_sql_server": resourceArmSqlServer(), - "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), - "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_storage_table_entity": resourceArmStorageTableEntity(), - "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), - "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), - "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), - "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), - "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), - "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), - "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), - "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), - "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), - "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), - "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), - "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), - "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), + + "azurerm_security_center_contact": resourceArmSecurityCenterContact(), + "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), + "azurerm_security_center_workspace": resourceArmSecurityCenterWorkspace(), + "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), + "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), + "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), + "azurerm_servicebus_queue": resourceArmServiceBusQueue(), + "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), + "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), + "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), + "azurerm_servicebus_topic": resourceArmServiceBusTopic(), + "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), + "azurerm_shared_image_version": resourceArmSharedImageVersion(), + "azurerm_shared_image": resourceArmSharedImage(), + "azurerm_signalr_service": resourceArmSignalRService(), + "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), + "azurerm_sql_database": resourceArmSqlDatabase(), + "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), + "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), + "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), + "azurerm_sql_server": resourceArmSqlServer(), + "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), + "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_storage_table_entity": resourceArmStorageTableEntity(), + "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), + "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), + "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), + "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), + "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), + "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), + "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), + "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), + "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), + "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), + "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), + "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), } return provider.AzureProvider(dataSources, resources) From f6dd945be5d2519a9907a3af6aa1dd3789a370b8 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:07:00 -0800 Subject: [PATCH 052/203] securitycenter --- .../services/securitycenter/registration.go | 7 +- ...resource_arm_advanced_threat_protection.go | 7 +- ...rce_arm_advanced_threat_protection_test.go | 17 ++-- .../resource_arm_security_center_contact.go | 2 +- ...source_arm_security_center_contact_test.go | 2 +- ...rm_security_center_subscription_pricing.go | 2 +- ...curity_center_subscription_pricing_test.go | 2 +- .../resource_arm_security_center_test.go | 2 +- .../resource_arm_security_center_workspace.go | 2 +- ...urce_arm_security_center_workspace_test.go | 2 +- azurerm/provider.go | 95 +++++++++---------- 11 files changed, 69 insertions(+), 71 deletions(-) rename azurerm/{ => internal/services/securitycenter}/resource_arm_advanced_threat_protection.go (94%) rename azurerm/{ => internal/services/securitycenter}/resource_arm_advanced_threat_protection_test.go (93%) rename azurerm/{ => internal/services/securitycenter}/resource_arm_security_center_contact.go (99%) rename azurerm/{ => internal/services/securitycenter}/resource_arm_security_center_contact_test.go (99%) rename azurerm/{ => internal/services/securitycenter}/resource_arm_security_center_subscription_pricing.go (99%) rename azurerm/{ => internal/services/securitycenter}/resource_arm_security_center_subscription_pricing_test.go (99%) rename azurerm/{ => internal/services/securitycenter}/resource_arm_security_center_test.go (97%) rename azurerm/{ => internal/services/securitycenter}/resource_arm_security_center_workspace.go (99%) rename azurerm/{ => internal/services/securitycenter}/resource_arm_security_center_workspace_test.go (99%) diff --git a/azurerm/internal/services/securitycenter/registration.go b/azurerm/internal/services/securitycenter/registration.go index 13986f15d339..4a882785f5fa 100644 --- a/azurerm/internal/services/securitycenter/registration.go +++ b/azurerm/internal/services/securitycenter/registration.go @@ -18,5 +18,10 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_advanced_threat_protection": resourceArmAdvancedThreatProtection(), + "azurerm_security_center_contact": resourceArmSecurityCenterContact(), + "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), + "azurerm_security_center_workspace": resourceArmSecurityCenterWorkspace(), + } } diff --git a/azurerm/resource_arm_advanced_threat_protection.go b/azurerm/internal/services/securitycenter/resource_arm_advanced_threat_protection.go similarity index 94% rename from azurerm/resource_arm_advanced_threat_protection.go rename to azurerm/internal/services/securitycenter/resource_arm_advanced_threat_protection.go index 4be3f1e97afc..d5a5e666923b 100644 --- a/azurerm/resource_arm_advanced_threat_protection.go +++ b/azurerm/internal/services/securitycenter/resource_arm_advanced_threat_protection.go @@ -1,4 +1,4 @@ -package azurerm +package securitycenter import ( "fmt" @@ -11,7 +11,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/securitycenter" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -94,7 +93,7 @@ func resourceArmAdvancedThreatProtectionRead(d *schema.ResourceData, meta interf ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := securitycenter.ParseAdvancedThreatProtectionID(d.Id()) + id, err := ParseAdvancedThreatProtectionID(d.Id()) if err != nil { return err } @@ -123,7 +122,7 @@ func resourceArmAdvancedThreatProtectionDelete(d *schema.ResourceData, meta inte ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := securitycenter.ParseAdvancedThreatProtectionID(d.Id()) + id, err := ParseAdvancedThreatProtectionID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_advanced_threat_protection_test.go b/azurerm/internal/services/securitycenter/resource_arm_advanced_threat_protection_test.go similarity index 93% rename from azurerm/resource_arm_advanced_threat_protection_test.go rename to azurerm/internal/services/securitycenter/resource_arm_advanced_threat_protection_test.go index 3b454339521d..c9ded2bd5f1d 100644 --- a/azurerm/resource_arm_advanced_threat_protection_test.go +++ b/azurerm/internal/services/securitycenter/resource_arm_advanced_threat_protection_test.go @@ -1,4 +1,4 @@ -package azurerm +package securitycenter import ( "fmt" @@ -12,13 +12,12 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/securitycenter" ) func TestAccAzureRMAdvancedThreatProtection_storageAccount(t *testing.T) { rn := "azurerm_advanced_threat_protection.test" ri := tf.AccRandTimeInt() - var id securitycenter.AdvancedThreatProtectionResourceID + var id AdvancedThreatProtectionResourceID resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -62,7 +61,7 @@ func TestAccAzureRMAdvancedThreatProtection_storageAccount(t *testing.T) { func TestAccAzureRMAdvancedThreatProtection_cosmosAccount(t *testing.T) { rn := "azurerm_advanced_threat_protection.test" ri := tf.AccRandTimeInt() - var id securitycenter.AdvancedThreatProtectionResourceID + var id AdvancedThreatProtectionResourceID // the API errors on deleting the cosmos DB account some of the time so lets skip this test for now // TODO: remove once this is fixed: https://github.com/Azure/azure-sdk-for-go/issues/6310 @@ -116,7 +115,7 @@ func TestAccAzureRMAdvancedThreatProtection_requiresImport(t *testing.T) { rn := "azurerm_advanced_threat_protection.test" ri := tf.AccRandTimeInt() - var id securitycenter.AdvancedThreatProtectionResourceID + var id AdvancedThreatProtectionResourceID resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -143,7 +142,7 @@ func TestAccAzureRMAdvancedThreatProtection_requiresImport(t *testing.T) { }) } -func testCheckAzureRMAdvancedThreatProtectionExists(resourceName string, idToReturn *securitycenter.AdvancedThreatProtectionResourceID) resource.TestCheckFunc { +func testCheckAzureRMAdvancedThreatProtectionExists(resourceName string, idToReturn *AdvancedThreatProtectionResourceID) resource.TestCheckFunc { return func(s *terraform.State) error { // Ensure resource group exists in API client := acceptance.AzureProvider.Meta().(*clients.Client).SecurityCenter.AdvancedThreatProtectionClient @@ -155,7 +154,7 @@ func testCheckAzureRMAdvancedThreatProtectionExists(resourceName string, idToRet return fmt.Errorf("Not found: %s", resourceName) } - id, err := securitycenter.ParseAdvancedThreatProtectionID(rs.Primary.ID) + id, err := ParseAdvancedThreatProtectionID(rs.Primary.ID) if err != nil { return err } @@ -175,7 +174,7 @@ func testCheckAzureRMAdvancedThreatProtectionExists(resourceName string, idToRet } } -func testCheckAzureRMAdvancedThreatProtectionIsFalse(id *securitycenter.AdvancedThreatProtectionResourceID) resource.TestCheckFunc { +func testCheckAzureRMAdvancedThreatProtectionIsFalse(id *AdvancedThreatProtectionResourceID) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).SecurityCenter.AdvancedThreatProtectionClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -206,7 +205,7 @@ func testCheckAzureRMAdvancedThreatProtectionDestroy(s *terraform.State) error { continue } - id, err := securitycenter.ParseAdvancedThreatProtectionID(rs.Primary.ID) + id, err := ParseAdvancedThreatProtectionID(rs.Primary.ID) if err != nil { return err } diff --git a/azurerm/resource_arm_security_center_contact.go b/azurerm/internal/services/securitycenter/resource_arm_security_center_contact.go similarity index 99% rename from azurerm/resource_arm_security_center_contact.go rename to azurerm/internal/services/securitycenter/resource_arm_security_center_contact.go index a68e57494934..1784118550c7 100644 --- a/azurerm/resource_arm_security_center_contact.go +++ b/azurerm/internal/services/securitycenter/resource_arm_security_center_contact.go @@ -1,4 +1,4 @@ -package azurerm +package securitycenter import ( "fmt" diff --git a/azurerm/resource_arm_security_center_contact_test.go b/azurerm/internal/services/securitycenter/resource_arm_security_center_contact_test.go similarity index 99% rename from azurerm/resource_arm_security_center_contact_test.go rename to azurerm/internal/services/securitycenter/resource_arm_security_center_contact_test.go index 96852986f6e8..aacede40f7dd 100644 --- a/azurerm/resource_arm_security_center_contact_test.go +++ b/azurerm/internal/services/securitycenter/resource_arm_security_center_contact_test.go @@ -1,4 +1,4 @@ -package azurerm +package securitycenter import ( "fmt" diff --git a/azurerm/resource_arm_security_center_subscription_pricing.go b/azurerm/internal/services/securitycenter/resource_arm_security_center_subscription_pricing.go similarity index 99% rename from azurerm/resource_arm_security_center_subscription_pricing.go rename to azurerm/internal/services/securitycenter/resource_arm_security_center_subscription_pricing.go index 3950e0ecc44e..2d0674f04505 100644 --- a/azurerm/resource_arm_security_center_subscription_pricing.go +++ b/azurerm/internal/services/securitycenter/resource_arm_security_center_subscription_pricing.go @@ -1,4 +1,4 @@ -package azurerm +package securitycenter import ( "fmt" diff --git a/azurerm/resource_arm_security_center_subscription_pricing_test.go b/azurerm/internal/services/securitycenter/resource_arm_security_center_subscription_pricing_test.go similarity index 99% rename from azurerm/resource_arm_security_center_subscription_pricing_test.go rename to azurerm/internal/services/securitycenter/resource_arm_security_center_subscription_pricing_test.go index 36fce6ed1cd4..44b9045fb52c 100644 --- a/azurerm/resource_arm_security_center_subscription_pricing_test.go +++ b/azurerm/internal/services/securitycenter/resource_arm_security_center_subscription_pricing_test.go @@ -1,4 +1,4 @@ -package azurerm +package securitycenter import ( "fmt" diff --git a/azurerm/resource_arm_security_center_test.go b/azurerm/internal/services/securitycenter/resource_arm_security_center_test.go similarity index 97% rename from azurerm/resource_arm_security_center_test.go rename to azurerm/internal/services/securitycenter/resource_arm_security_center_test.go index ca4d8183993e..c02dbdf7b708 100644 --- a/azurerm/resource_arm_security_center_test.go +++ b/azurerm/internal/services/securitycenter/resource_arm_security_center_test.go @@ -1,4 +1,4 @@ -package azurerm +package securitycenter import ( "testing" diff --git a/azurerm/resource_arm_security_center_workspace.go b/azurerm/internal/services/securitycenter/resource_arm_security_center_workspace.go similarity index 99% rename from azurerm/resource_arm_security_center_workspace.go rename to azurerm/internal/services/securitycenter/resource_arm_security_center_workspace.go index 5bf35223c78c..5d35b9b93751 100644 --- a/azurerm/resource_arm_security_center_workspace.go +++ b/azurerm/internal/services/securitycenter/resource_arm_security_center_workspace.go @@ -1,4 +1,4 @@ -package azurerm +package securitycenter import ( "fmt" diff --git a/azurerm/resource_arm_security_center_workspace_test.go b/azurerm/internal/services/securitycenter/resource_arm_security_center_workspace_test.go similarity index 99% rename from azurerm/resource_arm_security_center_workspace_test.go rename to azurerm/internal/services/securitycenter/resource_arm_security_center_workspace_test.go index 38d4990ef97a..2cf4aa7bb720 100644 --- a/azurerm/resource_arm_security_center_workspace_test.go +++ b/azurerm/internal/services/securitycenter/resource_arm_security_center_workspace_test.go @@ -1,4 +1,4 @@ -package azurerm +package securitycenter import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 150011e60f6d..cb8da2fdaba3 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -51,7 +51,6 @@ func Provider() terraform.ResourceProvider { } resources := map[string]*schema.Resource{ - "azurerm_advanced_threat_protection": resourceArmAdvancedThreatProtection(), "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), "azurerm_app_service_certificate": resourceArmAppServiceCertificate(), "azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(), @@ -99,55 +98,51 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip": resourceArmPublicIp(), "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), "azurerm_resource_group": resourceArmResourceGroup(), - - "azurerm_security_center_contact": resourceArmSecurityCenterContact(), - "azurerm_security_center_subscription_pricing": resourceArmSecurityCenterSubscriptionPricing(), - "azurerm_security_center_workspace": resourceArmSecurityCenterWorkspace(), - "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), - "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), - "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), - "azurerm_servicebus_queue": resourceArmServiceBusQueue(), - "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), - "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), - "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), - "azurerm_servicebus_topic": resourceArmServiceBusTopic(), - "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), - "azurerm_shared_image_version": resourceArmSharedImageVersion(), - "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_signalr_service": resourceArmSignalRService(), - "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), - "azurerm_sql_database": resourceArmSqlDatabase(), - "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), - "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), - "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), - "azurerm_sql_server": resourceArmSqlServer(), - "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), - "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_storage_table_entity": resourceArmStorageTableEntity(), - "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), - "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), - "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), - "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), - "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), - "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), - "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), - "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), - "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), - "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), - "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), - "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), - "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), + "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), + "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), + "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), + "azurerm_servicebus_queue": resourceArmServiceBusQueue(), + "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), + "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), + "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), + "azurerm_servicebus_topic": resourceArmServiceBusTopic(), + "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), + "azurerm_shared_image_version": resourceArmSharedImageVersion(), + "azurerm_shared_image": resourceArmSharedImage(), + "azurerm_signalr_service": resourceArmSignalRService(), + "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), + "azurerm_sql_database": resourceArmSqlDatabase(), + "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), + "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), + "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), + "azurerm_sql_server": resourceArmSqlServer(), + "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), + "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_storage_table_entity": resourceArmStorageTableEntity(), + "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), + "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), + "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), + "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), + "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), + "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), + "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), + "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), + "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), + "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), + "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), + "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), } return provider.AzureProvider(dataSources, resources) From 0f21bd51dcd2a4b629e9a67f61874e0e212e2a16 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:08:45 -0800 Subject: [PATCH 053/203] servicebus --- .../data_source_servicebus_namespace.go | 2 +- ...servicebus_namespace_authorization_rule.go | 2 +- ...cebus_namespace_authorization_rule_test.go | 2 +- .../data_source_servicebus_namespace_test.go | 2 +- .../services/servicebus/registration.go | 16 ++++++++-- .../resource_arm_servicebus_namespace.go | 2 +- ...servicebus_namespace_authorization_rule.go | 2 +- ...cebus_namespace_authorization_rule_test.go | 2 +- ...urce_arm_servicebus_namespace_migration.go | 2 +- ...arm_servicebus_namespace_migration_test.go | 2 +- .../resource_arm_servicebus_namespace_test.go | 2 +- .../resource_arm_servicebus_queue.go | 2 +- ...arm_servicebus_queue_authorization_rule.go | 2 +- ...ervicebus_queue_authorization_rule_test.go | 2 +- .../resource_arm_servicebus_queue_test.go | 2 +- .../resource_arm_servicebus_subscription.go | 2 +- ...source_arm_servicebus_subscription_rule.go | 2 +- ...e_arm_servicebus_subscription_rule_test.go | 2 +- ...source_arm_servicebus_subscription_test.go | 2 +- .../resource_arm_servicebus_topic.go | 2 +- ...arm_servicebus_topic_authorization_rule.go | 2 +- ...ervicebus_topic_authorization_rule_test.go | 2 +- .../resource_arm_servicebus_topic_test.go | 2 +- azurerm/provider.go | 31 ++++++------------- 24 files changed, 46 insertions(+), 45 deletions(-) rename azurerm/{ => internal/services/servicebus}/data_source_servicebus_namespace.go (99%) rename azurerm/{ => internal/services/servicebus}/data_source_servicebus_namespace_authorization_rule.go (99%) rename azurerm/{ => internal/services/servicebus}/data_source_servicebus_namespace_authorization_rule_test.go (98%) rename azurerm/{ => internal/services/servicebus}/data_source_servicebus_namespace_test.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_namespace.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_namespace_authorization_rule.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_namespace_authorization_rule_test.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_namespace_migration.go (98%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_namespace_migration_test.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_namespace_test.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_queue.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_queue_authorization_rule.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_queue_authorization_rule_test.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_queue_test.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_subscription.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_subscription_rule.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_subscription_rule_test.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_subscription_test.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_topic.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_topic_authorization_rule.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_topic_authorization_rule_test.go (99%) rename azurerm/{ => internal/services/servicebus}/resource_arm_servicebus_topic_test.go (99%) diff --git a/azurerm/data_source_servicebus_namespace.go b/azurerm/internal/services/servicebus/data_source_servicebus_namespace.go similarity index 99% rename from azurerm/data_source_servicebus_namespace.go rename to azurerm/internal/services/servicebus/data_source_servicebus_namespace.go index 9a80831577a1..41a84df4a593 100644 --- a/azurerm/data_source_servicebus_namespace.go +++ b/azurerm/internal/services/servicebus/data_source_servicebus_namespace.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/data_source_servicebus_namespace_authorization_rule.go b/azurerm/internal/services/servicebus/data_source_servicebus_namespace_authorization_rule.go similarity index 99% rename from azurerm/data_source_servicebus_namespace_authorization_rule.go rename to azurerm/internal/services/servicebus/data_source_servicebus_namespace_authorization_rule.go index 8ffe5c304114..928f3c65e7f2 100644 --- a/azurerm/data_source_servicebus_namespace_authorization_rule.go +++ b/azurerm/internal/services/servicebus/data_source_servicebus_namespace_authorization_rule.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/data_source_servicebus_namespace_authorization_rule_test.go b/azurerm/internal/services/servicebus/data_source_servicebus_namespace_authorization_rule_test.go similarity index 98% rename from azurerm/data_source_servicebus_namespace_authorization_rule_test.go rename to azurerm/internal/services/servicebus/data_source_servicebus_namespace_authorization_rule_test.go index 0ffaa7cfda7b..83302924f702 100644 --- a/azurerm/data_source_servicebus_namespace_authorization_rule_test.go +++ b/azurerm/internal/services/servicebus/data_source_servicebus_namespace_authorization_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/data_source_servicebus_namespace_test.go b/azurerm/internal/services/servicebus/data_source_servicebus_namespace_test.go similarity index 99% rename from azurerm/data_source_servicebus_namespace_test.go rename to azurerm/internal/services/servicebus/data_source_servicebus_namespace_test.go index 52a95b1afb70..46a71667906f 100644 --- a/azurerm/data_source_servicebus_namespace_test.go +++ b/azurerm/internal/services/servicebus/data_source_servicebus_namespace_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/internal/services/servicebus/registration.go b/azurerm/internal/services/servicebus/registration.go index 8c62515d0d01..fada39cfffa3 100644 --- a/azurerm/internal/services/servicebus/registration.go +++ b/azurerm/internal/services/servicebus/registration.go @@ -13,10 +13,22 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), + "azurerm_servicebus_namespace_authorization_rule": dataSourceArmServiceBusNamespaceAuthorizationRule(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), + "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), + "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), + "azurerm_servicebus_queue": resourceArmServiceBusQueue(), + "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), + "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), + "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), + "azurerm_servicebus_topic": resourceArmServiceBusTopic(), + } } diff --git a/azurerm/resource_arm_servicebus_namespace.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace.go similarity index 99% rename from azurerm/resource_arm_servicebus_namespace.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_namespace.go index d445f9ae3e22..515853a66cce 100644 --- a/azurerm/resource_arm_servicebus_namespace.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_namespace_authorization_rule.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_authorization_rule.go similarity index 99% rename from azurerm/resource_arm_servicebus_namespace_authorization_rule.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_authorization_rule.go index 26e886fb27b1..f5fd09f3c098 100644 --- a/azurerm/resource_arm_servicebus_namespace_authorization_rule.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_authorization_rule.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_namespace_authorization_rule_test.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_authorization_rule_test.go similarity index 99% rename from azurerm/resource_arm_servicebus_namespace_authorization_rule_test.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_authorization_rule_test.go index 4530e13b8aa9..38f1b2aaf943 100644 --- a/azurerm/resource_arm_servicebus_namespace_authorization_rule_test.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_authorization_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_namespace_migration.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration.go similarity index 98% rename from azurerm/resource_arm_servicebus_namespace_migration.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration.go index e793ab82dc73..3e37dcdcc775 100644 --- a/azurerm/resource_arm_servicebus_namespace_migration.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_namespace_migration_test.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration_test.go similarity index 99% rename from azurerm/resource_arm_servicebus_namespace_migration_test.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration_test.go index aadcff39f637..2f4c2762c6b9 100644 --- a/azurerm/resource_arm_servicebus_namespace_migration_test.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "reflect" diff --git a/azurerm/resource_arm_servicebus_namespace_test.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_test.go similarity index 99% rename from azurerm/resource_arm_servicebus_namespace_test.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_test.go index b9bd77b7f3ac..37070be888ee 100644 --- a/azurerm/resource_arm_servicebus_namespace_test.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_queue.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_queue.go similarity index 99% rename from azurerm/resource_arm_servicebus_queue.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_queue.go index ccefbe5dc029..7aec18581bfa 100644 --- a/azurerm/resource_arm_servicebus_queue.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_queue.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_queue_authorization_rule.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_queue_authorization_rule.go similarity index 99% rename from azurerm/resource_arm_servicebus_queue_authorization_rule.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_queue_authorization_rule.go index e8af556bd356..895bd7ed1a15 100644 --- a/azurerm/resource_arm_servicebus_queue_authorization_rule.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_queue_authorization_rule.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_queue_authorization_rule_test.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_queue_authorization_rule_test.go similarity index 99% rename from azurerm/resource_arm_servicebus_queue_authorization_rule_test.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_queue_authorization_rule_test.go index b45e9cd0f7c1..84ad347d2669 100644 --- a/azurerm/resource_arm_servicebus_queue_authorization_rule_test.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_queue_authorization_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_queue_test.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_queue_test.go similarity index 99% rename from azurerm/resource_arm_servicebus_queue_test.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_queue_test.go index dbe8c87dc5a0..7ad254b3e716 100644 --- a/azurerm/resource_arm_servicebus_queue_test.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_queue_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_subscription.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription.go similarity index 99% rename from azurerm/resource_arm_servicebus_subscription.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_subscription.go index 9de398b8ede8..205de49464d6 100644 --- a/azurerm/resource_arm_servicebus_subscription.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_subscription_rule.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go similarity index 99% rename from azurerm/resource_arm_servicebus_subscription_rule.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go index 6a7e9665393a..c8f82a1d66d1 100644 --- a/azurerm/resource_arm_servicebus_subscription_rule.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_subscription_rule_test.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule_test.go similarity index 99% rename from azurerm/resource_arm_servicebus_subscription_rule_test.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule_test.go index f06d7969b608..1872b51f9cee 100644 --- a/azurerm/resource_arm_servicebus_subscription_rule_test.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_subscription_test.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_test.go similarity index 99% rename from azurerm/resource_arm_servicebus_subscription_test.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_test.go index 94d27cfca7cc..adf30315e3f1 100644 --- a/azurerm/resource_arm_servicebus_subscription_test.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_topic.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_topic.go similarity index 99% rename from azurerm/resource_arm_servicebus_topic.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_topic.go index f0d3ad883047..f7469aea6b57 100644 --- a/azurerm/resource_arm_servicebus_topic.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_topic.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_topic_authorization_rule.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_topic_authorization_rule.go similarity index 99% rename from azurerm/resource_arm_servicebus_topic_authorization_rule.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_topic_authorization_rule.go index ba1622ba041f..564ae867da01 100644 --- a/azurerm/resource_arm_servicebus_topic_authorization_rule.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_topic_authorization_rule.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_topic_authorization_rule_test.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_topic_authorization_rule_test.go similarity index 99% rename from azurerm/resource_arm_servicebus_topic_authorization_rule_test.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_topic_authorization_rule_test.go index 0b2363ee9f0a..662d6df6fec0 100644 --- a/azurerm/resource_arm_servicebus_topic_authorization_rule_test.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_topic_authorization_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/resource_arm_servicebus_topic_test.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_topic_test.go similarity index 99% rename from azurerm/resource_arm_servicebus_topic_test.go rename to azurerm/internal/services/servicebus/resource_arm_servicebus_topic_test.go index c26cee7c04a4..76ffee51b078 100644 --- a/azurerm/resource_arm_servicebus_topic_test.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_topic_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicebus import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index cb8da2fdaba3..c9ac36206d08 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -35,19 +35,16 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip_prefix": dataSourceArmPublicIpPrefix(), "azurerm_resources": dataSourceArmResources(), "azurerm_resource_group": dataSourceArmResourceGroup(), - - "azurerm_servicebus_namespace": dataSourceArmServiceBusNamespace(), - "azurerm_servicebus_namespace_authorization_rule": dataSourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_sql_server": dataSourceSqlServer(), - "azurerm_sql_database": dataSourceSqlDatabase(), - "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), - "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), - "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), - "azurerm_storage_account": dataSourceArmStorageAccount(), - "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), - "azurerm_subscription": dataSourceArmSubscription(), - "azurerm_subscriptions": dataSourceArmSubscriptions(), - "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), + "azurerm_sql_server": dataSourceSqlServer(), + "azurerm_sql_database": dataSourceSqlDatabase(), + "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), + "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), + "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), + "azurerm_storage_account": dataSourceArmStorageAccount(), + "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), + "azurerm_subscription": dataSourceArmSubscription(), + "azurerm_subscriptions": dataSourceArmSubscriptions(), + "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), } resources := map[string]*schema.Resource{ @@ -99,14 +96,6 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), "azurerm_resource_group": resourceArmResourceGroup(), "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), - "azurerm_servicebus_namespace_authorization_rule": resourceArmServiceBusNamespaceAuthorizationRule(), - "azurerm_servicebus_namespace": resourceArmServiceBusNamespace(), - "azurerm_servicebus_queue_authorization_rule": resourceArmServiceBusQueueAuthorizationRule(), - "azurerm_servicebus_queue": resourceArmServiceBusQueue(), - "azurerm_servicebus_subscription_rule": resourceArmServiceBusSubscriptionRule(), - "azurerm_servicebus_subscription": resourceArmServiceBusSubscription(), - "azurerm_servicebus_topic_authorization_rule": resourceArmServiceBusTopicAuthorizationRule(), - "azurerm_servicebus_topic": resourceArmServiceBusTopic(), "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), "azurerm_shared_image_version": resourceArmSharedImageVersion(), "azurerm_shared_image": resourceArmSharedImage(), From ffb3c57f1b5f54516c3239fbb471fc6130133386 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:11:17 -0800 Subject: [PATCH 054/203] servicefabric --- azurerm/internal/services/servicefabric/registration.go | 4 +++- .../servicefabric}/resource_arm_service_fabric_cluster.go | 2 +- .../resource_arm_service_fabric_cluster_test.go | 2 +- azurerm/provider.go | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) rename azurerm/{ => internal/services/servicefabric}/resource_arm_service_fabric_cluster.go (99%) rename azurerm/{ => internal/services/servicefabric}/resource_arm_service_fabric_cluster_test.go (99%) diff --git a/azurerm/internal/services/servicefabric/registration.go b/azurerm/internal/services/servicefabric/registration.go index 320639dd9d4c..1d515febfc16 100644 --- a/azurerm/internal/services/servicefabric/registration.go +++ b/azurerm/internal/services/servicefabric/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), + } } diff --git a/azurerm/resource_arm_service_fabric_cluster.go b/azurerm/internal/services/servicefabric/resource_arm_service_fabric_cluster.go similarity index 99% rename from azurerm/resource_arm_service_fabric_cluster.go rename to azurerm/internal/services/servicefabric/resource_arm_service_fabric_cluster.go index 3b045825df50..9ae57714a957 100644 --- a/azurerm/resource_arm_service_fabric_cluster.go +++ b/azurerm/internal/services/servicefabric/resource_arm_service_fabric_cluster.go @@ -1,4 +1,4 @@ -package azurerm +package servicefabric import ( "fmt" diff --git a/azurerm/resource_arm_service_fabric_cluster_test.go b/azurerm/internal/services/servicefabric/resource_arm_service_fabric_cluster_test.go similarity index 99% rename from azurerm/resource_arm_service_fabric_cluster_test.go rename to azurerm/internal/services/servicefabric/resource_arm_service_fabric_cluster_test.go index 49f122dac997..3dcdd1f87c1d 100644 --- a/azurerm/resource_arm_service_fabric_cluster_test.go +++ b/azurerm/internal/services/servicefabric/resource_arm_service_fabric_cluster_test.go @@ -1,4 +1,4 @@ -package azurerm +package servicefabric import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index c9ac36206d08..6ffa90e70b4b 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -95,7 +95,6 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip": resourceArmPublicIp(), "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_service_fabric_cluster": resourceArmServiceFabricCluster(), "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), "azurerm_shared_image_version": resourceArmSharedImageVersion(), "azurerm_shared_image": resourceArmSharedImage(), From e0be2b5aef4fac26c44c8df6fcf16bb273ceb41a Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:12:19 -0800 Subject: [PATCH 055/203] signalr --- azurerm/internal/services/signalr/registration.go | 4 +++- .../services/signalr}/resource_arm_signalr_service.go | 2 +- .../services/signalr}/resource_arm_signalr_service_test.go | 2 +- azurerm/provider.go | 1 - 4 files changed, 5 insertions(+), 4 deletions(-) rename azurerm/{ => internal/services/signalr}/resource_arm_signalr_service.go (99%) rename azurerm/{ => internal/services/signalr}/resource_arm_signalr_service_test.go (99%) diff --git a/azurerm/internal/services/signalr/registration.go b/azurerm/internal/services/signalr/registration.go index 75d3e71ade82..66c4d9ce2b96 100644 --- a/azurerm/internal/services/signalr/registration.go +++ b/azurerm/internal/services/signalr/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_signalr_service": resourceArmSignalRService(), + } } diff --git a/azurerm/resource_arm_signalr_service.go b/azurerm/internal/services/signalr/resource_arm_signalr_service.go similarity index 99% rename from azurerm/resource_arm_signalr_service.go rename to azurerm/internal/services/signalr/resource_arm_signalr_service.go index 6c8925e41955..2dff07d6b17c 100644 --- a/azurerm/resource_arm_signalr_service.go +++ b/azurerm/internal/services/signalr/resource_arm_signalr_service.go @@ -1,4 +1,4 @@ -package azurerm +package signalr import ( "fmt" diff --git a/azurerm/resource_arm_signalr_service_test.go b/azurerm/internal/services/signalr/resource_arm_signalr_service_test.go similarity index 99% rename from azurerm/resource_arm_signalr_service_test.go rename to azurerm/internal/services/signalr/resource_arm_signalr_service_test.go index d9ddfb6c3c80..b54ffe268166 100644 --- a/azurerm/resource_arm_signalr_service_test.go +++ b/azurerm/internal/services/signalr/resource_arm_signalr_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package signalr import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 6ffa90e70b4b..bb50624274f0 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -98,7 +98,6 @@ func Provider() terraform.ResourceProvider { "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), "azurerm_shared_image_version": resourceArmSharedImageVersion(), "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_signalr_service": resourceArmSignalRService(), "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), "azurerm_sql_database": resourceArmSqlDatabase(), "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), From f5d958c172ba60ec5a1c4316463a69b0554f5358 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:15:22 -0800 Subject: [PATCH 056/203] sql --- .../services/sql}/data_source_sql_database.go | 2 +- .../sql}/data_source_sql_database_test.go | 2 +- .../services/sql}/data_source_sql_server.go | 2 +- .../services/sql}/data_source_sql_server_test.go | 2 +- azurerm/internal/services/sql/registration.go | 15 +++++++++++++-- .../sql}/resource_arm_sql_administrator.go | 2 +- .../sql}/resource_arm_sql_administrator_test.go | 2 +- .../services/sql}/resource_arm_sql_database.go | 2 +- .../sql}/resource_arm_sql_database_test.go | 2 +- .../services/sql}/resource_arm_sql_elasticpool.go | 2 +- .../sql}/resource_arm_sql_elasticpool_test.go | 2 +- .../sql}/resource_arm_sql_failover_group.go | 2 +- .../sql}/resource_arm_sql_failover_group_test.go | 2 +- .../sql}/resource_arm_sql_firewall_rule.go | 2 +- .../sql}/resource_arm_sql_firewall_rule_test.go | 2 +- .../services/sql}/resource_arm_sql_server.go | 2 +- .../services/sql}/resource_arm_sql_server_test.go | 2 +- .../sql}/resource_arm_sql_virtual_network_rule.go | 2 +- .../resource_arm_sql_virtual_network_rule_test.go | 2 +- azurerm/provider.go | 9 --------- azurerm/resource_arm_mssql_elasticpool.go | 11 ++++++++++- 21 files changed, 41 insertions(+), 30 deletions(-) rename azurerm/{ => internal/services/sql}/data_source_sql_database.go (99%) rename azurerm/{ => internal/services/sql}/data_source_sql_database_test.go (99%) rename azurerm/{ => internal/services/sql}/data_source_sql_server.go (99%) rename azurerm/{ => internal/services/sql}/data_source_sql_server_test.go (98%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_administrator.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_administrator_test.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_database.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_database_test.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_elasticpool.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_elasticpool_test.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_failover_group.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_failover_group_test.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_firewall_rule.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_firewall_rule_test.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_server.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_server_test.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_virtual_network_rule.go (99%) rename azurerm/{ => internal/services/sql}/resource_arm_sql_virtual_network_rule_test.go (99%) diff --git a/azurerm/data_source_sql_database.go b/azurerm/internal/services/sql/data_source_sql_database.go similarity index 99% rename from azurerm/data_source_sql_database.go rename to azurerm/internal/services/sql/data_source_sql_database.go index 455b6ec567c6..068a3fba2639 100644 --- a/azurerm/data_source_sql_database.go +++ b/azurerm/internal/services/sql/data_source_sql_database.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/data_source_sql_database_test.go b/azurerm/internal/services/sql/data_source_sql_database_test.go similarity index 99% rename from azurerm/data_source_sql_database_test.go rename to azurerm/internal/services/sql/data_source_sql_database_test.go index ef1c0e552993..2db52455675b 100644 --- a/azurerm/data_source_sql_database_test.go +++ b/azurerm/internal/services/sql/data_source_sql_database_test.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/data_source_sql_server.go b/azurerm/internal/services/sql/data_source_sql_server.go similarity index 99% rename from azurerm/data_source_sql_server.go rename to azurerm/internal/services/sql/data_source_sql_server.go index 3c30968a82cb..56b19d8b491d 100644 --- a/azurerm/data_source_sql_server.go +++ b/azurerm/internal/services/sql/data_source_sql_server.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/data_source_sql_server_test.go b/azurerm/internal/services/sql/data_source_sql_server_test.go similarity index 98% rename from azurerm/data_source_sql_server_test.go rename to azurerm/internal/services/sql/data_source_sql_server_test.go index 4ec6e1f26c78..2d2d7cd00cc9 100644 --- a/azurerm/data_source_sql_server_test.go +++ b/azurerm/internal/services/sql/data_source_sql_server_test.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/internal/services/sql/registration.go b/azurerm/internal/services/sql/registration.go index 6a91a8036a7c..c5bb17a61c8f 100644 --- a/azurerm/internal/services/sql/registration.go +++ b/azurerm/internal/services/sql/registration.go @@ -13,10 +13,21 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_sql_server": dataSourceSqlServer(), + "azurerm_sql_database": dataSourceSqlDatabase(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), + "azurerm_sql_database": resourceArmSqlDatabase(), + "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), + "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), + "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), + "azurerm_sql_server": resourceArmSqlServer(), + "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), + } } diff --git a/azurerm/resource_arm_sql_administrator.go b/azurerm/internal/services/sql/resource_arm_sql_administrator.go similarity index 99% rename from azurerm/resource_arm_sql_administrator.go rename to azurerm/internal/services/sql/resource_arm_sql_administrator.go index 3aa92cac4e49..0f3533ed8c38 100644 --- a/azurerm/resource_arm_sql_administrator.go +++ b/azurerm/internal/services/sql/resource_arm_sql_administrator.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_administrator_test.go b/azurerm/internal/services/sql/resource_arm_sql_administrator_test.go similarity index 99% rename from azurerm/resource_arm_sql_administrator_test.go rename to azurerm/internal/services/sql/resource_arm_sql_administrator_test.go index 026e2cbf736e..3d075fff9231 100644 --- a/azurerm/resource_arm_sql_administrator_test.go +++ b/azurerm/internal/services/sql/resource_arm_sql_administrator_test.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_database.go b/azurerm/internal/services/sql/resource_arm_sql_database.go similarity index 99% rename from azurerm/resource_arm_sql_database.go rename to azurerm/internal/services/sql/resource_arm_sql_database.go index 36229a937982..cf64faa23a88 100644 --- a/azurerm/resource_arm_sql_database.go +++ b/azurerm/internal/services/sql/resource_arm_sql_database.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_database_test.go b/azurerm/internal/services/sql/resource_arm_sql_database_test.go similarity index 99% rename from azurerm/resource_arm_sql_database_test.go rename to azurerm/internal/services/sql/resource_arm_sql_database_test.go index 99b374c54724..1eac5af96115 100644 --- a/azurerm/resource_arm_sql_database_test.go +++ b/azurerm/internal/services/sql/resource_arm_sql_database_test.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_elasticpool.go b/azurerm/internal/services/sql/resource_arm_sql_elasticpool.go similarity index 99% rename from azurerm/resource_arm_sql_elasticpool.go rename to azurerm/internal/services/sql/resource_arm_sql_elasticpool.go index ce7726ad5333..a85bb526a49f 100644 --- a/azurerm/resource_arm_sql_elasticpool.go +++ b/azurerm/internal/services/sql/resource_arm_sql_elasticpool.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_elasticpool_test.go b/azurerm/internal/services/sql/resource_arm_sql_elasticpool_test.go similarity index 99% rename from azurerm/resource_arm_sql_elasticpool_test.go rename to azurerm/internal/services/sql/resource_arm_sql_elasticpool_test.go index cbf4c8c77a53..356cf3b755f4 100644 --- a/azurerm/resource_arm_sql_elasticpool_test.go +++ b/azurerm/internal/services/sql/resource_arm_sql_elasticpool_test.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_failover_group.go b/azurerm/internal/services/sql/resource_arm_sql_failover_group.go similarity index 99% rename from azurerm/resource_arm_sql_failover_group.go rename to azurerm/internal/services/sql/resource_arm_sql_failover_group.go index 0372a64f3094..850490c073df 100644 --- a/azurerm/resource_arm_sql_failover_group.go +++ b/azurerm/internal/services/sql/resource_arm_sql_failover_group.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_failover_group_test.go b/azurerm/internal/services/sql/resource_arm_sql_failover_group_test.go similarity index 99% rename from azurerm/resource_arm_sql_failover_group_test.go rename to azurerm/internal/services/sql/resource_arm_sql_failover_group_test.go index 6f0aa56f8a73..d4e695e17326 100644 --- a/azurerm/resource_arm_sql_failover_group_test.go +++ b/azurerm/internal/services/sql/resource_arm_sql_failover_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_firewall_rule.go b/azurerm/internal/services/sql/resource_arm_sql_firewall_rule.go similarity index 99% rename from azurerm/resource_arm_sql_firewall_rule.go rename to azurerm/internal/services/sql/resource_arm_sql_firewall_rule.go index 96328e7b25e9..fa15cc9f2415 100644 --- a/azurerm/resource_arm_sql_firewall_rule.go +++ b/azurerm/internal/services/sql/resource_arm_sql_firewall_rule.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_firewall_rule_test.go b/azurerm/internal/services/sql/resource_arm_sql_firewall_rule_test.go similarity index 99% rename from azurerm/resource_arm_sql_firewall_rule_test.go rename to azurerm/internal/services/sql/resource_arm_sql_firewall_rule_test.go index e7183be4f612..9d40a5063b6c 100644 --- a/azurerm/resource_arm_sql_firewall_rule_test.go +++ b/azurerm/internal/services/sql/resource_arm_sql_firewall_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_server.go b/azurerm/internal/services/sql/resource_arm_sql_server.go similarity index 99% rename from azurerm/resource_arm_sql_server.go rename to azurerm/internal/services/sql/resource_arm_sql_server.go index 98d702a951be..648b3a820ed1 100644 --- a/azurerm/resource_arm_sql_server.go +++ b/azurerm/internal/services/sql/resource_arm_sql_server.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_server_test.go b/azurerm/internal/services/sql/resource_arm_sql_server_test.go similarity index 99% rename from azurerm/resource_arm_sql_server_test.go rename to azurerm/internal/services/sql/resource_arm_sql_server_test.go index 05e164fffa4d..64c9f62a09c8 100644 --- a/azurerm/resource_arm_sql_server_test.go +++ b/azurerm/internal/services/sql/resource_arm_sql_server_test.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/resource_arm_sql_virtual_network_rule.go b/azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule.go similarity index 99% rename from azurerm/resource_arm_sql_virtual_network_rule.go rename to azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule.go index 91ae073e8460..33681083dbc0 100644 --- a/azurerm/resource_arm_sql_virtual_network_rule.go +++ b/azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "context" diff --git a/azurerm/resource_arm_sql_virtual_network_rule_test.go b/azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule_test.go similarity index 99% rename from azurerm/resource_arm_sql_virtual_network_rule_test.go rename to azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule_test.go index fd35f6e4c124..b824ae51b72d 100644 --- a/azurerm/resource_arm_sql_virtual_network_rule_test.go +++ b/azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package sql import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index bb50624274f0..4ddd1e94e80e 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -35,8 +35,6 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip_prefix": dataSourceArmPublicIpPrefix(), "azurerm_resources": dataSourceArmResources(), "azurerm_resource_group": dataSourceArmResourceGroup(), - "azurerm_sql_server": dataSourceSqlServer(), - "azurerm_sql_database": dataSourceSqlDatabase(), "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), @@ -98,13 +96,6 @@ func Provider() terraform.ResourceProvider { "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), "azurerm_shared_image_version": resourceArmSharedImageVersion(), "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_sql_active_directory_administrator": resourceArmSqlAdministrator(), - "azurerm_sql_database": resourceArmSqlDatabase(), - "azurerm_sql_elasticpool": resourceArmSqlElasticPool(), - "azurerm_sql_failover_group": resourceArmSqlFailoverGroup(), - "azurerm_sql_firewall_rule": resourceArmSqlFirewallRule(), - "azurerm_sql_server": resourceArmSqlServer(), - "azurerm_sql_virtual_network_rule": resourceArmSqlVirtualNetworkRule(), "azurerm_storage_account": resourceArmStorageAccount(), "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), "azurerm_storage_blob": resourceArmStorageBlob(), diff --git a/azurerm/resource_arm_mssql_elasticpool.go b/azurerm/resource_arm_mssql_elasticpool.go index d7439d4c0485..2e6b3a6a07b0 100644 --- a/azurerm/resource_arm_mssql_elasticpool.go +++ b/azurerm/resource_arm_mssql_elasticpool.go @@ -340,7 +340,7 @@ func resourceArmMsSqlElasticPoolDelete(d *schema.ResourceData, meta interface{}) ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - resGroup, serverName, name, err := parseArmSqlElasticPoolId(d.Id()) + resGroup, serverName, name, err := parseArmMSSqlElasticPoolId(d.Id()) if err != nil { return err } @@ -444,3 +444,12 @@ func flattenAzureRmMsSqlElasticPoolPerDatabaseSettings(resp *sql.ElasticPoolPerD return []interface{}{perDatabaseSettings} } + +func parseArmMSSqlElasticPoolId(sqlElasticPoolId string) (string, string, string, error) { + id, err := azure.ParseAzureResourceID(sqlElasticPoolId) + if err != nil { + return "", "", "", fmt.Errorf("[ERROR] Unable to parse SQL ElasticPool ID %q: %+v", sqlElasticPoolId, err) + } + + return id.ResourceGroup, id.Path["servers"], id.Path["elasticPools"], nil +} From f3bc7178841b27511e5a877b12ff8af083e530f5 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:17:09 -0800 Subject: [PATCH 057/203] mssql --- .../mssql}/data_source_mssql_elasticpool.go | 2 +- .../data_source_mssql_elasticpool_test.go | 2 +- .../internal/services/mssql/registration.go | 11 +- ..._vulnerability_assessment_rule_baseline.go | 2 +- ...erability_assessment_rule_baseline_test.go | 2 +- .../mssql}/resource_arm_mssql_elasticpool.go | 2 +- .../resource_arm_mssql_elasticpool_test.go | 2 +- ..._arm_mssql_server_security_alert_policy.go | 2 +- ...mssql_server_security_alert_policy_test.go | 2 +- ...m_mssql_server_vulnerability_assessment.go | 2 +- ...ql_server_vulnerability_assessment_test.go | 2 +- azurerm/provider.go | 147 +++++++++--------- 12 files changed, 90 insertions(+), 88 deletions(-) rename azurerm/{ => internal/services/mssql}/data_source_mssql_elasticpool.go (99%) rename azurerm/{ => internal/services/mssql}/data_source_mssql_elasticpool_test.go (99%) rename azurerm/{ => internal/services/mssql}/resource_arm_mssql_database_vulnerability_assessment_rule_baseline.go (99%) rename azurerm/{ => internal/services/mssql}/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go (99%) rename azurerm/{ => internal/services/mssql}/resource_arm_mssql_elasticpool.go (99%) rename azurerm/{ => internal/services/mssql}/resource_arm_mssql_elasticpool_test.go (99%) rename azurerm/{ => internal/services/mssql}/resource_arm_mssql_server_security_alert_policy.go (99%) rename azurerm/{ => internal/services/mssql}/resource_arm_mssql_server_security_alert_policy_test.go (99%) rename azurerm/{ => internal/services/mssql}/resource_arm_mssql_server_vulnerability_assessment.go (99%) rename azurerm/{ => internal/services/mssql}/resource_arm_mssql_server_vulnerability_assessment_test.go (99%) diff --git a/azurerm/data_source_mssql_elasticpool.go b/azurerm/internal/services/mssql/data_source_mssql_elasticpool.go similarity index 99% rename from azurerm/data_source_mssql_elasticpool.go rename to azurerm/internal/services/mssql/data_source_mssql_elasticpool.go index 212fd19729c9..65b7809df256 100644 --- a/azurerm/data_source_mssql_elasticpool.go +++ b/azurerm/internal/services/mssql/data_source_mssql_elasticpool.go @@ -1,4 +1,4 @@ -package azurerm +package mssql import ( "fmt" diff --git a/azurerm/data_source_mssql_elasticpool_test.go b/azurerm/internal/services/mssql/data_source_mssql_elasticpool_test.go similarity index 99% rename from azurerm/data_source_mssql_elasticpool_test.go rename to azurerm/internal/services/mssql/data_source_mssql_elasticpool_test.go index 42858da485f5..349545b3c7ac 100644 --- a/azurerm/data_source_mssql_elasticpool_test.go +++ b/azurerm/internal/services/mssql/data_source_mssql_elasticpool_test.go @@ -1,4 +1,4 @@ -package azurerm +package mssql import ( "fmt" diff --git a/azurerm/internal/services/mssql/registration.go b/azurerm/internal/services/mssql/registration.go index 5fce694b2bd6..3cb495dca4c4 100644 --- a/azurerm/internal/services/mssql/registration.go +++ b/azurerm/internal/services/mssql/registration.go @@ -13,10 +13,17 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_mssql_elasticpool": resourceArmMsSqlElasticPool(), + "azurerm_mssql_database_vulnerability_assessment_rule_baseline": resourceArmMssqlDatabaseVulnerabilityAssessmentRuleBaseline(), + "azurerm_mssql_server_security_alert_policy": resourceArmMssqlServerSecurityAlertPolicy(), + "azurerm_mssql_server_vulnerability_assessment": resourceArmMssqlServerVulnerabilityAssessment(), + } } diff --git a/azurerm/resource_arm_mssql_database_vulnerability_assessment_rule_baseline.go b/azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline.go similarity index 99% rename from azurerm/resource_arm_mssql_database_vulnerability_assessment_rule_baseline.go rename to azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline.go index 8675099fd31b..b3bd11483cb3 100644 --- a/azurerm/resource_arm_mssql_database_vulnerability_assessment_rule_baseline.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline.go @@ -1,4 +1,4 @@ -package azurerm +package mssql import ( "fmt" diff --git a/azurerm/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go b/azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go similarity index 99% rename from azurerm/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go rename to azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go index 759a4b9ccfa5..1deec1323be7 100644 --- a/azurerm/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go @@ -1,4 +1,4 @@ -package azurerm +package mssql import ( "fmt" diff --git a/azurerm/resource_arm_mssql_elasticpool.go b/azurerm/internal/services/mssql/resource_arm_mssql_elasticpool.go similarity index 99% rename from azurerm/resource_arm_mssql_elasticpool.go rename to azurerm/internal/services/mssql/resource_arm_mssql_elasticpool.go index 2e6b3a6a07b0..04723f248ab6 100644 --- a/azurerm/resource_arm_mssql_elasticpool.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_elasticpool.go @@ -1,4 +1,4 @@ -package azurerm +package mssql import ( "fmt" diff --git a/azurerm/resource_arm_mssql_elasticpool_test.go b/azurerm/internal/services/mssql/resource_arm_mssql_elasticpool_test.go similarity index 99% rename from azurerm/resource_arm_mssql_elasticpool_test.go rename to azurerm/internal/services/mssql/resource_arm_mssql_elasticpool_test.go index 29367cd60acd..e4177a483e88 100644 --- a/azurerm/resource_arm_mssql_elasticpool_test.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_elasticpool_test.go @@ -1,4 +1,4 @@ -package azurerm +package mssql import ( "fmt" diff --git a/azurerm/resource_arm_mssql_server_security_alert_policy.go b/azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy.go similarity index 99% rename from azurerm/resource_arm_mssql_server_security_alert_policy.go rename to azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy.go index d2b7f7809085..268fcf909a47 100644 --- a/azurerm/resource_arm_mssql_server_security_alert_policy.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy.go @@ -1,4 +1,4 @@ -package azurerm +package mssql import ( "fmt" diff --git a/azurerm/resource_arm_mssql_server_security_alert_policy_test.go b/azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy_test.go similarity index 99% rename from azurerm/resource_arm_mssql_server_security_alert_policy_test.go rename to azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy_test.go index 8cb988026a12..88a24101c6ed 100644 --- a/azurerm/resource_arm_mssql_server_security_alert_policy_test.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package mssql import ( "fmt" diff --git a/azurerm/resource_arm_mssql_server_vulnerability_assessment.go b/azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment.go similarity index 99% rename from azurerm/resource_arm_mssql_server_vulnerability_assessment.go rename to azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment.go index 008003564b77..a985149da764 100644 --- a/azurerm/resource_arm_mssql_server_vulnerability_assessment.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment.go @@ -1,4 +1,4 @@ -package azurerm +package mssql import ( "fmt" diff --git a/azurerm/resource_arm_mssql_server_vulnerability_assessment_test.go b/azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment_test.go similarity index 99% rename from azurerm/resource_arm_mssql_server_vulnerability_assessment_test.go rename to azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment_test.go index 908a1e72dbd9..0cfe6834e82b 100644 --- a/azurerm/resource_arm_mssql_server_vulnerability_assessment_test.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment_test.go @@ -1,4 +1,4 @@ -package azurerm +package mssql import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 4ddd1e94e80e..68ac06ce2e67 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -23,7 +23,6 @@ func Provider() terraform.ResourceProvider { "azurerm_key_vault": dataSourceArmKeyVault(), "azurerm_lb": dataSourceArmLoadBalancer(), "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), - "azurerm_mssql_elasticpool": dataSourceArmMsSqlElasticpool(), "azurerm_platform_image": dataSourceArmPlatformImage(), "azurerm_private_link_endpoint_connection": dataSourceArmPrivateLinkEndpointConnection(), "azurerm_private_endpoint_connection": dataSourceArmPrivateEndpointConnection(), @@ -46,81 +45,77 @@ func Provider() terraform.ResourceProvider { } resources := map[string]*schema.Resource{ - "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), - "azurerm_app_service_certificate": resourceArmAppServiceCertificate(), - "azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(), - "azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(), - "azurerm_app_service_plan": resourceArmAppServicePlan(), - "azurerm_app_service_slot": resourceArmAppServiceSlot(), - "azurerm_app_service_source_control_token": resourceArmAppServiceSourceControlToken(), - "azurerm_app_service_virtual_network_swift_connection": resourceArmAppServiceVirtualNetworkSwiftConnection(), - "azurerm_app_service": resourceArmAppService(), - "azurerm_application_gateway": resourceArmApplicationGateway(), - "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), - "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_connection_monitor": resourceArmConnectionMonitor(), - "azurerm_dashboard": resourceArmDashboard(), - "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), - "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), - "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), - "azurerm_function_app": resourceArmFunctionApp(), - "azurerm_image": resourceArmImage(), - "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), - "azurerm_key_vault_key": resourceArmKeyVaultKey(), - "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), - "azurerm_key_vault": resourceArmKeyVault(), - "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), - "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), - "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), - "azurerm_lb_probe": resourceArmLoadBalancerProbe(), - "azurerm_lb_outbound_rule": resourceArmLoadBalancerOutboundRule(), - "azurerm_lb_rule": resourceArmLoadBalancerRule(), - "azurerm_lb": resourceArmLoadBalancer(), - "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), - "azurerm_mssql_elasticpool": resourceArmMsSqlElasticPool(), - "azurerm_mssql_database_vulnerability_assessment_rule_baseline": resourceArmMssqlDatabaseVulnerabilityAssessmentRuleBaseline(), - "azurerm_mssql_server_security_alert_policy": resourceArmMssqlServerSecurityAlertPolicy(), - "azurerm_mssql_server_vulnerability_assessment": resourceArmMssqlServerVulnerabilityAssessment(), - "azurerm_packet_capture": resourceArmPacketCapture(), - "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), - "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), - "azurerm_private_endpoint": resourceArmPrivateEndpoint(), - "azurerm_private_link_service": resourceArmPrivateLinkService(), - "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), - "azurerm_public_ip": resourceArmPublicIp(), - "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), - "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), - "azurerm_shared_image_version": resourceArmSharedImageVersion(), - "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), - "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_storage_table_entity": resourceArmStorageTableEntity(), - "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), - "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), - "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), - "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), - "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), - "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), - "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), - "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), - "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), - "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), - "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), - "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), - "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), + "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), + "azurerm_app_service_certificate": resourceArmAppServiceCertificate(), + "azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(), + "azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(), + "azurerm_app_service_plan": resourceArmAppServicePlan(), + "azurerm_app_service_slot": resourceArmAppServiceSlot(), + "azurerm_app_service_source_control_token": resourceArmAppServiceSourceControlToken(), + "azurerm_app_service_virtual_network_swift_connection": resourceArmAppServiceVirtualNetworkSwiftConnection(), + "azurerm_app_service": resourceArmAppService(), + "azurerm_application_gateway": resourceArmApplicationGateway(), + "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), + "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), + "azurerm_bastion_host": resourceArmBastionHost(), + "azurerm_connection_monitor": resourceArmConnectionMonitor(), + "azurerm_dashboard": resourceArmDashboard(), + "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), + "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), + "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), + "azurerm_function_app": resourceArmFunctionApp(), + "azurerm_image": resourceArmImage(), + "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), + "azurerm_key_vault_key": resourceArmKeyVaultKey(), + "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), + "azurerm_key_vault": resourceArmKeyVault(), + "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), + "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), + "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), + "azurerm_lb_probe": resourceArmLoadBalancerProbe(), + "azurerm_lb_outbound_rule": resourceArmLoadBalancerOutboundRule(), + "azurerm_lb_rule": resourceArmLoadBalancerRule(), + "azurerm_lb": resourceArmLoadBalancer(), + "azurerm_management_lock": resourceArmManagementLock(), + "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), + "azurerm_packet_capture": resourceArmPacketCapture(), + "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), + "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), + "azurerm_private_endpoint": resourceArmPrivateEndpoint(), + "azurerm_private_link_service": resourceArmPrivateLinkService(), + "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), + "azurerm_public_ip": resourceArmPublicIp(), + "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), + "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), + "azurerm_shared_image_version": resourceArmSharedImageVersion(), + "azurerm_shared_image": resourceArmSharedImage(), + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), + "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_storage_table_entity": resourceArmStorageTableEntity(), + "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), + "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), + "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), + "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), + "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), + "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), + "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), + "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), + "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), + "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), + "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), + "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), } return provider.AzureProvider(dataSources, resources) From 9fff7aa352d49dfe8b4045c32e80c7b052c058c8 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:19:51 -0800 Subject: [PATCH 058/203] streamanalytics --- .../data_source_stream_analytics_job.go | 2 +- .../data_source_stream_analytics_job_test.go | 2 +- .../services/streamanalytics/registration.go | 18 ++++++++++++++++-- ...tream_analytics_function_javascript_udf.go | 2 +- ..._analytics_function_javascript_udf_test.go | 2 +- .../resource_arm_stream_analytics_job.go | 2 +- .../resource_arm_stream_analytics_job_test.go | 2 +- ...source_arm_stream_analytics_output_blob.go | 2 +- ...e_arm_stream_analytics_output_blob_test.go | 2 +- ...ce_arm_stream_analytics_output_eventhub.go | 2 +- ...m_stream_analytics_output_eventhub_test.go | 2 +- ...ource_arm_stream_analytics_output_mssql.go | 2 +- ..._arm_stream_analytics_output_mssql_test.go | 2 +- ...tream_analytics_output_servicebus_queue.go | 2 +- ..._analytics_output_servicebus_queue_test.go | 2 +- ...tream_analytics_output_servicebus_topic.go | 2 +- ..._analytics_output_servicebus_topic_test.go | 2 +- ...m_stream_analytics_reference_input_blob.go | 2 +- ...eam_analytics_reference_input_blob_test.go | 2 +- ..._arm_stream_analytics_stream_input_blob.go | 2 +- ...stream_analytics_stream_input_blob_test.go | 2 +- ..._stream_analytics_stream_input_eventhub.go | 2 +- ...am_analytics_stream_input_eventhub_test.go | 2 +- ...rm_stream_analytics_stream_input_iothub.go | 2 +- ...ream_analytics_stream_input_iothub_test.go | 2 +- azurerm/provider.go | 19 ++++--------------- 26 files changed, 44 insertions(+), 41 deletions(-) rename azurerm/{ => internal/services/streamanalytics}/data_source_stream_analytics_job.go (99%) rename azurerm/{ => internal/services/streamanalytics}/data_source_stream_analytics_job_test.go (98%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_function_javascript_udf.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_function_javascript_udf_test.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_job.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_job_test.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_output_blob.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_output_blob_test.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_output_eventhub.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_output_eventhub_test.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_output_mssql.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_output_mssql_test.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_output_servicebus_queue.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_output_servicebus_queue_test.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_output_servicebus_topic.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_output_servicebus_topic_test.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_reference_input_blob.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_reference_input_blob_test.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_stream_input_blob.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_stream_input_blob_test.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_stream_input_eventhub.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_stream_input_eventhub_test.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_stream_input_iothub.go (99%) rename azurerm/{ => internal/services/streamanalytics}/resource_arm_stream_analytics_stream_input_iothub_test.go (99%) diff --git a/azurerm/data_source_stream_analytics_job.go b/azurerm/internal/services/streamanalytics/data_source_stream_analytics_job.go similarity index 99% rename from azurerm/data_source_stream_analytics_job.go rename to azurerm/internal/services/streamanalytics/data_source_stream_analytics_job.go index cf4c17b678f3..1368a11aaf61 100644 --- a/azurerm/data_source_stream_analytics_job.go +++ b/azurerm/internal/services/streamanalytics/data_source_stream_analytics_job.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/data_source_stream_analytics_job_test.go b/azurerm/internal/services/streamanalytics/data_source_stream_analytics_job_test.go similarity index 98% rename from azurerm/data_source_stream_analytics_job_test.go rename to azurerm/internal/services/streamanalytics/data_source_stream_analytics_job_test.go index 7847a4e23bff..5640cbb9e666 100644 --- a/azurerm/data_source_stream_analytics_job_test.go +++ b/azurerm/internal/services/streamanalytics/data_source_stream_analytics_job_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/internal/services/streamanalytics/registration.go b/azurerm/internal/services/streamanalytics/registration.go index 7da6767d0c92..2764a2feb81c 100644 --- a/azurerm/internal/services/streamanalytics/registration.go +++ b/azurerm/internal/services/streamanalytics/registration.go @@ -13,10 +13,24 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), + "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), + "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), + "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), + "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), + "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), + "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), + "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), + "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), + "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), + "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), + } } diff --git a/azurerm/resource_arm_stream_analytics_function_javascript_udf.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_function_javascript_udf.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_function_javascript_udf.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_function_javascript_udf.go index 5cbf078536ba..810f85a010e6 100644 --- a/azurerm/resource_arm_stream_analytics_function_javascript_udf.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_function_javascript_udf.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_function_javascript_udf_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_function_javascript_udf_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_function_javascript_udf_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_function_javascript_udf_test.go index ba7eb923a9ce..2e021c9afced 100644 --- a/azurerm/resource_arm_stream_analytics_function_javascript_udf_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_function_javascript_udf_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_job.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_job.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go index 72b7db9e7f8d..92ecd186f261 100644 --- a/azurerm/resource_arm_stream_analytics_job.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_job_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_job_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job_test.go index 77fd1930a1c4..edc50bfa9049 100644 --- a/azurerm/resource_arm_stream_analytics_job_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_output_blob.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_blob.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_output_blob.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_blob.go index 566d9f105313..8e44ae332799 100644 --- a/azurerm/resource_arm_stream_analytics_output_blob.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_blob.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_output_blob_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_blob_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_output_blob_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_blob_test.go index ce9118e1e16a..6cd6cbc3e57b 100644 --- a/azurerm/resource_arm_stream_analytics_output_blob_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_blob_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_output_eventhub.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_eventhub.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_output_eventhub.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_eventhub.go index 6d04c1aef9c0..ee37871fdc51 100644 --- a/azurerm/resource_arm_stream_analytics_output_eventhub.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_eventhub.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_output_eventhub_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_eventhub_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_output_eventhub_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_eventhub_test.go index aa5a92be5f3a..3a08a9ffb313 100644 --- a/azurerm/resource_arm_stream_analytics_output_eventhub_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_eventhub_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_output_mssql.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_mssql.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_output_mssql.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_mssql.go index 4962dd865632..22267dedd856 100644 --- a/azurerm/resource_arm_stream_analytics_output_mssql.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_mssql.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_output_mssql_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_mssql_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_output_mssql_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_mssql_test.go index e87a3b8e8c79..cdef3124c8ed 100644 --- a/azurerm/resource_arm_stream_analytics_output_mssql_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_mssql_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_output_servicebus_queue.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_queue.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_output_servicebus_queue.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_queue.go index 7f4380943391..cf41beabdd50 100644 --- a/azurerm/resource_arm_stream_analytics_output_servicebus_queue.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_queue.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_output_servicebus_queue_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_queue_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_output_servicebus_queue_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_queue_test.go index ac9736bff2eb..d053d81746b6 100644 --- a/azurerm/resource_arm_stream_analytics_output_servicebus_queue_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_queue_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_output_servicebus_topic.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_topic.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_output_servicebus_topic.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_topic.go index 78bf6d7fc192..3696e93a656f 100644 --- a/azurerm/resource_arm_stream_analytics_output_servicebus_topic.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_topic.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_output_servicebus_topic_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_topic_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_output_servicebus_topic_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_topic_test.go index 41d5a4e64b40..b7a2071c0580 100644 --- a/azurerm/resource_arm_stream_analytics_output_servicebus_topic_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_topic_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_reference_input_blob.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_reference_input_blob.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_reference_input_blob.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_reference_input_blob.go index b33f819ceffe..7125c4958db3 100644 --- a/azurerm/resource_arm_stream_analytics_reference_input_blob.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_reference_input_blob.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "context" diff --git a/azurerm/resource_arm_stream_analytics_reference_input_blob_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_reference_input_blob_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_reference_input_blob_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_reference_input_blob_test.go index ce9ec95e5769..c713b28a5a0c 100644 --- a/azurerm/resource_arm_stream_analytics_reference_input_blob_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_reference_input_blob_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_stream_input_blob.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_blob.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_stream_input_blob.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_blob.go index 8a621dc2ef85..431efb356d10 100644 --- a/azurerm/resource_arm_stream_analytics_stream_input_blob.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_blob.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_stream_input_blob_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_blob_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_stream_input_blob_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_blob_test.go index c92163fc2262..ee4969f82d8c 100644 --- a/azurerm/resource_arm_stream_analytics_stream_input_blob_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_blob_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_stream_input_eventhub.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_eventhub.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_stream_input_eventhub.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_eventhub.go index e97f7a21e00d..1d43813d8df6 100644 --- a/azurerm/resource_arm_stream_analytics_stream_input_eventhub.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_eventhub.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_stream_input_eventhub_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_eventhub_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_stream_input_eventhub_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_eventhub_test.go index 158a601a6d05..4c1f0a4d8f23 100644 --- a/azurerm/resource_arm_stream_analytics_stream_input_eventhub_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_eventhub_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_stream_input_iothub.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_iothub.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_stream_input_iothub.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_iothub.go index a62bde1dfa52..3a21c47a7247 100644 --- a/azurerm/resource_arm_stream_analytics_stream_input_iothub.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_iothub.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/resource_arm_stream_analytics_stream_input_iothub_test.go b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_iothub_test.go similarity index 99% rename from azurerm/resource_arm_stream_analytics_stream_input_iothub_test.go rename to azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_iothub_test.go index 22eed86ebafa..43d8bd67509c 100644 --- a/azurerm/resource_arm_stream_analytics_stream_input_iothub_test.go +++ b/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_iothub_test.go @@ -1,4 +1,4 @@ -package azurerm +package streamanalytics import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 68ac06ce2e67..e60ed021c9d5 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -34,7 +34,6 @@ func Provider() terraform.ResourceProvider { "azurerm_public_ip_prefix": dataSourceArmPublicIpPrefix(), "azurerm_resources": dataSourceArmResources(), "azurerm_resource_group": dataSourceArmResourceGroup(), - "azurerm_stream_analytics_job": dataSourceArmStreamAnalyticsJob(), "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), "azurerm_storage_account": dataSourceArmStorageAccount(), @@ -102,20 +101,10 @@ func Provider() terraform.ResourceProvider { "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), "azurerm_storage_table": resourceArmStorageTable(), "azurerm_storage_table_entity": resourceArmStorageTableEntity(), - "azurerm_stream_analytics_job": resourceArmStreamAnalyticsJob(), - "azurerm_stream_analytics_function_javascript_udf": resourceArmStreamAnalyticsFunctionUDF(), - "azurerm_stream_analytics_output_blob": resourceArmStreamAnalyticsOutputBlob(), - "azurerm_stream_analytics_output_mssql": resourceArmStreamAnalyticsOutputSql(), - "azurerm_stream_analytics_output_eventhub": resourceArmStreamAnalyticsOutputEventHub(), - "azurerm_stream_analytics_output_servicebus_queue": resourceArmStreamAnalyticsOutputServiceBusQueue(), - "azurerm_stream_analytics_output_servicebus_topic": resourceArmStreamAnalyticsOutputServiceBusTopic(), - "azurerm_stream_analytics_reference_input_blob": resourceArmStreamAnalyticsReferenceInputBlob(), - "azurerm_stream_analytics_stream_input_blob": resourceArmStreamAnalyticsStreamInputBlob(), - "azurerm_stream_analytics_stream_input_eventhub": resourceArmStreamAnalyticsStreamInputEventHub(), - "azurerm_stream_analytics_stream_input_iothub": resourceArmStreamAnalyticsStreamInputIoTHub(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), - "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), - "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), + + "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), + "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), } return provider.AzureProvider(dataSources, resources) From 6f932081b1512a543ac2ff26acf83658b83fb433 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:22:10 -0800 Subject: [PATCH 059/203] web --- .../services/web}/data_source_app_service.go | 2 +- .../data_source_app_service_certificate.go | 2 +- ...ta_source_app_service_certificate_order.go | 2 +- ...urce_app_service_certificate_order_test.go | 2 +- ...ata_source_app_service_certificate_test.go | 2 +- .../web}/data_source_app_service_plan.go | 2 +- .../web}/data_source_app_service_plan_test.go | 2 +- .../web}/data_source_app_service_test.go | 2 +- azurerm/internal/services/web/registration.go | 20 +++- .../services/web}/resource_arm_app_service.go | 11 +- .../resource_arm_app_service_active_slot.go | 7 +- ...source_arm_app_service_active_slot_test.go | 2 +- .../resource_arm_app_service_certificate.go | 9 +- ...ource_arm_app_service_certificate_order.go | 9 +- ..._arm_app_service_certificate_order_test.go | 2 +- ...source_arm_app_service_certificate_test.go | 2 +- ...arm_app_service_custom_hostname_binding.go | 9 +- ...pp_service_custom_hostname_binding_test.go | 2 +- .../web}/resource_arm_app_service_plan.go | 9 +- .../resource_arm_app_service_plan_test.go | 2 +- .../web}/resource_arm_app_service_slot.go | 11 +- .../resource_arm_app_service_slot_test.go | 2 +- ...ce_arm_app_service_source_control_token.go | 7 +- ...m_app_service_source_control_token_test.go | 2 +- .../web}/resource_arm_app_service_test.go | 2 +- ...app_service_virtual_network_association.go | 2 +- ...ervice_virtual_network_association_test.go | 2 +- .../web}/resource_arm_function_app.go | 13 +-- .../web}/resource_arm_function_app_test.go | 2 +- azurerm/provider.go | 108 ++++++++---------- 30 files changed, 122 insertions(+), 129 deletions(-) rename azurerm/{ => internal/services/web}/data_source_app_service.go (99%) rename azurerm/{ => internal/services/web}/data_source_app_service_certificate.go (99%) rename azurerm/{ => internal/services/web}/data_source_app_service_certificate_order.go (99%) rename azurerm/{ => internal/services/web}/data_source_app_service_certificate_order_test.go (99%) rename azurerm/{ => internal/services/web}/data_source_app_service_certificate_test.go (99%) rename azurerm/{ => internal/services/web}/data_source_app_service_plan.go (99%) rename azurerm/{ => internal/services/web}/data_source_app_service_plan_test.go (99%) rename azurerm/{ => internal/services/web}/data_source_app_service_test.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_app_service.go (98%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_active_slot.go (95%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_active_slot_test.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_certificate.go (96%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_certificate_order.go (97%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_certificate_order_test.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_certificate_test.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_custom_hostname_binding.go (95%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_custom_hostname_binding_test.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_plan.go (98%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_plan_test.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_slot.go (98%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_slot_test.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_source_control_token.go (95%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_source_control_token_test.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_test.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_virtual_network_association.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_app_service_virtual_network_association_test.go (99%) rename azurerm/{ => internal/services/web}/resource_arm_function_app.go (98%) rename azurerm/{ => internal/services/web}/resource_arm_function_app_test.go (99%) diff --git a/azurerm/data_source_app_service.go b/azurerm/internal/services/web/data_source_app_service.go similarity index 99% rename from azurerm/data_source_app_service.go rename to azurerm/internal/services/web/data_source_app_service.go index f937096acb34..3c7e66fbf02f 100644 --- a/azurerm/data_source_app_service.go +++ b/azurerm/internal/services/web/data_source_app_service.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/data_source_app_service_certificate.go b/azurerm/internal/services/web/data_source_app_service_certificate.go similarity index 99% rename from azurerm/data_source_app_service_certificate.go rename to azurerm/internal/services/web/data_source_app_service_certificate.go index 519a2e619b6e..8aa5e6467dd8 100644 --- a/azurerm/data_source_app_service_certificate.go +++ b/azurerm/internal/services/web/data_source_app_service_certificate.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/data_source_app_service_certificate_order.go b/azurerm/internal/services/web/data_source_app_service_certificate_order.go similarity index 99% rename from azurerm/data_source_app_service_certificate_order.go rename to azurerm/internal/services/web/data_source_app_service_certificate_order.go index 0f741f5b3112..42bc0bd75015 100644 --- a/azurerm/data_source_app_service_certificate_order.go +++ b/azurerm/internal/services/web/data_source_app_service_certificate_order.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/data_source_app_service_certificate_order_test.go b/azurerm/internal/services/web/data_source_app_service_certificate_order_test.go similarity index 99% rename from azurerm/data_source_app_service_certificate_order_test.go rename to azurerm/internal/services/web/data_source_app_service_certificate_order_test.go index 3d8771905dd8..de185e4b2e49 100644 --- a/azurerm/data_source_app_service_certificate_order_test.go +++ b/azurerm/internal/services/web/data_source_app_service_certificate_order_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/data_source_app_service_certificate_test.go b/azurerm/internal/services/web/data_source_app_service_certificate_test.go similarity index 99% rename from azurerm/data_source_app_service_certificate_test.go rename to azurerm/internal/services/web/data_source_app_service_certificate_test.go index 1d99a66534a1..b8ead3924528 100644 --- a/azurerm/data_source_app_service_certificate_test.go +++ b/azurerm/internal/services/web/data_source_app_service_certificate_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/data_source_app_service_plan.go b/azurerm/internal/services/web/data_source_app_service_plan.go similarity index 99% rename from azurerm/data_source_app_service_plan.go rename to azurerm/internal/services/web/data_source_app_service_plan.go index 67e780fb6e46..15a3f778fe0e 100644 --- a/azurerm/data_source_app_service_plan.go +++ b/azurerm/internal/services/web/data_source_app_service_plan.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/data_source_app_service_plan_test.go b/azurerm/internal/services/web/data_source_app_service_plan_test.go similarity index 99% rename from azurerm/data_source_app_service_plan_test.go rename to azurerm/internal/services/web/data_source_app_service_plan_test.go index 36aa33e6cfdf..80b350df3435 100644 --- a/azurerm/data_source_app_service_plan_test.go +++ b/azurerm/internal/services/web/data_source_app_service_plan_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/data_source_app_service_test.go b/azurerm/internal/services/web/data_source_app_service_test.go similarity index 99% rename from azurerm/data_source_app_service_test.go rename to azurerm/internal/services/web/data_source_app_service_test.go index 44a0acd84599..2308d9b8042e 100644 --- a/azurerm/data_source_app_service_test.go +++ b/azurerm/internal/services/web/data_source_app_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/internal/services/web/registration.go b/azurerm/internal/services/web/registration.go index 75171d2bc87b..ba51d8897cec 100644 --- a/azurerm/internal/services/web/registration.go +++ b/azurerm/internal/services/web/registration.go @@ -13,10 +13,26 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_app_service_plan": dataSourceAppServicePlan(), + "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), + "azurerm_app_service": dataSourceArmAppService(), + "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), + "azurerm_app_service_certificate": resourceArmAppServiceCertificate(), + "azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(), + "azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(), + "azurerm_app_service_plan": resourceArmAppServicePlan(), + "azurerm_app_service_slot": resourceArmAppServiceSlot(), + "azurerm_app_service_source_control_token": resourceArmAppServiceSourceControlToken(), + "azurerm_app_service_virtual_network_swift_connection": resourceArmAppServiceVirtualNetworkSwiftConnection(), + "azurerm_app_service": resourceArmAppService(), + "azurerm_function_app": resourceArmFunctionApp(), + } } diff --git a/azurerm/resource_arm_app_service.go b/azurerm/internal/services/web/resource_arm_app_service.go similarity index 98% rename from azurerm/resource_arm_app_service.go rename to azurerm/internal/services/web/resource_arm_app_service.go index 39403961e1f1..9ea6454b7a03 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/internal/services/web/resource_arm_app_service.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - webSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -28,7 +27,7 @@ func resourceArmAppService() *schema.Resource { Update: resourceArmAppServiceUpdate, Delete: resourceArmAppServiceDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := webSvc.ParseAppServiceID(id) + _, err := ParseAppServiceID(id) return err }), @@ -323,7 +322,7 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceID(d.Id()) + id, err := ParseAppServiceID(d.Id()) if err != nil { return err } @@ -512,7 +511,7 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error { ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceID(d.Id()) + id, err := ParseAppServiceID(d.Id()) if err != nil { return err } @@ -674,7 +673,7 @@ func resourceArmAppServiceDelete(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceID(d.Id()) + id, err := ParseAppServiceID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_app_service_active_slot.go b/azurerm/internal/services/web/resource_arm_app_service_active_slot.go similarity index 95% rename from azurerm/resource_arm_app_service_active_slot.go rename to azurerm/internal/services/web/resource_arm_app_service_active_slot.go index 8d8fca11f9d1..88697029b67a 100644 --- a/azurerm/resource_arm_app_service_active_slot.go +++ b/azurerm/internal/services/web/resource_arm_app_service_active_slot.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - webSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -22,7 +21,7 @@ func resourceArmAppServiceActiveSlot() *schema.Resource { Update: resourceArmAppServiceActiveSlotCreateUpdate, Delete: resourceArmAppServiceActiveSlotDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := webSvc.ParseAppServiceID(id) + _, err := ParseAppServiceID(id) return err }), @@ -98,7 +97,7 @@ func resourceArmAppServiceActiveSlotRead(d *schema.ResourceData, meta interface{ ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceID(d.Id()) + id, err := ParseAppServiceID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_app_service_active_slot_test.go b/azurerm/internal/services/web/resource_arm_app_service_active_slot_test.go similarity index 99% rename from azurerm/resource_arm_app_service_active_slot_test.go rename to azurerm/internal/services/web/resource_arm_app_service_active_slot_test.go index 5a7aaa79c866..d71254480d4b 100644 --- a/azurerm/resource_arm_app_service_active_slot_test.go +++ b/azurerm/internal/services/web/resource_arm_app_service_active_slot_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/resource_arm_app_service_certificate.go b/azurerm/internal/services/web/resource_arm_app_service_certificate.go similarity index 96% rename from azurerm/resource_arm_app_service_certificate.go rename to azurerm/internal/services/web/resource_arm_app_service_certificate.go index ccadcbd54f5c..deed19e8c1ce 100644 --- a/azurerm/resource_arm_app_service_certificate.go +++ b/azurerm/internal/services/web/resource_arm_app_service_certificate.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "encoding/base64" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - webSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -28,7 +27,7 @@ func resourceArmAppServiceCertificate() *schema.Resource { Update: resourceArmAppServiceCertificateCreateUpdate, Delete: resourceArmAppServiceCertificateDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := webSvc.ParseAppServiceCertificateID(id) + _, err := ParseAppServiceCertificateID(id) return err }), @@ -209,7 +208,7 @@ func resourceArmAppServiceCertificateRead(d *schema.ResourceData, meta interface ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceCertificateID(d.Id()) + id, err := ParseAppServiceCertificateID(d.Id()) if err != nil { return err } @@ -252,7 +251,7 @@ func resourceArmAppServiceCertificateDelete(d *schema.ResourceData, meta interfa ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceCertificateID(d.Id()) + id, err := ParseAppServiceCertificateID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_app_service_certificate_order.go b/azurerm/internal/services/web/resource_arm_app_service_certificate_order.go similarity index 97% rename from azurerm/resource_arm_app_service_certificate_order.go rename to azurerm/internal/services/web/resource_arm_app_service_certificate_order.go index b73847f07dbb..b18649fa76d2 100644 --- a/azurerm/resource_arm_app_service_certificate_order.go +++ b/azurerm/internal/services/web/resource_arm_app_service_certificate_order.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - webSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -28,7 +27,7 @@ func resourceArmAppServiceCertificateOrder() *schema.Resource { Update: resourceArmAppServiceCertificateOrderCreateUpdate, Delete: resourceArmAppServiceCertificateOrderDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := webSvc.ParseAppServiceCertificateOrderID(id) + _, err := ParseAppServiceCertificateOrderID(id) return err }), @@ -254,7 +253,7 @@ func resourceArmAppServiceCertificateOrderRead(d *schema.ResourceData, meta inte ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceCertificateOrderID(d.Id()) + id, err := ParseAppServiceCertificateOrderID(d.Id()) if err != nil { return err } @@ -323,7 +322,7 @@ func resourceArmAppServiceCertificateOrderDelete(d *schema.ResourceData, meta in ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceCertificateOrderID(d.Id()) + id, err := ParseAppServiceCertificateOrderID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_app_service_certificate_order_test.go b/azurerm/internal/services/web/resource_arm_app_service_certificate_order_test.go similarity index 99% rename from azurerm/resource_arm_app_service_certificate_order_test.go rename to azurerm/internal/services/web/resource_arm_app_service_certificate_order_test.go index 9f9416c04183..1a0dbba6a3a8 100644 --- a/azurerm/resource_arm_app_service_certificate_order_test.go +++ b/azurerm/internal/services/web/resource_arm_app_service_certificate_order_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/resource_arm_app_service_certificate_test.go b/azurerm/internal/services/web/resource_arm_app_service_certificate_test.go similarity index 99% rename from azurerm/resource_arm_app_service_certificate_test.go rename to azurerm/internal/services/web/resource_arm_app_service_certificate_test.go index 9b12f856f5da..877aeec598ed 100644 --- a/azurerm/resource_arm_app_service_certificate_test.go +++ b/azurerm/internal/services/web/resource_arm_app_service_certificate_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/resource_arm_app_service_custom_hostname_binding.go b/azurerm/internal/services/web/resource_arm_app_service_custom_hostname_binding.go similarity index 95% rename from azurerm/resource_arm_app_service_custom_hostname_binding.go rename to azurerm/internal/services/web/resource_arm_app_service_custom_hostname_binding.go index fb2fbf9c0f1f..be2f4d7cd2b5 100644 --- a/azurerm/resource_arm_app_service_custom_hostname_binding.go +++ b/azurerm/internal/services/web/resource_arm_app_service_custom_hostname_binding.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" - webSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -28,7 +27,7 @@ func resourceArmAppServiceCustomHostnameBinding() *schema.Resource { Read: resourceArmAppServiceCustomHostnameBindingRead, Delete: resourceArmAppServiceCustomHostnameBindingDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := webSvc.ParseAppServiceCustomHostnameBindingID(id) + _, err := ParseAppServiceCustomHostnameBindingID(id) return err }), @@ -152,7 +151,7 @@ func resourceArmAppServiceCustomHostnameBindingRead(d *schema.ResourceData, meta ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceCustomHostnameBindingID(d.Id()) + id, err := ParseAppServiceCustomHostnameBindingID(d.Id()) if err != nil { return err } @@ -189,7 +188,7 @@ func resourceArmAppServiceCustomHostnameBindingDelete(d *schema.ResourceData, me ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceCustomHostnameBindingID(d.Id()) + id, err := ParseAppServiceCustomHostnameBindingID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_app_service_custom_hostname_binding_test.go b/azurerm/internal/services/web/resource_arm_app_service_custom_hostname_binding_test.go similarity index 99% rename from azurerm/resource_arm_app_service_custom_hostname_binding_test.go rename to azurerm/internal/services/web/resource_arm_app_service_custom_hostname_binding_test.go index a5923b30e359..50eb6a4be27d 100644 --- a/azurerm/resource_arm_app_service_custom_hostname_binding_test.go +++ b/azurerm/internal/services/web/resource_arm_app_service_custom_hostname_binding_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/resource_arm_app_service_plan.go b/azurerm/internal/services/web/resource_arm_app_service_plan.go similarity index 98% rename from azurerm/resource_arm_app_service_plan.go rename to azurerm/internal/services/web/resource_arm_app_service_plan.go index 84edc355463c..885ee56dba11 100644 --- a/azurerm/resource_arm_app_service_plan.go +++ b/azurerm/internal/services/web/resource_arm_app_service_plan.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" @@ -15,7 +15,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - webSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -29,7 +28,7 @@ func resourceArmAppServicePlan() *schema.Resource { Update: resourceArmAppServicePlanCreateUpdate, Delete: resourceArmAppServicePlanDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := webSvc.ParseAppServicePlanID(id) + _, err := ParseAppServicePlanID(id) return err }), @@ -273,7 +272,7 @@ func resourceArmAppServicePlanRead(d *schema.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServicePlanID(d.Id()) + id, err := ParseAppServicePlanID(d.Id()) if err != nil { return err } @@ -340,7 +339,7 @@ func resourceArmAppServicePlanDelete(d *schema.ResourceData, meta interface{}) e ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServicePlanID(d.Id()) + id, err := ParseAppServicePlanID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_app_service_plan_test.go b/azurerm/internal/services/web/resource_arm_app_service_plan_test.go similarity index 99% rename from azurerm/resource_arm_app_service_plan_test.go rename to azurerm/internal/services/web/resource_arm_app_service_plan_test.go index 2b159607361c..4a4bf53b0643 100644 --- a/azurerm/resource_arm_app_service_plan_test.go +++ b/azurerm/internal/services/web/resource_arm_app_service_plan_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/resource_arm_app_service_slot.go b/azurerm/internal/services/web/resource_arm_app_service_slot.go similarity index 98% rename from azurerm/resource_arm_app_service_slot.go rename to azurerm/internal/services/web/resource_arm_app_service_slot.go index d14de8b9bb9e..ecb796d8bf78 100644 --- a/azurerm/resource_arm_app_service_slot.go +++ b/azurerm/internal/services/web/resource_arm_app_service_slot.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" @@ -13,7 +13,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - webSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -27,7 +26,7 @@ func resourceArmAppServiceSlot() *schema.Resource { Update: resourceArmAppServiceSlotCreateUpdate, Delete: resourceArmAppServiceSlotDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := webSvc.ParseAppServiceSlotID(id) + _, err := ParseAppServiceSlotID(id) return err }), @@ -243,7 +242,7 @@ func resourceArmAppServiceSlotUpdate(d *schema.ResourceData, meta interface{}) e ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceSlotID(d.Id()) + id, err := ParseAppServiceSlotID(d.Id()) if err != nil { return err } @@ -378,7 +377,7 @@ func resourceArmAppServiceSlotRead(d *schema.ResourceData, meta interface{}) err ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceSlotID(d.Id()) + id, err := ParseAppServiceSlotID(d.Id()) if err != nil { return err } @@ -512,7 +511,7 @@ func resourceArmAppServiceSlotDelete(d *schema.ResourceData, meta interface{}) e ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceSlotID(d.Id()) + id, err := ParseAppServiceSlotID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_app_service_slot_test.go b/azurerm/internal/services/web/resource_arm_app_service_slot_test.go similarity index 99% rename from azurerm/resource_arm_app_service_slot_test.go rename to azurerm/internal/services/web/resource_arm_app_service_slot_test.go index 1da2cc3aca47..9f23adf69ed7 100644 --- a/azurerm/resource_arm_app_service_slot_test.go +++ b/azurerm/internal/services/web/resource_arm_app_service_slot_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/resource_arm_app_service_source_control_token.go b/azurerm/internal/services/web/resource_arm_app_service_source_control_token.go similarity index 95% rename from azurerm/resource_arm_app_service_source_control_token.go rename to azurerm/internal/services/web/resource_arm_app_service_source_control_token.go index 0f7fb07fdafc..56071a354419 100644 --- a/azurerm/resource_arm_app_service_source_control_token.go +++ b/azurerm/internal/services/web/resource_arm_app_service_source_control_token.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" @@ -10,7 +10,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks" - webSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -25,7 +24,7 @@ func resourceArmAppServiceSourceControlToken() *schema.Resource { Update: resourceArmAppServiceSourceControlTokenCreateUpdate, Delete: resourceArmAppServiceSourceControlTokenDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := webSvc.ValidateAppServiceSourceControlTokenName()(id, "id") + _, err := ValidateAppServiceSourceControlTokenName()(id, "id") if len(err) > 0 { return fmt.Errorf("%s", err) } @@ -44,7 +43,7 @@ func resourceArmAppServiceSourceControlToken() *schema.Resource { "type": { Type: schema.TypeString, Required: true, - ValidateFunc: webSvc.ValidateAppServiceSourceControlTokenName(), + ValidateFunc: ValidateAppServiceSourceControlTokenName(), }, "token": { diff --git a/azurerm/resource_arm_app_service_source_control_token_test.go b/azurerm/internal/services/web/resource_arm_app_service_source_control_token_test.go similarity index 99% rename from azurerm/resource_arm_app_service_source_control_token_test.go rename to azurerm/internal/services/web/resource_arm_app_service_source_control_token_test.go index 70eb07c87e0c..c1eaa14ccfa6 100644 --- a/azurerm/resource_arm_app_service_source_control_token_test.go +++ b/azurerm/internal/services/web/resource_arm_app_service_source_control_token_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/resource_arm_app_service_test.go b/azurerm/internal/services/web/resource_arm_app_service_test.go similarity index 99% rename from azurerm/resource_arm_app_service_test.go rename to azurerm/internal/services/web/resource_arm_app_service_test.go index 15f609fca895..e177b6db7e7d 100644 --- a/azurerm/resource_arm_app_service_test.go +++ b/azurerm/internal/services/web/resource_arm_app_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/resource_arm_app_service_virtual_network_association.go b/azurerm/internal/services/web/resource_arm_app_service_virtual_network_association.go similarity index 99% rename from azurerm/resource_arm_app_service_virtual_network_association.go rename to azurerm/internal/services/web/resource_arm_app_service_virtual_network_association.go index 08a78d32a5ad..cd0a27de0ecb 100644 --- a/azurerm/resource_arm_app_service_virtual_network_association.go +++ b/azurerm/internal/services/web/resource_arm_app_service_virtual_network_association.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/resource_arm_app_service_virtual_network_association_test.go b/azurerm/internal/services/web/resource_arm_app_service_virtual_network_association_test.go similarity index 99% rename from azurerm/resource_arm_app_service_virtual_network_association_test.go rename to azurerm/internal/services/web/resource_arm_app_service_virtual_network_association_test.go index 635616458fb4..8bdce45f5b5e 100644 --- a/azurerm/resource_arm_app_service_virtual_network_association_test.go +++ b/azurerm/internal/services/web/resource_arm_app_service_virtual_network_association_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/resource_arm_function_app.go b/azurerm/internal/services/web/resource_arm_function_app.go similarity index 98% rename from azurerm/resource_arm_function_app.go rename to azurerm/internal/services/web/resource_arm_function_app.go index ef34163ecbd5..96f776392a62 100644 --- a/azurerm/resource_arm_function_app.go +++ b/azurerm/internal/services/web/resource_arm_function_app.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "context" @@ -15,7 +15,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - webSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -31,7 +30,7 @@ func resourceArmFunctionApp() *schema.Resource { Update: resourceArmFunctionAppUpdate, Delete: resourceArmFunctionAppDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := webSvc.ParseAppServiceID(id) + _, err := ParseAppServiceID(id) return err }), @@ -386,7 +385,7 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceID(d.Id()) + id, err := ParseAppServiceID(d.Id()) if err != nil { return err } @@ -494,7 +493,7 @@ func resourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) error ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceID(d.Id()) + id, err := ParseAppServiceID(d.Id()) if err != nil { return err } @@ -615,7 +614,7 @@ func resourceArmFunctionAppDelete(d *schema.ResourceData, meta interface{}) erro ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := webSvc.ParseAppServiceID(d.Id()) + id, err := ParseAppServiceID(d.Id()) if err != nil { return err } @@ -675,7 +674,7 @@ func getBasicFunctionAppAppSettings(d *schema.ResourceData, appServiceTier strin } func getFunctionAppServiceTier(ctx context.Context, appServicePlanId string, meta interface{}) (string, error) { - id, err := webSvc.ParseAppServicePlanID(appServicePlanId) + id, err := ParseAppServicePlanID(appServicePlanId) if err != nil { return "", fmt.Errorf("[ERROR] Unable to parse App Service Plan ID %q: %+v", appServicePlanId, err) } diff --git a/azurerm/resource_arm_function_app_test.go b/azurerm/internal/services/web/resource_arm_function_app_test.go similarity index 99% rename from azurerm/resource_arm_function_app_test.go rename to azurerm/internal/services/web/resource_arm_function_app_test.go index 9cfb888b07fc..b6c24660e1a2 100644 --- a/azurerm/resource_arm_function_app_test.go +++ b/azurerm/internal/services/web/resource_arm_function_app_test.go @@ -1,4 +1,4 @@ -package azurerm +package web import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index e60ed021c9d5..7cb6ef659be5 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -8,10 +8,6 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - "azurerm_app_service_plan": dataSourceAppServicePlan(), - "azurerm_app_service_certificate": dataSourceAppServiceCertificate(), - "azurerm_app_service": dataSourceArmAppService(), - "azurerm_app_service_certificate_order": dataSourceArmAppServiceCertificateOrder(), "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), @@ -44,63 +40,53 @@ func Provider() terraform.ResourceProvider { } resources := map[string]*schema.Resource{ - "azurerm_app_service_active_slot": resourceArmAppServiceActiveSlot(), - "azurerm_app_service_certificate": resourceArmAppServiceCertificate(), - "azurerm_app_service_certificate_order": resourceArmAppServiceCertificateOrder(), - "azurerm_app_service_custom_hostname_binding": resourceArmAppServiceCustomHostnameBinding(), - "azurerm_app_service_plan": resourceArmAppServicePlan(), - "azurerm_app_service_slot": resourceArmAppServiceSlot(), - "azurerm_app_service_source_control_token": resourceArmAppServiceSourceControlToken(), - "azurerm_app_service_virtual_network_swift_connection": resourceArmAppServiceVirtualNetworkSwiftConnection(), - "azurerm_app_service": resourceArmAppService(), - "azurerm_application_gateway": resourceArmApplicationGateway(), - "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), - "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_connection_monitor": resourceArmConnectionMonitor(), - "azurerm_dashboard": resourceArmDashboard(), - "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), - "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), - "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), - "azurerm_function_app": resourceArmFunctionApp(), - "azurerm_image": resourceArmImage(), - "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), - "azurerm_key_vault_key": resourceArmKeyVaultKey(), - "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), - "azurerm_key_vault": resourceArmKeyVault(), - "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), - "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), - "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), - "azurerm_lb_probe": resourceArmLoadBalancerProbe(), - "azurerm_lb_outbound_rule": resourceArmLoadBalancerOutboundRule(), - "azurerm_lb_rule": resourceArmLoadBalancerRule(), - "azurerm_lb": resourceArmLoadBalancer(), - "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), - "azurerm_packet_capture": resourceArmPacketCapture(), - "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), - "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), - "azurerm_private_endpoint": resourceArmPrivateEndpoint(), - "azurerm_private_link_service": resourceArmPrivateLinkService(), - "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), - "azurerm_public_ip": resourceArmPublicIp(), - "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), - "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), - "azurerm_shared_image_version": resourceArmSharedImageVersion(), - "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), - "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_storage_table_entity": resourceArmStorageTableEntity(), + "azurerm_application_gateway": resourceArmApplicationGateway(), + "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), + "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), + "azurerm_bastion_host": resourceArmBastionHost(), + "azurerm_connection_monitor": resourceArmConnectionMonitor(), + "azurerm_dashboard": resourceArmDashboard(), + "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), + "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), + "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), + "azurerm_image": resourceArmImage(), + "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), + "azurerm_key_vault_key": resourceArmKeyVaultKey(), + "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), + "azurerm_key_vault": resourceArmKeyVault(), + "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), + "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), + "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), + "azurerm_lb_probe": resourceArmLoadBalancerProbe(), + "azurerm_lb_outbound_rule": resourceArmLoadBalancerOutboundRule(), + "azurerm_lb_rule": resourceArmLoadBalancerRule(), + "azurerm_lb": resourceArmLoadBalancer(), + "azurerm_management_lock": resourceArmManagementLock(), + "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), + "azurerm_packet_capture": resourceArmPacketCapture(), + "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), + "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), + "azurerm_private_endpoint": resourceArmPrivateEndpoint(), + "azurerm_private_link_service": resourceArmPrivateLinkService(), + "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), + "azurerm_public_ip": resourceArmPublicIp(), + "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), + "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), + "azurerm_shared_image_version": resourceArmSharedImageVersion(), + "azurerm_shared_image": resourceArmSharedImage(), + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), + "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_storage_table_entity": resourceArmStorageTableEntity(), "azurerm_template_deployment": resourceArmTemplateDeployment(), "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), From e92110001dd7da16730dfead8a396bb6a85ef231 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:38:42 -0800 Subject: [PATCH 060/203] more networking --- .../data_source_express_route_circuit.go | 2 +- .../data_source_express_route_circuit_test.go | 2 +- .../network}/data_source_loadbalancer.go | 2 +- ...ource_loadbalancer_backend_address_pool.go | 2 +- ..._loadbalancer_backend_address_pool_test.go | 2 +- .../network}/data_source_loadbalancer_test.go | 2 +- ...data_source_private_endpoint_connection.go | 5 +- ...source_private_endpoint_connection_test.go | 2 +- ...source_private_link_endpoint_connection.go | 5 +- ...e_private_link_endpoint_connection_test.go | 2 +- .../data_source_private_link_service.go | 5 +- ...ivate_link_service_endpoint_connections.go | 2 +- ..._link_service_endpoint_connections_test.go | 2 +- .../data_source_private_link_service_test.go | 2 +- .../network}/data_source_public_ip.go | 2 +- .../network}/data_source_public_ip_prefix.go | 2 +- .../data_source_public_ip_prefix_test.go | 2 +- .../network}/data_source_public_ip_test.go | 2 +- .../network}/data_source_public_ips.go | 2 +- .../network}/data_source_public_ips_test.go | 2 +- .../services/network}/loadbalancer.go | 2 +- .../internal/services/network/registration.go | 54 ++++++-- .../resource_arm_express_route_circuit.go | 2 +- ...arm_express_route_circuit_authorization.go | 2 +- ...xpress_route_circuit_authorization_test.go | 2 +- ...ource_arm_express_route_circuit_peering.go | 2 +- ..._arm_express_route_circuit_peering_test.go | 2 +- ...resource_arm_express_route_circuit_test.go | 2 +- .../network}/resource_arm_loadbalancer.go | 2 +- ...e_arm_loadbalancer_backend_address_pool.go | 2 +- ..._loadbalancer_backend_address_pool_test.go | 2 +- .../resource_arm_loadbalancer_nat_pool.go | 2 +- ...resource_arm_loadbalancer_nat_pool_test.go | 2 +- .../resource_arm_loadbalancer_nat_rule.go | 2 +- ...resource_arm_loadbalancer_nat_rule_test.go | 2 +- ...resource_arm_loadbalancer_outbound_rule.go | 2 +- ...rce_arm_loadbalancer_outbound_rule_test.go | 2 +- .../resource_arm_loadbalancer_probe.go | 2 +- .../resource_arm_loadbalancer_probe_test.go | 2 +- .../resource_arm_loadbalancer_rule.go | 2 +- .../resource_arm_loadbalancer_rule_test.go | 2 +- .../resource_arm_loadbalancer_test.go | 2 +- .../network}/resource_arm_packet_capture.go | 2 +- .../resource_arm_packet_capture_test.go | 2 +- .../resource_arm_point_to_site_vpn_gateway.go | 11 +- ...urce_arm_point_to_site_vpn_gateway_test.go | 2 +- .../network}/resource_arm_private_endpoint.go | 11 +- .../resource_arm_private_endpoint_test.go | 2 +- .../resource_arm_private_link_endpoint.go | 11 +- ...resource_arm_private_link_endpoint_test.go | 2 +- .../resource_arm_private_link_service.go | 9 +- .../resource_arm_private_link_service_test.go | 2 +- .../resource_arm_proximity_placement_group.go | 2 +- ...urce_arm_proximity_placement_group_test.go | 2 +- .../network}/resource_arm_public_ip.go | 2 +- .../network}/resource_arm_public_ip_prefix.go | 2 +- .../resource_arm_public_ip_prefix_test.go | 2 +- .../network}/resource_arm_public_ip_test.go | 2 +- azurerm/provider.go | 124 +++++++----------- 59 files changed, 164 insertions(+), 171 deletions(-) rename azurerm/{ => internal/services/network}/data_source_express_route_circuit.go (99%) rename azurerm/{ => internal/services/network}/data_source_express_route_circuit_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_loadbalancer.go (99%) rename azurerm/{ => internal/services/network}/data_source_loadbalancer_backend_address_pool.go (99%) rename azurerm/{ => internal/services/network}/data_source_loadbalancer_backend_address_pool_test.go (98%) rename azurerm/{ => internal/services/network}/data_source_loadbalancer_test.go (98%) rename azurerm/{ => internal/services/network}/data_source_private_endpoint_connection.go (97%) rename azurerm/{ => internal/services/network}/data_source_private_endpoint_connection_test.go (98%) rename azurerm/{ => internal/services/network}/data_source_private_link_endpoint_connection.go (96%) rename azurerm/{ => internal/services/network}/data_source_private_link_endpoint_connection_test.go (98%) rename azurerm/{ => internal/services/network}/data_source_private_link_service.go (97%) rename azurerm/{ => internal/services/network}/data_source_private_link_service_endpoint_connections.go (99%) rename azurerm/{ => internal/services/network}/data_source_private_link_service_endpoint_connections_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_private_link_service_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_public_ip.go (99%) rename azurerm/{ => internal/services/network}/data_source_public_ip_prefix.go (99%) rename azurerm/{ => internal/services/network}/data_source_public_ip_prefix_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_public_ip_test.go (99%) rename azurerm/{ => internal/services/network}/data_source_public_ips.go (99%) rename azurerm/{ => internal/services/network}/data_source_public_ips_test.go (99%) rename azurerm/{ => internal/services/network}/loadbalancer.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_express_route_circuit.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_express_route_circuit_authorization.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_express_route_circuit_authorization_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_express_route_circuit_peering.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_express_route_circuit_peering_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_express_route_circuit_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_backend_address_pool.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_backend_address_pool_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_nat_pool.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_nat_pool_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_nat_rule.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_nat_rule_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_outbound_rule.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_outbound_rule_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_probe.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_probe_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_rule.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_rule_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_loadbalancer_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_packet_capture.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_packet_capture_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_point_to_site_vpn_gateway.go (96%) rename azurerm/{ => internal/services/network}/resource_arm_point_to_site_vpn_gateway_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_private_endpoint.go (96%) rename azurerm/{ => internal/services/network}/resource_arm_private_endpoint_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_private_link_endpoint.go (96%) rename azurerm/{ => internal/services/network}/resource_arm_private_link_endpoint_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_private_link_service.go (98%) rename azurerm/{ => internal/services/network}/resource_arm_private_link_service_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_proximity_placement_group.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_proximity_placement_group_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_public_ip.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_public_ip_prefix.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_public_ip_prefix_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_public_ip_test.go (99%) diff --git a/azurerm/data_source_express_route_circuit.go b/azurerm/internal/services/network/data_source_express_route_circuit.go similarity index 99% rename from azurerm/data_source_express_route_circuit.go rename to azurerm/internal/services/network/data_source_express_route_circuit.go index 7b02d5ef2393..daecfbf9db60 100644 --- a/azurerm/data_source_express_route_circuit.go +++ b/azurerm/internal/services/network/data_source_express_route_circuit.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_express_route_circuit_test.go b/azurerm/internal/services/network/data_source_express_route_circuit_test.go similarity index 99% rename from azurerm/data_source_express_route_circuit_test.go rename to azurerm/internal/services/network/data_source_express_route_circuit_test.go index 8967f563beea..b6bf471735f1 100644 --- a/azurerm/data_source_express_route_circuit_test.go +++ b/azurerm/internal/services/network/data_source_express_route_circuit_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_loadbalancer.go b/azurerm/internal/services/network/data_source_loadbalancer.go similarity index 99% rename from azurerm/data_source_loadbalancer.go rename to azurerm/internal/services/network/data_source_loadbalancer.go index f608580612b3..631031c5e992 100644 --- a/azurerm/data_source_loadbalancer.go +++ b/azurerm/internal/services/network/data_source_loadbalancer.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_loadbalancer_backend_address_pool.go b/azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool.go similarity index 99% rename from azurerm/data_source_loadbalancer_backend_address_pool.go rename to azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool.go index 193aaa2d4c09..5ecde9b35100 100644 --- a/azurerm/data_source_loadbalancer_backend_address_pool.go +++ b/azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_loadbalancer_backend_address_pool_test.go b/azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool_test.go similarity index 98% rename from azurerm/data_source_loadbalancer_backend_address_pool_test.go rename to azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool_test.go index 58593d55c3b1..a5a8836cc2cc 100644 --- a/azurerm/data_source_loadbalancer_backend_address_pool_test.go +++ b/azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_loadbalancer_test.go b/azurerm/internal/services/network/data_source_loadbalancer_test.go similarity index 98% rename from azurerm/data_source_loadbalancer_test.go rename to azurerm/internal/services/network/data_source_loadbalancer_test.go index bc2a3ebce788..c363ea711879 100644 --- a/azurerm/data_source_loadbalancer_test.go +++ b/azurerm/internal/services/network/data_source_loadbalancer_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_private_endpoint_connection.go b/azurerm/internal/services/network/data_source_private_endpoint_connection.go similarity index 97% rename from azurerm/data_source_private_endpoint_connection.go rename to azurerm/internal/services/network/data_source_private_endpoint_connection.go index 612f0961f9e2..a279ebd1bdae 100644 --- a/azurerm/data_source_private_endpoint_connection.go +++ b/azurerm/internal/services/network/data_source_private_endpoint_connection.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "context" @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -26,7 +25,7 @@ func dataSourceArmPrivateEndpointConnection() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznet.ValidatePrivateLinkName, + ValidateFunc: ValidatePrivateLinkName, }, "location": azure.SchemaLocationForDataSource(), diff --git a/azurerm/data_source_private_endpoint_connection_test.go b/azurerm/internal/services/network/data_source_private_endpoint_connection_test.go similarity index 98% rename from azurerm/data_source_private_endpoint_connection_test.go rename to azurerm/internal/services/network/data_source_private_endpoint_connection_test.go index 731391325900..585e9c0147cf 100644 --- a/azurerm/data_source_private_endpoint_connection_test.go +++ b/azurerm/internal/services/network/data_source_private_endpoint_connection_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_private_link_endpoint_connection.go b/azurerm/internal/services/network/data_source_private_link_endpoint_connection.go similarity index 96% rename from azurerm/data_source_private_link_endpoint_connection.go rename to azurerm/internal/services/network/data_source_private_link_endpoint_connection.go index 58a1f402fbb6..18af1beda8d7 100644 --- a/azurerm/data_source_private_link_endpoint_connection.go +++ b/azurerm/internal/services/network/data_source_private_link_endpoint_connection.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -32,7 +31,7 @@ As such the existing 'azurerm_private_link_endpoint_connection' resource is depr Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznet.ValidatePrivateLinkName, + ValidateFunc: ValidatePrivateLinkName, }, "location": azure.SchemaLocationForDataSource(), diff --git a/azurerm/data_source_private_link_endpoint_connection_test.go b/azurerm/internal/services/network/data_source_private_link_endpoint_connection_test.go similarity index 98% rename from azurerm/data_source_private_link_endpoint_connection_test.go rename to azurerm/internal/services/network/data_source_private_link_endpoint_connection_test.go index 32c2dc3e27e6..b6f3a6bc84cb 100644 --- a/azurerm/data_source_private_link_endpoint_connection_test.go +++ b/azurerm/internal/services/network/data_source_private_link_endpoint_connection_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_private_link_service.go b/azurerm/internal/services/network/data_source_private_link_service.go similarity index 97% rename from azurerm/data_source_private_link_service.go rename to azurerm/internal/services/network/data_source_private_link_service.go index 0ecce410aab8..23b7d1cb3996 100644 --- a/azurerm/data_source_private_link_service.go +++ b/azurerm/internal/services/network/data_source_private_link_service.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -26,7 +25,7 @@ func dataSourceArmPrivateLinkService() *schema.Resource { "name": { Type: schema.TypeString, Required: true, - ValidateFunc: aznet.ValidatePrivateLinkName, + ValidateFunc: ValidatePrivateLinkName, }, "location": azure.SchemaLocationForDataSource(), diff --git a/azurerm/data_source_private_link_service_endpoint_connections.go b/azurerm/internal/services/network/data_source_private_link_service_endpoint_connections.go similarity index 99% rename from azurerm/data_source_private_link_service_endpoint_connections.go rename to azurerm/internal/services/network/data_source_private_link_service_endpoint_connections.go index 008d9e15d3ad..6a5002d3e2c2 100644 --- a/azurerm/data_source_private_link_service_endpoint_connections.go +++ b/azurerm/internal/services/network/data_source_private_link_service_endpoint_connections.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_private_link_service_endpoint_connections_test.go b/azurerm/internal/services/network/data_source_private_link_service_endpoint_connections_test.go similarity index 99% rename from azurerm/data_source_private_link_service_endpoint_connections_test.go rename to azurerm/internal/services/network/data_source_private_link_service_endpoint_connections_test.go index b140dfd2bc76..f36fbeca12d7 100644 --- a/azurerm/data_source_private_link_service_endpoint_connections_test.go +++ b/azurerm/internal/services/network/data_source_private_link_service_endpoint_connections_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_private_link_service_test.go b/azurerm/internal/services/network/data_source_private_link_service_test.go similarity index 99% rename from azurerm/data_source_private_link_service_test.go rename to azurerm/internal/services/network/data_source_private_link_service_test.go index a31abc9dc6b2..912cfdbcdaca 100644 --- a/azurerm/data_source_private_link_service_test.go +++ b/azurerm/internal/services/network/data_source_private_link_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_public_ip.go b/azurerm/internal/services/network/data_source_public_ip.go similarity index 99% rename from azurerm/data_source_public_ip.go rename to azurerm/internal/services/network/data_source_public_ip.go index 4055278d2deb..2f4ca73d78bf 100644 --- a/azurerm/data_source_public_ip.go +++ b/azurerm/internal/services/network/data_source_public_ip.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_public_ip_prefix.go b/azurerm/internal/services/network/data_source_public_ip_prefix.go similarity index 99% rename from azurerm/data_source_public_ip_prefix.go rename to azurerm/internal/services/network/data_source_public_ip_prefix.go index 72143c27fe2d..a33826a1ff83 100644 --- a/azurerm/data_source_public_ip_prefix.go +++ b/azurerm/internal/services/network/data_source_public_ip_prefix.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_public_ip_prefix_test.go b/azurerm/internal/services/network/data_source_public_ip_prefix_test.go similarity index 99% rename from azurerm/data_source_public_ip_prefix_test.go rename to azurerm/internal/services/network/data_source_public_ip_prefix_test.go index 6e967c37399f..aec8d2629438 100644 --- a/azurerm/data_source_public_ip_prefix_test.go +++ b/azurerm/internal/services/network/data_source_public_ip_prefix_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_public_ip_test.go b/azurerm/internal/services/network/data_source_public_ip_test.go similarity index 99% rename from azurerm/data_source_public_ip_test.go rename to azurerm/internal/services/network/data_source_public_ip_test.go index a20952decf7e..f1c5fe235bfc 100644 --- a/azurerm/data_source_public_ip_test.go +++ b/azurerm/internal/services/network/data_source_public_ip_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_public_ips.go b/azurerm/internal/services/network/data_source_public_ips.go similarity index 99% rename from azurerm/data_source_public_ips.go rename to azurerm/internal/services/network/data_source_public_ips.go index 8d67712992a4..38d7b300c76f 100644 --- a/azurerm/data_source_public_ips.go +++ b/azurerm/internal/services/network/data_source_public_ips.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_public_ips_test.go b/azurerm/internal/services/network/data_source_public_ips_test.go similarity index 99% rename from azurerm/data_source_public_ips_test.go rename to azurerm/internal/services/network/data_source_public_ips_test.go index f64f9bafdaa1..0d6eedc9e418 100644 --- a/azurerm/data_source_public_ips_test.go +++ b/azurerm/internal/services/network/data_source_public_ips_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/loadbalancer.go b/azurerm/internal/services/network/loadbalancer.go similarity index 99% rename from azurerm/loadbalancer.go rename to azurerm/internal/services/network/loadbalancer.go index dbf46c838bda..2f351f09624b 100644 --- a/azurerm/loadbalancer.go +++ b/azurerm/internal/services/network/loadbalancer.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/internal/services/network/registration.go b/azurerm/internal/services/network/registration.go index 8ef4096fd29e..a6b923a0d039 100644 --- a/azurerm/internal/services/network/registration.go +++ b/azurerm/internal/services/network/registration.go @@ -14,19 +14,29 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_firewall": dataSourceArmFirewall(), - "azurerm_nat_gateway": dataSourceArmNatGateway(), - "azurerm_network_ddos_protection_plan": dataSourceNetworkDDoSProtectionPlan(), - "azurerm_network_interface": dataSourceArmNetworkInterface(), - "azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(), - "azurerm_network_watcher": dataSourceArmNetworkWatcher(), - "azurerm_route_table": dataSourceArmRouteTable(), - "azurerm_subnet": dataSourceArmSubnet(), - "azurerm_virtual_hub": dataSourceArmVirtualHub(), - "azurerm_virtual_machine": dataSourceArmVirtualMachine(), - "azurerm_virtual_network_gateway": dataSourceArmVirtualNetworkGateway(), - "azurerm_virtual_network_gateway_connection": dataSourceArmVirtualNetworkGatewayConnection(), - "azurerm_virtual_network": dataSourceArmVirtualNetwork(), + "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), + "azurerm_firewall": dataSourceArmFirewall(), + "azurerm_lb": dataSourceArmLoadBalancer(), + "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), + "azurerm_nat_gateway": dataSourceArmNatGateway(), + "azurerm_network_ddos_protection_plan": dataSourceNetworkDDoSProtectionPlan(), + "azurerm_network_interface": dataSourceArmNetworkInterface(), + "azurerm_network_security_group": dataSourceArmNetworkSecurityGroup(), + "azurerm_network_watcher": dataSourceArmNetworkWatcher(), + "azurerm_private_link_endpoint_connection": dataSourceArmPrivateLinkEndpointConnection(), + "azurerm_private_endpoint_connection": dataSourceArmPrivateEndpointConnection(), + "azurerm_private_link_service": dataSourceArmPrivateLinkService(), + "azurerm_private_link_service_endpoint_connections": dataSourceArmPrivateLinkServiceEndpointConnections(), + "azurerm_public_ip": dataSourceArmPublicIP(), + "azurerm_public_ips": dataSourceArmPublicIPs(), + "azurerm_public_ip_prefix": dataSourceArmPublicIpPrefix(), + "azurerm_route_table": dataSourceArmRouteTable(), + "azurerm_subnet": dataSourceArmSubnet(), + "azurerm_virtual_hub": dataSourceArmVirtualHub(), + "azurerm_virtual_machine": dataSourceArmVirtualMachine(), + "azurerm_virtual_network_gateway": dataSourceArmVirtualNetworkGateway(), + "azurerm_virtual_network_gateway_connection": dataSourceArmVirtualNetworkGatewayConnection(), + "azurerm_virtual_network": dataSourceArmVirtualNetwork(), } } @@ -34,11 +44,21 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), + "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), + "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), + "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), "azurerm_firewall_application_rule_collection": resourceArmFirewallApplicationRuleCollection(), "azurerm_firewall_nat_rule_collection": resourceArmFirewallNatRuleCollection(), "azurerm_firewall_network_rule_collection": resourceArmFirewallNetworkRuleCollection(), "azurerm_firewall": resourceArmFirewall(), "azurerm_local_network_gateway": resourceArmLocalNetworkGateway(), + "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), + "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), + "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), + "azurerm_lb_probe": resourceArmLoadBalancerProbe(), + "azurerm_lb_outbound_rule": resourceArmLoadBalancerOutboundRule(), + "azurerm_lb_rule": resourceArmLoadBalancerRule(), + "azurerm_lb": resourceArmLoadBalancer(), "azurerm_nat_gateway": resourceArmNatGateway(), "azurerm_network_connection_monitor": resourceArmNetworkConnectionMonitor(), "azurerm_network_ddos_protection_plan": resourceArmNetworkDDoSProtectionPlan(), @@ -49,6 +69,14 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_network_interface_nat_rule_association": resourceArmNetworkInterfaceNatRuleAssociation(), "azurerm_network_packet_capture": resourceArmNetworkPacketCapture(), "azurerm_network_profile": resourceArmNetworkProfile(), + "azurerm_packet_capture": resourceArmPacketCapture(), + "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), + "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), + "azurerm_private_endpoint": resourceArmPrivateEndpoint(), + "azurerm_private_link_service": resourceArmPrivateLinkService(), + "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), + "azurerm_public_ip": resourceArmPublicIp(), + "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), "azurerm_network_security_group": resourceArmNetworkSecurityGroup(), "azurerm_network_security_rule": resourceArmNetworkSecurityRule(), "azurerm_network_watcher_flow_log": resourceArmNetworkWatcherFlowLog(), diff --git a/azurerm/resource_arm_express_route_circuit.go b/azurerm/internal/services/network/resource_arm_express_route_circuit.go similarity index 99% rename from azurerm/resource_arm_express_route_circuit.go rename to azurerm/internal/services/network/resource_arm_express_route_circuit.go index 8b89c148b892..5fc10ddfc9a8 100644 --- a/azurerm/resource_arm_express_route_circuit.go +++ b/azurerm/internal/services/network/resource_arm_express_route_circuit.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_express_route_circuit_authorization.go b/azurerm/internal/services/network/resource_arm_express_route_circuit_authorization.go similarity index 99% rename from azurerm/resource_arm_express_route_circuit_authorization.go rename to azurerm/internal/services/network/resource_arm_express_route_circuit_authorization.go index 2a31d28601b5..dc221ad06e42 100644 --- a/azurerm/resource_arm_express_route_circuit_authorization.go +++ b/azurerm/internal/services/network/resource_arm_express_route_circuit_authorization.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_express_route_circuit_authorization_test.go b/azurerm/internal/services/network/resource_arm_express_route_circuit_authorization_test.go similarity index 99% rename from azurerm/resource_arm_express_route_circuit_authorization_test.go rename to azurerm/internal/services/network/resource_arm_express_route_circuit_authorization_test.go index 02d32461d167..0d9842265d56 100644 --- a/azurerm/resource_arm_express_route_circuit_authorization_test.go +++ b/azurerm/internal/services/network/resource_arm_express_route_circuit_authorization_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_express_route_circuit_peering.go b/azurerm/internal/services/network/resource_arm_express_route_circuit_peering.go similarity index 99% rename from azurerm/resource_arm_express_route_circuit_peering.go rename to azurerm/internal/services/network/resource_arm_express_route_circuit_peering.go index 67acd4fcfd69..e86f5aaca26c 100644 --- a/azurerm/resource_arm_express_route_circuit_peering.go +++ b/azurerm/internal/services/network/resource_arm_express_route_circuit_peering.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_express_route_circuit_peering_test.go b/azurerm/internal/services/network/resource_arm_express_route_circuit_peering_test.go similarity index 99% rename from azurerm/resource_arm_express_route_circuit_peering_test.go rename to azurerm/internal/services/network/resource_arm_express_route_circuit_peering_test.go index 73e168d10828..e3ab9663f3c2 100644 --- a/azurerm/resource_arm_express_route_circuit_peering_test.go +++ b/azurerm/internal/services/network/resource_arm_express_route_circuit_peering_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_express_route_circuit_test.go b/azurerm/internal/services/network/resource_arm_express_route_circuit_test.go similarity index 99% rename from azurerm/resource_arm_express_route_circuit_test.go rename to azurerm/internal/services/network/resource_arm_express_route_circuit_test.go index 56dbb73c40ff..5f9f2ac43dbd 100644 --- a/azurerm/resource_arm_express_route_circuit_test.go +++ b/azurerm/internal/services/network/resource_arm_express_route_circuit_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer.go b/azurerm/internal/services/network/resource_arm_loadbalancer.go similarity index 99% rename from azurerm/resource_arm_loadbalancer.go rename to azurerm/internal/services/network/resource_arm_loadbalancer.go index 05856cb80ed5..a3fdda89f690 100644 --- a/azurerm/resource_arm_loadbalancer.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_backend_address_pool.go b/azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_backend_address_pool.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool.go index 013034cee11d..d5d078b0f5ee 100644 --- a/azurerm/resource_arm_loadbalancer_backend_address_pool.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_backend_address_pool_test.go b/azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool_test.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_backend_address_pool_test.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool_test.go index 85dad591a88e..73d0561cea26 100644 --- a/azurerm/resource_arm_loadbalancer_backend_address_pool_test.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_nat_pool.go b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_nat_pool.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool.go index da2158b72edf..5ad3b2e3c00b 100644 --- a/azurerm/resource_arm_loadbalancer_nat_pool.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_nat_pool_test.go b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool_test.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_nat_pool_test.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool_test.go index 270ff653c605..a0b086903bb9 100644 --- a/azurerm/resource_arm_loadbalancer_nat_pool_test.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_nat_rule.go b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_nat_rule.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule.go index abb3e113ccad..4b9436e81351 100644 --- a/azurerm/resource_arm_loadbalancer_nat_rule.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_nat_rule_test.go b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule_test.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_nat_rule_test.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule_test.go index d62705cef6a9..8a69f699b9c4 100644 --- a/azurerm/resource_arm_loadbalancer_nat_rule_test.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_outbound_rule.go b/azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_outbound_rule.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule.go index 3db5dcb1b1d4..df514bc7effc 100644 --- a/azurerm/resource_arm_loadbalancer_outbound_rule.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_outbound_rule_test.go b/azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule_test.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_outbound_rule_test.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule_test.go index 0256fbad40c1..768ab96706f4 100644 --- a/azurerm/resource_arm_loadbalancer_outbound_rule_test.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_probe.go b/azurerm/internal/services/network/resource_arm_loadbalancer_probe.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_probe.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_probe.go index d5c2a39793a7..0cac7cd3a7c1 100644 --- a/azurerm/resource_arm_loadbalancer_probe.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_probe.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_probe_test.go b/azurerm/internal/services/network/resource_arm_loadbalancer_probe_test.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_probe_test.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_probe_test.go index 0fbee2d30c78..ecc72b2cce9a 100644 --- a/azurerm/resource_arm_loadbalancer_probe_test.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_probe_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_rule.go b/azurerm/internal/services/network/resource_arm_loadbalancer_rule.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_rule.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_rule.go index b4e43e9a6110..a980504662fe 100644 --- a/azurerm/resource_arm_loadbalancer_rule.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_rule.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_rule_test.go b/azurerm/internal/services/network/resource_arm_loadbalancer_rule_test.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_rule_test.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_rule_test.go index 478737d19b82..dd666642a1ec 100644 --- a/azurerm/resource_arm_loadbalancer_rule_test.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_rule_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_loadbalancer_test.go b/azurerm/internal/services/network/resource_arm_loadbalancer_test.go similarity index 99% rename from azurerm/resource_arm_loadbalancer_test.go rename to azurerm/internal/services/network/resource_arm_loadbalancer_test.go index 809edbbaf720..4a422608348b 100644 --- a/azurerm/resource_arm_loadbalancer_test.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_packet_capture.go b/azurerm/internal/services/network/resource_arm_packet_capture.go similarity index 99% rename from azurerm/resource_arm_packet_capture.go rename to azurerm/internal/services/network/resource_arm_packet_capture.go index 57c9f950a943..14ff54fa6ea0 100644 --- a/azurerm/resource_arm_packet_capture.go +++ b/azurerm/internal/services/network/resource_arm_packet_capture.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_packet_capture_test.go b/azurerm/internal/services/network/resource_arm_packet_capture_test.go similarity index 99% rename from azurerm/resource_arm_packet_capture_test.go rename to azurerm/internal/services/network/resource_arm_packet_capture_test.go index d606127adfa0..060bf0404a20 100644 --- a/azurerm/resource_arm_packet_capture_test.go +++ b/azurerm/internal/services/network/resource_arm_packet_capture_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_point_to_site_vpn_gateway.go b/azurerm/internal/services/network/resource_arm_point_to_site_vpn_gateway.go similarity index 96% rename from azurerm/resource_arm_point_to_site_vpn_gateway.go rename to azurerm/internal/services/network/resource_arm_point_to_site_vpn_gateway.go index 469529fc4d80..42ec07cc8377 100644 --- a/azurerm/resource_arm_point_to_site_vpn_gateway.go +++ b/azurerm/internal/services/network/resource_arm_point_to_site_vpn_gateway.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -13,7 +13,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - networkSvc "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -52,14 +51,14 @@ func resourceArmPointToSiteVPNGateway() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: networkSvc.ValidateVirtualHubID, + ValidateFunc: ValidateVirtualHubID, }, "vpn_server_configuration_id": { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: networkSvc.ValidateVpnServerConfigurationID, + ValidateFunc: ValidateVpnServerConfigurationID, }, "connection_configuration": { @@ -177,7 +176,7 @@ func resourceArmPointToSiteVPNGatewayRead(d *schema.ResourceData, meta interface ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParsePointToSiteVPNGatewayID(d.Id()) + id, err := ParsePointToSiteVPNGatewayID(d.Id()) if err != nil { return err } @@ -233,7 +232,7 @@ func resourceArmPointToSiteVPNGatewayDelete(d *schema.ResourceData, meta interfa ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := networkSvc.ParsePointToSiteVPNGatewayID(d.Id()) + id, err := ParsePointToSiteVPNGatewayID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_point_to_site_vpn_gateway_test.go b/azurerm/internal/services/network/resource_arm_point_to_site_vpn_gateway_test.go similarity index 99% rename from azurerm/resource_arm_point_to_site_vpn_gateway_test.go rename to azurerm/internal/services/network/resource_arm_point_to_site_vpn_gateway_test.go index 6f2ec7027a7a..03cf143c4f78 100644 --- a/azurerm/resource_arm_point_to_site_vpn_gateway_test.go +++ b/azurerm/internal/services/network/resource_arm_point_to_site_vpn_gateway_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_private_endpoint.go b/azurerm/internal/services/network/resource_arm_private_endpoint.go similarity index 96% rename from azurerm/resource_arm_private_endpoint.go rename to azurerm/internal/services/network/resource_arm_private_endpoint.go index 104aa8546ac5..dee07ccdd314 100644 --- a/azurerm/resource_arm_private_endpoint.go +++ b/azurerm/internal/services/network/resource_arm_private_endpoint.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -13,7 +13,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -40,7 +39,7 @@ func resourceArmPrivateEndpoint() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznet.ValidatePrivateLinkName, + ValidateFunc: ValidatePrivateLinkName, }, "location": azure.SchemaLocation(), @@ -64,7 +63,7 @@ func resourceArmPrivateEndpoint() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznet.ValidatePrivateLinkName, + ValidateFunc: ValidatePrivateLinkName, }, "is_manual_connection": { Type: schema.TypeBool, @@ -83,7 +82,7 @@ func resourceArmPrivateEndpoint() *schema.Resource { ForceNew: true, Elem: &schema.Schema{ Type: schema.TypeString, - ValidateFunc: aznet.ValidatePrivateLinkSubResourceName, + ValidateFunc: ValidatePrivateLinkSubResourceName, }, }, "request_message": { @@ -109,7 +108,7 @@ func resourceArmPrivateEndpointCreateUpdate(d *schema.ResourceData, meta interfa name := d.Get("name").(string) resourceGroup := d.Get("resource_group_name").(string) - if err := aznet.ValidatePrivateEndpointSettings(d); err != nil { + if err := ValidatePrivateEndpointSettings(d); err != nil { return fmt.Errorf("Error validating the configuration for the Private Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) } diff --git a/azurerm/resource_arm_private_endpoint_test.go b/azurerm/internal/services/network/resource_arm_private_endpoint_test.go similarity index 99% rename from azurerm/resource_arm_private_endpoint_test.go rename to azurerm/internal/services/network/resource_arm_private_endpoint_test.go index d1dad444a6ba..13736defac4e 100644 --- a/azurerm/resource_arm_private_endpoint_test.go +++ b/azurerm/internal/services/network/resource_arm_private_endpoint_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_private_link_endpoint.go b/azurerm/internal/services/network/resource_arm_private_link_endpoint.go similarity index 96% rename from azurerm/resource_arm_private_link_endpoint.go rename to azurerm/internal/services/network/resource_arm_private_link_endpoint.go index f770cda3e8e4..b4f420a31649 100644 --- a/azurerm/resource_arm_private_link_endpoint.go +++ b/azurerm/internal/services/network/resource_arm_private_link_endpoint.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" @@ -13,7 +13,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -47,7 +46,7 @@ As such the existing 'azurerm_private_link_endpoint' resource is deprecated and Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznet.ValidatePrivateLinkName, + ValidateFunc: ValidatePrivateLinkName, }, "location": azure.SchemaLocation(), @@ -71,7 +70,7 @@ As such the existing 'azurerm_private_link_endpoint' resource is deprecated and Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznet.ValidatePrivateLinkName, + ValidateFunc: ValidatePrivateLinkName, }, "is_manual_connection": { Type: schema.TypeBool, @@ -90,7 +89,7 @@ As such the existing 'azurerm_private_link_endpoint' resource is deprecated and ForceNew: true, Elem: &schema.Schema{ Type: schema.TypeString, - ValidateFunc: aznet.ValidatePrivateLinkSubResourceName, + ValidateFunc: ValidatePrivateLinkSubResourceName, }, }, "request_message": { @@ -116,7 +115,7 @@ func resourceArmPrivateLinkEndpointCreateUpdate(d *schema.ResourceData, meta int name := d.Get("name").(string) resourceGroup := d.Get("resource_group_name").(string) - if err := aznet.ValidatePrivateEndpointSettings(d); err != nil { + if err := ValidatePrivateEndpointSettings(d); err != nil { return fmt.Errorf("Error validating the configuration for the Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) } diff --git a/azurerm/resource_arm_private_link_endpoint_test.go b/azurerm/internal/services/network/resource_arm_private_link_endpoint_test.go similarity index 99% rename from azurerm/resource_arm_private_link_endpoint_test.go rename to azurerm/internal/services/network/resource_arm_private_link_endpoint_test.go index 0ab7bb22089f..bb20d1a94279 100644 --- a/azurerm/resource_arm_private_link_endpoint_test.go +++ b/azurerm/internal/services/network/resource_arm_private_link_endpoint_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_private_link_service.go b/azurerm/internal/services/network/resource_arm_private_link_service.go similarity index 98% rename from azurerm/resource_arm_private_link_service.go rename to azurerm/internal/services/network/resource_arm_private_link_service.go index d916b1e1f5d6..9312e14792f9 100644 --- a/azurerm/resource_arm_private_link_service.go +++ b/azurerm/internal/services/network/resource_arm_private_link_service.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "context" @@ -16,7 +16,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -45,7 +44,7 @@ func resourceArmPrivateLinkService() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznet.ValidatePrivateLinkName, + ValidateFunc: ValidatePrivateLinkName, }, "location": azure.SchemaLocation(), @@ -90,7 +89,7 @@ func resourceArmPrivateLinkService() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: aznet.ValidatePrivateLinkName, + ValidateFunc: ValidatePrivateLinkName, }, "private_ip_address": { Type: schema.TypeString, @@ -152,7 +151,7 @@ func resourceArmPrivateLinkService() *schema.Resource { }, CustomizeDiff: func(d *schema.ResourceDiff, v interface{}) error { - if err := aznet.ValidatePrivateLinkNatIpConfiguration(d); err != nil { + if err := ValidatePrivateLinkNatIpConfiguration(d); err != nil { return err } diff --git a/azurerm/resource_arm_private_link_service_test.go b/azurerm/internal/services/network/resource_arm_private_link_service_test.go similarity index 99% rename from azurerm/resource_arm_private_link_service_test.go rename to azurerm/internal/services/network/resource_arm_private_link_service_test.go index d28768d0da8d..0b7deb74bde4 100644 --- a/azurerm/resource_arm_private_link_service_test.go +++ b/azurerm/internal/services/network/resource_arm_private_link_service_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_proximity_placement_group.go b/azurerm/internal/services/network/resource_arm_proximity_placement_group.go similarity index 99% rename from azurerm/resource_arm_proximity_placement_group.go rename to azurerm/internal/services/network/resource_arm_proximity_placement_group.go index a6d7e963ad68..9a5cbfe2e754 100644 --- a/azurerm/resource_arm_proximity_placement_group.go +++ b/azurerm/internal/services/network/resource_arm_proximity_placement_group.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_proximity_placement_group_test.go b/azurerm/internal/services/network/resource_arm_proximity_placement_group_test.go similarity index 99% rename from azurerm/resource_arm_proximity_placement_group_test.go rename to azurerm/internal/services/network/resource_arm_proximity_placement_group_test.go index b0074ef33c4c..bb54626c91af 100644 --- a/azurerm/resource_arm_proximity_placement_group_test.go +++ b/azurerm/internal/services/network/resource_arm_proximity_placement_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_public_ip.go b/azurerm/internal/services/network/resource_arm_public_ip.go similarity index 99% rename from azurerm/resource_arm_public_ip.go rename to azurerm/internal/services/network/resource_arm_public_ip.go index c19b45f6fbcd..fb3e4190a55b 100644 --- a/azurerm/resource_arm_public_ip.go +++ b/azurerm/internal/services/network/resource_arm_public_ip.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_public_ip_prefix.go b/azurerm/internal/services/network/resource_arm_public_ip_prefix.go similarity index 99% rename from azurerm/resource_arm_public_ip_prefix.go rename to azurerm/internal/services/network/resource_arm_public_ip_prefix.go index c906a2f307d6..4f4ac653e25f 100644 --- a/azurerm/resource_arm_public_ip_prefix.go +++ b/azurerm/internal/services/network/resource_arm_public_ip_prefix.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_public_ip_prefix_test.go b/azurerm/internal/services/network/resource_arm_public_ip_prefix_test.go similarity index 99% rename from azurerm/resource_arm_public_ip_prefix_test.go rename to azurerm/internal/services/network/resource_arm_public_ip_prefix_test.go index 350e9e27a409..b27930041ece 100644 --- a/azurerm/resource_arm_public_ip_prefix_test.go +++ b/azurerm/internal/services/network/resource_arm_public_ip_prefix_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_public_ip_test.go b/azurerm/internal/services/network/resource_arm_public_ip_test.go similarity index 99% rename from azurerm/resource_arm_public_ip_test.go rename to azurerm/internal/services/network/resource_arm_public_ip_test.go index c16fc684b16c..6f873f4e3118 100644 --- a/azurerm/resource_arm_public_ip_test.go +++ b/azurerm/internal/services/network/resource_arm_public_ip_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 7cb6ef659be5..feae3829a348 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -8,85 +8,57 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), - "azurerm_image": dataSourceArmImage(), - "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), - "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), - "azurerm_key_vault": dataSourceArmKeyVault(), - "azurerm_lb": dataSourceArmLoadBalancer(), - "azurerm_lb_backend_address_pool": dataSourceArmLoadBalancerBackendAddressPool(), - "azurerm_platform_image": dataSourceArmPlatformImage(), - "azurerm_private_link_endpoint_connection": dataSourceArmPrivateLinkEndpointConnection(), - "azurerm_private_endpoint_connection": dataSourceArmPrivateEndpointConnection(), - "azurerm_private_link_service": dataSourceArmPrivateLinkService(), - "azurerm_private_link_service_endpoint_connections": dataSourceArmPrivateLinkServiceEndpointConnections(), - "azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(), - "azurerm_public_ip": dataSourceArmPublicIP(), - "azurerm_public_ips": dataSourceArmPublicIPs(), - "azurerm_public_ip_prefix": dataSourceArmPublicIpPrefix(), - "azurerm_resources": dataSourceArmResources(), - "azurerm_resource_group": dataSourceArmResourceGroup(), - "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), - "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), - "azurerm_storage_account": dataSourceArmStorageAccount(), - "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), - "azurerm_subscription": dataSourceArmSubscription(), - "azurerm_subscriptions": dataSourceArmSubscriptions(), - "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), + "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), + "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), + "azurerm_client_config": dataSourceArmClientConfig(), + "azurerm_image": dataSourceArmImage(), + "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), + "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), + "azurerm_key_vault": dataSourceArmKeyVault(), + "azurerm_platform_image": dataSourceArmPlatformImage(), + "azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(), + "azurerm_resources": dataSourceArmResources(), + "azurerm_resource_group": dataSourceArmResourceGroup(), + "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), + "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), + "azurerm_storage_account": dataSourceArmStorageAccount(), + "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), + "azurerm_subscription": dataSourceArmSubscription(), + "azurerm_subscriptions": dataSourceArmSubscriptions(), + "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), } resources := map[string]*schema.Resource{ - "azurerm_application_gateway": resourceArmApplicationGateway(), - "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), - "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_connection_monitor": resourceArmConnectionMonitor(), - "azurerm_dashboard": resourceArmDashboard(), - "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), - "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), - "azurerm_express_route_circuit": resourceArmExpressRouteCircuit(), - "azurerm_image": resourceArmImage(), - "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), - "azurerm_key_vault_key": resourceArmKeyVaultKey(), - "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), - "azurerm_key_vault": resourceArmKeyVault(), - "azurerm_lb_backend_address_pool": resourceArmLoadBalancerBackendAddressPool(), - "azurerm_lb_nat_pool": resourceArmLoadBalancerNatPool(), - "azurerm_lb_nat_rule": resourceArmLoadBalancerNatRule(), - "azurerm_lb_probe": resourceArmLoadBalancerProbe(), - "azurerm_lb_outbound_rule": resourceArmLoadBalancerOutboundRule(), - "azurerm_lb_rule": resourceArmLoadBalancerRule(), - "azurerm_lb": resourceArmLoadBalancer(), - "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), - "azurerm_packet_capture": resourceArmPacketCapture(), - "azurerm_point_to_site_vpn_gateway": resourceArmPointToSiteVPNGateway(), - "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), - "azurerm_private_endpoint": resourceArmPrivateEndpoint(), - "azurerm_private_link_service": resourceArmPrivateLinkService(), - "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), - "azurerm_public_ip": resourceArmPublicIp(), - "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), - "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), - "azurerm_shared_image_version": resourceArmSharedImageVersion(), - "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), - "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_storage_table_entity": resourceArmStorageTableEntity(), + "azurerm_application_gateway": resourceArmApplicationGateway(), + "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), + "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), + "azurerm_bastion_host": resourceArmBastionHost(), + "azurerm_connection_monitor": resourceArmConnectionMonitor(), + "azurerm_dashboard": resourceArmDashboard(), + "azurerm_image": resourceArmImage(), + "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), + "azurerm_key_vault_key": resourceArmKeyVaultKey(), + "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), + "azurerm_key_vault": resourceArmKeyVault(), + "azurerm_management_lock": resourceArmManagementLock(), + "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), + "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), + "azurerm_shared_image_version": resourceArmSharedImageVersion(), + "azurerm_shared_image": resourceArmSharedImage(), + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), + "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_storage_table_entity": resourceArmStorageTableEntity(), "azurerm_template_deployment": resourceArmTemplateDeployment(), "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), From 34c43a4a35310d15f9d5c45523b4068269281a37 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:41:56 -0800 Subject: [PATCH 061/203] trafficmanager --- ...e_traffic_manager_geographical_location.go | 2 +- ...ffic_manager_geographical_location_test.go | 2 +- .../services/trafficmanager/registration.go | 9 +++- .../resource_arm_traffic_manager_endpoint.go | 2 +- ...ource_arm_traffic_manager_endpoint_test.go | 2 +- .../resource_arm_traffic_manager_profile.go | 2 +- ...source_arm_traffic_manager_profile_test.go | 2 +- azurerm/provider.go | 42 +++++++++---------- 8 files changed, 32 insertions(+), 31 deletions(-) rename azurerm/{ => internal/services/trafficmanager}/data_source_traffic_manager_geographical_location.go (98%) rename azurerm/{ => internal/services/trafficmanager}/data_source_traffic_manager_geographical_location_test.go (99%) rename azurerm/{ => internal/services/trafficmanager}/resource_arm_traffic_manager_endpoint.go (99%) rename azurerm/{ => internal/services/trafficmanager}/resource_arm_traffic_manager_endpoint_test.go (99%) rename azurerm/{ => internal/services/trafficmanager}/resource_arm_traffic_manager_profile.go (99%) rename azurerm/{ => internal/services/trafficmanager}/resource_arm_traffic_manager_profile_test.go (99%) diff --git a/azurerm/data_source_traffic_manager_geographical_location.go b/azurerm/internal/services/trafficmanager/data_source_traffic_manager_geographical_location.go similarity index 98% rename from azurerm/data_source_traffic_manager_geographical_location.go rename to azurerm/internal/services/trafficmanager/data_source_traffic_manager_geographical_location.go index df6d58b58aba..3786c1104d9b 100644 --- a/azurerm/data_source_traffic_manager_geographical_location.go +++ b/azurerm/internal/services/trafficmanager/data_source_traffic_manager_geographical_location.go @@ -1,4 +1,4 @@ -package azurerm +package trafficmanager import ( "fmt" diff --git a/azurerm/data_source_traffic_manager_geographical_location_test.go b/azurerm/internal/services/trafficmanager/data_source_traffic_manager_geographical_location_test.go similarity index 99% rename from azurerm/data_source_traffic_manager_geographical_location_test.go rename to azurerm/internal/services/trafficmanager/data_source_traffic_manager_geographical_location_test.go index 531a12072bad..0ded980f95e4 100644 --- a/azurerm/data_source_traffic_manager_geographical_location_test.go +++ b/azurerm/internal/services/trafficmanager/data_source_traffic_manager_geographical_location_test.go @@ -1,4 +1,4 @@ -package azurerm +package trafficmanager import ( "fmt" diff --git a/azurerm/internal/services/trafficmanager/registration.go b/azurerm/internal/services/trafficmanager/registration.go index 16f7d1335e9e..0e38ab6b6df5 100644 --- a/azurerm/internal/services/trafficmanager/registration.go +++ b/azurerm/internal/services/trafficmanager/registration.go @@ -13,10 +13,15 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), + "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), + } } diff --git a/azurerm/resource_arm_traffic_manager_endpoint.go b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_endpoint.go similarity index 99% rename from azurerm/resource_arm_traffic_manager_endpoint.go rename to azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_endpoint.go index bd456f72ffd6..d1fd7f8badb6 100644 --- a/azurerm/resource_arm_traffic_manager_endpoint.go +++ b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_endpoint.go @@ -1,4 +1,4 @@ -package azurerm +package trafficmanager import ( "fmt" diff --git a/azurerm/resource_arm_traffic_manager_endpoint_test.go b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_endpoint_test.go similarity index 99% rename from azurerm/resource_arm_traffic_manager_endpoint_test.go rename to azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_endpoint_test.go index e1fea3341ed7..d045f2da7e2e 100644 --- a/azurerm/resource_arm_traffic_manager_endpoint_test.go +++ b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_endpoint_test.go @@ -1,4 +1,4 @@ -package azurerm +package trafficmanager import ( "fmt" diff --git a/azurerm/resource_arm_traffic_manager_profile.go b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go similarity index 99% rename from azurerm/resource_arm_traffic_manager_profile.go rename to azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go index 261768b966f7..39991b3ab057 100644 --- a/azurerm/resource_arm_traffic_manager_profile.go +++ b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile.go @@ -1,4 +1,4 @@ -package azurerm +package trafficmanager import ( "bytes" diff --git a/azurerm/resource_arm_traffic_manager_profile_test.go b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile_test.go similarity index 99% rename from azurerm/resource_arm_traffic_manager_profile_test.go rename to azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile_test.go index 2c83f3c41f7e..0ea6d2cd140c 100644 --- a/azurerm/resource_arm_traffic_manager_profile_test.go +++ b/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile_test.go @@ -1,4 +1,4 @@ -package azurerm +package trafficmanager import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index feae3829a348..e9cce9345abe 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -8,25 +8,24 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_image": dataSourceArmImage(), - "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), - "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), - "azurerm_key_vault": dataSourceArmKeyVault(), - "azurerm_platform_image": dataSourceArmPlatformImage(), - "azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(), - "azurerm_resources": dataSourceArmResources(), - "azurerm_resource_group": dataSourceArmResourceGroup(), - "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), - "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), - "azurerm_storage_account": dataSourceArmStorageAccount(), - "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), - "azurerm_subscription": dataSourceArmSubscription(), - "azurerm_subscriptions": dataSourceArmSubscriptions(), - "azurerm_traffic_manager_geographical_location": dataSourceArmTrafficManagerGeographicalLocation(), + "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), + "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), + "azurerm_client_config": dataSourceArmClientConfig(), + "azurerm_image": dataSourceArmImage(), + "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), + "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), + "azurerm_key_vault": dataSourceArmKeyVault(), + "azurerm_platform_image": dataSourceArmPlatformImage(), + "azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(), + "azurerm_resources": dataSourceArmResources(), + "azurerm_resource_group": dataSourceArmResourceGroup(), + "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), + "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), + "azurerm_storage_account": dataSourceArmStorageAccount(), + "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), + "azurerm_subscription": dataSourceArmSubscription(), + "azurerm_subscriptions": dataSourceArmSubscriptions(), } resources := map[string]*schema.Resource{ @@ -59,10 +58,7 @@ func Provider() terraform.ResourceProvider { "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), "azurerm_storage_table": resourceArmStorageTable(), "azurerm_storage_table_entity": resourceArmStorageTableEntity(), - - "azurerm_template_deployment": resourceArmTemplateDeployment(), - "azurerm_traffic_manager_endpoint": resourceArmTrafficManagerEndpoint(), - "azurerm_traffic_manager_profile": resourceArmTrafficManagerProfile(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), } return provider.AzureProvider(dataSources, resources) From dfac32eb9e84607ab0e360d5b5a8d25c847fe53a Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:43:00 -0800 Subject: [PATCH 062/203] subscription --- .../services/subscription}/data_source_subscription.go | 2 +- .../services/subscription}/data_source_subscription_test.go | 2 +- .../services/subscription}/data_source_subscriptions.go | 2 +- .../services/subscription}/data_source_subscriptions_test.go | 2 +- azurerm/internal/services/subscription/registration.go | 5 ++++- azurerm/provider.go | 2 -- 6 files changed, 8 insertions(+), 7 deletions(-) rename azurerm/{ => internal/services/subscription}/data_source_subscription.go (98%) rename azurerm/{ => internal/services/subscription}/data_source_subscription_test.go (99%) rename azurerm/{ => internal/services/subscription}/data_source_subscriptions.go (99%) rename azurerm/{ => internal/services/subscription}/data_source_subscriptions_test.go (97%) diff --git a/azurerm/data_source_subscription.go b/azurerm/internal/services/subscription/data_source_subscription.go similarity index 98% rename from azurerm/data_source_subscription.go rename to azurerm/internal/services/subscription/data_source_subscription.go index d0bc36e5a040..94ba9ce6cfb9 100644 --- a/azurerm/data_source_subscription.go +++ b/azurerm/internal/services/subscription/data_source_subscription.go @@ -1,4 +1,4 @@ -package azurerm +package subscription import ( "fmt" diff --git a/azurerm/data_source_subscription_test.go b/azurerm/internal/services/subscription/data_source_subscription_test.go similarity index 99% rename from azurerm/data_source_subscription_test.go rename to azurerm/internal/services/subscription/data_source_subscription_test.go index db9b71a8d2eb..b77a62c5bae2 100644 --- a/azurerm/data_source_subscription_test.go +++ b/azurerm/internal/services/subscription/data_source_subscription_test.go @@ -1,4 +1,4 @@ -package azurerm +package subscription import ( "fmt" diff --git a/azurerm/data_source_subscriptions.go b/azurerm/internal/services/subscription/data_source_subscriptions.go similarity index 99% rename from azurerm/data_source_subscriptions.go rename to azurerm/internal/services/subscription/data_source_subscriptions.go index 5244870751ae..4b9743d3d99e 100644 --- a/azurerm/data_source_subscriptions.go +++ b/azurerm/internal/services/subscription/data_source_subscriptions.go @@ -1,4 +1,4 @@ -package azurerm +package subscription import ( "fmt" diff --git a/azurerm/data_source_subscriptions_test.go b/azurerm/internal/services/subscription/data_source_subscriptions_test.go similarity index 97% rename from azurerm/data_source_subscriptions_test.go rename to azurerm/internal/services/subscription/data_source_subscriptions_test.go index 85d7a1935219..ccc101caa930 100644 --- a/azurerm/data_source_subscriptions_test.go +++ b/azurerm/internal/services/subscription/data_source_subscriptions_test.go @@ -1,4 +1,4 @@ -package azurerm +package subscription import ( "testing" diff --git a/azurerm/internal/services/subscription/registration.go b/azurerm/internal/services/subscription/registration.go index 7a32d84ac6f5..63943922ca60 100644 --- a/azurerm/internal/services/subscription/registration.go +++ b/azurerm/internal/services/subscription/registration.go @@ -13,7 +13,10 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_subscription": dataSourceArmSubscription(), + "azurerm_subscriptions": dataSourceArmSubscriptions(), + } } // SupportedResources returns the supported Resources supported by this Service diff --git a/azurerm/provider.go b/azurerm/provider.go index e9cce9345abe..c2e19956f9bc 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -24,8 +24,6 @@ func Provider() terraform.ResourceProvider { "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), "azurerm_storage_account": dataSourceArmStorageAccount(), "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), - "azurerm_subscription": dataSourceArmSubscription(), - "azurerm_subscriptions": dataSourceArmSubscriptions(), } resources := map[string]*schema.Resource{ From 148d42937895845d3c2b674495d93799e4e61c4f Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:44:26 -0800 Subject: [PATCH 063/203] keyvault --- .../services/keyvault}/data_source_key_vault.go | 2 +- .../data_source_key_vault_access_policy.go | 2 +- .../data_source_key_vault_access_policy_test.go | 2 +- .../keyvault}/data_source_key_vault_key.go | 2 +- .../keyvault}/data_source_key_vault_key_test.go | 2 +- .../keyvault}/data_source_key_vault_secret.go | 2 +- .../data_source_key_vault_secret_test.go | 2 +- .../keyvault}/data_source_key_vault_test.go | 2 +- .../internal/services/keyvault/registration.go | 15 +++++++++++++-- .../services/keyvault}/resource_arm_key_vault.go | 2 +- .../resource_arm_key_vault_access_policy.go | 2 +- .../resource_arm_key_vault_access_policy_test.go | 2 +- .../resource_arm_key_vault_certificate.go | 2 +- .../resource_arm_key_vault_certificate_test.go | 2 +- .../keyvault}/resource_arm_key_vault_key.go | 2 +- .../keyvault}/resource_arm_key_vault_key_test.go | 2 +- .../keyvault}/resource_arm_key_vault_migration.go | 2 +- .../resource_arm_key_vault_migration_test.go | 2 +- .../keyvault}/resource_arm_key_vault_secret.go | 2 +- .../resource_arm_key_vault_secret_test.go | 2 +- .../keyvault}/resource_arm_key_vault_test.go | 2 +- azurerm/provider.go | 9 --------- 22 files changed, 33 insertions(+), 31 deletions(-) rename azurerm/{ => internal/services/keyvault}/data_source_key_vault.go (99%) rename azurerm/{ => internal/services/keyvault}/data_source_key_vault_access_policy.go (99%) rename azurerm/{ => internal/services/keyvault}/data_source_key_vault_access_policy_test.go (99%) rename azurerm/{ => internal/services/keyvault}/data_source_key_vault_key.go (99%) rename azurerm/{ => internal/services/keyvault}/data_source_key_vault_key_test.go (98%) rename azurerm/{ => internal/services/keyvault}/data_source_key_vault_secret.go (99%) rename azurerm/{ => internal/services/keyvault}/data_source_key_vault_secret_test.go (99%) rename azurerm/{ => internal/services/keyvault}/data_source_key_vault_test.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_access_policy.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_access_policy_test.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_certificate.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_certificate_test.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_key.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_key_test.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_migration.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_migration_test.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_secret.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_secret_test.go (99%) rename azurerm/{ => internal/services/keyvault}/resource_arm_key_vault_test.go (99%) diff --git a/azurerm/data_source_key_vault.go b/azurerm/internal/services/keyvault/data_source_key_vault.go similarity index 99% rename from azurerm/data_source_key_vault.go rename to azurerm/internal/services/keyvault/data_source_key_vault.go index 7bb1ba34030a..2e18d242effa 100644 --- a/azurerm/data_source_key_vault.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/data_source_key_vault_access_policy.go b/azurerm/internal/services/keyvault/data_source_key_vault_access_policy.go similarity index 99% rename from azurerm/data_source_key_vault_access_policy.go rename to azurerm/internal/services/keyvault/data_source_key_vault_access_policy.go index 4e120c2a7c52..df7ae10c4226 100644 --- a/azurerm/data_source_key_vault_access_policy.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault_access_policy.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "strings" diff --git a/azurerm/data_source_key_vault_access_policy_test.go b/azurerm/internal/services/keyvault/data_source_key_vault_access_policy_test.go similarity index 99% rename from azurerm/data_source_key_vault_access_policy_test.go rename to azurerm/internal/services/keyvault/data_source_key_vault_access_policy_test.go index 89448d8785a3..b5fc0c8d3b40 100644 --- a/azurerm/data_source_key_vault_access_policy_test.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault_access_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/data_source_key_vault_key.go b/azurerm/internal/services/keyvault/data_source_key_vault_key.go similarity index 99% rename from azurerm/data_source_key_vault_key.go rename to azurerm/internal/services/keyvault/data_source_key_vault_key.go index a34bbbc6cb61..a5f989d5755a 100644 --- a/azurerm/data_source_key_vault_key.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault_key.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/data_source_key_vault_key_test.go b/azurerm/internal/services/keyvault/data_source_key_vault_key_test.go similarity index 98% rename from azurerm/data_source_key_vault_key_test.go rename to azurerm/internal/services/keyvault/data_source_key_vault_key_test.go index 3307e1cbf817..c2cc5cf74272 100644 --- a/azurerm/data_source_key_vault_key_test.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault_key_test.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/data_source_key_vault_secret.go b/azurerm/internal/services/keyvault/data_source_key_vault_secret.go similarity index 99% rename from azurerm/data_source_key_vault_secret.go rename to azurerm/internal/services/keyvault/data_source_key_vault_secret.go index 0f6ccf4d8b50..98a4db4d19ca 100644 --- a/azurerm/data_source_key_vault_secret.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault_secret.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/data_source_key_vault_secret_test.go b/azurerm/internal/services/keyvault/data_source_key_vault_secret_test.go similarity index 99% rename from azurerm/data_source_key_vault_secret_test.go rename to azurerm/internal/services/keyvault/data_source_key_vault_secret_test.go index 1ecb3eaa8576..cf83fbdb8ff2 100644 --- a/azurerm/data_source_key_vault_secret_test.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault_secret_test.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/data_source_key_vault_test.go b/azurerm/internal/services/keyvault/data_source_key_vault_test.go similarity index 99% rename from azurerm/data_source_key_vault_test.go rename to azurerm/internal/services/keyvault/data_source_key_vault_test.go index 9863a6a6256f..cc8d96d77f76 100644 --- a/azurerm/data_source_key_vault_test.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault_test.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/internal/services/keyvault/registration.go b/azurerm/internal/services/keyvault/registration.go index 97b119635560..95c8c926102c 100644 --- a/azurerm/internal/services/keyvault/registration.go +++ b/azurerm/internal/services/keyvault/registration.go @@ -13,10 +13,21 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), + "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), + "azurerm_key_vault": dataSourceArmKeyVault(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), + "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), + "azurerm_key_vault_key": resourceArmKeyVaultKey(), + "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), + "azurerm_key_vault": resourceArmKeyVault(), + } } diff --git a/azurerm/resource_arm_key_vault.go b/azurerm/internal/services/keyvault/resource_arm_key_vault.go similarity index 99% rename from azurerm/resource_arm_key_vault.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault.go index 523023c66d70..0e071d1fd02d 100644 --- a/azurerm/resource_arm_key_vault.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/resource_arm_key_vault_access_policy.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go similarity index 99% rename from azurerm/resource_arm_key_vault_access_policy.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go index 2ba65bf7b4ce..71a76c7ed360 100644 --- a/azurerm/resource_arm_key_vault_access_policy.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/resource_arm_key_vault_access_policy_test.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy_test.go similarity index 99% rename from azurerm/resource_arm_key_vault_access_policy_test.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy_test.go index 3088ec555f91..9ce37e81176e 100644 --- a/azurerm/resource_arm_key_vault_access_policy_test.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/resource_arm_key_vault_certificate.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_certificate.go similarity index 99% rename from azurerm/resource_arm_key_vault_certificate.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_certificate.go index be59ace00fd4..4da9f66ab37e 100644 --- a/azurerm/resource_arm_key_vault_certificate.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_certificate.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "context" diff --git a/azurerm/resource_arm_key_vault_certificate_test.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_certificate_test.go similarity index 99% rename from azurerm/resource_arm_key_vault_certificate_test.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_certificate_test.go index 8fcf9ab1a6dd..8284def0639d 100644 --- a/azurerm/resource_arm_key_vault_certificate_test.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_certificate_test.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/resource_arm_key_vault_key.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_key.go similarity index 99% rename from azurerm/resource_arm_key_vault_key.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_key.go index 7f03c2d7dbfb..a4d73e74de18 100644 --- a/azurerm/resource_arm_key_vault_key.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_key.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "encoding/base64" diff --git a/azurerm/resource_arm_key_vault_key_test.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_key_test.go similarity index 99% rename from azurerm/resource_arm_key_vault_key_test.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_key_test.go index 72aea9f8623e..afed4a81fb7f 100644 --- a/azurerm/resource_arm_key_vault_key_test.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_key_test.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/resource_arm_key_vault_migration.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go similarity index 99% rename from azurerm/resource_arm_key_vault_migration.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go index 29cb4093027f..f3dff4890ebe 100644 --- a/azurerm/resource_arm_key_vault_migration.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/resource_arm_key_vault_migration_test.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_migration_test.go similarity index 99% rename from azurerm/resource_arm_key_vault_migration_test.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_migration_test.go index 013ea29285ad..e3eed458484f 100644 --- a/azurerm/resource_arm_key_vault_migration_test.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_migration_test.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "reflect" diff --git a/azurerm/resource_arm_key_vault_secret.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_secret.go similarity index 99% rename from azurerm/resource_arm_key_vault_secret.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_secret.go index 58878cabb13c..32d0974970c8 100644 --- a/azurerm/resource_arm_key_vault_secret.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_secret.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/resource_arm_key_vault_secret_test.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_secret_test.go similarity index 99% rename from azurerm/resource_arm_key_vault_secret_test.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_secret_test.go index 8bf950c843ff..1e6c11423266 100644 --- a/azurerm/resource_arm_key_vault_secret_test.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_secret_test.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/resource_arm_key_vault_test.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_test.go similarity index 99% rename from azurerm/resource_arm_key_vault_test.go rename to azurerm/internal/services/keyvault/resource_arm_key_vault_test.go index 83167e326f9a..9b807eb77a21 100644 --- a/azurerm/resource_arm_key_vault_test.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_test.go @@ -1,4 +1,4 @@ -package azurerm +package keyvault import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index c2e19956f9bc..6e63b0d93dcf 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -12,10 +12,6 @@ func Provider() terraform.ResourceProvider { "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), "azurerm_image": dataSourceArmImage(), - "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_key": dataSourceArmKeyVaultKey(), - "azurerm_key_vault_secret": dataSourceArmKeyVaultSecret(), - "azurerm_key_vault": dataSourceArmKeyVault(), "azurerm_platform_image": dataSourceArmPlatformImage(), "azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(), "azurerm_resources": dataSourceArmResources(), @@ -34,11 +30,6 @@ func Provider() terraform.ResourceProvider { "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_dashboard": resourceArmDashboard(), "azurerm_image": resourceArmImage(), - "azurerm_key_vault_access_policy": resourceArmKeyVaultAccessPolicy(), - "azurerm_key_vault_certificate": resourceArmKeyVaultCertificate(), - "azurerm_key_vault_key": resourceArmKeyVaultKey(), - "azurerm_key_vault_secret": resourceArmKeyVaultSecret(), - "azurerm_key_vault": resourceArmKeyVault(), "azurerm_management_lock": resourceArmManagementLock(), "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), "azurerm_resource_group": resourceArmResourceGroup(), From 9a73efa829dc053bedad7bccc48d3ac4ca94ba30 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:46:17 -0800 Subject: [PATCH 064/203] storage --- .../storage}/data_source_storage_account.go | 2 +- ...urce_storage_account_blob_container_sas.go | 2 +- ...storage_account_blob_container_sas_test.go | 2 +- .../data_source_storage_account_sas.go | 2 +- .../data_source_storage_account_sas_test.go | 2 +- .../data_source_storage_account_test.go | 2 +- .../data_source_storage_management_policy.go | 2 +- ...a_source_storage_management_policy_test.go | 2 +- .../internal/services/storage/registration.go | 21 ++++++- .../storage}/resource_arm_storage_account.go | 2 +- .../resource_arm_storage_account_migration.go | 2 +- ...urce_arm_storage_account_migration_test.go | 2 +- ...ource_arm_storage_account_network_rules.go | 2 +- ..._arm_storage_account_network_rules_test.go | 2 +- .../resource_arm_storage_account_test.go | 2 +- .../storage}/resource_arm_storage_blob.go | 13 ++-- .../resource_arm_storage_blob_migration.go | 2 +- ...esource_arm_storage_blob_migration_test.go | 2 +- .../resource_arm_storage_blob_test.go | 2 +- .../resource_arm_storage_container.go | 11 ++-- ...esource_arm_storage_container_migration.go | 2 +- ...ce_arm_storage_container_migration_test.go | 2 +- .../resource_arm_storage_container_test.go | 2 +- ...e_arm_storage_data_lake_gen2_filesystem.go | 11 ++-- ..._storage_data_lake_gen2_filesystem_test.go | 2 +- .../resource_arm_storage_management_policy.go | 2 +- ...urce_arm_storage_management_policy_test.go | 2 +- .../storage}/resource_arm_storage_queue.go | 11 ++-- .../resource_arm_storage_queue_migration.go | 2 +- ...source_arm_storage_queue_migration_test.go | 2 +- .../resource_arm_storage_queue_test.go | 2 +- .../storage}/resource_arm_storage_share.go | 13 ++-- .../resource_arm_storage_share_directory.go | 11 ++-- ...source_arm_storage_share_directory_test.go | 2 +- .../resource_arm_storage_share_migration.go | 5 +- ...source_arm_storage_share_migration_test.go | 2 +- .../resource_arm_storage_share_test.go | 2 +- .../storage}/resource_arm_storage_table.go | 2 +- .../resource_arm_storage_table_entity.go | 2 +- .../resource_arm_storage_table_entity_test.go | 2 +- .../resource_arm_storage_table_migration.go | 2 +- ...source_arm_storage_table_migration_test.go | 2 +- .../resource_arm_storage_table_test.go | 2 +- azurerm/provider.go | 59 +++++++------------ 44 files changed, 110 insertions(+), 115 deletions(-) rename azurerm/{ => internal/services/storage}/data_source_storage_account.go (99%) rename azurerm/{ => internal/services/storage}/data_source_storage_account_blob_container_sas.go (99%) rename azurerm/{ => internal/services/storage}/data_source_storage_account_blob_container_sas_test.go (99%) rename azurerm/{ => internal/services/storage}/data_source_storage_account_sas.go (99%) rename azurerm/{ => internal/services/storage}/data_source_storage_account_sas_test.go (99%) rename azurerm/{ => internal/services/storage}/data_source_storage_account_test.go (99%) rename azurerm/{ => internal/services/storage}/data_source_storage_management_policy.go (99%) rename azurerm/{ => internal/services/storage}/data_source_storage_management_policy_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_account.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_account_migration.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_account_migration_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_account_network_rules.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_account_network_rules_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_account_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_blob.go (97%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_blob_migration.go (98%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_blob_migration_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_blob_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_container.go (97%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_container_migration.go (98%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_container_migration_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_container_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_data_lake_gen2_filesystem.go (96%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_data_lake_gen2_filesystem_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_management_policy.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_management_policy_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_queue.go (95%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_queue_migration.go (98%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_queue_migration_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_queue_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_share.go (96%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_share_directory.go (96%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_share_directory_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_share_migration.go (93%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_share_migration_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_share_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_table.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_table_entity.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_table_entity_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_table_migration.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_table_migration_test.go (99%) rename azurerm/{ => internal/services/storage}/resource_arm_storage_table_test.go (99%) diff --git a/azurerm/data_source_storage_account.go b/azurerm/internal/services/storage/data_source_storage_account.go similarity index 99% rename from azurerm/data_source_storage_account.go rename to azurerm/internal/services/storage/data_source_storage_account.go index 58712ee979b1..ba8d8770769e 100644 --- a/azurerm/data_source_storage_account.go +++ b/azurerm/internal/services/storage/data_source_storage_account.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/data_source_storage_account_blob_container_sas.go b/azurerm/internal/services/storage/data_source_storage_account_blob_container_sas.go similarity index 99% rename from azurerm/data_source_storage_account_blob_container_sas.go rename to azurerm/internal/services/storage/data_source_storage_account_blob_container_sas.go index 32c11b4564ac..691af2c924c8 100644 --- a/azurerm/data_source_storage_account_blob_container_sas.go +++ b/azurerm/internal/services/storage/data_source_storage_account_blob_container_sas.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "crypto/sha256" diff --git a/azurerm/data_source_storage_account_blob_container_sas_test.go b/azurerm/internal/services/storage/data_source_storage_account_blob_container_sas_test.go similarity index 99% rename from azurerm/data_source_storage_account_blob_container_sas_test.go rename to azurerm/internal/services/storage/data_source_storage_account_blob_container_sas_test.go index 13b91ce1a715..8959e41c9a62 100644 --- a/azurerm/data_source_storage_account_blob_container_sas_test.go +++ b/azurerm/internal/services/storage/data_source_storage_account_blob_container_sas_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/data_source_storage_account_sas.go b/azurerm/internal/services/storage/data_source_storage_account_sas.go similarity index 99% rename from azurerm/data_source_storage_account_sas.go rename to azurerm/internal/services/storage/data_source_storage_account_sas.go index 315c88279d6d..0b18b89ec609 100644 --- a/azurerm/data_source_storage_account_sas.go +++ b/azurerm/internal/services/storage/data_source_storage_account_sas.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "crypto/sha256" diff --git a/azurerm/data_source_storage_account_sas_test.go b/azurerm/internal/services/storage/data_source_storage_account_sas_test.go similarity index 99% rename from azurerm/data_source_storage_account_sas_test.go rename to azurerm/internal/services/storage/data_source_storage_account_sas_test.go index ac3c2d2487c5..a7a1eb00a023 100644 --- a/azurerm/data_source_storage_account_sas_test.go +++ b/azurerm/internal/services/storage/data_source_storage_account_sas_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/data_source_storage_account_test.go b/azurerm/internal/services/storage/data_source_storage_account_test.go similarity index 99% rename from azurerm/data_source_storage_account_test.go rename to azurerm/internal/services/storage/data_source_storage_account_test.go index 15151f740a40..19ed75c26912 100644 --- a/azurerm/data_source_storage_account_test.go +++ b/azurerm/internal/services/storage/data_source_storage_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/data_source_storage_management_policy.go b/azurerm/internal/services/storage/data_source_storage_management_policy.go similarity index 99% rename from azurerm/data_source_storage_management_policy.go rename to azurerm/internal/services/storage/data_source_storage_management_policy.go index 4086575995ab..9927072e8928 100644 --- a/azurerm/data_source_storage_management_policy.go +++ b/azurerm/internal/services/storage/data_source_storage_management_policy.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/data_source_storage_management_policy_test.go b/azurerm/internal/services/storage/data_source_storage_management_policy_test.go similarity index 99% rename from azurerm/data_source_storage_management_policy_test.go rename to azurerm/internal/services/storage/data_source_storage_management_policy_test.go index 46fb74eba9d6..e0a305fa9003 100644 --- a/azurerm/data_source_storage_management_policy_test.go +++ b/azurerm/internal/services/storage/data_source_storage_management_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/internal/services/storage/registration.go b/azurerm/internal/services/storage/registration.go index 8bdfdf63ebc6..25e4e3dec36c 100644 --- a/azurerm/internal/services/storage/registration.go +++ b/azurerm/internal/services/storage/registration.go @@ -13,10 +13,27 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), + "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), + "azurerm_storage_account": dataSourceArmStorageAccount(), + "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_storage_account": resourceArmStorageAccount(), + "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), + "azurerm_storage_blob": resourceArmStorageBlob(), + "azurerm_storage_container": resourceArmStorageContainer(), + "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), + "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), + "azurerm_storage_queue": resourceArmStorageQueue(), + "azurerm_storage_share": resourceArmStorageShare(), + "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), + "azurerm_storage_table": resourceArmStorageTable(), + "azurerm_storage_table_entity": resourceArmStorageTableEntity(), + } } diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/internal/services/storage/resource_arm_storage_account.go similarity index 99% rename from azurerm/resource_arm_storage_account.go rename to azurerm/internal/services/storage/resource_arm_storage_account.go index fcf696edf4eb..e94a4fce9cf5 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_account_migration.go b/azurerm/internal/services/storage/resource_arm_storage_account_migration.go similarity index 99% rename from azurerm/resource_arm_storage_account_migration.go rename to azurerm/internal/services/storage/resource_arm_storage_account_migration.go index 53b64126903c..e8d88fd16c03 100644 --- a/azurerm/resource_arm_storage_account_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account_migration.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_account_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go similarity index 99% rename from azurerm/resource_arm_storage_account_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go index 04cf839a6cf1..663dcae4c61d 100644 --- a/azurerm/resource_arm_storage_account_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "testing" diff --git a/azurerm/resource_arm_storage_account_network_rules.go b/azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go similarity index 99% rename from azurerm/resource_arm_storage_account_network_rules.go rename to azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go index 841da2f05c50..3735483df7fe 100644 --- a/azurerm/resource_arm_storage_account_network_rules.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_account_network_rules_test.go b/azurerm/internal/services/storage/resource_arm_storage_account_network_rules_test.go similarity index 99% rename from azurerm/resource_arm_storage_account_network_rules_test.go rename to azurerm/internal/services/storage/resource_arm_storage_account_network_rules_test.go index 90f7eb3e592b..3a9bb6568cec 100644 --- a/azurerm/resource_arm_storage_account_network_rules_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account_network_rules_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_account_test.go b/azurerm/internal/services/storage/resource_arm_storage_account_test.go similarity index 99% rename from azurerm/resource_arm_storage_account_test.go rename to azurerm/internal/services/storage/resource_arm_storage_account_test.go index 9e8273ca2f3c..63111673ed06 100644 --- a/azurerm/resource_arm_storage_account_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_blob.go b/azurerm/internal/services/storage/resource_arm_storage_blob.go similarity index 97% rename from azurerm/resource_arm_storage_blob.go rename to azurerm/internal/services/storage/resource_arm_storage_blob.go index 6ef88fd611d2..c4d3a01ff432 100644 --- a/azurerm/resource_arm_storage_blob.go +++ b/azurerm/internal/services/storage/resource_arm_storage_blob.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" @@ -14,7 +14,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/blobs" @@ -133,7 +132,7 @@ func resourceArmStorageBlob() *schema.Resource { ValidateFunc: validation.IntAtLeast(1), }, - "metadata": storage.MetaDataComputedSchema(), + "metadata": MetaDataComputedSchema(), // Deprecated fields "attempts": { @@ -188,7 +187,7 @@ func resourceArmStorageBlobCreate(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Creating Blob %q in Container %q within Storage Account %q..", name, containerName, accountName) metaDataRaw := d.Get("metadata").(map[string]interface{}) - blobInput := storage.BlobUpload{ + blobInput := BlobUpload{ AccountName: accountName, ContainerName: containerName, BlobName: name, @@ -196,7 +195,7 @@ func resourceArmStorageBlobCreate(d *schema.ResourceData, meta interface{}) erro BlobType: d.Get("type").(string), ContentType: d.Get("content_type").(string), - MetaData: storage.ExpandMetaData(metaDataRaw), + MetaData: ExpandMetaData(metaDataRaw), Parallelism: d.Get("parallelism").(int), Size: d.Get("size").(int), Source: d.Get("source").(string), @@ -263,7 +262,7 @@ func resourceArmStorageBlobUpdate(d *schema.ResourceData, meta interface{}) erro log.Printf("[DEBUG] Updating MetaData for Blob %q (Container %q / Account %q)...", id.BlobName, id.ContainerName, id.AccountName) metaDataRaw := d.Get("metadata").(map[string]interface{}) input := blobs.SetMetaDataInput{ - MetaData: storage.ExpandMetaData(metaDataRaw), + MetaData: ExpandMetaData(metaDataRaw), } if _, err := blobsClient.SetMetaData(ctx, id.AccountName, id.ContainerName, id.BlobName, input); err != nil { return fmt.Errorf("Error updating MetaData for Blob %q (Container %q / Account %q): %s", id.BlobName, id.ContainerName, id.AccountName, err) @@ -322,7 +321,7 @@ func resourceArmStorageBlobRead(d *schema.ResourceData, meta interface{}) error d.Set("type", strings.TrimSuffix(string(props.BlobType), "Blob")) d.Set("url", d.Id()) - if err := d.Set("metadata", storage.FlattenMetaData(props.MetaData)); err != nil { + if err := d.Set("metadata", FlattenMetaData(props.MetaData)); err != nil { return fmt.Errorf("Error setting `metadata`: %+v", err) } // The CopySource is only returned if the blob hasn't been modified (e.g. metadata configured etc) diff --git a/azurerm/resource_arm_storage_blob_migration.go b/azurerm/internal/services/storage/resource_arm_storage_blob_migration.go similarity index 98% rename from azurerm/resource_arm_storage_blob_migration.go rename to azurerm/internal/services/storage/resource_arm_storage_blob_migration.go index 77f1a764491f..0b5056c6feed 100644 --- a/azurerm/resource_arm_storage_blob_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_blob_migration.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_blob_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go similarity index 99% rename from azurerm/resource_arm_storage_blob_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go index 7ca0917fa37c..65452307ca8b 100644 --- a/azurerm/resource_arm_storage_blob_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "context" diff --git a/azurerm/resource_arm_storage_blob_test.go b/azurerm/internal/services/storage/resource_arm_storage_blob_test.go similarity index 99% rename from azurerm/resource_arm_storage_blob_test.go rename to azurerm/internal/services/storage/resource_arm_storage_blob_test.go index 0b9dc225310e..1d5a890857be 100644 --- a/azurerm/resource_arm_storage_blob_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_blob_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "crypto/rand" diff --git a/azurerm/resource_arm_storage_container.go b/azurerm/internal/services/storage/resource_arm_storage_container.go similarity index 97% rename from azurerm/resource_arm_storage_container.go rename to azurerm/internal/services/storage/resource_arm_storage_container.go index 9ee6dd90f3d0..5d2b563f51d3 100644 --- a/azurerm/resource_arm_storage_container.go +++ b/azurerm/internal/services/storage/resource_arm_storage_container.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" @@ -12,7 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/blob/containers" @@ -64,7 +63,7 @@ func resourceArmStorageContainer() *schema.Resource { }, false), }, - "metadata": storage.MetaDataComputedSchema(), + "metadata": MetaDataComputedSchema(), // TODO: support for ACL's, Legal Holds and Immutability Policies "has_immutability_policy": { @@ -102,7 +101,7 @@ func resourceArmStorageContainerCreate(d *schema.ResourceData, meta interface{}) accessLevel := expandStorageContainerAccessLevel(accessLevelRaw) metaDataRaw := d.Get("metadata").(map[string]interface{}) - metaData := storage.ExpandMetaData(metaDataRaw) + metaData := ExpandMetaData(metaDataRaw) account, err := storageClient.FindAccount(ctx, accountName) if err != nil { @@ -181,7 +180,7 @@ func resourceArmStorageContainerUpdate(d *schema.ResourceData, meta interface{}) if d.HasChange("metadata") { log.Printf("[DEBUG] Updating the MetaData for Container %q (Storage Account %q / Resource Group %q)..", id.ContainerName, id.AccountName, account.ResourceGroup) metaDataRaw := d.Get("metadata").(map[string]interface{}) - metaData := storage.ExpandMetaData(metaDataRaw) + metaData := ExpandMetaData(metaDataRaw) if _, err := client.SetMetaData(ctx, id.AccountName, id.ContainerName, metaData); err != nil { return fmt.Errorf("Error updating the MetaData for Container %q (Storage Account %q / Resource Group %q): %s", id.ContainerName, id.AccountName, account.ResourceGroup, err) @@ -234,7 +233,7 @@ func resourceArmStorageContainerRead(d *schema.ResourceData, meta interface{}) e d.Set("container_access_type", flattenStorageContainerAccessLevel(props.AccessLevel)) - if err := d.Set("metadata", storage.FlattenMetaData(props.MetaData)); err != nil { + if err := d.Set("metadata", FlattenMetaData(props.MetaData)); err != nil { return fmt.Errorf("Error setting `metadata`: %+v", err) } diff --git a/azurerm/resource_arm_storage_container_migration.go b/azurerm/internal/services/storage/resource_arm_storage_container_migration.go similarity index 98% rename from azurerm/resource_arm_storage_container_migration.go rename to azurerm/internal/services/storage/resource_arm_storage_container_migration.go index bf9936ce4447..cf0c3f29bdf6 100644 --- a/azurerm/resource_arm_storage_container_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_container_migration.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_container_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go similarity index 99% rename from azurerm/resource_arm_storage_container_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go index db4b67f1edb0..21c2100ec091 100644 --- a/azurerm/resource_arm_storage_container_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "context" diff --git a/azurerm/resource_arm_storage_container_test.go b/azurerm/internal/services/storage/resource_arm_storage_container_test.go similarity index 99% rename from azurerm/resource_arm_storage_container_test.go rename to azurerm/internal/services/storage/resource_arm_storage_container_test.go index e71272ea47de..93d21845df80 100644 --- a/azurerm/resource_arm_storage_container_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_container_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_data_lake_gen2_filesystem.go b/azurerm/internal/services/storage/resource_arm_storage_data_lake_gen2_filesystem.go similarity index 96% rename from azurerm/resource_arm_storage_data_lake_gen2_filesystem.go rename to azurerm/internal/services/storage/resource_arm_storage_data_lake_gen2_filesystem.go index 5d5693b4bbe2..b24a5e6f07fe 100644 --- a/azurerm/resource_arm_storage_data_lake_gen2_filesystem.go +++ b/azurerm/internal/services/storage/resource_arm_storage_data_lake_gen2_filesystem.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "context" @@ -11,7 +11,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage/parsers" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -66,9 +65,9 @@ func resourceArmStorageDataLakeGen2FileSystem() *schema.Resource { ValidateFunc: validateArmStorageDataLakeGen2FileSystemName, }, - "storage_account_id": storage.AccountIDSchema(), + "storage_account_id": AccountIDSchema(), - "properties": storage.MetaDataSchema(), + "properties": MetaDataSchema(), }, } } @@ -96,7 +95,7 @@ func resourceArmStorageDataLakeGen2FileSystemCreate(d *schema.ResourceData, meta fileSystemName := d.Get("name").(string) propertiesRaw := d.Get("properties").(map[string]interface{}) - properties := storage.ExpandMetaData(propertiesRaw) + properties := ExpandMetaData(propertiesRaw) id := client.GetResourceID(storageID.Name, fileSystemName) @@ -152,7 +151,7 @@ func resourceArmStorageDataLakeGen2FileSystemUpdate(d *schema.ResourceData, meta } propertiesRaw := d.Get("properties").(map[string]interface{}) - properties := storage.ExpandMetaData(propertiesRaw) + properties := ExpandMetaData(propertiesRaw) log.Printf("[INFO] Updating Properties for File System %q in Storage Account %q.", id.DirectoryName, id.AccountName) input := filesystems.SetPropertiesInput{ diff --git a/azurerm/resource_arm_storage_data_lake_gen2_filesystem_test.go b/azurerm/internal/services/storage/resource_arm_storage_data_lake_gen2_filesystem_test.go similarity index 99% rename from azurerm/resource_arm_storage_data_lake_gen2_filesystem_test.go rename to azurerm/internal/services/storage/resource_arm_storage_data_lake_gen2_filesystem_test.go index 4d96123760ad..1803d984affd 100644 --- a/azurerm/resource_arm_storage_data_lake_gen2_filesystem_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_data_lake_gen2_filesystem_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_management_policy.go b/azurerm/internal/services/storage/resource_arm_storage_management_policy.go similarity index 99% rename from azurerm/resource_arm_storage_management_policy.go rename to azurerm/internal/services/storage/resource_arm_storage_management_policy.go index 6b73e0718301..1c88f0f98f29 100644 --- a/azurerm/resource_arm_storage_management_policy.go +++ b/azurerm/internal/services/storage/resource_arm_storage_management_policy.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_management_policy_test.go b/azurerm/internal/services/storage/resource_arm_storage_management_policy_test.go similarity index 99% rename from azurerm/resource_arm_storage_management_policy_test.go rename to azurerm/internal/services/storage/resource_arm_storage_management_policy_test.go index 89d2e092ec1b..bbc08724071e 100644 --- a/azurerm/resource_arm_storage_management_policy_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_management_policy_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_queue.go b/azurerm/internal/services/storage/resource_arm_storage_queue.go similarity index 95% rename from azurerm/resource_arm_storage_queue.go rename to azurerm/internal/services/storage/resource_arm_storage_queue.go index bb6c425745e4..f2d626d6e310 100644 --- a/azurerm/resource_arm_storage_queue.go +++ b/azurerm/internal/services/storage/resource_arm_storage_queue.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" @@ -11,7 +11,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/queue/queues" @@ -53,7 +52,7 @@ func resourceArmStorageQueue() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), - "metadata": storage.MetaDataSchema(), + "metadata": MetaDataSchema(), }, } } @@ -96,7 +95,7 @@ func resourceArmStorageQueueCreate(d *schema.ResourceData, meta interface{}) err accountName := d.Get("storage_account_name").(string) metaDataRaw := d.Get("metadata").(map[string]interface{}) - metaData := storage.ExpandMetaData(metaDataRaw) + metaData := ExpandMetaData(metaDataRaw) account, err := storageClient.FindAccount(ctx, accountName) if err != nil { @@ -145,7 +144,7 @@ func resourceArmStorageQueueUpdate(d *schema.ResourceData, meta interface{}) err } metaDataRaw := d.Get("metadata").(map[string]interface{}) - metaData := storage.ExpandMetaData(metaDataRaw) + metaData := ExpandMetaData(metaDataRaw) account, err := storageClient.FindAccount(ctx, id.AccountName) if err != nil { @@ -207,7 +206,7 @@ func resourceArmStorageQueueRead(d *schema.ResourceData, meta interface{}) error d.Set("storage_account_name", id.AccountName) d.Set("resource_group_name", account.ResourceGroup) - if err := d.Set("metadata", storage.FlattenMetaData(metaData.MetaData)); err != nil { + if err := d.Set("metadata", FlattenMetaData(metaData.MetaData)); err != nil { return fmt.Errorf("Error setting `metadata`: %s", err) } diff --git a/azurerm/resource_arm_storage_queue_migration.go b/azurerm/internal/services/storage/resource_arm_storage_queue_migration.go similarity index 98% rename from azurerm/resource_arm_storage_queue_migration.go rename to azurerm/internal/services/storage/resource_arm_storage_queue_migration.go index da3daa1e0a41..c8d9681c5e25 100644 --- a/azurerm/resource_arm_storage_queue_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_queue_migration.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_queue_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go similarity index 99% rename from azurerm/resource_arm_storage_queue_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go index 9f0c3eee6124..eea7f691760f 100644 --- a/azurerm/resource_arm_storage_queue_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "context" diff --git a/azurerm/resource_arm_storage_queue_test.go b/azurerm/internal/services/storage/resource_arm_storage_queue_test.go similarity index 99% rename from azurerm/resource_arm_storage_queue_test.go rename to azurerm/internal/services/storage/resource_arm_storage_queue_test.go index d4518700fad3..772bdd975a7f 100644 --- a/azurerm/resource_arm_storage_queue_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_queue_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_share.go b/azurerm/internal/services/storage/resource_arm_storage_share.go similarity index 96% rename from azurerm/resource_arm_storage_share.go rename to azurerm/internal/services/storage/resource_arm_storage_share.go index 0b882638a61b..3931a93ff797 100644 --- a/azurerm/resource_arm_storage_share.go +++ b/azurerm/internal/services/storage/resource_arm_storage_share.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" @@ -12,7 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/shares" @@ -54,7 +53,7 @@ func resourceArmStorageShare() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: storage.ValidateArmStorageShareName, + ValidateFunc: ValidateArmStorageShareName, }, "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), @@ -72,7 +71,7 @@ func resourceArmStorageShare() *schema.Resource { ValidateFunc: validation.IntBetween(1, 102400), }, - "metadata": storage.MetaDataSchema(), + "metadata": MetaDataSchema(), "acl": { Type: schema.TypeSet, @@ -128,7 +127,7 @@ func resourceArmStorageShareCreate(d *schema.ResourceData, meta interface{}) err quota := d.Get("quota").(int) metaDataRaw := d.Get("metadata").(map[string]interface{}) - metaData := storage.ExpandMetaData(metaDataRaw) + metaData := ExpandMetaData(metaDataRaw) aclsRaw := d.Get("acl").(*schema.Set).List() acls := expandStorageShareACLs(aclsRaw) @@ -224,7 +223,7 @@ func resourceArmStorageShareRead(d *schema.ResourceData, meta interface{}) error d.Set("url", client.GetResourceID(id.AccountName, id.ShareName)) d.Set("quota", props.ShareQuota) - if err := d.Set("metadata", storage.FlattenMetaData(props.MetaData)); err != nil { + if err := d.Set("metadata", FlattenMetaData(props.MetaData)); err != nil { return fmt.Errorf("Error flattening `metadata`: %+v", err) } @@ -275,7 +274,7 @@ func resourceArmStorageShareUpdate(d *schema.ResourceData, meta interface{}) err log.Printf("[DEBUG] Updating the MetaData for File Share %q (Storage Account %q)", id.ShareName, id.AccountName) metaDataRaw := d.Get("metadata").(map[string]interface{}) - metaData := storage.ExpandMetaData(metaDataRaw) + metaData := ExpandMetaData(metaDataRaw) if _, err := client.SetMetaData(ctx, id.AccountName, id.ShareName, metaData); err != nil { return fmt.Errorf("Error updating MetaData for File Share %q (Storage Account %q): %s", id.ShareName, id.AccountName, err) diff --git a/azurerm/resource_arm_storage_share_directory.go b/azurerm/internal/services/storage/resource_arm_storage_share_directory.go similarity index 96% rename from azurerm/resource_arm_storage_share_directory.go rename to azurerm/internal/services/storage/resource_arm_storage_share_directory.go index b731855181b2..627c3333adb8 100644 --- a/azurerm/resource_arm_storage_share_directory.go +++ b/azurerm/internal/services/storage/resource_arm_storage_share_directory.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "context" @@ -13,7 +13,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/directories" @@ -56,7 +55,7 @@ func resourceArmStorageShareDirectory() *schema.Resource { ValidateFunc: validate.NoEmptyStrings, }, - "metadata": storage.MetaDataSchema(), + "metadata": MetaDataSchema(), }, } } @@ -71,7 +70,7 @@ func resourceArmStorageShareDirectoryCreate(d *schema.ResourceData, meta interfa directoryName := d.Get("name").(string) metaDataRaw := d.Get("metadata").(map[string]interface{}) - metaData := storage.ExpandMetaData(metaDataRaw) + metaData := ExpandMetaData(metaDataRaw) account, err := storageClient.FindAccount(ctx, accountName) if err != nil { @@ -141,7 +140,7 @@ func resourceArmStorageShareDirectoryUpdate(d *schema.ResourceData, meta interfa } metaDataRaw := d.Get("metadata").(map[string]interface{}) - metaData := storage.ExpandMetaData(metaDataRaw) + metaData := ExpandMetaData(metaDataRaw) account, err := storageClient.FindAccount(ctx, id.AccountName) if err != nil { @@ -197,7 +196,7 @@ func resourceArmStorageShareDirectoryRead(d *schema.ResourceData, meta interface d.Set("share_name", id.ShareName) d.Set("storage_account_name", id.AccountName) - if err := d.Set("metadata", storage.FlattenMetaData(props.MetaData)); err != nil { + if err := d.Set("metadata", FlattenMetaData(props.MetaData)); err != nil { return fmt.Errorf("Error setting `metadata`: %s", err) } diff --git a/azurerm/resource_arm_storage_share_directory_test.go b/azurerm/internal/services/storage/resource_arm_storage_share_directory_test.go similarity index 99% rename from azurerm/resource_arm_storage_share_directory_test.go rename to azurerm/internal/services/storage/resource_arm_storage_share_directory_test.go index 91a47438ed37..c7fc1f4d77b4 100644 --- a/azurerm/resource_arm_storage_share_directory_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_share_directory_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_share_migration.go b/azurerm/internal/services/storage/resource_arm_storage_share_migration.go similarity index 93% rename from azurerm/resource_arm_storage_share_migration.go rename to azurerm/internal/services/storage/resource_arm_storage_share_migration.go index 471c9f232578..a6c89ba4734f 100644 --- a/azurerm/resource_arm_storage_share_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_share_migration.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/shares" ) @@ -21,7 +20,7 @@ func resourceStorageShareStateResourceV0V1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: storage.ValidateArmStorageShareName, + ValidateFunc: ValidateArmStorageShareName, }, "resource_group_name": azure.SchemaResourceGroupName(), "storage_account_name": { diff --git a/azurerm/resource_arm_storage_share_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go similarity index 99% rename from azurerm/resource_arm_storage_share_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go index 59f0fe0f5fd8..35a811e38925 100644 --- a/azurerm/resource_arm_storage_share_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_share_test.go b/azurerm/internal/services/storage/resource_arm_storage_share_test.go similarity index 99% rename from azurerm/resource_arm_storage_share_test.go rename to azurerm/internal/services/storage/resource_arm_storage_share_test.go index 22af48d1719f..be469a76a849 100644 --- a/azurerm/resource_arm_storage_share_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_share_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_table.go b/azurerm/internal/services/storage/resource_arm_storage_table.go similarity index 99% rename from azurerm/resource_arm_storage_table.go rename to azurerm/internal/services/storage/resource_arm_storage_table.go index ec19675353dc..79913d4d9287 100644 --- a/azurerm/resource_arm_storage_table.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_table_entity.go b/azurerm/internal/services/storage/resource_arm_storage_table_entity.go similarity index 99% rename from azurerm/resource_arm_storage_table_entity.go rename to azurerm/internal/services/storage/resource_arm_storage_table_entity.go index c8b94ba7275b..04f1d5226f31 100644 --- a/azurerm/resource_arm_storage_table_entity.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_entity.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_table_entity_test.go b/azurerm/internal/services/storage/resource_arm_storage_table_entity_test.go similarity index 99% rename from azurerm/resource_arm_storage_table_entity_test.go rename to azurerm/internal/services/storage/resource_arm_storage_table_entity_test.go index 1d4cdfae7390..ea7278a5b29d 100644 --- a/azurerm/resource_arm_storage_table_entity_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_entity_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_table_migration.go b/azurerm/internal/services/storage/resource_arm_storage_table_migration.go similarity index 99% rename from azurerm/resource_arm_storage_table_migration.go rename to azurerm/internal/services/storage/resource_arm_storage_table_migration.go index 28b7df0f4dcf..1396197249a6 100644 --- a/azurerm/resource_arm_storage_table_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_migration.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_table_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go similarity index 99% rename from azurerm/resource_arm_storage_table_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go index 856817e689c0..f24b171aa7f9 100644 --- a/azurerm/resource_arm_storage_table_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/resource_arm_storage_table_test.go b/azurerm/internal/services/storage/resource_arm_storage_table_test.go similarity index 99% rename from azurerm/resource_arm_storage_table_test.go rename to azurerm/internal/services/storage/resource_arm_storage_table_test.go index 215d553df7f3..8b9f7017664e 100644 --- a/azurerm/resource_arm_storage_table_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_test.go @@ -1,4 +1,4 @@ -package azurerm +package storage import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 6e63b0d93dcf..fcb9057474c5 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -8,46 +8,31 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_image": dataSourceArmImage(), - "azurerm_platform_image": dataSourceArmPlatformImage(), - "azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(), - "azurerm_resources": dataSourceArmResources(), - "azurerm_resource_group": dataSourceArmResourceGroup(), - "azurerm_storage_account_blob_container_sas": dataSourceArmStorageAccountBlobContainerSharedAccessSignature(), - "azurerm_storage_account_sas": dataSourceArmStorageAccountSharedAccessSignature(), - "azurerm_storage_account": dataSourceArmStorageAccount(), - "azurerm_storage_management_policy": dataSourceArmStorageManagementPolicy(), + "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), + "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), + "azurerm_client_config": dataSourceArmClientConfig(), + "azurerm_image": dataSourceArmImage(), + "azurerm_platform_image": dataSourceArmPlatformImage(), + "azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(), + "azurerm_resources": dataSourceArmResources(), + "azurerm_resource_group": dataSourceArmResourceGroup(), } resources := map[string]*schema.Resource{ - "azurerm_application_gateway": resourceArmApplicationGateway(), - "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), - "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_connection_monitor": resourceArmConnectionMonitor(), - "azurerm_dashboard": resourceArmDashboard(), - "azurerm_image": resourceArmImage(), - "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), - "azurerm_resource_group": resourceArmResourceGroup(), - "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), - "azurerm_shared_image_version": resourceArmSharedImageVersion(), - "azurerm_shared_image": resourceArmSharedImage(), - "azurerm_storage_account": resourceArmStorageAccount(), - "azurerm_storage_account_network_rules": resourceArmStorageAccountNetworkRules(), - "azurerm_storage_blob": resourceArmStorageBlob(), - "azurerm_storage_container": resourceArmStorageContainer(), - "azurerm_storage_data_lake_gen2_filesystem": resourceArmStorageDataLakeGen2FileSystem(), - "azurerm_storage_management_policy": resourceArmStorageManagementPolicy(), - "azurerm_storage_queue": resourceArmStorageQueue(), - "azurerm_storage_share": resourceArmStorageShare(), - "azurerm_storage_share_directory": resourceArmStorageShareDirectory(), - "azurerm_storage_table": resourceArmStorageTable(), - "azurerm_storage_table_entity": resourceArmStorageTableEntity(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_application_gateway": resourceArmApplicationGateway(), + "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), + "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), + "azurerm_bastion_host": resourceArmBastionHost(), + "azurerm_connection_monitor": resourceArmConnectionMonitor(), + "azurerm_dashboard": resourceArmDashboard(), + "azurerm_image": resourceArmImage(), + "azurerm_management_lock": resourceArmManagementLock(), + "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), + "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), + "azurerm_shared_image_version": resourceArmSharedImageVersion(), + "azurerm_shared_image": resourceArmSharedImage(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), } return provider.AzureProvider(dataSources, resources) From 544b42d74719aadf848166c5a85f2150809f1bcd Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:54:39 -0800 Subject: [PATCH 065/203] resource 2 --- .../services/resource}/data_source_resource_group.go | 2 +- .../resource}/data_source_resource_group_test.go | 2 +- .../services/resource}/data_source_resources.go | 2 +- .../services/resource}/data_source_resources_test.go | 2 +- azurerm/internal/services/resource/registration.go | 9 +++++++-- .../services/resource}/resource_arm_resource_group.go | 9 ++++----- .../resource}/resource_arm_resource_group_test.go | 2 +- azurerm/provider.go | 3 --- 8 files changed, 16 insertions(+), 15 deletions(-) rename azurerm/{ => internal/services/resource}/data_source_resource_group.go (98%) rename azurerm/{ => internal/services/resource}/data_source_resource_group_test.go (98%) rename azurerm/{ => internal/services/resource}/data_source_resources.go (99%) rename azurerm/{ => internal/services/resource}/data_source_resources_test.go (99%) rename azurerm/{ => internal/services/resource}/resource_arm_resource_group.go (94%) rename azurerm/{ => internal/services/resource}/resource_arm_resource_group_test.go (99%) diff --git a/azurerm/data_source_resource_group.go b/azurerm/internal/services/resource/data_source_resource_group.go similarity index 98% rename from azurerm/data_source_resource_group.go rename to azurerm/internal/services/resource/data_source_resource_group.go index c0bc307a97f9..aa1f39e96127 100644 --- a/azurerm/data_source_resource_group.go +++ b/azurerm/internal/services/resource/data_source_resource_group.go @@ -1,4 +1,4 @@ -package azurerm +package resource import ( "fmt" diff --git a/azurerm/data_source_resource_group_test.go b/azurerm/internal/services/resource/data_source_resource_group_test.go similarity index 98% rename from azurerm/data_source_resource_group_test.go rename to azurerm/internal/services/resource/data_source_resource_group_test.go index d14e36b44b99..c6bd34d47985 100644 --- a/azurerm/data_source_resource_group_test.go +++ b/azurerm/internal/services/resource/data_source_resource_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package resource import ( "testing" diff --git a/azurerm/data_source_resources.go b/azurerm/internal/services/resource/data_source_resources.go similarity index 99% rename from azurerm/data_source_resources.go rename to azurerm/internal/services/resource/data_source_resources.go index 0913c4f5501f..48ed9e975ab6 100644 --- a/azurerm/data_source_resources.go +++ b/azurerm/internal/services/resource/data_source_resources.go @@ -1,4 +1,4 @@ -package azurerm +package resource import ( "fmt" diff --git a/azurerm/data_source_resources_test.go b/azurerm/internal/services/resource/data_source_resources_test.go similarity index 99% rename from azurerm/data_source_resources_test.go rename to azurerm/internal/services/resource/data_source_resources_test.go index 0dad12df1cb9..2e36c6010e29 100644 --- a/azurerm/data_source_resources_test.go +++ b/azurerm/internal/services/resource/data_source_resources_test.go @@ -1,4 +1,4 @@ -package azurerm +package resource import ( "fmt" diff --git a/azurerm/internal/services/resource/registration.go b/azurerm/internal/services/resource/registration.go index b8bb3231d400..cd89cda1bbb2 100644 --- a/azurerm/internal/services/resource/registration.go +++ b/azurerm/internal/services/resource/registration.go @@ -13,10 +13,15 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_resources": dataSourceArmResources(), + "azurerm_resource_group": dataSourceArmResourceGroup(), + } } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_resource_group": resourceArmResourceGroup(), + } } diff --git a/azurerm/resource_arm_resource_group.go b/azurerm/internal/services/resource/resource_arm_resource_group.go similarity index 94% rename from azurerm/resource_arm_resource_group.go rename to azurerm/internal/services/resource/resource_arm_resource_group.go index 2d22dcd9618a..cc80dd516055 100644 --- a/azurerm/resource_arm_resource_group.go +++ b/azurerm/internal/services/resource/resource_arm_resource_group.go @@ -1,4 +1,4 @@ -package azurerm +package resource import ( "fmt" @@ -9,7 +9,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -27,7 +26,7 @@ func resourceArmResourceGroup() *schema.Resource { Update: resourceArmResourceGroupCreateUpdate, Delete: resourceArmResourceGroupDelete, Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { - _, err := resource.ParseResourceGroupID(id) + _, err := ParseResourceGroupID(id) return err }), @@ -94,7 +93,7 @@ func resourceArmResourceGroupRead(d *schema.ResourceData, meta interface{}) erro ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := resource.ParseResourceGroupID(d.Id()) + id, err := ParseResourceGroupID(d.Id()) if err != nil { return err } @@ -124,7 +123,7 @@ func resourceArmResourceGroupDelete(d *schema.ResourceData, meta interface{}) er ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := resource.ParseResourceGroupID(d.Id()) + id, err := ParseResourceGroupID(d.Id()) if err != nil { return err } diff --git a/azurerm/resource_arm_resource_group_test.go b/azurerm/internal/services/resource/resource_arm_resource_group_test.go similarity index 99% rename from azurerm/resource_arm_resource_group_test.go rename to azurerm/internal/services/resource/resource_arm_resource_group_test.go index 7b7ae3fe2917..8ba7ab541f93 100644 --- a/azurerm/resource_arm_resource_group_test.go +++ b/azurerm/internal/services/resource/resource_arm_resource_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package resource import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index fcb9057474c5..b5d5ed6616c7 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -14,8 +14,6 @@ func Provider() terraform.ResourceProvider { "azurerm_image": dataSourceArmImage(), "azurerm_platform_image": dataSourceArmPlatformImage(), "azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(), - "azurerm_resources": dataSourceArmResources(), - "azurerm_resource_group": dataSourceArmResourceGroup(), } resources := map[string]*schema.Resource{ @@ -28,7 +26,6 @@ func Provider() terraform.ResourceProvider { "azurerm_image": resourceArmImage(), "azurerm_management_lock": resourceArmManagementLock(), "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), - "azurerm_resource_group": resourceArmResourceGroup(), "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), "azurerm_shared_image_version": resourceArmSharedImageVersion(), "azurerm_shared_image": resourceArmSharedImage(), From 78b28044e337c03cf53895be5c689d62fafe7bf2 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 19:58:40 -0800 Subject: [PATCH 066/203] more compute pls --- .../services/compute}/data_source_image.go | 2 +- .../compute}/data_source_image_test.go | 2 +- .../compute}/data_source_platform_image.go | 2 +- .../data_source_platform_image_test.go | 2 +- .../data_source_proximity_placement_group.go | 2 +- ...a_source_proximity_placement_group_test.go | 2 +- .../internal/services/compute/registration.go | 20 +++++++++++++------ .../services/compute}/resource_arm_image.go | 2 +- .../compute}/resource_arm_image_test.go | 2 +- .../resource_arm_marketplace_agreement.go | 2 +- ...resource_arm_marketplace_agreement_test.go | 2 +- .../compute}/resource_arm_shared_image.go | 2 +- .../resource_arm_shared_image_gallery.go | 2 +- .../resource_arm_shared_image_gallery_test.go | 2 +- .../resource_arm_shared_image_test.go | 2 +- .../resource_arm_shared_image_version.go | 2 +- .../resource_arm_shared_image_version_test.go | 2 +- azurerm/provider.go | 8 -------- 18 files changed, 30 insertions(+), 30 deletions(-) rename azurerm/{ => internal/services/compute}/data_source_image.go (99%) rename azurerm/{ => internal/services/compute}/data_source_image_test.go (99%) rename azurerm/{ => internal/services/compute}/data_source_platform_image.go (99%) rename azurerm/{ => internal/services/compute}/data_source_platform_image_test.go (98%) rename azurerm/{ => internal/services/compute}/data_source_proximity_placement_group.go (99%) rename azurerm/{ => internal/services/compute}/data_source_proximity_placement_group_test.go (98%) rename azurerm/{ => internal/services/compute}/resource_arm_image.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_image_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_marketplace_agreement.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_marketplace_agreement_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_shared_image.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_shared_image_gallery.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_shared_image_gallery_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_shared_image_test.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_shared_image_version.go (99%) rename azurerm/{ => internal/services/compute}/resource_arm_shared_image_version_test.go (99%) diff --git a/azurerm/data_source_image.go b/azurerm/internal/services/compute/data_source_image.go similarity index 99% rename from azurerm/data_source_image.go rename to azurerm/internal/services/compute/data_source_image.go index d0a0c2bd9a13..216a160e393a 100644 --- a/azurerm/data_source_image.go +++ b/azurerm/internal/services/compute/data_source_image.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_image_test.go b/azurerm/internal/services/compute/data_source_image_test.go similarity index 99% rename from azurerm/data_source_image_test.go rename to azurerm/internal/services/compute/data_source_image_test.go index 73ec903b94b5..a3f2e3eae26f 100644 --- a/azurerm/data_source_image_test.go +++ b/azurerm/internal/services/compute/data_source_image_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_platform_image.go b/azurerm/internal/services/compute/data_source_platform_image.go similarity index 99% rename from azurerm/data_source_platform_image.go rename to azurerm/internal/services/compute/data_source_platform_image.go index 7fe914c410ac..6b4962d97a6b 100644 --- a/azurerm/data_source_platform_image.go +++ b/azurerm/internal/services/compute/data_source_platform_image.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_platform_image_test.go b/azurerm/internal/services/compute/data_source_platform_image_test.go similarity index 98% rename from azurerm/data_source_platform_image_test.go rename to azurerm/internal/services/compute/data_source_platform_image_test.go index ad837950945d..84f4878088cc 100644 --- a/azurerm/data_source_platform_image_test.go +++ b/azurerm/internal/services/compute/data_source_platform_image_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_proximity_placement_group.go b/azurerm/internal/services/compute/data_source_proximity_placement_group.go similarity index 99% rename from azurerm/data_source_proximity_placement_group.go rename to azurerm/internal/services/compute/data_source_proximity_placement_group.go index 85cdba2da462..d783ae710306 100644 --- a/azurerm/data_source_proximity_placement_group.go +++ b/azurerm/internal/services/compute/data_source_proximity_placement_group.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/data_source_proximity_placement_group_test.go b/azurerm/internal/services/compute/data_source_proximity_placement_group_test.go similarity index 98% rename from azurerm/data_source_proximity_placement_group_test.go rename to azurerm/internal/services/compute/data_source_proximity_placement_group_test.go index e6544103c83b..eb94cac9a32a 100644 --- a/azurerm/data_source_proximity_placement_group_test.go +++ b/azurerm/internal/services/compute/data_source_proximity_placement_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/internal/services/compute/registration.go b/azurerm/internal/services/compute/registration.go index a87acf3aa145..f6086757c50c 100644 --- a/azurerm/internal/services/compute/registration.go +++ b/azurerm/internal/services/compute/registration.go @@ -15,12 +15,15 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_availability_set": dataSourceArmAvailabilitySet(), - "azurerm_managed_disk": dataSourceArmManagedDisk(), - "azurerm_shared_image_gallery": dataSourceArmSharedImageGallery(), - "azurerm_shared_image_version": dataSourceArmSharedImageVersion(), - "azurerm_shared_image": dataSourceArmSharedImage(), - "azurerm_snapshot": dataSourceArmSnapshot(), + "azurerm_availability_set": dataSourceArmAvailabilitySet(), + "azurerm_managed_disk": dataSourceArmManagedDisk(), + "azurerm_image": dataSourceArmImage(), + "azurerm_platform_image": dataSourceArmPlatformImage(), + "azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(), + "azurerm_shared_image_gallery": dataSourceArmSharedImageGallery(), + "azurerm_shared_image_version": dataSourceArmSharedImageVersion(), + "azurerm_shared_image": dataSourceArmSharedImage(), + "azurerm_snapshot": dataSourceArmSnapshot(), } } @@ -29,6 +32,11 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { resources := map[string]*schema.Resource{ "azurerm_availability_set": resourceArmAvailabilitySet(), "azurerm_managed_disk": resourceArmManagedDisk(), + "azurerm_image": resourceArmImage(), + "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), + "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), + "azurerm_shared_image_version": resourceArmSharedImageVersion(), + "azurerm_shared_image": resourceArmSharedImage(), "azurerm_snapshot": resourceArmSnapshot(), "azurerm_virtual_machine_data_disk_attachment": resourceArmVirtualMachineDataDiskAttachment(), "azurerm_virtual_machine_extension": resourceArmVirtualMachineExtensions(), diff --git a/azurerm/resource_arm_image.go b/azurerm/internal/services/compute/resource_arm_image.go similarity index 99% rename from azurerm/resource_arm_image.go rename to azurerm/internal/services/compute/resource_arm_image.go index f32cb194e193..b186b9def99e 100644 --- a/azurerm/resource_arm_image.go +++ b/azurerm/internal/services/compute/resource_arm_image.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_image_test.go b/azurerm/internal/services/compute/resource_arm_image_test.go similarity index 99% rename from azurerm/resource_arm_image_test.go rename to azurerm/internal/services/compute/resource_arm_image_test.go index 1b368984ad12..de715e97f2fe 100644 --- a/azurerm/resource_arm_image_test.go +++ b/azurerm/internal/services/compute/resource_arm_image_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "bytes" diff --git a/azurerm/resource_arm_marketplace_agreement.go b/azurerm/internal/services/compute/resource_arm_marketplace_agreement.go similarity index 99% rename from azurerm/resource_arm_marketplace_agreement.go rename to azurerm/internal/services/compute/resource_arm_marketplace_agreement.go index e4ee49313787..1a25e93cc44d 100644 --- a/azurerm/resource_arm_marketplace_agreement.go +++ b/azurerm/internal/services/compute/resource_arm_marketplace_agreement.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_marketplace_agreement_test.go b/azurerm/internal/services/compute/resource_arm_marketplace_agreement_test.go similarity index 99% rename from azurerm/resource_arm_marketplace_agreement_test.go rename to azurerm/internal/services/compute/resource_arm_marketplace_agreement_test.go index ec4bd759af41..d3b2c835395b 100644 --- a/azurerm/resource_arm_marketplace_agreement_test.go +++ b/azurerm/internal/services/compute/resource_arm_marketplace_agreement_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_shared_image.go b/azurerm/internal/services/compute/resource_arm_shared_image.go similarity index 99% rename from azurerm/resource_arm_shared_image.go rename to azurerm/internal/services/compute/resource_arm_shared_image.go index 7431b063f21f..0182c1be8e64 100644 --- a/azurerm/resource_arm_shared_image.go +++ b/azurerm/internal/services/compute/resource_arm_shared_image.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_shared_image_gallery.go b/azurerm/internal/services/compute/resource_arm_shared_image_gallery.go similarity index 99% rename from azurerm/resource_arm_shared_image_gallery.go rename to azurerm/internal/services/compute/resource_arm_shared_image_gallery.go index 4aca3872b10b..f04a5c94126c 100644 --- a/azurerm/resource_arm_shared_image_gallery.go +++ b/azurerm/internal/services/compute/resource_arm_shared_image_gallery.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_shared_image_gallery_test.go b/azurerm/internal/services/compute/resource_arm_shared_image_gallery_test.go similarity index 99% rename from azurerm/resource_arm_shared_image_gallery_test.go rename to azurerm/internal/services/compute/resource_arm_shared_image_gallery_test.go index 3d8d1464ee23..ace54dd33144 100644 --- a/azurerm/resource_arm_shared_image_gallery_test.go +++ b/azurerm/internal/services/compute/resource_arm_shared_image_gallery_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_shared_image_test.go b/azurerm/internal/services/compute/resource_arm_shared_image_test.go similarity index 99% rename from azurerm/resource_arm_shared_image_test.go rename to azurerm/internal/services/compute/resource_arm_shared_image_test.go index aada94f53381..de560adfebf8 100644 --- a/azurerm/resource_arm_shared_image_test.go +++ b/azurerm/internal/services/compute/resource_arm_shared_image_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_shared_image_version.go b/azurerm/internal/services/compute/resource_arm_shared_image_version.go similarity index 99% rename from azurerm/resource_arm_shared_image_version.go rename to azurerm/internal/services/compute/resource_arm_shared_image_version.go index 258a5dfc5667..f266536d7bb4 100644 --- a/azurerm/resource_arm_shared_image_version.go +++ b/azurerm/internal/services/compute/resource_arm_shared_image_version.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/resource_arm_shared_image_version_test.go b/azurerm/internal/services/compute/resource_arm_shared_image_version_test.go similarity index 99% rename from azurerm/resource_arm_shared_image_version_test.go rename to azurerm/internal/services/compute/resource_arm_shared_image_version_test.go index 4e0a87c6b69e..8ec44953442e 100644 --- a/azurerm/resource_arm_shared_image_version_test.go +++ b/azurerm/internal/services/compute/resource_arm_shared_image_version_test.go @@ -1,4 +1,4 @@ -package azurerm +package compute import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index b5d5ed6616c7..f4be84d8c64b 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -11,9 +11,6 @@ func Provider() terraform.ResourceProvider { "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), "azurerm_client_config": dataSourceArmClientConfig(), - "azurerm_image": dataSourceArmImage(), - "azurerm_platform_image": dataSourceArmPlatformImage(), - "azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(), } resources := map[string]*schema.Resource{ @@ -23,12 +20,7 @@ func Provider() terraform.ResourceProvider { "azurerm_bastion_host": resourceArmBastionHost(), "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_dashboard": resourceArmDashboard(), - "azurerm_image": resourceArmImage(), "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), - "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), - "azurerm_shared_image_version": resourceArmSharedImageVersion(), - "azurerm_shared_image": resourceArmSharedImage(), "azurerm_template_deployment": resourceArmTemplateDeployment(), } From 53fa403ef46c04a8ce19dd74fa87edf3977d76eb Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 20:02:27 -0800 Subject: [PATCH 067/203] network 2 --- .../data_source_application_security_group.go | 2 +- ..._source_application_security_group_test.go | 2 +- .../internal/services/network/registration.go | 5 +++++ .../resource_arm_application_gateway.go | 2 +- .../resource_arm_application_gateway_test.go | 2 +- ...resource_arm_application_security_group.go | 2 +- ...rce_arm_application_security_group_test.go | 2 +- .../network}/resource_arm_bastion_host.go | 2 +- .../resource_arm_bastion_host_test.go | 2 +- .../resource_arm_connection_monitor.go | 2 +- .../resource_arm_connection_monitor_test.go | 2 +- azurerm/provider.go | 19 ++++++++----------- 12 files changed, 23 insertions(+), 21 deletions(-) rename azurerm/{ => internal/services/network}/data_source_application_security_group.go (99%) rename azurerm/{ => internal/services/network}/data_source_application_security_group_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_application_gateway.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_application_gateway_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_application_security_group.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_application_security_group_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_bastion_host.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_bastion_host_test.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_connection_monitor.go (99%) rename azurerm/{ => internal/services/network}/resource_arm_connection_monitor_test.go (99%) diff --git a/azurerm/data_source_application_security_group.go b/azurerm/internal/services/network/data_source_application_security_group.go similarity index 99% rename from azurerm/data_source_application_security_group.go rename to azurerm/internal/services/network/data_source_application_security_group.go index 154eae5305bd..1c95bcc37ce4 100644 --- a/azurerm/data_source_application_security_group.go +++ b/azurerm/internal/services/network/data_source_application_security_group.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/data_source_application_security_group_test.go b/azurerm/internal/services/network/data_source_application_security_group_test.go similarity index 99% rename from azurerm/data_source_application_security_group_test.go rename to azurerm/internal/services/network/data_source_application_security_group_test.go index 89a15d4dacef..20b9a646be49 100644 --- a/azurerm/data_source_application_security_group_test.go +++ b/azurerm/internal/services/network/data_source_application_security_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/internal/services/network/registration.go b/azurerm/internal/services/network/registration.go index a6b923a0d039..511642f05109 100644 --- a/azurerm/internal/services/network/registration.go +++ b/azurerm/internal/services/network/registration.go @@ -14,6 +14,7 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ + "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), "azurerm_express_route_circuit": dataSourceArmExpressRouteCircuit(), "azurerm_firewall": dataSourceArmFirewall(), "azurerm_lb": dataSourceArmLoadBalancer(), @@ -43,6 +44,10 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ + "azurerm_application_gateway": resourceArmApplicationGateway(), + "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), + "azurerm_bastion_host": resourceArmBastionHost(), + "azurerm_connection_monitor": resourceArmConnectionMonitor(), "azurerm_ddos_protection_plan": resourceArmDDoSProtectionPlan(), "azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(), "azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(), diff --git a/azurerm/resource_arm_application_gateway.go b/azurerm/internal/services/network/resource_arm_application_gateway.go similarity index 99% rename from azurerm/resource_arm_application_gateway.go rename to azurerm/internal/services/network/resource_arm_application_gateway.go index b3bb15a383d6..814bb10fd9d5 100644 --- a/azurerm/resource_arm_application_gateway.go +++ b/azurerm/internal/services/network/resource_arm_application_gateway.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_application_gateway_test.go b/azurerm/internal/services/network/resource_arm_application_gateway_test.go similarity index 99% rename from azurerm/resource_arm_application_gateway_test.go rename to azurerm/internal/services/network/resource_arm_application_gateway_test.go index 2c0b9c4fdaa1..f4678c029abb 100644 --- a/azurerm/resource_arm_application_gateway_test.go +++ b/azurerm/internal/services/network/resource_arm_application_gateway_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_application_security_group.go b/azurerm/internal/services/network/resource_arm_application_security_group.go similarity index 99% rename from azurerm/resource_arm_application_security_group.go rename to azurerm/internal/services/network/resource_arm_application_security_group.go index 03f075a43990..28529f486bce 100644 --- a/azurerm/resource_arm_application_security_group.go +++ b/azurerm/internal/services/network/resource_arm_application_security_group.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_application_security_group_test.go b/azurerm/internal/services/network/resource_arm_application_security_group_test.go similarity index 99% rename from azurerm/resource_arm_application_security_group_test.go rename to azurerm/internal/services/network/resource_arm_application_security_group_test.go index 23b7c4fed2b4..82d1854de7ec 100644 --- a/azurerm/resource_arm_application_security_group_test.go +++ b/azurerm/internal/services/network/resource_arm_application_security_group_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_bastion_host.go b/azurerm/internal/services/network/resource_arm_bastion_host.go similarity index 99% rename from azurerm/resource_arm_bastion_host.go rename to azurerm/internal/services/network/resource_arm_bastion_host.go index 4b3354f1c772..0abd01a1afa6 100644 --- a/azurerm/resource_arm_bastion_host.go +++ b/azurerm/internal/services/network/resource_arm_bastion_host.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_bastion_host_test.go b/azurerm/internal/services/network/resource_arm_bastion_host_test.go similarity index 99% rename from azurerm/resource_arm_bastion_host_test.go rename to azurerm/internal/services/network/resource_arm_bastion_host_test.go index 30228f4a2f57..8485d6e70f9e 100644 --- a/azurerm/resource_arm_bastion_host_test.go +++ b/azurerm/internal/services/network/resource_arm_bastion_host_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_connection_monitor.go b/azurerm/internal/services/network/resource_arm_connection_monitor.go similarity index 99% rename from azurerm/resource_arm_connection_monitor.go rename to azurerm/internal/services/network/resource_arm_connection_monitor.go index 24544f52381c..7ec5afe112ac 100644 --- a/azurerm/resource_arm_connection_monitor.go +++ b/azurerm/internal/services/network/resource_arm_connection_monitor.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/resource_arm_connection_monitor_test.go b/azurerm/internal/services/network/resource_arm_connection_monitor_test.go similarity index 99% rename from azurerm/resource_arm_connection_monitor_test.go rename to azurerm/internal/services/network/resource_arm_connection_monitor_test.go index 7639c83dfaa2..1b19af1fcdf3 100644 --- a/azurerm/resource_arm_connection_monitor_test.go +++ b/azurerm/internal/services/network/resource_arm_connection_monitor_test.go @@ -1,4 +1,4 @@ -package azurerm +package network import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index f4be84d8c64b..876729063914 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -8,20 +8,17 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - "azurerm_application_security_group": dataSourceArmApplicationSecurityGroup(), - "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_client_config": dataSourceArmClientConfig(), + + "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), + "azurerm_client_config": dataSourceArmClientConfig(), } resources := map[string]*schema.Resource{ - "azurerm_application_gateway": resourceArmApplicationGateway(), - "azurerm_application_security_group": resourceArmApplicationSecurityGroup(), - "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_bastion_host": resourceArmBastionHost(), - "azurerm_connection_monitor": resourceArmConnectionMonitor(), - "azurerm_dashboard": resourceArmDashboard(), - "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), + + "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), + "azurerm_dashboard": resourceArmDashboard(), + "azurerm_management_lock": resourceArmManagementLock(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), } return provider.AzureProvider(dataSources, resources) From e760eb8e98fde6c79a2e081ecc19c6edc93f81b3 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 20:03:57 -0800 Subject: [PATCH 068/203] additional authorization --- .../authorization}/data_source_builtin_role_definition.go | 2 +- .../data_source_builtin_role_definition_test.go | 2 +- azurerm/internal/services/authorization/registration.go | 3 ++- azurerm/provider.go | 4 +--- 4 files changed, 5 insertions(+), 6 deletions(-) rename azurerm/{ => internal/services/authorization}/data_source_builtin_role_definition.go (99%) rename azurerm/{ => internal/services/authorization}/data_source_builtin_role_definition_test.go (99%) diff --git a/azurerm/data_source_builtin_role_definition.go b/azurerm/internal/services/authorization/data_source_builtin_role_definition.go similarity index 99% rename from azurerm/data_source_builtin_role_definition.go rename to azurerm/internal/services/authorization/data_source_builtin_role_definition.go index 4f2817b3351f..3c47827503a1 100644 --- a/azurerm/data_source_builtin_role_definition.go +++ b/azurerm/internal/services/authorization/data_source_builtin_role_definition.go @@ -1,4 +1,4 @@ -package azurerm +package authorization import ( "fmt" diff --git a/azurerm/data_source_builtin_role_definition_test.go b/azurerm/internal/services/authorization/data_source_builtin_role_definition_test.go similarity index 99% rename from azurerm/data_source_builtin_role_definition_test.go rename to azurerm/internal/services/authorization/data_source_builtin_role_definition_test.go index f61c626523ca..f9cde6d89bfe 100644 --- a/azurerm/data_source_builtin_role_definition_test.go +++ b/azurerm/internal/services/authorization/data_source_builtin_role_definition_test.go @@ -1,4 +1,4 @@ -package azurerm +package authorization import ( "fmt" diff --git a/azurerm/internal/services/authorization/registration.go b/azurerm/internal/services/authorization/registration.go index 4191d118e700..bd5c394e93aa 100644 --- a/azurerm/internal/services/authorization/registration.go +++ b/azurerm/internal/services/authorization/registration.go @@ -14,7 +14,8 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_role_definition": dataSourceArmRoleDefinition(), + "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), + "azurerm_role_definition": dataSourceArmRoleDefinition(), } } diff --git a/azurerm/provider.go b/azurerm/provider.go index 876729063914..54bceb2a9301 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -8,9 +8,7 @@ import ( func Provider() terraform.ResourceProvider { dataSources := map[string]*schema.Resource{ - - "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), - "azurerm_client_config": dataSourceArmClientConfig(), + "azurerm_client_config": dataSourceArmClientConfig(), } resources := map[string]*schema.Resource{ From d7a121526a2043491ad0d38c8e541b51a271d1d0 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 20:30:45 -0800 Subject: [PATCH 069/203] remaining resource --- azurerm/helpers/azure/json.go | 19 +++++++++++++++++++ .../services/resource/registration.go | 4 +++- .../resource}/resource_arm_management_lock.go | 2 +- .../resource_arm_management_lock_test.go | 2 +- .../resource_arm_template_deployment.go | 19 +++---------------- .../resource_arm_template_deployment_test.go | 2 +- azurerm/provider.go | 6 ++---- azurerm/resource_arm_dashboard.go | 2 +- 8 files changed, 31 insertions(+), 25 deletions(-) create mode 100644 azurerm/helpers/azure/json.go rename azurerm/{ => internal/services/resource}/resource_arm_management_lock.go (99%) rename azurerm/{ => internal/services/resource}/resource_arm_management_lock_test.go (99%) rename azurerm/{ => internal/services/resource}/resource_arm_template_deployment.go (96%) rename azurerm/{ => internal/services/resource}/resource_arm_template_deployment_test.go (99%) diff --git a/azurerm/helpers/azure/json.go b/azurerm/helpers/azure/json.go new file mode 100644 index 000000000000..ce4f772c671b --- /dev/null +++ b/azurerm/helpers/azure/json.go @@ -0,0 +1,19 @@ +package azure + +import ( + "encoding/json" + "fmt" +) + +func NormalizeJson(jsonString interface{}) string { + if jsonString == nil || jsonString == "" { + return "" + } + var j interface{} + + if err := json.Unmarshal([]byte(jsonString.(string)), &j); err != nil { + return fmt.Sprintf("Error parsing JSON: %+v", err) + } + b, _ := json.Marshal(j) + return string(b[:]) +} diff --git a/azurerm/internal/services/resource/registration.go b/azurerm/internal/services/resource/registration.go index cd89cda1bbb2..08ad4bd5b533 100644 --- a/azurerm/internal/services/resource/registration.go +++ b/azurerm/internal/services/resource/registration.go @@ -22,6 +22,8 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_resource_group": resourceArmResourceGroup(), + "azurerm_management_lock": resourceArmManagementLock(), + "azurerm_template_deployment": resourceArmTemplateDeployment(), } } diff --git a/azurerm/resource_arm_management_lock.go b/azurerm/internal/services/resource/resource_arm_management_lock.go similarity index 99% rename from azurerm/resource_arm_management_lock.go rename to azurerm/internal/services/resource/resource_arm_management_lock.go index 3d525883b31f..1bf9bc215802 100644 --- a/azurerm/resource_arm_management_lock.go +++ b/azurerm/internal/services/resource/resource_arm_management_lock.go @@ -1,4 +1,4 @@ -package azurerm +package resource import ( "fmt" diff --git a/azurerm/resource_arm_management_lock_test.go b/azurerm/internal/services/resource/resource_arm_management_lock_test.go similarity index 99% rename from azurerm/resource_arm_management_lock_test.go rename to azurerm/internal/services/resource/resource_arm_management_lock_test.go index bbaeca61ce8a..0135192abfcd 100644 --- a/azurerm/resource_arm_management_lock_test.go +++ b/azurerm/internal/services/resource/resource_arm_management_lock_test.go @@ -1,4 +1,4 @@ -package azurerm +package resource import ( "fmt" diff --git a/azurerm/resource_arm_template_deployment.go b/azurerm/internal/services/resource/resource_arm_template_deployment.go similarity index 96% rename from azurerm/resource_arm_template_deployment.go rename to azurerm/internal/services/resource/resource_arm_template_deployment.go index b2b41a1c64fb..cdeefef24500 100644 --- a/azurerm/resource_arm_template_deployment.go +++ b/azurerm/internal/services/resource/resource_arm_template_deployment.go @@ -1,4 +1,4 @@ -package azurerm +package resource import ( "context" @@ -49,7 +49,7 @@ func resourceArmTemplateDeployment() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - StateFunc: normalizeJson, + StateFunc: azure.NormalizeJson, }, "parameters": { @@ -64,7 +64,7 @@ func resourceArmTemplateDeployment() *schema.Resource { "parameters_body": { Type: schema.TypeString, Optional: true, - StateFunc: normalizeJson, + StateFunc: azure.NormalizeJson, ConflictsWith: []string{"parameters"}, }, @@ -302,19 +302,6 @@ func expandTemplateBody(template string) (map[string]interface{}, error) { return templateBody, nil } -func normalizeJson(jsonString interface{}) string { - if jsonString == nil || jsonString == "" { - return "" - } - var j interface{} - - if err := json.Unmarshal([]byte(jsonString.(string)), &j); err != nil { - return fmt.Sprintf("Error parsing JSON: %+v", err) - } - b, _ := json.Marshal(j) - return string(b[:]) -} - func waitForTemplateDeploymentToBeDeleted(ctx context.Context, client *resources.DeploymentsClient, resourceGroup, name string, d *schema.ResourceData) error { // we can't use the Waiter here since the API returns a 200 once it's deleted which is considered a polling status code.. log.Printf("[DEBUG] Waiting for Template Deployment (%q in Resource Group %q) to be deleted", name, resourceGroup) diff --git a/azurerm/resource_arm_template_deployment_test.go b/azurerm/internal/services/resource/resource_arm_template_deployment_test.go similarity index 99% rename from azurerm/resource_arm_template_deployment_test.go rename to azurerm/internal/services/resource/resource_arm_template_deployment_test.go index d8f9a41fbfee..12009bd84158 100644 --- a/azurerm/resource_arm_template_deployment_test.go +++ b/azurerm/internal/services/resource/resource_arm_template_deployment_test.go @@ -1,4 +1,4 @@ -package azurerm +package resource import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 54bceb2a9301..836c58b2df72 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -13,10 +13,8 @@ func Provider() terraform.ResourceProvider { resources := map[string]*schema.Resource{ - "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_dashboard": resourceArmDashboard(), - "azurerm_management_lock": resourceArmManagementLock(), - "azurerm_template_deployment": resourceArmTemplateDeployment(), + "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), + "azurerm_dashboard": resourceArmDashboard(), } return provider.AzureProvider(dataSources, resources) diff --git a/azurerm/resource_arm_dashboard.go b/azurerm/resource_arm_dashboard.go index 09c4503fd720..70be194c5f15 100644 --- a/azurerm/resource_arm_dashboard.go +++ b/azurerm/resource_arm_dashboard.go @@ -47,7 +47,7 @@ func resourceArmDashboard() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - StateFunc: normalizeJson, + StateFunc: azure.NormalizeJson, }, }, } From 1507aac77f15c44c9fd115eaf670fbf189507e0e Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 20:35:52 -0800 Subject: [PATCH 070/203] portal --- azurerm/internal/services/portal/registration.go | 4 +++- .../{ => internal/services/portal}/resource_arm_dashboard.go | 2 +- .../services/portal}/resource_arm_dashboard_test.go | 2 +- azurerm/provider.go | 2 -- 4 files changed, 5 insertions(+), 5 deletions(-) rename azurerm/{ => internal/services/portal}/resource_arm_dashboard.go (99%) rename azurerm/{ => internal/services/portal}/resource_arm_dashboard_test.go (99%) diff --git a/azurerm/internal/services/portal/registration.go b/azurerm/internal/services/portal/registration.go index 9894b9c5fbc0..8f0a6b4e399c 100644 --- a/azurerm/internal/services/portal/registration.go +++ b/azurerm/internal/services/portal/registration.go @@ -18,5 +18,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_dashboard": resourceArmDashboard(), + } } diff --git a/azurerm/resource_arm_dashboard.go b/azurerm/internal/services/portal/resource_arm_dashboard.go similarity index 99% rename from azurerm/resource_arm_dashboard.go rename to azurerm/internal/services/portal/resource_arm_dashboard.go index 70be194c5f15..17d0c4d22e87 100644 --- a/azurerm/resource_arm_dashboard.go +++ b/azurerm/internal/services/portal/resource_arm_dashboard.go @@ -1,4 +1,4 @@ -package azurerm +package portal import ( "encoding/json" diff --git a/azurerm/resource_arm_dashboard_test.go b/azurerm/internal/services/portal/resource_arm_dashboard_test.go similarity index 99% rename from azurerm/resource_arm_dashboard_test.go rename to azurerm/internal/services/portal/resource_arm_dashboard_test.go index 74e83e3b39e3..bd144c95aa45 100644 --- a/azurerm/resource_arm_dashboard_test.go +++ b/azurerm/internal/services/portal/resource_arm_dashboard_test.go @@ -1,4 +1,4 @@ -package azurerm +package portal import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index 836c58b2df72..a1e6cc432d0b 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -12,9 +12,7 @@ func Provider() terraform.ResourceProvider { } resources := map[string]*schema.Resource{ - "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - "azurerm_dashboard": resourceArmDashboard(), } return provider.AzureProvider(dataSources, resources) From e0f9d1b536e8efad759cf8c4c3fdd3cfda884d3a Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 20:36:57 -0800 Subject: [PATCH 071/203] more monitor --- azurerm/internal/services/monitor/registration.go | 1 + .../services/monitor}/resource_arm_autoscale_setting.go | 2 +- .../services/monitor}/resource_arm_autoscale_setting_test.go | 2 +- azurerm/provider.go | 4 +--- 4 files changed, 4 insertions(+), 5 deletions(-) rename azurerm/{ => internal/services/monitor}/resource_arm_autoscale_setting.go (99%) rename azurerm/{ => internal/services/monitor}/resource_arm_autoscale_setting_test.go (99%) diff --git a/azurerm/internal/services/monitor/registration.go b/azurerm/internal/services/monitor/registration.go index e04dcda74c9e..dfc09bd0b42d 100644 --- a/azurerm/internal/services/monitor/registration.go +++ b/azurerm/internal/services/monitor/registration.go @@ -22,6 +22,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ + "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), "azurerm_metric_alertrule": resourceArmMetricAlertRule(), "azurerm_monitor_autoscale_setting": resourceArmMonitorAutoScaleSetting(), "azurerm_monitor_action_group": resourceArmMonitorActionGroup(), diff --git a/azurerm/resource_arm_autoscale_setting.go b/azurerm/internal/services/monitor/resource_arm_autoscale_setting.go similarity index 99% rename from azurerm/resource_arm_autoscale_setting.go rename to azurerm/internal/services/monitor/resource_arm_autoscale_setting.go index 9ad31c99a921..7f6b0647d0d4 100644 --- a/azurerm/resource_arm_autoscale_setting.go +++ b/azurerm/internal/services/monitor/resource_arm_autoscale_setting.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/resource_arm_autoscale_setting_test.go b/azurerm/internal/services/monitor/resource_arm_autoscale_setting_test.go similarity index 99% rename from azurerm/resource_arm_autoscale_setting_test.go rename to azurerm/internal/services/monitor/resource_arm_autoscale_setting_test.go index a8cee67e8945..e96d2da7962c 100644 --- a/azurerm/resource_arm_autoscale_setting_test.go +++ b/azurerm/internal/services/monitor/resource_arm_autoscale_setting_test.go @@ -1,4 +1,4 @@ -package azurerm +package monitor import ( "fmt" diff --git a/azurerm/provider.go b/azurerm/provider.go index a1e6cc432d0b..f50b570106d3 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -11,9 +11,7 @@ func Provider() terraform.ResourceProvider { "azurerm_client_config": dataSourceArmClientConfig(), } - resources := map[string]*schema.Resource{ - "azurerm_autoscale_setting": resourceArmAutoScaleSetting(), - } + resources := map[string]*schema.Resource{} return provider.AzureProvider(dataSources, resources) } From 7cc74f56718d62d21db97788cc28365b807de694 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 07:47:25 +0100 Subject: [PATCH 072/203] sql: moving the testdata into the package folder --- .../services/sql}/testdata/sql_import.bacpac | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename azurerm/{ => internal/services/sql}/testdata/sql_import.bacpac (100%) diff --git a/azurerm/testdata/sql_import.bacpac b/azurerm/internal/services/sql/testdata/sql_import.bacpac similarity index 100% rename from azurerm/testdata/sql_import.bacpac rename to azurerm/internal/services/sql/testdata/sql_import.bacpac From aebb7bfbfe85626e87c6a125ee4d3dffe0886ff2 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 07:49:23 +0100 Subject: [PATCH 073/203] apimanagement: moving the testdata folder --- .../testdata/api_management_api2_test.pfx | Bin .../testdata/api_management_api_schema.xml | 0 .../testdata/api_management_api_swagger.json | 0 .../testdata/api_management_api_test.pfx | Bin .../testdata/api_management_api_wsdl.xml | 0 .../testdata/api_management_portal_test.pfx | Bin .../testdata/api_management_testdata.sh | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename azurerm/{ => internal/services/apimanagement}/testdata/api_management_api2_test.pfx (100%) rename azurerm/{ => internal/services/apimanagement}/testdata/api_management_api_schema.xml (100%) rename azurerm/{ => internal/services/apimanagement}/testdata/api_management_api_swagger.json (100%) rename azurerm/{ => internal/services/apimanagement}/testdata/api_management_api_test.pfx (100%) rename azurerm/{ => internal/services/apimanagement}/testdata/api_management_api_wsdl.xml (100%) rename azurerm/{ => internal/services/apimanagement}/testdata/api_management_portal_test.pfx (100%) rename azurerm/{ => internal/services/apimanagement}/testdata/api_management_testdata.sh (100%) diff --git a/azurerm/testdata/api_management_api2_test.pfx b/azurerm/internal/services/apimanagement/testdata/api_management_api2_test.pfx similarity index 100% rename from azurerm/testdata/api_management_api2_test.pfx rename to azurerm/internal/services/apimanagement/testdata/api_management_api2_test.pfx diff --git a/azurerm/testdata/api_management_api_schema.xml b/azurerm/internal/services/apimanagement/testdata/api_management_api_schema.xml similarity index 100% rename from azurerm/testdata/api_management_api_schema.xml rename to azurerm/internal/services/apimanagement/testdata/api_management_api_schema.xml diff --git a/azurerm/testdata/api_management_api_swagger.json b/azurerm/internal/services/apimanagement/testdata/api_management_api_swagger.json similarity index 100% rename from azurerm/testdata/api_management_api_swagger.json rename to azurerm/internal/services/apimanagement/testdata/api_management_api_swagger.json diff --git a/azurerm/testdata/api_management_api_test.pfx b/azurerm/internal/services/apimanagement/testdata/api_management_api_test.pfx similarity index 100% rename from azurerm/testdata/api_management_api_test.pfx rename to azurerm/internal/services/apimanagement/testdata/api_management_api_test.pfx diff --git a/azurerm/testdata/api_management_api_wsdl.xml b/azurerm/internal/services/apimanagement/testdata/api_management_api_wsdl.xml similarity index 100% rename from azurerm/testdata/api_management_api_wsdl.xml rename to azurerm/internal/services/apimanagement/testdata/api_management_api_wsdl.xml diff --git a/azurerm/testdata/api_management_portal_test.pfx b/azurerm/internal/services/apimanagement/testdata/api_management_portal_test.pfx similarity index 100% rename from azurerm/testdata/api_management_portal_test.pfx rename to azurerm/internal/services/apimanagement/testdata/api_management_portal_test.pfx diff --git a/azurerm/testdata/api_management_testdata.sh b/azurerm/internal/services/apimanagement/testdata/api_management_testdata.sh similarity index 100% rename from azurerm/testdata/api_management_testdata.sh rename to azurerm/internal/services/apimanagement/testdata/api_management_testdata.sh From 06ce5c86450424050c322e4180b87bd64bf9bf99 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 08:09:37 +0100 Subject: [PATCH 074/203] testdata: moving into packages --- .../apimanagement}/testdata/keyvaultcert.pfx | Bin .../testdata/automation_certificate_test.pfx | Bin .../automation_certificate_test.thumb | 0 .../automation_certificate_testdata.sh | 0 .../batch}/testdata/batch_certificate.cer | 0 .../batch}/testdata/batch_certificate.pfx | Bin .../testdata/application_gateway_test.cer | 0 .../testdata/application_gateway_test.cer | 21 +++++++++++++ .../iothub/testdata/batch_certificate.cer | 21 +++++++++++++ .../keyvault/testdata/keyvaultcert.pfx | Bin 0 -> 2717 bytes .../testdata/app_service_certificate.pfx | Bin .../testdata/application_gateway_test.cer | 21 +++++++++++++ .../testdata/application_gateway_test.pfx | Bin .../testdata/application_gateway_test_2.crt | 0 .../testdata/application_gateway_test_2.pfx | Bin .../testdata/application_gateway_test.pfx | Bin 0 -> 4213 bytes .../web/testdata/app_service_certificate.pfx | Bin 0 -> 2629 bytes .../app_service_certificate_nopassword.pfx | Bin .../testdata/application_gateway_test_2.key | 28 ------------------ .../testdata/automation_certificate_test.crt | 16 ---------- .../testdata/automation_certificate_test.key | 28 ------------------ azurerm/testdata/hadoop_cluster_empty_node.sh | 2 -- 22 files changed, 63 insertions(+), 74 deletions(-) rename azurerm/{ => internal/services/apimanagement}/testdata/keyvaultcert.pfx (100%) rename azurerm/{ => internal/services/automation}/testdata/automation_certificate_test.pfx (100%) rename azurerm/{ => internal/services/automation}/testdata/automation_certificate_test.thumb (100%) rename azurerm/{ => internal/services/automation}/testdata/automation_certificate_testdata.sh (100%) rename azurerm/{ => internal/services/batch}/testdata/batch_certificate.cer (100%) rename azurerm/{ => internal/services/batch}/testdata/batch_certificate.pfx (100%) rename azurerm/{ => internal/services/datalake}/testdata/application_gateway_test.cer (100%) create mode 100644 azurerm/internal/services/iothub/testdata/application_gateway_test.cer create mode 100644 azurerm/internal/services/iothub/testdata/batch_certificate.cer create mode 100644 azurerm/internal/services/keyvault/testdata/keyvaultcert.pfx rename azurerm/{ => internal/services/network}/testdata/app_service_certificate.pfx (100%) create mode 100644 azurerm/internal/services/network/testdata/application_gateway_test.cer rename azurerm/{ => internal/services/network}/testdata/application_gateway_test.pfx (100%) rename azurerm/{ => internal/services/network}/testdata/application_gateway_test_2.crt (100%) rename azurerm/{ => internal/services/network}/testdata/application_gateway_test_2.pfx (100%) create mode 100644 azurerm/internal/services/scheduler/testdata/application_gateway_test.pfx create mode 100644 azurerm/internal/services/web/testdata/app_service_certificate.pfx rename azurerm/{ => internal/services/web}/testdata/app_service_certificate_nopassword.pfx (100%) delete mode 100644 azurerm/testdata/application_gateway_test_2.key delete mode 100644 azurerm/testdata/automation_certificate_test.crt delete mode 100644 azurerm/testdata/automation_certificate_test.key delete mode 100644 azurerm/testdata/hadoop_cluster_empty_node.sh diff --git a/azurerm/testdata/keyvaultcert.pfx b/azurerm/internal/services/apimanagement/testdata/keyvaultcert.pfx similarity index 100% rename from azurerm/testdata/keyvaultcert.pfx rename to azurerm/internal/services/apimanagement/testdata/keyvaultcert.pfx diff --git a/azurerm/testdata/automation_certificate_test.pfx b/azurerm/internal/services/automation/testdata/automation_certificate_test.pfx similarity index 100% rename from azurerm/testdata/automation_certificate_test.pfx rename to azurerm/internal/services/automation/testdata/automation_certificate_test.pfx diff --git a/azurerm/testdata/automation_certificate_test.thumb b/azurerm/internal/services/automation/testdata/automation_certificate_test.thumb similarity index 100% rename from azurerm/testdata/automation_certificate_test.thumb rename to azurerm/internal/services/automation/testdata/automation_certificate_test.thumb diff --git a/azurerm/testdata/automation_certificate_testdata.sh b/azurerm/internal/services/automation/testdata/automation_certificate_testdata.sh similarity index 100% rename from azurerm/testdata/automation_certificate_testdata.sh rename to azurerm/internal/services/automation/testdata/automation_certificate_testdata.sh diff --git a/azurerm/testdata/batch_certificate.cer b/azurerm/internal/services/batch/testdata/batch_certificate.cer similarity index 100% rename from azurerm/testdata/batch_certificate.cer rename to azurerm/internal/services/batch/testdata/batch_certificate.cer diff --git a/azurerm/testdata/batch_certificate.pfx b/azurerm/internal/services/batch/testdata/batch_certificate.pfx similarity index 100% rename from azurerm/testdata/batch_certificate.pfx rename to azurerm/internal/services/batch/testdata/batch_certificate.pfx diff --git a/azurerm/testdata/application_gateway_test.cer b/azurerm/internal/services/datalake/testdata/application_gateway_test.cer similarity index 100% rename from azurerm/testdata/application_gateway_test.cer rename to azurerm/internal/services/datalake/testdata/application_gateway_test.cer diff --git a/azurerm/internal/services/iothub/testdata/application_gateway_test.cer b/azurerm/internal/services/iothub/testdata/application_gateway_test.cer new file mode 100644 index 000000000000..577947b220d7 --- /dev/null +++ b/azurerm/internal/services/iothub/testdata/application_gateway_test.cer @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDbzCCAlegAwIBAgIJAIzjRD36sIbbMA0GCSqGSIb3DQEBCwUAME0xCzAJBgNV +BAYTAlVTMRMwEQYDVQQIDApTb21lLVN0YXRlMRIwEAYDVQQKDAl0ZXJyYWZvcm0x +FTATBgNVBAMMDHRlcnJhZm9ybS5pbzAgFw0xNzA0MjEyMDA1MjdaGA8yMTE3MDMy +ODIwMDUyN1owTTELMAkGA1UEBhMCVVMxEzARBgNVBAgMClNvbWUtU3RhdGUxEjAQ +BgNVBAoMCXRlcnJhZm9ybTEVMBMGA1UEAwwMdGVycmFmb3JtLmlvMIIBIjANBgkq +hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3L9L5szT4+FLykTFNyyPjy/k3BQTYAfR +QzP2dhnsuUKm3cdPC0NyZ+wEXIUGhoDO2YG6EYChOl8fsDqDOjloSUGKqYw++nlp +HIuUgJx8IxxG2XkALCjFU7EmF+w7kn76d0ezpEIYxnLP+KG2DVornoEt1aLhv1ML +mpgEZZPhDbMSLhSYWeTVRMayXLwqtfgnDumQSB+8d/1JuJqrSI4pD12JozVThzb6 +hsjfb6RMX4epPmrGn0PbTPEEA6awmsxBCXB0s13nNQt/O0hLM2agwvAyozilQV+s +616Ckgk6DJoUkqZhDy7vPYMIRSr98fBws6zkrV6tTLjmD8xAvobePQIDAQABo1Aw +TjAdBgNVHQ4EFgQUXIqO421zMMmbcRRX9wctZFCQuPIwHwYDVR0jBBgwFoAUXIqO +421zMMmbcRRX9wctZFCQuPIwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC +AQEAr82NeT3BYJOKLlUL6Om5LjUF66ewcJjG9ltdvyQwVneMcq7t5UAPxgChzqNR +Vk4da8PzkXpjBJyWezHupdJNX3XqeUk2kSxqQ6/gmhqvfI3y7djrwoO6jvMEY26W +qtkTNORWDP3THJJVimC3zV+KMU5UBVrEzhOVhHSU709lBP75o0BBn3xGsPqSq9k8 +IotIFfyAc6a+XP3+ZMpvh7wqAUml7vWa5wlcXExCx39h1balfDSLGNC4swWPCp9A +MnQR0p+vMay9hNP1Eh+9QYUai14d5KS3cFV+KxE1cJR5HD/iLltnnOEbpMsB0eVO +ZWkFvE7Y5lW0oVSAfin5TwTJMQ== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/azurerm/internal/services/iothub/testdata/batch_certificate.cer b/azurerm/internal/services/iothub/testdata/batch_certificate.cer new file mode 100644 index 000000000000..577947b220d7 --- /dev/null +++ b/azurerm/internal/services/iothub/testdata/batch_certificate.cer @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDbzCCAlegAwIBAgIJAIzjRD36sIbbMA0GCSqGSIb3DQEBCwUAME0xCzAJBgNV +BAYTAlVTMRMwEQYDVQQIDApTb21lLVN0YXRlMRIwEAYDVQQKDAl0ZXJyYWZvcm0x +FTATBgNVBAMMDHRlcnJhZm9ybS5pbzAgFw0xNzA0MjEyMDA1MjdaGA8yMTE3MDMy +ODIwMDUyN1owTTELMAkGA1UEBhMCVVMxEzARBgNVBAgMClNvbWUtU3RhdGUxEjAQ +BgNVBAoMCXRlcnJhZm9ybTEVMBMGA1UEAwwMdGVycmFmb3JtLmlvMIIBIjANBgkq +hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3L9L5szT4+FLykTFNyyPjy/k3BQTYAfR +QzP2dhnsuUKm3cdPC0NyZ+wEXIUGhoDO2YG6EYChOl8fsDqDOjloSUGKqYw++nlp +HIuUgJx8IxxG2XkALCjFU7EmF+w7kn76d0ezpEIYxnLP+KG2DVornoEt1aLhv1ML +mpgEZZPhDbMSLhSYWeTVRMayXLwqtfgnDumQSB+8d/1JuJqrSI4pD12JozVThzb6 +hsjfb6RMX4epPmrGn0PbTPEEA6awmsxBCXB0s13nNQt/O0hLM2agwvAyozilQV+s +616Ckgk6DJoUkqZhDy7vPYMIRSr98fBws6zkrV6tTLjmD8xAvobePQIDAQABo1Aw +TjAdBgNVHQ4EFgQUXIqO421zMMmbcRRX9wctZFCQuPIwHwYDVR0jBBgwFoAUXIqO +421zMMmbcRRX9wctZFCQuPIwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC +AQEAr82NeT3BYJOKLlUL6Om5LjUF66ewcJjG9ltdvyQwVneMcq7t5UAPxgChzqNR +Vk4da8PzkXpjBJyWezHupdJNX3XqeUk2kSxqQ6/gmhqvfI3y7djrwoO6jvMEY26W +qtkTNORWDP3THJJVimC3zV+KMU5UBVrEzhOVhHSU709lBP75o0BBn3xGsPqSq9k8 +IotIFfyAc6a+XP3+ZMpvh7wqAUml7vWa5wlcXExCx39h1balfDSLGNC4swWPCp9A +MnQR0p+vMay9hNP1Eh+9QYUai14d5KS3cFV+KxE1cJR5HD/iLltnnOEbpMsB0eVO +ZWkFvE7Y5lW0oVSAfin5TwTJMQ== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/azurerm/internal/services/keyvault/testdata/keyvaultcert.pfx b/azurerm/internal/services/keyvault/testdata/keyvaultcert.pfx new file mode 100644 index 0000000000000000000000000000000000000000..28af8bf52e9a1c94b4e96295a789eeed7f5103dd GIT binary patch literal 2717 zcmV;O3S#vzf(n@e0Ru3C3SR~ZDuzgg_YDCD0ic2kPy~VsOfZ59NHBr~{{{&vhDe6@ z4FLxRpn?SOFoFc^0s#Opf&}FT2`Yw2hW8Bt2LUh~1_~;MNQUIc5xWv(CguI6b8@VUG9Oz zA3bl;|K?>N)g%SG8OB1lZxL?oG*VISPeD-c{pEif;$#_ir`HEK8pz_4a30A@6~Oig z@&UYT7ic*Vd1hGBXhm8)#P>36_!_J?UyRNR(cv?^9wvf*iHcyF9~*rcz0VpG$?grpB z36>Pd*b#lHxB{bNDA=)`*~V3tHpv#y_@&kw_0S@Ak|ZWEm14L%M#oV3$70y&cYd3irWf6AgY+?jJ|Vdj0M( zzG__`drnoUG{jU%Ez%2=?^VE^$ezyvI59_8f_M&ljL3s%oy%iRUuw&)zNJ_Cc=hxm zj%53fVN-jx_BL|HyA$?Xz&eZIWdnLac$^VvTm0v zNJ#+;Lfo59$a|Bo{X`XU+y&UfH-B<3<{I5bhyj=$X?t53z|o0naI)dh0m7TUsaov> zW<+!pW#S%)Q8e=uGG(<_0GckeZd<|fkgj|=!}#|}p|AtwQXH_r<<9yH)0WBs zHH-H78hRD6^M<#GlyX?4D-fcCiMi84AYb+1P#Boi93&it*+W^E$zVX8p&jG8`D-^wa| z9NZ>l39(Br{gKmhJ;o~`?su06Pm1M>o;GwjC}uql>H9Ae?1eMA8EFdB&g12>*XO=2 zPI#0!`JzF1zpD{@#Ilm-(`dFv4O)GWC6}k<`RY$3>{i;DD^|%vGC%Z1^6TN$V&?3@ zh?e)Hg5L--Z1mc*k70~h;cj&a`8ammZyuetfOSR3Y-DtXPJfK9Iv0B_rR>0?*LPoasflny2nJund=1$wRx&=7ht6X3uw~(yX~S z>p6|y@V8epDnVAi)E3HsX%ji6NMxIe(Cdxb9GX;uh1` z1<`l=rK;vpg|r&(GBS-e`bz@Y8{8?q5_zQ`!qs2Uiqbe5wPG;n1YhFS**w>08KebX zIsMSd^;mw`u@oxz8+SIyD znRk&PmbjHmmg`NJA3(xkIobD>DlpuaFoFd^1_>&LNQU~(AYTg?BNt=fZ|OqTT2mmgMk zE1ZqZoYa;@Lh=6G=Y$=ypsJ&`x!D12^EFRXK?QOxSnb+U7lckIUQG!2EM~p9eqfP$ zT)MzaXFAH_^x2XptS)`I`5cwWL2kx6PlJRP5#Nlw^0RX4y z!3G&u81{2AcNUgYdOIS`3D$RiDV3mocaEW)b<&AaM{T}560-1XAbV+yZ5@!l6$&>c z%S~PBI(%)6XZ-N^Yj?k*D;_2a8y ziuKu6RCS+_XyM}YI)zAHeQ^BCl+w$Py_vp{KQ310qsSS_vUqF>Y<77zcE2&uOrUlW z)*cM_s97o|O;uwd*gON;Q_lP0d&4sod(km*T=(SYH|vXxnukRxsbqnPy_6RSs^thT zN=7sF9EeGWC+=c_BThkgAy=16TW151hvtZ-IB%f1vX?aVtgI!(rR+26FLdtcG5uAO z0$~izj0^}o!kulU`eHmko~K&82-5KGlTo1}&ZnQ_VRNBR96f#atnz2LUzqOU+na5p zO$eb_2=xhJ!qtn7Z>G||Pw4F`E%DT`J z3Ykq48OYR$Bm`FXPH9Etdh5bvVYln*#6jCeFz^y`q`YSoY_*+@NYYtTO>8FU@TSWF zcL6=f(;pHM!+0bu#J|-)}HAq1shur6UK@7?)}q0JxgV&+_w}8D=0ZM{B5&mW~kY<4k)l;Y0;!DT3~V z*jLXu^z5q6P{h)cfGj_Gc*^%@S&`a~(T?aXtJK`)iFsj3qzjpFFE~dFso1R@;3e;8 zM$Wd95=lDuRhO4WUlNern?l$kx6n!2p@7TQ(=++@fG_n^w#c2M@> z(VAGQ%F#8oaY{6&pu-WUtg0QL%qd4Or3XFxD24_m@lIh}n%7(Rf!7~+#}Q2TSsRyI zBc&4bGi2%Z(u5LebF=Sa103;M{=`S~Wpn3aV?1~3i6)7wQSk z9tW$Up_cxy=PiQxYS(X{wkm|Aa0V$)8FK=7fW=t_9Fe3&DDuzgg_YDCF6)_eB z6h+gpAd&|nn$AAnNU8QtfBwlPgfKBMAutIB1uG5%0vZJX1QaHi%%Q+L8<;;6MteCM XL&WLz!K?%blc&$)Z?p>J0s;sCWGxrT literal 0 HcmV?d00001 diff --git a/azurerm/testdata/app_service_certificate.pfx b/azurerm/internal/services/network/testdata/app_service_certificate.pfx similarity index 100% rename from azurerm/testdata/app_service_certificate.pfx rename to azurerm/internal/services/network/testdata/app_service_certificate.pfx diff --git a/azurerm/internal/services/network/testdata/application_gateway_test.cer b/azurerm/internal/services/network/testdata/application_gateway_test.cer new file mode 100644 index 000000000000..577947b220d7 --- /dev/null +++ b/azurerm/internal/services/network/testdata/application_gateway_test.cer @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDbzCCAlegAwIBAgIJAIzjRD36sIbbMA0GCSqGSIb3DQEBCwUAME0xCzAJBgNV +BAYTAlVTMRMwEQYDVQQIDApTb21lLVN0YXRlMRIwEAYDVQQKDAl0ZXJyYWZvcm0x +FTATBgNVBAMMDHRlcnJhZm9ybS5pbzAgFw0xNzA0MjEyMDA1MjdaGA8yMTE3MDMy +ODIwMDUyN1owTTELMAkGA1UEBhMCVVMxEzARBgNVBAgMClNvbWUtU3RhdGUxEjAQ +BgNVBAoMCXRlcnJhZm9ybTEVMBMGA1UEAwwMdGVycmFmb3JtLmlvMIIBIjANBgkq +hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3L9L5szT4+FLykTFNyyPjy/k3BQTYAfR +QzP2dhnsuUKm3cdPC0NyZ+wEXIUGhoDO2YG6EYChOl8fsDqDOjloSUGKqYw++nlp +HIuUgJx8IxxG2XkALCjFU7EmF+w7kn76d0ezpEIYxnLP+KG2DVornoEt1aLhv1ML +mpgEZZPhDbMSLhSYWeTVRMayXLwqtfgnDumQSB+8d/1JuJqrSI4pD12JozVThzb6 +hsjfb6RMX4epPmrGn0PbTPEEA6awmsxBCXB0s13nNQt/O0hLM2agwvAyozilQV+s +616Ckgk6DJoUkqZhDy7vPYMIRSr98fBws6zkrV6tTLjmD8xAvobePQIDAQABo1Aw +TjAdBgNVHQ4EFgQUXIqO421zMMmbcRRX9wctZFCQuPIwHwYDVR0jBBgwFoAUXIqO +421zMMmbcRRX9wctZFCQuPIwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC +AQEAr82NeT3BYJOKLlUL6Om5LjUF66ewcJjG9ltdvyQwVneMcq7t5UAPxgChzqNR +Vk4da8PzkXpjBJyWezHupdJNX3XqeUk2kSxqQ6/gmhqvfI3y7djrwoO6jvMEY26W +qtkTNORWDP3THJJVimC3zV+KMU5UBVrEzhOVhHSU709lBP75o0BBn3xGsPqSq9k8 +IotIFfyAc6a+XP3+ZMpvh7wqAUml7vWa5wlcXExCx39h1balfDSLGNC4swWPCp9A +MnQR0p+vMay9hNP1Eh+9QYUai14d5KS3cFV+KxE1cJR5HD/iLltnnOEbpMsB0eVO +ZWkFvE7Y5lW0oVSAfin5TwTJMQ== +-----END CERTIFICATE----- \ No newline at end of file diff --git a/azurerm/testdata/application_gateway_test.pfx b/azurerm/internal/services/network/testdata/application_gateway_test.pfx similarity index 100% rename from azurerm/testdata/application_gateway_test.pfx rename to azurerm/internal/services/network/testdata/application_gateway_test.pfx diff --git a/azurerm/testdata/application_gateway_test_2.crt b/azurerm/internal/services/network/testdata/application_gateway_test_2.crt similarity index 100% rename from azurerm/testdata/application_gateway_test_2.crt rename to azurerm/internal/services/network/testdata/application_gateway_test_2.crt diff --git a/azurerm/testdata/application_gateway_test_2.pfx b/azurerm/internal/services/network/testdata/application_gateway_test_2.pfx similarity index 100% rename from azurerm/testdata/application_gateway_test_2.pfx rename to azurerm/internal/services/network/testdata/application_gateway_test_2.pfx diff --git a/azurerm/internal/services/scheduler/testdata/application_gateway_test.pfx b/azurerm/internal/services/scheduler/testdata/application_gateway_test.pfx new file mode 100644 index 0000000000000000000000000000000000000000..691fa08577cf8afdfc91a241bc623883f5b132fa GIT binary patch literal 4213 zcmY+GWl$81w}*G>rQxN!muATYN$Ji7B%~z-L0Ca)Sdea|m+p{Ix}{<122mPhX%K0- zzBBjU|Ggj1oSEl0=X`yB5Co|w1`rd1Acf+9cq7y!u84rRzEwuo4BMl%Eh0}l{_z`>jBvG1qU z?e?(Y*J2~LXFI74Kl_=zjvHoU=s72yM6IC zbCe)wQyC&AlRGx`&)vc}W@t7aVTn1@wpWx6e^eWz-ZQP=)~cxWdwWV6ZdcK3#on2e z7_~4W#EY;lM+&E?V>{go5oqHiKZZ%t^=dDPPPsQe!=DetF28s}Wxhu@)mDjv*vr0R zN+9oAfO+YkBi3Ol`8#z!xl?Yy{VfGKY$~kkJbBWHvPG|Fm7N^CaOk6 z!<|8)d#H9{%OFo@tsDl};)E*d=~ZkG>ZNN==+aXF!A4z6Z94c;TQ$Jv@?AMyiu+ZFn=4 zTUPI9{oF>q)|jr-PUu#@zuuLGQ^}_~aLavep3mwW{Lqs&>*>Ahhc0#hvbK2S19GPI`xBU!}7buz1EEM^q zl`$){pIGShBy!w^hwwwev;}Te$x#6O{R_sZu<8y_YQwe0Ik~K6UBMP^xTyN2kDTVd zD3hYzkt*mm1BP!|bt9GzXz|JXczT&Rsi!Ngvs`E0GneVwZcIt_UB@7}>Xv3|TbGaG~ zqcv^i_JgI&iNy~eqbG4dZVq`>vjt>sTA5Jvd^9J~U0I_D23}Cc$bz+c|axa7e0n3}8o}50Vnqpkn%teQ;_RaX-%-SCc?Q^$8hK<% zzjc~@lh|9OYo0Q^#MT5@isFcgOg-xPUSL|>6xL%cL2(`bQ~87#Hs=Rj%fFj&<~#U! z7QoY7xswx^L6Lq+5DW@BvrGI#uq@Nh@0#~9DrPQ10!O+)Z0Y-4#JxS0|FzVUukbM% z=;jZbe~#qszgS(I){@1^OZ0QdW4{Cgbnc0{=B9Itl{RFU@NJJ_*sC<6jXYbzw)|{I zfSc9UHbJ~IaEAjkFnnxXa`M6`>VhLPA&Q8n&qBSiSFEGpWd8^-f3q6G$xavAU<+mX zme(4oib-u}h5B0bKI-~sWu%iu*L`QdWQyd8$mq6tPzpPGZJSL9tz!{_LMawJibUiC49YZ+v*sN04@$O|N%5+sa=IkY-;43GHHSLbvL3-j3bCI4 z9e>(z7RcXE_fvi{-lkr#sn0O;qrr&wAL6IAvP9)5ZJOCz8|iq!S$}7t3PWHw6!my8 zZcM06O3P(Zsj);V$pfG1FBeER#&K~*^^R%W!Qdc4pv%iWD}&vYsyio$%1m5nzRvBB zQd{@I%c^VmQ4LfZO6@04W%#vx%J5IEAP%1{*8mKYvp@K)V$5{~;jJOvKm_06yQ-x1 zmS#{mcbKf{OhYrMNEQ;rBK@*KU_VYSAjGcPI->}J0FC?~apWUFZCD6U(_j4g@6_NB z{EtTPff#>7pTE%S|JeoeU%Rj^nwWZ>;#>V|m%r!wLw}re%UJN31WGJO!=|6F30;Ru zZ$HAq?~=IJ03D=I_GE5gT)Ei??aI|}8$1g@`0#KxKv3$4wQXS_; z!SCoJytrRs)G)U+*ye(Q^rf_X7kdi=DROMyS-sL%6vpWA{W+i9FNyDfP`%^M318xn zz1WS_kvi9ZV%6d++nQy`nHgOx_XbS;JO^q-B~AmRusH?%u}rs!q~LAZ%BB1pdcA53 zZHL9vMqjOm6L&vXmU6V7W7WcdYKFDr&BzZ%iLS;G%eQ27(%@$nx#op73-s65saMegfD;i}r$?SEHKXfDVzV>$W zSa#p(fdpV|?Sht_zE!ET)A^=w!JnuhjD%QNxwp%wS7o#U4(FEF3^$vUo>#P#Gy25F ziCttJafzK8X;PPji)H;4Ui*+fg*4q{fm@}iFeT&ka%0(S&1RPh?54Hhq??=s@@ZG~ z;kbWfu9%J(q9M>q_4tVtSkjvu*nS0ceQwzFqm~aNVi8(fw3OO@gm(H>Ii&Qkkg9pu zg@oOey2u+4nWH8(q){WJ&k+)YQvIlvw!QyV9W-4$h*!y?JD` zKQI*uK?#REqf47@A=DQ)sF>BtH&Ky=Qgm9lme}o{JgYk~d9Av=e;f!l@tG}WI)p4x zP+QisKLTdHEO~oG7ble}uhTSI2rNznV@Zt19aUhlgG=frT$gx<@;_8vy}7dg@i}x; z-5L++PozLX=MsNS`12OV0j{v_txep#r_@LmYoy3ZNLF3J-;~#42bkFEraHmCXQwT$ z1TM%3-nSX7d88Q)ivA7#nD4rjK))MqDY-=Ir8wNG*LO2sn`zm$7Pwc4^`<>1{zi2Q z(n7yvaV!UCnIhRL`F8VNUNfy(=*oiL_D8^UFD=6 zi^fMwKQdXJ9~l4SV{8roK}dzn3cV8!(E8-5zUG_p4v8S9cRDce32Z2p=SnR&CAD=vU0t%j3lf1-NQPhu-@LsREm=szBzwkR)=z!Qogt- zJdw~Hm|fj=w^5Eo4kkCxhXpC33~#5HqJq%PoQjORJHA2MvZXt412!j4siDAj;N0|WpprTO0q6up6%ugZj;RiEQX|W zk@l$m{%8lph#lNW6_$zGrEBq@TO*-Rv0XUHO}Z;`W}>_NBIze+kNjoQbU*Cxz|+gh zg~P)kY$!fdonxnVrN121dnFZa8YE%uvmflLNhLTPq$m3hhR&M`n^#nZ1x&u+a(Goo zwjLp}Bz4{DlBZ!Q+5EE`@;hHNtRO)Jxi$ZgG%`TaHjR_3ZGc-kd$fdxj=PfQAd@4q z_9K8bJ>R3d5F=j1SSgR}oq_qO_ExL=JMPwHhf{D?_vaOh2J{A3(-^&kGH=S@&o{)Q z~B3q3ug8yzGPx0s!E9Ywbg5i51r?QP(dt4L{6TCv7 z7kQ+$!c2Hd)z@}NFPE(ypn_wwj1=E^`e3{`L8%gUb#FJ1e&?1fPTN7XLEi^c_k?f8 ze@I5RZvXrwIoWxu#*dMf%A&4%hmLz~a+}0mViePiU3WAFe9{~c`~shEVrbi+*f|>6 zxLrQh!c(wu4A(PlL+B{hASkm)-v6fZr4c;7!P)nZv@?(Yi zAZ8vm;#u-=pxzTeC9ERP=SX+q@ z)fHrMb`*08=Iv(?-h5EW0@UiDKf*Eb9jRcSQIMg5vR^PD$8WUx7$Ad<<>^UqOV-PX zeRO#^=>_u?5#<%9$d%O<WsM15pZ7VNoc4#f{XP+OBvel2UjEN=V%P ze6#`)hOk0FIM{r|m>6`}04$0}f@fZN@u;gi)PP0@-*(&P0s#Opf&`5Q2`Yw2hW8Bt2LUh~1_~;MNQUB zCdqBs_2FcN@$$L%!{d8qc<&EO62>Y+T+@^~I%OzC)=_4YWe?v}wU>O|dd{9AQav2y zKO1@8-i}>_eIk;d=WM3VfsLH~wPGn#EEUW~=6?BQp@L@3EST`1*)&i0*1S6I(@l6D zFW&rZDyjP)ZAVM+Mig=`=B4}x5~rcHS$-))$%k^X3X=fsLc4RE5QOhxOlhU~Of0Q=;gR#6EW5;x&O5(G1gW~J(cT7qO&;qhe1YmM+t1j01 zKKFQ^Z{Dh(MQVPL;6gUPUV?%_9#UL}22>Vwo0YoOJ|%>KDIv9qm%rR_Y9{H-9W_cw z_m5?VdxBnD(^gNp{iGhRPg$K=DngN81>}eXPE{JG7=~Q(UMmg^fab5hxyFQ9&p%!I zb6i&#%Y+`&e9YvmObtKc3Nu5G5^!|Ua|hp!Bl#rpU@a?QaqZ9qStPCqCS1|1SSQR0 zh+8GKD4}g$ixMifDl3o}C5zMh-x7mu5*?GNE!1;L<$ObMTtpt;ZPeFyMgPzJNak*l zm>Z}UZe6-?UEBZVNB;%@$4soECVK}Zazm+#gI@r-#p)*Z{u9_P;|*b(cw{&~gPsr+ zi6*v{K85k}U#cx4os1!u_Xoqr(!!H*cFU~XcB|sa>F+;L=#A;@98j+r?ZEcSh!?O8 z>}V!!@dZF;_gPoI;#j%CjGy z%dpoM>Bq*i&iJh)Y?5AI4|}sOoG~}kYs97=l{RK&vl^e9gdX;f+yNJ5V|DP^CN3f0 zoQEskqqir++(3bgRI>~5bcJ_cNS?KJ#JY(cbm_N5==$t9N;~>(6R4O3*KBZqx(%z_ zAH>KC>VkWXeB_tcuavh|zjmOMW{%i;h@bS!_n16(yoKHcu$Ib7w-&S={ACTUM9`Gj zpYCd8*QS4P#HM4Zg8B;Q*l=ahcMZ+0dMvv4!IQ`cJ6y|k+m(_pPbuJ8^v+P#=H{&B(vK7mx3;JP70lM{R zMVNe3(KSo>gF?u!d8E#MlHcbb!@S4|EbGAMg?mCTd*w6U40{tVFoFd^1_>&LNQUCnvDci;#4QkMZUC=Y-wT{)Nh9v5S#hBC~>5Lp)=)ZMfjVdKcfYs+R`J^u55; zb4}_|u#gf!@`qmYN%Nc`y`wM0m@v6!F1=iMa`UN&Hr`x)WgkZrJt1)6v0}0St1pkY z8N1Y?Qcf)$P~^GHM2h}y#7Bf5Vbm$A{_hX=;Vx#DrK*tuSrNw1p&sQs_9VR+PUMt>@T!=_c%oaX$Mutx}2M|0b}JZJVBOh@>3$@GoOS=piZ zeM(WRniL(WafjACpPs}+CK`P47Hg-H-b7m#CxAHR@$%eq?ZWZnY@%(6Z6ywsrXM@{ z?Sg4~9lagB)eq*w4b{vUOF&wO^$uNQ0BrH@YxdJtZd^BrLRKOwHbZ_SOyfzFU$z59 z(&=vH`9yErH|z=USUiLyHb0pF+wwo##5^--*ohfTcB(^<?2l&_yPiMMIJED0O#n7rZJszF09mmThGc4Q$RdfWDdXups2W)6spc%v3)_zKXQ( zZuHy``84(SauYKIe)iW1rY*7O-(#$>I3xTY&n$3uc;BXo%F$uQw^@8uI9tmKsVE6) z&&>N&M{sXQpp)MlwetD+qm64{hLg~V_!i}pA-4K7QlN|vcO1yx7gx{)GUH;@30{`> z;hZ~_i`wC{b_VY``}x@!38C@a2pX>B`dlaG>nQfCMK%j(x*@DR|&s4^e!6_y)h`rej#RJ&RWm z3U5gjI0w+^@&>#HTxXK)c1qwn0{tn?F02uY!d=Y&C}xwJDK}$@*bFFhz-;ccdCibM zoN<)}%NGzTRm+sSXUh&cq3CjZv$NM%jcrkGiq!dF78d3mBf)!lJBJ4strlnHsTT)Z zpRdi%Oy}PKJ_rW({!%R>$<(8(-Z)qFF-0O3Kz{PI*Fmpx7k3=Rf@G8jRC=M_XEDL| zsN!Z`o5LyKrTUR#X7=yAayK1bV8DH@GnodgYrH_xEjHy-&{MrJiOlz8allMBbA5*1 zGm;bM?akP55-}HLcNJ9fU4P2(i#YKnMTl6r*?~(+?QCkM3nk>fhydLtnnU&D>$gYg zEq*aPgU&HqI*A$!u0k#(d_yAog4)j}&ey8scsQ(E8YTvRihgi__sXgQ9~U0sVq`HT zFe3&DDuzgg_YDCF6)_eB6nmIk^dx6_A0y=}HcCE?>#Lk#ZZI)0AutIB1uG5%0vZJX n1QaH%{e6j3#v2A&==7N=vUM};qhbUIwzcI3GEUjB0s;sCigE7L literal 0 HcmV?d00001 diff --git a/azurerm/testdata/app_service_certificate_nopassword.pfx b/azurerm/internal/services/web/testdata/app_service_certificate_nopassword.pfx similarity index 100% rename from azurerm/testdata/app_service_certificate_nopassword.pfx rename to azurerm/internal/services/web/testdata/app_service_certificate_nopassword.pfx diff --git a/azurerm/testdata/application_gateway_test_2.key b/azurerm/testdata/application_gateway_test_2.key deleted file mode 100644 index 2f24fd8f36c4..000000000000 --- a/azurerm/testdata/application_gateway_test_2.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDD3ZPXq4Xwja38 -PKt76l4fg/4Mp0+bpWNZoAJV8kh0INJyiyg6IVU8eWyV9TAEBoCjDMj8TjgiXTl2 -17Gp0xDJ5KTEousxuM3wLWxtZGRRuyo/tmLy1GfoEdFt7g6RNA0sjL+EvV4dgQKi -PWr9VPfbMkaXnUnKJPPSdkmkkzMtCpPAoJZbr2JSHugO77B5zEjExFmmP2Iuis+8 -TImLRmPvrBY0rMt2cYDUhpTuQrTXIWuH0PZ3Na4nn8Frz3MbCTQ6uq1whs4EW3WW -HcbebUjsqaw9en99JATqmen1ICGoA+UQrNOcd6dWbbW38OpKLdD6vUzxJvYJPHPI -bRR8lf3tAgMBAAECggEAZ9fAHGYJ2yGijsqzuDznrhnSxW6nHEQxSkE1O8/6bedA -7A2vRDKL+EYANfkKfffcl5WdsXbe+AkpAEMXJIyMqB2a5c3imDf8p0vN4qmJLnPm -0GSoTUoj1LwtpvTBsGZCXc45c+zaSxYtCUs6wBkeV45uMs/nYU76Hiksnh6U0VmO -v84UFtY5iDvViLoZXEt/6Yv7VQkD13oRsc04Zs5SYFymBPB8I23LkhVraVEkVttW -rs7MFQNYRDchpS7ydZtKIHtJ3AZLGhZCMwYLx2q2DbCh6pBZeoF7ZaMnSpHBfnjD -z/A09a2E2V0uFTRXttWmLW177mlzOYS1b+QzLskUAQKBgQDlG9pyHWDKUd8D6Sby -yzlnfs7k2QAsrfcSe/rcMqkU5mNbqFshDzQGaq0QJFyYbhGbYyvkOR+YQQ4c9Qsh -UTXT9h4F6xPQyvqB2tar+1BZ2lSKQjdgQCgAqMlU9rt6ffZzReCgzScl+gsbiguC -m3oLYlOsO+qEp9zZcO06KAy1gQKBgQDa2tjiy9bZrHudraItbuFrMJ9hMi6+My/W -r4ky8+vibjb7/dZweoeIDzgQwX7cntG8Wi7IY7mYl9duSzvbSAW+dYX9GG9MBt6/ -O/YNxsmq26TellJukWHiSJMGYrCohKyKrN6kBgnjjUM8BDxWdnJeQxTuysx4bnlL -afr9VaO2bQKBgQCWiunL5//skUVgNXhxOxYaKlnaR7h0o07g53Rb8jHl2MjatlJC -89F0ke3r2Gi7hD+vgceaa+qVydFzN5S7rLgY8fSiYOghXu6iGuDKGxWeJPc97eqj -JSTj4gSA/qsL/u7MqdLC9mrN6nIYA2oyxOS5zD88whYEWqSkgC5w81X+gQKBgG/C -kD0I8PeJoDq+H3JqDA0L8GfXE42nYAeW7k4px8yCkeuPDcG0oJ93fh74YMtTAzHX -L8q/OljVOXsmSjPJjL1dEIZVwwgk/fzUJuuUFwn8Ti4ov4GdFkpS21nIbgQwdFgA -vVUvjD86tRnh49oXdIH0aa0jvNTHPYOoZDaYVBjlAoGAXjYfgRNin0osLFWzBQOR -rY/NWrkToY23HLmGojwBqdEWQKhIj/KD+Vh9vE4km46o60WkoJOoO+mCIjLgu/Sw -iS1bZlfKCD9YL4w5Te5mJtqIwQdnR9Ql/fBWYpuFBC/DrA2TD59qyiMZ1pT/W1Tk -1bfnHZPpBT5aFVq7CtD7ffk= ------END PRIVATE KEY----- diff --git a/azurerm/testdata/automation_certificate_test.crt b/azurerm/testdata/automation_certificate_test.crt deleted file mode 100644 index 8a573d3eaece..000000000000 --- a/azurerm/testdata/automation_certificate_test.crt +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICnDCCAYQCCQCL8XdPvGCY3DANBgkqhkiG9w0BAQsFADAQMQ4wDAYDVQQDDAVM -b2NhbDAeFw0xOTExMDYxNDUzMjhaFw0yOTExMDMxNDUzMjhaMBAxDjAMBgNVBAMM -BUxvY2FsMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArap1ZhMoz6A7 -uaFb/PTYwW1C+cByX4VAPyBxASk0+Lal/DAfdFgX9LpMOOXKZB3O5nU1AG8YNd0I -6+zy1T6mGUxVdZd2/Y0c4LZT3Iib9fDy8YJDap8CJK+FcRLPYNodfnOHBF48G2tP -Ozxf1Hn8F6ilZDsGwIvwpTsCg5sSI+WqcLD6u3I98F/XEbj3dLKfRb+KmxBW0DrH -4PhT4UArweaexHxIUKz76at96TRQcoM2BO+5HK5NpxyHt9sVbYcXBJ02+FT4sYkH -oDC7gVAr4j8PRYlc6U9RUApNfSgM1L6tmYjySGxwTo7UTPE4nElXSoGZ8xD4k8vR -rrh5ZyHe+wIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBBobmw043lmMMsrK0FWQ2z -zRykC/bVdyXvKmW9PdkPnAvy+8r7u2M//89USIUTL35weQXwLhBaI49u40IRbn3P -ilTXfPX8BEl2oaFpqIonM4w0iF6HDUgrwnFngCpX0G6AgTc7vLt0ljAG01q65wRi -y9x40eBcyW5D/eZ1GRD2QqUxdNwGQSzWnfmprp2xGkVQ4+7Raf6Af+pfY++epndo -13uL+3lsItPyJsCSQzsiOt341qfwfFXABZpEbH9XOivc+WLisD/rrU/+9V1HxD46 -GvpY0CTL+/UNV1yB/BYxXDQVwdnU0MA6fOgb+Vfbk8qkNf5huhLfXLnu6sz8uEwC ------END CERTIFICATE----- diff --git a/azurerm/testdata/automation_certificate_test.key b/azurerm/testdata/automation_certificate_test.key deleted file mode 100644 index 09167c5dab31..000000000000 --- a/azurerm/testdata/automation_certificate_test.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCtqnVmEyjPoDu5 -oVv89NjBbUL5wHJfhUA/IHEBKTT4tqX8MB90WBf0ukw45cpkHc7mdTUAbxg13Qjr -7PLVPqYZTFV1l3b9jRzgtlPciJv18PLxgkNqnwIkr4VxEs9g2h1+c4cEXjwba087 -PF/UefwXqKVkOwbAi/ClOwKDmxIj5apwsPq7cj3wX9cRuPd0sp9Fv4qbEFbQOsfg -+FPhQCvB5p7EfEhQrPvpq33pNFBygzYE77kcrk2nHIe32xVthxcEnTb4VPixiQeg -MLuBUCviPw9FiVzpT1FQCk19KAzUvq2ZiPJIbHBOjtRM8TicSVdKgZnzEPiTy9Gu -uHlnId77AgMBAAECggEASMFg7aKZNmKqoto274KkTGS56mf1go8Qm2G79gCNcKUU -ZNLEWrmNT7m8tRmP8OGMDICN8+CXA/nWAwEButTEQVT5eIo8D31O29WGzJ1uuVp4 -bTVliQWUoEnoXbbDqo+2S4OazPmttM8AIpDolNuGAWNl5tfTvFbkOlS+eOQ+dUrR -sSfdNjBDCU2XNwZu6acYPWvxqLqUasxOvvBbuVBdvwg4TzkusfsfKg6NCG6aa9rx -W1DneYmG/ZSZgVS1vJxAVFi3Mx1Vvo/0Ze6tVgz8wJ60nCABDlQkHmgH8YM6/bxu -WZmqp0B4eKlOX8uXRzcr/Hg7jRHzAjQb417W1tQUAQKBgQDTH2Dc/7XDC0W6aWJh -PLnEyhR3aIr6OKA2Cby7ne2R8zEZStQo9U/8M6gGiodfVWtuuYQhR/2CXDRAZU61 -AH3fnE6pOtyBKyOv2R/KSfI9i0s5c6ivyjlmbbmXBKGTOVVQhY82LVFOueGKD0DY -ctN8Ll0hicm/9IF3NWHB0tpDSQKBgQDSlM3kw15CQ9P9lZAd04PgHCbB2THYXWpL -Uis7+hwVMDhJlT3sO1ipbywgoPQ5qzciFuLqFUcqtEXAQWin33ETvzJmPsVdAipj -Nbtt4+Bw5enKh7CqTW71J2xm3d3HxUNbrdvbuW+SbZL3znQwP2enTx/FV0APQm55 -SQ1fW8lMIwKBgQDEbSpjE+rZyHAcqxYkYCp65IU8P+EmQ28UN+UILjyuETU6Ufup -C+xaOvl29IZU9ZWaFDLSADfmhMD8tQUQtJ9oX/Zzz1b/OtLeNkY0oK4oAqR/lJN6 -0syq9yW4U0+9OZed7lW7U1iVxa4JFH4BpHwNytlNbfRuix+1eM42VmZKOQKBgQCe -/m8+jCv9CE1lJ6m6e1sUuOyibCTwYgfBevbdwAe4D8JP/HjWhjB5LVE6CYychiOI -f5MwfoRPP/FyKXClX1V3PWMGQ9qsUNhEM+uiGu35D/6nRjAjRXfDbdKxEE9FaDFl -ZS2dBrOw8T6ID782NolCj8FDNI9Pdi8HMBsCpsCj1QKBgQC7p6yWuMD/k8F/rkAe -eFv6s/Bf0V6nbfGStf0wHS59DnIolEBudo7FjgyUAuaxhj4tHFbSpKvZUSsYbgUi -UcdoS1PfVl4iUYjkNsLDWbb1gBcmlpHB+B7o3OqkFvVQmLwlJgesbEcWVDONMmmc -yPaMshP3a4X+/QyosnmIKn5kVw== ------END PRIVATE KEY----- diff --git a/azurerm/testdata/hadoop_cluster_empty_node.sh b/azurerm/testdata/hadoop_cluster_empty_node.sh deleted file mode 100644 index 3215f0b3f34f..000000000000 --- a/azurerm/testdata/hadoop_cluster_empty_node.sh +++ /dev/null @@ -1,2 +0,0 @@ -#! /bin/bash -echo "Empty node setup" \ No newline at end of file From 0168697ad29ba4d46bc6ec5752c9b6961218ddd7 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 08:10:55 +0100 Subject: [PATCH 075/203] d/client_config: moving into the authorization package --- .../services/authorization}/data_source_client_config.go | 2 +- .../services/authorization}/data_source_client_config_test.go | 2 +- azurerm/internal/services/authorization/registration.go | 1 + azurerm/provider.go | 4 +--- 4 files changed, 4 insertions(+), 5 deletions(-) rename azurerm/{ => internal/services/authorization}/data_source_client_config.go (99%) rename azurerm/{ => internal/services/authorization}/data_source_client_config_test.go (98%) diff --git a/azurerm/data_source_client_config.go b/azurerm/internal/services/authorization/data_source_client_config.go similarity index 99% rename from azurerm/data_source_client_config.go rename to azurerm/internal/services/authorization/data_source_client_config.go index a689a196c8bf..5a0dc5656dff 100644 --- a/azurerm/data_source_client_config.go +++ b/azurerm/internal/services/authorization/data_source_client_config.go @@ -1,4 +1,4 @@ -package azurerm +package authorization import ( "fmt" diff --git a/azurerm/data_source_client_config_test.go b/azurerm/internal/services/authorization/data_source_client_config_test.go similarity index 98% rename from azurerm/data_source_client_config_test.go rename to azurerm/internal/services/authorization/data_source_client_config_test.go index f695c51d5f54..829b18c31e04 100644 --- a/azurerm/data_source_client_config_test.go +++ b/azurerm/internal/services/authorization/data_source_client_config_test.go @@ -1,4 +1,4 @@ -package azurerm +package authorization import ( "os" diff --git a/azurerm/internal/services/authorization/registration.go b/azurerm/internal/services/authorization/registration.go index bd5c394e93aa..47a95de3a214 100644 --- a/azurerm/internal/services/authorization/registration.go +++ b/azurerm/internal/services/authorization/registration.go @@ -15,6 +15,7 @@ func (r Registration) Name() string { func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ "azurerm_builtin_role_definition": dataSourceArmBuiltInRoleDefinition(), + "azurerm_client_config": dataSourceArmClientConfig(), "azurerm_role_definition": dataSourceArmRoleDefinition(), } } diff --git a/azurerm/provider.go b/azurerm/provider.go index f50b570106d3..c39af82b4a14 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -7,9 +7,7 @@ import ( ) func Provider() terraform.ResourceProvider { - dataSources := map[string]*schema.Resource{ - "azurerm_client_config": dataSourceArmClientConfig(), - } + dataSources := map[string]*schema.Resource{} resources := map[string]*schema.Resource{} From 3311b2702731a94846430317fc8434b547a03583 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 08:19:44 +0100 Subject: [PATCH 076/203] provider: cleaning up the remaining top-level functions --- azurerm/internal/acceptance/hack.go | 8 ++++--- .../required_resource_providers_test.go | 12 ++++------ azurerm/internal/provider/provider.go | 8 +++---- .../{ => internal/provider}/provider_test.go | 23 ++++--------------- azurerm/provider.go | 7 +----- main.go | 3 ++- 6 files changed, 21 insertions(+), 40 deletions(-) rename azurerm/{ => internal/acceptance}/required_resource_providers_test.go (84%) rename azurerm/{ => internal/provider}/provider_test.go (78%) diff --git a/azurerm/internal/acceptance/hack.go b/azurerm/internal/acceptance/hack.go index 46a3a50acb09..51e1a7a1f462 100644 --- a/azurerm/internal/acceptance/hack.go +++ b/azurerm/internal/acceptance/hack.go @@ -4,13 +4,15 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azuread/azuread" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider" ) -func CustomInit(provider *schema.Provider) { - AzureProvider = provider +func init() { + azureProvider := provider.AzureProvider().(*schema.Provider) + AzureProvider = azureProvider SupportedProviders = map[string]terraform.ResourceProvider{ - "azurerm": provider, + "azurerm": azureProvider, "azuread": azuread.Provider().(*schema.Provider), } } diff --git a/azurerm/required_resource_providers_test.go b/azurerm/internal/acceptance/required_resource_providers_test.go similarity index 84% rename from azurerm/required_resource_providers_test.go rename to azurerm/internal/acceptance/required_resource_providers_test.go index e67fe354c082..ef683285cd78 100644 --- a/azurerm/required_resource_providers_test.go +++ b/azurerm/internal/acceptance/required_resource_providers_test.go @@ -1,4 +1,4 @@ -package azurerm +package acceptance import ( "context" @@ -6,17 +6,15 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/hashicorp/go-azure-helpers/resourceproviders" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider" ) -// NOTE: this file has to remain in the root until all resources have been migrated into -// packages & out of the root, since it requires an empty initializer for the AzureProvider -// this will end up in ./azurerm/internal/provider +// NOTE: unfortunately this has to live here to avoid a circular reference for testing +// however since this is only used for testing, it's not the end of the world func TestAccAzureRMEnsureRequiredResourceProvidersAreRegistered(t *testing.T) { - config := acceptance.GetAuthConfig(t) + config := GetAuthConfig(t) if config == nil { return } @@ -36,7 +34,7 @@ func TestAccAzureRMEnsureRequiredResourceProvidersAreRegistered(t *testing.T) { } client := armClient.Resource.ProvidersClient - ctx := acceptance.AzureProvider.StopContext() + ctx := AzureProvider.StopContext() providerList, err := client.List(ctx, nil, "") if err != nil { t.Fatalf("Unable to list provider registration status, it is possible that this is due to invalid "+ diff --git a/azurerm/internal/provider/provider.go b/azurerm/internal/provider/provider.go index b0e9e23736a5..f7906b3ee9e8 100644 --- a/azurerm/internal/provider/provider.go +++ b/azurerm/internal/provider/provider.go @@ -15,11 +15,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -// for now the AzureProvider func takes a list of existing Data Sources & Resources at the top level -// which haven't been migrated into packages. once they have been this function can be updated to -// have no arguments - -func AzureProvider(dataSources map[string]*schema.Resource, resources map[string]*schema.Resource) terraform.ResourceProvider { +func AzureProvider() terraform.ResourceProvider { // avoids this showing up in test output var debugLog = func(f string, v ...interface{}) { if os.Getenv("TF_LOG") == "" { @@ -29,6 +25,8 @@ func AzureProvider(dataSources map[string]*schema.Resource, resources map[string log.Printf(f, v...) } + dataSources := make(map[string]*schema.Resource, 0) + resources := make(map[string]*schema.Resource, 0) for _, service := range SupportedServices() { debugLog("[DEBUG] Registering Data Sources for %q..", service.Name()) for k, v := range service.SupportedDataSources() { diff --git a/azurerm/provider_test.go b/azurerm/internal/provider/provider_test.go similarity index 78% rename from azurerm/provider_test.go rename to azurerm/internal/provider/provider_test.go index 98a78921475b..d41e663cfa3a 100644 --- a/azurerm/provider_test.go +++ b/azurerm/internal/provider/provider_test.go @@ -1,4 +1,4 @@ -package azurerm +package provider import ( "fmt" @@ -6,23 +6,10 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) -// NOTE: this file has to remain in the root until all resources have been migrated into -// packages & out of the root, since it requires an empty initializer for the AzureProvider -// this will end up in ./azurerm/internal/acceptance - -func init() { - azureProvider := Provider().(*schema.Provider) - - // HACK: remove this as soon as we can (when everything's moved out of the root, - // so ultimately when the AzureProvider function takes no args) - acceptance.CustomInit(azureProvider) -} - func TestProvider(t *testing.T) { - if err := Provider().(*schema.Provider).InternalValidate(); err != nil { + if err := AzureProvider().(*schema.Provider).InternalValidate(); err != nil { t.Fatalf("err: %s", err) } } @@ -31,7 +18,7 @@ func TestDataSourcesSupportCustomTimeouts(t *testing.T) { // this is required until 2.0 os.Setenv("ARM_PROVIDER_CUSTOM_TIMEOUTS", "true") - provider := Provider().(*schema.Provider) + provider := AzureProvider().(*schema.Provider) for dataSourceName, dataSource := range provider.DataSourcesMap { t.Run(fmt.Sprintf("DataSource/%s", dataSourceName), func(t *testing.T) { t.Logf("[DEBUG] Testing Data Source %q..", dataSourceName) @@ -70,7 +57,7 @@ func TestResourcesSupportCustomTimeouts(t *testing.T) { // this is required until 2.0 os.Setenv("ARM_PROVIDER_CUSTOM_TIMEOUTS", "true") - provider := Provider().(*schema.Provider) + provider := AzureProvider().(*schema.Provider) for resourceName, resource := range provider.ResourcesMap { t.Run(fmt.Sprintf("Resource/%s", resourceName), func(t *testing.T) { t.Logf("[DEBUG] Testing Resource %q..", resourceName) @@ -104,5 +91,5 @@ func TestResourcesSupportCustomTimeouts(t *testing.T) { } func TestProvider_impl(t *testing.T) { - var _ = Provider() + var _ = AzureProvider() } diff --git a/azurerm/provider.go b/azurerm/provider.go index c39af82b4a14..ec7914993869 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -1,15 +1,10 @@ package azurerm import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider" ) func Provider() terraform.ResourceProvider { - dataSources := map[string]*schema.Resource{} - - resources := map[string]*schema.Resource{} - - return provider.AzureProvider(dataSources, resources) + return provider.AzureProvider() } diff --git a/main.go b/main.go index 864219dea829..41127181ca84 100644 --- a/main.go +++ b/main.go @@ -12,5 +12,6 @@ func main() { log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime)) plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: azurerm.Provider}) + ProviderFunc: azurerm.Provider, + }) } From c0991c92095f131f4735390facdb2fcfa8ba72f5 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 08:22:47 +0100 Subject: [PATCH 077/203] signalr: fixing the tests --- .../services/signalr/resource_arm_signalr_service_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/services/signalr/resource_arm_signalr_service_test.go b/azurerm/internal/services/signalr/resource_arm_signalr_service_test.go index b54ffe268166..ba1d89f4ba5e 100644 --- a/azurerm/internal/services/signalr/resource_arm_signalr_service_test.go +++ b/azurerm/internal/services/signalr/resource_arm_signalr_service_test.go @@ -2,7 +2,6 @@ package signalr import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/monitor" "net/http" "testing" @@ -163,7 +162,7 @@ func TestAccAzureRMSignalRService_skuUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: monitor.testCheckAzureRMMonitorMetricAlertDestroy, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, Steps: []resource.TestStep{ { Config: freeConfig, @@ -227,7 +226,7 @@ func TestAccAzureRMSignalRService_capacityUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: monitor.testCheckAzureRMMonitorMetricAlertDestroy, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, Steps: []resource.TestStep{ { Config: standardConfig, @@ -291,7 +290,7 @@ func TestAccAzureRMSignalRService_skuAndCapacityUpdate(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: monitor.testCheckAzureRMMonitorMetricAlertDestroy, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, Steps: []resource.TestStep{ { Config: freeConfig, From 7860a1632e9b1c863ee8e1bb4fed8b7be4720ccb Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 19 Dec 2019 23:23:21 -0800 Subject: [PATCH 078/203] fix test failures --- .../services/cdn/data_source_cdn_profile_test.go | 9 ++++----- .../services/compute/resource_arm_managed_disk_test.go | 4 ++-- ...ource_arm_virtual_machine_scale_set_extension_test.go | 4 ++-- .../resource_arm_virtual_machine_scale_set_test.go | 2 +- .../datalake/data_source_data_lake_store_test.go | 3 +-- .../internal/services/dns/data_source_dns_zone_test.go | 7 +++---- .../monitor/resource_arm_metric_alertrule_test.go | 3 +-- .../services/mssql/data_source_mssql_elasticpool_test.go | 2 +- .../services/netapp/resource_arm_netapp_account_test.go | 3 +-- .../services/scheduler/resource_arm_scheduler_job.go | 5 +++-- .../services/storage/resource_arm_storage_account.go | 4 ++-- .../resource_arm_storage_account_network_rules.go | 2 +- .../storage/resource_arm_storage_account_test.go | 2 +- .../services/storage/resource_arm_storage_blob.go | 2 +- .../services/storage/resource_arm_storage_container.go | 2 +- .../services/storage/resource_arm_storage_queue.go | 2 +- .../services/storage/resource_arm_storage_table.go | 2 +- .../storage/resource_arm_storage_table_entity.go | 2 +- .../storage/resource_arm_storage_table_migration.go | 2 +- 19 files changed, 29 insertions(+), 33 deletions(-) diff --git a/azurerm/internal/services/cdn/data_source_cdn_profile_test.go b/azurerm/internal/services/cdn/data_source_cdn_profile_test.go index 514e52be9d53..9a1c7bab7505 100644 --- a/azurerm/internal/services/cdn/data_source_cdn_profile_test.go +++ b/azurerm/internal/services/cdn/data_source_cdn_profile_test.go @@ -2,7 +2,6 @@ package cdn import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -18,12 +17,12 @@ func TestAccDataSourceAzureRMCdnProfile_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: azurerm.testCheckAzureRMCdnProfileDestroy, + CheckDestroy: testCheckAzureRMCdnProfileDestroy, Steps: []resource.TestStep{ { Config: config, Check: resource.ComposeTestCheckFunc( - azurerm.testCheckAzureRMCdnProfileExists("data.azurerm_cdn_profile.test"), + testCheckAzureRMCdnProfileExists("data.azurerm_cdn_profile.test"), ), }, }, @@ -39,12 +38,12 @@ func TestAccDataSourceAzureRMCdnProfile_withTags(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: azurerm.testCheckAzureRMCdnProfileDestroy, + CheckDestroy: testCheckAzureRMCdnProfileDestroy, Steps: []resource.TestStep{ { Config: preConfig, Check: resource.ComposeTestCheckFunc( - azurerm.testCheckAzureRMCdnProfileExists(resourceName), + testCheckAzureRMCdnProfileExists(resourceName), resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), diff --git a/azurerm/internal/services/compute/resource_arm_managed_disk_test.go b/azurerm/internal/services/compute/resource_arm_managed_disk_test.go index da23f7e4ada2..e6d27cff65c4 100644 --- a/azurerm/internal/services/compute/resource_arm_managed_disk_test.go +++ b/azurerm/internal/services/compute/resource_arm_managed_disk_test.go @@ -105,11 +105,11 @@ func TestAccAzureRMManagedDisk_import(t *testing.T) { Steps: []resource.TestStep{ { //need to create a vm and then delete it so we can use the vhd to test import - Config: compute2.testAccAzureRMVirtualMachine_basicLinuxMachine(ri, location), + Config: testAccAzureRMVirtualMachine_basicLinuxMachine(ri, location), Destroy: false, ExpectNonEmptyPlan: true, Check: resource.ComposeTestCheckFunc( - compute2.testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), testDeleteAzureRMVirtualMachine("azurerm_virtual_machine.test"), ), }, diff --git a/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension_test.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension_test.go index f14489841e83..a971b5b9036a 100644 --- a/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension_test.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension_test.go @@ -278,7 +278,7 @@ func testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName string) name := rs.Primary.Attributes["name"] virtualMachineScaleSetIdRaw := rs.Primary.Attributes["virtual_machine_scale_set_id"] - virtualMachineScaleSetId, err := computeSvc.ParseVirtualMachineScaleSetID(virtualMachineScaleSetIdRaw) + virtualMachineScaleSetId, err := ParseVirtualMachineScaleSetID(virtualMachineScaleSetIdRaw) if err != nil { return err } @@ -307,7 +307,7 @@ func testCheckAzureRMVirtualMachineScaleSetExtensionDestroy(s *terraform.State) name := rs.Primary.Attributes["name"] virtualMachineScaleSetIdRaw := rs.Primary.Attributes["virtual_machine_scale_set_id"] - virtualMachineScaleSetId, err := computeSvc.ParseVirtualMachineScaleSetID(virtualMachineScaleSetIdRaw) + virtualMachineScaleSetId, err := ParseVirtualMachineScaleSetID(virtualMachineScaleSetIdRaw) if err != nil { return err } diff --git a/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_test.go index 339a0920ea00..82b5463968bd 100644 --- a/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_test.go +++ b/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_test.go @@ -703,7 +703,7 @@ func TestAccAzureRMVirtualMachineScaleSet_customImage(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - estGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, acceptance.Location()), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, acceptance.Location()), ), }, { diff --git a/azurerm/internal/services/datalake/data_source_data_lake_store_test.go b/azurerm/internal/services/datalake/data_source_data_lake_store_test.go index d2a3e96553ce..c97394500fac 100644 --- a/azurerm/internal/services/datalake/data_source_data_lake_store_test.go +++ b/azurerm/internal/services/datalake/data_source_data_lake_store_test.go @@ -2,7 +2,6 @@ package datalake import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" @@ -24,7 +23,7 @@ func TestAccDataSourceAzureRMDataLakeStore_basic(t *testing.T) { { Config: testAccDataSourceDataLakeStore_basic(rInt, rs, location), Check: resource.ComposeTestCheckFunc( - azurerm.testCheckAzureRMDataLakeStoreExists(dataSourceName), + testCheckAzureRMDataLakeStoreExists(dataSourceName), resource.TestCheckResourceAttr(dataSourceName, "tier", "Consumption"), ), }, diff --git a/azurerm/internal/services/dns/data_source_dns_zone_test.go b/azurerm/internal/services/dns/data_source_dns_zone_test.go index c2acf460985e..abcfad28f1c2 100644 --- a/azurerm/internal/services/dns/data_source_dns_zone_test.go +++ b/azurerm/internal/services/dns/data_source_dns_zone_test.go @@ -2,7 +2,6 @@ package dns import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -18,7 +17,7 @@ func TestAccDataSourceAzureRMDNSZone_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: azurerm.testCheckAzureRMDnsZoneDestroy, + CheckDestroy: testCheckAzureRMDnsZoneDestroy, Steps: []resource.TestStep{ { Config: testAccDataSourceDNSZone_basic(rInt, location), @@ -38,7 +37,7 @@ func TestAccDataSourceAzureRMDNSZone_tags(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: azurerm.testCheckAzureRMDnsZoneDestroy, + CheckDestroy: testCheckAzureRMDnsZoneDestroy, Steps: []resource.TestStep{ { Config: testAccDataSourceDNSZone_tags(rInt, location), @@ -60,7 +59,7 @@ func TestAccDataSourceAzureRMDNSZone_withoutResourceGroupName(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: azurerm.testCheckAzureRMDnsZoneDestroy, + CheckDestroy: testCheckAzureRMDnsZoneDestroy, Steps: []resource.TestStep{ { Config: testAccDataSourceDNSZone_onlyName(rInt, location, resourceGroupName), diff --git a/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go b/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go index 0473f9badead..fd57dc7fbafd 100644 --- a/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go +++ b/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go @@ -2,7 +2,6 @@ package monitor import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "testing" @@ -298,7 +297,7 @@ resource "azurerm_metric_alertrule" "import" { } func testAccAzureRMMetricAlertRule_sqlDatabaseStorage(rInt int, location string) string { - basicSqlServerDatabase := azurerm.testAccAzureRMSqlDatabase_basic(rInt, location) + basicSqlServerDatabase := testAccAzureRMSqlDatabase_basic(rInt, location) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/mssql/data_source_mssql_elasticpool_test.go b/azurerm/internal/services/mssql/data_source_mssql_elasticpool_test.go index 349545b3c7ac..7cdff4ed43d9 100644 --- a/azurerm/internal/services/mssql/data_source_mssql_elasticpool_test.go +++ b/azurerm/internal/services/mssql/data_source_mssql_elasticpool_test.go @@ -22,7 +22,7 @@ func TestAccDataSourceAzureRMMsSqlElasticPool_basic(t *testing.T) { { Config: testAccDataSourceAzureRMMsSqlElasticPool_basic(ri, location), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlElasticPoolExists(dataSourceName), + testCheckAzureRMMsSqlElasticPoolExists(dataSourceName), resource.TestCheckResourceAttrSet(dataSourceName, "name"), resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), resource.TestCheckResourceAttrSet(dataSourceName, "server_name"), diff --git a/azurerm/internal/services/netapp/resource_arm_netapp_account_test.go b/azurerm/internal/services/netapp/resource_arm_netapp_account_test.go index ab7fda711ea4..0fb077bf8162 100644 --- a/azurerm/internal/services/netapp/resource_arm_netapp_account_test.go +++ b/azurerm/internal/services/netapp/resource_arm_netapp_account_test.go @@ -2,7 +2,6 @@ package netapp import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -26,7 +25,7 @@ func TestAccAzureRMNetAppAccount(t *testing.T) { "update": testAccAzureRMNetAppAccount_update, }, "DataSource": { - "basic": azurerm.testAccDataSourceAzureRMNetAppAccount_basic, + "basic": testAccDataSourceAzureRMNetAppAccount_basic, }, } diff --git a/azurerm/internal/services/scheduler/resource_arm_scheduler_job.go b/azurerm/internal/services/scheduler/resource_arm_scheduler_job.go index 5f14b71b14a3..50c3e13aa7d7 100644 --- a/azurerm/internal/services/scheduler/resource_arm_scheduler_job.go +++ b/azurerm/internal/services/scheduler/resource_arm_scheduler_job.go @@ -22,6 +22,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -424,14 +425,14 @@ func resourceArmSchedulerJobActionStorageSchema() *schema.Resource { Type: schema.TypeString, Required: true, DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validateArmStorageAccountName, + ValidateFunc: storage.ValidateArmStorageAccountName, }, "storage_queue_name": { Type: schema.TypeString, Required: true, DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validateArmStorageQueueName, + ValidateFunc: storage.ValidateArmStorageAccountName, }, "sas_token": { diff --git a/azurerm/internal/services/storage/resource_arm_storage_account.go b/azurerm/internal/services/storage/resource_arm_storage_account.go index e94a4fce9cf5..e45257a259ba 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account.go @@ -58,7 +58,7 @@ func resourceArmStorageAccount() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageAccountName, + ValidateFunc: ValidateArmStorageAccountName, }, "resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(), @@ -1734,7 +1734,7 @@ func flattenStorageAccountBypass(input storage.Bypass) []interface{} { return bypass } -func validateArmStorageAccountName(v interface{}, _ string) (warnings []string, errors []error) { +func ValidateArmStorageAccountName(v interface{}, _ string) (warnings []string, errors []error) { input := v.(string) if !regexp.MustCompile(`\A([a-z0-9]{3,24})\z`).MatchString(input) { diff --git a/azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go b/azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go index 3735483df7fe..a85b4e115b25 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account_network_rules.go @@ -43,7 +43,7 @@ func resourceArmStorageAccountNetworkRules() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageAccountName, + ValidateFunc: ValidateArmStorageAccountName, }, "bypass": { diff --git a/azurerm/internal/services/storage/resource_arm_storage_account_test.go b/azurerm/internal/services/storage/resource_arm_storage_account_test.go index 63111673ed06..549a80a49e76 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account_test.go @@ -50,7 +50,7 @@ func TestValidateArmStorageAccountName(t *testing.T) { } for _, test := range testCases { - _, es := validateArmStorageAccountName(test.input, "name") + _, es := ValidateArmStorageAccountName(test.input, "name") if test.shouldError && len(es) == 0 { t.Fatalf("Expected validating name %q to fail", test.input) diff --git a/azurerm/internal/services/storage/resource_arm_storage_blob.go b/azurerm/internal/services/storage/resource_arm_storage_blob.go index c4d3a01ff432..1c8c89add5a0 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_blob.go +++ b/azurerm/internal/services/storage/resource_arm_storage_blob.go @@ -50,7 +50,7 @@ func resourceArmStorageBlob() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageAccountName, + ValidateFunc: ValidateArmStorageAccountName, }, "storage_container_name": { diff --git a/azurerm/internal/services/storage/resource_arm_storage_container.go b/azurerm/internal/services/storage/resource_arm_storage_container.go index 5d2b563f51d3..4de23eeb53c9 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_container.go +++ b/azurerm/internal/services/storage/resource_arm_storage_container.go @@ -49,7 +49,7 @@ func resourceArmStorageContainer() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageAccountName, + ValidateFunc: ValidateArmStorageAccountName, }, "container_access_type": { diff --git a/azurerm/internal/services/storage/resource_arm_storage_queue.go b/azurerm/internal/services/storage/resource_arm_storage_queue.go index f2d626d6e310..20575ca10d93 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_queue.go +++ b/azurerm/internal/services/storage/resource_arm_storage_queue.go @@ -47,7 +47,7 @@ func resourceArmStorageQueue() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageAccountName, + ValidateFunc: ValidateArmStorageAccountName, }, "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), diff --git a/azurerm/internal/services/storage/resource_arm_storage_table.go b/azurerm/internal/services/storage/resource_arm_storage_table.go index 79913d4d9287..c41358990ee0 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table.go @@ -61,7 +61,7 @@ func resourceArmStorageTable() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageAccountName, + ValidateFunc: ValidateArmStorageAccountName, }, // TODO: deprecate this in the docs diff --git a/azurerm/internal/services/storage/resource_arm_storage_table_entity.go b/azurerm/internal/services/storage/resource_arm_storage_table_entity.go index 04f1d5226f31..d66ab10f1ead 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table_entity.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_entity.go @@ -43,7 +43,7 @@ func resourceArmStorageTableEntity() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageAccountName, + ValidateFunc: ValidateArmStorageAccountName, }, "partition_key": { Type: schema.TypeString, diff --git a/azurerm/internal/services/storage/resource_arm_storage_table_migration.go b/azurerm/internal/services/storage/resource_arm_storage_table_migration.go index 1396197249a6..423c09309fb9 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_migration.go @@ -25,7 +25,7 @@ func resourceStorageTableStateResourceV0V1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageAccountName, + ValidateFunc: ValidateArmStorageAccountName, }, "resource_group_name": azure.SchemaResourceGroupNameDeprecated(), "acl": { From d86ba0ef8e32fc0a25fdb0ca7c1f3f7b6c283e7f Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 08:31:15 +0100 Subject: [PATCH 079/203] refactor: removing a circular reference by moving the init to provider --- azurerm/internal/acceptance/hack.go | 18 ------------------ azurerm/internal/provider/provider_test.go | 13 +++++++++++++ .../required_resource_providers_test.go | 15 ++++++--------- 3 files changed, 19 insertions(+), 27 deletions(-) delete mode 100644 azurerm/internal/acceptance/hack.go rename azurerm/internal/{acceptance => provider}/required_resource_providers_test.go (81%) diff --git a/azurerm/internal/acceptance/hack.go b/azurerm/internal/acceptance/hack.go deleted file mode 100644 index 51e1a7a1f462..000000000000 --- a/azurerm/internal/acceptance/hack.go +++ /dev/null @@ -1,18 +0,0 @@ -package acceptance - -import ( - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azuread/azuread" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider" -) - -func init() { - azureProvider := provider.AzureProvider().(*schema.Provider) - - AzureProvider = azureProvider - SupportedProviders = map[string]terraform.ResourceProvider{ - "azurerm": azureProvider, - "azuread": azuread.Provider().(*schema.Provider), - } -} diff --git a/azurerm/internal/provider/provider_test.go b/azurerm/internal/provider/provider_test.go index d41e663cfa3a..3cd1eadba3ba 100644 --- a/azurerm/internal/provider/provider_test.go +++ b/azurerm/internal/provider/provider_test.go @@ -6,8 +6,21 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azuread/azuread" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) +func init() { + azureProvider := AzureProvider().(*schema.Provider) + + acceptance.AzureProvider = azureProvider + acceptance.SupportedProviders = map[string]terraform.ResourceProvider{ + "azurerm": azureProvider, + "azuread": azuread.Provider().(*schema.Provider), + } +} + func TestProvider(t *testing.T) { if err := AzureProvider().(*schema.Provider).InternalValidate(); err != nil { t.Fatalf("err: %s", err) diff --git a/azurerm/internal/acceptance/required_resource_providers_test.go b/azurerm/internal/provider/required_resource_providers_test.go similarity index 81% rename from azurerm/internal/acceptance/required_resource_providers_test.go rename to azurerm/internal/provider/required_resource_providers_test.go index ef683285cd78..a53b03d48075 100644 --- a/azurerm/internal/acceptance/required_resource_providers_test.go +++ b/azurerm/internal/provider/required_resource_providers_test.go @@ -1,4 +1,4 @@ -package acceptance +package provider import ( "context" @@ -6,15 +6,12 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/hashicorp/go-azure-helpers/resourceproviders" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider" ) -// NOTE: unfortunately this has to live here to avoid a circular reference for testing -// however since this is only used for testing, it's not the end of the world - func TestAccAzureRMEnsureRequiredResourceProvidersAreRegistered(t *testing.T) { - config := GetAuthConfig(t) + config := acceptance.GetAuthConfig(t) if config == nil { return } @@ -34,7 +31,7 @@ func TestAccAzureRMEnsureRequiredResourceProvidersAreRegistered(t *testing.T) { } client := armClient.Resource.ProvidersClient - ctx := AzureProvider.StopContext() + ctx := acceptance.AzureProvider.StopContext() providerList, err := client.List(ctx, nil, "") if err != nil { t.Fatalf("Unable to list provider registration status, it is possible that this is due to invalid "+ @@ -43,8 +40,8 @@ func TestAccAzureRMEnsureRequiredResourceProvidersAreRegistered(t *testing.T) { } availableResourceProviders := providerList.Values() - requiredResourceProviders := provider.RequiredResourceProviders() - err = provider.EnsureResourceProvidersAreRegistered(ctx, *client, availableResourceProviders, requiredResourceProviders) + requiredResourceProviders := RequiredResourceProviders() + err = EnsureResourceProvidersAreRegistered(ctx, *client, availableResourceProviders, requiredResourceProviders) if err != nil { t.Fatalf("Error registering Resource Providers: %+v", err) } From 1c8950caaaf0c1d701d0d57d46e4d66c69286e4b Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 08:35:30 +0100 Subject: [PATCH 080/203] compute: moving proximity placement group to the right package --- azurerm/internal/services/compute/registration.go | 1 + .../resource_arm_proximity_placement_group.go | 2 +- .../resource_arm_proximity_placement_group_test.go | 2 +- azurerm/internal/services/network/registration.go | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) rename azurerm/internal/services/{network => compute}/resource_arm_proximity_placement_group.go (99%) rename azurerm/internal/services/{network => compute}/resource_arm_proximity_placement_group_test.go (99%) diff --git a/azurerm/internal/services/compute/registration.go b/azurerm/internal/services/compute/registration.go index f6086757c50c..8ac9a25433ff 100644 --- a/azurerm/internal/services/compute/registration.go +++ b/azurerm/internal/services/compute/registration.go @@ -33,6 +33,7 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_availability_set": resourceArmAvailabilitySet(), "azurerm_managed_disk": resourceArmManagedDisk(), "azurerm_image": resourceArmImage(), + "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), "azurerm_shared_image_version": resourceArmSharedImageVersion(), diff --git a/azurerm/internal/services/network/resource_arm_proximity_placement_group.go b/azurerm/internal/services/compute/resource_arm_proximity_placement_group.go similarity index 99% rename from azurerm/internal/services/network/resource_arm_proximity_placement_group.go rename to azurerm/internal/services/compute/resource_arm_proximity_placement_group.go index 9a5cbfe2e754..f6adbf12960e 100644 --- a/azurerm/internal/services/network/resource_arm_proximity_placement_group.go +++ b/azurerm/internal/services/compute/resource_arm_proximity_placement_group.go @@ -1,4 +1,4 @@ -package network +package compute import ( "fmt" diff --git a/azurerm/internal/services/network/resource_arm_proximity_placement_group_test.go b/azurerm/internal/services/compute/resource_arm_proximity_placement_group_test.go similarity index 99% rename from azurerm/internal/services/network/resource_arm_proximity_placement_group_test.go rename to azurerm/internal/services/compute/resource_arm_proximity_placement_group_test.go index bb54626c91af..923520b8f0dc 100644 --- a/azurerm/internal/services/network/resource_arm_proximity_placement_group_test.go +++ b/azurerm/internal/services/compute/resource_arm_proximity_placement_group_test.go @@ -1,4 +1,4 @@ -package network +package compute import ( "fmt" diff --git a/azurerm/internal/services/network/registration.go b/azurerm/internal/services/network/registration.go index 511642f05109..48f9f9769bd9 100644 --- a/azurerm/internal/services/network/registration.go +++ b/azurerm/internal/services/network/registration.go @@ -79,7 +79,6 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_private_link_endpoint": resourceArmPrivateLinkEndpoint(), "azurerm_private_endpoint": resourceArmPrivateEndpoint(), "azurerm_private_link_service": resourceArmPrivateLinkService(), - "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), "azurerm_public_ip": resourceArmPublicIp(), "azurerm_public_ip_prefix": resourceArmPublicIpPrefix(), "azurerm_network_security_group": resourceArmNetworkSecurityGroup(), From 229cd035c4932a433a1d67bd8cbf3344de85bd61 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 08:41:04 +0100 Subject: [PATCH 081/203] resource: fixing the `azurerm_resources` test --- .../resource/data_source_resources_test.go | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/azurerm/internal/services/resource/data_source_resources_test.go b/azurerm/internal/services/resource/data_source_resources_test.go index 2e36c6010e29..6e1bdb678ab2 100644 --- a/azurerm/internal/services/resource/data_source_resources_test.go +++ b/azurerm/internal/services/resource/data_source_resources_test.go @@ -21,7 +21,7 @@ func TestAccDataSourceAzureRMResources_ByName(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMStorageAccount_basic(ri, rs, location), + Config: testAccDataSourceAzureRMResources_template(ri, rs, location), }, { Config: testAccDataSourceAzureRMResources_ByName(ri, rs, location), @@ -44,7 +44,7 @@ func TestAccDataSourceAzureRMResources_ByResourceGroup(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMStorageAccount_basic(ri, rs, location), + Config: testAccDataSourceAzureRMResources_template(ri, rs, location), }, { Config: testAccDataSourceAzureRMResources_ByResourceGroup(ri, rs, location), @@ -67,7 +67,7 @@ func TestAccDataSourceAzureRMResources_ByResourceType(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMStorageAccount_basic(ri, rs, location), + Config: testAccDataSourceAzureRMResources_template(ri, rs, location), }, { Config: testAccDataSourceAzureRMResources_ByResourceType(ri, rs, location), @@ -90,7 +90,7 @@ func TestAccDataSourceAzureRMResources_FilteredByTags(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMStorageAccount_basic(ri, rs, location), + Config: testAccDataSourceAzureRMResources_template(ri, rs, location), }, { Config: testAccDataSourceAzureRMResources_FilteredByTags(ri, rs, location), @@ -103,7 +103,7 @@ func TestAccDataSourceAzureRMResources_FilteredByTags(t *testing.T) { } func testAccDataSourceAzureRMResources_ByName(rInt int, rString string, location string) string { - r := testAccDataSourceAzureRMStorageAccount_basic(rInt, rString, location) + r := testAccDataSourceAzureRMResources_template(rInt, rString, location) return fmt.Sprintf(` %s @@ -114,7 +114,7 @@ data "azurerm_resources" "test" { } func testAccDataSourceAzureRMResources_ByResourceGroup(rInt int, rString string, location string) string { - r := testAccDataSourceAzureRMStorageAccount_basic(rInt, rString, location) + r := testAccDataSourceAzureRMResources_template(rInt, rString, location) return fmt.Sprintf(` %s @@ -125,7 +125,7 @@ data "azurerm_resources" "test" { } func testAccDataSourceAzureRMResources_ByResourceType(rInt int, rString string, location string) string { - r := testAccDataSourceAzureRMStorageAccount_basic(rInt, rString, location) + r := testAccDataSourceAzureRMResources_template(rInt, rString, location) return fmt.Sprintf(` %s @@ -137,7 +137,7 @@ data "azurerm_resources" "test" { } func testAccDataSourceAzureRMResources_FilteredByTags(rInt int, rString string, location string) string { - r := testAccDataSourceAzureRMStorageAccount_basic(rInt, rString, location) + r := testAccDataSourceAzureRMResources_template(rInt, rString, location) return fmt.Sprintf(` %s @@ -151,3 +151,25 @@ data "azurerm_resources" "test" { } `, r) } + +func testAccDataSourceAzureRMResources_template(rInt int, rString string, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "acctestsads%s" + resource_group_name = "${azurerm_resource_group.test.name}" + + location = "${azurerm_resource_group.test.location}" + account_tier = "Standard" + account_replication_type = "LRS" + + tags = { + environment = "production" + } +} +`, rInt, location, rString) +} From 8488c5a670d665f8db8953a4f51c64a7611547c6 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 09:31:24 +0100 Subject: [PATCH 082/203] compute: fixing the compile errors --- ..._virtual_machine_scale_set_network_test.go | 93 ++++++++++++++++++- ..._virtual_machine_scale_set_network_test.go | 93 ++++++++++++++++++- 2 files changed, 180 insertions(+), 6 deletions(-) diff --git a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_network_test.go b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_network_test.go index a4617b566fd2..82a9a4fe4f7f 100644 --- a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_network_test.go +++ b/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_network_test.go @@ -892,9 +892,96 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } func testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationGateway(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_basic(rInt, location) return fmt.Sprintf(` -%s +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctest-vnet-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" +} + +resource "azurerm_subnet" "test" { + name = "subnet-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.0.0/24" +} + +resource "azurerm_public_ip" "test" { + name = "acctest-pubip-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + allocation_method = "Dynamic" +} + +# since these variables are re-used - a locals block makes this more maintainable +locals { + backend_address_pool_name = "${azurerm_virtual_network.test.name}-beap" + frontend_port_name = "${azurerm_virtual_network.test.name}-feport" + frontend_ip_configuration_name = "${azurerm_virtual_network.test.name}-feip" + http_setting_name = "${azurerm_virtual_network.test.name}-be-htst" + listener_name = "${azurerm_virtual_network.test.name}-httplstn" + request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt" +} + +resource "azurerm_application_gateway" "test" { + name = "acctestag-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + + sku { + name = "Standard_Small" + tier = "Standard" + capacity = 2 + } + + gateway_ip_configuration { + name = "my-gateway-ip-configuration" + subnet_id = "${azurerm_subnet.test.id}" + } + + frontend_port { + name = "${local.frontend_port_name}" + port = 80 + } + + frontend_ip_configuration { + name = "${local.frontend_ip_configuration_name}" + public_ip_address_id = "${azurerm_public_ip.test.id}" + } + + backend_address_pool { + name = "${local.backend_address_pool_name}" + } + + backend_http_settings { + name = "${local.http_setting_name}" + cookie_based_affinity = "Disabled" + port = 80 + protocol = "Http" + request_timeout = 1 + } + + http_listener { + name = "${local.listener_name}" + frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" + frontend_port_name = "${local.frontend_port_name}" + protocol = "Http" + } + + request_routing_rule { + name = "${local.request_routing_rule_name}" + rule_type = "Basic" + http_listener_name = "${local.listener_name}" + backend_address_pool_name = "${local.backend_address_pool_name}" + backend_http_settings_name = "${local.http_setting_name}" + } +} resource "azurerm_subnet" "other" { name = "other" @@ -938,7 +1025,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, rInt, location, rInt, rInt, rInt, rInt, rInt) } func testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroup(rInt int, location string) string { diff --git a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_network_test.go b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_network_test.go index 4914237e81fb..8bf659dd8529 100644 --- a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_network_test.go +++ b/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_network_test.go @@ -890,10 +890,97 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } func testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationGateway(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_basic(rInt, location) name := testAccAzureRMWindowsVirtualMachineScaleSet_vmName(rInt) return fmt.Sprintf(` -%s +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctest-vnet-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" +} + +resource "azurerm_subnet" "test" { + name = "subnet-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.0.0/24" +} + +resource "azurerm_public_ip" "test" { + name = "acctest-pubip-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + allocation_method = "Dynamic" +} + +# since these variables are re-used - a locals block makes this more maintainable +locals { + backend_address_pool_name = "${azurerm_virtual_network.test.name}-beap" + frontend_port_name = "${azurerm_virtual_network.test.name}-feport" + frontend_ip_configuration_name = "${azurerm_virtual_network.test.name}-feip" + http_setting_name = "${azurerm_virtual_network.test.name}-be-htst" + listener_name = "${azurerm_virtual_network.test.name}-httplstn" + request_routing_rule_name = "${azurerm_virtual_network.test.name}-rqrt" +} + +resource "azurerm_application_gateway" "test" { + name = "acctestag-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + + sku { + name = "Standard_Small" + tier = "Standard" + capacity = 2 + } + + gateway_ip_configuration { + name = "my-gateway-ip-configuration" + subnet_id = "${azurerm_subnet.test.id}" + } + + frontend_port { + name = "${local.frontend_port_name}" + port = 80 + } + + frontend_ip_configuration { + name = "${local.frontend_ip_configuration_name}" + public_ip_address_id = "${azurerm_public_ip.test.id}" + } + + backend_address_pool { + name = "${local.backend_address_pool_name}" + } + + backend_http_settings { + name = "${local.http_setting_name}" + cookie_based_affinity = "Disabled" + port = 80 + protocol = "Http" + request_timeout = 1 + } + + http_listener { + name = "${local.listener_name}" + frontend_ip_configuration_name = "${local.frontend_ip_configuration_name}" + frontend_port_name = "${local.frontend_port_name}" + protocol = "Http" + } + + request_routing_rule { + name = "${local.request_routing_rule_name}" + rule_type = "Basic" + http_listener_name = "${local.listener_name}" + backend_address_pool_name = "${local.backend_address_pool_name}" + backend_http_settings_name = "${local.http_setting_name}" + } +} locals { vm_name = "%s" @@ -939,7 +1026,7 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, name) +`, rInt, location, rInt, rInt, rInt, rInt, name) } func testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroup(rInt int, location string) string { From cfce06bdadaa3a3fe87facbdd3ec8a7168fd171c Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 09:55:12 +0100 Subject: [PATCH 083/203] r/mssql_server_security_alert_policy: adding a local CheckDestroy func --- ...mssql_server_security_alert_policy_test.go | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy_test.go b/azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy_test.go index 88a24101c6ed..6f3d3c51c6c6 100644 --- a/azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy_test.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy_test.go @@ -2,6 +2,7 @@ package mssql import ( "fmt" + "net/http" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -19,7 +20,7 @@ func TestAccAzureRMMssqlServerSecurityAlertPolicy_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountSqlServerDestroy, + CheckDestroy: testCheckAzureRMMssqlServerSecurityAlertPolicyDestroy, Steps: []resource.TestStep{ { Config: testAccAzureRMMssqlServerSecurityAlertPolicy_basic(ri, acceptance.Location()), @@ -49,7 +50,7 @@ func TestAccAzureRMMssqlServerSecurityAlertPolicy_update(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountSqlServerDestroy, + CheckDestroy: testCheckAzureRMMssqlServerSecurityAlertPolicyDestroy, Steps: []resource.TestStep{ { Config: testAccAzureRMMssqlServerSecurityAlertPolicy_basic(ri, acceptance.Location()), @@ -116,13 +117,29 @@ func testCheckAzureRMMssqlServerSecurityAlertPolicyExists(resourceName string) r } } -func testCheckAzureRMStorageAccountSqlServerDestroy(s *terraform.State) error { - err := testCheckAzureRMStorageAccountDestroy(s) - if err != nil { - return err +func testCheckAzureRMMssqlServerSecurityAlertPolicyDestroy(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_mssql_server_security_alert_policy" { + continue + } + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + serverName := rs.Primary.Attributes["server_name"] + + client := acceptance.AzureProvider.Meta().(*clients.Client).MSSQL.ServerSecurityAlertPoliciesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + resp, err := client.Get(ctx, resourceGroup, serverName) + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Security Alert Policy still exists:\n%#v", resp.SecurityAlertPolicyProperties) + } } - return testCheckAzureRMSqlServerDestroy(s) + return nil } func testAccAzureRMMssqlServerSecurityAlertPolicy_basic(rInt int, location string) string { From 42ff4448e67526225030c73348444b91c6cd0387 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 10:00:47 +0100 Subject: [PATCH 084/203] r/mssql_database_vulnerability_assessment_rule_baseline: switching to a local CheckDestroy func --- ...erability_assessment_rule_baseline_test.go | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go b/azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go index 1deec1323be7..ebe7e6a7ff0a 100644 --- a/azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go @@ -2,6 +2,7 @@ package mssql import ( "fmt" + "net/http" "testing" "github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2017-03-01-preview/sql" @@ -21,12 +22,12 @@ func TestAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_basic(t *tes resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountDatabaseDestroy, + CheckDestroy: testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineDestroy, Steps: []resource.TestStep{ { Config: testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_basic(ri, acceptance.Location()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBaselineExists(resourceName), + testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "rule_id", "VA2002"), resource.TestCheckResourceAttr(resourceName, "baseline_name", "default"), resource.TestCheckResourceAttr(resourceName, "baseline_result.#", "2"), @@ -47,12 +48,12 @@ func TestAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_master(t *te resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountDatabaseDestroy, + CheckDestroy: testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineDestroy, Steps: []resource.TestStep{ { Config: testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_master(ri, acceptance.Location()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBaselineExists(resourceName), + testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "rule_id", "VA2065"), resource.TestCheckResourceAttr(resourceName, "baseline_name", "master"), resource.TestCheckResourceAttr(resourceName, "baseline_result.#", "1"), @@ -66,7 +67,7 @@ func TestAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_master(t *te { Config: testAccAzureRMDatabaseVulnerabilityAssessmentRuleBaseline_update(ri, acceptance.Location()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBaselineExists(resourceName), + testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineExists(resourceName), resource.TestCheckResourceAttr(resourceName, "rule_id", "VA2065"), resource.TestCheckResourceAttr(resourceName, "baseline_name", "master"), resource.TestCheckResourceAttr(resourceName, "baseline_result.#", "2"), @@ -81,7 +82,7 @@ func TestAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_master(t *te }) } -func testCheckAzureRMBaselineExists(resourceName string) resource.TestCheckFunc { +func testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] if !ok { @@ -117,13 +118,37 @@ func testCheckAzureRMBaselineExists(resourceName string) resource.TestCheckFunc } } -func testCheckAzureRMStorageAccountDatabaseDestroy(s *terraform.State) error { - err := testCheckAzureRMStorageAccountDestroy(s) - if err != nil { - return err +func testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineDestroy(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_mssql_database_vulnerability_assessment_rule_baseline" { + continue + } + + id, err := azure.ParseAzureResourceID(rs.Primary.ID) + if err != nil { + return err + } + + resourceGroupName := id.ResourceGroup + serverName := id.Path["servers"] + databaseName := rs.Primary.Attributes["database_name"] + ruleId := rs.Primary.Attributes["rule_id"] + baselineName := sql.VulnerabilityAssessmentPolicyBaselineName(rs.Primary.Attributes["baseline_name"]) + + client := acceptance.AzureProvider.Meta().(*clients.Client).MSSQL.DatabaseVulnerabilityAssessmentRuleBaselinesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + resp, err := client.Get(ctx, resourceGroupName, serverName, databaseName, ruleId, baselineName) + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Database Vulnerability Assessment Rule Baseline still exists:\n%#v", resp.DatabaseVulnerabilityAssessmentRuleBaselineProperties) + } } - return testCheckAzureRMSqlDatabaseDestroy(s) + return nil } func testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_basic(rInt int, location string) string { From b8c3a314a12f91f15801070f75734de89af3382b Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 10:04:13 +0100 Subject: [PATCH 085/203] r/(montitor_)metric_alert_rule: switching to a local template func --- .../resource_arm_metric_alertrule_test.go | 146 +++++++++++++++++- ...ource_arm_monitor_metric_alertrule_test.go | 146 +++++++++++++++++- 2 files changed, 276 insertions(+), 16 deletions(-) diff --git a/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go b/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go index fd57dc7fbafd..d2d9ce2a346e 100644 --- a/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go +++ b/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go @@ -2,7 +2,6 @@ package monitor import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -217,9 +216,75 @@ func testCheckAzureRMMetricAlertRuleDestroy(s *terraform.State) error { } func testAccAzureRMMetricAlertRule_virtualMachineCpu(rInt int, location string, enabled bool) string { - template := compute.testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt, location) return fmt.Sprintf(` -%s +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "acctsub-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_network_interface" "test" { + name = "acctni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_D1_v2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + storage_os_disk { + name = "osd-%d" + caching = "ReadWrite" + create_option = "FromImage" + disk_size_gb = "50" + managed_disk_type = "Standard_LRS" + } + + os_profile { + computer_name = "hn%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags = { + environment = "Production" + cost-center = "Ops" + } +} resource "azurerm_metric_alertrule" "test" { name = "${azurerm_virtual_machine.test.name}-cpu" @@ -254,7 +319,7 @@ resource "azurerm_metric_alertrule" "test" { } } } -`, template, enabled) +`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, enabled) } func testAccAzureRMMetricAlertRule_requiresImport(rInt int, location string, enabled bool) string { @@ -297,10 +362,75 @@ resource "azurerm_metric_alertrule" "import" { } func testAccAzureRMMetricAlertRule_sqlDatabaseStorage(rInt int, location string) string { - basicSqlServerDatabase := testAccAzureRMSqlDatabase_basic(rInt, location) - return fmt.Sprintf(` -%s +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "acctsub-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_network_interface" "test" { + name = "acctni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_D1_v2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + storage_os_disk { + name = "osd-%d" + caching = "ReadWrite" + create_option = "FromImage" + disk_size_gb = "50" + managed_disk_type = "Standard_LRS" + } + + os_profile { + computer_name = "hn%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags = { + environment = "Production" + cost-center = "Ops" + } +} resource "azurerm_metric_alertrule" "test" { name = "${azurerm_sql_database.test.name}-storage" @@ -335,5 +465,5 @@ resource "azurerm_metric_alertrule" "test" { } } } -`, basicSqlServerDatabase) +`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) } diff --git a/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule_test.go b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule_test.go index f6cd4894c7ff..b05197ace56d 100644 --- a/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule_test.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule_test.go @@ -10,7 +10,6 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -217,9 +216,75 @@ func testCheckAzureRMMonitorMetricAlertRuleDestroy(s *terraform.State) error { } func testAccAzureRMMonitorMetricAlertRule_virtualMachineCpu(rInt int, location string, enabled bool) string { - template := compute.testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt, location) return fmt.Sprintf(` -%s +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "acctsub-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_network_interface" "test" { + name = "acctni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_D1_v2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + storage_os_disk { + name = "osd-%d" + caching = "ReadWrite" + create_option = "FromImage" + disk_size_gb = "50" + managed_disk_type = "Standard_LRS" + } + + os_profile { + computer_name = "hn%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags = { + environment = "Production" + cost-center = "Ops" + } +} resource "azurerm_monitor_metric_alertrule" "test" { name = "${azurerm_virtual_machine.test.name}-cpu" @@ -254,7 +319,7 @@ resource "azurerm_monitor_metric_alertrule" "test" { } } } -`, template, enabled) +`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, enabled) } func testAccAzureRMMonitorMetricAlertRule_requiresImport(rInt int, location string, enabled bool) string { @@ -297,10 +362,75 @@ resource "azurerm_monitor_metric_alertrule" "import" { } func testAccAzureRMMonitorMetricAlertRule_sqlDatabaseStorage(rInt int, location string) string { - basicSqlServerDatabase := testAccAzureRMSqlDatabase_basic(rInt, location) - return fmt.Sprintf(` -%s +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctvn-%d" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_subnet" "test" { + name = "acctsub-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" +} + +resource "azurerm_network_interface" "test" { + name = "acctni-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + ip_configuration { + name = "testconfiguration1" + subnet_id = "${azurerm_subnet.test.id}" + private_ip_address_allocation = "Dynamic" + } +} + +resource "azurerm_virtual_machine" "test" { + name = "acctvm-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + network_interface_ids = ["${azurerm_network_interface.test.id}"] + vm_size = "Standard_D1_v2" + + storage_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "16.04-LTS" + version = "latest" + } + + storage_os_disk { + name = "osd-%d" + caching = "ReadWrite" + create_option = "FromImage" + disk_size_gb = "50" + managed_disk_type = "Standard_LRS" + } + + os_profile { + computer_name = "hn%d" + admin_username = "testadmin" + admin_password = "Password1234!" + } + + os_profile_linux_config { + disable_password_authentication = false + } + + tags = { + environment = "Production" + cost-center = "Ops" + } +} resource "azurerm_monitor_metric_alertrule" "test" { name = "${azurerm_sql_database.test.name}-storage" @@ -335,5 +465,5 @@ resource "azurerm_monitor_metric_alertrule" "test" { } } } -`, basicSqlServerDatabase) +`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) } From 4485dcc2b22143b47db92d234cbebf097e45b5d0 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 10:11:26 +0100 Subject: [PATCH 086/203] r/mssql_server_vulnerability_assessment: fixing tests --- ...ql_server_vulnerability_assessment_test.go | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment_test.go b/azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment_test.go index 0cfe6834e82b..165a42b04332 100644 --- a/azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment_test.go +++ b/azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment_test.go @@ -2,6 +2,7 @@ package mssql import ( "fmt" + "net/http" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -20,7 +21,7 @@ func TestAccAzureRMMssqlServerVulnerabilityAssessment_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountSqlServerDestroy, + CheckDestroy: testCheckAzureRMMssqlServerVulnerabilityAssessmentDestroy, Steps: []resource.TestStep{ { Config: testAccAzureRMMssqlServerVulnerabilityAssessment_basic(ri, acceptance.Location()), @@ -45,7 +46,7 @@ func TestAccAzureRMMssqlServerVulnerabilityAssessment_update(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountSqlServerDestroy, + CheckDestroy: testCheckAzureRMMssqlServerVulnerabilityAssessmentDestroy, Steps: []resource.TestStep{ { Config: testAccAzureRMMssqlServerVulnerabilityAssessment_basic(ri, acceptance.Location()), @@ -110,6 +111,36 @@ func testCheckAzureRMMssqlServerVulnerabilityAssessmentExists(resourceName strin } } +func testCheckAzureRMMssqlServerVulnerabilityAssessmentDestroy(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_mssql_server_vulnerability_assessment" { + continue + } + + id, err := azure.ParseAzureResourceID(rs.Primary.ID) + if err != nil { + return err + } + + resourceGroupName := id.ResourceGroup + serverName := id.Path["servers"] + + client := acceptance.AzureProvider.Meta().(*clients.Client).MSSQL.ServerVulnerabilityAssessmentsClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + result, err := client.Get(ctx, resourceGroupName, serverName) + if err != nil { + return nil + } + + if result.StatusCode != http.StatusNotFound { + return fmt.Errorf("Server Vulnerability Assessment still exists:\n%#v", result.ServerVulnerabilityAssessmentProperties) + } + } + + return nil +} + func testAccAzureRMMssqlServerVulnerabilityAssessment_basic(rInt int, location string) string { server := testAccAzureRMMssqlServerVulnerabilityAssessment_server(rInt, location) From 9b3d13d3f9f54986e088565de7128dece856144b Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 12:37:44 +0100 Subject: [PATCH 087/203] provider: moving the init func --- azurerm/internal/acceptance/client_data.go | 4 +++- azurerm/internal/acceptance/data.go | 12 ++++++++++++ azurerm/internal/provider/provider_test.go | 13 ------------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/azurerm/internal/acceptance/client_data.go b/azurerm/internal/acceptance/client_data.go index 46176d7cc401..cd568b009811 100644 --- a/azurerm/internal/acceptance/client_data.go +++ b/azurerm/internal/acceptance/client_data.go @@ -1,6 +1,8 @@ package acceptance -import "os" +import ( + "os" +) type ClientData struct { // ClientID is the UUID of the Service Principal being used to connect to Azure diff --git a/azurerm/internal/acceptance/data.go b/azurerm/internal/acceptance/data.go index 3fef273094b4..82535c9307ef 100644 --- a/azurerm/internal/acceptance/data.go +++ b/azurerm/internal/acceptance/data.go @@ -6,8 +6,12 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azuread/azuread" "github.com/terraform-providers/terraform-provider-azuread/azuread/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider" ) type TestData struct { @@ -41,6 +45,14 @@ type TestData struct { // BuildTestData generates some test data for the given resource func BuildTestData(t *testing.T, resourceType string, resourceLabel string) TestData { + azureProvider := provider.AzureProvider().(*schema.Provider) + + AzureProvider = azureProvider + SupportedProviders = map[string]terraform.ResourceProvider{ + "azurerm": azureProvider, + "azuread": azuread.Provider().(*schema.Provider), + } + env, err := Environment() if err != nil { t.Fatalf("Error retrieving Environment: %+v", err) diff --git a/azurerm/internal/provider/provider_test.go b/azurerm/internal/provider/provider_test.go index 3cd1eadba3ba..d41e663cfa3a 100644 --- a/azurerm/internal/provider/provider_test.go +++ b/azurerm/internal/provider/provider_test.go @@ -6,21 +6,8 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azuread/azuread" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) -func init() { - azureProvider := AzureProvider().(*schema.Provider) - - acceptance.AzureProvider = azureProvider - acceptance.SupportedProviders = map[string]terraform.ResourceProvider{ - "azurerm": azureProvider, - "azuread": azuread.Provider().(*schema.Provider), - } -} - func TestProvider(t *testing.T) { if err := AzureProvider().(*schema.Provider).InternalValidate(); err != nil { t.Fatalf("err: %s", err) From 9806e33875901a918363ed6e7ffb7d7839dbfb0e Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 13:13:30 +0100 Subject: [PATCH 088/203] resources: moving the tests into their own package ``` $ TF_ACC=1 envchain azurerm go test -v ./azurerm/internal/services/resource/tests/ -run=TestAccAzureRMResourceGroup_basic === RUN TestAccAzureRMResourceGroup_basic === PAUSE TestAccAzureRMResourceGroup_basic === CONT TestAccAzureRMResourceGroup_basic --- PASS: TestAccAzureRMResourceGroup_basic (81.93s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/resource/tests 81.969s ``` --- .../data_source_resource_group_test.go | 51 ----- .../tests/data_source_resource_group_test.go | 47 ++++ .../{ => tests}/data_source_resources_test.go | 68 +++--- .../resource_arm_management_lock_test.go | 201 +++++------------- .../resource_arm_resource_group_test.go | 62 +++--- .../resource_arm_template_deployment_test.go | 109 +++++----- ...e_arm_management_lock.go => validation.go} | 0 .../services/resource/validation_test.go | 34 +++ 8 files changed, 256 insertions(+), 316 deletions(-) delete mode 100644 azurerm/internal/services/resource/data_source_resource_group_test.go create mode 100644 azurerm/internal/services/resource/tests/data_source_resource_group_test.go rename azurerm/internal/services/resource/{ => tests}/data_source_resources_test.go (51%) rename azurerm/internal/services/resource/{ => tests}/resource_arm_management_lock_test.go (65%) rename azurerm/internal/services/resource/{ => tests}/resource_arm_resource_group_test.go (72%) rename azurerm/internal/services/resource/{ => tests}/resource_arm_template_deployment_test.go (86%) rename azurerm/internal/services/resource/{resource_arm_management_lock.go => validation.go} (100%) create mode 100644 azurerm/internal/services/resource/validation_test.go diff --git a/azurerm/internal/services/resource/data_source_resource_group_test.go b/azurerm/internal/services/resource/data_source_resource_group_test.go deleted file mode 100644 index c6bd34d47985..000000000000 --- a/azurerm/internal/services/resource/data_source_resource_group_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package resource - -import ( - "testing" - - "fmt" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMResourceGroup_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - name := fmt.Sprintf("acctestRg_%d", ri) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMResourceGroupBasic(name, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.azurerm_resource_group.test", "name", name), - resource.TestCheckResourceAttr("data.azurerm_resource_group.test", "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr("data.azurerm_resource_group.test", "tags.%", "1"), - resource.TestCheckResourceAttr("data.azurerm_resource_group.test", "tags.env", "test"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMResourceGroupBasic(name string, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "%s" - location = "%s" - - tags = { - env = "test" - } -} - -data "azurerm_resource_group" "test" { - name = "${azurerm_resource_group.test.name}" -} -`, name, location) -} diff --git a/azurerm/internal/services/resource/tests/data_source_resource_group_test.go b/azurerm/internal/services/resource/tests/data_source_resource_group_test.go new file mode 100644 index 000000000000..850a17354db8 --- /dev/null +++ b/azurerm/internal/services/resource/tests/data_source_resource_group_test.go @@ -0,0 +1,47 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMResourceGroup_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_resource_group", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMResourceGroupBasic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctestRg-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMResourceGroupBasic(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRg-%d" + location = "%s" + + tags = { + env = "test" + } +} + +data "azurerm_resource_group" "test" { + name = "${azurerm_resource_group.test.name}" +} +`, data.RandomInteger, data.Locations.Primary) +} diff --git a/azurerm/internal/services/resource/data_source_resources_test.go b/azurerm/internal/services/resource/tests/data_source_resources_test.go similarity index 51% rename from azurerm/internal/services/resource/data_source_resources_test.go rename to azurerm/internal/services/resource/tests/data_source_resources_test.go index 6e1bdb678ab2..46515e17e182 100644 --- a/azurerm/internal/services/resource/data_source_resources_test.go +++ b/azurerm/internal/services/resource/tests/data_source_resources_test.go @@ -1,32 +1,27 @@ -package resource +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMResources_ByName(t *testing.T) { - dataSourceName := "data.azurerm_resources.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_resources", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMResources_template(ri, rs, location), + Config: testAccDataSourceAzureRMResources_template(data), }, { - Config: testAccDataSourceAzureRMResources_ByName(ri, rs, location), + Config: testAccDataSourceAzureRMResources_ByName(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "resources.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "resources.#", "1"), ), }, }, @@ -34,22 +29,19 @@ func TestAccDataSourceAzureRMResources_ByName(t *testing.T) { } func TestAccDataSourceAzureRMResources_ByResourceGroup(t *testing.T) { - dataSourceName := "data.azurerm_resources.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_resources", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMResources_template(ri, rs, location), + Config: testAccDataSourceAzureRMResources_template(data), }, { - Config: testAccDataSourceAzureRMResources_ByResourceGroup(ri, rs, location), + Config: testAccDataSourceAzureRMResources_ByResourceGroup(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "resources.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "resources.#", "1"), ), }, }, @@ -57,22 +49,19 @@ func TestAccDataSourceAzureRMResources_ByResourceGroup(t *testing.T) { } func TestAccDataSourceAzureRMResources_ByResourceType(t *testing.T) { - dataSourceName := "data.azurerm_resources.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_resources", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMResources_template(ri, rs, location), + Config: testAccDataSourceAzureRMResources_template(data), }, { - Config: testAccDataSourceAzureRMResources_ByResourceType(ri, rs, location), + Config: testAccDataSourceAzureRMResources_ByResourceType(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "resources.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "resources.#", "1"), ), }, }, @@ -80,30 +69,27 @@ func TestAccDataSourceAzureRMResources_ByResourceType(t *testing.T) { } func TestAccDataSourceAzureRMResources_FilteredByTags(t *testing.T) { - dataSourceName := "data.azurerm_resources.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_resources", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMResources_template(ri, rs, location), + Config: testAccDataSourceAzureRMResources_template(data), }, { - Config: testAccDataSourceAzureRMResources_FilteredByTags(ri, rs, location), + Config: testAccDataSourceAzureRMResources_FilteredByTags(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "resources.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "resources.#", "1"), ), }, }, }) } -func testAccDataSourceAzureRMResources_ByName(rInt int, rString string, location string) string { - r := testAccDataSourceAzureRMResources_template(rInt, rString, location) +func testAccDataSourceAzureRMResources_ByName(data acceptance.TestData) string { + r := testAccDataSourceAzureRMResources_template(data) return fmt.Sprintf(` %s @@ -113,8 +99,8 @@ data "azurerm_resources" "test" { `, r) } -func testAccDataSourceAzureRMResources_ByResourceGroup(rInt int, rString string, location string) string { - r := testAccDataSourceAzureRMResources_template(rInt, rString, location) +func testAccDataSourceAzureRMResources_ByResourceGroup(data acceptance.TestData) string { + r := testAccDataSourceAzureRMResources_template(data) return fmt.Sprintf(` %s @@ -124,8 +110,8 @@ data "azurerm_resources" "test" { `, r) } -func testAccDataSourceAzureRMResources_ByResourceType(rInt int, rString string, location string) string { - r := testAccDataSourceAzureRMResources_template(rInt, rString, location) +func testAccDataSourceAzureRMResources_ByResourceType(data acceptance.TestData) string { + r := testAccDataSourceAzureRMResources_template(data) return fmt.Sprintf(` %s @@ -136,8 +122,8 @@ data "azurerm_resources" "test" { `, r) } -func testAccDataSourceAzureRMResources_FilteredByTags(rInt int, rString string, location string) string { - r := testAccDataSourceAzureRMResources_template(rInt, rString, location) +func testAccDataSourceAzureRMResources_FilteredByTags(data acceptance.TestData) string { + r := testAccDataSourceAzureRMResources_template(data) return fmt.Sprintf(` %s @@ -152,7 +138,7 @@ data "azurerm_resources" "test" { `, r) } -func testAccDataSourceAzureRMResources_template(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMResources_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" @@ -171,5 +157,5 @@ resource "azurerm_storage_account" "test" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/resource/resource_arm_management_lock_test.go b/azurerm/internal/services/resource/tests/resource_arm_management_lock_test.go similarity index 65% rename from azurerm/internal/services/resource/resource_arm_management_lock_test.go rename to azurerm/internal/services/resource/tests/resource_arm_management_lock_test.go index 0135192abfcd..7359d06e4585 100644 --- a/azurerm/internal/services/resource/resource_arm_management_lock_test.go +++ b/azurerm/internal/services/resource/tests/resource_arm_management_lock_test.go @@ -1,53 +1,20 @@ -package resource +package tests import ( "fmt" - "testing" - "os" + "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestValidateManagementLockName(t *testing.T) { - str := acctest.RandString(259) - testCases := []struct { - input string - shouldError bool - }{ - {"ab", false}, - {"ABC", false}, - {"abc", false}, - {"abc123ABC", false}, - {"123abcABC", false}, - {"ABC123abc", false}, - {"abc-123", false}, - {"abc_123", false}, - {str, false}, - {str + "h", true}, - } - - for _, test := range testCases { - _, es := validateArmManagementLockName(test.input, "name") - - if test.shouldError && len(es) == 0 { - t.Fatalf("Expected validating name %q to fail", test.input) - } - } -} - func TestAccAzureRMManagementLock_resourceGroupReadOnlyBasic(t *testing.T) { - resourceName := "azurerm_management_lock.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMManagementLock_resourceGroupReadOnlyBasic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_management_lock", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,16 +22,12 @@ func TestAccAzureRMManagementLock_resourceGroupReadOnlyBasic(t *testing.T) { CheckDestroy: testCheckAzureRMManagementLockDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMManagementLock_resourceGroupReadOnlyBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementLockExists(resourceName), + testCheckAzureRMManagementLockExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -75,9 +38,7 @@ func TestAccAzureRMManagementLock_requiresImport(t *testing.T) { return } - resourceName := "azurerm_management_lock.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_management_lock", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -85,24 +46,18 @@ func TestAccAzureRMManagementLock_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMManagementLockDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagementLock_resourceGroupReadOnlyBasic(ri, location), + Config: testAccAzureRMManagementLock_resourceGroupReadOnlyBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementLockExists(resourceName), + testCheckAzureRMManagementLockExists(data.ResourceName), ), }, - { - Config: testAccAzureRMManagementLock_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_management_lock"), - }, + data.RequiresImportErrorStep(testAccAzureRMManagementLock_requiresImport), }, }) } func TestAccAzureRMManagementLock_resourceGroupReadOnlyComplete(t *testing.T) { - resourceName := "azurerm_management_lock.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMManagementLock_resourceGroupReadOnlyComplete(ri, location) + data := acceptance.BuildTestData(t, "azurerm_management_lock", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -110,25 +65,18 @@ func TestAccAzureRMManagementLock_resourceGroupReadOnlyComplete(t *testing.T) { CheckDestroy: testCheckAzureRMManagementLockDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMManagementLock_resourceGroupReadOnlyComplete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementLockExists(resourceName), + testCheckAzureRMManagementLockExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMManagementLock_resourceGroupCanNotDeleteBasic(t *testing.T) { - resourceName := "azurerm_management_lock.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMManagementLock_resourceGroupCanNotDeleteBasic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_management_lock", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -136,25 +84,18 @@ func TestAccAzureRMManagementLock_resourceGroupCanNotDeleteBasic(t *testing.T) { CheckDestroy: testCheckAzureRMManagementLockDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMManagementLock_resourceGroupCanNotDeleteBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementLockExists(resourceName), + testCheckAzureRMManagementLockExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMManagementLock_resourceGroupCanNotDeleteComplete(t *testing.T) { - resourceName := "azurerm_management_lock.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMManagementLock_resourceGroupCanNotDeleteComplete(ri, location) + data := acceptance.BuildTestData(t, "azurerm_management_lock", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -162,25 +103,18 @@ func TestAccAzureRMManagementLock_resourceGroupCanNotDeleteComplete(t *testing.T CheckDestroy: testCheckAzureRMManagementLockDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMManagementLock_resourceGroupCanNotDeleteComplete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementLockExists(resourceName), + testCheckAzureRMManagementLockExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMManagementLock_publicIPReadOnlyBasic(t *testing.T) { - resourceName := "azurerm_management_lock.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMManagementLock_publicIPReadOnlyBasic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_management_lock", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -188,25 +122,18 @@ func TestAccAzureRMManagementLock_publicIPReadOnlyBasic(t *testing.T) { CheckDestroy: testCheckAzureRMManagementLockDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMManagementLock_publicIPReadOnlyBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementLockExists(resourceName), + testCheckAzureRMManagementLockExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMManagementLock_publicIPCanNotDeleteBasic(t *testing.T) { - resourceName := "azurerm_management_lock.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMManagementLock_publicIPCanNotDeleteBasic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_management_lock", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -214,16 +141,12 @@ func TestAccAzureRMManagementLock_publicIPCanNotDeleteBasic(t *testing.T) { CheckDestroy: testCheckAzureRMManagementLockDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMManagementLock_publicIPCanNotDeleteBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementLockExists(resourceName), + testCheckAzureRMManagementLockExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -234,9 +157,7 @@ func TestAccAzureRMManagementLock_subscriptionReadOnlyBasic(t *testing.T) { t.Skip("`TF_ACC_SUBSCRIPTION_PARALLEL_LOCK` isn't specified - skipping since this test can't be run in Parallel") } - resourceName := "azurerm_management_lock.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMManagementLock_subscriptionReadOnlyBasic(ri) + data := acceptance.BuildTestData(t, "azurerm_management_lock", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -244,16 +165,12 @@ func TestAccAzureRMManagementLock_subscriptionReadOnlyBasic(t *testing.T) { CheckDestroy: testCheckAzureRMManagementLockDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMManagementLock_subscriptionReadOnlyBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementLockExists(resourceName), + testCheckAzureRMManagementLockExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -264,9 +181,7 @@ func TestAccAzureRMManagementLock_subscriptionCanNotDeleteBasic(t *testing.T) { t.Skip("`TF_ACC_SUBSCRIPTION_PARALLEL_LOCK` isn't specified - skipping since this test can't be run in Parallel") } - resourceName := "azurerm_management_lock.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMManagementLock_subscriptionCanNotDeleteBasic(ri) + data := acceptance.BuildTestData(t, "azurerm_management_lock", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -274,16 +189,12 @@ func TestAccAzureRMManagementLock_subscriptionCanNotDeleteBasic(t *testing.T) { CheckDestroy: testCheckAzureRMManagementLockDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMManagementLock_subscriptionCanNotDeleteBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementLockExists(resourceName), + testCheckAzureRMManagementLockExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -341,7 +252,7 @@ func testCheckAzureRMManagementLockDestroy(s *terraform.State) error { return nil } -func testAccAzureRMManagementLock_resourceGroupReadOnlyBasic(rInt int, location string) string { +func testAccAzureRMManagementLock_resourceGroupReadOnlyBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -353,11 +264,11 @@ resource "azurerm_management_lock" "test" { scope = "${azurerm_resource_group.test.id}" lock_level = "ReadOnly" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagementLock_requiresImport(rInt int, location string) string { - template := testAccAzureRMManagementLock_resourceGroupReadOnlyBasic(rInt, location) +func testAccAzureRMManagementLock_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMManagementLock_resourceGroupReadOnlyBasic(data) return fmt.Sprintf(` %s @@ -369,7 +280,7 @@ resource "azurerm_management_lock" "import" { `, template) } -func testAccAzureRMManagementLock_resourceGroupReadOnlyComplete(rInt int, location string) string { +func testAccAzureRMManagementLock_resourceGroupReadOnlyComplete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -382,10 +293,10 @@ resource "azurerm_management_lock" "test" { lock_level = "ReadOnly" notes = "Hello, World!" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagementLock_resourceGroupCanNotDeleteBasic(rInt int, location string) string { +func testAccAzureRMManagementLock_resourceGroupCanNotDeleteBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -397,10 +308,10 @@ resource "azurerm_management_lock" "test" { scope = "${azurerm_resource_group.test.id}" lock_level = "CanNotDelete" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagementLock_resourceGroupCanNotDeleteComplete(rInt int, location string) string { +func testAccAzureRMManagementLock_resourceGroupCanNotDeleteComplete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -413,10 +324,10 @@ resource "azurerm_management_lock" "test" { lock_level = "CanNotDelete" notes = "Hello, World!" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagementLock_publicIPReadOnlyBasic(rInt int, location string) string { +func testAccAzureRMManagementLock_publicIPReadOnlyBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -436,10 +347,10 @@ resource "azurerm_management_lock" "test" { scope = "${azurerm_public_ip.test.id}" lock_level = "ReadOnly" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMManagementLock_publicIPCanNotDeleteBasic(rInt int, location string) string { +func testAccAzureRMManagementLock_publicIPCanNotDeleteBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -459,10 +370,10 @@ resource "azurerm_management_lock" "test" { scope = "${azurerm_public_ip.test.id}" lock_level = "CanNotDelete" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMManagementLock_subscriptionReadOnlyBasic(rInt int) string { +func testAccAzureRMManagementLock_subscriptionReadOnlyBasic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_subscription" "current" {} @@ -471,10 +382,10 @@ resource "azurerm_management_lock" "test" { scope = "${data.azurerm_subscription.current.id}" lock_level = "ReadOnly" } -`, rInt) +`, data.RandomInteger) } -func testAccAzureRMManagementLock_subscriptionCanNotDeleteBasic(rInt int) string { +func testAccAzureRMManagementLock_subscriptionCanNotDeleteBasic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_subscription" "current" {} @@ -483,5 +394,5 @@ resource "azurerm_management_lock" "test" { scope = "${data.azurerm_subscription.current.id}" lock_level = "CanNotDelete" } -`, rInt) +`, data.RandomInteger) } diff --git a/azurerm/internal/services/resource/resource_arm_resource_group_test.go b/azurerm/internal/services/resource/tests/resource_arm_resource_group_test.go similarity index 72% rename from azurerm/internal/services/resource/resource_arm_resource_group_test.go rename to azurerm/internal/services/resource/tests/resource_arm_resource_group_test.go index 8ba7ab541f93..e569eecac851 100644 --- a/azurerm/internal/services/resource/resource_arm_resource_group_test.go +++ b/azurerm/internal/services/resource/tests/resource_arm_resource_group_test.go @@ -1,4 +1,4 @@ -package resource +package tests import ( "fmt" @@ -13,7 +13,7 @@ import ( ) func TestAccAzureRMResourceGroup_basic(t *testing.T) { - testData := acceptance.BuildTestData(t, "azurerm_resource_group", "test") + data := acceptance.BuildTestData(t, "azurerm_resource_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,12 +21,12 @@ func TestAccAzureRMResourceGroup_basic(t *testing.T) { CheckDestroy: testCheckAzureRMResourceGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMResourceGroup_basic(testData), + Config: testAccAzureRMResourceGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMResourceGroupExists(testData.ResourceName), + testCheckAzureRMResourceGroupExists(data.ResourceName), ), }, - testData.ImportStep(), + data.ImportStep(), }, }) } @@ -37,7 +37,7 @@ func TestAccAzureRMResourceGroup_requiresImport(t *testing.T) { return } - testData := acceptance.BuildTestData(t, "azurerm_resource_group", "test") + data := acceptance.BuildTestData(t, "azurerm_resource_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -45,25 +45,25 @@ func TestAccAzureRMResourceGroup_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMResourceGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMResourceGroup_basic(testData), + Config: testAccAzureRMResourceGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMResourceGroupExists(testData.ResourceName), + testCheckAzureRMResourceGroupExists(data.ResourceName), ), }, - testData.RequiresImportErrorStep(testAccAzureRMResourceGroup_requiresImport), + data.RequiresImportErrorStep(testAccAzureRMResourceGroup_requiresImport), }, }) } func TestAccAzureRMResourceGroup_disappears(t *testing.T) { - testData := acceptance.BuildTestData(t, "azurerm_resource_group", "test") + data := acceptance.BuildTestData(t, "azurerm_resource_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMResourceGroupDestroy, Steps: []resource.TestStep{ - testData.DisappearsStep(acceptance.DisappearsStepData{ + data.DisappearsStep(acceptance.DisappearsStepData{ Config: testAccAzureRMResourceGroup_basic, CheckExists: testCheckAzureRMResourceGroupExists, Destroy: testCheckAzureRMResourceGroupDisappears, @@ -73,7 +73,7 @@ func TestAccAzureRMResourceGroup_disappears(t *testing.T) { } func TestAccAzureRMResourceGroup_withTags(t *testing.T) { - testData := acceptance.BuildTestData(t, "azurerm_resource_group", "test") + data := acceptance.BuildTestData(t, "azurerm_resource_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,24 +81,24 @@ func TestAccAzureRMResourceGroup_withTags(t *testing.T) { CheckDestroy: testCheckAzureRMResourceGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMResourceGroup_withTags(testData), + Config: testAccAzureRMResourceGroup_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMResourceGroupExists(testData.ResourceName), - resource.TestCheckResourceAttr(testData.ResourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(testData.ResourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(testData.ResourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMResourceGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, - testData.ImportStep(), + data.ImportStep(), { - Config: testAccAzureRMResourceGroup_withTagsUpdated(testData), + Config: testAccAzureRMResourceGroup_withTagsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMResourceGroupExists(testData.ResourceName), - resource.TestCheckResourceAttr(testData.ResourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(testData.ResourceName, "tags.environment", "staging"), + testCheckAzureRMResourceGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, - testData.ImportStep(), + data.ImportStep(), }, }) } @@ -182,17 +182,17 @@ func testCheckAzureRMResourceGroupDestroy(s *terraform.State) error { return nil } -func testAccAzureRMResourceGroup_basic(testData acceptance.TestData) string { +func testAccAzureRMResourceGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" location = "%s" } -`, testData.RandomInteger, testData.Locations.Primary) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMResourceGroup_requiresImport(testData acceptance.TestData) string { - template := testAccAzureRMResourceGroup_basic(testData) +func testAccAzureRMResourceGroup_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMResourceGroup_basic(data) return fmt.Sprintf(` %s @@ -203,7 +203,7 @@ resource "azurerm_resource_group" "import" { `, template) } -func testAccAzureRMResourceGroup_withTags(testData acceptance.TestData) string { +func testAccAzureRMResourceGroup_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -214,10 +214,10 @@ resource "azurerm_resource_group" "test" { cost_center = "MSFT" } } -`, testData.RandomInteger, testData.Locations.Primary) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMResourceGroup_withTagsUpdated(testData acceptance.TestData) string { +func testAccAzureRMResourceGroup_withTagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -227,5 +227,5 @@ resource "azurerm_resource_group" "test" { environment = "staging" } } -`, testData.RandomInteger, testData.Locations.Primary) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/resource/resource_arm_template_deployment_test.go b/azurerm/internal/services/resource/tests/resource_arm_template_deployment_test.go similarity index 86% rename from azurerm/internal/services/resource/resource_arm_template_deployment_test.go rename to azurerm/internal/services/resource/tests/resource_arm_template_deployment_test.go index 12009bd84158..cd8158d3535c 100644 --- a/azurerm/internal/services/resource/resource_arm_template_deployment_test.go +++ b/azurerm/internal/services/resource/tests/resource_arm_template_deployment_test.go @@ -1,23 +1,24 @@ -package resource +package tests import ( "fmt" "log" "net/http" "regexp" + "strconv" "testing" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMTemplateDeployment_basic(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_template_deployment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,21 +26,22 @@ func TestAccAzureRMTemplateDeployment_basic(t *testing.T) { CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTemplateDeployment_basicMultiple(ri, acceptance.Location()), + Config: testAccAzureRMTemplateDeployment_basicMultiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTemplateDeploymentExists("azurerm_template_deployment.test"), + testCheckAzureRMTemplateDeploymentExists(data.ResourceName), ), }, }, }) } + func TestAccAzureRMTemplateDeployment_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") return } - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_template_deployment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -47,21 +49,18 @@ func TestAccAzureRMTemplateDeployment_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTemplateDeployment_basicMultiple(ri, acceptance.Location()), + Config: testAccAzureRMTemplateDeployment_basicMultiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTemplateDeploymentExists("azurerm_template_deployment.test"), + testCheckAzureRMTemplateDeploymentExists(data.ResourceName), ), }, - { - Config: testAccAzureRMTemplateDeployment_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_template_deployment"), - }, + data.RequiresImportErrorStep(testAccAzureRMTemplateDeployment_requiresImport), }, }) } func TestAccAzureRMTemplateDeployment_disappears(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_template_deployment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -69,10 +68,10 @@ func TestAccAzureRMTemplateDeployment_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTemplateDeployment_basicSingle(ri, acceptance.Location()), + Config: testAccAzureRMTemplateDeployment_basicSingle(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTemplateDeploymentExists("azurerm_template_deployment.test"), - testCheckAzureRMTemplateDeploymentDisappears("azurerm_template_deployment.test"), + testCheckAzureRMTemplateDeploymentExists(data.ResourceName), + testCheckAzureRMTemplateDeploymentDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -81,7 +80,7 @@ func TestAccAzureRMTemplateDeployment_disappears(t *testing.T) { } func TestAccAzureRMTemplateDeployment_nestedTemplate(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_template_deployment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -89,9 +88,9 @@ func TestAccAzureRMTemplateDeployment_nestedTemplate(t *testing.T) { CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTemplateDeployment_nestedTemplate(ri, acceptance.Location()), + Config: testAccAzureRMTemplateDeployment_nestedTemplate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTemplateDeploymentExists("azurerm_template_deployment.test"), + testCheckAzureRMTemplateDeploymentExists(data.ResourceName), ), }, }, @@ -99,7 +98,7 @@ func TestAccAzureRMTemplateDeployment_nestedTemplate(t *testing.T) { } func TestAccAzureRMTemplateDeployment_withParams(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_template_deployment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -107,9 +106,9 @@ func TestAccAzureRMTemplateDeployment_withParams(t *testing.T) { CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTemplateDeployment_withParams(ri, acceptance.Location()), + Config: testAccAzureRMTemplateDeployment_withParams(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTemplateDeploymentExists("azurerm_template_deployment.test"), + testCheckAzureRMTemplateDeploymentExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_template_deployment.test", "outputs.testOutput", "Output Value"), ), }, @@ -118,7 +117,7 @@ func TestAccAzureRMTemplateDeployment_withParams(t *testing.T) { } func TestAccAzureRMTemplateDeployment_withParamsBody(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_template_deployment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -126,9 +125,9 @@ func TestAccAzureRMTemplateDeployment_withParamsBody(t *testing.T) { CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMTemplateDeployment_withParamsBody(ri, acceptance.Location()), + Config: testaccAzureRMTemplateDeployment_withParamsBody(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTemplateDeploymentExists("azurerm_template_deployment.test"), + testCheckAzureRMTemplateDeploymentExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_template_deployment.test", "outputs.testOutput", "Output Value"), ), }, @@ -137,7 +136,7 @@ func TestAccAzureRMTemplateDeployment_withParamsBody(t *testing.T) { } func TestAccAzureRMTemplateDeployment_withOutputs(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_template_deployment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -145,9 +144,9 @@ func TestAccAzureRMTemplateDeployment_withOutputs(t *testing.T) { CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTemplateDeployment_withOutputs(ri, acceptance.Location()), + Config: testAccAzureRMTemplateDeployment_withOutputs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTemplateDeploymentExists("azurerm_template_deployment.test"), + testCheckAzureRMTemplateDeploymentExists(data.ResourceName), resource.TestCheckOutput("tfIntOutput", "-123"), resource.TestCheckOutput("tfStringOutput", "Standard_GRS"), @@ -157,7 +156,7 @@ func TestAccAzureRMTemplateDeployment_withOutputs(t *testing.T) { // at a later date these may return the expected 'true' / 'false' and should be changed back resource.TestCheckOutput("tfFalseOutput", "false"), resource.TestCheckOutput("tfTrueOutput", "true"), - resource.TestCheckResourceAttr("azurerm_template_deployment.test", "outputs.stringOutput", "Standard_GRS"), + resource.TestCheckResourceAttr(data.ResourceName, "outputs.stringOutput", "Standard_GRS"), ), }, }, @@ -165,7 +164,7 @@ func TestAccAzureRMTemplateDeployment_withOutputs(t *testing.T) { } func TestAccAzureRMTemplateDeployment_withError(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_template_deployment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -173,7 +172,7 @@ func TestAccAzureRMTemplateDeployment_withError(t *testing.T) { CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTemplateDeployment_withError(ri, acceptance.Location()), + Config: testAccAzureRMTemplateDeployment_withError(data), ExpectError: regexp.MustCompile("Error validating Template for Deployment"), }, }, @@ -237,7 +236,20 @@ func testCheckAzureRMTemplateDeploymentDisappears(resourceName string) resource. Pending: []string{"200"}, Target: []string{"404"}, Timeout: 40 * time.Minute, - Refresh: templateDeploymentStateStatusCodeRefreshFunc(ctx, client, resourceGroup, deploymentName), + Refresh: func() (interface{}, string, error) { + res, err := client.Get(ctx, resourceGroup, deploymentName) + + log.Printf("Retrieving Template Deployment %q (Resource Group %q) returned Status %d", resourceGroup, deploymentName, res.StatusCode) + + if err != nil { + if utils.ResponseWasNotFound(res.Response) { + return res, strconv.Itoa(res.StatusCode), nil + } + return nil, "", fmt.Errorf("Error polling for the status of the Template Deployment %q (RG: %q): %+v", deploymentName, resourceGroup, err) + } + + return res, strconv.Itoa(res.StatusCode), nil + }, } if _, err := stateConf.WaitForState(); err != nil { @@ -274,7 +286,7 @@ func testCheckAzureRMTemplateDeploymentDestroy(s *terraform.State) error { return nil } -func testAccAzureRMTemplateDeployment_basicSingle(rInt int, location string) string { +func testAccAzureRMTemplateDeployment_basicSingle(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -314,10 +326,10 @@ DEPLOY deployment_mode = "Complete" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTemplateDeployment_basicMultiple(rInt int, location string) string { +func testAccAzureRMTemplateDeployment_basicMultiple(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -382,10 +394,11 @@ DEPLOY deployment_mode = "Complete" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMTemplateDeployment_requiresImport(rInt int, location string) string { +func testAccAzureRMTemplateDeployment_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMTemplateDeployment_basicMultiple(data) return fmt.Sprintf(` %s @@ -396,10 +409,10 @@ resource "azurerm_template_deployment" "import" { template_body = "${azurerm_template_deployment.test.template_body}" deployment_mode = "${azurerm_template_deployment.test.deployment_mode}" } -`, testAccAzureRMTemplateDeployment_basicMultiple(rInt, location)) +`, template) } -func testAccAzureRMTemplateDeployment_nestedTemplate(rInt int, location string) string { +func testAccAzureRMTemplateDeployment_nestedTemplate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -455,10 +468,10 @@ DEPLOY deployment_mode = "Complete" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testaccAzureRMTemplateDeployment_withParamsBody(rInt int, location string) string { +func testaccAzureRMTemplateDeployment_withParamsBody(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -605,10 +618,10 @@ DEPLOY deployment_mode = "Incremental" depends_on = ["azurerm_key_vault_secret.test-secret"] } -`, rInt, location, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTemplateDeployment_withParams(rInt int, location string) string { +func testAccAzureRMTemplateDeployment_withParams(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -704,10 +717,10 @@ DEPLOY deployment_mode = "Complete" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTemplateDeployment_withOutputs(rInt int, location string) string { +func testAccAzureRMTemplateDeployment_withOutputs(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -828,11 +841,11 @@ DEPLOY deployment_mode = "Incremental" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } // StorageAccount name is too long, forces error -func testAccAzureRMTemplateDeployment_withError(rInt int, location string) string { +func testAccAzureRMTemplateDeployment_withError(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -896,5 +909,5 @@ DEPLOY deployment_mode = "Complete" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/resource/resource_arm_management_lock.go b/azurerm/internal/services/resource/validation.go similarity index 100% rename from azurerm/internal/services/resource/resource_arm_management_lock.go rename to azurerm/internal/services/resource/validation.go diff --git a/azurerm/internal/services/resource/validation_test.go b/azurerm/internal/services/resource/validation_test.go new file mode 100644 index 000000000000..dfe91f7524b7 --- /dev/null +++ b/azurerm/internal/services/resource/validation_test.go @@ -0,0 +1,34 @@ +package resource + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" +) + +func TestValidateManagementLockName(t *testing.T) { + str := acctest.RandString(259) + testCases := []struct { + input string + shouldError bool + }{ + {"ab", false}, + {"ABC", false}, + {"abc", false}, + {"abc123ABC", false}, + {"123abcABC", false}, + {"ABC123abc", false}, + {"abc-123", false}, + {"abc_123", false}, + {str, false}, + {str + "h", true}, + } + + for _, test := range testCases { + _, es := validateArmManagementLockName(test.input, "name") + + if test.shouldError && len(es) == 0 { + t.Fatalf("Expected validating name %q to fail", test.input) + } + } +} From 3817b9f1c706803eb20b87a57c1f5e5131387ce1 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 17:22:29 +0100 Subject: [PATCH 089/203] web: updating the tests --- .../web/data_source_app_service_test.go | 331 --- ...urce_app_service_certificate_order_test.go | 63 +- ...ata_source_app_service_certificate_test.go | 23 +- .../data_source_app_service_plan_test.go | 93 +- .../web/tests/data_source_app_service_test.go | 310 +++ ...source_arm_app_service_active_slot_test.go | 36 +- ..._arm_app_service_certificate_order_test.go | 153 +- ...source_arm_app_service_certificate_test.go | 68 +- ...pp_service_custom_hostname_binding_test.go | 76 +- .../resource_arm_app_service_plan_test.go | 267 +-- .../resource_arm_app_service_slot_test.go | 1258 +++++------ ...m_app_service_source_control_token_test.go | 20 +- .../resource_arm_app_service_test.go | 1882 ++++++----------- ...ervice_virtual_network_association_test.go | 61 +- .../resource_arm_function_app_test.go | 641 +++--- .../testdata/app_service_certificate.pfx | Bin .../app_service_certificate_nopassword.pfx | Bin .../internal/services/web/validation_test.go | 83 + 18 files changed, 2156 insertions(+), 3209 deletions(-) delete mode 100644 azurerm/internal/services/web/data_source_app_service_test.go rename azurerm/internal/services/web/{ => tests}/data_source_app_service_certificate_order_test.go (52%) rename azurerm/internal/services/web/{ => tests}/data_source_app_service_certificate_test.go (53%) rename azurerm/internal/services/web/{ => tests}/data_source_app_service_plan_test.go (57%) create mode 100644 azurerm/internal/services/web/tests/data_source_app_service_test.go rename azurerm/internal/services/web/{ => tests}/resource_arm_app_service_active_slot_test.go (79%) rename azurerm/internal/services/web/{ => tests}/resource_arm_app_service_certificate_order_test.go (58%) rename azurerm/internal/services/web/{ => tests}/resource_arm_app_service_certificate_test.go (70%) rename azurerm/internal/services/web/{ => tests}/resource_arm_app_service_custom_hostname_binding_test.go (80%) rename azurerm/internal/services/web/{ => tests}/resource_arm_app_service_plan_test.go (61%) rename azurerm/internal/services/web/{ => tests}/resource_arm_app_service_slot_test.go (66%) rename azurerm/internal/services/web/{ => tests}/resource_arm_app_service_source_control_token_test.go (78%) rename azurerm/internal/services/web/{ => tests}/resource_arm_app_service_test.go (60%) rename azurerm/internal/services/web/{ => tests}/resource_arm_app_service_virtual_network_association_test.go (86%) rename azurerm/internal/services/web/{ => tests}/resource_arm_function_app_test.go (67%) rename azurerm/internal/services/web/{ => tests}/testdata/app_service_certificate.pfx (100%) rename azurerm/internal/services/web/{ => tests}/testdata/app_service_certificate_nopassword.pfx (100%) create mode 100644 azurerm/internal/services/web/validation_test.go diff --git a/azurerm/internal/services/web/data_source_app_service_test.go b/azurerm/internal/services/web/data_source_app_service_test.go deleted file mode 100644 index 2308d9b8042e..000000000000 --- a/azurerm/internal/services/web/data_source_app_service_test.go +++ /dev/null @@ -1,331 +0,0 @@ -package web - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMAppService_basic(t *testing.T) { - dataSourceName := "data.azurerm_app_service.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAppService_basic(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "app_service_plan_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "outbound_ip_addresses"), - resource.TestCheckResourceAttrSet(dataSourceName, "possible_outbound_ip_addresses"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMAppService_tags(t *testing.T) { - dataSourceName := "data.azurerm_app_service.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAppService_tags(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.Hello", "World"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMAppService_clientAppAffinityDisabled(t *testing.T) { - dataSourceName := "data.azurerm_app_service.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAppService_clientAffinityDisabled(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "client_affinity_enabled", "false"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMAppService_32Bit(t *testing.T) { - dataSourceName := "data.azurerm_app_service.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAppService_32Bit(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "site_config.0.use_32_bit_worker_process", "true"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMAppService_appSettings(t *testing.T) { - dataSourceName := "data.azurerm_app_service.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAppService_appSettings(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "app_settings.foo", "bar"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMAppService_connectionString(t *testing.T) { - dataSourceName := "data.azurerm_app_service.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAppService_connectionStrings(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "connection_string.0.name", "First"), - resource.TestCheckResourceAttr(dataSourceName, "connection_string.0.value", "first-connection-string"), - resource.TestCheckResourceAttr(dataSourceName, "connection_string.0.type", "Custom"), - resource.TestCheckResourceAttr(dataSourceName, "connection_string.1.name", "Second"), - resource.TestCheckResourceAttr(dataSourceName, "connection_string.1.value", "some-postgresql-connection-string"), - resource.TestCheckResourceAttr(dataSourceName, "connection_string.1.type", "PostgreSQL"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMAppService_ipRestriction(t *testing.T) { - dataSourceName := "data.azurerm_app_service.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAppService_ipRestriction(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10"), - resource.TestCheckResourceAttr(dataSourceName, "site_config.0.ip_restriction.0.subnet_mask", "255.255.255.255"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMAppService_http2Enabled(t *testing.T) { - dataSourceName := "data.azurerm_app_service.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAppService_http2Enabled(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "site_config.0.http2_enabled", "true"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMAppService_minTls(t *testing.T) { - dataSourceName := "data.azurerm_app_service.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAppService_minTls(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "site_config.0.min_tls_version", "1.1"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMAppService_basicWindowsContainer(t *testing.T) { - dataSourceName := "data.azurerm_app_service.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAppService_basicWindowsContainer(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "site_config.0.windows_fx_version", "DOCKER|mcr.microsoft.com/azure-app-service/samples/aspnethelloworld:latest"), - resource.TestCheckResourceAttr(dataSourceName, "app_settings.DOCKER_REGISTRY_SERVER_URL", "https://mcr.microsoft.com"), - ), - }, - }, - }) -} - -func testAccDataSourceAppService_basic(rInt int, location string) string { - config := testAccAzureRMAppService_basic(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_app_service" "test" { - name = "${azurerm_app_service.test.name}" - resource_group_name = "${azurerm_app_service.test.resource_group_name}" -} -`, config) -} - -func testAccDataSourceAppService_tags(rInt int, location string) string { - config := testAccAzureRMAppService_tags(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_app_service" "test" { - name = "${azurerm_app_service.test.name}" - resource_group_name = "${azurerm_app_service.test.resource_group_name}" -} -`, config) -} - -func testAccDataSourceAppService_clientAffinityDisabled(rInt int, location string) string { - config := testAccAzureRMAppService_clientAffinityDisabled(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_app_service" "test" { - name = "${azurerm_app_service.test.name}" - resource_group_name = "${azurerm_app_service.test.resource_group_name}" -} -`, config) -} - -func testAccDataSourceAppService_32Bit(rInt int, location string) string { - config := testAccAzureRMAppService_32Bit(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_app_service" "test" { - name = "${azurerm_app_service.test.name}" - resource_group_name = "${azurerm_app_service.test.resource_group_name}" -} -`, config) -} - -func testAccDataSourceAppService_appSettings(rInt int, location string) string { - config := testAccAzureRMAppService_appSettings(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_app_service" "test" { - name = "${azurerm_app_service.test.name}" - resource_group_name = "${azurerm_app_service.test.resource_group_name}" -} -`, config) -} - -func testAccDataSourceAppService_connectionStrings(rInt int, location string) string { - config := testAccAzureRMAppService_connectionStrings(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_app_service" "test" { - name = "${azurerm_app_service.test.name}" - resource_group_name = "${azurerm_app_service.test.resource_group_name}" -} -`, config) -} - -func testAccDataSourceAppService_ipRestriction(rInt int, location string) string { - config := testAccAzureRMAppService_oneIpRestriction(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_app_service" "test" { - name = "${azurerm_app_service.test.name}" - resource_group_name = "${azurerm_app_service.test.resource_group_name}" -} -`, config) -} - -func testAccDataSourceAppService_http2Enabled(rInt int, location string) string { - config := testAccAzureRMAppService_http2Enabled(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_app_service" "test" { - name = "${azurerm_app_service.test.name}" - resource_group_name = "${azurerm_app_service.test.resource_group_name}" -} -`, config) -} - -func testAccDataSourceAppService_minTls(rInt int, location string) string { - config := testAccAzureRMAppService_minTls(rInt, location, "1.1") - return fmt.Sprintf(` -%s - -data "azurerm_app_service" "test" { - name = "${azurerm_app_service.test.name}" - resource_group_name = "${azurerm_app_service.test.resource_group_name}" -} -`, config) -} - -func testAccDataSourceAppService_basicWindowsContainer(rInt int, location string) string { - config := testAccAzureRMAppService_basicWindowsContainer(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_app_service" "test" { - name = "${azurerm_app_service.test.name}" - resource_group_name = "${azurerm_app_service.test.resource_group_name}" -} -`, config) -} diff --git a/azurerm/internal/services/web/data_source_app_service_certificate_order_test.go b/azurerm/internal/services/web/tests/data_source_app_service_certificate_order_test.go similarity index 52% rename from azurerm/internal/services/web/data_source_app_service_certificate_order_test.go rename to azurerm/internal/services/web/tests/data_source_app_service_certificate_order_test.go index de185e4b2e49..a68129aa3333 100644 --- a/azurerm/internal/services/web/data_source_app_service_certificate_order_test.go +++ b/azurerm/internal/services/web/tests/data_source_app_service_certificate_order_test.go @@ -1,4 +1,4 @@ -package web +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) @@ -16,21 +15,19 @@ func TestAccDataSourceAzureRMAppServiceCertificateOrder_basic(t *testing.T) { return } - dataSourceName := "data.azurerm_app_service_certificate_order.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_app_service_certificate_order", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAppServiceCertificateOrder_basic(rInt, location), + Config: testAccDataSourceAppServiceCertificateOrder_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "csr"), - resource.TestCheckResourceAttrSet(dataSourceName, "domain_verification_token"), - resource.TestCheckResourceAttr(dataSourceName, "distinguished_name", "CN=example.com"), - resource.TestCheckResourceAttr(dataSourceName, "product_type", "Standard"), + resource.TestCheckResourceAttrSet(data.ResourceName, "csr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "domain_verification_token"), + resource.TestCheckResourceAttr(data.ResourceName, "distinguished_name", "CN=example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "product_type", "Standard"), ), }, }, @@ -43,21 +40,19 @@ func TestAccDataSourceAzureRMAppServiceCertificateOrder_wildcard(t *testing.T) { return } - dataSourceName := "data.azurerm_app_service_certificate_order.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_app_service_certificate_order", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAppServiceCertificateOrder_wildcard(rInt, location), + Config: testAccDataSourceAppServiceCertificateOrder_wildcard(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "csr"), - resource.TestCheckResourceAttrSet(dataSourceName, "domain_verification_token"), - resource.TestCheckResourceAttr(dataSourceName, "distinguished_name", "CN=*.example.com"), - resource.TestCheckResourceAttr(dataSourceName, "product_type", "WildCard"), + resource.TestCheckResourceAttrSet(data.ResourceName, "csr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "domain_verification_token"), + resource.TestCheckResourceAttr(data.ResourceName, "distinguished_name", "CN=*.example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "product_type", "WildCard"), ), }, }, @@ -70,32 +65,30 @@ func TestAccDataSourceAzureRMAppServiceCertificateOrder_complete(t *testing.T) { return } - dataSourceName := "data.azurerm_app_service_certificate_order.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_app_service_certificate_order", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAppServiceCertificateOrder_complete(rInt, location), + Config: testAccDataSourceAppServiceCertificateOrder_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "csr"), - resource.TestCheckResourceAttrSet(dataSourceName, "domain_verification_token"), - resource.TestCheckResourceAttr(dataSourceName, "distinguished_name", "CN=example.com"), - resource.TestCheckResourceAttr(dataSourceName, "product_type", "Standard"), - resource.TestCheckResourceAttr(dataSourceName, "validity_in_years", "1"), - resource.TestCheckResourceAttr(dataSourceName, "auto_renew", "false"), - resource.TestCheckResourceAttr(dataSourceName, "key_size", "4096"), + resource.TestCheckResourceAttrSet(data.ResourceName, "csr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "domain_verification_token"), + resource.TestCheckResourceAttr(data.ResourceName, "distinguished_name", "CN=example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "product_type", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "validity_in_years", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_renew", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "key_size", "4096"), ), }, }, }) } -func testAccDataSourceAppServiceCertificateOrder_basic(rInt int, location string) string { - config := testAccAzureRMAppServiceCertificateOrder_basic(rInt, location) +func testAccDataSourceAppServiceCertificateOrder_basic(data acceptance.TestData) string { + config := testAccAzureRMAppServiceCertificateOrder_basic(data) return fmt.Sprintf(` %s @@ -106,8 +99,8 @@ data "azurerm_app_service_certificate_order" "test" { `, config) } -func testAccDataSourceAppServiceCertificateOrder_wildcard(rInt int, location string) string { - config := testAccAzureRMAppServiceCertificateOrder_wildcard(rInt, location) +func testAccDataSourceAppServiceCertificateOrder_wildcard(data acceptance.TestData) string { + config := testAccAzureRMAppServiceCertificateOrder_wildcard(data) return fmt.Sprintf(` %s @@ -118,8 +111,8 @@ data "azurerm_app_service_certificate_order" "test" { `, config) } -func testAccDataSourceAppServiceCertificateOrder_complete(rInt int, location string) string { - config := testAccAzureRMAppServiceCertificateOrder_complete(rInt, location, 4096) +func testAccDataSourceAppServiceCertificateOrder_complete(data acceptance.TestData) string { + config := testAccAzureRMAppServiceCertificateOrder_complete(data, 4096) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/web/data_source_app_service_certificate_test.go b/azurerm/internal/services/web/tests/data_source_app_service_certificate_test.go similarity index 53% rename from azurerm/internal/services/web/data_source_app_service_certificate_test.go rename to azurerm/internal/services/web/tests/data_source_app_service_certificate_test.go index b8ead3924528..580d4d86e51a 100644 --- a/azurerm/internal/services/web/data_source_app_service_certificate_test.go +++ b/azurerm/internal/services/web/tests/data_source_app_service_certificate_test.go @@ -1,18 +1,15 @@ -package web +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMAppServiceCertificate_basic(t *testing.T) { - dataSourceName := "data.azurerm_app_service_certificate.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_app_service_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,21 +17,21 @@ func TestAccDataSourceAzureRMAppServiceCertificate_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMAppServiceCertificate_basic(rInt, location), + Config: testAccDataSourceAzureRMAppServiceCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "id"), - resource.TestCheckResourceAttrSet(dataSourceName, "subject_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "issue_date"), - resource.TestCheckResourceAttrSet(dataSourceName, "expiration_date"), - resource.TestCheckResourceAttrSet(dataSourceName, "thumbprint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subject_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "issue_date"), + resource.TestCheckResourceAttrSet(data.ResourceName, "expiration_date"), + resource.TestCheckResourceAttrSet(data.ResourceName, "thumbprint"), ), }, }, }) } -func testAccDataSourceAzureRMAppServiceCertificate_basic(rInt int, location string) string { - template := testAccAzureRMAppServiceCertificatePfxNoPassword(rInt, location) +func testAccDataSourceAzureRMAppServiceCertificate_basic(data acceptance.TestData) string { + template := testAccAzureRMAppServiceCertificatePfxNoPassword(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/web/data_source_app_service_plan_test.go b/azurerm/internal/services/web/tests/data_source_app_service_plan_test.go similarity index 57% rename from azurerm/internal/services/web/data_source_app_service_plan_test.go rename to azurerm/internal/services/web/tests/data_source_app_service_plan_test.go index 80b350df3435..f55157e01d6d 100644 --- a/azurerm/internal/services/web/data_source_app_service_plan_test.go +++ b/azurerm/internal/services/web/tests/data_source_app_service_plan_test.go @@ -1,35 +1,32 @@ -package web +package tests import ( "fmt" "testing" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccDataSourceAzureRMAppServicePlan_basic(t *testing.T) { - dataSourceName := "data.azurerm_app_service_plan.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAppServicePlan_basic(rInt, location), + Config: testAccDataSourceAppServicePlan_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "Windows"), - resource.TestCheckResourceAttr(dataSourceName, "sku.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.tier", "Basic"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.size", "B1"), - resource.TestCheckResourceAttr(dataSourceName, "properties.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "properties.0.per_site_scaling", "false"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "Windows"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Basic"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.size", "B1"), + resource.TestCheckResourceAttr(data.ResourceName, "properties.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "properties.0.per_site_scaling", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -37,25 +34,23 @@ func TestAccDataSourceAzureRMAppServicePlan_basic(t *testing.T) { } func TestAccDataSourceAzureRMAppServicePlan_complete(t *testing.T) { - dataSourceName := "data.azurerm_app_service_plan.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAppServicePlan_complete(rInt, location), + Config: testAccDataSourceAppServicePlan_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "Windows"), - resource.TestCheckResourceAttr(dataSourceName, "sku.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.tier", "Standard"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.size", "S1"), - resource.TestCheckResourceAttr(dataSourceName, "properties.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "properties.0.per_site_scaling", "true"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "Test"), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "Windows"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.size", "S1"), + resource.TestCheckResourceAttr(data.ResourceName, "properties.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "properties.0.per_site_scaling", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Test"), ), }, }, @@ -63,22 +58,20 @@ func TestAccDataSourceAzureRMAppServicePlan_complete(t *testing.T) { } func TestAccDataSourceAzureRMAppServicePlan_premiumSKU(t *testing.T) { - dataSourceName := "data.azurerm_app_service_plan.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAppServicePlan_premiumSKU(rInt, location), + Config: testAccDataSourceAppServicePlan_premiumSKU(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "elastic"), - resource.TestCheckResourceAttr(dataSourceName, "sku.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.tier", "ElasticPremium"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.size", "EP1"), - resource.TestCheckResourceAttr(dataSourceName, "maximum_elastic_worker_count", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "elastic"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "ElasticPremium"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.size", "EP1"), + resource.TestCheckResourceAttr(data.ResourceName, "maximum_elastic_worker_count", "20"), ), }, }, @@ -86,29 +79,27 @@ func TestAccDataSourceAzureRMAppServicePlan_premiumSKU(t *testing.T) { } func TestAccDataSourceAzureRMAppServicePlan_basicWindowsContainer(t *testing.T) { - dataSourceName := "data.azurerm_app_service_plan.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAppServicePlan_basicWindowsContainer(rInt, location), + Config: testAccDataSourceAppServicePlan_basicWindowsContainer(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "xenon"), - resource.TestCheckResourceAttr(dataSourceName, "sku.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.tier", "PremiumContainer"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.size", "PC2"), - resource.TestCheckResourceAttr(dataSourceName, "is_xenon", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "xenon"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "PremiumContainer"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.size", "PC2"), + resource.TestCheckResourceAttr(data.ResourceName, "is_xenon", "true"), ), }, }, }) } -func testAccDataSourceAppServicePlan_basic(rInt int, location string) string { +func testAccDataSourceAppServicePlan_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -130,10 +121,10 @@ data "azurerm_app_service_plan" "test" { name = "${azurerm_app_service_plan.test.name}" resource_group_name = "${azurerm_app_service_plan.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceAppServicePlan_complete(rInt int, location string) string { +func testAccDataSourceAppServicePlan_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -164,10 +155,10 @@ data "azurerm_app_service_plan" "test" { name = "${azurerm_app_service_plan.test.name}" resource_group_name = "${azurerm_app_service_plan.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceAppServicePlan_premiumSKU(rInt int, location string) string { +func testAccDataSourceAppServicePlan_premiumSKU(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -199,10 +190,10 @@ data "azurerm_app_service_plan" "test" { name = "${azurerm_app_service_plan.test.name}" resource_group_name = "${azurerm_app_service_plan.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceAppServicePlan_basicWindowsContainer(rInt int, location string) string { +func testAccDataSourceAppServicePlan_basicWindowsContainer(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -226,5 +217,5 @@ data "azurerm_app_service_plan" "test" { name = "${azurerm_app_service_plan.test.name}" resource_group_name = "${azurerm_app_service_plan.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/web/tests/data_source_app_service_test.go b/azurerm/internal/services/web/tests/data_source_app_service_test.go new file mode 100644 index 000000000000..cc22b0e56656 --- /dev/null +++ b/azurerm/internal/services/web/tests/data_source_app_service_test.go @@ -0,0 +1,310 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMAppService_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_app_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAppService_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "app_service_plan_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "outbound_ip_addresses"), + resource.TestCheckResourceAttrSet(data.ResourceName, "possible_outbound_ip_addresses"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMAppService_tags(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_app_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAppService_tags(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMAppService_clientAppAffinityDisabled(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_app_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAppService_clientAffinityDisabled(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "client_affinity_enabled", "false"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMAppService_32Bit(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_app_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAppService_32Bit(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.use_32_bit_worker_process", "true"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMAppService_appSettings(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_app_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAppService_appSettings(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.foo", "bar"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMAppService_connectionString(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_app_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAppService_connectionStrings(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.0.name", "First"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.0.value", "first-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.0.type", "Custom"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.1.name", "Second"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.1.value", "some-postgresql-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.1.type", "PostgreSQL"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMAppService_ipRestriction(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_app_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAppService_ipRestriction(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.subnet_mask", "255.255.255.255"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMAppService_http2Enabled(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_app_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAppService_http2Enabled(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.http2_enabled", "true"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMAppService_minTls(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_app_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAppService_minTls(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.min_tls_version", "1.1"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMAppService_basicWindowsContainer(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_app_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAppService_basicWindowsContainer(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.windows_fx_version", "DOCKER|mcr.microsoft.com/azure-app-service/samples/aspnethelloworld:latest"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.DOCKER_REGISTRY_SERVER_URL", "https://mcr.microsoft.com"), + ), + }, + }, + }) +} + +func testAccDataSourceAppService_basic(data acceptance.TestData) string { + config := testAccAzureRMAppService_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_app_service" "test" { + name = "${azurerm_app_service.test.name}" + resource_group_name = "${azurerm_app_service.test.resource_group_name}" +} +`, config) +} + +func testAccDataSourceAppService_tags(data acceptance.TestData) string { + config := testAccAzureRMAppService_tags(data) + return fmt.Sprintf(` +%s + +data "azurerm_app_service" "test" { + name = "${azurerm_app_service.test.name}" + resource_group_name = "${azurerm_app_service.test.resource_group_name}" +} +`, config) +} + +func testAccDataSourceAppService_clientAffinityDisabled(data acceptance.TestData) string { + config := testAccAzureRMAppService_clientAffinityDisabled(data) + return fmt.Sprintf(` +%s + +data "azurerm_app_service" "test" { + name = "${azurerm_app_service.test.name}" + resource_group_name = "${azurerm_app_service.test.resource_group_name}" +} +`, config) +} + +func testAccDataSourceAppService_32Bit(data acceptance.TestData) string { + config := testAccAzureRMAppService_32Bit(data) + return fmt.Sprintf(` +%s + +data "azurerm_app_service" "test" { + name = "${azurerm_app_service.test.name}" + resource_group_name = "${azurerm_app_service.test.resource_group_name}" +} +`, config) +} + +func testAccDataSourceAppService_appSettings(data acceptance.TestData) string { + config := testAccAzureRMAppService_appSettings(data) + return fmt.Sprintf(` +%s + +data "azurerm_app_service" "test" { + name = "${azurerm_app_service.test.name}" + resource_group_name = "${azurerm_app_service.test.resource_group_name}" +} +`, config) +} + +func testAccDataSourceAppService_connectionStrings(data acceptance.TestData) string { + config := testAccAzureRMAppService_connectionStrings(data) + return fmt.Sprintf(` +%s + +data "azurerm_app_service" "test" { + name = "${azurerm_app_service.test.name}" + resource_group_name = "${azurerm_app_service.test.resource_group_name}" +} +`, config) +} + +func testAccDataSourceAppService_ipRestriction(data acceptance.TestData) string { + config := testAccAzureRMAppService_oneIpRestriction(data) + return fmt.Sprintf(` +%s + +data "azurerm_app_service" "test" { + name = "${azurerm_app_service.test.name}" + resource_group_name = "${azurerm_app_service.test.resource_group_name}" +} +`, config) +} + +func testAccDataSourceAppService_http2Enabled(data acceptance.TestData) string { + config := testAccAzureRMAppService_http2Enabled(data) + return fmt.Sprintf(` +%s + +data "azurerm_app_service" "test" { + name = "${azurerm_app_service.test.name}" + resource_group_name = "${azurerm_app_service.test.resource_group_name}" +} +`, config) +} + +func testAccDataSourceAppService_minTls(data acceptance.TestData) string { + config := testAccAzureRMAppService_minTls(data, "1.1") + return fmt.Sprintf(` +%s + +data "azurerm_app_service" "test" { + name = "${azurerm_app_service.test.name}" + resource_group_name = "${azurerm_app_service.test.resource_group_name}" +} +`, config) +} + +func testAccDataSourceAppService_basicWindowsContainer(data acceptance.TestData) string { + config := testAccAzureRMAppService_basicWindowsContainer(data) + return fmt.Sprintf(` +%s + +data "azurerm_app_service" "test" { + name = "${azurerm_app_service.test.name}" + resource_group_name = "${azurerm_app_service.test.resource_group_name}" +} +`, config) +} diff --git a/azurerm/internal/services/web/resource_arm_app_service_active_slot_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_active_slot_test.go similarity index 79% rename from azurerm/internal/services/web/resource_arm_app_service_active_slot_test.go rename to azurerm/internal/services/web/tests/resource_arm_app_service_active_slot_test.go index d71254480d4b..f62f8020e91e 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_active_slot_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_active_slot_test.go @@ -1,18 +1,15 @@ -package web +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMAppServiceActiveSlot_basic(t *testing.T) { - resourceName := "azurerm_app_service_active_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceActiveSlot_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_active_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,9 +18,9 @@ func TestAccAzureRMAppServiceActiveSlot_basic(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceActiveSlot_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "app_service_slot_name", fmt.Sprintf("acctestASSlot-%d", ri)), + resource.TestCheckResourceAttr(data.ResourceName, "app_service_slot_name", fmt.Sprintf("acctestASSlot-%d", data.RandomInteger)), ), }, }, @@ -31,10 +28,7 @@ func TestAccAzureRMAppServiceActiveSlot_basic(t *testing.T) { } func TestAccAzureRMAppServiceActiveSlot_update(t *testing.T) { - resourceName := "azurerm_app_service_active_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceActiveSlot_update(ri, acceptance.Location()) - config2 := testAccAzureRMAppServiceActiveSlot_updated(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_active_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -43,22 +37,22 @@ func TestAccAzureRMAppServiceActiveSlot_update(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceActiveSlot_update(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "app_service_slot_name", fmt.Sprintf("acctestASSlot-%d", ri)), + resource.TestCheckResourceAttr(data.ResourceName, "app_service_slot_name", fmt.Sprintf("acctestASSlot-%d", data.RandomInteger)), ), }, { - Config: config2, + Config: testAccAzureRMAppServiceActiveSlot_updated(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "app_service_slot_name", fmt.Sprintf("acctestASSlot2-%d", ri)), + resource.TestCheckResourceAttr(data.ResourceName, "app_service_slot_name", fmt.Sprintf("acctestASSlot2-%d", data.RandomInteger)), ), }, }, }) } -func testAccAzureRMAppServiceActiveSlot_basic(rInt int, location string) string { +func testAccAzureRMAppServiceActiveSlot_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -96,10 +90,10 @@ resource "azurerm_app_service_active_slot" "test" { app_service_name = "${azurerm_app_service.test.name}" app_service_slot_name = "${azurerm_app_service_slot.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceActiveSlot_update(rInt int, location string) string { +func testAccAzureRMAppServiceActiveSlot_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -145,10 +139,10 @@ resource "azurerm_app_service_active_slot" "test" { app_service_name = "${azurerm_app_service.test.name}" app_service_slot_name = "${azurerm_app_service_slot.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceActiveSlot_updated(rInt int, location string) string { +func testAccAzureRMAppServiceActiveSlot_updated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -194,5 +188,5 @@ resource "azurerm_app_service_active_slot" "test" { app_service_name = "${azurerm_app_service.test.name}" app_service_slot_name = "${azurerm_app_service_slot.test2.name}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/web/resource_arm_app_service_certificate_order_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_certificate_order_test.go similarity index 58% rename from azurerm/internal/services/web/resource_arm_app_service_certificate_order_test.go rename to azurerm/internal/services/web/tests/resource_arm_app_service_certificate_order_test.go index 1a0dbba6a3a8..f7be8d3df8bc 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_certificate_order_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_certificate_order_test.go @@ -1,4 +1,4 @@ -package web +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -19,10 +18,7 @@ func TestAccAzureRMAppServiceCertificateOrder_basic(t *testing.T) { t.Skip("Skipping as ARM_RUN_TEST_APP_SERVICE_CERTIFICATE is not specified") return } - - resourceName := "azurerm_app_service_certificate_order.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceCertificateOrder_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_certificate_order", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -30,20 +26,16 @@ func TestAccAzureRMAppServiceCertificateOrder_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceCertificateOrderDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceCertificateOrder_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCertificateOrderExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "csr"), - resource.TestCheckResourceAttrSet(resourceName, "domain_verification_token"), - resource.TestCheckResourceAttr(resourceName, "distinguished_name", "CN=example.com"), - resource.TestCheckResourceAttr(resourceName, "product_type", "Standard"), + testCheckAzureRMAppServiceCertificateOrderExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "csr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "domain_verification_token"), + resource.TestCheckResourceAttr(data.ResourceName, "distinguished_name", "CN=example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "product_type", "Standard"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -54,9 +46,7 @@ func TestAccAzureRMAppServiceCertificateOrder_wildcard(t *testing.T) { return } - resourceName := "azurerm_app_service_certificate_order.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceCertificateOrder_wildcard(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_certificate_order", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -64,20 +54,16 @@ func TestAccAzureRMAppServiceCertificateOrder_wildcard(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceCertificateOrderDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceCertificateOrder_wildcard(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCertificateOrderExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "csr"), - resource.TestCheckResourceAttrSet(resourceName, "domain_verification_token"), - resource.TestCheckResourceAttr(resourceName, "distinguished_name", "CN=*.example.com"), - resource.TestCheckResourceAttr(resourceName, "product_type", "WildCard"), + testCheckAzureRMAppServiceCertificateOrderExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "csr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "domain_verification_token"), + resource.TestCheckResourceAttr(data.ResourceName, "distinguished_name", "CN=*.example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "product_type", "WildCard"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -93,25 +79,19 @@ func TestAccAzureRMAppServiceCertificateOrder_requiresImport(t *testing.T) { return } - resourceName := "azurerm_app_service_certificate_order.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_app_service_certificate_order", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceCertificateOrderDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceCertificateOrder_basic(ri, location), + Config: testAccAzureRMAppServiceCertificateOrder_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCertificateOrderExists(resourceName), + testCheckAzureRMAppServiceCertificateOrderExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAppServiceCertificateOrder_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_app_service_certificate_order"), - }, + data.RequiresImportErrorStep(testAccAzureRMAppServiceCertificateOrder_requiresImport), }, }) } @@ -121,10 +101,7 @@ func TestAccAzureRMAppServiceCertificateOrder_complete(t *testing.T) { t.Skip("Skipping as ARM_RUN_TEST_APP_SERVICE_CERTIFICATE is not specified") return } - - resourceName := "azurerm_app_service_certificate_order.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceCertificateOrder_complete(ri, acceptance.Location(), 4096) + data := acceptance.BuildTestData(t, "azurerm_app_service_certificate_order", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -132,23 +109,19 @@ func TestAccAzureRMAppServiceCertificateOrder_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceCertificateOrderDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceCertificateOrder_complete(data, 4096), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCertificateOrderExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "csr"), - resource.TestCheckResourceAttrSet(resourceName, "domain_verification_token"), - resource.TestCheckResourceAttr(resourceName, "distinguished_name", "CN=example.com"), - resource.TestCheckResourceAttr(resourceName, "product_type", "Standard"), - resource.TestCheckResourceAttr(resourceName, "validity_in_years", "1"), - resource.TestCheckResourceAttr(resourceName, "auto_renew", "false"), - resource.TestCheckResourceAttr(resourceName, "key_size", "4096"), + testCheckAzureRMAppServiceCertificateOrderExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "csr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "domain_verification_token"), + resource.TestCheckResourceAttr(data.ResourceName, "distinguished_name", "CN=example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "product_type", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "validity_in_years", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_renew", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "key_size", "4096"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -159,48 +132,42 @@ func TestAccAzureRMAppServiceCertificateOrder_update(t *testing.T) { return } - resourceName := "azurerm_app_service_certificate_order.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_app_service_certificate_order", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceCertificateOrderDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceCertificateOrder_basic(ri, acceptance.Location()), + Config: testAccAzureRMAppServiceCertificateOrder_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCertificateOrderExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "csr"), - resource.TestCheckResourceAttrSet(resourceName, "domain_verification_token"), - resource.TestCheckResourceAttr(resourceName, "distinguished_name", "CN=example.com"), - resource.TestCheckResourceAttr(resourceName, "product_type", "Standard"), + testCheckAzureRMAppServiceCertificateOrderExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "csr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "domain_verification_token"), + resource.TestCheckResourceAttr(data.ResourceName, "distinguished_name", "CN=example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "product_type", "Standard"), ), }, { - Config: testAccAzureRMAppServiceCertificateOrder_complete(ri, acceptance.Location(), 2048), // keySize cannot be updated + Config: testAccAzureRMAppServiceCertificateOrder_complete(data, 2048), // keySize cannot be updated Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCertificateOrderExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "domain_verification_token"), - resource.TestCheckResourceAttr(resourceName, "distinguished_name", "CN=example.com"), - resource.TestCheckResourceAttr(resourceName, "auto_renew", "false"), + testCheckAzureRMAppServiceCertificateOrderExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "domain_verification_token"), + resource.TestCheckResourceAttr(data.ResourceName, "distinguished_name", "CN=example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_renew", "false"), ), }, { - Config: testAccAzureRMAppServiceCertificateOrder_basic(ri, acceptance.Location()), + Config: testAccAzureRMAppServiceCertificateOrder_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCertificateOrderExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "domain_verification_token"), - resource.TestCheckResourceAttr(resourceName, "distinguished_name", "CN=example.com"), - resource.TestCheckResourceAttr(resourceName, "auto_renew", "true"), - resource.TestCheckResourceAttr(resourceName, "key_size", "2048"), + testCheckAzureRMAppServiceCertificateOrderExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "domain_verification_token"), + resource.TestCheckResourceAttr(data.ResourceName, "distinguished_name", "CN=example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_renew", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "key_size", "2048"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -209,7 +176,7 @@ func testCheckAzureRMAppServiceCertificateOrderDestroy(s *terraform.State) error client := acceptance.AzureProvider.Meta().(*clients.Client).Web.CertificatesOrderClient for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_app_service" { + if rs.Type != "azurerm_app_service_certificate_order" { continue } @@ -261,7 +228,7 @@ func testCheckAzureRMAppServiceCertificateOrderExists(resourceName string) resou } } -func testAccAzureRMAppServiceCertificateOrder_basic(rInt int, location string) string { +func testAccAzureRMAppServiceCertificateOrder_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -275,10 +242,10 @@ resource "azurerm_app_service_certificate_order" "test" { distinguished_name = "CN=example.com" product_type = "Standard" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServiceCertificateOrder_wildcard(rInt int, location string) string { +func testAccAzureRMAppServiceCertificateOrder_wildcard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -292,11 +259,11 @@ resource "azurerm_app_service_certificate_order" "test" { distinguished_name = "CN=*.example.com" product_type = "WildCard" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServiceCertificateOrder_requiresImport(rInt int, location string) string { - template := testAccAzureRMAppServiceCertificateOrder_basic(rInt, location) +func testAccAzureRMAppServiceCertificateOrder_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAppServiceCertificateOrder_basic(data) return fmt.Sprintf(` %s @@ -310,7 +277,7 @@ resource "azurerm_app_service_certificate_order" "import" { `, template) } -func testAccAzureRMAppServiceCertificateOrder_complete(rInt int, location string, keySize int) string { +func testAccAzureRMAppServiceCertificateOrder_complete(data acceptance.TestData, keySize int) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -327,5 +294,5 @@ resource "azurerm_app_service_certificate_order" "test" { validity_in_years = 1 key_size = %d } -`, rInt, location, rInt, keySize) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, keySize) } diff --git a/azurerm/internal/services/web/resource_arm_app_service_certificate_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_certificate_test.go similarity index 70% rename from azurerm/internal/services/web/resource_arm_app_service_certificate_test.go rename to azurerm/internal/services/web/tests/resource_arm_app_service_certificate_test.go index 877aeec598ed..813d1cbb809f 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_certificate_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_certificate_test.go @@ -1,4 +1,4 @@ -package web +package tests import ( "fmt" @@ -6,18 +6,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMAppServiceCertificate_Pfx(t *testing.T) { - resourceName := "azurerm_app_service_certificate.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - config := testAccAzureRMAppServiceCertificatePfx(ri, location) + data := acceptance.BuildTestData(t, "azurerm_app_service_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,28 +20,19 @@ func TestAccAzureRMAppServiceCertificate_Pfx(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceCertificateDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceCertificatePfx(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "password", "terraform"), - resource.TestCheckResourceAttr(resourceName, "thumbprint", "7B985BF42467791F23E52B364A3E8DEBAB9C606E"), + resource.TestCheckResourceAttr(data.ResourceName, "password", "terraform"), + resource.TestCheckResourceAttr(data.ResourceName, "thumbprint", "7B985BF42467791F23E52B364A3E8DEBAB9C606E"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"pfx_blob", "password"}, - }, + data.ImportStep("pfx_blob", "password"), }, }) } func TestAccAzureRMAppServiceCertificate_PfxNoPassword(t *testing.T) { - resourceName := "azurerm_app_service_certificate.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - config := testAccAzureRMAppServiceCertificatePfxNoPassword(ri, location) + data := acceptance.BuildTestData(t, "azurerm_app_service_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,27 +40,18 @@ func TestAccAzureRMAppServiceCertificate_PfxNoPassword(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceCertificateDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceCertificatePfxNoPassword(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "thumbprint", "7B985BF42467791F23E52B364A3E8DEBAB9C606E"), + resource.TestCheckResourceAttr(data.ResourceName, "thumbprint", "7B985BF42467791F23E52B364A3E8DEBAB9C606E"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"pfx_blob"}, - }, + data.ImportStep("pfx_blob"), }, }) } func TestAccAzureRMAppServiceCertificate_KeyVault(t *testing.T) { - resourceName := "azurerm_app_service_certificate.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - config := testAccAzureRMAppServiceCertificateKeyVault(ri, location) + data := acceptance.BuildTestData(t, "azurerm_app_service_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,22 +59,17 @@ func TestAccAzureRMAppServiceCertificate_KeyVault(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceCertificateDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceCertificateKeyVault(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "thumbprint", "7B985BF42467791F23E52B364A3E8DEBAB9C606E"), + resource.TestCheckResourceAttr(data.ResourceName, "thumbprint", "7B985BF42467791F23E52B364A3E8DEBAB9C606E"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"key_vault_secret_id"}, - }, + data.ImportStep("key_vault_secret_id"), }, }) } -func testAccAzureRMAppServiceCertificatePfx(rInt int, location string) string { +func testAccAzureRMAppServiceCertificatePfx(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestwebcert%d" @@ -111,10 +83,10 @@ resource "azurerm_app_service_certificate" "test" { pfx_blob = filebase64("testdata/app_service_certificate.pfx") password = "terraform" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServiceCertificatePfxNoPassword(rInt int, location string) string { +func testAccAzureRMAppServiceCertificatePfxNoPassword(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestwebcert%d" @@ -127,10 +99,10 @@ resource "azurerm_app_service_certificate" "test" { location = azurerm_resource_group.test.location pfx_blob = filebase64("testdata/app_service_certificate_nopassword.pfx") } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServiceCertificateKeyVault(rInt int, location string) string { +func testAccAzureRMAppServiceCertificateKeyVault(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "test" {} @@ -200,7 +172,7 @@ resource "azurerm_app_service_certificate" "test" { location = azurerm_resource_group.test.location key_vault_secret_id = azurerm_key_vault_certificate.test.id } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMAppServiceCertificateDestroy(s *terraform.State) error { diff --git a/azurerm/internal/services/web/resource_arm_app_service_custom_hostname_binding_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_custom_hostname_binding_test.go similarity index 80% rename from azurerm/internal/services/web/resource_arm_app_service_custom_hostname_binding_test.go rename to azurerm/internal/services/web/tests/resource_arm_app_service_custom_hostname_binding_test.go index 50eb6a4be27d..eedef845c758 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_custom_hostname_binding_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_custom_hostname_binding_test.go @@ -1,14 +1,12 @@ -package web +package tests import ( "fmt" - "testing" - "os" + "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/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -53,10 +51,7 @@ func TestAccAzureRMAppServiceCustomHostnameBinding(t *testing.T) { } func testAccAzureRMAppServiceCustomHostnameBinding_basic(t *testing.T, appServiceEnv, domainEnv string) { - resourceName := "azurerm_app_service_custom_hostname_binding.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(ri, location, appServiceEnv, domainEnv) + data := acceptance.BuildTestData(t, "azurerm_app_service_custom_hostname_binding", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -64,16 +59,12 @@ func testAccAzureRMAppServiceCustomHostnameBinding_basic(t *testing.T, appServic CheckDestroy: testCheckAzureRMAppServiceCustomHostnameBindingDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(data, appServiceEnv, domainEnv), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCustomHostnameBindingExists(resourceName), + testCheckAzureRMAppServiceCustomHostnameBindingExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -84,9 +75,7 @@ func testAccAzureRMAppServiceCustomHostnameBinding_requiresImport(t *testing.T, return } - resourceName := "azurerm_app_service_custom_hostname_binding.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service_custom_hostname_binding", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -94,15 +83,14 @@ func testAccAzureRMAppServiceCustomHostnameBinding_requiresImport(t *testing.T, CheckDestroy: testCheckAzureRMAppServiceCustomHostnameBindingDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(ri, location, appServiceEnv, domainEnv), + Config: testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(data, appServiceEnv, domainEnv), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCustomHostnameBindingExists(resourceName), + testCheckAzureRMAppServiceCustomHostnameBindingExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAppServiceCustomHostnameBinding_requiresImportConfig(ri, location, appServiceEnv, domainEnv), - ExpectError: acceptance.RequiresImportError("azurerm_app_service_custom_hostname_binding"), - }, + data.RequiresImportErrorStep(func(data acceptance.TestData) string { + return testAccAzureRMAppServiceCustomHostnameBinding_requiresImportConfig(data, appServiceEnv, domainEnv) + }), }, }) } @@ -114,10 +102,7 @@ func testAccAzureRMAppServiceCustomHostnameBinding_multiple(t *testing.T, appSer t.Skipf("Skipping as %q is not specified", altDomainEnvVariable) } - resourceName := "azurerm_app_service_custom_hostname_binding.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMAppServiceCustomHostnameBinding_multipleConfig(ri, location, appServiceEnv, domainEnv, altDomainEnv) + data := acceptance.BuildTestData(t, "azurerm_app_service_custom_hostname_binding", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -125,9 +110,9 @@ func testAccAzureRMAppServiceCustomHostnameBinding_multiple(t *testing.T, appSer CheckDestroy: testCheckAzureRMAppServiceCustomHostnameBindingDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceCustomHostnameBinding_multipleConfig(data, appServiceEnv, domainEnv, altDomainEnv), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCustomHostnameBindingExists(resourceName), + testCheckAzureRMAppServiceCustomHostnameBindingExists(data.ResourceName), ), }, }, @@ -135,10 +120,7 @@ func testAccAzureRMAppServiceCustomHostnameBinding_multiple(t *testing.T, appSer } func testAccAzureRMAppServiceCustomHostnameBinding_ssl(t *testing.T, appServiceEnv, domainEnv string) { - resourceName := "azurerm_app_service_custom_hostname_binding.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMAppServiceCustomHostnameBinding_sslConfig(ri, location, appServiceEnv, domainEnv) + data := acceptance.BuildTestData(t, "azurerm_app_service_custom_hostname_binding", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -146,16 +128,12 @@ func testAccAzureRMAppServiceCustomHostnameBinding_ssl(t *testing.T, appServiceE CheckDestroy: testCheckAzureRMAppServiceCustomHostnameBindingDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceCustomHostnameBinding_sslConfig(data, appServiceEnv, domainEnv), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceCustomHostnameBindingExists(resourceName), + testCheckAzureRMAppServiceCustomHostnameBindingExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -215,7 +193,7 @@ func testCheckAzureRMAppServiceCustomHostnameBindingExists(resourceName string) } } -func testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(rInt int, location string, appServiceName string, domain string) string { +func testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(data acceptance.TestData, appServiceName string, domain string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -245,11 +223,11 @@ resource "azurerm_app_service_custom_hostname_binding" "test" { app_service_name = "${azurerm_app_service.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, appServiceName, domain) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, appServiceName, domain) } -func testAccAzureRMAppServiceCustomHostnameBinding_requiresImportConfig(rInt int, location string, appServiceName string, domain string) string { - template := testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(rInt, location, appServiceName, domain) +func testAccAzureRMAppServiceCustomHostnameBinding_requiresImportConfig(data acceptance.TestData, appServiceName string, domain string) string { + template := testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(data, appServiceName, domain) return fmt.Sprintf(` %s @@ -261,8 +239,8 @@ resource "azurerm_app_service_custom_hostname_binding" "import" { `, template) } -func testAccAzureRMAppServiceCustomHostnameBinding_multipleConfig(rInt int, location, appServiceName, domain, altDomain string) string { - template := testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(rInt, location, appServiceName, domain) +func testAccAzureRMAppServiceCustomHostnameBinding_multipleConfig(data acceptance.TestData, appServiceName, domain, altDomain string) string { + template := testAccAzureRMAppServiceCustomHostnameBinding_basicConfig(data, appServiceName, domain) return fmt.Sprintf(` %s @@ -274,7 +252,7 @@ resource "azurerm_app_service_custom_hostname_binding" "test2" { `, template, altDomain) } -func testAccAzureRMAppServiceCustomHostnameBinding_sslConfig(rInt int, location, appServiceName, domain string) string { +func testAccAzureRMAppServiceCustomHostnameBinding_sslConfig(data acceptance.TestData, appServiceName, domain string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -369,5 +347,5 @@ resource "azurerm_app_service_custom_hostname_binding" "test" { ssl_state = "SniEnabled" thumbprint = "${azurerm_app_service_certificate.test.thumbprint}" } -`, rInt, location, rInt, appServiceName, rInt, rInt, domain, rInt, domain) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, appServiceName, data.RandomInteger, data.RandomInteger, domain, data.RandomInteger, domain) } diff --git a/azurerm/internal/services/web/resource_arm_app_service_plan_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_plan_test.go similarity index 61% rename from azurerm/internal/services/web/resource_arm_app_service_plan_test.go rename to azurerm/internal/services/web/tests/resource_arm_app_service_plan_test.go index 4a4bf53b0643..0934a2cd280d 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_plan_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_plan_test.go @@ -1,4 +1,4 @@ -package web +package tests import ( "fmt" @@ -6,56 +6,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAzureRMAppServicePlanName_validation(t *testing.T) { - cases := []struct { - Value string - ErrCount int - }{ - { - Value: "ab", - ErrCount: 0, - }, - { - Value: "abc", - ErrCount: 0, - }, - { - Value: "webapp1", - ErrCount: 0, - }, - { - Value: "hello-world", - ErrCount: 0, - }, - { - Value: "hello_world", - ErrCount: 0, - }, - { - Value: "helloworld21!", - ErrCount: 1, - }, - } - - for _, tc := range cases { - _, errors := validateAppServicePlanName(tc.Value, "azurerm_app_service_plan") - - if len(errors) != tc.ErrCount { - t.Fatalf("Expected the App Service Plan Name to trigger a validation error for '%s'", tc.Value) - } - } -} - func TestAccAzureRMAppServicePlan_basicWindows(t *testing.T) { - resourceName := "azurerm_app_service_plan.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -63,25 +21,21 @@ func TestAccAzureRMAppServicePlan_basicWindows(t *testing.T) { CheckDestroy: testCheckAzureRMAppServicePlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServicePlan_basicWindows(ri, acceptance.Location()), + Config: testAccAzureRMAppServicePlan_basicWindows(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "per_site_scaling", "false"), - resource.TestCheckResourceAttr(resourceName, "reserved", "false"), + testCheckAzureRMAppServicePlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "per_site_scaling", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "reserved", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServicePlan_basicLinux(t *testing.T) { - resourceName := "azurerm_app_service_plan.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -89,24 +43,21 @@ func TestAccAzureRMAppServicePlan_basicLinux(t *testing.T) { CheckDestroy: testCheckAzureRMAppServicePlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServicePlan_basicLinux(ri, acceptance.Location()), + Config: testAccAzureRMAppServicePlan_basicLinux(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), + testCheckAzureRMAppServicePlanExists(data.ResourceName), ), }, { - Config: testAccAzureRMAppServicePlan_basicLinuxNew(ri, acceptance.Location()), + Config: testAccAzureRMAppServicePlan_basicLinuxNew(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "per_site_scaling", "false"), - resource.TestCheckResourceAttr(resourceName, "reserved", "true"), + testCheckAzureRMAppServicePlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "per_site_scaling", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "reserved", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } @@ -116,10 +67,7 @@ func TestAccAzureRMAppServicePlan_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_app_service_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -127,22 +75,18 @@ func TestAccAzureRMAppServicePlan_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAppServicePlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServicePlan_basicLinux(ri, location), + Config: testAccAzureRMAppServicePlan_basicLinux(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), + testCheckAzureRMAppServicePlanExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAppServicePlan_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_app_service_plan"), - }, + data.RequiresImportErrorStep(testAccAzureRMAppServicePlan_requiresImport), }, }) } func TestAccAzureRMAppServicePlan_standardWindows(t *testing.T) { - resourceName := "azurerm_app_service_plan.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -150,23 +94,19 @@ func TestAccAzureRMAppServicePlan_standardWindows(t *testing.T) { CheckDestroy: testCheckAzureRMAppServicePlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServicePlan_standardWindows(ri, acceptance.Location()), + Config: testAccAzureRMAppServicePlan_standardWindows(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), + testCheckAzureRMAppServicePlanExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServicePlan_premiumWindows(t *testing.T) { - resourceName := "azurerm_app_service_plan.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,24 +114,19 @@ func TestAccAzureRMAppServicePlan_premiumWindows(t *testing.T) { CheckDestroy: testCheckAzureRMAppServicePlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServicePlan_premiumWindows(ri, acceptance.Location()), + Config: testAccAzureRMAppServicePlan_premiumWindows(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), + testCheckAzureRMAppServicePlanExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServicePlan_premiumWindowsUpdated(t *testing.T) { - resourceName := "azurerm_app_service_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -199,31 +134,27 @@ func TestAccAzureRMAppServicePlan_premiumWindowsUpdated(t *testing.T) { CheckDestroy: testCheckAzureRMAppServicePlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServicePlan_premiumWindows(ri, location), + Config: testAccAzureRMAppServicePlan_premiumWindows(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), + testCheckAzureRMAppServicePlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), ), }, { - Config: testAccAzureRMAppServicePlan_premiumWindowsUpdated(ri, location), + Config: testAccAzureRMAppServicePlan_premiumWindowsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "2"), + testCheckAzureRMAppServicePlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServicePlan_completeWindows(t *testing.T) { - resourceName := "azurerm_app_service_plan.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -231,33 +162,29 @@ func TestAccAzureRMAppServicePlan_completeWindows(t *testing.T) { CheckDestroy: testCheckAzureRMAppServicePlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServicePlan_completeWindows(ri, acceptance.Location()), + Config: testAccAzureRMAppServicePlan_completeWindows(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "properties.0.per_site_scaling", "true"), - resource.TestCheckResourceAttr(resourceName, "properties.0.reserved", "false"), + testCheckAzureRMAppServicePlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "properties.0.per_site_scaling", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "properties.0.reserved", "false"), ), }, { - Config: testAccAzureRMAppServicePlan_completeWindowsNew(ri, acceptance.Location()), + Config: testAccAzureRMAppServicePlan_completeWindowsNew(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "per_site_scaling", "true"), - resource.TestCheckResourceAttr(resourceName, "reserved", "false"), + testCheckAzureRMAppServicePlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "per_site_scaling", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "reserved", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServicePlan_consumptionPlan(t *testing.T) { - resourceName := "azurerm_app_service_plan.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -265,11 +192,11 @@ func TestAccAzureRMAppServicePlan_consumptionPlan(t *testing.T) { CheckDestroy: testCheckAzureRMAppServicePlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServicePlan_consumptionPlan(ri, acceptance.Location()), + Config: testAccAzureRMAppServicePlan_consumptionPlan(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Dynamic"), - resource.TestCheckResourceAttr(resourceName, "sku.0.size", "Y1"), + testCheckAzureRMAppServicePlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Dynamic"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.size", "Y1"), ), }, }, @@ -277,8 +204,7 @@ func TestAccAzureRMAppServicePlan_consumptionPlan(t *testing.T) { } func TestAccAzureRMAppServicePlan_premiumConsumptionPlan(t *testing.T) { - resourceName := "azurerm_app_service_plan.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -286,12 +212,12 @@ func TestAccAzureRMAppServicePlan_premiumConsumptionPlan(t *testing.T) { CheckDestroy: testCheckAzureRMAppServicePlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServicePlan_premiumConsumptionPlan(ri, acceptance.Location()), + Config: testAccAzureRMAppServicePlan_premiumConsumptionPlan(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "ElasticPremium"), - resource.TestCheckResourceAttr(resourceName, "sku.0.size", "EP1"), - resource.TestCheckResourceAttr(resourceName, "maximum_elastic_worker_count", "20"), + testCheckAzureRMAppServicePlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "ElasticPremium"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.size", "EP1"), + resource.TestCheckResourceAttr(data.ResourceName, "maximum_elastic_worker_count", "20"), ), }, }, @@ -299,8 +225,7 @@ func TestAccAzureRMAppServicePlan_premiumConsumptionPlan(t *testing.T) { } func TestAccAzureRMAppServicePlan_basicWindowsContainer(t *testing.T) { - resourceName := "azurerm_app_service_plan.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_plan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -308,20 +233,16 @@ func TestAccAzureRMAppServicePlan_basicWindowsContainer(t *testing.T) { CheckDestroy: testCheckAzureRMAppServicePlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServicePlan_basicWindowsContainer(ri, acceptance.Location()), + Config: testAccAzureRMAppServicePlan_basicWindowsContainer(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServicePlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "xenon"), - resource.TestCheckResourceAttr(resourceName, "is_xenon", "true"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "PremiumContainer"), - resource.TestCheckResourceAttr(resourceName, "sku.0.size", "PC2"), + testCheckAzureRMAppServicePlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "xenon"), + resource.TestCheckResourceAttr(data.ResourceName, "is_xenon", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "PremiumContainer"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.size", "PC2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -382,7 +303,7 @@ func testCheckAzureRMAppServicePlanExists(resourceName string) resource.TestChec } } -func testAccAzureRMAppServicePlan_basicWindows(rInt int, location string) string { +func testAccAzureRMAppServicePlan_basicWindows(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -399,10 +320,10 @@ resource "azurerm_app_service_plan" "test" { size = "B1" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServicePlan_basicLinux(rInt int, location string) string { +func testAccAzureRMAppServicePlan_basicLinux(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -422,11 +343,11 @@ resource "azurerm_app_service_plan" "test" { reserved = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServicePlan_requiresImport(rInt int, location string) string { - template := testAccAzureRMAppServicePlan_basicLinux(rInt, location) +func testAccAzureRMAppServicePlan_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAppServicePlan_basicLinux(data) return fmt.Sprintf(` %s @@ -446,7 +367,7 @@ resource "azurerm_app_service_plan" "import" { `, template) } -func testAccAzureRMAppServicePlan_basicLinuxNew(rInt int, location string) string { +func testAccAzureRMAppServicePlan_basicLinuxNew(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -466,10 +387,10 @@ resource "azurerm_app_service_plan" "test" { reserved = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServicePlan_standardWindows(rInt int, location string) string { +func testAccAzureRMAppServicePlan_standardWindows(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -486,10 +407,10 @@ resource "azurerm_app_service_plan" "test" { size = "S1" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServicePlan_premiumWindows(rInt int, location string) string { +func testAccAzureRMAppServicePlan_premiumWindows(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -506,10 +427,10 @@ resource "azurerm_app_service_plan" "test" { size = "P1" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServicePlan_premiumWindowsUpdated(rInt int, location string) string { +func testAccAzureRMAppServicePlan_premiumWindowsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -527,10 +448,10 @@ resource "azurerm_app_service_plan" "test" { capacity = 2 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServicePlan_completeWindows(rInt int, location string) string { +func testAccAzureRMAppServicePlan_completeWindows(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -555,10 +476,10 @@ resource "azurerm_app_service_plan" "test" { environment = "Test" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServicePlan_completeWindowsNew(rInt int, location string) string { +func testAccAzureRMAppServicePlan_completeWindowsNew(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -583,10 +504,10 @@ resource "azurerm_app_service_plan" "test" { environment = "Test" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServicePlan_consumptionPlan(rInt int, location string) string { +func testAccAzureRMAppServicePlan_consumptionPlan(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -604,10 +525,10 @@ resource "azurerm_app_service_plan" "test" { size = "Y1" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServicePlan_premiumConsumptionPlan(rInt int, location string) string { +func testAccAzureRMAppServicePlan_premiumConsumptionPlan(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -627,10 +548,10 @@ resource "azurerm_app_service_plan" "test" { size = "EP1" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAppServicePlan_basicWindowsContainer(rInt int, location string) string { +func testAccAzureRMAppServicePlan_basicWindowsContainer(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -649,5 +570,5 @@ resource "azurerm_app_service_plan" "test" { size = "PC2" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/web/resource_arm_app_service_slot_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_slot_test.go similarity index 66% rename from azurerm/internal/services/web/resource_arm_app_service_slot_test.go rename to azurerm/internal/services/web/tests/resource_arm_app_service_slot_test.go index 9f23adf69ed7..bbe647954940 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_slot_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_slot_test.go @@ -1,4 +1,4 @@ -package web +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" @@ -17,26 +16,19 @@ import ( ) func TestAccAzureRMAppServiceSlot_basic(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,9 +39,7 @@ func TestAccAzureRMAppServiceSlot_requiresImport(t *testing.T) { return } - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,23 +47,18 @@ func TestAccAzureRMAppServiceSlot_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceSlot_basic(ri, location), + Config: testAccAzureRMAppServiceSlot_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAppServiceSlot_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_app_service_slot"), - }, + data.RequiresImportErrorStep(testAccAzureRMAppServiceSlot_requiresImport), }, }) } func TestAccAzureRMAppServiceSlot_32Bit(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_32Bit(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,25 +66,19 @@ func TestAccAzureRMAppServiceSlot_32Bit(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_32Bit(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.use_32_bit_worker_process", "true"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.use_32_bit_worker_process", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_alwaysOn(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_alwaysOn(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -107,25 +86,19 @@ func TestAccAzureRMAppServiceSlot_alwaysOn(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_alwaysOn(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.always_on", "true"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.always_on", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_appCommandLine(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_appCommandLine(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -133,25 +106,20 @@ func TestAccAzureRMAppServiceSlot_appCommandLine(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_appCommandLine(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.app_command_line", "/sbin/myservice -b 0.0.0.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.app_command_line", "/sbin/myservice -b 0.0.0.0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_appSettings(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_appSettings(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -159,25 +127,20 @@ func TestAccAzureRMAppServiceSlot_appSettings(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_appSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "app_settings.foo", "bar"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.foo", "bar"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_clientAffinityEnabled(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_clientAffinityEnabled(ri, acceptance.Location(), true) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -185,10 +148,10 @@ func TestAccAzureRMAppServiceSlot_clientAffinityEnabled(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_clientAffinityEnabled(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "client_affinity_enabled", "true"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_affinity_enabled", "true"), ), }, }, @@ -196,10 +159,7 @@ func TestAccAzureRMAppServiceSlot_clientAffinityEnabled(t *testing.T) { } func TestAccAzureRMAppServiceSlot_clientAffinityEnabledUpdate(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_clientAffinityEnabled(ri, acceptance.Location(), true) - updatedConfig := testAccAzureRMAppServiceSlot_clientAffinityEnabled(ri, acceptance.Location(), false) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -207,17 +167,17 @@ func TestAccAzureRMAppServiceSlot_clientAffinityEnabledUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_clientAffinityEnabled(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "client_affinity_enabled", "true"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_affinity_enabled", "true"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMAppServiceSlot_clientAffinityEnabled(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "client_affinity_enabled", "false"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_affinity_enabled", "false"), ), }, }, @@ -225,9 +185,7 @@ func TestAccAzureRMAppServiceSlot_clientAffinityEnabledUpdate(t *testing.T) { } func TestAccAzureRMAppServiceSlot_connectionStrings(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -235,27 +193,27 @@ func TestAccAzureRMAppServiceSlot_connectionStrings(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceSlot_connectionStrings(ri, location), + Config: testAccAzureRMAppServiceSlot_connectionStrings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.name", "First"), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.value", "first-connection-string"), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.type", "Custom"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.name", "Second"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.type", "PostgreSQL"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.name", "First"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.value", "first-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.type", "Custom"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.name", "Second"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.type", "PostgreSQL"), ), }, { - Config: testAccAzureRMAppServiceSlot_connectionStringsUpdated(ri, location), + Config: testAccAzureRMAppServiceSlot_connectionStringsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.name", "First"), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.value", "first-connection-string"), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.type", "Custom"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.name", "Second"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.type", "PostgreSQL"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.name", "First"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.value", "first-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.type", "Custom"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.name", "Second"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.type", "PostgreSQL"), ), }, }, @@ -263,9 +221,7 @@ func TestAccAzureRMAppServiceSlot_connectionStrings(t *testing.T) { } func TestAccAzureRMAppServiceSlot_corsSettings(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -273,24 +229,19 @@ func TestAccAzureRMAppServiceSlot_corsSettings(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceSlot_corsSettings(ri, location), + Config: testAccAzureRMAppServiceSlot_corsSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - )}, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + testCheckAzureRMAppServiceExists(data.ResourceName), + ), }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_authSettingsAdditionalLoginParams(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppServiceSlot_authSettingsAdditionalLoginParams(ri, acceptance.Location(), tenantID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -298,31 +249,25 @@ func TestAccAzureRMAppServiceSlot_authSettingsAdditionalLoginParams(t *testing.T CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_authSettingsAdditionalLoginParams(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.additional_login_params.test_key", "test_value"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.additional_login_params.test_key", "test_value"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_authSettingsAdditionalAllowedExternalRedirectUrls(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppServiceSlot_authSettingsAdditionalAllowedExternalRedirectUrls(ri, acceptance.Location(), tenantID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -330,32 +275,28 @@ func TestAccAzureRMAppServiceSlot_authSettingsAdditionalAllowedExternalRedirectU CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_authSettingsAdditionalAllowedExternalRedirectUrls(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.allowed_external_redirect_urls.#", "1"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.allowed_external_redirect_urls.0", "https://terra.form"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.allowed_external_redirect_urls.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.allowed_external_redirect_urls.0", "https://terra.form"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_authSettingsRuntimeVersion(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppServiceSlot_authSettingsRuntimeVersion(ri, acceptance.Location(), tenantID) + config := testAccAzureRMAppServiceSlot_authSettingsRuntimeVersion(data, tenantID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -365,29 +306,24 @@ func TestAccAzureRMAppServiceSlot_authSettingsRuntimeVersion(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.runtime_version", "1.0"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.runtime_version", "1.0"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_authSettingsTokenRefreshExtensionHours(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppServiceSlot_authSettingsTokenRefreshExtensionHours(ri, acceptance.Location(), tenantID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -395,31 +331,25 @@ func TestAccAzureRMAppServiceSlot_authSettingsTokenRefreshExtensionHours(t *test CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_authSettingsTokenRefreshExtensionHours(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.token_refresh_extension_hours", "75"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.token_refresh_extension_hours", "75"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_authSettingsUnauthenticatedClientAction(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppServiceSlot_authSettingsUnauthenticatedClientAction(ri, acceptance.Location(), tenantID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -427,31 +357,26 @@ func TestAccAzureRMAppServiceSlot_authSettingsUnauthenticatedClientAction(t *tes CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_authSettingsUnauthenticatedClientAction(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.unauthenticated_client_action", "RedirectToLoginPage"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.unauthenticated_client_action", "RedirectToLoginPage"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_authSettingsTokenStoreEnabled(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppServiceSlot_authSettingsTokenStoreEnabled(ri, acceptance.Location(), tenantID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -459,31 +384,26 @@ func TestAccAzureRMAppServiceSlot_authSettingsTokenStoreEnabled(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_authSettingsTokenStoreEnabled(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.token_store_enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.token_store_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_aadAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppServiceSlot_aadAuthSettings(ri, acceptance.Location(), tenantID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -491,29 +411,24 @@ func TestAccAzureRMAppServiceSlot_aadAuthSettings(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_aadAuthSettings(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_facebookAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_facebookAuthSettings(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -521,28 +436,23 @@ func TestAccAzureRMAppServiceSlot_facebookAuthSettings(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_facebookAuthSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.facebook.0.app_id", "facebookappid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.facebook.0.app_secret", "facebookappsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.facebook.0.oauth_scopes.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.facebook.0.app_id", "facebookappid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.facebook.0.app_secret", "facebookappsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.facebook.0.oauth_scopes.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_googleAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_googleAuthSettings(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -550,28 +460,21 @@ func TestAccAzureRMAppServiceSlot_googleAuthSettings(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_googleAuthSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.google.0.client_id", "googleclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.google.0.client_secret", "googleclientsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.google.0.oauth_scopes.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.google.0.client_id", "googleclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.google.0.client_secret", "googleclientsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.google.0.oauth_scopes.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, }, }) } func TestAccAzureRMAppServiceSlot_microsoftAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_microsoftAuthSettings(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -579,28 +482,22 @@ func TestAccAzureRMAppServiceSlot_microsoftAuthSettings(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_microsoftAuthSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.client_id", "microsoftclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.client_secret", "microsoftclientsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.oauth_scopes.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.client_id", "microsoftclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.client_secret", "microsoftclientsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.oauth_scopes.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_twitterAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_twitterAuthSettings(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -608,29 +505,22 @@ func TestAccAzureRMAppServiceSlot_twitterAuthSettings(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_twitterAuthSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.twitter.0.consumer_key", "twitterconsumerkey"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.twitter.0.consumer_secret", "twitterconsumersecret"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.twitter.0.consumer_key", "twitterconsumerkey"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.twitter.0.consumer_secret", "twitterconsumersecret"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_multiAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") tenantID := os.Getenv("ARM_TENANT_ID") - config1 := testAccAzureRMAppServiceSlot_aadAuthSettings(ri, acceptance.Location(), tenantID) - config2 := testAccAzureRMAppServiceSlot_aadMicrosoftAuthSettings(ri, acceptance.Location(), tenantID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -638,48 +528,38 @@ func TestAccAzureRMAppServiceSlot_multiAuthSettings(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config1, + Config: testAccAzureRMAppServiceSlot_aadAuthSettings(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: config2, + Config: testAccAzureRMAppServiceSlot_aadMicrosoftAuthSettings(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.client_id", "microsoftclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.client_secret", "microsoftclientsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.oauth_scopes.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.client_id", "microsoftclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.client_secret", "microsoftclientsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.oauth_scopes.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_defaultDocuments(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_defaultDocuments(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -687,12 +567,12 @@ func TestAccAzureRMAppServiceSlot_defaultDocuments(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_defaultDocuments(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.default_documents.0", "first.html"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.default_documents.1", "second.jsp"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.default_documents.2", "third.aspx"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.default_documents.0", "first.html"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.default_documents.1", "second.jsp"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.default_documents.2", "third.aspx"), ), }, }, @@ -700,9 +580,7 @@ func TestAccAzureRMAppServiceSlot_defaultDocuments(t *testing.T) { } func TestAccAzureRMAppServiceSlot_enabled(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_enabled(ri, acceptance.Location(), false) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -710,10 +588,10 @@ func TestAccAzureRMAppServiceSlot_enabled(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_enabled(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), ), }, }, @@ -721,10 +599,7 @@ func TestAccAzureRMAppServiceSlot_enabled(t *testing.T) { } func TestAccAzureRMAppServiceSlot_enabledUpdate(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_enabled(ri, acceptance.Location(), false) - updatedConfig := testAccAzureRMAppServiceSlot_enabled(ri, acceptance.Location(), true) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -732,17 +607,17 @@ func TestAccAzureRMAppServiceSlot_enabledUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_enabled(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMAppServiceSlot_enabled(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), ), }, }, @@ -750,9 +625,7 @@ func TestAccAzureRMAppServiceSlot_enabledUpdate(t *testing.T) { } func TestAccAzureRMAppServiceSlot_httpsOnly(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_httpsOnly(ri, acceptance.Location(), true) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -760,10 +633,10 @@ func TestAccAzureRMAppServiceSlot_httpsOnly(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_httpsOnly(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "https_only", "true"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "https_only", "true"), ), }, }, @@ -771,10 +644,7 @@ func TestAccAzureRMAppServiceSlot_httpsOnly(t *testing.T) { } func TestAccAzureRMAppServiceSlot_httpsOnlyUpdate(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_httpsOnly(ri, acceptance.Location(), true) - updatedConfig := testAccAzureRMAppServiceSlot_httpsOnly(ri, acceptance.Location(), false) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -782,17 +652,17 @@ func TestAccAzureRMAppServiceSlot_httpsOnlyUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_httpsOnly(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "https_only", "true"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "https_only", "true"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMAppServiceSlot_httpsOnly(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "https_only", "false"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "https_only", "false"), ), }, }, @@ -800,9 +670,7 @@ func TestAccAzureRMAppServiceSlot_httpsOnlyUpdate(t *testing.T) { } func TestAccAzureRMAppServiceSlot_http2Enabled(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_http2Enabled(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -810,10 +678,10 @@ func TestAccAzureRMAppServiceSlot_http2Enabled(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_http2Enabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.http2_enabled", "true"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.http2_enabled", "true"), ), }, }, @@ -821,9 +689,7 @@ func TestAccAzureRMAppServiceSlot_http2Enabled(t *testing.T) { } func TestAccAzureRMAppServiceSlot_oneIpRestriction(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_oneIpRestriction(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -831,11 +697,11 @@ func TestAccAzureRMAppServiceSlot_oneIpRestriction(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_oneIpRestriction(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.0.subnet_mask", "255.255.255.255"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.subnet_mask", "255.255.255.255"), ), }, }, @@ -843,9 +709,7 @@ func TestAccAzureRMAppServiceSlot_oneIpRestriction(t *testing.T) { } func TestAccAzureRMAppServiceSlot_oneVNetSubnetIpRestriction(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_oneVNetSubnetIpRestriction(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -853,26 +717,18 @@ func TestAccAzureRMAppServiceSlot_oneVNetSubnetIpRestriction(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_oneVNetSubnetIpRestriction(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_zeroedIpRestriction(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_oneIpRestriction(ri, acceptance.Location()) - noBlocksConfig := testAccAzureRMAppServiceSlot_basic(ri, acceptance.Location()) - blocksEmptyConfig := testAccAzureRMAppServiceSlot_zeroedIpRestriction(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -881,26 +737,26 @@ func TestAccAzureRMAppServiceSlot_zeroedIpRestriction(t *testing.T) { Steps: []resource.TestStep{ { // This configuration includes a single explicit ip_restriction - Config: config, + Config: testAccAzureRMAppServiceSlot_oneIpRestriction(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.#", "1"), ), }, { // This configuration has no site_config blocks at all. - Config: noBlocksConfig, + Config: testAccAzureRMAppServiceSlot_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.#", "1"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.#", "1"), ), }, { // This configuration explicitly sets ip_restriction to [] using attribute syntax. - Config: blocksEmptyConfig, + Config: testAccAzureRMAppServiceSlot_zeroedIpRestriction(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.#", "0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.#", "0"), ), }, }, @@ -908,9 +764,7 @@ func TestAccAzureRMAppServiceSlot_zeroedIpRestriction(t *testing.T) { } func TestAccAzureRMAppServiceSlot_manyIpRestrictions(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_manyIpRestrictions(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -918,17 +772,17 @@ func TestAccAzureRMAppServiceSlot_manyIpRestrictions(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_manyIpRestrictions(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.0.subnet_mask", "255.255.255.255"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.1.ip_address", "20.20.20.0"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.1.subnet_mask", "255.255.255.0"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.2.ip_address", "30.30.0.0"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.2.subnet_mask", "255.255.0.0"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.3.ip_address", "192.168.1.2"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.3.subnet_mask", "255.255.255.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.subnet_mask", "255.255.255.255"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.1.ip_address", "20.20.20.0"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.1.subnet_mask", "255.255.255.0"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.2.ip_address", "30.30.0.0"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.2.subnet_mask", "255.255.0.0"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.3.ip_address", "192.168.1.2"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.3.subnet_mask", "255.255.255.0"), ), }, }, @@ -936,9 +790,7 @@ func TestAccAzureRMAppServiceSlot_manyIpRestrictions(t *testing.T) { } func TestAccAzureRMAppServiceSlot_localMySql(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_localMySql(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -946,10 +798,10 @@ func TestAccAzureRMAppServiceSlot_localMySql(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_localMySql(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.local_mysql_enabled", "true"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.local_mysql_enabled", "true"), ), }, }, @@ -957,9 +809,7 @@ func TestAccAzureRMAppServiceSlot_localMySql(t *testing.T) { } func TestAccAzureRMAppServiceSlot_managedPipelineMode(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_managedPipelineMode(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -967,10 +817,10 @@ func TestAccAzureRMAppServiceSlot_managedPipelineMode(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_managedPipelineMode(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.managed_pipeline_mode", "Classic"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.managed_pipeline_mode", "Classic"), ), }, }, @@ -978,10 +828,7 @@ func TestAccAzureRMAppServiceSlot_managedPipelineMode(t *testing.T) { } func TestAccAzureRMAppServiceSlot_tagsUpdate(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_tags(ri, acceptance.Location()) - updatedConfig := testAccAzureRMAppServiceSlot_tagsUpdated(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -989,20 +836,20 @@ func TestAccAzureRMAppServiceSlot_tagsUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMAppServiceSlot_tagsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), - resource.TestCheckResourceAttr(resourceName, "tags.Terraform", "AcceptanceTests"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Terraform", "AcceptanceTests"), ), }, }, @@ -1010,9 +857,7 @@ func TestAccAzureRMAppServiceSlot_tagsUpdate(t *testing.T) { } func TestAccAzureRMAppServiceSlot_remoteDebugging(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_remoteDebugging(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1020,11 +865,11 @@ func TestAccAzureRMAppServiceSlot_remoteDebugging(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_remoteDebugging(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.remote_debugging_enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.remote_debugging_version", "VS2015"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.remote_debugging_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.remote_debugging_version", "VS2015"), ), }, }, @@ -1032,9 +877,7 @@ func TestAccAzureRMAppServiceSlot_remoteDebugging(t *testing.T) { } func TestAccAzureRMAppServiceSlot_virtualNetwork(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1042,17 +885,17 @@ func TestAccAzureRMAppServiceSlot_virtualNetwork(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceSlot_virtualNetwork(ri, location), + Config: testAccAzureRMAppServiceSlot_virtualNetwork(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn-%d", ri)), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn-%d", data.RandomInteger)), ), }, { - Config: testAccAzureRMAppServiceSlot_virtualNetworkUpdated(ri, location), + Config: testAccAzureRMAppServiceSlot_virtualNetworkUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn2-%d", ri)), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn2-%d", data.RandomInteger)), ), }, }, @@ -1060,9 +903,7 @@ func TestAccAzureRMAppServiceSlot_virtualNetwork(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsDotNet2(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsDotNet(ri, acceptance.Location(), "v2.0") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1070,10 +911,10 @@ func TestAccAzureRMAppServiceSlot_windowsDotNet2(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsDotNet(data, "v2.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.dotnet_framework_version", "v2.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.dotnet_framework_version", "v2.0"), ), }, }, @@ -1081,8 +922,7 @@ func TestAccAzureRMAppServiceSlot_windowsDotNet2(t *testing.T) { } func TestAccAzureRMAppServiceSlot_updateManageServiceIdentity(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1090,18 +930,18 @@ func TestAccAzureRMAppServiceSlot_updateManageServiceIdentity(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceSlot_basic(ri, acceptance.Location()), + Config: testAccAzureRMAppServiceSlot_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), ), }, { - Config: testAccAzureRMAppServiceSlot_enableManageServiceIdentity(ri, acceptance.Location()), + Config: testAccAzureRMAppServiceSlot_enableManageServiceIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, }, @@ -1109,9 +949,7 @@ func TestAccAzureRMAppServiceSlot_updateManageServiceIdentity(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsDotNet4(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsDotNet(ri, acceptance.Location(), "v4.0") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1119,10 +957,10 @@ func TestAccAzureRMAppServiceSlot_windowsDotNet4(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsDotNet(data, "v4.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.dotnet_framework_version", "v4.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.dotnet_framework_version", "v4.0"), ), }, }, @@ -1130,9 +968,7 @@ func TestAccAzureRMAppServiceSlot_windowsDotNet4(t *testing.T) { } func TestAccAzureRMAppServiceSlot_userAssignedIdentity(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_userAssignedIdentity(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1140,13 +976,13 @@ func TestAccAzureRMAppServiceSlot_userAssignedIdentity(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_userAssignedIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "identity.0.principal_id", ""), - resource.TestCheckResourceAttr(resourceName, "identity.0.tenant_id", ""), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.principal_id", ""), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.tenant_id", ""), ), }, }, @@ -1154,9 +990,7 @@ func TestAccAzureRMAppServiceSlot_userAssignedIdentity(t *testing.T) { } func TestAccAzureRMAppServiceSlot_multipleAssignedIdentities(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_multipleAssignedIdentities(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1164,13 +998,13 @@ func TestAccAzureRMAppServiceSlot_multipleAssignedIdentities(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_multipleAssignedIdentities(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned, UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned, UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, }, @@ -1178,10 +1012,7 @@ func TestAccAzureRMAppServiceSlot_multipleAssignedIdentities(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsDotNetUpdate(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsDotNet(ri, acceptance.Location(), "v2.0") - updatedConfig := testAccAzureRMAppServiceSlot_windowsDotNet(ri, acceptance.Location(), "v4.0") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1189,17 +1020,17 @@ func TestAccAzureRMAppServiceSlot_windowsDotNetUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsDotNet(data, "v2.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.dotnet_framework_version", "v2.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.dotnet_framework_version", "v2.0"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMAppServiceSlot_windowsDotNet(data, "v4.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.dotnet_framework_version", "v4.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.dotnet_framework_version", "v4.0"), ), }, }, @@ -1207,9 +1038,7 @@ func TestAccAzureRMAppServiceSlot_windowsDotNetUpdate(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsJava7Jetty(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsJava(ri, acceptance.Location(), "1.7", "JETTY", "9.3") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1217,12 +1046,12 @@ func TestAccAzureRMAppServiceSlot_windowsJava7Jetty(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsJava(data, "1.7", "JETTY", "9.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.7"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JETTY"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.7"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "JETTY"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.3"), ), }, }, @@ -1230,9 +1059,7 @@ func TestAccAzureRMAppServiceSlot_windowsJava7Jetty(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsJava8Jetty(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsJava(ri, acceptance.Location(), "1.8", "JETTY", "9.3") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1240,21 +1067,19 @@ func TestAccAzureRMAppServiceSlot_windowsJava8Jetty(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsJava(data, "1.8", "JETTY", "9.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.8"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JETTY"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.8"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "JETTY"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.3"), ), }, }, }) } func TestAccAzureRMAppServiceSlot_windowsJava11Jetty(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsJava(ri, acceptance.Location(), "11", "JETTY", "9.3") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1262,12 +1087,12 @@ func TestAccAzureRMAppServiceSlot_windowsJava11Jetty(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsJava(data, "11", "JETTY", "9.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "11"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JETTY"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "JETTY"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.3"), ), }, }, @@ -1275,9 +1100,7 @@ func TestAccAzureRMAppServiceSlot_windowsJava11Jetty(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsJava7Tomcat(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsJava(ri, acceptance.Location(), "1.7", "TOMCAT", "9.0") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1285,12 +1108,12 @@ func TestAccAzureRMAppServiceSlot_windowsJava7Tomcat(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsJava(data, "1.7", "TOMCAT", "9.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.7"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.7"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "TOMCAT"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.0"), ), }, }, @@ -1298,9 +1121,7 @@ func TestAccAzureRMAppServiceSlot_windowsJava7Tomcat(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsJava8Tomcat(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsJava(ri, acceptance.Location(), "1.8", "TOMCAT", "9.0") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1308,12 +1129,12 @@ func TestAccAzureRMAppServiceSlot_windowsJava8Tomcat(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsJava(data, "1.8", "TOMCAT", "9.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.8"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.8"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "TOMCAT"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.0"), ), }, }, @@ -1321,9 +1142,7 @@ func TestAccAzureRMAppServiceSlot_windowsJava8Tomcat(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsJava11Tomcat(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsJava(ri, acceptance.Location(), "11", "TOMCAT", "9.0") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1331,12 +1150,12 @@ func TestAccAzureRMAppServiceSlot_windowsJava11Tomcat(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsJava(data, "11", "TOMCAT", "9.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "11"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "TOMCAT"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.0"), ), }, }, @@ -1344,9 +1163,7 @@ func TestAccAzureRMAppServiceSlot_windowsJava11Tomcat(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsJava7Minor(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsJava(ri, acceptance.Location(), "1.7.0_80", "TOMCAT", "9.0") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1354,12 +1171,12 @@ func TestAccAzureRMAppServiceSlot_windowsJava7Minor(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsJava(data, "1.7.0_80", "TOMCAT", "9.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.7.0_80"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.7.0_80"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "TOMCAT"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.0"), ), }, }, @@ -1367,9 +1184,7 @@ func TestAccAzureRMAppServiceSlot_windowsJava7Minor(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsJava8Minor(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsJava(ri, acceptance.Location(), "1.8.0_181", "TOMCAT", "9.0") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1377,12 +1192,12 @@ func TestAccAzureRMAppServiceSlot_windowsJava8Minor(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsJava(data, "1.8.0_181", "TOMCAT", "9.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.8.0_181"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.8.0_181"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "TOMCAT"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.0"), ), }, }, @@ -1390,9 +1205,7 @@ func TestAccAzureRMAppServiceSlot_windowsJava8Minor(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsPHP7(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsPHP(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1400,10 +1213,10 @@ func TestAccAzureRMAppServiceSlot_windowsPHP7(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsPHP(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.php_version", "7.3"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.php_version", "7.3"), ), }, }, @@ -1411,9 +1224,7 @@ func TestAccAzureRMAppServiceSlot_windowsPHP7(t *testing.T) { } func TestAccAzureRMAppServiceSlot_windowsPython(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_windowsPython(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1421,10 +1232,10 @@ func TestAccAzureRMAppServiceSlot_windowsPython(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_windowsPython(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.python_version", "3.4"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.python_version", "3.4"), ), }, }, @@ -1432,9 +1243,7 @@ func TestAccAzureRMAppServiceSlot_windowsPython(t *testing.T) { } func TestAccAzureRMAppServiceSlot_webSockets(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_webSockets(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1442,10 +1251,10 @@ func TestAccAzureRMAppServiceSlot_webSockets(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_webSockets(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.websockets_enabled", "true"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.websockets_enabled", "true"), ), }, }, @@ -1453,9 +1262,7 @@ func TestAccAzureRMAppServiceSlot_webSockets(t *testing.T) { } func TestAccAzureRMAppServiceSlot_enableManageServiceIdentity(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_enableManageServiceIdentity(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1463,12 +1270,12 @@ func TestAccAzureRMAppServiceSlot_enableManageServiceIdentity(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_enableManageServiceIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, }, @@ -1476,10 +1283,7 @@ func TestAccAzureRMAppServiceSlot_enableManageServiceIdentity(t *testing.T) { } func TestAccAzureRMAppServiceSlot_minTls(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_minTls(ri, acceptance.Location(), "1.0") - updatedConfig := testAccAzureRMAppServiceSlot_minTls(ri, acceptance.Location(), "1.1") + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1487,32 +1291,26 @@ func TestAccAzureRMAppServiceSlot_minTls(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_minTls(data, "1.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.min_tls_version", "1.0"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.min_tls_version", "1.0"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMAppServiceSlot_minTls(data, "1.1"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.min_tls_version", "1.1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.min_tls_version", "1.1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_applicationBlobStorageLogs(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_applicationBlobStorageLogs(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1520,26 +1318,20 @@ func TestAccAzureRMAppServiceSlot_applicationBlobStorageLogs(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_applicationBlobStorageLogs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "logs.0.application_logs.0.azure_blob_storage.0.level", "Information"), - resource.TestCheckResourceAttr(resourceName, "logs.0.application_logs.0.azure_blob_storage.0.sas_url", "https://example.com/"), - resource.TestCheckResourceAttr(resourceName, "logs.0.application_logs.0.azure_blob_storage.0.retention_in_days", "3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.application_logs.0.azure_blob_storage.0.level", "Information"), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.application_logs.0.azure_blob_storage.0.sas_url", "https://example.com/"), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.application_logs.0.azure_blob_storage.0.retention_in_days", "3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_httpFileSystemLogs(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_httpFileSystemLogs(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1547,25 +1339,19 @@ func TestAccAzureRMAppServiceSlot_httpFileSystemLogs(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_httpFileSystemLogs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "logs.0.http_logs.0.file_system.0.retention_in_days", "4"), - resource.TestCheckResourceAttr(resourceName, "logs.0.http_logs.0.file_system.0.retention_in_mb", "25"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.http_logs.0.file_system.0.retention_in_days", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.http_logs.0.file_system.0.retention_in_mb", "25"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_httpBlobStorageLogs(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_httpBlobStorageLogs(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1573,26 +1359,20 @@ func TestAccAzureRMAppServiceSlot_httpBlobStorageLogs(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_httpBlobStorageLogs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "logs.0.http_logs.0.azure_blob_storage.0.sas_url", "https://example.com/"), - resource.TestCheckResourceAttr(resourceName, "logs.0.http_logs.0.azure_blob_storage.0.retention_in_days", "3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.http_logs.0.azure_blob_storage.0.sas_url", "https://example.com/"), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.http_logs.0.azure_blob_storage.0.retention_in_days", "3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceSlot_autoSwap(t *testing.T) { - resourceName := "azurerm_app_service_slot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppServiceSlot_autoSwap(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service_slot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1600,17 +1380,13 @@ func TestAccAzureRMAppServiceSlot_autoSwap(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceSlotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSlot_autoSwap(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceSlotExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.auto_swap_slot_name", "production"), + testCheckAzureRMAppServiceSlotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.auto_swap_slot_name", "production"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -1672,7 +1448,7 @@ func testCheckAzureRMAppServiceSlotExists(slot string) resource.TestCheckFunc { } } -func testAccAzureRMAppServiceSlot_basic(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1704,11 +1480,11 @@ resource "azurerm_app_service_slot" "test" { app_service_plan_id = "${azurerm_app_service_plan.test.id}" app_service_name = "${azurerm_app_service.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_requiresImport(rInt int, location string) string { - template := testAccAzureRMAppServiceSlot_basic(rInt, location) +func testAccAzureRMAppServiceSlot_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAppServiceSlot_basic(data) return fmt.Sprintf(` %s @@ -1722,7 +1498,7 @@ resource "azurerm_app_service_slot" "import" { `, template) } -func testAccAzureRMAppServiceSlot_32Bit(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_32Bit(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1758,10 +1534,10 @@ resource "azurerm_app_service_slot" "test" { use_32_bit_worker_process = true } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_alwaysOn(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_alwaysOn(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1797,10 +1573,10 @@ resource "azurerm_app_service_slot" "test" { always_on = true } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_appCommandLine(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_appCommandLine(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1836,10 +1612,10 @@ resource "azurerm_app_service_slot" "test" { app_command_line = "/sbin/myservice -b 0.0.0.0" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_appSettings(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_appSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1875,10 +1651,10 @@ resource "azurerm_app_service_slot" "test" { "foo" = "bar" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_clientAffinityEnabled(rInt int, location string, clientAffinityEnabled bool) string { +func testAccAzureRMAppServiceSlot_clientAffinityEnabled(data acceptance.TestData, clientAffinityEnabled bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1911,10 +1687,10 @@ resource "azurerm_app_service_slot" "test" { app_service_name = "${azurerm_app_service.test.name}" client_affinity_enabled = %t } -`, rInt, location, rInt, rInt, rInt, clientAffinityEnabled) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientAffinityEnabled) } -func testAccAzureRMAppServiceSlot_connectionStrings(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_connectionStrings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1958,10 +1734,10 @@ resource "azurerm_app_service_slot" "test" { type = "PostgreSQL" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_connectionStringsUpdated(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_connectionStringsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2005,10 +1781,10 @@ resource "azurerm_app_service_slot" "test" { type = "Custom" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_corsSettings(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_corsSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2051,10 +1827,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_authSettingsAdditionalLoginParams(rInt int, location string, tenantID string) string { +func testAccAzureRMAppServiceSlot_authSettingsAdditionalLoginParams(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2110,10 +1886,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppServiceSlot_authSettingsAdditionalAllowedExternalRedirectUrls(rInt int, location string, tenantID string) string { +func testAccAzureRMAppServiceSlot_authSettingsAdditionalAllowedExternalRedirectUrls(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2169,10 +1945,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppServiceSlot_authSettingsRuntimeVersion(rInt int, location string, tenantID string) string { +func testAccAzureRMAppServiceSlot_authSettingsRuntimeVersion(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2225,10 +2001,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppServiceSlot_authSettingsTokenRefreshExtensionHours(rInt int, location string, tenantID string) string { +func testAccAzureRMAppServiceSlot_authSettingsTokenRefreshExtensionHours(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2281,10 +2057,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppServiceSlot_authSettingsTokenStoreEnabled(rInt int, location string, tenantID string) string { +func testAccAzureRMAppServiceSlot_authSettingsTokenStoreEnabled(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2337,10 +2113,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppServiceSlot_authSettingsUnauthenticatedClientAction(rInt int, location string, tenantID string) string { +func testAccAzureRMAppServiceSlot_authSettingsUnauthenticatedClientAction(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2393,10 +2169,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppServiceSlot_aadAuthSettings(rInt int, location string, tenantID string) string { +func testAccAzureRMAppServiceSlot_aadAuthSettings(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2447,10 +2223,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppServiceSlot_facebookAuthSettings(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_facebookAuthSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2500,10 +2276,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_googleAuthSettings(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_googleAuthSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2554,10 +2330,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_microsoftAuthSettings(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_microsoftAuthSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2606,10 +2382,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_twitterAuthSettings(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_twitterAuthSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2655,10 +2431,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_aadMicrosoftAuthSettings(rInt int, location string, tenantID string) string { +func testAccAzureRMAppServiceSlot_aadMicrosoftAuthSettings(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2720,10 +2496,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt, tenantID, web.AzureActiveDirectory) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, tenantID, web.AzureActiveDirectory) } -func testAccAzureRMAppServiceSlot_defaultDocuments(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_defaultDocuments(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2763,10 +2539,10 @@ resource "azurerm_app_service_slot" "test" { ] } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_enabled(rInt int, location string, enabled bool) string { +func testAccAzureRMAppServiceSlot_enabled(data acceptance.TestData, enabled bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2799,10 +2575,10 @@ resource "azurerm_app_service_slot" "test" { app_service_name = "${azurerm_app_service.test.name}" enabled = %t } -`, rInt, location, rInt, rInt, rInt, enabled) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, enabled) } -func testAccAzureRMAppServiceSlot_httpsOnly(rInt int, location string, httpsOnly bool) string { +func testAccAzureRMAppServiceSlot_httpsOnly(data acceptance.TestData, httpsOnly bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2835,10 +2611,10 @@ resource "azurerm_app_service_slot" "test" { app_service_name = "${azurerm_app_service.test.name}" https_only = %t } -`, rInt, location, rInt, rInt, rInt, httpsOnly) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, httpsOnly) } -func testAccAzureRMAppServiceSlot_http2Enabled(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_http2Enabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2874,10 +2650,10 @@ resource "azurerm_app_service_slot" "test" { http2_enabled = true } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_oneIpRestriction(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_oneIpRestriction(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2915,10 +2691,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_oneVNetSubnetIpRestriction(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_oneVNetSubnetIpRestriction(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2970,10 +2746,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_zeroedIpRestriction(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_zeroedIpRestriction(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3009,10 +2785,10 @@ resource "azurerm_app_service_slot" "test" { ip_restriction = [] } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_manyIpRestrictions(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_manyIpRestrictions(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3065,10 +2841,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_localMySql(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_localMySql(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3104,10 +2880,10 @@ resource "azurerm_app_service_slot" "test" { local_mysql_enabled = true } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_managedPipelineMode(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_managedPipelineMode(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3143,10 +2919,10 @@ resource "azurerm_app_service_slot" "test" { managed_pipeline_mode = "Classic" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_tags(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_tags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3182,10 +2958,10 @@ resource "azurerm_app_service_slot" "test" { Hello = "World" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_tagsUpdated(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_tagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3222,10 +2998,10 @@ resource "azurerm_app_service_slot" "test" { "Terraform" = "AcceptanceTests" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_remoteDebugging(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_remoteDebugging(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3266,10 +3042,10 @@ resource "azurerm_app_service_slot" "test" { Hello = "World" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_virtualNetwork(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_virtualNetwork(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3317,10 +3093,10 @@ resource "azurerm_app_service_slot" "test" { virtual_network_name = "${azurerm_virtual_network.test.name}" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_virtualNetworkUpdated(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_virtualNetworkUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3380,10 +3156,10 @@ resource "azurerm_app_service_slot" "test" { virtual_network_name = "${azurerm_virtual_network.second.name}" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_windowsDotNet(rInt int, location, version string) string { +func testAccAzureRMAppServiceSlot_windowsDotNet(data acceptance.TestData, version string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3419,10 +3195,10 @@ resource "azurerm_app_service_slot" "test" { dotnet_framework_version = "%s" } } -`, rInt, location, rInt, rInt, rInt, version) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, version) } -func testAccAzureRMAppServiceSlot_windowsJava(rInt int, location, javaVersion, container, containerVersion string) string { +func testAccAzureRMAppServiceSlot_windowsJava(data acceptance.TestData, javaVersion, container, containerVersion string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3460,10 +3236,10 @@ resource "azurerm_app_service_slot" "test" { java_container_version = "%s" } } -`, rInt, location, rInt, rInt, rInt, javaVersion, container, containerVersion) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, javaVersion, container, containerVersion) } -func testAccAzureRMAppServiceSlot_windowsPHP(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_windowsPHP(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3499,10 +3275,10 @@ resource "azurerm_app_service_slot" "test" { php_version = "7.3" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_windowsPython(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_windowsPython(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3538,10 +3314,10 @@ resource "azurerm_app_service_slot" "test" { python_version = "3.4" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_webSockets(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_webSockets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3577,10 +3353,10 @@ resource "azurerm_app_service_slot" "test" { websockets_enabled = true } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_enableManageServiceIdentity(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_enableManageServiceIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3616,10 +3392,10 @@ resource "azurerm_app_service_slot" "test" { type = "SystemAssigned" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_userAssignedIdentity(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_userAssignedIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3662,10 +3438,10 @@ resource "azurerm_app_service_slot" "test" { identity_ids = ["${azurerm_user_assigned_identity.test.id}"] } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_multipleAssignedIdentities(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_multipleAssignedIdentities(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3708,10 +3484,10 @@ resource "azurerm_app_service_slot" "test" { identity_ids = ["${azurerm_user_assigned_identity.test.id}"] } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_minTls(rInt int, location string, tlsVersion string) string { +func testAccAzureRMAppServiceSlot_minTls(data acceptance.TestData, tlsVersion string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3747,10 +3523,10 @@ resource "azurerm_app_service_slot" "test" { min_tls_version = "%s" } } -`, rInt, location, rInt, rInt, rInt, tlsVersion) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, tlsVersion) } -func testAccAzureRMAppServiceSlot_applicationBlobStorageLogs(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_applicationBlobStorageLogs(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3792,10 +3568,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_httpFileSystemLogs(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_httpFileSystemLogs(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3836,10 +3612,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_httpBlobStorageLogs(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_httpBlobStorageLogs(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3880,10 +3656,10 @@ resource "azurerm_app_service_slot" "test" { } } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceSlot_autoSwap(rInt int, location string) string { +func testAccAzureRMAppServiceSlot_autoSwap(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3919,5 +3695,5 @@ resource "azurerm_app_service_slot" "test" { auto_swap_slot_name = "production" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/web/resource_arm_app_service_source_control_token_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_source_control_token_test.go similarity index 78% rename from azurerm/internal/services/web/resource_arm_app_service_source_control_token_test.go rename to azurerm/internal/services/web/tests/resource_arm_app_service_source_control_token_test.go index c1eaa14ccfa6..7879f7d833c0 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_source_control_token_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_source_control_token_test.go @@ -1,4 +1,4 @@ -package web +package tests import ( "fmt" @@ -14,30 +14,24 @@ import ( ) func TestAccAzureRMAppServiceSourceControlToken(t *testing.T) { - resourceName := "azurerm_app_service_source_control_token.test" + data := acceptance.BuildTestData(t, "azurerm_app_service_source_control_token", "test") token := strings.ToLower(acctest.RandString(41)) tokenSecret := strings.ToLower(acctest.RandString(41)) - config := testAccAzureRMAppServiceSourceControlToken(token, tokenSecret) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceSourceControlTokenDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppServiceSourceControlToken(token, tokenSecret), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "type", "GitHub"), - resource.TestCheckResourceAttr(resourceName, "token", token), - resource.TestCheckResourceAttr(resourceName, "token_secret", tokenSecret), + resource.TestCheckResourceAttr(data.ResourceName, "type", "GitHub"), + resource.TestCheckResourceAttr(data.ResourceName, "token", token), + resource.TestCheckResourceAttr(data.ResourceName, "token_secret", tokenSecret), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/web/resource_arm_app_service_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_test.go similarity index 60% rename from azurerm/internal/services/web/resource_arm_app_service_test.go rename to azurerm/internal/services/web/tests/resource_arm_app_service_test.go index e177b6db7e7d..4ab0f784f546 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_test.go @@ -1,4 +1,4 @@ -package web +package tests import ( "fmt" @@ -6,11 +6,9 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" @@ -18,50 +16,8 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAzureRMAppServiceName_validation(t *testing.T) { - cases := []struct { - Value string - ErrCount int - }{ - { - Value: "ab", - ErrCount: 0, - }, - { - Value: "abc", - ErrCount: 0, - }, - { - Value: "webapp1", - ErrCount: 0, - }, - { - Value: "hello-world", - ErrCount: 0, - }, - { - Value: "hello_world", - ErrCount: 1, - }, - { - Value: "helloworld21!", - ErrCount: 1, - }, - } - - for _, tc := range cases { - _, errors := validateAppServiceName(tc.Value, "azurerm_app_service") - - if len(errors) != tc.ErrCount { - t.Fatalf("Expected the App Service Name to trigger a validation error for '%s'", tc.Value) - } - } -} - func TestAccAzureRMAppService_basic(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -69,18 +25,14 @@ func TestAccAzureRMAppService_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "outbound_ip_addresses"), - resource.TestCheckResourceAttrSet(resourceName, "possible_outbound_ip_addresses"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "outbound_ip_addresses"), + resource.TestCheckResourceAttrSet(data.ResourceName, "possible_outbound_ip_addresses"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -91,49 +43,40 @@ func TestAccAzureRMAppService_requiresImport(t *testing.T) { return } - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppService_basic(ri, location), + Config: testAccAzureRMAppService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAppService_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_app_service"), - }, + data.RequiresImportErrorStep(testAccAzureRMAppService_requiresImport), }, }) } func TestAccAzureRMAppService_movingAppService(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppService_basic(ri, location), + Config: testAccAzureRMAppService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, { - Config: testAccAzureRMAppService_moved(ri, location), + Config: testAccAzureRMAppService_moved(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, }, @@ -141,410 +84,306 @@ func TestAccAzureRMAppService_movingAppService(t *testing.T) { } func TestAccAzureRMAppService_freeTier(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_freeTier(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_freeTier(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_sharedTier(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_sharedTier(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_sharedTier(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_32Bit(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_32Bit(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_32Bit(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.use_32_bit_worker_process", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.use_32_bit_worker_process", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_backup(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppService_backup(ri, rs, location), + Config: testAccAzureRMAppService_backup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAppService_backupUpdated(ri, rs, location), + Config: testAccAzureRMAppService_backupUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { // Enabled - Config: testAccAzureRMAppService_backup(ri, rs, location), + Config: testAccAzureRMAppService_backup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, { // Disabled - Config: testAccAzureRMAppService_backupDisabled(ri, rs, location), + Config: testAccAzureRMAppService_backupDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, { // remove it - Config: testAccAzureRMAppService_basic(ri, location), + Config: testAccAzureRMAppService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_http2Enabled(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_http2Enabled(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_http2Enabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.http2_enabled", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.http2_enabled", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_alwaysOn(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_alwaysOn(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_alwaysOn(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.always_on", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.always_on", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_appCommandLine(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_appCommandLine(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_appCommandLine(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.app_command_line", "/sbin/myserver -b 0.0.0.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.app_command_line", "/sbin/myserver -b 0.0.0.0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_httpsOnly(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_httpsOnly(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_httpsOnly(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "https_only", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "https_only", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_clientCertEnabled(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - configClientCertEnabled := testAccAzureRMAppService_clientCertEnabled(ri, acceptance.Location()) - configClientCertEnabledNotSet := testAccAzureRMAppService_clientCertEnabledNotSet(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: configClientCertEnabled, + Config: testAccAzureRMAppService_clientCertEnabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "client_cert_enabled", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_cert_enabled", "true"), ), }, { - Config: configClientCertEnabledNotSet, + Config: testAccAzureRMAppService_clientCertEnabledNotSet(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "client_cert_enabled", "false"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_cert_enabled", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_appSettings(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_appSettings(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_appSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "app_settings.foo", "bar"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.foo", "bar"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_clientAffinityEnabled(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_clientAffinityEnabled(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_clientAffinityEnabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "client_affinity_enabled", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_affinity_enabled", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_clientAffinityDisabled(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_clientAffinityDisabled(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_clientAffinityDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "client_affinity_enabled", "false"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_affinity_enabled", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_virtualNetwork(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppService_virtualNetwork(ri, location), + Config: testAccAzureRMAppService_virtualNetwork(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn-%d", ri)), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn-%d", data.RandomInteger)), ), }, { - Config: testAccAzureRMAppService_virtualNetworkUpdated(ri, location), + Config: testAccAzureRMAppService_virtualNetworkUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn2-%d", ri)), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.virtual_network_name", fmt.Sprintf("acctestvn2-%d", data.RandomInteger)), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_enableManageServiceIdentity(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_mangedServiceIdentity(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_mangedServiceIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, }, @@ -552,31 +391,26 @@ func TestAccAzureRMAppService_enableManageServiceIdentity(t *testing.T) { } func TestAccAzureRMAppService_updateResourceByEnablingManageServiceIdentity(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - - basicResourceNoManagedIdentity := testAccAzureRMAppService_basic(ri, acceptance.Location()) - managedIdentityEnabled := testAccAzureRMAppService_mangedServiceIdentity(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: basicResourceNoManagedIdentity, + Config: testAccAzureRMAppService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.#", "0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.#", "0"), ), }, { - Config: managedIdentityEnabled, + Config: testAccAzureRMAppService_mangedServiceIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, }, @@ -584,23 +418,20 @@ func TestAccAzureRMAppService_updateResourceByEnablingManageServiceIdentity(t *t } func TestAccAzureRMAppService_userAssignedIdentity(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_userAssignedIdentity(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_userAssignedIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "identity.0.principal_id", ""), - resource.TestCheckResourceAttr(resourceName, "identity.0.tenant_id", ""), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.principal_id", ""), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.tenant_id", ""), ), }, }, @@ -608,23 +439,20 @@ func TestAccAzureRMAppService_userAssignedIdentity(t *testing.T) { } func TestAccAzureRMAppService_multipleAssignedIdentities(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_multipleAssignedIdentities(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_multipleAssignedIdentities(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned, UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned, UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, }, @@ -632,179 +460,136 @@ func TestAccAzureRMAppService_multipleAssignedIdentities(t *testing.T) { } func TestAccAzureRMAppService_clientAffinityUpdate(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_clientAffinity(ri, acceptance.Location(), true) - updatedConfig := testAccAzureRMAppService_clientAffinity(ri, acceptance.Location(), false) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_clientAffinity(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "client_affinity_enabled", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_affinity_enabled", "true"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: updatedConfig, + Config: testAccAzureRMAppService_clientAffinity(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "client_affinity_enabled", "false"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_affinity_enabled", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_connectionStrings(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppService_connectionStrings(ri, location), + Config: testAccAzureRMAppService_connectionStrings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.name", "First"), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.value", "first-connection-string"), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.type", "Custom"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.name", "Second"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.type", "PostgreSQL"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.name", "First"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.value", "first-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.type", "Custom"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.name", "Second"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.type", "PostgreSQL"), ), }, { - Config: testAccAzureRMAppService_connectionStringsUpdated(ri, location), + Config: testAccAzureRMAppService_connectionStringsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.name", "First"), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.value", "first-connection-string"), - resource.TestCheckResourceAttr(resourceName, "connection_string.3173438943.type", "Custom"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.name", "Second"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"), - resource.TestCheckResourceAttr(resourceName, "connection_string.2442860602.type", "PostgreSQL"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.name", "First"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.value", "first-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.3173438943.type", "Custom"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.name", "Second"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.value", "some-postgresql-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.2442860602.type", "PostgreSQL"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_storageAccounts(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppService_storageAccounts(ri, location), + Config: testAccAzureRMAppService_storageAccounts(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_account.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_account.#", "1"), ), }, { - Config: testAccAzureRMAppService_storageAccountsUpdated(ri, location), + Config: testAccAzureRMAppService_storageAccountsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_account.#", "2"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_account.#", "2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_oneIpRestriction(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_oneIpRestriction(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_oneIpRestriction(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.0.subnet_mask", "255.255.255.255"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.subnet_mask", "255.255.255.255"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_oneVNetSubnetIpRestriction(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_oneVNetSubnetIpRestriction(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_oneVNetSubnetIpRestriction(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_zeroedIpRestriction(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_oneIpRestriction(ri, acceptance.Location()) - noBlocksConfig := testAccAzureRMAppService_basic(ri, acceptance.Location()) - blocksEmptyConfig := testAccAzureRMAppService_zeroedIpRestriction(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -812,26 +597,26 @@ func TestAccAzureRMAppService_zeroedIpRestriction(t *testing.T) { Steps: []resource.TestStep{ { // This configuration includes a single explicit ip_restriction - Config: config, + Config: testAccAzureRMAppService_oneIpRestriction(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.#", "1"), ), }, { // This configuration has no site_config blocks at all. - Config: noBlocksConfig, + Config: testAccAzureRMAppService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.#", "1"), ), }, { // This configuration explicitly sets ip_restriction to [] using attribute syntax. - Config: blocksEmptyConfig, + Config: testAccAzureRMAppService_zeroedIpRestriction(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.#", "0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.#", "0"), ), }, }, @@ -839,310 +624,230 @@ func TestAccAzureRMAppService_zeroedIpRestriction(t *testing.T) { } func TestAccAzureRMAppService_manyIpRestrictions(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_manyIpRestrictions(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_manyIpRestrictions(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.0.subnet_mask", "255.255.255.255"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.1.ip_address", "20.20.20.0"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.1.subnet_mask", "255.255.255.0"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.2.ip_address", "30.30.0.0"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.2.subnet_mask", "255.255.0.0"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.3.ip_address", "192.168.1.2"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ip_restriction.3.subnet_mask", "255.255.255.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.ip_address", "10.10.10.10"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.0.subnet_mask", "255.255.255.255"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.1.ip_address", "20.20.20.0"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.1.subnet_mask", "255.255.255.0"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.2.ip_address", "30.30.0.0"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.2.subnet_mask", "255.255.0.0"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.3.ip_address", "192.168.1.2"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ip_restriction.3.subnet_mask", "255.255.255.0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_defaultDocuments(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_defaultDocuments(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_defaultDocuments(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.default_documents.0", "first.html"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.default_documents.1", "second.jsp"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.default_documents.2", "third.aspx"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.default_documents.0", "first.html"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.default_documents.1", "second.jsp"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.default_documents.2", "third.aspx"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_enabled(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_enabled(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_enabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_localMySql(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_localMySql(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_localMySql(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.local_mysql_enabled", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.local_mysql_enabled", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_applicationBlobStorageLogs(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_applicationBlobStorageLogs(ri, acceptance.Location()) - updated := testAccAzureRMAppService_applicationBlobStorageLogsWithAppSettings(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_applicationBlobStorageLogs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "logs.0.application_logs.0.azure_blob_storage.0.level", "Information"), - resource.TestCheckResourceAttr(resourceName, "logs.0.application_logs.0.azure_blob_storage.0.sas_url", "http://x.com/"), - resource.TestCheckResourceAttr(resourceName, "logs.0.application_logs.0.azure_blob_storage.0.retention_in_days", "3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.application_logs.0.azure_blob_storage.0.level", "Information"), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.application_logs.0.azure_blob_storage.0.sas_url", "http://x.com/"), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.application_logs.0.azure_blob_storage.0.retention_in_days", "3"), ), }, { - Config: updated, + Config: testAccAzureRMAppService_applicationBlobStorageLogsWithAppSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "logs.0.application_logs.0.azure_blob_storage.0.level", "Information"), - resource.TestCheckResourceAttr(resourceName, "logs.0.application_logs.0.azure_blob_storage.0.sas_url", "http://x.com/"), - resource.TestCheckResourceAttr(resourceName, "logs.0.application_logs.0.azure_blob_storage.0.retention_in_days", "3"), - resource.TestCheckResourceAttr(resourceName, "app_settings.foo", "bar"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.application_logs.0.azure_blob_storage.0.level", "Information"), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.application_logs.0.azure_blob_storage.0.sas_url", "http://x.com/"), + resource.TestCheckResourceAttr(data.ResourceName, "logs.0.application_logs.0.azure_blob_storage.0.retention_in_days", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.foo", "bar"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_httpFileSystemLogs(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_httpFileSystemLogs(ri, acceptance.Location()) - config2 := testAccAzureRMAppService_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_httpFileSystemLogs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: config2, + Config: testAccAzureRMAppService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_httpBlobStorageLogs(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - config := testAccAzureRMAppService_httpBlobStorageLogs(ri, rs, acceptance.Location()) - config2 := testAccAzureRMAppService_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_httpBlobStorageLogs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: config2, + Config: testAccAzureRMAppService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_httpFileSystemAndStorageBlobLogs(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - config := testAccAzureRMAppService_httpFileSystemAndStorageBlobLogs(ri, rs, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_httpFileSystemAndStorageBlobLogs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), + testCheckAzureRMAppServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_managedPipelineMode(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_managedPipelineMode(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_managedPipelineMode(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.managed_pipeline_mode", "Classic"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.managed_pipeline_mode", "Classic"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_tagsUpdate(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_tags(ri, acceptance.Location()) - updatedConfig := testAccAzureRMAppService_tagsUpdated(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMAppService_tagsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), - resource.TestCheckResourceAttr(resourceName, "tags.Terraform", "AcceptanceTests"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Terraform", "AcceptanceTests"), ), }, }, @@ -1150,107 +855,82 @@ func TestAccAzureRMAppService_tagsUpdate(t *testing.T) { } func TestAccAzureRMAppService_remoteDebugging(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_remoteDebugging(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_remoteDebugging(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.remote_debugging_enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.remote_debugging_version", "VS2015"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.remote_debugging_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.remote_debugging_version", "VS2015"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsDotNet2(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsDotNet(ri, acceptance.Location(), "v2.0") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsDotNet(data, "v2.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.dotnet_framework_version", "v2.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.dotnet_framework_version", "v2.0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsDotNet4(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsDotNet(ri, acceptance.Location(), "v4.0") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsDotNet(data, "v4.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.dotnet_framework_version", "v4.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.dotnet_framework_version", "v4.0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsDotNetUpdate(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsDotNet(ri, acceptance.Location(), "v2.0") - updatedConfig := testAccAzureRMAppService_windowsDotNet(ri, acceptance.Location(), "v4.0") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsDotNet(data, "v2.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.dotnet_framework_version", "v2.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.dotnet_framework_version", "v2.0"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMAppService_windowsDotNet(data, "v4.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.dotnet_framework_version", "v4.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.dotnet_framework_version", "v4.0"), ), }, }, @@ -1258,457 +938,343 @@ func TestAccAzureRMAppService_windowsDotNetUpdate(t *testing.T) { } func TestAccAzureRMAppService_windowsJava7Java(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "1.7", "JAVA", "9.3") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "1.7", "JAVA", "9.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.7"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JAVA"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.7"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "JAVA"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsJava8Java(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "1.8", "JAVA", "9.3") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "1.8", "JAVA", "9.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.8"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JAVA"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.8"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "JAVA"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsJava11Java(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "11", "JAVA", "9.3") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "11", "JAVA", "9.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "11"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JAVA"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "JAVA"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsJava7Jetty(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "1.7", "JETTY", "9.3") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "1.7", "JETTY", "9.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.7"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JETTY"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.7"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "JETTY"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsJava8Jetty(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "1.8", "JETTY", "9.3") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "1.8", "JETTY", "9.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.8"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JETTY"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.8"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "JETTY"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsJava11Jetty(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "11", "JETTY", "9.3") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "11", "JETTY", "9.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "11"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "JETTY"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "JETTY"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsJava7Tomcat(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "1.7", "TOMCAT", "9.0") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "1.7", "TOMCAT", "9.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.7"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.7"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "TOMCAT"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsJava8Tomcat(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "1.8", "TOMCAT", "9.0") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "1.8", "TOMCAT", "9.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.8"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.8"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "TOMCAT"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsJava11Tomcat(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "11", "TOMCAT", "9.0") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "11", "TOMCAT", "9.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "11"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "TOMCAT"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsJava7Minor(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "1.7.0_80", "TOMCAT", "9.0") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "1.7.0_80", "TOMCAT", "9.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.7.0_80"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.7.0_80"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "TOMCAT"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsJava8Minor(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsJava(ri, acceptance.Location(), "1.8.0_181", "TOMCAT", "9.0") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsJava(data, "1.8.0_181", "TOMCAT", "9.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_version", "1.8.0_181"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container", "TOMCAT"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.java_container_version", "9.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_version", "1.8.0_181"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container", "TOMCAT"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.java_container_version", "9.0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsPHP7(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsPHP(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsPHP(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.php_version", "7.3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.php_version", "7.3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_windowsPython(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_windowsPython(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_windowsPython(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.python_version", "3.4"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.python_version", "3.4"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_webSockets(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_webSockets(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_webSockets(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.websockets_enabled", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.websockets_enabled", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_scmType(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_scmType(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_scmType(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.scm_type", "LocalGit"), - resource.TestCheckResourceAttr(resourceName, "source_control.#", "1"), - resource.TestCheckResourceAttr(resourceName, "site_credential.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.scm_type", "LocalGit"), + resource.TestCheckResourceAttr(data.ResourceName, "source_control.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "site_credential.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_ftpsState(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_ftpsState(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_ftpsState(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ftps_state", "AllAllowed"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ftps_state", "AllAllowed"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_linuxFxVersion(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_linuxFxVersion(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_linuxFxVersion(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.always_on", "true"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.linux_fx_version", "DOCKER|(golang:latest)"), - resource.TestCheckResourceAttr(resourceName, "app_settings.WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.always_on", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.linux_fx_version", "DOCKER|(golang:latest)"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.WEBSITES_ENABLE_APP_SERVICE_STORAGE", "false"), ), }, }, @@ -1716,484 +1282,378 @@ func TestAccAzureRMAppService_linuxFxVersion(t *testing.T) { } func TestAccAzureRMAppService_minTls(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_minTls(ri, acceptance.Location(), "1.0") - updatedConfig := testAccAzureRMAppService_minTls(ri, acceptance.Location(), "1.1") - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_minTls(data, "1.0"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.min_tls_version", "1.0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.min_tls_version", "1.0"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: updatedConfig, + Config: testAccAzureRMAppService_minTls(data, "1.1"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.min_tls_version", "1.1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.min_tls_version", "1.1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_corsSettings(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_corsSettings(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_corsSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.#", "1"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.support_credentials", "true"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.#", "3"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.cors.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.cors.0.support_credentials", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.cors.0.allowed_origins.#", "3"), )}, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_authSettingsAdditionalLoginParams(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppService_authSettingsAdditionalLoginParams(ri, acceptance.Location(), tenantID) + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_authSettingsAdditionalLoginParams(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.additional_login_params.test_key", "test_value"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.additional_login_params.test_key", "test_value"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_authSettingsAdditionalAllowedExternalRedirectUrls(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppService_authSettingsAdditionalAllowedExternalRedirectUrls(ri, acceptance.Location(), tenantID) + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_authSettingsAdditionalAllowedExternalRedirectUrls(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.allowed_external_redirect_urls.#", "1"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.allowed_external_redirect_urls.0", "https://terra.form"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.allowed_external_redirect_urls.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.allowed_external_redirect_urls.0", "https://terra.form"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_authSettingsRuntimeVersion(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppService_authSettingsRuntimeVersion(ri, acceptance.Location(), tenantID) + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_authSettingsRuntimeVersion(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.runtime_version", "1.0"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.runtime_version", "1.0"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_authSettingsTokenRefreshExtensionHours(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppService_authSettingsTokenRefreshExtensionHours(ri, acceptance.Location(), tenantID) + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_authSettingsTokenRefreshExtensionHours(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.token_refresh_extension_hours", "75"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.token_refresh_extension_hours", "75"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_authSettingsUnauthenticatedClientAction(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppService_authSettingsUnauthenticatedClientAction(ri, acceptance.Location(), tenantID) + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_authSettingsUnauthenticatedClientAction(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.unauthenticated_client_action", "RedirectToLoginPage"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.unauthenticated_client_action", "RedirectToLoginPage"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_authSettingsTokenStoreEnabled(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppService_authSettingsTokenStoreEnabled(ri, acceptance.Location(), tenantID) + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_authSettingsTokenStoreEnabled(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.token_store_enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.token_store_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_aadAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMAppService_aadAuthSettings(ri, acceptance.Location(), tenantID) + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_aadAuthSettings(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_facebookAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_facebookAuthSettings(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_facebookAuthSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.facebook.0.app_id", "facebookappid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.facebook.0.app_secret", "facebookappsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.facebook.0.oauth_scopes.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.facebook.0.app_id", "facebookappid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.facebook.0.app_secret", "facebookappsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.facebook.0.oauth_scopes.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_googleAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_googleAuthSettings(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_googleAuthSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.google.0.client_id", "googleclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.google.0.client_secret", "googleclientsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.google.0.oauth_scopes.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.google.0.client_id", "googleclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.google.0.client_secret", "googleclientsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.google.0.oauth_scopes.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_microsoftAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_microsoftAuthSettings(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_microsoftAuthSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.client_id", "microsoftclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.client_secret", "microsoftclientsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.oauth_scopes.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.client_id", "microsoftclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.client_secret", "microsoftclientsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.oauth_scopes.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_twitterAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_twitterAuthSettings(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_twitterAuthSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.twitter.0.consumer_key", "twitterconsumerkey"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.twitter.0.consumer_secret", "twitterconsumersecret"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.twitter.0.consumer_key", "twitterconsumerkey"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.twitter.0.consumer_secret", "twitterconsumersecret"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_multiAuthSettings(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() + tenantID := os.Getenv("ARM_TENANT_ID") - config1 := testAccAzureRMAppService_aadAuthSettings(ri, acceptance.Location(), tenantID) - config2 := testAccAzureRMAppService_aadMicrosoftAuthSettings(ri, acceptance.Location(), tenantID) + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config1, + Config: testAccAzureRMAppService_aadAuthSettings(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: config2, + Config: testAccAzureRMAppService_aadMicrosoftAuthSettings(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.client_id", "microsoftclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.client_secret", "microsoftclientsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.microsoft.0.oauth_scopes.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.client_id", "microsoftclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.client_secret", "microsoftclientsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.microsoft.0.oauth_scopes.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppService_basicWindowsContainer(t *testing.T) { - resourceName := "azurerm_app_service.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAppService_basicWindowsContainer(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAppServiceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMAppService_basicWindowsContainer(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.windows_fx_version", "DOCKER|mcr.microsoft.com/azure-app-service/samples/aspnethelloworld:latest"), - resource.TestCheckResourceAttr(resourceName, "app_settings.DOCKER_REGISTRY_SERVER_URL", "https://mcr.microsoft.com"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.windows_fx_version", "DOCKER|mcr.microsoft.com/azure-app-service/samples/aspnethelloworld:latest"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.DOCKER_REGISTRY_SERVER_URL", "https://mcr.microsoft.com"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -2254,7 +1714,7 @@ func testCheckAzureRMAppServiceExists(resourceName string) resource.TestCheckFun } } -func testAccAzureRMAppService_basic(rInt int, location string) string { +func testAccAzureRMAppService_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2278,11 +1738,11 @@ resource "azurerm_app_service" "test" { resource_group_name = "${azurerm_resource_group.test.name}" app_service_plan_id = "${azurerm_app_service_plan.test.id}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_requiresImport(rInt int, location string) string { - template := testAccAzureRMAppService_basic(rInt, location) +func testAccAzureRMAppService_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAppService_basic(data) return fmt.Sprintf(` %s @@ -2295,7 +1755,7 @@ resource "azurerm_app_service" "import" { `, template) } -func testAccAzureRMAppService_freeTier(rInt int, location string) string { +func testAccAzureRMAppService_freeTier(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2323,10 +1783,10 @@ resource "azurerm_app_service" "test" { use_32_bit_worker_process = true } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_moved(rInt int, location string) string { +func testAccAzureRMAppService_moved(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2361,10 +1821,10 @@ resource "azurerm_app_service" "test" { resource_group_name = "${azurerm_resource_group.test.name}" app_service_plan_id = "${azurerm_app_service_plan.other.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_sharedTier(rInt int, location string) string { +func testAccAzureRMAppService_sharedTier(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2392,10 +1852,10 @@ resource "azurerm_app_service" "test" { use_32_bit_worker_process = true } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_alwaysOn(rInt int, location string) string { +func testAccAzureRMAppService_alwaysOn(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2423,10 +1883,10 @@ resource "azurerm_app_service" "test" { always_on = true } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_appCommandLine(rInt int, location string) string { +func testAccAzureRMAppService_appCommandLine(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2454,10 +1914,10 @@ resource "azurerm_app_service" "test" { app_command_line = "/sbin/myserver -b 0.0.0.0" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_httpsOnly(rInt int, location string) string { +func testAccAzureRMAppService_httpsOnly(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2482,10 +1942,10 @@ resource "azurerm_app_service" "test" { app_service_plan_id = "${azurerm_app_service_plan.test.id}" https_only = true } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_clientCertEnabled(rInt int, location string) string { +func testAccAzureRMAppService_clientCertEnabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2510,10 +1970,10 @@ resource "azurerm_app_service" "test" { app_service_plan_id = "${azurerm_app_service_plan.test.id}" client_cert_enabled = true } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_clientCertEnabledNotSet(rInt int, location string) string { +func testAccAzureRMAppService_clientCertEnabledNotSet(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2537,10 +1997,10 @@ resource "azurerm_app_service" "test" { resource_group_name = "${azurerm_resource_group.test.name}" app_service_plan_id = "${azurerm_app_service_plan.test.id}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_32Bit(rInt int, location string) string { +func testAccAzureRMAppService_32Bit(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2568,11 +2028,11 @@ resource "azurerm_app_service" "test" { use_32_bit_worker_process = true } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_backup(rInt int, rString, location string) string { - template := testAccAzureRMAppService_backupTemplate(rInt, rString, location) +func testAccAzureRMAppService_backup(data acceptance.TestData) string { + template := testAccAzureRMAppService_backupTemplate(data) return fmt.Sprintf(` %s @@ -2591,11 +2051,11 @@ resource "azurerm_app_service" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAppService_backupDisabled(rInt int, rString, location string) string { - template := testAccAzureRMAppService_backupTemplate(rInt, rString, location) +func testAccAzureRMAppService_backupDisabled(data acceptance.TestData) string { + template := testAccAzureRMAppService_backupTemplate(data) return fmt.Sprintf(` %s @@ -2615,11 +2075,11 @@ resource "azurerm_app_service" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAppService_backupUpdated(rInt int, rString, location string) string { - template := testAccAzureRMAppService_backupTemplate(rInt, rString, location) +func testAccAzureRMAppService_backupUpdated(data acceptance.TestData) string { + template := testAccAzureRMAppService_backupTemplate(data) return fmt.Sprintf(` %s @@ -2638,10 +2098,10 @@ resource "azurerm_app_service" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAppService_backupTemplate(rInt int, rString, location string) string { +func testAccAzureRMAppService_backupTemplate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2705,10 +2165,10 @@ resource "azurerm_app_service_plan" "test" { size = "S1" } } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMAppService_http2Enabled(rInt int, location string) string { +func testAccAzureRMAppService_http2Enabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2736,10 +2196,10 @@ resource "azurerm_app_service" "test" { http2_enabled = true } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_appSettings(rInt int, location string) string { +func testAccAzureRMAppService_appSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2767,18 +2227,18 @@ resource "azurerm_app_service" "test" { "foo" = "bar" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_clientAffinityEnabled(rInt int, location string) string { - return testAccAzureRMAppService_clientAffinity(rInt, location, true) +func testAccAzureRMAppService_clientAffinityEnabled(data acceptance.TestData) string { + return testAccAzureRMAppService_clientAffinity(data, true) } -func testAccAzureRMAppService_clientAffinityDisabled(rInt int, location string) string { - return testAccAzureRMAppService_clientAffinity(rInt, location, false) +func testAccAzureRMAppService_clientAffinityDisabled(data acceptance.TestData) string { + return testAccAzureRMAppService_clientAffinity(data, false) } -func testAccAzureRMAppService_clientAffinity(rInt int, location string, clientAffinity bool) string { +func testAccAzureRMAppService_clientAffinity(data acceptance.TestData, clientAffinity bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2803,10 +2263,10 @@ resource "azurerm_app_service" "test" { app_service_plan_id = "${azurerm_app_service_plan.test.id}" client_affinity_enabled = %t } -`, rInt, location, rInt, rInt, clientAffinity) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientAffinity) } -func testAccAzureRMAppService_virtualNetwork(rInt int, location string) string { +func testAccAzureRMAppService_virtualNetwork(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2846,10 +2306,10 @@ resource "azurerm_app_service" "test" { virtual_network_name = "${azurerm_virtual_network.test.name}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_virtualNetworkUpdated(rInt int, location string) string { +func testAccAzureRMAppService_virtualNetworkUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2901,10 +2361,10 @@ resource "azurerm_app_service" "test" { virtual_network_name = "${azurerm_virtual_network.second.name}" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_mangedServiceIdentity(rInt int, location string) string { +func testAccAzureRMAppService_mangedServiceIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2932,10 +2392,10 @@ resource "azurerm_app_service" "test" { type = "SystemAssigned" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_userAssignedIdentity(rInt int, location string) string { +func testAccAzureRMAppService_userAssignedIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2970,10 +2430,10 @@ resource "azurerm_app_service" "test" { identity_ids = ["${azurerm_user_assigned_identity.test.id}"] } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_multipleAssignedIdentities(rInt int, location string) string { +func testAccAzureRMAppService_multipleAssignedIdentities(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3008,10 +2468,10 @@ resource "azurerm_app_service" "test" { identity_ids = ["${azurerm_user_assigned_identity.test.id}"] } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_connectionStrings(rInt int, location string) string { +func testAccAzureRMAppService_connectionStrings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3047,10 +2507,10 @@ resource "azurerm_app_service" "test" { type = "PostgreSQL" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_connectionStringsUpdated(rInt int, location string) string { +func testAccAzureRMAppService_connectionStringsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3086,10 +2546,10 @@ resource "azurerm_app_service" "test" { type = "Custom" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_storageAccounts(rInt int, location string) string { +func testAccAzureRMAppService_storageAccounts(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3136,10 +2596,10 @@ resource "azurerm_app_service" "test" { mount_path = "/blobs" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_storageAccountsUpdated(rInt int, location string) string { +func testAccAzureRMAppService_storageAccountsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3201,10 +2661,10 @@ resource "azurerm_app_service" "test" { mount_path = "/files" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_oneIpRestriction(rInt int, location string) string { +func testAccAzureRMAppService_oneIpRestriction(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3234,10 +2694,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_oneVNetSubnetIpRestriction(rInt int, location string) string { +func testAccAzureRMAppService_oneVNetSubnetIpRestriction(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3281,10 +2741,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_manyIpRestrictions(rInt int, location string) string { +func testAccAzureRMAppService_manyIpRestrictions(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3329,10 +2789,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_zeroedIpRestriction(rInt int, location string) string { +func testAccAzureRMAppService_zeroedIpRestriction(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3360,10 +2820,10 @@ resource "azurerm_app_service" "test" { ip_restriction = [] } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_defaultDocuments(rInt int, location string) string { +func testAccAzureRMAppService_defaultDocuments(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3395,10 +2855,10 @@ resource "azurerm_app_service" "test" { ] } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_enabled(rInt int, location string) string { +func testAccAzureRMAppService_enabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3423,10 +2883,10 @@ resource "azurerm_app_service" "test" { app_service_plan_id = "${azurerm_app_service_plan.test.id}" enabled = false } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_localMySql(rInt int, location string) string { +func testAccAzureRMAppService_localMySql(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3454,10 +2914,10 @@ resource "azurerm_app_service" "test" { local_mysql_enabled = true } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_applicationBlobStorageLogs(rInt int, location string) string { +func testAccAzureRMAppService_applicationBlobStorageLogs(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3491,9 +2951,9 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_applicationBlobStorageLogsWithAppSettings(rInt int, location string) string { +func testAccAzureRMAppService_applicationBlobStorageLogsWithAppSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3529,9 +2989,9 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_httpFileSystemLogs(rInt int, location string) string { +func testAccAzureRMAppService_httpFileSystemLogs(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3564,10 +3024,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_httpBlobStorageLogs(rInt int, rString string, location string) string { - template := testAccAzureRMAppService_backupTemplate(rInt, rString, location) +func testAccAzureRMAppService_httpBlobStorageLogs(data acceptance.TestData) string { + template := testAccAzureRMAppService_backupTemplate(data) return fmt.Sprintf(` %s @@ -3586,11 +3046,11 @@ resource "azurerm_app_service" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAppService_httpFileSystemAndStorageBlobLogs(rInt int, rString string, location string) string { - template := testAccAzureRMAppService_backupTemplate(rInt, rString, location) +func testAccAzureRMAppService_httpFileSystemAndStorageBlobLogs(data acceptance.TestData) string { + template := testAccAzureRMAppService_backupTemplate(data) return fmt.Sprintf(` %s @@ -3616,10 +3076,10 @@ resource "azurerm_app_service" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAppService_managedPipelineMode(rInt int, location string) string { +func testAccAzureRMAppService_managedPipelineMode(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3647,10 +3107,10 @@ resource "azurerm_app_service" "test" { managed_pipeline_mode = "Classic" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_remoteDebugging(rInt int, location string) string { +func testAccAzureRMAppService_remoteDebugging(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3683,10 +3143,10 @@ resource "azurerm_app_service" "test" { Hello = "World" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_tags(rInt int, location string) string { +func testAccAzureRMAppService_tags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3714,10 +3174,10 @@ resource "azurerm_app_service" "test" { Hello = "World" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_tagsUpdated(rInt int, location string) string { +func testAccAzureRMAppService_tagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3746,10 +3206,10 @@ resource "azurerm_app_service" "test" { "Terraform" = "AcceptanceTests" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_windowsDotNet(rInt int, location, version string) string { +func testAccAzureRMAppService_windowsDotNet(data acceptance.TestData, version string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3777,10 +3237,10 @@ resource "azurerm_app_service" "test" { dotnet_framework_version = "%s" } } -`, rInt, location, rInt, rInt, version) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, version) } -func testAccAzureRMAppService_windowsJava(rInt int, location, javaVersion, container, containerVersion string) string { +func testAccAzureRMAppService_windowsJava(data acceptance.TestData, javaVersion, container, containerVersion string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3810,10 +3270,10 @@ resource "azurerm_app_service" "test" { java_container_version = "%s" } } -`, rInt, location, rInt, rInt, javaVersion, container, containerVersion) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, javaVersion, container, containerVersion) } -func testAccAzureRMAppService_windowsPHP(rInt int, location string) string { +func testAccAzureRMAppService_windowsPHP(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3841,10 +3301,10 @@ resource "azurerm_app_service" "test" { php_version = "7.3" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_windowsPython(rInt int, location string) string { +func testAccAzureRMAppService_windowsPython(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3872,10 +3332,10 @@ resource "azurerm_app_service" "test" { python_version = "3.4" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_webSockets(rInt int, location string) string { +func testAccAzureRMAppService_webSockets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3903,10 +3363,10 @@ resource "azurerm_app_service" "test" { websockets_enabled = true } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_scmType(rInt int, location string) string { +func testAccAzureRMAppService_scmType(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3934,10 +3394,10 @@ resource "azurerm_app_service" "test" { scm_type = "LocalGit" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_ftpsState(rInt int, location string) string { +func testAccAzureRMAppService_ftpsState(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3965,10 +3425,10 @@ resource "azurerm_app_service" "test" { ftps_state = "AllAllowed" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_linuxFxVersion(rInt int, location string) string { +func testAccAzureRMAppService_linuxFxVersion(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4001,10 +3461,10 @@ resource "azurerm_app_service" "test" { "WEBSITES_ENABLE_APP_SERVICE_STORAGE" = "false" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_minTls(rInt int, location string, tlsVersion string) string { +func testAccAzureRMAppService_minTls(data acceptance.TestData, tlsVersion string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4032,10 +3492,10 @@ resource "azurerm_app_service" "test" { min_tls_version = "%s" } } -`, rInt, location, rInt, rInt, tlsVersion) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, tlsVersion) } -func testAccAzureRMAppService_corsSettings(rInt int, location string) string { +func testAccAzureRMAppService_corsSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4071,10 +3531,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_authSettingsAdditionalLoginParams(rInt int, location string, tenantID string) string { +func testAccAzureRMAppService_authSettingsAdditionalLoginParams(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4122,10 +3582,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppService_authSettingsAdditionalAllowedExternalRedirectUrls(rInt int, location string, tenantID string) string { +func testAccAzureRMAppService_authSettingsAdditionalAllowedExternalRedirectUrls(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4173,10 +3633,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppService_authSettingsRuntimeVersion(rInt int, location string, tenantID string) string { +func testAccAzureRMAppService_authSettingsRuntimeVersion(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4221,10 +3681,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppService_authSettingsTokenRefreshExtensionHours(rInt int, location string, tenantID string) string { +func testAccAzureRMAppService_authSettingsTokenRefreshExtensionHours(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4269,10 +3729,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppService_authSettingsTokenStoreEnabled(rInt int, location string, tenantID string) string { +func testAccAzureRMAppService_authSettingsTokenStoreEnabled(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4317,10 +3777,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppService_authSettingsUnauthenticatedClientAction(rInt int, location string, tenantID string) string { +func testAccAzureRMAppService_authSettingsUnauthenticatedClientAction(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4365,10 +3825,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppService_aadAuthSettings(rInt int, location string, tenantID string) string { +func testAccAzureRMAppService_aadAuthSettings(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4412,10 +3872,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, tenantID) } -func testAccAzureRMAppService_facebookAuthSettings(rInt int, location string) string { +func testAccAzureRMAppService_facebookAuthSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4458,10 +3918,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_googleAuthSettings(rInt int, location string) string { +func testAccAzureRMAppService_googleAuthSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4504,10 +3964,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_microsoftAuthSettings(rInt int, location string) string { +func testAccAzureRMAppService_microsoftAuthSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4550,10 +4010,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_twitterAuthSettings(rInt int, location string) string { +func testAccAzureRMAppService_twitterAuthSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4592,10 +4052,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppService_aadMicrosoftAuthSettings(rInt int, location string, tenantID string) string { +func testAccAzureRMAppService_aadMicrosoftAuthSettings(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4649,10 +4109,10 @@ resource "azurerm_app_service" "test" { } } } -`, rInt, location, rInt, rInt, tenantID, web.AzureActiveDirectory) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, tenantID, web.AzureActiveDirectory) } -func testAccAzureRMAppService_basicWindowsContainer(rInt int, location string) string { +func testAccAzureRMAppService_basicWindowsContainer(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4688,5 +4148,5 @@ resource "azurerm_app_service" "test" { "DOCKER_REGISTRY_SERVER_PASSWORD" = "" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/web/resource_arm_app_service_virtual_network_association_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_virtual_network_association_test.go similarity index 86% rename from azurerm/internal/services/web/resource_arm_app_service_virtual_network_association_test.go rename to azurerm/internal/services/web/tests/resource_arm_app_service_virtual_network_association_test.go index 8bdce45f5b5e..8dd0402ca4ae 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_virtual_network_association_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_virtual_network_association_test.go @@ -1,4 +1,4 @@ -package web +package tests import ( "fmt" @@ -7,16 +7,15 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) +// TODO: requires import + func TestAccAzureRMAppServiceVirtualNetworkSwiftConnection_basic(t *testing.T) { - resourceName := "azurerm_app_service_virtual_network_swift_connection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service_virtual_network_swift_connection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,25 +23,19 @@ func TestAccAzureRMAppServiceVirtualNetworkSwiftConnection_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceVirtualNetworkSwiftConnection_basic(ri, location), + Config: testAccAzureRMAppServiceVirtualNetworkSwiftConnection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subnet_id"), + testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAppServiceVirtualNetworkSwiftConnection_update(t *testing.T) { - resourceName := "azurerm_app_service_virtual_network_swift_connection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service_virtual_network_swift_connection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,17 +43,17 @@ func TestAccAzureRMAppServiceVirtualNetworkSwiftConnection_update(t *testing.T) CheckDestroy: testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceVirtualNetworkSwiftConnection_basic(ri, location), + Config: testAccAzureRMAppServiceVirtualNetworkSwiftConnection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subnet_id"), + testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), ), }, { - Config: testAccAzureRMAppServiceVirtualNetworkSwiftConnection_update(ri, location), + Config: testAccAzureRMAppServiceVirtualNetworkSwiftConnection_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subnet_id"), + testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), ), }, }, @@ -68,9 +61,7 @@ func TestAccAzureRMAppServiceVirtualNetworkSwiftConnection_update(t *testing.T) } func TestAccAzureRMAppServiceVirtualNetworkSwiftConnection_disappears(t *testing.T) { - resourceName := "azurerm_app_service_virtual_network_swift_connection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_service_virtual_network_swift_connection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,11 +69,11 @@ func TestAccAzureRMAppServiceVirtualNetworkSwiftConnection_disappears(t *testing CheckDestroy: testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAppServiceVirtualNetworkSwiftConnection_basic(ri, location), + Config: testAccAzureRMAppServiceVirtualNetworkSwiftConnection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subnet_id"), - testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionDisappears(resourceName), + testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), + testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -182,7 +173,7 @@ func testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionDestroy(s *terraform return nil } -func testAccAzureRMAppServiceVirtualNetworkSwiftConnection_base(rInt int, location string) string { +func testAccAzureRMAppServiceVirtualNetworkSwiftConnection_base(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-appservice-%d" @@ -248,11 +239,11 @@ resource "azurerm_app_service" "test" { resource_group_name = "${azurerm_resource_group.test.name}" app_service_plan_id = "${azurerm_app_service_plan.test.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAppServiceVirtualNetworkSwiftConnection_basic(rInt int, location string) string { - template := testAccAzureRMAppServiceVirtualNetworkSwiftConnection_base(rInt, location) +func testAccAzureRMAppServiceVirtualNetworkSwiftConnection_basic(data acceptance.TestData) string { + template := testAccAzureRMAppServiceVirtualNetworkSwiftConnection_base(data) return fmt.Sprintf(` %s @@ -263,8 +254,8 @@ resource "azurerm_app_service_virtual_network_swift_connection" "test" { `, template) } -func testAccAzureRMAppServiceVirtualNetworkSwiftConnection_update(rInt int, location string) string { - template := testAccAzureRMAppServiceVirtualNetworkSwiftConnection_base(rInt, location) +func testAccAzureRMAppServiceVirtualNetworkSwiftConnection_update(data acceptance.TestData) string { + template := testAccAzureRMAppServiceVirtualNetworkSwiftConnection_base(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/web/resource_arm_function_app_test.go b/azurerm/internal/services/web/tests/resource_arm_function_app_test.go similarity index 67% rename from azurerm/internal/services/web/resource_arm_function_app_test.go rename to azurerm/internal/services/web/tests/resource_arm_function_app_test.go index b6c24660e1a2..5eefd8d64438 100644 --- a/azurerm/internal/services/web/resource_arm_function_app_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_function_app_test.go @@ -1,4 +1,4 @@ -package web +package tests import ( "fmt" @@ -14,15 +14,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMFunctionApp_basic(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_basic(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -30,61 +26,46 @@ func TestAccAzureRMFunctionApp_basic(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - testCheckAzureRMFunctionAppHasNoContentShare(resourceName), - resource.TestCheckResourceAttr(resourceName, "version", "~1"), - resource.TestCheckResourceAttrSet(resourceName, "outbound_ip_addresses"), - resource.TestCheckResourceAttrSet(resourceName, "possible_outbound_ip_addresses"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + testCheckAzureRMFunctionAppHasNoContentShare(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "version", "~1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "outbound_ip_addresses"), + resource.TestCheckResourceAttrSet(data.ResourceName, "possible_outbound_ip_addresses"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() - rs := strings.ToLower(acctest.RandString(11)) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFunctionApp_basic(ri, rs, location), + Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - testCheckAzureRMFunctionAppHasNoContentShare(resourceName), + testCheckAzureRMFunctionAppExists(data.ResourceName), + testCheckAzureRMFunctionAppHasNoContentShare(data.ResourceName), ), }, - { - Config: testAccAzureRMFunctionApp_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_function_app"), - }, + data.RequiresImportErrorStep(testAccAzureRMFunctionApp_requiresImport), }, }) } func TestAccAzureRMFunctionApp_tags(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_tags(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -92,28 +73,20 @@ func TestAccAzureRMFunctionApp_tags(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_tagsUpdate(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_tags(ri, rs, acceptance.Location()) - updatedConfig := testAccAzureRMFunctionApp_tagsUpdated(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -121,20 +94,20 @@ func TestAccAzureRMFunctionApp_tagsUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMFunctionApp_tagsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), - resource.TestCheckResourceAttr(resourceName, "tags.hello", "Berlin"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.hello", "Berlin"), ), }, }, @@ -142,11 +115,7 @@ func TestAccAzureRMFunctionApp_tagsUpdate(t *testing.T) { } func TestAccAzureRMFunctionApp_appSettings(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_basic(ri, rs, acceptance.Location()) - updatedConfig := testAccAzureRMFunctionApp_appSettings(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -154,42 +123,35 @@ func TestAccAzureRMFunctionApp_appSettings(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "app_settings.%", "0"), - resource.TestCheckResourceAttr(resourceName, "site_credential.#", "1"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "site_credential.#", "1"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMFunctionApp_appSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "app_settings.%", "1"), - resource.TestCheckResourceAttr(resourceName, "app_settings.hello", "world"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.hello", "world"), ), }, { - Config: config, + Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "app_settings.%", "0"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_siteConfig(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_alwaysOn(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -197,26 +159,19 @@ func TestAccAzureRMFunctionApp_siteConfig(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_alwaysOn(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.always_on", "true"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.always_on", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_linuxFxVersion(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_linuxFxVersion(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -224,27 +179,20 @@ func TestAccAzureRMFunctionApp_linuxFxVersion(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_linuxFxVersion(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "functionapp,linux,container"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.linux_fx_version", "DOCKER|(golang:latest)"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "functionapp,linux,container"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.linux_fx_version", "DOCKER|(golang:latest)"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_connectionStrings(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_connectionStrings(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -252,32 +200,21 @@ func TestAccAzureRMFunctionApp_connectionStrings(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_connectionStrings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "connection_string.0.name", "Example"), - resource.TestCheckResourceAttr(resourceName, "connection_string.0.value", "some-postgresql-connection-string"), - resource.TestCheckResourceAttr(resourceName, "connection_string.0.type", "PostgreSQL"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.0.name", "Example"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.0.value", "some-postgresql-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.0.type", "PostgreSQL"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_siteConfigMulti(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - configBase := testAccAzureRMFunctionApp_basic(ri, rs, acceptance.Location()) - configUpdate1 := testAccAzureRMFunctionApp_appSettings(ri, rs, acceptance.Location()) - configUpdate2 := testAccAzureRMFunctionApp_appSettingsAlwaysOn(ri, rs, acceptance.Location()) - configUpdate3 := testAccAzureRMFunctionApp_appSettingsAlwaysOnLinuxFxVersion(ri, rs, acceptance.Location()) - configUpdate4 := testAccAzureRMFunctionApp_appSettingsAlwaysOnLinuxFxVersionConnectionStrings(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -285,52 +222,52 @@ func TestAccAzureRMFunctionApp_siteConfigMulti(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: configBase, + Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "app_settings.%", "0"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "0"), ), }, { - Config: configUpdate1, + Config: testAccAzureRMFunctionApp_appSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "app_settings.%", "1"), - resource.TestCheckResourceAttr(resourceName, "app_settings.hello", "world"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.hello", "world"), ), }, { - Config: configUpdate2, + Config: testAccAzureRMFunctionApp_appSettingsAlwaysOn(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "app_settings.%", "1"), - resource.TestCheckResourceAttr(resourceName, "app_settings.hello", "world"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.always_on", "true"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.hello", "world"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.always_on", "true"), ), }, { - Config: configUpdate3, + Config: testAccAzureRMFunctionApp_appSettingsAlwaysOnLinuxFxVersion(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "functionapp,linux,container"), - resource.TestCheckResourceAttr(resourceName, "app_settings.%", "1"), - resource.TestCheckResourceAttr(resourceName, "app_settings.hello", "world"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.always_on", "true"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.linux_fx_version", "DOCKER|(golang:latest)"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "functionapp,linux,container"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.hello", "world"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.always_on", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.linux_fx_version", "DOCKER|(golang:latest)"), ), }, { - Config: configUpdate4, + Config: testAccAzureRMFunctionApp_appSettingsAlwaysOnLinuxFxVersionConnectionStrings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "functionapp,linux,container"), - resource.TestCheckResourceAttr(resourceName, "app_settings.%", "1"), - resource.TestCheckResourceAttr(resourceName, "app_settings.hello", "world"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.always_on", "true"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.linux_fx_version", "DOCKER|(golang:latest)"), - resource.TestCheckResourceAttr(resourceName, "connection_string.0.name", "Example"), - resource.TestCheckResourceAttr(resourceName, "connection_string.0.value", "some-postgresql-connection-string"), - resource.TestCheckResourceAttr(resourceName, "connection_string.0.type", "PostgreSQL"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "functionapp,linux,container"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "app_settings.hello", "world"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.always_on", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.linux_fx_version", "DOCKER|(golang:latest)"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.0.name", "Example"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.0.value", "some-postgresql-connection-string"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_string.0.type", "PostgreSQL"), ), }, }, @@ -338,11 +275,7 @@ func TestAccAzureRMFunctionApp_siteConfigMulti(t *testing.T) { } func TestAccAzureRMFunctionApp_updateVersion(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - preConfig := testAccAzureRMFunctionApp_version(ri, rs, acceptance.Location(), "~1") - postConfig := testAccAzureRMFunctionApp_version(ri, rs, acceptance.Location(), "~2") + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -350,17 +283,17 @@ func TestAccAzureRMFunctionApp_updateVersion(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMFunctionApp_version(data, "~1"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "version", "~1"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "version", "~1"), ), }, { - Config: postConfig, + Config: testAccAzureRMFunctionApp_version(data, "~2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "version", "~2"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "version", "~2"), ), }, }, @@ -368,12 +301,7 @@ func TestAccAzureRMFunctionApp_updateVersion(t *testing.T) { } func TestAccAzureRMFunctionApp_3264bit(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - config := testAccAzureRMFunctionApp_basic(ri, rs, location) - updatedConfig := testAccAzureRMFunctionApp_64bit(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -381,17 +309,17 @@ func TestAccAzureRMFunctionApp_3264bit(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.use_32_bit_worker_process", "true"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.use_32_bit_worker_process", "true"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMFunctionApp_64bit(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.use_32_bit_worker_process", "false"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.use_32_bit_worker_process", "false"), ), }, }, @@ -399,11 +327,7 @@ func TestAccAzureRMFunctionApp_3264bit(t *testing.T) { } func TestAccAzureRMFunctionApp_httpsOnly(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - config := testAccAzureRMFunctionApp_httpsOnly(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -411,10 +335,10 @@ func TestAccAzureRMFunctionApp_httpsOnly(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_httpsOnly(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "https_only", "true"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "https_only", "true"), ), }, }, @@ -422,11 +346,7 @@ func TestAccAzureRMFunctionApp_httpsOnly(t *testing.T) { } func TestAccAzureRMFunctionApp_consumptionPlan(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - config := testAccAzureRMFunctionApp_consumptionPlan(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -434,11 +354,11 @@ func TestAccAzureRMFunctionApp_consumptionPlan(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_consumptionPlan(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - testCheckAzureRMFunctionAppHasContentShare(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.use_32_bit_worker_process", "true"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + testCheckAzureRMFunctionAppHasContentShare(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.use_32_bit_worker_process", "true"), ), }, }, @@ -446,11 +366,7 @@ func TestAccAzureRMFunctionApp_consumptionPlan(t *testing.T) { } func TestAccAzureRMFunctionApp_consumptionPlanUppercaseName(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - config := testAccAzureRMFunctionApp_consumptionPlanUppercaseName(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -458,27 +374,20 @@ func TestAccAzureRMFunctionApp_consumptionPlanUppercaseName(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_consumptionPlanUppercaseName(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - testCheckAzureRMFunctionAppHasContentShare(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.use_32_bit_worker_process", "true"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + testCheckAzureRMFunctionAppHasContentShare(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.use_32_bit_worker_process", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_createIdentity(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_basicIdentity(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -486,13 +395,13 @@ func TestAccAzureRMFunctionApp_createIdentity(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_basicIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.#", "1"), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, }, @@ -500,12 +409,7 @@ func TestAccAzureRMFunctionApp_createIdentity(t *testing.T) { } func TestAccAzureRMFunctionApp_updateIdentity(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - - preConfig := testAccAzureRMFunctionApp_basic(ri, rs, acceptance.Location()) - postConfig := testAccAzureRMFunctionApp_basicIdentity(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -513,20 +417,20 @@ func TestAccAzureRMFunctionApp_updateIdentity(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.#", "0"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.#", "0"), ), }, { - Config: postConfig, + Config: testAccAzureRMFunctionApp_basicIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.#", "1"), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, }, @@ -534,10 +438,7 @@ func TestAccAzureRMFunctionApp_updateIdentity(t *testing.T) { } func TestAccAzureRMFunctionApp_loggingDisabled(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_loggingDisabled(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -545,30 +446,20 @@ func TestAccAzureRMFunctionApp_loggingDisabled(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_loggingDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - testCheckAzureRMFunctionAppHasNoContentShare(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_builtin_logging", "false"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + testCheckAzureRMFunctionAppHasNoContentShare(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_builtin_logging", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_updateLogging(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - enabledConfig := testAccAzureRMFunctionApp_basic(ri, rs, location) - disabledConfig := testAccAzureRMFunctionApp_loggingDisabled(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -576,24 +467,24 @@ func TestAccAzureRMFunctionApp_updateLogging(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: enabledConfig, + Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_builtin_logging", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_builtin_logging", "true"), ), }, { - Config: disabledConfig, + Config: testAccAzureRMFunctionApp_loggingDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_builtin_logging", "false"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_builtin_logging", "false"), ), }, { - Config: enabledConfig, + Config: testAccAzureRMFunctionApp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_builtin_logging", "true"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_builtin_logging", "true"), ), }, }, @@ -601,11 +492,9 @@ func TestAccAzureRMFunctionApp_updateLogging(t *testing.T) { } func TestAccAzureRMFunctionApp_authSettings(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") + tenantID := os.Getenv("ARM_TENANT_ID") - config := testAccAzureRMFunctionApp_authSettings(ri, rs, acceptance.Location(), tenantID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -613,37 +502,30 @@ func TestAccAzureRMFunctionApp_authSettings(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_authSettings(data, tenantID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAppServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.runtime_version", "1.0"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.unauthenticated_client_action", "RedirectToLoginPage"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.token_refresh_extension_hours", "75"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.token_store_enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.additional_login_params.test_key", "test_value"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.allowed_external_redirect_urls.#", "1"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.allowed_external_redirect_urls.0", "https://terra.form"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), - resource.TestCheckResourceAttr(resourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), + testCheckAzureRMAppServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.issuer", fmt.Sprintf("https://sts.windows.net/%s", tenantID)), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.runtime_version", "1.0"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.unauthenticated_client_action", "RedirectToLoginPage"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.token_refresh_extension_hours", "75"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.token_store_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.additional_login_params.test_key", "test_value"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.allowed_external_redirect_urls.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.allowed_external_redirect_urls.0", "https://terra.form"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_id", "aadclientid"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.client_secret", "aadsecret"), + resource.TestCheckResourceAttr(data.ResourceName, "auth_settings.0.active_directory.0.allowed_audiences.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_corsSettings(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_corsSettings(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -651,29 +533,23 @@ func TestAccAzureRMFunctionApp_corsSettings(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_corsSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.#", "1"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.support_credentials", "true"), - resource.TestCheckResourceAttr(resourceName, "site_config.0.cors.0.allowed_origins.#", "4"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.cors.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.cors.0.support_credentials", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.cors.0.allowed_origins.#", "4"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_vnetName(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") + vnetName := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_vnetName(ri, rs, acceptance.Location(), vnetName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -681,26 +557,19 @@ func TestAccAzureRMFunctionApp_vnetName(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_vnetName(data, vnetName), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.virtual_network_name", vnetName), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.virtual_network_name", vnetName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_enableHttp2(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_enableHttp2(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -708,26 +577,19 @@ func TestAccAzureRMFunctionApp_enableHttp2(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_enableHttp2(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.http2_enabled", "true"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.http2_enabled", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_minTlsVersion(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_minTlsVersion(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -735,26 +597,19 @@ func TestAccAzureRMFunctionApp_minTlsVersion(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_minTlsVersion(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.min_tls_version", "1.2"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.min_tls_version", "1.2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFunctionApp_ftpsState(t *testing.T) { - resourceName := "azurerm_function_app.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMFunctionApp_ftpsState(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_function_app", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -762,17 +617,13 @@ func TestAccAzureRMFunctionApp_ftpsState(t *testing.T) { CheckDestroy: testCheckAzureRMFunctionAppDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFunctionApp_ftpsState(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFunctionAppExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "site_config.0.ftps_state", "AllAllowed"), + testCheckAzureRMFunctionAppExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "site_config.0.ftps_state", "AllAllowed"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -896,7 +747,7 @@ func testCheckAzureRMFunctionAppHasNoContentShare(resourceName string) resource. } } -func testAccAzureRMFunctionApp_basic(rInt int, storage string, location string) string { +func testAccAzureRMFunctionApp_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -929,11 +780,11 @@ resource "azurerm_function_app" "test" { app_service_plan_id = "${azurerm_app_service_plan.test.id}" storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}" } -`, rInt, location, storage) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_requiresImport(rInt int, storage, location string) string { - template := testAccAzureRMFunctionApp_basic(rInt, storage, location) +func testAccAzureRMFunctionApp_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMFunctionApp_basic(data) return fmt.Sprintf(` %s @@ -947,7 +798,7 @@ resource "azurerm_function_app" "import" { `, template) } -func testAccAzureRMFunctionApp_tags(rInt int, storage string, location string) string { +func testAccAzureRMFunctionApp_tags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -984,10 +835,10 @@ resource "azurerm_function_app" "test" { environment = "production" } } -`, rInt, location, storage) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_tagsUpdated(rInt int, storage string, location string) string { +func testAccAzureRMFunctionApp_tagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1025,10 +876,10 @@ resource "azurerm_function_app" "test" { hello = "Berlin" } } -`, rInt, location, storage) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_version(rInt int, storage string, location string, version string) string { +func testAccAzureRMFunctionApp_version(data acceptance.TestData, version string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1062,10 +913,10 @@ resource "azurerm_function_app" "test" { version = "%[4]s" storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}" } -`, rInt, location, storage, version) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, version) } -func testAccAzureRMFunctionApp_appSettings(rInt int, rString, location string) string { +func testAccAzureRMFunctionApp_appSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1102,10 +953,10 @@ resource "azurerm_function_app" "test" { "hello" = "world" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_alwaysOn(rInt int, rString, location string) string { +func testAccAzureRMFunctionApp_alwaysOn(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1142,10 +993,10 @@ resource "azurerm_function_app" "test" { always_on = true } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_linuxFxVersion(rInt int, rString, location string) string { +func testAccAzureRMFunctionApp_linuxFxVersion(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1186,10 +1037,10 @@ resource "azurerm_function_app" "test" { linux_fx_version = "DOCKER|(golang:latest)" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_connectionStrings(rInt int, rString, location string) string { +func testAccAzureRMFunctionApp_connectionStrings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1228,10 +1079,10 @@ resource "azurerm_function_app" "test" { type = "PostgreSQL" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_appSettingsAlwaysOn(rInt int, rString, location string) string { +func testAccAzureRMFunctionApp_appSettingsAlwaysOn(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1272,10 +1123,10 @@ resource "azurerm_function_app" "test" { always_on = true } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_appSettingsAlwaysOnLinuxFxVersion(rInt int, rString, location string) string { +func testAccAzureRMFunctionApp_appSettingsAlwaysOnLinuxFxVersion(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1321,10 +1172,10 @@ resource "azurerm_function_app" "test" { linux_fx_version = "DOCKER|(golang:latest)" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_appSettingsAlwaysOnLinuxFxVersionConnectionStrings(rInt int, rString, location string) string { +func testAccAzureRMFunctionApp_appSettingsAlwaysOnLinuxFxVersionConnectionStrings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1376,10 +1227,10 @@ resource "azurerm_function_app" "test" { type = "PostgreSQL" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_64bit(rInt int, rString string, location string) string { +func testAccAzureRMFunctionApp_64bit(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1416,10 +1267,10 @@ resource "azurerm_function_app" "test" { use_32_bit_worker_process = false } } -`, rInt, location, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFunctionApp_httpsOnly(rInt int, rString string, location string) string { +func testAccAzureRMFunctionApp_httpsOnly(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1453,10 +1304,10 @@ resource "azurerm_function_app" "test" { storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}" https_only = true } -`, rInt, location, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFunctionApp_consumptionPlan(rInt int, rString string, location string) string { +func testAccAzureRMFunctionApp_consumptionPlan(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1490,10 +1341,10 @@ resource "azurerm_function_app" "test" { app_service_plan_id = "${azurerm_app_service_plan.test.id}" storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}" } -`, rInt, location, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFunctionApp_consumptionPlanUppercaseName(rInt int, rString string, location string) string { +func testAccAzureRMFunctionApp_consumptionPlanUppercaseName(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1527,10 +1378,10 @@ resource "azurerm_function_app" "test" { app_service_plan_id = "${azurerm_app_service_plan.test.id}" storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}" } -`, rInt, location, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFunctionApp_basicIdentity(rInt int, storage string, location string) string { +func testAccAzureRMFunctionApp_basicIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1567,10 +1418,10 @@ resource "azurerm_function_app" "test" { type = "SystemAssigned" } } -`, rInt, location, storage) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_loggingDisabled(rInt int, storage string, location string) string { +func testAccAzureRMFunctionApp_loggingDisabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1604,10 +1455,10 @@ resource "azurerm_function_app" "test" { storage_connection_string = "${azurerm_storage_account.test.primary_connection_string}" enable_builtin_logging = false } -`, rInt, location, storage) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_authSettings(rInt int, storage string, location string, tenantID string) string { +func testAccAzureRMFunctionApp_authSettings(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1666,10 +1517,10 @@ resource "azurerm_function_app" "test" { } } } -`, rInt, location, storage, tenantID) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, tenantID) } -func testAccAzureRMFunctionApp_corsSettings(rInt int, storage string, location string) string { +func testAccAzureRMFunctionApp_corsSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1715,10 +1566,10 @@ resource "azurerm_function_app" "test" { } } } -`, rInt, location, storage) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMFunctionApp_vnetName(rInt int, storage, location, vnetName string) string { +func testAccAzureRMFunctionApp_vnetName(data acceptance.TestData, vnetName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1755,10 +1606,10 @@ resource "azurerm_function_app" "test" { virtual_network_name = "%[4]s" } } -`, rInt, location, storage, vnetName) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, vnetName) } -func testAccAzureRMFunctionApp_enableHttp2(rInt int, rString string, location string) string { +func testAccAzureRMFunctionApp_enableHttp2(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1795,10 +1646,10 @@ resource "azurerm_function_app" "test" { http2_enabled = true } } -`, rInt, location, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFunctionApp_minTlsVersion(rInt int, rString string, location string) string { +func testAccAzureRMFunctionApp_minTlsVersion(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1835,10 +1686,10 @@ resource "azurerm_function_app" "test" { min_tls_version = "1.2" } } -`, rInt, location, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFunctionApp_ftpsState(rInt int, rString string, location string) string { +func testAccAzureRMFunctionApp_ftpsState(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1875,5 +1726,5 @@ resource "azurerm_function_app" "test" { ftps_state = "AllAllowed" } } -`, rInt, location, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/web/testdata/app_service_certificate.pfx b/azurerm/internal/services/web/tests/testdata/app_service_certificate.pfx similarity index 100% rename from azurerm/internal/services/web/testdata/app_service_certificate.pfx rename to azurerm/internal/services/web/tests/testdata/app_service_certificate.pfx diff --git a/azurerm/internal/services/web/testdata/app_service_certificate_nopassword.pfx b/azurerm/internal/services/web/tests/testdata/app_service_certificate_nopassword.pfx similarity index 100% rename from azurerm/internal/services/web/testdata/app_service_certificate_nopassword.pfx rename to azurerm/internal/services/web/tests/testdata/app_service_certificate_nopassword.pfx diff --git a/azurerm/internal/services/web/validation_test.go b/azurerm/internal/services/web/validation_test.go new file mode 100644 index 000000000000..212ac37d14ae --- /dev/null +++ b/azurerm/internal/services/web/validation_test.go @@ -0,0 +1,83 @@ +package web + +import "testing" + +func TestAzureRMAppServicePlanName_validation(t *testing.T) { + cases := []struct { + Value string + ErrCount int + }{ + { + Value: "ab", + ErrCount: 0, + }, + { + Value: "abc", + ErrCount: 0, + }, + { + Value: "webapp1", + ErrCount: 0, + }, + { + Value: "hello-world", + ErrCount: 0, + }, + { + Value: "hello_world", + ErrCount: 0, + }, + { + Value: "helloworld21!", + ErrCount: 1, + }, + } + + for _, tc := range cases { + _, errors := validateAppServicePlanName(tc.Value, "azurerm_app_service_plan") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the App Service Plan Name to trigger a validation error for '%s'", tc.Value) + } + } +} + +func TestAzureRMAppServiceName_validation(t *testing.T) { + cases := []struct { + Value string + ErrCount int + }{ + { + Value: "ab", + ErrCount: 0, + }, + { + Value: "abc", + ErrCount: 0, + }, + { + Value: "webapp1", + ErrCount: 0, + }, + { + Value: "hello-world", + ErrCount: 0, + }, + { + Value: "hello_world", + ErrCount: 1, + }, + { + Value: "helloworld21!", + ErrCount: 1, + }, + } + + for _, tc := range cases { + _, errors := validateAppServiceName(tc.Value, "azurerm_app_service") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the App Service Name to trigger a validation error for '%s'", tc.Value) + } + } +} From b8b99969d04c2226c87a4cbf6b2fd2d6ec1c8b12 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 18:27:30 +0100 Subject: [PATCH 090/203] trafficmanager: switching to use the new test structure --- ...ffic_manager_geographical_location_test.go | 26 +- ...ource_arm_traffic_manager_endpoint_test.go | 258 ++++++++--------- ...source_arm_traffic_manager_profile_test.go | 262 +++++++----------- 3 files changed, 223 insertions(+), 323 deletions(-) rename azurerm/internal/services/trafficmanager/{ => tests}/data_source_traffic_manager_geographical_location_test.go (67%) rename azurerm/internal/services/trafficmanager/{ => tests}/resource_arm_traffic_manager_endpoint_test.go (78%) rename azurerm/internal/services/trafficmanager/{ => tests}/resource_arm_traffic_manager_profile_test.go (64%) diff --git a/azurerm/internal/services/trafficmanager/data_source_traffic_manager_geographical_location_test.go b/azurerm/internal/services/trafficmanager/tests/data_source_traffic_manager_geographical_location_test.go similarity index 67% rename from azurerm/internal/services/trafficmanager/data_source_traffic_manager_geographical_location_test.go rename to azurerm/internal/services/trafficmanager/tests/data_source_traffic_manager_geographical_location_test.go index 0ded980f95e4..4e50fdd726ca 100644 --- a/azurerm/internal/services/trafficmanager/data_source_traffic_manager_geographical_location_test.go +++ b/azurerm/internal/services/trafficmanager/tests/data_source_traffic_manager_geographical_location_test.go @@ -1,4 +1,4 @@ -package trafficmanager +package tests import ( "fmt" @@ -9,7 +9,7 @@ import ( ) func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_europe(t *testing.T) { - dataSourceName := "data.azurerm_traffic_manager_geographical_location.test" + data := acceptance.BuildTestData(t, "data.azurerm_traffic_manager_geographical_location", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -18,8 +18,8 @@ func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_europe(t *testin { Config: testAccAzureRMDataSourceTrafficManagerGeographicalLocation_template("Europe"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "GEO-EU"), - resource.TestCheckResourceAttr(dataSourceName, "name", "Europe"), + resource.TestCheckResourceAttr(data.ResourceName, "id", "GEO-EU"), + resource.TestCheckResourceAttr(data.ResourceName, "name", "Europe"), ), }, }, @@ -27,7 +27,7 @@ func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_europe(t *testin } func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_germany(t *testing.T) { - dataSourceName := "data.azurerm_traffic_manager_geographical_location.test" + data := acceptance.BuildTestData(t, "data.azurerm_traffic_manager_geographical_location", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -36,8 +36,8 @@ func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_germany(t *testi { Config: testAccAzureRMDataSourceTrafficManagerGeographicalLocation_template("Germany"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "DE"), - resource.TestCheckResourceAttr(dataSourceName, "name", "Germany"), + resource.TestCheckResourceAttr(data.ResourceName, "id", "DE"), + resource.TestCheckResourceAttr(data.ResourceName, "name", "Germany"), ), }, }, @@ -45,7 +45,7 @@ func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_germany(t *testi } func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_unitedKingdom(t *testing.T) { - dataSourceName := "data.azurerm_traffic_manager_geographical_location.test" + data := acceptance.BuildTestData(t, "data.azurerm_traffic_manager_geographical_location", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,8 +54,8 @@ func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_unitedKingdom(t { Config: testAccAzureRMDataSourceTrafficManagerGeographicalLocation_template("United Kingdom"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "GB"), - resource.TestCheckResourceAttr(dataSourceName, "name", "United Kingdom"), + resource.TestCheckResourceAttr(data.ResourceName, "id", "GB"), + resource.TestCheckResourceAttr(data.ResourceName, "name", "United Kingdom"), ), }, }, @@ -63,7 +63,7 @@ func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_unitedKingdom(t } func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_world(t *testing.T) { - dataSourceName := "data.azurerm_traffic_manager_geographical_location.test" + data := acceptance.BuildTestData(t, "data.azurerm_traffic_manager_geographical_location", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -72,8 +72,8 @@ func TestAccAzureRMDataSourceTrafficManagerGeographicalLocation_world(t *testing { Config: testAccAzureRMDataSourceTrafficManagerGeographicalLocation_template("World"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "WORLD"), - resource.TestCheckResourceAttr(dataSourceName, "name", "World"), + resource.TestCheckResourceAttr(data.ResourceName, "id", "WORLD"), + resource.TestCheckResourceAttr(data.ResourceName, "name", "World"), ), }, }, diff --git a/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_endpoint_test.go b/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_endpoint_test.go similarity index 78% rename from azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_endpoint_test.go rename to azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_endpoint_test.go index d045f2da7e2e..9142dea526d9 100644 --- a/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_endpoint_test.go +++ b/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_endpoint_test.go @@ -1,4 +1,4 @@ -package trafficmanager +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMTrafficManagerEndpoint_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "testExternal") azureResourceName := "azurerm_traffic_manager_endpoint.testAzure" - externalResourceName := "azurerm_traffic_manager_endpoint.testExternal" - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,19 +23,15 @@ func TestAccAzureRMTrafficManagerEndpoint_basic(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTrafficManagerEndpoint_basic(ri, acceptance.Location()), + Config: testAccAzureRMTrafficManagerEndpoint_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMTrafficManagerEndpointExists(azureResourceName), - testCheckAzureRMTrafficManagerEndpointExists(externalResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), resource.TestCheckResourceAttr(azureResourceName, "endpoint_status", "Enabled"), - resource.TestCheckResourceAttr(externalResourceName, "endpoint_status", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint_status", "Enabled"), ), }, - { - ResourceName: externalResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,9 +41,8 @@ func TestAccAzureRMTrafficManagerEndpoint_requiresImport(t *testing.T) { return } - azureResourceName := "azurerm_traffic_manager_endpoint.testAzure" + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "testAzure") externalResourceName := "azurerm_traffic_manager_endpoint.testExternal" - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,26 +50,22 @@ func TestAccAzureRMTrafficManagerEndpoint_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTrafficManagerEndpoint_basic(ri, acceptance.Location()), + Config: testAccAzureRMTrafficManagerEndpoint_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(azureResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(externalResourceName), - resource.TestCheckResourceAttr(azureResourceName, "endpoint_status", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint_status", "Enabled"), resource.TestCheckResourceAttr(externalResourceName, "endpoint_status", "Enabled"), ), }, - { - Config: testAccAzureRMTrafficManagerEndpoint_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_traffic_manager_endpoint"), - }, + data.RequiresImportErrorStep(testAccAzureRMTrafficManagerEndpoint_requiresImport), }, }) } func TestAccAzureRMTrafficManagerEndpoint_disappears(t *testing.T) { - azureResourceName := "azurerm_traffic_manager_endpoint.testAzure" + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "testAzure") externalResourceName := "azurerm_traffic_manager_endpoint.testExternal" - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,13 +73,13 @@ func TestAccAzureRMTrafficManagerEndpoint_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTrafficManagerEndpoint_basic(ri, acceptance.Location()), + Config: testAccAzureRMTrafficManagerEndpoint_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(azureResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(externalResourceName), - resource.TestCheckResourceAttr(azureResourceName, "endpoint_status", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint_status", "Enabled"), resource.TestCheckResourceAttr(externalResourceName, "endpoint_status", "Enabled"), - testCheckAzureRMTrafficManagerEndpointDisappears(azureResourceName), + testCheckAzureRMTrafficManagerEndpointDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -99,11 +88,8 @@ func TestAccAzureRMTrafficManagerEndpoint_disappears(t *testing.T) { } func TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal(t *testing.T) { - azureResourceName := "azurerm_traffic_manager_endpoint.testAzure" + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "testAzure") externalResourceName := "azurerm_traffic_manager_endpoint.testExternal" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMTrafficManagerEndpoint_basic(ri, acceptance.Location()) - postConfig := testAccAzureRMTrafficManagerEndpoint_basicDisableExternal(ri, acceptance.Location()) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,20 +97,20 @@ func TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMTrafficManagerEndpoint_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(azureResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(externalResourceName), - resource.TestCheckResourceAttr(azureResourceName, "endpoint_status", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint_status", "Enabled"), resource.TestCheckResourceAttr(externalResourceName, "endpoint_status", "Enabled"), ), }, { - Config: postConfig, + Config: testAccAzureRMTrafficManagerEndpoint_basicDisableExternal(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(azureResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(externalResourceName), - resource.TestCheckResourceAttr(azureResourceName, "endpoint_status", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint_status", "Enabled"), resource.TestCheckResourceAttr(externalResourceName, "endpoint_status", "Disabled"), ), }, @@ -134,34 +120,29 @@ func TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal(t *testing.T) { // Altering weight might be used to ramp up migration traffic func TestAccAzureRMTrafficManagerEndpoint_updateWeight(t *testing.T) { - firstResourceName := "azurerm_traffic_manager_endpoint.testExternal" + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "testExternal") secondResourceName := "azurerm_traffic_manager_endpoint.testExternalNew" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMTrafficManagerEndpoint_weight(ri, location) - postConfig := testAccAzureRMTrafficManagerEndpoint_updateWeight(ri, location) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMTrafficManagerEndpoint_weight(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(firstResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "weight", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "weight", "50"), resource.TestCheckResourceAttr(secondResourceName, "weight", "50"), ), }, { - Config: postConfig, + Config: testAccAzureRMTrafficManagerEndpoint_updateWeight(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(firstResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "weight", "25"), + resource.TestCheckResourceAttr(data.ResourceName, "weight", "25"), resource.TestCheckResourceAttr(secondResourceName, "weight", "75"), ), }, @@ -170,40 +151,35 @@ func TestAccAzureRMTrafficManagerEndpoint_updateWeight(t *testing.T) { } func TestAccAzureRMTrafficManagerEndpoint_updateSubnets(t *testing.T) { - firstResourceName := "azurerm_traffic_manager_endpoint.testExternal" + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "testExternal") secondResourceName := "azurerm_traffic_manager_endpoint.testExternalNew" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMTrafficManagerEndpoint_subnets(ri, location) - postConfig := testAccAzureRMTrafficManagerEndpoint_updateSubnets(ri, location) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMTrafficManagerEndpoint_subnets(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(firstResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "subnet.#", "2"), - resource.TestCheckResourceAttr(firstResourceName, "subnet.0.first", "1.2.3.0"), - resource.TestCheckResourceAttr(firstResourceName, "subnet.0.scope", "24"), - resource.TestCheckResourceAttr(firstResourceName, "subnet.1.first", "11.12.13.14"), - resource.TestCheckResourceAttr(firstResourceName, "subnet.1.last", "11.12.13.14"), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.0.first", "1.2.3.0"), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.0.scope", "24"), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.1.first", "11.12.13.14"), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.1.last", "11.12.13.14"), resource.TestCheckResourceAttr(secondResourceName, "subnet.#", "1"), resource.TestCheckResourceAttr(secondResourceName, "subnet.0.first", "21.22.23.24"), resource.TestCheckResourceAttr(secondResourceName, "subnet.0.scope", "32"), ), }, { - Config: postConfig, + Config: testAccAzureRMTrafficManagerEndpoint_updateSubnets(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(firstResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "subnet.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.#", "0"), resource.TestCheckResourceAttr(secondResourceName, "subnet.#", "1"), resource.TestCheckResourceAttr(secondResourceName, "subnet.0.first", "12.34.56.78"), resource.TestCheckResourceAttr(secondResourceName, "subnet.0.last", "12.34.56.78"), @@ -214,36 +190,31 @@ func TestAccAzureRMTrafficManagerEndpoint_updateSubnets(t *testing.T) { } func TestAccAzureRMTrafficManagerEndpoint_updateCustomeHeaders(t *testing.T) { - firstResourceName := "azurerm_traffic_manager_endpoint.testExternal" + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "testExternal") secondResourceName := "azurerm_traffic_manager_endpoint.testExternalNew" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMTrafficManagerEndpoint_headers(ri, location) - postConfig := testAccAzureRMTrafficManagerEndpoint_updateHeaders(ri, location) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMTrafficManagerEndpoint_headers(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(firstResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "custom_header.#", "1"), - resource.TestCheckResourceAttr(firstResourceName, "custom_header.0.name", "header"), - resource.TestCheckResourceAttr(firstResourceName, "custom_header.0.value", "www.bing.com"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_header.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_header.0.name", "header"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_header.0.value", "www.bing.com"), resource.TestCheckResourceAttr(secondResourceName, "custom_header.#", "0"), ), }, { - Config: postConfig, + Config: testAccAzureRMTrafficManagerEndpoint_updateHeaders(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(firstResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "custom_header.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_header.#", "0"), resource.TestCheckResourceAttr(secondResourceName, "custom_header.#", "1"), resource.TestCheckResourceAttr(secondResourceName, "custom_header.0.name", "header"), resource.TestCheckResourceAttr(secondResourceName, "custom_header.0.value", "www.bing.com"), @@ -255,34 +226,29 @@ func TestAccAzureRMTrafficManagerEndpoint_updateCustomeHeaders(t *testing.T) { // Altering priority might be used to switch failover/active roles func TestAccAzureRMTrafficManagerEndpoint_updatePriority(t *testing.T) { - firstResourceName := "azurerm_traffic_manager_endpoint.testExternal" + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "testExternal") secondResourceName := "azurerm_traffic_manager_endpoint.testExternalNew" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMTrafficManagerEndpoint_priority(ri, location) - postConfig := testAccAzureRMTrafficManagerEndpoint_updatePriority(ri, location) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMTrafficManagerEndpoint_priority(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(firstResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "priority", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "1"), resource.TestCheckResourceAttr(secondResourceName, "priority", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMTrafficManagerEndpoint_updatePriority(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(firstResourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), testCheckAzureRMTrafficManagerEndpointExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "priority", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "3"), resource.TestCheckResourceAttr(secondResourceName, "priority", "2"), ), }, @@ -291,8 +257,7 @@ func TestAccAzureRMTrafficManagerEndpoint_updatePriority(t *testing.T) { } func TestAccAzureRMTrafficManagerEndpoint_nestedEndpoints(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMTrafficManagerEndpoint_nestedEndpoints(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "nested") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -300,7 +265,7 @@ func TestAccAzureRMTrafficManagerEndpoint_nestedEndpoints(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMTrafficManagerEndpoint_nestedEndpoints(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMTrafficManagerEndpointExists("azurerm_traffic_manager_endpoint.nested"), testCheckAzureRMTrafficManagerEndpointExists("azurerm_traffic_manager_endpoint.externalChild"), @@ -311,11 +276,7 @@ func TestAccAzureRMTrafficManagerEndpoint_nestedEndpoints(t *testing.T) { } func TestAccAzureRMTrafficManagerEndpoint_location(t *testing.T) { - resourceName := "azurerm_traffic_manager_endpoint.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - first := testAccAzureRMTrafficManagerEndpoint_location(ri, location) - second := testAccAzureRMTrafficManagerEndpoint_locationUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -323,15 +284,15 @@ func TestAccAzureRMTrafficManagerEndpoint_location(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: first, + Config: testAccAzureRMTrafficManagerEndpoint_location(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(resourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), ), }, { - Config: second, + Config: testAccAzureRMTrafficManagerEndpoint_locationUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(resourceName), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), ), }, }, @@ -339,11 +300,7 @@ func TestAccAzureRMTrafficManagerEndpoint_location(t *testing.T) { } func TestAccAzureRMTrafficManagerEndpoint_withGeoMappings(t *testing.T) { - resourceName := "azurerm_traffic_manager_endpoint.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - first := testAccAzureRMTrafficManagerEndpoint_geoMappings(ri, location) - second := testAccAzureRMTrafficManagerEndpoint_geoMappingsUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_endpoint", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -351,21 +308,21 @@ func TestAccAzureRMTrafficManagerEndpoint_withGeoMappings(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy, Steps: []resource.TestStep{ { - Config: first, + Config: testAccAzureRMTrafficManagerEndpoint_geoMappings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "geo_mappings.#", "2"), - resource.TestCheckResourceAttr(resourceName, "geo_mappings.0", "GB"), - resource.TestCheckResourceAttr(resourceName, "geo_mappings.1", "FR"), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "geo_mappings.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "geo_mappings.0", "GB"), + resource.TestCheckResourceAttr(data.ResourceName, "geo_mappings.1", "FR"), ), }, { - Config: second, + Config: testAccAzureRMTrafficManagerEndpoint_geoMappingsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "geo_mappings.#", "2"), - resource.TestCheckResourceAttr(resourceName, "geo_mappings.0", "FR"), - resource.TestCheckResourceAttr(resourceName, "geo_mappings.1", "DE"), + testCheckAzureRMTrafficManagerEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "geo_mappings.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "geo_mappings.0", "FR"), + resource.TestCheckResourceAttr(data.ResourceName, "geo_mappings.1", "DE"), ), }, }, @@ -458,7 +415,7 @@ func testCheckAzureRMTrafficManagerEndpointDestroy(s *terraform.State) error { return nil } -func testAccAzureRMTrafficManagerEndpoint_basic(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -507,10 +464,11 @@ resource "azurerm_traffic_manager_endpoint" "testExternal" { profile_name = "${azurerm_traffic_manager_profile.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_requiresImport(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMTrafficManagerEndpoint_basic(data) return fmt.Sprintf(` %s @@ -522,10 +480,10 @@ resource "azurerm_traffic_manager_endpoint" "import" { profile_name = "${azurerm_traffic_manager_endpoint.testAzure.profile_name}" resource_group_name = "${azurerm_traffic_manager_endpoint.testAzure.resource_group_name}" } -`, testAccAzureRMTrafficManagerEndpoint_basic(rInt, location)) +`, template) } -func testAccAzureRMTrafficManagerEndpoint_basicDisableExternal(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_basicDisableExternal(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -575,10 +533,10 @@ resource "azurerm_traffic_manager_endpoint" "testExternal" { profile_name = "${azurerm_traffic_manager_profile.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_weight(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_weight(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -619,10 +577,10 @@ resource "azurerm_traffic_manager_endpoint" "testExternalNew" { profile_name = "${azurerm_traffic_manager_profile.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_updateWeight(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_updateWeight(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -663,9 +621,9 @@ resource "azurerm_traffic_manager_endpoint" "testExternalNew" { profile_name = "${azurerm_traffic_manager_profile.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_priority(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_priority(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -706,10 +664,10 @@ resource "azurerm_traffic_manager_endpoint" "testExternalNew" { profile_name = "${azurerm_traffic_manager_profile.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_updatePriority(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_updatePriority(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -750,10 +708,10 @@ resource "azurerm_traffic_manager_endpoint" "testExternalNew" { profile_name = "${azurerm_traffic_manager_profile.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_subnets(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_subnets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -804,10 +762,10 @@ resource "azurerm_traffic_manager_endpoint" "testExternalNew" { scope = "32" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_updateSubnets(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_updateSubnets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -850,10 +808,10 @@ resource "azurerm_traffic_manager_endpoint" "testExternalNew" { last = "12.34.56.78" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_headers(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_headers(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -898,10 +856,10 @@ resource "azurerm_traffic_manager_endpoint" "testExternalNew" { resource_group_name = "${azurerm_resource_group.test.name}" priority = 2 } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_updateHeaders(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_updateHeaders(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -946,10 +904,10 @@ resource "azurerm_traffic_manager_endpoint" "testExternalNew" { value = "www.bing.com" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_nestedEndpoints(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_nestedEndpoints(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1008,10 +966,10 @@ resource "azurerm_traffic_manager_endpoint" "externalChild" { profile_name = "${azurerm_traffic_manager_profile.child.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_location(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_location(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1043,10 +1001,10 @@ resource "azurerm_traffic_manager_endpoint" "test" { profile_name = "${azurerm_traffic_manager_profile.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_locationUpdated(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_locationUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1078,10 +1036,10 @@ resource "azurerm_traffic_manager_endpoint" "test" { profile_name = "${azurerm_traffic_manager_profile.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_geoMappings(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_geoMappings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1117,10 +1075,10 @@ resource "azurerm_traffic_manager_endpoint" "test" { type = "externalEndpoints" geo_mappings = ["GB", "FR"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerEndpoint_geoMappingsUpdated(rInt int, location string) string { +func testAccAzureRMTrafficManagerEndpoint_geoMappingsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1156,5 +1114,5 @@ resource "azurerm_traffic_manager_endpoint" "test" { type = "externalEndpoints" geo_mappings = ["FR", "DE"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile_test.go b/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go similarity index 64% rename from azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile_test.go rename to azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go index 0ea6d2cd140c..d9e6dbbb9a64 100644 --- a/azurerm/internal/services/trafficmanager/resource_arm_traffic_manager_profile_test.go +++ b/azurerm/internal/services/trafficmanager/tests/resource_arm_traffic_manager_profile_test.go @@ -1,4 +1,4 @@ -package trafficmanager +package tests import ( "fmt" @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -25,8 +24,7 @@ func getTrafficManagerFQDN(hostname string) (string, error) { } func TestAccAzureRMTrafficManagerProfile_geographic(t *testing.T) { - resourceName := "azurerm_traffic_manager_profile.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -34,17 +32,13 @@ func TestAccAzureRMTrafficManagerProfile_geographic(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTrafficManagerProfile_geographic(ri, acceptance.Location()), + Config: testAccAzureRMTrafficManagerProfile_geographic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "traffic_routing_method", "Geographic"), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "Geographic"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -54,35 +48,28 @@ func TestAccAzureRMTrafficManagerProfile_requiresImport(t *testing.T) { return } - resourceName := "azurerm_traffic_manager_profile.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTrafficManagerProfile_geographic(ri, acceptance.Location()), + Config: testAccAzureRMTrafficManagerProfile_geographic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "traffic_routing_method", "Geographic"), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "Geographic"), ), }, - { - Config: testAccAzureRMTrafficManagerProfile_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_traffic_manager_profile"), - }, + data.RequiresImportErrorStep(testAccAzureRMTrafficManagerProfile_requiresImport), }, }) } func TestAccAzureRMTrafficManagerProfile_weighted(t *testing.T) { - resourceName := "azurerm_traffic_manager_profile.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMTrafficManagerProfile_weighted(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") - fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", ri)) + fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", data.RandomInteger)) if err != nil { t.Fatalf("Error obtaining Azure Region: %+v", err) } @@ -93,28 +80,22 @@ func TestAccAzureRMTrafficManagerProfile_weighted(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMTrafficManagerProfile_weighted(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "traffic_routing_method", "Weighted"), - resource.TestCheckResourceAttr(resourceName, "fqdn", fqdn), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "Weighted"), + resource.TestCheckResourceAttr(data.ResourceName, "fqdn", fqdn), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMTrafficManagerProfile_weightedTCP(t *testing.T) { - resourceName := "azurerm_traffic_manager_profile.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMTrafficManagerProfile_weightedTCP(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") - fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", ri)) + fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", data.RandomInteger)) if err != nil { t.Fatalf("Error obtaining Azure Region: %+v", err) } @@ -125,28 +106,22 @@ func TestAccAzureRMTrafficManagerProfile_weightedTCP(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMTrafficManagerProfile_weightedTCP(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "traffic_routing_method", "Weighted"), - resource.TestCheckResourceAttr(resourceName, "fqdn", fqdn), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "Weighted"), + resource.TestCheckResourceAttr(data.ResourceName, "fqdn", fqdn), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMTrafficManagerProfile_performance(t *testing.T) { - resourceName := "azurerm_traffic_manager_profile.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMTrafficManagerProfile_performance(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") - fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", ri)) + fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", data.RandomInteger)) if err != nil { t.Fatalf("Error obtaining Azure Region: %+v", err) } @@ -157,28 +132,22 @@ func TestAccAzureRMTrafficManagerProfile_performance(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMTrafficManagerProfile_performance(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "traffic_routing_method", "Performance"), - resource.TestCheckResourceAttr(resourceName, "fqdn", fqdn), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "Performance"), + resource.TestCheckResourceAttr(data.ResourceName, "fqdn", fqdn), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMTrafficManagerProfile_priority(t *testing.T) { - resourceName := "azurerm_traffic_manager_profile.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMTrafficManagerProfile_priority(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") - fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", ri)) + fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", data.RandomInteger)) if err != nil { t.Fatalf("Error obtaining Azure Region: %+v", err) } @@ -189,27 +158,20 @@ func TestAccAzureRMTrafficManagerProfile_priority(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMTrafficManagerProfile_priority(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "traffic_routing_method", "Priority"), - resource.TestCheckResourceAttr(resourceName, "fqdn", fqdn), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "Priority"), + resource.TestCheckResourceAttr(data.ResourceName, "fqdn", fqdn), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMTrafficManagerProfile_withTags(t *testing.T) { - resourceName := "azurerm_traffic_manager_profile.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMTrafficManagerProfile_withTags(ri, acceptance.Location()) - postConfig := testAccAzureRMTrafficManagerProfile_withTagsUpdated(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -217,38 +179,31 @@ func TestAccAzureRMTrafficManagerProfile_withTags(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMTrafficManagerProfile_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { - Config: postConfig, + Config: testAccAzureRMTrafficManagerProfile_withTagsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMTrafficManagerProfile_performanceToGeographic(t *testing.T) { - resourceName := "azurerm_traffic_manager_profile.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMTrafficManagerProfile_performance(ri, acceptance.Location()) - postConfig := testAccAzureRMTrafficManagerProfile_geographic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") - fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", ri)) + fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", data.RandomInteger)) if err != nil { t.Fatalf("Error obtaining Azure Region: %+v", err) } @@ -259,19 +214,19 @@ func TestAccAzureRMTrafficManagerProfile_performanceToGeographic(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMTrafficManagerProfile_performance(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "traffic_routing_method", "Performance"), - resource.TestCheckResourceAttr(resourceName, "fqdn", fqdn), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "Performance"), + resource.TestCheckResourceAttr(data.ResourceName, "fqdn", fqdn), ), }, { - Config: postConfig, + Config: testAccAzureRMTrafficManagerProfile_geographic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "traffic_routing_method", "Geographic"), - resource.TestCheckResourceAttr(resourceName, "fqdn", fqdn), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "Geographic"), + resource.TestCheckResourceAttr(data.ResourceName, "fqdn", fqdn), ), }, }, @@ -279,12 +234,9 @@ func TestAccAzureRMTrafficManagerProfile_performanceToGeographic(t *testing.T) { } func TestAccAzureRMTrafficManagerProfile_priorityToWeighted(t *testing.T) { - resourceName := "azurerm_traffic_manager_profile.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMTrafficManagerProfile_priority(ri, acceptance.Location()) - postConfig := testAccAzureRMTrafficManagerProfile_weighted(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") - fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", ri)) + fqdn, err := getTrafficManagerFQDN(fmt.Sprintf("acctesttmp%d", data.RandomInteger)) if err != nil { t.Fatalf("Error obtaining Azure Region: %+v", err) } @@ -295,19 +247,19 @@ func TestAccAzureRMTrafficManagerProfile_priorityToWeighted(t *testing.T) { CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMTrafficManagerProfile_priority(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "traffic_routing_method", "Priority"), - resource.TestCheckResourceAttr(resourceName, "fqdn", fqdn), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "Priority"), + resource.TestCheckResourceAttr(data.ResourceName, "fqdn", fqdn), ), }, { - Config: postConfig, + Config: testAccAzureRMTrafficManagerProfile_weighted(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "traffic_routing_method", "Weighted"), - resource.TestCheckResourceAttr(resourceName, "fqdn", fqdn), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_routing_method", "Weighted"), + resource.TestCheckResourceAttr(data.ResourceName, "fqdn", fqdn), ), }, }, @@ -315,9 +267,7 @@ func TestAccAzureRMTrafficManagerProfile_priorityToWeighted(t *testing.T) { } func TestAccAzureRMTrafficManagerProfile_fastEndpointFailoverSettings(t *testing.T) { - resourceName := "azurerm_traffic_manager_profile.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -325,34 +275,25 @@ func TestAccAzureRMTrafficManagerProfile_fastEndpointFailoverSettings(t *testing CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTrafficManagerProfile_failover(rInt, location), + Config: testAccAzureRMTrafficManagerProfile_failover(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMTrafficManagerProfile_failoverUpdate(rInt, location), + Config: testAccAzureRMTrafficManagerProfile_failoverUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTrafficManagerProfileExists(resourceName), + testCheckAzureRMTrafficManagerProfileExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMTrafficManagerProfile_fastEndpointFailoverSettingsError(t *testing.T) { - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_traffic_manager_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -360,7 +301,7 @@ func TestAccAzureRMTrafficManagerProfile_fastEndpointFailoverSettingsError(t *te CheckDestroy: testCheckAzureRMTrafficManagerProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTrafficManagerProfile_failoverError(rInt, location), + Config: testAccAzureRMTrafficManagerProfile_failoverError(data), ExpectError: regexp.MustCompile("`timeout_in_seconds` must be between `5` and `9` when `interval_in_seconds` is set to `10`"), }, }, @@ -423,7 +364,7 @@ func testCheckAzureRMTrafficManagerProfileDestroy(s *terraform.State) error { return nil } -func testAccAzureRMTrafficManagerProfile_geographic(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_geographic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -446,9 +387,10 @@ resource "azurerm_traffic_manager_profile" "test" { path = "/" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerProfile_requiresImport(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMTrafficManagerProfile_geographic(data) return fmt.Sprintf(` %s @@ -468,10 +410,10 @@ resource "azurerm_traffic_manager_profile" "import" { path = "/" } } -`, testAccAzureRMTrafficManagerProfile_geographic(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMTrafficManagerProfile_weighted(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_weighted(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -494,10 +436,10 @@ resource "azurerm_traffic_manager_profile" "test" { path = "/" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerProfile_weightedTCP(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_weightedTCP(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -519,10 +461,10 @@ resource "azurerm_traffic_manager_profile" "test" { port = 443 } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerProfile_performance(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_performance(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -545,10 +487,10 @@ resource "azurerm_traffic_manager_profile" "test" { path = "/" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerProfile_priority(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_priority(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -571,10 +513,10 @@ resource "azurerm_traffic_manager_profile" "test" { path = "/" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerProfile_withTags(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -602,10 +544,10 @@ resource "azurerm_traffic_manager_profile" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerProfile_withTagsUpdated(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_withTagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -632,10 +574,10 @@ resource "azurerm_traffic_manager_profile" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerProfile_failover(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_failover(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -661,10 +603,10 @@ resource "azurerm_traffic_manager_profile" "test" { tolerated_number_of_failures = 3 } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerProfile_failoverUpdate(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_failoverUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -690,10 +632,10 @@ resource "azurerm_traffic_manager_profile" "test" { tolerated_number_of_failures = 6 } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTrafficManagerProfile_failoverError(rInt int, location string) string { +func testAccAzureRMTrafficManagerProfile_failoverError(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -719,5 +661,5 @@ resource "azurerm_traffic_manager_profile" "test" { tolerated_number_of_failures = 3 } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } From 1f693cc69605632376bbf5dcea1c2dcf60b53dd6 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 18:33:05 +0100 Subject: [PATCH 091/203] subscription: switching over to use the new test builder --- .../data_source_subscription_test.go | 30 +++++++++---------- .../data_source_subscriptions_test.go | 12 ++++---- 2 files changed, 21 insertions(+), 21 deletions(-) rename azurerm/internal/services/subscription/{ => tests}/data_source_subscription_test.go (66%) rename azurerm/internal/services/subscription/{ => tests}/data_source_subscriptions_test.go (54%) diff --git a/azurerm/internal/services/subscription/data_source_subscription_test.go b/azurerm/internal/services/subscription/tests/data_source_subscription_test.go similarity index 66% rename from azurerm/internal/services/subscription/data_source_subscription_test.go rename to azurerm/internal/services/subscription/tests/data_source_subscription_test.go index b77a62c5bae2..d8591f6c3a4d 100644 --- a/azurerm/internal/services/subscription/data_source_subscription_test.go +++ b/azurerm/internal/services/subscription/tests/data_source_subscription_test.go @@ -1,4 +1,4 @@ -package subscription +package tests import ( "fmt" @@ -12,7 +12,7 @@ import ( ) func TestAccDataSourceAzureRMSubscription_current(t *testing.T) { - resourceName := "data.azurerm_subscription.current" + data := acceptance.BuildTestData(t, "data.azurerm_subscription", "current") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,11 +21,11 @@ func TestAccDataSourceAzureRMSubscription_current(t *testing.T) { { Config: testAccDataSourceAzureRMSubscription_currentConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(resourceName, "subscription_id"), - testCheckAzureRMSubscriptionId(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "display_name"), - resource.TestCheckResourceAttrSet(resourceName, "tenant_id"), - resource.TestCheckResourceAttr(resourceName, "state", "Enabled"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"), + testCheckAzureRMSubscriptionId(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "display_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "tenant_id"), + resource.TestCheckResourceAttr(data.ResourceName, "state", "Enabled"), ), }, }, @@ -33,7 +33,7 @@ func TestAccDataSourceAzureRMSubscription_current(t *testing.T) { } func TestAccDataSourceAzureRMSubscription_specific(t *testing.T) { - resourceName := "data.azurerm_subscription.specific" + data := acceptance.BuildTestData(t, "data.azurerm_subscription", "specific") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -42,13 +42,13 @@ func TestAccDataSourceAzureRMSubscription_specific(t *testing.T) { { Config: testAccDataSourceAzureRMSubscription_specificConfig(os.Getenv("ARM_SUBSCRIPTION_ID")), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(resourceName, "subscription_id"), - testCheckAzureRMSubscriptionId(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "display_name"), - resource.TestCheckResourceAttrSet(resourceName, "tenant_id"), - resource.TestCheckResourceAttrSet(resourceName, "location_placement_id"), - resource.TestCheckResourceAttrSet(resourceName, "quota_id"), - resource.TestCheckResourceAttrSet(resourceName, "spending_limit"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"), + testCheckAzureRMSubscriptionId(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "display_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location_placement_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "quota_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "spending_limit"), ), }, }, diff --git a/azurerm/internal/services/subscription/data_source_subscriptions_test.go b/azurerm/internal/services/subscription/tests/data_source_subscriptions_test.go similarity index 54% rename from azurerm/internal/services/subscription/data_source_subscriptions_test.go rename to azurerm/internal/services/subscription/tests/data_source_subscriptions_test.go index ccc101caa930..41aa6230e4c3 100644 --- a/azurerm/internal/services/subscription/data_source_subscriptions_test.go +++ b/azurerm/internal/services/subscription/tests/data_source_subscriptions_test.go @@ -1,4 +1,4 @@ -package subscription +package tests import ( "testing" @@ -8,7 +8,7 @@ import ( ) func TestAccDataSourceAzureRMSubscriptions_basic(t *testing.T) { - resourceName := "data.azurerm_subscriptions.current" + data := acceptance.BuildTestData(t, "data.azurerm_subscriptions", "current") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -17,10 +17,10 @@ func TestAccDataSourceAzureRMSubscriptions_basic(t *testing.T) { { Config: `data "azurerm_subscriptions" "current" {}`, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(resourceName, "subscriptions.0.subscription_id"), - resource.TestCheckResourceAttrSet(resourceName, "subscriptions.0.display_name"), - resource.TestCheckResourceAttrSet(resourceName, "subscriptions.0.tenant_id"), - resource.TestCheckResourceAttrSet(resourceName, "subscriptions.0.state"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subscriptions.0.subscription_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subscriptions.0.display_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subscriptions.0.tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subscriptions.0.state"), ), }, }, From 2de39d7392ed2f07c433a500136abd43291b2149 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 20 Dec 2019 20:58:50 +0100 Subject: [PATCH 092/203] streamanalytics: switching to the new structure --- .../data_source_stream_analytics_job_test.go | 14 +- ..._analytics_function_javascript_udf_test.go | 75 +++----- .../resource_arm_stream_analytics_job_test.go | 87 ++++----- ...e_arm_stream_analytics_output_blob_test.go | 132 ++++---------- ...m_stream_analytics_output_eventhub_test.go | 167 ++++++------------ ..._arm_stream_analytics_output_mssql_test.go | 83 +++------ ..._analytics_output_servicebus_queue_test.go | 124 ++++--------- ..._analytics_output_servicebus_topic_test.go | 124 ++++--------- ...eam_analytics_reference_input_blob_test.go | 139 +++++---------- ...stream_analytics_stream_input_blob_test.go | 133 +++++--------- ...am_analytics_stream_input_eventhub_test.go | 124 ++++--------- ...ream_analytics_stream_input_iothub_test.go | 121 ++++--------- 12 files changed, 423 insertions(+), 900 deletions(-) rename azurerm/internal/services/streamanalytics/{ => tests}/data_source_stream_analytics_job_test.go (61%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_function_javascript_udf_test.go (81%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_job_test.go (74%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_output_blob_test.go (71%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_output_eventhub_test.go (70%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_output_mssql_test.go (72%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_output_servicebus_queue_test.go (80%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_output_servicebus_topic_test.go (80%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_reference_input_blob_test.go (74%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_stream_input_blob_test.go (73%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_stream_input_eventhub_test.go (78%) rename azurerm/internal/services/streamanalytics/{ => tests}/resource_arm_stream_analytics_stream_input_iothub_test.go (77%) diff --git a/azurerm/internal/services/streamanalytics/data_source_stream_analytics_job_test.go b/azurerm/internal/services/streamanalytics/tests/data_source_stream_analytics_job_test.go similarity index 61% rename from azurerm/internal/services/streamanalytics/data_source_stream_analytics_job_test.go rename to azurerm/internal/services/streamanalytics/tests/data_source_stream_analytics_job_test.go index 5640cbb9e666..05b69ccefc9f 100644 --- a/azurerm/internal/services/streamanalytics/data_source_stream_analytics_job_test.go +++ b/azurerm/internal/services/streamanalytics/tests/data_source_stream_analytics_job_test.go @@ -1,17 +1,15 @@ -package streamanalytics +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMStreamAnalyticsJob_basic(t *testing.T) { - dataSourceName := "data.azurerm_stream_analytics_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_stream_analytics_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -19,17 +17,17 @@ func TestAccDataSourceAzureRMStreamAnalyticsJob_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsJobDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMStreamAnalyticsJob_basic(ri, acceptance.Location()), + Config: testAccDataSourceAzureRMStreamAnalyticsJob_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "job_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "job_id"), ), }, }, }) } -func testAccDataSourceAzureRMStreamAnalyticsJob_basic(rInt int, location string) string { - config := testAccAzureRMStreamAnalyticsJob_basic(rInt, location) +func testAccDataSourceAzureRMStreamAnalyticsJob_basic(data acceptance.TestData) string { + config := testAccAzureRMStreamAnalyticsJob_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_function_javascript_udf_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_function_javascript_udf_test.go similarity index 81% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_function_javascript_udf_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_function_javascript_udf_test.go index 2e021c9afced..d75e8c0457d9 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_function_javascript_udf_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_function_javascript_udf_test.go @@ -1,4 +1,4 @@ -package streamanalytics +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(t *testing.T) { - resourceName := "azurerm_stream_analytics_function_javascript_udf.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_function_javascript_udf", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +21,12 @@ func TestAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(ri, location), + Config: testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFExists(resourceName), + testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,33 +37,25 @@ func TestAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_requiresImport(t *testin return } - resourceName := "azurerm_stream_analytics_function_javascript_udf.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_function_javascript_udf", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(ri, location), + Config: testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFExists(resourceName), + testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_function_javascript_udf"), - }, + data.RequiresImportErrorStep(testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_requiresImport), }, }) } func TestAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_inputs(t *testing.T) { - resourceName := "azurerm_stream_analytics_function_javascript_udf.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_function_javascript_udf", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,27 +63,19 @@ func TestAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_inputs(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(ri, location), + Config: testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFExists(resourceName), + testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_inputs(ri, location), + Config: testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_inputs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFExists(resourceName), + testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -155,8 +132,8 @@ func testCheckAzureRMStreamAnalyticsFunctionJavaScriptUDFDestroy(s *terraform.St return nil } -func testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_template(rInt, location) +func testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_template(data) return fmt.Sprintf(` %s @@ -179,11 +156,11 @@ SCRIPT type = "bigint" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_requiresImport(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(rInt, location) +func testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_basic(data) return fmt.Sprintf(` %s @@ -198,8 +175,8 @@ resource "azurerm_stream_analytics_function_javascript_udf" "import" { `, template) } -func testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_inputs(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_template(rInt, location) +func testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_inputs(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_template(data) return fmt.Sprintf(` %s @@ -226,10 +203,10 @@ SCRIPT type = "bigint" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_template(rInt int, location string) string { +func testAccAzureRMStreamAnalyticsFunctionJavaScriptUDF_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -254,5 +231,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_job_test.go similarity index 74% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_job_test.go index edc50bfa9049..25b361a20efa 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_job_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_job_test.go @@ -1,4 +1,4 @@ -package streamanalytics +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsJob_basic(t *testing.T) { - resourceName := "azurerm_stream_analytics_job.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,26 +21,20 @@ func TestAccAzureRMStreamAnalyticsJob_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsJob_basic(ri, location), + Config: testAccAzureRMStreamAnalyticsJob_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Test"), + testCheckAzureRMStreamAnalyticsJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStreamAnalyticsJob_complete(t *testing.T) { - resourceName := "azurerm_stream_analytics_job.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,18 +42,14 @@ func TestAccAzureRMStreamAnalyticsJob_complete(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsJob_complete(ri, location), + Config: testAccAzureRMStreamAnalyticsJob_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Test"), + testCheckAzureRMStreamAnalyticsJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -73,33 +60,25 @@ func TestAccAzureRMStreamAnalyticsJob_requiresImport(t *testing.T) { return } - resourceName := "azurerm_stream_analytics_job.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMStreamAnalyticsJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsJob_basic(ri, location), + Config: testAccAzureRMStreamAnalyticsJob_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsJobExists(resourceName), + testCheckAzureRMStreamAnalyticsJobExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStreamAnalyticsJob_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_job"), - }, + data.RequiresImportErrorStep(testAccAzureRMStreamAnalyticsJob_requiresImport), }, }) } func TestAccAzureRMStreamAnalyticsJob_update(t *testing.T) { - resourceName := "azurerm_stream_analytics_job.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -107,22 +86,18 @@ func TestAccAzureRMStreamAnalyticsJob_update(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsJob_basic(ri, location), + Config: testAccAzureRMStreamAnalyticsJob_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsJobExists(resourceName), + testCheckAzureRMStreamAnalyticsJobExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsJob_updated(ri, location), + Config: testAccAzureRMStreamAnalyticsJob_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsJobExists(resourceName), + testCheckAzureRMStreamAnalyticsJobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -177,7 +152,7 @@ func testCheckAzureRMStreamAnalyticsJobDestroy(s *terraform.State) error { return nil } -func testAccAzureRMStreamAnalyticsJob_basic(rInt int, location string) string { +func testAccAzureRMStreamAnalyticsJob_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -200,10 +175,10 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsJob_complete(rInt int, location string) string { +func testAccAzureRMStreamAnalyticsJob_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -232,11 +207,11 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsJob_requiresImport(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsJob_basic(rInt, location) +func testAccAzureRMStreamAnalyticsJob_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsJob_basic(data) return fmt.Sprintf(` %s @@ -257,7 +232,7 @@ resource "azurerm_stream_analytics_job" "import" { `, template) } -func testAccAzureRMStreamAnalyticsJob_updated(rInt int, location string) string { +func testAccAzureRMStreamAnalyticsJob_updated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -282,5 +257,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [SomeOtherInputAlias] QUERY } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_blob_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_blob_test.go similarity index 71% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_blob_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_blob_test.go index 6cd6cbc3e57b..a1cce606bf6c 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_blob_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_blob_test.go @@ -1,25 +1,19 @@ -package streamanalytics +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsOutputBlob_avro(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,29 +21,18 @@ func TestAccAzureRMStreamAnalyticsOutputBlob_avro(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputBlob_avro(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputBlob_avro(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputBlob_csv(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,29 +40,18 @@ func TestAccAzureRMStreamAnalyticsOutputBlob_csv(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputBlob_csv(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputBlob_csv(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputBlob_json(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,56 +59,36 @@ func TestAccAzureRMStreamAnalyticsOutputBlob_json(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputBlob_json(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputBlob_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputBlob_update(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMStreamAnalyticsOutputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputBlob_json(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputBlob_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputBlobExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsOutputBlob_updated(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputBlob_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } @@ -147,10 +99,7 @@ func TestAccAzureRMStreamAnalyticsOutputBlob_requiresImport(t *testing.T) { return } - resourceName := "azurerm_stream_analytics_output_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -158,15 +107,12 @@ func TestAccAzureRMStreamAnalyticsOutputBlob_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputBlob_json(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputBlob_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputBlobExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStreamAnalyticsOutputBlob_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_output_blob"), - }, + data.RequiresImportErrorStep(testAccAzureRMStreamAnalyticsOutputBlob_requiresImport), }, }) } @@ -223,8 +169,8 @@ func testCheckAzureRMStreamAnalyticsOutputBlobDestroy(s *terraform.State) error return nil } -func testAccAzureRMStreamAnalyticsOutputBlob_avro(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsOutputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsOutputBlob_avro(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputBlob_template(data) return fmt.Sprintf(` %s @@ -243,11 +189,11 @@ resource "azurerm_stream_analytics_output_blob" "test" { type = "Avro" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputBlob_csv(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsOutputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsOutputBlob_csv(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputBlob_template(data) return fmt.Sprintf(` %s @@ -268,11 +214,11 @@ resource "azurerm_stream_analytics_output_blob" "test" { field_delimiter = "," } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputBlob_json(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsOutputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsOutputBlob_json(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputBlob_template(data) return fmt.Sprintf(` %s @@ -293,11 +239,11 @@ resource "azurerm_stream_analytics_output_blob" "test" { format = "LineSeparated" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputBlob_updated(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsOutputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsOutputBlob_updated(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputBlob_template(data) return fmt.Sprintf(` %s @@ -331,11 +277,11 @@ resource "azurerm_stream_analytics_output_blob" "test" { type = "Avro" } } -`, template, rString, rInt) +`, template, data.RandomString, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputBlob_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsOutputBlob_json(rInt, rString, location) +func testAccAzureRMStreamAnalyticsOutputBlob_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputBlob_json(data) return fmt.Sprintf(` %s @@ -354,7 +300,7 @@ resource "azurerm_stream_analytics_output_blob" "import" { `, template) } -func testAccAzureRMStreamAnalyticsOutputBlob_template(rInt int, rString string, location string) string { +func testAccAzureRMStreamAnalyticsOutputBlob_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -394,5 +340,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_eventhub_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_eventhub_test.go similarity index 70% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_eventhub_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_eventhub_test.go index 3a08a9ffb313..809a1cb3eec6 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_eventhub_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_eventhub_test.go @@ -1,4 +1,4 @@ -package streamanalytics +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsOutputEventHub_avro(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,29 +21,19 @@ func TestAccAzureRMStreamAnalyticsOutputEventHub_avro(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputEventHub_avro(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputEventHub_avro(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "serialization.0.type", "Avro"), + testCheckAzureRMStreamAnalyticsOutputEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "serialization.0.type", "Avro"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputEventHub_csv(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,31 +41,21 @@ func TestAccAzureRMStreamAnalyticsOutputEventHub_csv(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputEventHub_csv(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputEventHub_csv(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "serialization.0.type", "Csv"), - resource.TestCheckResourceAttr(resourceName, "serialization.0.field_delimiter", ","), - resource.TestCheckResourceAttr(resourceName, "serialization.0.encoding", "UTF8"), + testCheckAzureRMStreamAnalyticsOutputEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "serialization.0.type", "Csv"), + resource.TestCheckResourceAttr(data.ResourceName, "serialization.0.field_delimiter", ","), + resource.TestCheckResourceAttr(data.ResourceName, "serialization.0.encoding", "UTF8"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputEventHub_json(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,29 +63,19 @@ func TestAccAzureRMStreamAnalyticsOutputEventHub_json(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputEventHub_json(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputEventHub_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "serialization.0.format", "LineSeparated"), + testCheckAzureRMStreamAnalyticsOutputEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "serialization.0.format", "LineSeparated"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputEventHub_jsonArrayFormat(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -116,31 +83,21 @@ func TestAccAzureRMStreamAnalyticsOutputEventHub_jsonArrayFormat(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputEventHub_jsonArrayFormat(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputEventHub_jsonArrayFormat(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "serialization.0.format", "Array"), - resource.TestCheckResourceAttr(resourceName, "serialization.0.type", "Json"), - resource.TestCheckResourceAttr(resourceName, "serialization.0.encoding", "UTF8"), + testCheckAzureRMStreamAnalyticsOutputEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "serialization.0.format", "Array"), + resource.TestCheckResourceAttr(data.ResourceName, "serialization.0.type", "Json"), + resource.TestCheckResourceAttr(data.ResourceName, "serialization.0.encoding", "UTF8"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputEventHub_update(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -148,27 +105,19 @@ func TestAccAzureRMStreamAnalyticsOutputEventHub_update(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputEventHub_json(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputEventHub_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputEventHubExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputEventHubExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsOutputEventHub_updated(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputEventHub_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "serialization.0.type", "Avro"), + testCheckAzureRMStreamAnalyticsOutputEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "serialization.0.type", "Avro"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } @@ -179,25 +128,19 @@ func TestAccAzureRMStreamAnalyticsOutputEventHub_requiresImport(t *testing.T) { return } - resourceName := "azurerm_stream_analytics_output_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMStreamAnalyticsOutputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputEventHub_json(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputEventHub_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputEventHubExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputEventHubExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStreamAnalyticsOutputEventHub_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_output_eventhub"), - }, + data.RequiresImportErrorStep(testAccAzureRMStreamAnalyticsOutputEventHub_requiresImport), }, }) } @@ -254,8 +197,8 @@ func testCheckAzureRMStreamAnalyticsOutputEventHubDestroy(s *terraform.State) er return nil } -func testAccAzureRMStreamAnalyticsOutputEventHub_avro(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputEventHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputEventHub_avro(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputEventHub_template(data) return fmt.Sprintf(` %s @@ -272,11 +215,11 @@ resource "azurerm_stream_analytics_output_eventhub" "test" { type = "Avro" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputEventHub_csv(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputEventHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputEventHub_csv(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputEventHub_template(data) return fmt.Sprintf(` %s @@ -295,11 +238,11 @@ resource "azurerm_stream_analytics_output_eventhub" "test" { field_delimiter = "," } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputEventHub_json(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputEventHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputEventHub_json(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputEventHub_template(data) return fmt.Sprintf(` %s @@ -318,11 +261,11 @@ resource "azurerm_stream_analytics_output_eventhub" "test" { format = "LineSeparated" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputEventHub_jsonArrayFormat(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputEventHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputEventHub_jsonArrayFormat(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputEventHub_template(data) return fmt.Sprintf(` %s @@ -341,11 +284,11 @@ resource "azurerm_stream_analytics_output_eventhub" "test" { format = "Array" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputEventHub_updated(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputEventHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputEventHub_updated(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputEventHub_template(data) return fmt.Sprintf(` %s @@ -378,11 +321,11 @@ resource "azurerm_stream_analytics_output_eventhub" "test" { type = "Avro" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputEventHub_requiresImport(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputEventHub_json(rInt, location) +func testAccAzureRMStreamAnalyticsOutputEventHub_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputEventHub_json(data) return fmt.Sprintf(` %s @@ -398,7 +341,7 @@ resource "azurerm_stream_analytics_output_eventhub" "import" { `, template) } -func testAccAzureRMStreamAnalyticsOutputEventHub_template(rInt int, location string) string { +func testAccAzureRMStreamAnalyticsOutputEventHub_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -439,5 +382,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_mssql_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_mssql_test.go similarity index 72% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_mssql_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_mssql_test.go index cdef3124c8ed..81a724660992 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_mssql_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_mssql_test.go @@ -1,25 +1,19 @@ -package streamanalytics +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsOutputSql_basic(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_mssql.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_mssql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,56 +21,36 @@ func TestAccAzureRMStreamAnalyticsOutputSql_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputSqlDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputSql_basic(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputSql_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputSqlExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputSqlExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "password", - }, - }, + data.ImportStep("password"), }, }) } func TestAccAzureRMStreamAnalyticsOutputSql_update(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_mssql.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_mssql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMStreamAnalyticsOutputSqlDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputSql_basic(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputSql_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputSqlExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputSqlExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsOutputSql_updated(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputSql_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputSqlExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputSqlExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "password", - }, - }, + data.ImportStep("password"), }, }) } @@ -87,10 +61,7 @@ func TestAccAzureRMStreamAnalyticsOutputSql_requiresImport(t *testing.T) { return } - resourceName := "azurerm_stream_analytics_output_mssql.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_mssql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -98,13 +69,13 @@ func TestAccAzureRMStreamAnalyticsOutputSql_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputSqlDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputSql_basic(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputSql_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputSqlExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputSqlExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsOutputSql_requiresImport(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsOutputSql_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_output_mssql"), }, }, @@ -131,7 +102,7 @@ func testCheckAzureRMStreamAnalyticsOutputSqlExists(resourceName string) resourc } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: Stream Output %q (Stream Analytics Job %q / Resource Group %q) does not exist", name, jobName, resourceGroup) + return fmt.Errorf("Bad: Stream Output SQL %q (Stream Analytics Job %q / Resource Group %q) does not exist", name, jobName, resourceGroup) } return nil @@ -156,15 +127,15 @@ func testCheckAzureRMStreamAnalyticsOutputSqlDestroy(s *terraform.State) error { } if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Stream Analytics Output ServiceBus Queue still exists:\n%#v", resp.OutputProperties) + return fmt.Errorf("Stream Analytics Output SQL still exists:\n%#v", resp.OutputProperties) } } return nil } -func testAccAzureRMStreamAnalyticsOutputSql_basic(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsOutputSql_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsOutputSql_basic(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputSql_template(data) return fmt.Sprintf(` %s @@ -179,11 +150,11 @@ resource "azurerm_stream_analytics_output_mssql" "test" { database = "${azurerm_sql_database.test.name}" table = "AccTestTable" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputSql_updated(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsOutputSql_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsOutputSql_updated(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputSql_template(data) return fmt.Sprintf(` %s @@ -198,11 +169,11 @@ resource "azurerm_stream_analytics_output_mssql" "test" { database = "${azurerm_sql_database.test.name}" table = "AccTestTable" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputSql_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsOutputSql_basic(rInt, rString, location) +func testAccAzureRMStreamAnalyticsOutputSql_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputSql_basic(data) return fmt.Sprintf(` %s @@ -220,7 +191,7 @@ resource "azurerm_stream_analytics_output_mssql" "import" { `, template) } -func testAccAzureRMStreamAnalyticsOutputSql_template(rInt int, rString string, location string) string { +func testAccAzureRMStreamAnalyticsOutputSql_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -265,5 +236,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rString, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_queue_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_servicebus_queue_test.go similarity index 80% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_queue_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_servicebus_queue_test.go index d053d81746b6..c780a6a86638 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_queue_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_servicebus_queue_test.go @@ -1,4 +1,4 @@ -package streamanalytics +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsOutputServiceBusQueue_avro(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_servicebus_queue.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,28 +21,18 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusQueue_avro(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_avro(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_avro(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputServiceBusQueue_csv(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_servicebus_queue.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,28 +40,18 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusQueue_csv(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_csv(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_csv(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_servicebus_queue.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,28 +59,18 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputServiceBusQueue_update(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_servicebus_queue.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,26 +78,18 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusQueue_update(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_updated(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } @@ -141,9 +100,7 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusQueue_requiresImport(t *testin return } - resourceName := "azurerm_stream_analytics_output_servicebus_queue.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -151,15 +108,12 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusQueue_requiresImport(t *testin CheckDestroy: testCheckAzureRMStreamAnalyticsOutputServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusQueueExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusQueue_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_output_servicebus_queue"), - }, + data.RequiresImportErrorStep(testAccAzureRMStreamAnalyticsOutputServiceBusQueue_requiresImport), }, }) } @@ -216,8 +170,8 @@ func testCheckAzureRMStreamAnalyticsOutputServiceBusQueueDestroy(s *terraform.St return nil } -func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_avro(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputServiceBusQueue_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_avro(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputServiceBusQueue_template(data) return fmt.Sprintf(` %s @@ -234,11 +188,11 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" { type = "Avro" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_csv(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputServiceBusQueue_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_csv(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputServiceBusQueue_template(data) return fmt.Sprintf(` %s @@ -257,11 +211,11 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" { field_delimiter = "," } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputServiceBusQueue_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputServiceBusQueue_template(data) return fmt.Sprintf(` %s @@ -280,11 +234,11 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" { format = "LineSeparated" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_updated(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputServiceBusQueue_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_updated(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputServiceBusQueue_template(data) return fmt.Sprintf(` %s @@ -315,11 +269,11 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "test" { type = "Avro" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_requiresImport(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(rInt, location) +func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputServiceBusQueue_json(data) return fmt.Sprintf(` %s @@ -336,7 +290,7 @@ resource "azurerm_stream_analytics_output_servicebus_queue" "import" { `, template) } -func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_template(rInt int, location string) string { +func testAccAzureRMStreamAnalyticsOutputServiceBusQueue_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -375,5 +329,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_topic_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_servicebus_topic_test.go similarity index 80% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_topic_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_servicebus_topic_test.go index b7a2071c0580..578d87d24148 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_output_servicebus_topic_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_output_servicebus_topic_test.go @@ -1,4 +1,4 @@ -package streamanalytics +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsOutputServiceBusTopic_avro(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_servicebus_topic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,28 +21,18 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusTopic_avro(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_avro(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_avro(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputServiceBusTopic_csv(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_servicebus_topic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,28 +40,18 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusTopic_csv(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_csv(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_csv(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_servicebus_topic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,28 +59,18 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsOutputServiceBusTopic_update(t *testing.T) { - resourceName := "azurerm_stream_analytics_output_servicebus_topic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,26 +78,18 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusTopic_update(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsOutputServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_updated(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } @@ -141,9 +100,7 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusTopic_requiresImport(t *testin return } - resourceName := "azurerm_stream_analytics_output_servicebus_topic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_output_servicebus_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -151,15 +108,12 @@ func TestAccAzureRMStreamAnalyticsOutputServiceBusTopic_requiresImport(t *testin CheckDestroy: testCheckAzureRMStreamAnalyticsOutputServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(ri, location), + Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(resourceName), + testCheckAzureRMStreamAnalyticsOutputServiceBusTopicExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStreamAnalyticsOutputServiceBusTopic_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_output_servicebus_topic"), - }, + data.RequiresImportErrorStep(testAccAzureRMStreamAnalyticsOutputServiceBusTopic_requiresImport), }, }) } @@ -216,8 +170,8 @@ func testCheckAzureRMStreamAnalyticsOutputServiceBusTopicDestroy(s *terraform.St return nil } -func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_avro(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputServiceBusTopic_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_avro(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputServiceBusTopic_template(data) return fmt.Sprintf(` %s @@ -234,11 +188,11 @@ resource "azurerm_stream_analytics_output_servicebus_topic" "test" { type = "Avro" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_csv(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputServiceBusTopic_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_csv(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputServiceBusTopic_template(data) return fmt.Sprintf(` %s @@ -257,11 +211,11 @@ resource "azurerm_stream_analytics_output_servicebus_topic" "test" { field_delimiter = "," } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputServiceBusTopic_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputServiceBusTopic_template(data) return fmt.Sprintf(` %s @@ -280,11 +234,11 @@ resource "azurerm_stream_analytics_output_servicebus_topic" "test" { format = "LineSeparated" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_updated(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputServiceBusTopic_template(rInt, location) +func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_updated(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputServiceBusTopic_template(data) return fmt.Sprintf(` %s @@ -315,11 +269,11 @@ resource "azurerm_stream_analytics_output_servicebus_topic" "test" { type = "Avro" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_requiresImport(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(rInt, location) +func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsOutputServiceBusTopic_json(data) return fmt.Sprintf(` %s @@ -336,7 +290,7 @@ resource "azurerm_stream_analytics_output_servicebus_topic" "import" { `, template) } -func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_template(rInt int, location string) string { +func testAccAzureRMStreamAnalyticsOutputServiceBusTopic_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -375,5 +329,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_reference_input_blob_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_reference_input_blob_test.go similarity index 74% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_reference_input_blob_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_reference_input_blob_test.go index c713b28a5a0c..aff2cd51623c 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_reference_input_blob_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_reference_input_blob_test.go @@ -1,25 +1,19 @@ -package streamanalytics +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsReferenceInputBlob_avro(t *testing.T) { - resourceName := "azurerm_stream_analytics_reference_input_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_reference_input_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,29 +21,18 @@ func TestAccAzureRMStreamAnalyticsReferenceInputBlob_avro(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsReferenceInputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_avro(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_avro(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } func TestAccAzureRMStreamAnalyticsReferenceInputBlob_csv(t *testing.T) { - resourceName := "azurerm_stream_analytics_reference_input_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_reference_input_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,29 +40,18 @@ func TestAccAzureRMStreamAnalyticsReferenceInputBlob_csv(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsReferenceInputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_csv(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_csv(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } func TestAccAzureRMStreamAnalyticsReferenceInputBlob_json(t *testing.T) { - resourceName := "azurerm_stream_analytics_reference_input_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_reference_input_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,29 +59,18 @@ func TestAccAzureRMStreamAnalyticsReferenceInputBlob_json(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsReferenceInputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_json(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } func TestAccAzureRMStreamAnalyticsReferenceInputBlob_update(t *testing.T) { - resourceName := "azurerm_stream_analytics_reference_input_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_reference_input_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -117,26 +78,18 @@ func TestAccAzureRMStreamAnalyticsReferenceInputBlob_update(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsReferenceInputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_json(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_updated(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } @@ -147,10 +100,7 @@ func TestAccAzureRMStreamAnalyticsReferenceInputBlob_requiresImport(t *testing.T return } - resourceName := "azurerm_stream_analytics_reference_input_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_reference_input_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -158,15 +108,12 @@ func TestAccAzureRMStreamAnalyticsReferenceInputBlob_requiresImport(t *testing.T CheckDestroy: testCheckAzureRMStreamAnalyticsReferenceInputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_json(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsReferenceInputBlobExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStreamAnalyticsReferenceInputBlob_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_reference_input_blob"), - }, + data.RequiresImportErrorStep(testAccAzureRMStreamAnalyticsReferenceInputBlob_requiresImport), }, }) } @@ -223,8 +170,8 @@ func testCheckAzureRMStreamAnalyticsReferenceInputBlobDestroy(s *terraform.State return nil } -func testAccAzureRMStreamAnalyticsReferenceInputBlob_avro(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsReferenceInputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsReferenceInputBlob_avro(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsReferenceInputBlob_template(data) return fmt.Sprintf(` %s @@ -243,11 +190,11 @@ resource "azurerm_stream_analytics_reference_input_blob" "test" { type = "Avro" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsReferenceInputBlob_csv(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsReferenceInputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsReferenceInputBlob_csv(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsReferenceInputBlob_template(data) return fmt.Sprintf(` %s @@ -268,11 +215,11 @@ resource "azurerm_stream_analytics_reference_input_blob" "test" { field_delimiter = "," } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsReferenceInputBlob_json(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsReferenceInputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsReferenceInputBlob_json(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsReferenceInputBlob_template(data) return fmt.Sprintf(` %s @@ -292,18 +239,18 @@ resource "azurerm_stream_analytics_reference_input_blob" "test" { encoding = "UTF8" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsReferenceInputBlob_updated(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsReferenceInputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsReferenceInputBlob_updated(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsReferenceInputBlob_template(data) return fmt.Sprintf(` %s resource "azurerm_storage_account" "updated" { name = "acctestsa2%s" resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + data.Locations.Primary = "${azurerm_resource_group.test.data.Locations.Primary}" account_tier = "Standard" account_replication_type = "LRS" } @@ -330,11 +277,11 @@ resource "azurerm_stream_analytics_reference_input_blob" "test" { type = "Avro" } } -`, template, rString, rInt) +`, template, data.RandomString, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsReferenceInputBlob_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsReferenceInputBlob_json(rInt, rString, location) +func testAccAzureRMStreamAnalyticsReferenceInputBlob_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsReferenceInputBlob_json(data) return fmt.Sprintf(` %s @@ -353,17 +300,17 @@ resource "azurerm_stream_analytics_reference_input_blob" "import" { `, template) } -func testAccAzureRMStreamAnalyticsReferenceInputBlob_template(rInt int, rString string, location string) string { +func testAccAzureRMStreamAnalyticsReferenceInputBlob_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" - location = "%s" + data.Locations.Primary = "%s" } resource "azurerm_storage_account" "test" { name = "acctestsa%s" resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + data.Locations.Primary = "${azurerm_resource_group.test.data.Locations.Primary}" account_tier = "Standard" account_replication_type = "LRS" } @@ -378,7 +325,7 @@ resource "azurerm_storage_container" "test" { resource "azurerm_stream_analytics_job" "test" { name = "acctestjob-%d" resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" + data.Locations.Primary = "${azurerm_resource_group.test.data.Locations.Primary}" compatibility_level = "1.0" data_locale = "en-GB" events_late_arrival_max_delay_in_seconds = 60 @@ -393,5 +340,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_blob_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_stream_input_blob_test.go similarity index 73% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_blob_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_stream_input_blob_test.go index ee4969f82d8c..e535c311b667 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_blob_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_stream_input_blob_test.go @@ -1,25 +1,19 @@ -package streamanalytics +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsStreamInputBlob_avro(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,29 +21,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputBlob_avro(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputBlob_avro(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsStreamInputBlob_avro(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } func TestAccAzureRMStreamAnalyticsStreamInputBlob_csv(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,29 +40,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputBlob_csv(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputBlob_csv(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsStreamInputBlob_csv(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } func TestAccAzureRMStreamAnalyticsStreamInputBlob_json(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,29 +59,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputBlob_json(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputBlob_json(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsStreamInputBlob_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } func TestAccAzureRMStreamAnalyticsStreamInputBlob_update(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -117,26 +78,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputBlob_update(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputBlob_json(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsStreamInputBlob_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputBlobExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsStreamInputBlob_updated(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsStreamInputBlob_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputBlobExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "storage_account_key", - }, - }, + data.ImportStep("storage_account_key"), }, }) } @@ -147,10 +100,7 @@ func TestAccAzureRMStreamAnalyticsStreamInputBlob_requiresImport(t *testing.T) { return } - resourceName := "azurerm_stream_analytics_stream_input_blob.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -158,15 +108,12 @@ func TestAccAzureRMStreamAnalyticsStreamInputBlob_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputBlob_json(ri, rs, location), + Config: testAccAzureRMStreamAnalyticsStreamInputBlob_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputBlobExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputBlobExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStreamAnalyticsStreamInputBlob_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_stream_input_blob"), - }, + data.RequiresImportErrorStep(testAccAzureRMStreamAnalyticsStreamInputBlob_requiresImport), }, }) } @@ -202,7 +149,7 @@ func testCheckAzureRMStreamAnalyticsStreamInputBlobDestroy(s *terraform.State) e conn := acceptance.AzureProvider.Meta().(*clients.Client).StreamAnalytics.InputsClient for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_stream_analytics_stream_input_eventhub" { + if rs.Type != "azurerm_stream_analytics_stream_input_blob" { continue } @@ -223,8 +170,8 @@ func testCheckAzureRMStreamAnalyticsStreamInputBlobDestroy(s *terraform.State) e return nil } -func testAccAzureRMStreamAnalyticsStreamInputBlob_avro(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsStreamInputBlob_avro(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputBlob_template(data) return fmt.Sprintf(` %s @@ -243,11 +190,11 @@ resource "azurerm_stream_analytics_stream_input_blob" "test" { type = "Avro" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputBlob_csv(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsStreamInputBlob_csv(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputBlob_template(data) return fmt.Sprintf(` %s @@ -268,11 +215,11 @@ resource "azurerm_stream_analytics_stream_input_blob" "test" { field_delimiter = "," } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputBlob_json(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsStreamInputBlob_json(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputBlob_template(data) return fmt.Sprintf(` %s @@ -292,11 +239,11 @@ resource "azurerm_stream_analytics_stream_input_blob" "test" { encoding = "UTF8" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputBlob_updated(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputBlob_template(rInt, rString, location) +func testAccAzureRMStreamAnalyticsStreamInputBlob_updated(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputBlob_template(data) return fmt.Sprintf(` %s @@ -330,11 +277,11 @@ resource "azurerm_stream_analytics_stream_input_blob" "test" { type = "Avro" } } -`, template, rString, rInt) +`, template, data.RandomString, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputBlob_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputBlob_json(rInt, rString, location) +func testAccAzureRMStreamAnalyticsStreamInputBlob_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputBlob_json(data) return fmt.Sprintf(` %s @@ -353,7 +300,7 @@ resource "azurerm_stream_analytics_stream_input_blob" "import" { `, template) } -func testAccAzureRMStreamAnalyticsStreamInputBlob_template(rInt int, rString string, location string) string { +func testAccAzureRMStreamAnalyticsStreamInputBlob_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -393,5 +340,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_eventhub_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_stream_input_eventhub_test.go similarity index 78% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_eventhub_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_stream_input_eventhub_test.go index 4c1f0a4d8f23..2fc6166fcdc9 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_eventhub_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_stream_input_eventhub_test.go @@ -1,4 +1,4 @@ -package streamanalytics +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsStreamInputEventHub_avro(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,28 +21,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputEventHub_avro(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_avro(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_avro(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsStreamInputEventHub_csv(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,28 +40,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputEventHub_csv(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_csv(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_csv(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsStreamInputEventHub_json(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,28 +59,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputEventHub_json(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_json(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsStreamInputEventHub_update(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,26 +78,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputEventHub_update(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_json(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_updated(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } @@ -141,9 +100,7 @@ func TestAccAzureRMStreamAnalyticsStreamInputEventHub_requiresImport(t *testing. return } - resourceName := "azurerm_stream_analytics_stream_input_eventhub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -151,15 +108,12 @@ func TestAccAzureRMStreamAnalyticsStreamInputEventHub_requiresImport(t *testing. CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_json(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputEventHubExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStreamAnalyticsStreamInputEventHub_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_stream_input_eventhub"), - }, + data.RequiresImportErrorStep(testAccAzureRMStreamAnalyticsStreamInputEventHub_requiresImport), }, }) } @@ -216,8 +170,8 @@ func testCheckAzureRMStreamAnalyticsStreamInputEventHubDestroy(s *terraform.Stat return nil } -func testAccAzureRMStreamAnalyticsStreamInputEventHub_avro(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputEventHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsStreamInputEventHub_avro(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputEventHub_template(data) return fmt.Sprintf(` %s @@ -235,11 +189,11 @@ resource "azurerm_stream_analytics_stream_input_eventhub" "test" { type = "Avro" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputEventHub_csv(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputEventHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsStreamInputEventHub_csv(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputEventHub_template(data) return fmt.Sprintf(` %s @@ -259,11 +213,11 @@ resource "azurerm_stream_analytics_stream_input_eventhub" "test" { field_delimiter = "," } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputEventHub_json(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputEventHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsStreamInputEventHub_json(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputEventHub_template(data) return fmt.Sprintf(` %s @@ -282,11 +236,11 @@ resource "azurerm_stream_analytics_stream_input_eventhub" "test" { encoding = "UTF8" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputEventHub_updated(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputEventHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsStreamInputEventHub_updated(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputEventHub_template(data) return fmt.Sprintf(` %s @@ -327,11 +281,11 @@ resource "azurerm_stream_analytics_stream_input_eventhub" "test" { type = "Avro" } } -`, template, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputEventHub_requiresImport(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputEventHub_json(rInt, location) +func testAccAzureRMStreamAnalyticsStreamInputEventHub_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputEventHub_json(data) return fmt.Sprintf(` %s @@ -349,7 +303,7 @@ resource "azurerm_stream_analytics_stream_input_eventhub" "import" { `, template) } -func testAccAzureRMStreamAnalyticsStreamInputEventHub_template(rInt int, location string) string { +func testAccAzureRMStreamAnalyticsStreamInputEventHub_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -397,5 +351,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_iothub_test.go b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_stream_input_iothub_test.go similarity index 77% rename from azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_iothub_test.go rename to azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_stream_input_iothub_test.go index 43d8bd67509c..9454ebb69af4 100644 --- a/azurerm/internal/services/streamanalytics/resource_arm_stream_analytics_stream_input_iothub_test.go +++ b/azurerm/internal/services/streamanalytics/tests/resource_arm_stream_analytics_stream_input_iothub_test.go @@ -1,4 +1,4 @@ -package streamanalytics +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStreamAnalyticsStreamInputIoTHub_avro(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_iothub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,28 +21,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputIoTHub_avro(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputIoTHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_avro(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_avro(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsStreamInputIoTHub_csv(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_iothub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,28 +40,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputIoTHub_csv(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputIoTHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_csv(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_csv(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsStreamInputIoTHub_json(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_iothub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,28 +59,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputIoTHub_json(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputIoTHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_json(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } func TestAccAzureRMStreamAnalyticsStreamInputIoTHub_update(t *testing.T) { - resourceName := "azurerm_stream_analytics_stream_input_iothub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,26 +78,18 @@ func TestAccAzureRMStreamAnalyticsStreamInputIoTHub_update(t *testing.T) { CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputIoTHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_json(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_updated(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "shared_access_policy_key", - }, - }, + data.ImportStep("shared_access_policy_key"), }, }) } @@ -141,9 +100,7 @@ func TestAccAzureRMStreamAnalyticsStreamInputIoTHub_requiresImport(t *testing.T) return } - resourceName := "azurerm_stream_analytics_stream_input_iothub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_stream_analytics_stream_input_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -151,13 +108,13 @@ func TestAccAzureRMStreamAnalyticsStreamInputIoTHub_requiresImport(t *testing.T) CheckDestroy: testCheckAzureRMStreamAnalyticsStreamInputIoTHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_json(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_json(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(resourceName), + testCheckAzureRMStreamAnalyticsStreamInputIoTHubExists(data.ResourceName), ), }, { - Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_requiresImport(ri, location), + Config: testAccAzureRMStreamAnalyticsStreamInputIoTHub_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_stream_analytics_stream_input_iothub"), }, }, @@ -216,8 +173,8 @@ func testCheckAzureRMStreamAnalyticsStreamInputIoTHubDestroy(s *terraform.State) return nil } -func testAccAzureRMStreamAnalyticsStreamInputIoTHub_avro(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputIoTHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsStreamInputIoTHub_avro(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputIoTHub_template(data) return fmt.Sprintf(` %s @@ -235,11 +192,11 @@ resource "azurerm_stream_analytics_stream_input_iothub" "test" { type = "Avro" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputIoTHub_csv(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputIoTHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsStreamInputIoTHub_csv(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputIoTHub_template(data) return fmt.Sprintf(` %s @@ -259,11 +216,11 @@ resource "azurerm_stream_analytics_stream_input_iothub" "test" { field_delimiter = "," } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputIoTHub_json(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputIoTHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsStreamInputIoTHub_json(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputIoTHub_template(data) return fmt.Sprintf(` %s @@ -282,11 +239,11 @@ resource "azurerm_stream_analytics_stream_input_iothub" "test" { encoding = "UTF8" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputIoTHub_updated(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputIoTHub_template(rInt, location) +func testAccAzureRMStreamAnalyticsStreamInputIoTHub_updated(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputIoTHub_template(data) return fmt.Sprintf(` %s @@ -316,11 +273,11 @@ resource "azurerm_stream_analytics_stream_input_iothub" "test" { type = "Avro" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMStreamAnalyticsStreamInputIoTHub_requiresImport(rInt int, location string) string { - template := testAccAzureRMStreamAnalyticsStreamInputIoTHub_json(rInt, location) +func testAccAzureRMStreamAnalyticsStreamInputIoTHub_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStreamAnalyticsStreamInputIoTHub_json(data) return fmt.Sprintf(` %s @@ -338,7 +295,7 @@ resource "azurerm_stream_analytics_stream_input_eventhub" "import" { `, template) } -func testAccAzureRMStreamAnalyticsStreamInputIoTHub_template(rInt int, location string) string { +func testAccAzureRMStreamAnalyticsStreamInputIoTHub_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -375,5 +332,5 @@ resource "azurerm_stream_analytics_job" "test" { FROM [YourInputAlias] QUERY } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } From f7ab7fcca023b51e6b94c6c6244db132045dbe0c Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Fri, 20 Dec 2019 09:54:24 -0800 Subject: [PATCH 093/203] test analysisservices --- ...ource_arm_analysis_services_server_test.go | 167 ++++++++---------- 1 file changed, 78 insertions(+), 89 deletions(-) rename azurerm/internal/services/analysisservices/{ => tests}/resource_arm_analysis_services_server_test.go (68%) diff --git a/azurerm/internal/services/analysisservices/resource_arm_analysis_services_server_test.go b/azurerm/internal/services/analysisservices/tests/resource_arm_analysis_services_server_test.go similarity index 68% rename from azurerm/internal/services/analysisservices/resource_arm_analysis_services_server_test.go rename to azurerm/internal/services/analysisservices/tests/resource_arm_analysis_services_server_test.go index 028dd0ade22c..4e315297bb4c 100644 --- a/azurerm/internal/services/analysisservices/resource_arm_analysis_services_server_test.go +++ b/azurerm/internal/services/analysisservices/tests/resource_arm_analysis_services_server_test.go @@ -1,4 +1,4 @@ -package analysisservices +package tests import ( "fmt" @@ -6,18 +6,15 @@ import ( "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMAnalysisServicesServer_basic(t *testing.T) { - resourceName := "azurerm_analysis_services_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_analysis_services_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,13 +22,13 @@ func TestAccAzureRMAnalysisServicesServer_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAnalysisServicesServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAnalysisServicesServer_basic(ri, acceptance.Location()), + Config: testAccAzureRMAnalysisServicesServer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAnalysisServicesServerExists(resourceName), + testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -40,10 +37,9 @@ func TestAccAzureRMAnalysisServicesServer_basic(t *testing.T) { } func TestAccAzureRMAnalysisServicesServer_withTags(t *testing.T) { - resourceName := "azurerm_analysis_services_server.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMAnalysisServicesServer_withTags(ri, acceptance.Location()) - postConfig := testAccAzureRMAnalysisServicesServer_withTagsUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_analysis_services_server", "test") + preConfig := testAccAzureRMAnalysisServicesServer_withTags(data) + postConfig := testAccAzureRMAnalysisServicesServer_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,18 +49,18 @@ func TestAccAzureRMAnalysisServicesServer_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAnalysisServicesServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.label", "test"), + testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.label", "test"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAnalysisServicesServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.label", "test1"), - resource.TestCheckResourceAttr(resourceName, "tags.ENV", "prod"), + testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.label", "test1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "prod"), ), }, }, @@ -72,10 +68,9 @@ func TestAccAzureRMAnalysisServicesServer_withTags(t *testing.T) { } func TestAccAzureRMAnalysisServicesServer_querypoolConnectionMode(t *testing.T) { - resourceName := "azurerm_analysis_services_server.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMAnalysisServicesServer_querypoolConnectionMode(ri, acceptance.Location(), "All") - postConfig := testAccAzureRMAnalysisServicesServer_querypoolConnectionMode(ri, acceptance.Location(), "ReadOnly") + data := acceptance.BuildTestData(t, "azurerm_analysis_services_server", "test") + preConfig := testAccAzureRMAnalysisServicesServer_querypoolConnectionMode(data, "All") + postConfig := testAccAzureRMAnalysisServicesServer_querypoolConnectionMode(data, "ReadOnly") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -85,15 +80,15 @@ func TestAccAzureRMAnalysisServicesServer_querypoolConnectionMode(t *testing.T) { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAnalysisServicesServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "querypool_connection_mode", "All"), + testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "querypool_connection_mode", "All"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAnalysisServicesServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "querypool_connection_mode", "ReadOnly"), + testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "querypool_connection_mode", "ReadOnly"), ), }, }, @@ -101,14 +96,12 @@ func TestAccAzureRMAnalysisServicesServer_querypoolConnectionMode(t *testing.T) } func TestAccAzureRMAnalysisServicesServer_firewallSettings(t *testing.T) { - resourceName := "azurerm_analysis_services_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_analysis_services_server", "test") + config1 := testAccAzureRMAnalysisServicesServer_firewallSettings1(data, true) - config1 := testAccAzureRMAnalysisServicesServer_firewallSettings1(ri, acceptance.Location(), true) + config2 := testAccAzureRMAnalysisServicesServer_firewallSettings2(data, false) - config2 := testAccAzureRMAnalysisServicesServer_firewallSettings2(ri, acceptance.Location(), false) - - config3 := testAccAzureRMAnalysisServicesServer_firewallSettings3(ri, acceptance.Location(), true) + config3 := testAccAzureRMAnalysisServicesServer_firewallSettings3(data, true) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -118,34 +111,34 @@ func TestAccAzureRMAnalysisServicesServer_firewallSettings(t *testing.T) { { Config: config1, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAnalysisServicesServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_power_bi_service", "true"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.#", "0"), + testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_power_bi_service", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.#", "0"), ), }, { Config: config2, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAnalysisServicesServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_power_bi_service", "false"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.0.name", "test1"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.0.range_start", "92.123.234.11"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.0.range_end", "92.123.234.12"), + testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_power_bi_service", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.0.name", "test1"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.0.range_start", "92.123.234.11"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.0.range_end", "92.123.234.12"), ), }, { Config: config3, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAnalysisServicesServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_power_bi_service", "true"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.#", "2"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.0.name", "test1"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.0.range_start", "92.123.234.11"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.0.range_end", "92.123.234.13"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.1.name", "test2"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.1.range_start", "226.202.187.57"), - resource.TestCheckResourceAttr(resourceName, "ipv4_firewall_rule.1.range_end", "226.208.192.47"), + testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_power_bi_service", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.0.name", "test1"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.0.range_start", "92.123.234.11"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.0.range_end", "92.123.234.13"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.1.name", "test2"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.1.range_start", "226.202.187.57"), + resource.TestCheckResourceAttr(data.ResourceName, "ipv4_firewall_rule.1.range_end", "226.208.192.47"), ), }, }, @@ -161,14 +154,13 @@ func TestAccAzureRMAnalysisServicesServer_adminUsers(t *testing.T) { return } - resourceName := "azurerm_analysis_services_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_analysis_services_server", "test") email1 := os.Getenv(ArmAccAdminEmail1) email2 := os.Getenv(ArmAccAdminEmail2) preAdminUsers := []string{email1} postAdminUsers := []string{email1, email2} - preConfig := testAccAzureRMAnalysisServicesServer_adminUsers(ri, acceptance.Location(), preAdminUsers) - postConfig := testAccAzureRMAnalysisServicesServer_adminUsers(ri, acceptance.Location(), postAdminUsers) + preConfig := testAccAzureRMAnalysisServicesServer_adminUsers(data, preAdminUsers) + postConfig := testAccAzureRMAnalysisServicesServer_adminUsers(data, postAdminUsers) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -179,7 +171,7 @@ func TestAccAzureRMAnalysisServicesServer_adminUsers(t *testing.T) { Config: preConfig, }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -187,7 +179,7 @@ func TestAccAzureRMAnalysisServicesServer_adminUsers(t *testing.T) { Config: postConfig, }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -196,8 +188,7 @@ func TestAccAzureRMAnalysisServicesServer_adminUsers(t *testing.T) { } func TestAccAzureRMAnalysisServicesServer_serverFullName(t *testing.T) { - resourceName := "azurerm_analysis_services_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_analysis_services_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -205,14 +196,14 @@ func TestAccAzureRMAnalysisServicesServer_serverFullName(t *testing.T) { CheckDestroy: testCheckAzureRMAnalysisServicesServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAnalysisServicesServer_serverFullName(ri, acceptance.Location()), + Config: testAccAzureRMAnalysisServicesServer_serverFullName(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAnalysisServicesServerExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "server_full_name"), + testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_full_name"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -221,9 +212,7 @@ func TestAccAzureRMAnalysisServicesServer_serverFullName(t *testing.T) { } func TestAccAzureRMAnalysisServicesServer_backupBlobContainerUri(t *testing.T) { - resourceName := "azurerm_analysis_services_server.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(6) + data := acceptance.BuildTestData(t, "azurerm_analysis_services_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -231,17 +220,17 @@ func TestAccAzureRMAnalysisServicesServer_backupBlobContainerUri(t *testing.T) { CheckDestroy: testCheckAzureRMAnalysisServicesServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAnalysisServicesServer_backupBlobContainerUri(ri, acceptance.Location(), rs), + Config: testAccAzureRMAnalysisServicesServer_backupBlobContainerUri(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAnalysisServicesServerExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "backup_blob_container_uri"), + testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "backup_blob_container_uri"), ), }, }, }) } -func testAccAzureRMAnalysisServicesServer_basic(rInt int, location string) string { +func testAccAzureRMAnalysisServicesServer_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -254,10 +243,10 @@ resource "azurerm_analysis_services_server" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "B1" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAnalysisServicesServer_withTags(rInt int, location string) string { +func testAccAzureRMAnalysisServicesServer_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -274,10 +263,10 @@ resource "azurerm_analysis_services_server" "test" { label = "test" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAnalysisServicesServer_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMAnalysisServicesServer_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -295,10 +284,10 @@ resource "azurerm_analysis_services_server" "test" { ENV = "prod" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAnalysisServicesServer_querypoolConnectionMode(rInt int, location, connectionMode string) string { +func testAccAzureRMAnalysisServicesServer_querypoolConnectionMode(data acceptance.TestData, connectionMode string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -312,10 +301,10 @@ resource "azurerm_analysis_services_server" "test" { sku = "B1" querypool_connection_mode = "%s" } -`, rInt, location, rInt, connectionMode) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, connectionMode) } -func testAccAzureRMAnalysisServicesServer_firewallSettings1(rInt int, location string, enablePowerBIService bool) string { +func testAccAzureRMAnalysisServicesServer_firewallSettings1(data acceptance.TestData, enablePowerBIService bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -329,10 +318,10 @@ resource "azurerm_analysis_services_server" "test" { sku = "B1" enable_power_bi_service = %t } -`, rInt, location, rInt, enablePowerBIService) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, enablePowerBIService) } -func testAccAzureRMAnalysisServicesServer_firewallSettings2(rInt int, location string, enablePowerBIService bool) string { +func testAccAzureRMAnalysisServicesServer_firewallSettings2(data acceptance.TestData, enablePowerBIService bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -352,10 +341,10 @@ resource "azurerm_analysis_services_server" "test" { range_end = "92.123.234.12" } } -`, rInt, location, rInt, enablePowerBIService) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, enablePowerBIService) } -func testAccAzureRMAnalysisServicesServer_firewallSettings3(rInt int, location string, enablePowerBIService bool) string { +func testAccAzureRMAnalysisServicesServer_firewallSettings3(data acceptance.TestData, enablePowerBIService bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -381,10 +370,10 @@ resource "azurerm_analysis_services_server" "test" { range_end = "226.208.192.47" } } -`, rInt, location, rInt, enablePowerBIService) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, enablePowerBIService) } -func testAccAzureRMAnalysisServicesServer_adminUsers(rInt int, location string, adminUsers []string) string { +func testAccAzureRMAnalysisServicesServer_adminUsers(data acceptance.TestData, adminUsers []string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -398,10 +387,10 @@ resource "azurerm_analysis_services_server" "test" { sku = "B1" admin_users = ["%s"] } -`, rInt, location, rInt, strings.Join(adminUsers, "\", \"")) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, strings.Join(adminUsers, "\", \"")) } -func testAccAzureRMAnalysisServicesServer_serverFullName(rInt int, location string) string { +func testAccAzureRMAnalysisServicesServer_serverFullName(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -414,10 +403,10 @@ resource "azurerm_analysis_services_server" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "B1" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAnalysisServicesServer_backupBlobContainerUri(rInt int, location string, rString string) string { +func testAccAzureRMAnalysisServicesServer_backupBlobContainerUri(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -465,7 +454,7 @@ resource "azurerm_analysis_services_server" "test" { backup_blob_container_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}${data.azurerm_storage_account_blob_container_sas.test.sas}" } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } func testCheckAzureRMAnalysisServicesServerDestroy(s *terraform.State) error { From 28a412a2cdbe571df928938e4cf80652f5ce5225 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Fri, 20 Dec 2019 11:47:40 -0800 Subject: [PATCH 094/203] apimanagement --- .../data_source_api_management_api_test.go | 91 -------- .../data_source_api_management_api_test.go | 86 +++++++ .../data_source_api_management_group_test.go | 21 +- ...data_source_api_management_product_test.go | 27 +-- .../data_source_api_management_test.go | 27 +-- .../data_source_api_management_user_test.go | 25 +- .../{ => tests}/diff_suppress_test.go | 5 +- ...pi_management_api_operation_policy_test.go | 53 ++--- ...e_arm_api_management_api_operation_test.go | 117 ++++------ ...urce_arm_api_management_api_policy_test.go | 63 ++--- ...urce_arm_api_management_api_schema_test.go | 43 ++-- .../resource_arm_api_management_api_test.go | 189 +++++++-------- ...arm_api_management_api_version_set_test.go | 101 ++++---- ...pi_management_authorization_server_test.go | 57 ++--- ...esource_arm_api_management_backend_test.go | 217 ++++++++---------- ...rce_arm_api_management_certificate_test.go | 41 ++-- ...urce_arm_api_management_diagnostic_test.go | 34 ++- .../resource_arm_api_management_group_test.go | 93 ++++---- ...urce_arm_api_management_group_user_test.go | 35 ++- ...resource_arm_api_management_logger_test.go | 185 +++++++-------- ...management_openid_connect_provider_test.go | 61 ++--- ...rce_arm_api_management_product_api_test.go | 35 ++- ...e_arm_api_management_product_group_test.go | 35 ++- ..._arm_api_management_product_policy_test.go | 53 ++--- ...esource_arm_api_management_product_test.go | 175 +++++++------- ...source_arm_api_management_property_test.go | 59 +++-- ...ce_arm_api_management_subscription_test.go | 111 ++++----- .../resource_arm_api_management_test.go | 134 +++++------ .../resource_arm_api_management_user_test.go | 165 ++++++------- .../testdata/api_management_api2_test.pfx | Bin .../testdata/api_management_api_schema.xml | 0 .../testdata/api_management_api_swagger.json | 0 .../testdata/api_management_api_test.pfx | Bin .../testdata/api_management_api_wsdl.xml | 0 .../testdata/api_management_portal_test.pfx | Bin .../testdata/api_management_testdata.sh | 0 .../{ => tests}/testdata/keyvaultcert.pfx | Bin 37 files changed, 1023 insertions(+), 1315 deletions(-) delete mode 100644 azurerm/internal/services/apimanagement/data_source_api_management_api_test.go create mode 100644 azurerm/internal/services/apimanagement/tests/data_source_api_management_api_test.go rename azurerm/internal/services/apimanagement/{ => tests}/data_source_api_management_group_test.go (67%) rename azurerm/internal/services/apimanagement/{ => tests}/data_source_api_management_product_test.go (62%) rename azurerm/internal/services/apimanagement/{ => tests}/data_source_api_management_test.go (54%) rename azurerm/internal/services/apimanagement/{ => tests}/data_source_api_management_user_test.go (64%) rename azurerm/internal/services/apimanagement/{ => tests}/diff_suppress_test.go (96%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_api_operation_policy_test.go (80%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_api_operation_test.go (79%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_api_policy_test.go (78%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_api_schema_test.go (79%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_api_test.go (69%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_api_version_set_test.go (68%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_authorization_server_test.go (82%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_backend_test.go (59%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_certificate_test.go (77%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_diagnostic_test.go (79%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_group_test.go (64%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_group_user_test.go (81%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_logger_test.go (57%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_openid_connect_provider_test.go (79%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_product_api_test.go (82%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_product_group_test.go (81%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_product_policy_test.go (79%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_product_test.go (63%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_property_test.go (68%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_subscription_test.go (64%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_test.go (78%) rename azurerm/internal/services/apimanagement/{ => tests}/resource_arm_api_management_user_test.go (65%) rename azurerm/internal/services/apimanagement/{ => tests}/testdata/api_management_api2_test.pfx (100%) rename azurerm/internal/services/apimanagement/{ => tests}/testdata/api_management_api_schema.xml (100%) rename azurerm/internal/services/apimanagement/{ => tests}/testdata/api_management_api_swagger.json (100%) rename azurerm/internal/services/apimanagement/{ => tests}/testdata/api_management_api_test.pfx (100%) rename azurerm/internal/services/apimanagement/{ => tests}/testdata/api_management_api_wsdl.xml (100%) rename azurerm/internal/services/apimanagement/{ => tests}/testdata/api_management_portal_test.pfx (100%) rename azurerm/internal/services/apimanagement/{ => tests}/testdata/api_management_testdata.sh (100%) rename azurerm/internal/services/apimanagement/{ => tests}/testdata/keyvaultcert.pfx (100%) diff --git a/azurerm/internal/services/apimanagement/data_source_api_management_api_test.go b/azurerm/internal/services/apimanagement/data_source_api_management_api_test.go deleted file mode 100644 index 269e474f3682..000000000000 --- a/azurerm/internal/services/apimanagement/data_source_api_management_api_test.go +++ /dev/null @@ -1,91 +0,0 @@ -package apimanagement - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMApiManagementApi_basic(t *testing.T) { - dataSourceName := "data.azurerm_api_management_api.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceApiManagementApi_basic(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "display_name", "api1"), - resource.TestCheckResourceAttr(dataSourceName, "path", "api1"), - resource.TestCheckResourceAttr(dataSourceName, "protocols.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "protocols.0", "https"), - resource.TestCheckResourceAttr(dataSourceName, "soap_pass_through", "false"), - resource.TestCheckResourceAttr(dataSourceName, "is_current", "true"), - resource.TestCheckResourceAttr(dataSourceName, "is_online", "false"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMApiManagementApi_complete(t *testing.T) { - dataSourceName := "data.azurerm_api_management_api.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceApiManagementApi_complete(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "display_name", "Butter Parser"), - resource.TestCheckResourceAttr(dataSourceName, "path", "butter-parser"), - resource.TestCheckResourceAttr(dataSourceName, "protocols.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "description", "What is my purpose? You parse butter."), - resource.TestCheckResourceAttr(dataSourceName, "service_url", "https://example.com/foo/bar"), - resource.TestCheckResourceAttr(dataSourceName, "soap_pass_through", "false"), - resource.TestCheckResourceAttr(dataSourceName, "subscription_key_parameter_names.0.header", "X-Butter-Robot-API-Key"), - resource.TestCheckResourceAttr(dataSourceName, "subscription_key_parameter_names.0.query", "location"), - resource.TestCheckResourceAttr(dataSourceName, "is_current", "true"), - resource.TestCheckResourceAttr(dataSourceName, "is_online", "false"), - ), - }, - }, - }) -} - -func testAccDataSourceApiManagementApi_basic(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_basic(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_api_management_api" "test" { - name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management_api.test.api_management_name}" - resource_group_name = "${azurerm_api_management_api.test.resource_group_name}" - revision = "${azurerm_api_management_api.test.revision}" -} -`, template) -} - -func testAccDataSourceApiManagementApi_complete(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_complete(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_api_management_api" "test" { - name = "${azurerm_api_management_api.test.name}" - api_management_name = "${azurerm_api_management_api.test.api_management_name}" - resource_group_name = "${azurerm_api_management_api.test.resource_group_name}" - revision = "${azurerm_api_management_api.test.revision}" -} -`, template) -} diff --git a/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_test.go new file mode 100644 index 000000000000..d08c94c5f975 --- /dev/null +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_api_test.go @@ -0,0 +1,86 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMApiManagementApi_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_api_management_api", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceApiManagementApi_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "api1"), + resource.TestCheckResourceAttr(data.ResourceName, "path", "api1"), + resource.TestCheckResourceAttr(data.ResourceName, "protocols.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "protocols.0", "https"), + resource.TestCheckResourceAttr(data.ResourceName, "soap_pass_through", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "is_current", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMApiManagementApi_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_api_management_api", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceApiManagementApi_complete(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Butter Parser"), + resource.TestCheckResourceAttr(data.ResourceName, "path", "butter-parser"), + resource.TestCheckResourceAttr(data.ResourceName, "protocols.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "What is my purpose? You parse butter."), + resource.TestCheckResourceAttr(data.ResourceName, "service_url", "https://example.com/foo/bar"), + resource.TestCheckResourceAttr(data.ResourceName, "soap_pass_through", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_key_parameter_names.0.header", "X-Butter-Robot-API-Key"), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_key_parameter_names.0.query", "location"), + resource.TestCheckResourceAttr(data.ResourceName, "is_current", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"), + ), + }, + }, + }) +} + +func testAccDataSourceApiManagementApi_basic(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_api_management_api" "test" { + name = "${azurerm_api_management_api.test.name}" + api_management_name = "${azurerm_api_management_api.test.api_management_name}" + resource_group_name = "${azurerm_api_management_api.test.resource_group_name}" + revision = "${azurerm_api_management_api.test.revision}" +} +`, template) +} + +func testAccDataSourceApiManagementApi_complete(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_complete(data) + return fmt.Sprintf(` +%s + +data "azurerm_api_management_api" "test" { + name = "${azurerm_api_management_api.test.name}" + api_management_name = "${azurerm_api_management_api.test.api_management_name}" + resource_group_name = "${azurerm_api_management_api.test.resource_group_name}" + revision = "${azurerm_api_management_api.test.revision}" +} +`, template) +} diff --git a/azurerm/internal/services/apimanagement/data_source_api_management_group_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_group_test.go similarity index 67% rename from azurerm/internal/services/apimanagement/data_source_api_management_group_test.go rename to azurerm/internal/services/apimanagement/tests/data_source_api_management_group_test.go index ec3f35e824b2..a5b18026b829 100644 --- a/azurerm/internal/services/apimanagement/data_source_api_management_group_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_group_test.go @@ -1,37 +1,34 @@ -package apimanagement +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMApiManagementGroup_basic(t *testing.T) { - dataSourceName := "data.azurerm_api_management_group.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_api_management_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceApiManagementGroup_basic(rInt, location), + Config: testAccDataSourceApiManagementGroup_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "display_name", "Test Group"), - resource.TestCheckResourceAttr(dataSourceName, "description", ""), - resource.TestCheckResourceAttr(dataSourceName, "external_id", ""), - resource.TestCheckResourceAttr(dataSourceName, "type", "custom"), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Test Group"), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), + resource.TestCheckResourceAttr(data.ResourceName, "external_id", ""), + resource.TestCheckResourceAttr(data.ResourceName, "type", "custom"), ), }, }, }) } -func testAccDataSourceApiManagementGroup_basic(rInt int, location string) string { +func testAccDataSourceApiManagementGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -63,5 +60,5 @@ data "azurerm_api_management_group" "test" { api_management_name = "${azurerm_api_management_group.test.api_management_name}" resource_group_name = "${azurerm_api_management_group.test.resource_group_name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/data_source_api_management_product_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_product_test.go similarity index 62% rename from azurerm/internal/services/apimanagement/data_source_api_management_product_test.go rename to azurerm/internal/services/apimanagement/tests/data_source_api_management_product_test.go index 8cc1fe1346b8..4c6ae3ae6017 100644 --- a/azurerm/internal/services/apimanagement/data_source_api_management_product_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_product_test.go @@ -1,40 +1,37 @@ -package apimanagement +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMApiManagementProduct_basic(t *testing.T) { - dataSourceName := "data.azurerm_api_management_product.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_api_management_product", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceApiManagementProduct_basic(rInt, location), + Config: testAccDataSourceApiManagementProduct_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "product_id", "test-product"), - resource.TestCheckResourceAttr(dataSourceName, "display_name", "Test Product"), - resource.TestCheckResourceAttr(dataSourceName, "subscription_required", "true"), - resource.TestCheckResourceAttr(dataSourceName, "approval_required", "true"), - resource.TestCheckResourceAttr(dataSourceName, "published", "true"), - resource.TestCheckResourceAttr(dataSourceName, "description", "This is an example description"), - resource.TestCheckResourceAttr(dataSourceName, "terms", "These are some example terms and conditions"), + resource.TestCheckResourceAttr(data.ResourceName, "product_id", "test-product"), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Test Product"), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "approval_required", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "published", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This is an example description"), + resource.TestCheckResourceAttr(data.ResourceName, "terms", "These are some example terms and conditions"), ), }, }, }) } -func testAccDataSourceApiManagementProduct_basic(rInt int, location string) string { +func testAccDataSourceApiManagementProduct_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "amtestRG-%d" @@ -73,5 +70,5 @@ data "azurerm_api_management_product" "test" { api_management_name = "${azurerm_api_management_product.test.api_management_name}" resource_group_name = "${azurerm_api_management_product.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/data_source_api_management_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_test.go similarity index 54% rename from azurerm/internal/services/apimanagement/data_source_api_management_test.go rename to azurerm/internal/services/apimanagement/tests/data_source_api_management_test.go index afb68fb4c2a0..0efd692c1e06 100644 --- a/azurerm/internal/services/apimanagement/data_source_api_management_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_test.go @@ -1,40 +1,37 @@ -package apimanagement +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMApiManagement_basic(t *testing.T) { - dataSourceName := "data.azurerm_api_management.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_api_management", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceApiManagement_basic(rInt, location), + Config: testAccDataSourceApiManagement_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "publisher_email", "pub1@email.com"), - resource.TestCheckResourceAttr(dataSourceName, "publisher_name", "pub1"), - resource.TestCheckResourceAttr(dataSourceName, "sku.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.name", "Developer"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - resource.TestCheckResourceAttrSet(dataSourceName, "public_ip_addresses.#"), + resource.TestCheckResourceAttr(data.ResourceName, "publisher_email", "pub1@email.com"), + resource.TestCheckResourceAttr(data.ResourceName, "publisher_name", "pub1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Developer"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_ip_addresses.#"), ), }, }, }) } -func testAccDataSourceApiManagement_basic(rInt int, location string) string { +func testAccDataSourceApiManagement_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "amtestRG-%d" @@ -59,5 +56,5 @@ data "azurerm_api_management" "test" { name = "${azurerm_api_management.test.name}" resource_group_name = "${azurerm_api_management.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/data_source_api_management_user_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go similarity index 64% rename from azurerm/internal/services/apimanagement/data_source_api_management_user_test.go rename to azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go index b18e2a3e727a..23251c840887 100644 --- a/azurerm/internal/services/apimanagement/data_source_api_management_user_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go @@ -1,39 +1,36 @@ -package apimanagement +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMApiManagementUser_basic(t *testing.T) { - dataSourceName := "data.azurerm_api_management_user.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_api_management_user", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceApiManagementUser_basic(rInt, location), + Config: testAccDataSourceApiManagementUser_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "user_id", "test-user"), - resource.TestCheckResourceAttr(dataSourceName, "first_name", "Acceptance"), - resource.TestCheckResourceAttr(dataSourceName, "last_name", "Test"), - resource.TestCheckResourceAttr(dataSourceName, "email", fmt.Sprintf("azure-acctest%d@example.com", rInt)), - resource.TestCheckResourceAttr(dataSourceName, "state", "active"), - resource.TestCheckResourceAttr(dataSourceName, "note", "Used for testing in dimension C-137."), + resource.TestCheckResourceAttr(data.ResourceName, "user_id", "test-user"), + resource.TestCheckResourceAttr(data.ResourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(data.ResourceName, "last_name", "Test"), + resource.TestCheckResourceAttr(data.ResourceName, "email", fmt.Sprintf("azure-acctest%d@example.com", rInt)), + resource.TestCheckResourceAttr(data.ResourceName, "state", "active"), + resource.TestCheckResourceAttr(data.ResourceName, "note", "Used for testing in dimension C-137."), ), }, }, }) } -func testAccDataSourceApiManagementUser_basic(rInt int, location string) string { +func testAccDataSourceApiManagementUser_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "amtestRG-%d" @@ -70,5 +67,5 @@ data "azurerm_api_management_user" "test" { api_management_name = "${azurerm_api_management_user.test.api_management_name}" resource_group_name = "${azurerm_api_management_user.test.resource_group_name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, &data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/diff_suppress_test.go b/azurerm/internal/services/apimanagement/tests/diff_suppress_test.go similarity index 96% rename from azurerm/internal/services/apimanagement/diff_suppress_test.go rename to azurerm/internal/services/apimanagement/tests/diff_suppress_test.go index f214e1b768b0..48a784724def 100644 --- a/azurerm/internal/services/apimanagement/diff_suppress_test.go +++ b/azurerm/internal/services/apimanagement/tests/diff_suppress_test.go @@ -1,6 +1,7 @@ -package apimanagement +package tests import ( + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement" "log" "testing" ) @@ -95,7 +96,7 @@ func TestXmlWithDotNetInterpolationsDiffSuppress(t *testing.T) { for _, v := range testData { log.Printf("[DEBUG] Testing %q vs %q..", v.old, v.new) - actual := XmlWithDotNetInterpolationsDiffSuppress("", v.old, v.new, nil) + actual := apimanagement.XmlWithDotNetInterpolationsDiffSuppress("", v.old, v.new, nil) if actual != v.same { t.Fatalf("Expected %t but got %t", v.same, actual) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_policy_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_policy_test.go similarity index 80% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_policy_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_policy_test.go index e54ea72d5d2f..1bce89956630 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_policy_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_policy_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementAPIOperationPolicy_basic(t *testing.T) { - resourceName := "azurerm_api_management_api_operation_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_operation_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMApiManagementAPIOperationPolicy_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementAPIOperationPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementAPIOperationPolicy_basic(ri, location), + Config: testAccAzureRMApiManagementAPIOperationPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementAPIOperationPolicyExists(resourceName), + testCheckAzureRMApiManagementAPIOperationPolicyExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"xml_link"}, @@ -44,10 +41,7 @@ func TestAccAzureRMApiManagementAPIOperationPolicy_requiresImport(t *testing.T) t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_api_operation_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_operation_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,23 +49,18 @@ func TestAccAzureRMApiManagementAPIOperationPolicy_requiresImport(t *testing.T) CheckDestroy: testCheckAzureRMApiManagementAPIOperationPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementAPIOperationPolicy_basic(ri, location), + Config: testAccAzureRMApiManagementAPIOperationPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementAPIOperationPolicyExists(resourceName), + testCheckAzureRMApiManagementAPIOperationPolicyExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementAPIOperationPolicy_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_api_policy"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementAPIOperationPolicy_requiresImport), }, }) } func TestAccAzureRMApiManagementAPIOperationPolicy_update(t *testing.T) { - resourceName := "azurerm_api_management_api_operation_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_operation_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,19 +68,19 @@ func TestAccAzureRMApiManagementAPIOperationPolicy_update(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementAPIOperationPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementAPIOperationPolicy_basic(ri, location), + Config: testAccAzureRMApiManagementAPIOperationPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementAPIOperationPolicyExists(resourceName), + testCheckAzureRMApiManagementAPIOperationPolicyExists(data.ResourceName), ), }, { - Config: testAccAzureRMApiManagementAPIOperationPolicy_updated(ri, location), + Config: testAccAzureRMApiManagementAPIOperationPolicy_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementAPIOperationPolicyExists(resourceName), + testCheckAzureRMApiManagementAPIOperationPolicyExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"xml_link"}, @@ -157,8 +146,8 @@ func testCheckAzureRMApiManagementAPIOperationPolicyDestroy(s *terraform.State) return nil } -func testAccAzureRMApiManagementAPIOperationPolicy_basic(rInt int, location string) string { - template := testAccAzureRMApiManagementApiOperation_basic(rInt, location) +func testAccAzureRMApiManagementAPIOperationPolicy_basic(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiOperation_basic(data) return fmt.Sprintf(` %s @@ -173,8 +162,8 @@ resource "azurerm_api_management_api_operation_policy" "test" { `, template) } -func testAccAzureRMApiManagementAPIOperationPolicy_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementAPIOperationPolicy_basic(rInt, location) +func testAccAzureRMApiManagementAPIOperationPolicy_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementAPIOperationPolicy_basic(data) return fmt.Sprintf(` %s @@ -188,8 +177,8 @@ resource "azurerm_api_management_api_operation_policy" "import" { `, template) } -func testAccAzureRMApiManagementAPIOperationPolicy_updated(rInt int, location string) string { - template := testAccAzureRMApiManagementApiOperation_basic(rInt, location) +func testAccAzureRMApiManagementAPIOperationPolicy_updated(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiOperation_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go similarity index 79% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go index 36e95a30b957..ae44c431f0d8 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementApiOperation_basic(t *testing.T) { - resourceName := "azurerm_api_management_api_operation.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_operation", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMApiManagementApiOperation_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiOperationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiOperation_basic(ri, location), + Config: testAccAzureRMApiManagementApiOperation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiOperationExists(resourceName), + testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -43,10 +40,7 @@ func TestAccAzureRMApiManagementApiOperation_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_api_operation.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_operation", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,23 +48,18 @@ func TestAccAzureRMApiManagementApiOperation_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiOperationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiOperation_basic(ri, location), + Config: testAccAzureRMApiManagementApiOperation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiOperationExists(resourceName), + testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementApiOperation_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_api_operation"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementApiOperation_requiresImport), }, }) } func TestAccAzureRMApiManagementApiOperation_customMethod(t *testing.T) { - resourceName := "azurerm_api_management_api_operation.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_operation", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,14 +67,14 @@ func TestAccAzureRMApiManagementApiOperation_customMethod(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiOperationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiOperation_customMethod(ri, location), + Config: testAccAzureRMApiManagementApiOperation_customMethod(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiOperationExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "method", "HAMMERTIME"), + testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "method", "HAMMERTIME"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -94,9 +83,7 @@ func TestAccAzureRMApiManagementApiOperation_customMethod(t *testing.T) { } func TestAccAzureRMApiManagementApiOperation_headers(t *testing.T) { - resourceName := "azurerm_api_management_api_operation.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_operation", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,13 +91,13 @@ func TestAccAzureRMApiManagementApiOperation_headers(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiOperationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiOperation_headers(ri, location), + Config: testAccAzureRMApiManagementApiOperation_headers(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiOperationExists(resourceName), + testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -119,9 +106,7 @@ func TestAccAzureRMApiManagementApiOperation_headers(t *testing.T) { } func TestAccAzureRMApiManagementApiOperation_requestRepresentations(t *testing.T) { - resourceName := "azurerm_api_management_api_operation.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_operation", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -129,24 +114,24 @@ func TestAccAzureRMApiManagementApiOperation_requestRepresentations(t *testing.T CheckDestroy: testCheckAzureRMApiManagementApiOperationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiOperation_requestRepresentation(ri, location), + Config: testAccAzureRMApiManagementApiOperation_requestRepresentation(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiOperationExists(resourceName), + testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, { - Config: testAccAzureRMApiManagementApiOperation_requestRepresentationUpdated(ri, location), + Config: testAccAzureRMApiManagementApiOperation_requestRepresentationUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiOperationExists(resourceName), + testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -156,9 +141,7 @@ func TestAccAzureRMApiManagementApiOperation_requestRepresentations(t *testing.T func TestAccAzureRMApiManagementApiOperation_representations(t *testing.T) { // TODO: once `azurerm_api_management_schema` is supported add `request.0.representation.0.schema_id` - resourceName := "azurerm_api_management_api_operation.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_operation", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -166,24 +149,24 @@ func TestAccAzureRMApiManagementApiOperation_representations(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiOperationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiOperation_representation(ri, location), + Config: testAccAzureRMApiManagementApiOperation_representation(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiOperationExists(resourceName), + testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, { - Config: testAccAzureRMApiManagementApiOperation_representationUpdated(ri, location), + Config: testAccAzureRMApiManagementApiOperation_representationUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiOperationExists(resourceName), + testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -249,8 +232,8 @@ func testCheckAzureRMApiManagementApiOperationExists(name string) resource.TestC } } -func testAccAzureRMApiManagementApiOperation_basic(rInt int, location string) string { - template := testAccAzureRMApiManagementApiOperation_template(rInt, location) +func testAccAzureRMApiManagementApiOperation_basic(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiOperation_template(data) return fmt.Sprintf(` %s @@ -266,8 +249,8 @@ resource "azurerm_api_management_api_operation" "test" { `, template) } -func testAccAzureRMApiManagementApiOperation_customMethod(rInt int, location string) string { - template := testAccAzureRMApiManagementApiOperation_template(rInt, location) +func testAccAzureRMApiManagementApiOperation_customMethod(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiOperation_template(data) return fmt.Sprintf(` %s @@ -283,8 +266,8 @@ resource "azurerm_api_management_api_operation" "test" { `, template) } -func testAccAzureRMApiManagementApiOperation_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementApiOperation_template(rInt, location) +func testAccAzureRMApiManagementApiOperation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiOperation_template(data) return fmt.Sprintf(` %s @@ -300,8 +283,8 @@ resource "azurerm_api_management_api_operation" "import" { `, template) } -func testAccAzureRMApiManagementApiOperation_requestRepresentation(rInt int, location string) string { - template := testAccAzureRMApiManagementApiOperation_template(rInt, location) +func testAccAzureRMApiManagementApiOperation_requestRepresentation(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiOperation_template(data) return fmt.Sprintf(` %s @@ -327,8 +310,8 @@ resource "azurerm_api_management_api_operation" "test" { `, template) } -func testAccAzureRMApiManagementApiOperation_requestRepresentationUpdated(rInt int, location string) string { - template := testAccAzureRMApiManagementApiOperation_template(rInt, location) +func testAccAzureRMApiManagementApiOperation_requestRepresentationUpdated(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiOperation_template(data) return fmt.Sprintf(` %s @@ -354,8 +337,8 @@ resource "azurerm_api_management_api_operation" "test" { `, template) } -func testAccAzureRMApiManagementApiOperation_headers(rInt int, location string) string { - template := testAccAzureRMApiManagementApiOperation_template(rInt, location) +func testAccAzureRMApiManagementApiOperation_headers(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiOperation_template(data) return fmt.Sprintf(` %s @@ -413,8 +396,8 @@ SAMPLE `, template) } -func testAccAzureRMApiManagementApiOperation_representation(rInt int, location string) string { - template := testAccAzureRMApiManagementApiOperation_template(rInt, location) +func testAccAzureRMApiManagementApiOperation_representation(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiOperation_template(data) return fmt.Sprintf(` %s @@ -460,8 +443,8 @@ SAMPLE `, template) } -func testAccAzureRMApiManagementApiOperation_representationUpdated(rInt int, location string) string { - template := testAccAzureRMApiManagementApiOperation_template(rInt, location) +func testAccAzureRMApiManagementApiOperation_representationUpdated(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiOperation_template(data) return fmt.Sprintf(` %s @@ -528,7 +511,7 @@ SAMPLE `, template) } -func testAccAzureRMApiManagementApiOperation_template(rInt int, location string) string { +func testAccAzureRMApiManagementApiOperation_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -564,5 +547,5 @@ resource "azurerm_api_management_api" "test" { query = "location" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_policy_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_policy_test.go similarity index 78% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_api_policy_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_policy_test.go index 9b53a7c64811..6d6a90a4e7f1 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_policy_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_policy_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementAPIPolicy_basic(t *testing.T) { - resourceName := "azurerm_api_management_api_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMApiManagementAPIPolicy_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementAPIPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementAPIPolicy_basic(ri, location), + Config: testAccAzureRMApiManagementAPIPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementAPIPolicyExists(resourceName), + testCheckAzureRMApiManagementAPIPolicyExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"xml_link"}, @@ -44,10 +41,7 @@ func TestAccAzureRMApiManagementAPIPolicy_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_api_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,23 +49,18 @@ func TestAccAzureRMApiManagementAPIPolicy_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementAPIPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementAPIPolicy_basic(ri, location), + Config: testAccAzureRMApiManagementAPIPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementAPIPolicyExists(resourceName), + testCheckAzureRMApiManagementAPIPolicyExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementAPIPolicy_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_api_policy"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementAPIPolicy_requiresImport), }, }) } func TestAccAzureRMApiManagementAPIPolicy_update(t *testing.T) { - resourceName := "azurerm_api_management_api_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,19 +68,19 @@ func TestAccAzureRMApiManagementAPIPolicy_update(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementAPIPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementAPIPolicy_basic(ri, location), + Config: testAccAzureRMApiManagementAPIPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementAPIPolicyExists(resourceName), + testCheckAzureRMApiManagementAPIPolicyExists(data.ResourceName), ), }, { - Config: testAccAzureRMApiManagementAPIPolicy_customPolicy(ri, location), + Config: testAccAzureRMApiManagementAPIPolicy_customPolicy(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementAPIPolicyExists(resourceName), + testCheckAzureRMApiManagementAPIPolicyExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"xml_link"}, @@ -101,9 +90,7 @@ func TestAccAzureRMApiManagementAPIPolicy_update(t *testing.T) { } func TestAccAzureRMApiManagementAPIPolicy_customPolicy(t *testing.T) { - resourceName := "azurerm_api_management_api_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,13 +98,13 @@ func TestAccAzureRMApiManagementAPIPolicy_customPolicy(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementAPIPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementAPIPolicy_customPolicy(ri, location), + Config: testAccAzureRMApiManagementAPIPolicy_customPolicy(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementAPIPolicyExists(resourceName), + testCheckAzureRMApiManagementAPIPolicyExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"xml_link"}, @@ -180,7 +167,7 @@ func testCheckAzureRMApiManagementAPIPolicyDestroy(s *terraform.State) error { return nil } -func testAccAzureRMApiManagementAPIPolicy_basic(rInt int, location string) string { +func testAccAzureRMApiManagementAPIPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -216,11 +203,11 @@ resource "azurerm_api_management_api_policy" "test" { resource_group_name = "${azurerm_resource_group.test.name}" xml_link = "https://gist.githubusercontent.com/riordanp/ca22f8113afae0eb38cc12d718fd048d/raw/d6ac89a2f35a6881a7729f8cb4883179dc88eea1/example.xml" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementAPIPolicy_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementAPIPolicy_basic(rInt, location) +func testAccAzureRMApiManagementAPIPolicy_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementAPIPolicy_basic(data) return fmt.Sprintf(` %s @@ -233,7 +220,7 @@ resource "azurerm_api_management_api_policy" "import" { `, template) } -func testAccAzureRMApiManagementAPIPolicy_customPolicy(rInt int, location string) string { +func testAccAzureRMApiManagementAPIPolicy_customPolicy(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -277,5 +264,5 @@ resource "azurerm_api_management_api_policy" "test" { XML } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_schema_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go similarity index 79% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_api_schema_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go index b0b650f1ed0d..45b30785bd3e 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_schema_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementApiSchema_basic(t *testing.T) { - resourceName := "azurerm_api_management_api_schema.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_schema", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMApiManagementApiSchema_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiSchemaDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiSchema_basic(ri, location), + Config: testAccAzureRMApiManagementApiSchema_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiSchemaExists(resourceName), + testCheckAzureRMApiManagementApiSchemaExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -43,10 +40,7 @@ func TestAccAzureRMApiManagementApiSchema_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_api_schema.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_schema", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,15 +48,12 @@ func TestAccAzureRMApiManagementApiSchema_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiSchemaDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiSchema_basic(ri, location), + Config: testAccAzureRMApiManagementApiSchema_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiSchemaExists(resourceName), + testCheckAzureRMApiManagementApiSchemaExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementApiSchema_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_api_schema"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementApiSchema_requiresImport), }, }) } @@ -125,8 +116,8 @@ func testCheckAzureRMApiManagementApiSchemaExists(name string) resource.TestChec } } -func testAccAzureRMApiManagementApiSchema_basic(rInt int, location string) string { - template := testAccAzureRMApiManagementApiSchema_template(rInt, location) +func testAccAzureRMApiManagementApiSchema_basic(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiSchema_template(data) return fmt.Sprintf(` %s @@ -138,11 +129,11 @@ resource "azurerm_api_management_api_schema" "test" { content_type = "application/vnd.ms-azure-apim.xsd+xml" value = "${file("testdata/api_management_api_schema.xml")}" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementApiSchema_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementApiSchema_template(rInt, location) +func testAccAzureRMApiManagementApiSchema_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiSchema_template(data) return fmt.Sprintf(` %s @@ -154,10 +145,10 @@ resource "azurerm_api_management_api_schema" "test" { content_type = "application/vnd.ms-azure-apim.xsd+xml" value = "${file("testdata/api_management_api_schema.xml")}" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementApiSchema_template(rInt int, location string) string { +func testAccAzureRMApiManagementApiSchema_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -186,5 +177,5 @@ resource "azurerm_api_management_api" "test" { protocols = ["https"] revision = "1" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go similarity index 69% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_api_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go index 7ac4c27b8016..3f524561b005 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementApi_basic(t *testing.T) { - resourceName := "azurerm_api_management_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +21,16 @@ func TestAccAzureRMApiManagementApi_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApi_basic(ri, location), + Config: testAccAzureRMApiManagementApi_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "soap_pass_through", "false"), - resource.TestCheckResourceAttr(resourceName, "is_current", "true"), - resource.TestCheckResourceAttr(resourceName, "is_online", "false"), + testCheckAzureRMApiManagementApiExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soap_pass_through", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "is_current", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -43,9 +40,7 @@ func TestAccAzureRMApiManagementApi_basic(t *testing.T) { // Remove in 2.0 func TestAccAzureRMApiManagementApi_basicClassic(t *testing.T) { - resourceName := "azurerm_api_management_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,16 +48,16 @@ func TestAccAzureRMApiManagementApi_basicClassic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApi_basicClassic(ri, location), + Config: testAccAzureRMApiManagementApi_basicClassic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "soap_pass_through", "false"), - resource.TestCheckResourceAttr(resourceName, "is_current", "true"), - resource.TestCheckResourceAttr(resourceName, "is_online", "false"), + testCheckAzureRMApiManagementApiExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soap_pass_through", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "is_current", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -71,9 +66,7 @@ func TestAccAzureRMApiManagementApi_basicClassic(t *testing.T) { } func TestAccAzureRMApiManagementApi_wordRevision(t *testing.T) { - resourceName := "azurerm_api_management_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,14 +74,14 @@ func TestAccAzureRMApiManagementApi_wordRevision(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApi_wordRevision(ri, location), + Config: testAccAzureRMApiManagementApi_wordRevision(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "revision", "one-point-oh"), + testCheckAzureRMApiManagementApiExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "revision", "one-point-oh"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -97,9 +90,7 @@ func TestAccAzureRMApiManagementApi_wordRevision(t *testing.T) { } func TestAccAzureRMApiManagementApi_version(t *testing.T) { - resourceName := "azurerm_api_management_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -107,14 +98,14 @@ func TestAccAzureRMApiManagementApi_version(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApi_versionSet(ri, location), + Config: testAccAzureRMApiManagementApi_versionSet(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "version", "v1"), + testCheckAzureRMApiManagementApiExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "version", "v1"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -127,10 +118,7 @@ func TestAccAzureRMApiManagementApi_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -138,23 +126,18 @@ func TestAccAzureRMApiManagementApi_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApi_basic(ri, location), + Config: testAccAzureRMApiManagementApi_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), + testCheckAzureRMApiManagementApiExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementApi_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_api"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementApi_requiresImport), }, }) } func TestAccAzureRMApiManagementApi_soapPassthrough(t *testing.T) { - resourceName := "azurerm_api_management_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -162,13 +145,13 @@ func TestAccAzureRMApiManagementApi_soapPassthrough(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApi_soapPassthrough(ri, location), + Config: testAccAzureRMApiManagementApi_soapPassthrough(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), + testCheckAzureRMApiManagementApiExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -177,9 +160,7 @@ func TestAccAzureRMApiManagementApi_soapPassthrough(t *testing.T) { } func TestAccAzureRMApiManagementApi_importSwagger(t *testing.T) { - resourceName := "azurerm_api_management_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -187,13 +168,13 @@ func TestAccAzureRMApiManagementApi_importSwagger(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApi_importSwagger(ri, location), + Config: testAccAzureRMApiManagementApi_importSwagger(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), + testCheckAzureRMApiManagementApiExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -206,9 +187,7 @@ func TestAccAzureRMApiManagementApi_importSwagger(t *testing.T) { } func TestAccAzureRMApiManagementApi_importWsdl(t *testing.T) { - resourceName := "azurerm_api_management_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -216,13 +195,13 @@ func TestAccAzureRMApiManagementApi_importWsdl(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApi_importWsdl(ri, location), + Config: testAccAzureRMApiManagementApi_importWsdl(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), + testCheckAzureRMApiManagementApiExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -235,9 +214,7 @@ func TestAccAzureRMApiManagementApi_importWsdl(t *testing.T) { } func TestAccAzureRMApiManagementApi_importUpdate(t *testing.T) { - resourceName := "azurerm_api_management_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -245,13 +222,13 @@ func TestAccAzureRMApiManagementApi_importUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApi_importWsdl(ri, location), + Config: testAccAzureRMApiManagementApi_importWsdl(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), + testCheckAzureRMApiManagementApiExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -260,13 +237,13 @@ func TestAccAzureRMApiManagementApi_importUpdate(t *testing.T) { }, }, { - Config: testAccAzureRMApiManagementApi_importSwagger(ri, location), + Config: testAccAzureRMApiManagementApi_importSwagger(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), + testCheckAzureRMApiManagementApiExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -279,9 +256,7 @@ func TestAccAzureRMApiManagementApi_importUpdate(t *testing.T) { } func TestAccAzureRMApiManagementApi_complete(t *testing.T) { - resourceName := "azurerm_api_management_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -289,13 +264,13 @@ func TestAccAzureRMApiManagementApi_complete(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApi_complete(ri, location), + Config: testAccAzureRMApiManagementApi_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiExists(resourceName), + testCheckAzureRMApiManagementApiExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -363,8 +338,8 @@ func testCheckAzureRMApiManagementApiExists(name string) resource.TestCheckFunc } } -func testAccAzureRMApiManagementApi_basic(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_template(rInt, location) +func testAccAzureRMApiManagementApi_basic(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_template(data) return fmt.Sprintf(` %s @@ -377,12 +352,12 @@ resource "azurerm_api_management_api" "test" { protocols = ["https"] revision = "1" } -`, template, rInt) +`, template, data.RandomInteger) } // Remove in 2.0 -func testAccAzureRMApiManagementApi_basicClassic(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_templateClassic(rInt, location) +func testAccAzureRMApiManagementApi_basicClassic(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_templateClassic(data) return fmt.Sprintf(` %s @@ -395,11 +370,11 @@ resource "azurerm_api_management_api" "test" { protocols = ["https"] revision = "1" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementApi_wordRevision(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_template(rInt, location) +func testAccAzureRMApiManagementApi_wordRevision(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_template(data) return fmt.Sprintf(` %s @@ -412,11 +387,11 @@ resource "azurerm_api_management_api" "test" { protocols = ["https"] revision = "one-point-oh" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementApi_soapPassthrough(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_template(rInt, location) +func testAccAzureRMApiManagementApi_soapPassthrough(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_template(data) return fmt.Sprintf(` %s @@ -430,11 +405,11 @@ resource "azurerm_api_management_api" "test" { revision = "1" soap_pass_through = true } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementApi_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_basic(rInt, location) +func testAccAzureRMApiManagementApi_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_basic(data) return fmt.Sprintf(` %s @@ -450,8 +425,8 @@ resource "azurerm_api_management_api" "import" { `, template) } -func testAccAzureRMApiManagementApi_importSwagger(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_template(rInt, location) +func testAccAzureRMApiManagementApi_importSwagger(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_template(data) return fmt.Sprintf(` %s @@ -469,11 +444,11 @@ resource "azurerm_api_management_api" "test" { content_format = "swagger-json" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementApi_importWsdl(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_template(rInt, location) +func testAccAzureRMApiManagementApi_importWsdl(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_template(data) return fmt.Sprintf(` %s @@ -496,11 +471,11 @@ resource "azurerm_api_management_api" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementApi_complete(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_template(rInt, location) +func testAccAzureRMApiManagementApi_complete(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_template(data) return fmt.Sprintf(` %s @@ -520,11 +495,11 @@ resource "azurerm_api_management_api" "test" { query = "location" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementApi_versionSet(rInt int, location string) string { - template := testAccAzureRMApiManagementApi_template(rInt, location) +func testAccAzureRMApiManagementApi_versionSet(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApi_template(data) return fmt.Sprintf(` %s @@ -547,10 +522,10 @@ resource "azurerm_api_management_api" "test" { version = "v1" version_set_id = "${azurerm_api_management_api_version_set.test.id}" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementApi_template(rInt int, location string) string { +func testAccAzureRMApiManagementApi_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -566,11 +541,11 @@ resource "azurerm_api_management" "test" { sku_name = "Developer_1" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } // Remove in 2.0 -func testAccAzureRMApiManagementApi_templateClassic(rInt int, location string) string { +func testAccAzureRMApiManagementApi_templateClassic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -589,5 +564,5 @@ resource "azurerm_api_management" "test" { capacity = 1 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_version_set_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go similarity index 68% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_api_version_set_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go index 991bcc65019b..3f434ea59eb2 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_version_set_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementApiVersionSet_basic(t *testing.T) { - resourceName := "azurerm_api_management_api_version_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_version_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMApiManagementApiVersionSet_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiVersionSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiVersionSet_basic(ri, location), + Config: testAccAzureRMApiManagementApiVersionSet_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiVersionSetExists(resourceName), + testCheckAzureRMApiManagementApiVersionSetExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -43,10 +40,7 @@ func TestAccAzureRMApiManagementApiVersionSet_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_api_version_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_version_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,23 +48,18 @@ func TestAccAzureRMApiManagementApiVersionSet_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiVersionSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiVersionSet_basic(ri, location), + Config: testAccAzureRMApiManagementApiVersionSet_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiVersionSetExists(resourceName), + testCheckAzureRMApiManagementApiVersionSetExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementApiVersionSet_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_api_version_set"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementApiVersionSet_requiresImport), }, }) } func TestAccAzureRMApiManagementApiVersionSet_header(t *testing.T) { - resourceName := "azurerm_api_management_api_version_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_version_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,13 +67,13 @@ func TestAccAzureRMApiManagementApiVersionSet_header(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiVersionSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiVersionSet_header(ri, location), + Config: testAccAzureRMApiManagementApiVersionSet_header(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiVersionSetExists(resourceName), + testCheckAzureRMApiManagementApiVersionSetExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -93,9 +82,7 @@ func TestAccAzureRMApiManagementApiVersionSet_header(t *testing.T) { } func TestAccAzureRMApiManagementApiVersionSet_query(t *testing.T) { - resourceName := "azurerm_api_management_api_version_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_version_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -103,13 +90,13 @@ func TestAccAzureRMApiManagementApiVersionSet_query(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiVersionSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiVersionSet_query(ri, location), + Config: testAccAzureRMApiManagementApiVersionSet_query(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiVersionSetExists(resourceName), + testCheckAzureRMApiManagementApiVersionSetExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -118,9 +105,7 @@ func TestAccAzureRMApiManagementApiVersionSet_query(t *testing.T) { } func TestAccAzureRMApiManagementApiVersionSet_update(t *testing.T) { - resourceName := "azurerm_api_management_api_version_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_api_version_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -128,23 +113,23 @@ func TestAccAzureRMApiManagementApiVersionSet_update(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementApiVersionSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementApiVersionSet_basic(ri, location), + Config: testAccAzureRMApiManagementApiVersionSet_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiVersionSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "TestDescription1"), - resource.TestCheckResourceAttr(resourceName, "display_name", fmt.Sprintf("TestApiVersionSet1%d", ri)), + testCheckAzureRMApiManagementApiVersionSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "TestDescription1"), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", fmt.Sprintf("TestApiVersionSet1%d", data.RandomInteger)), ), }, { - Config: testAccAzureRMApiManagementApiVersionSet_update(ri, location), + Config: testAccAzureRMApiManagementApiVersionSet_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementApiVersionSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "TestDescription2"), - resource.TestCheckResourceAttr(resourceName, "display_name", fmt.Sprintf("TestApiVersionSet2%d", ri)), + testCheckAzureRMApiManagementApiVersionSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "TestDescription2"), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", fmt.Sprintf("TestApiVersionSet2%d", data.RandomInteger)), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -202,8 +187,8 @@ func testCheckAzureRMApiManagementApiVersionSetExists(resourceName string) resou } } -func testAccAzureRMApiManagementApiVersionSet_basic(rInt int, location string) string { - template := testAccAzureRMApiManagementApiVersionSet_template(rInt, location) +func testAccAzureRMApiManagementApiVersionSet_basic(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiVersionSet_template(data) return fmt.Sprintf(` %s @@ -215,11 +200,11 @@ resource "azurerm_api_management_api_version_set" "test" { display_name = "TestApiVersionSet1%d" versioning_scheme = "Segment" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementApiVersionSet_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementApiVersionSet_basic(rInt, location) +func testAccAzureRMApiManagementApiVersionSet_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiVersionSet_basic(data) return fmt.Sprintf(` %s @@ -234,8 +219,8 @@ resource "azurerm_api_management_api_version_set" "import" { `, template) } -func testAccAzureRMApiManagementApiVersionSet_header(rInt int, location string) string { - template := testAccAzureRMApiManagementApiVersionSet_template(rInt, location) +func testAccAzureRMApiManagementApiVersionSet_header(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiVersionSet_template(data) return fmt.Sprintf(` %s @@ -248,11 +233,11 @@ resource "azurerm_api_management_api_version_set" "test" { versioning_scheme = "Header" version_header_name = "Header1" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementApiVersionSet_query(rInt int, location string) string { - template := testAccAzureRMApiManagementApiVersionSet_template(rInt, location) +func testAccAzureRMApiManagementApiVersionSet_query(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiVersionSet_template(data) return fmt.Sprintf(` %s @@ -265,11 +250,11 @@ resource "azurerm_api_management_api_version_set" "test" { versioning_scheme = "Query" version_query_name = "Query1" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementApiVersionSet_update(rInt int, location string) string { - template := testAccAzureRMApiManagementApiVersionSet_template(rInt, location) +func testAccAzureRMApiManagementApiVersionSet_update(data acceptance.TestData) string { + template := testAccAzureRMApiManagementApiVersionSet_template(data) return fmt.Sprintf(` %s @@ -281,10 +266,10 @@ resource "azurerm_api_management_api_version_set" "test" { display_name = "TestApiVersionSet2%d" versioning_scheme = "Segment" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementApiVersionSet_template(rInt int, location string) string { +func testAccAzureRMApiManagementApiVersionSet_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -303,5 +288,5 @@ resource "azurerm_api_management" "test" { capacity = 1 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_authorization_server_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go similarity index 82% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_authorization_server_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go index 7dc6fa1ff9e1..45a444c02cfe 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_authorization_server_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMAPIManagementAuthorizationServer_basic(t *testing.T) { - resourceName := "azurerm_api_management_authorization_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_authorization_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMAPIManagementAuthorizationServer_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementAuthorizationServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementAuthorizationServer_basic(ri, location), + Config: testAccAzureRMAPIManagementAuthorizationServer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementAuthorizationServerExists(resourceName), + testCheckAzureRMAPIManagementAuthorizationServerExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -43,10 +40,7 @@ func TestAccAzureRMAPIManagementAuthorizationServer_requiresImport(t *testing.T) t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_authorization_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_authorization_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,23 +48,18 @@ func TestAccAzureRMAPIManagementAuthorizationServer_requiresImport(t *testing.T) CheckDestroy: testCheckAzureRMAPIManagementAuthorizationServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementAuthorizationServer_basic(ri, location), + Config: testAccAzureRMAPIManagementAuthorizationServer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementAuthorizationServerExists(resourceName), + testCheckAzureRMAPIManagementAuthorizationServerExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAPIManagementAuthorizationServer_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_authorization_server"), - }, + data.RequiresImportErrorStep(testAccAzureRMAPIManagementAuthorizationServer_requiresImport), }, }) } func TestAccAzureRMAPIManagementAuthorizationServer_complete(t *testing.T) { - resourceName := "azurerm_api_management_authorization_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_authorization_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,13 +67,13 @@ func TestAccAzureRMAPIManagementAuthorizationServer_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementAuthorizationServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementAuthorizationServer_complete(ri, location), + Config: testAccAzureRMAPIManagementAuthorizationServer_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementAuthorizationServerExists(resourceName), + testCheckAzureRMAPIManagementAuthorizationServerExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -142,8 +131,8 @@ func testCheckAzureRMAPIManagementAuthorizationServerExists(resourceName string) } } -func testAccAzureRMAPIManagementAuthorizationServer_basic(rInt int, location string) string { - template := testAccAzureRMAPIManagementAuthorizationServer_template(rInt, location) +func testAccAzureRMAPIManagementAuthorizationServer_basic(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementAuthorizationServer_template(data) return fmt.Sprintf(` %s @@ -164,11 +153,11 @@ resource "azurerm_api_management_authorization_server" "test" { "GET", ] } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAPIManagementAuthorizationServer_requiresImport(rInt int, location string) string { - template := testAccAzureRMAPIManagementAuthorizationServer_basic(rInt, location) +func testAccAzureRMAPIManagementAuthorizationServer_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementAuthorizationServer_basic(data) return fmt.Sprintf(` %s @@ -189,8 +178,8 @@ resource "azurerm_api_management_authorization_server" "import" { `, template) } -func testAccAzureRMAPIManagementAuthorizationServer_complete(rInt int, location string) string { - template := testAccAzureRMAPIManagementAuthorizationServer_template(rInt, location) +func testAccAzureRMAPIManagementAuthorizationServer_complete(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementAuthorizationServer_template(data) return fmt.Sprintf(` %s @@ -223,10 +212,10 @@ resource "azurerm_api_management_authorization_server" "test" { resource_owner_password = "C-193P" support_state = true } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAPIManagementAuthorizationServer_template(rInt int, location string) string { +func testAccAzureRMAPIManagementAuthorizationServer_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -245,5 +234,5 @@ resource "azurerm_api_management" "test" { capacity = 1 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_backend_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go similarity index 59% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_backend_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go index fd967626aae7..aa3ccb482946 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_backend_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementBackend_basic(t *testing.T) { - resourceName := "azurerm_api_management_backend.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_backend", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,15 +21,15 @@ func TestAccAzureRMApiManagementBackend_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementBackendDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementBackend_basic(ri, "basic", location), + Config: testAccAzureRMApiManagementBackend_basic(data, "basic"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementBackendExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "protocol", "http"), - resource.TestCheckResourceAttr(resourceName, "url", "https://acctest"), + testCheckAzureRMApiManagementBackendExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "protocol", "http"), + resource.TestCheckResourceAttr(data.ResourceName, "url", "https://acctest"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -41,9 +38,7 @@ func TestAccAzureRMApiManagementBackend_basic(t *testing.T) { } func TestAccAzureRMApiManagementBackend_allProperties(t *testing.T) { - resourceName := "azurerm_api_management_backend.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_backend", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,33 +46,33 @@ func TestAccAzureRMApiManagementBackend_allProperties(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementBackendDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementBackend_allProperties(ri, location), + Config: testAccAzureRMApiManagementBackend_allProperties(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementBackendExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "protocol", "http"), - resource.TestCheckResourceAttr(resourceName, "url", "https://acctest"), - resource.TestCheckResourceAttr(resourceName, "description", "description"), - resource.TestCheckResourceAttr(resourceName, "resource_id", "https://resourceid"), - resource.TestCheckResourceAttr(resourceName, "title", "title"), - resource.TestCheckResourceAttr(resourceName, "credentials.#", "1"), - resource.TestCheckResourceAttr(resourceName, "credentials.0.authorization.0.parameter", "parameter"), - resource.TestCheckResourceAttr(resourceName, "credentials.0.authorization.0.scheme", "scheme"), - resource.TestCheckResourceAttrSet(resourceName, "credentials.0.certificate.0"), - resource.TestCheckResourceAttr(resourceName, "credentials.0.header.header1", "header1value1,header1value2"), - resource.TestCheckResourceAttr(resourceName, "credentials.0.header.header2", "header2value1,header2value2"), - resource.TestCheckResourceAttr(resourceName, "credentials.0.query.query1", "query1value1,query1value2"), - resource.TestCheckResourceAttr(resourceName, "credentials.0.query.query2", "query2value1,query2value2"), - resource.TestCheckResourceAttr(resourceName, "proxy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "proxy.0.url", "http://192.168.1.1:8080"), - resource.TestCheckResourceAttr(resourceName, "proxy.0.username", "username"), - resource.TestCheckResourceAttr(resourceName, "proxy.0.password", "password"), - resource.TestCheckResourceAttr(resourceName, "tls.#", "1"), - resource.TestCheckResourceAttr(resourceName, "tls.0.validate_certificate_chain", "false"), - resource.TestCheckResourceAttr(resourceName, "tls.0.validate_certificate_name", "true"), + testCheckAzureRMApiManagementBackendExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "protocol", "http"), + resource.TestCheckResourceAttr(data.ResourceName, "url", "https://acctest"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "description"), + resource.TestCheckResourceAttr(data.ResourceName, "resource_id", "https://resourceid"), + resource.TestCheckResourceAttr(data.ResourceName, "title", "title"), + resource.TestCheckResourceAttr(data.ResourceName, "credentials.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "credentials.0.authorization.0.parameter", "parameter"), + resource.TestCheckResourceAttr(data.ResourceName, "credentials.0.authorization.0.scheme", "scheme"), + resource.TestCheckResourceAttrSet(data.ResourceName, "credentials.0.certificate.0"), + resource.TestCheckResourceAttr(data.ResourceName, "credentials.0.header.header1", "header1value1,header1value2"), + resource.TestCheckResourceAttr(data.ResourceName, "credentials.0.header.header2", "header2value1,header2value2"), + resource.TestCheckResourceAttr(data.ResourceName, "credentials.0.query.query1", "query1value1,query1value2"), + resource.TestCheckResourceAttr(data.ResourceName, "credentials.0.query.query2", "query2value1,query2value2"), + resource.TestCheckResourceAttr(data.ResourceName, "proxy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "proxy.0.url", "http://192.168.1.1:8080"), + resource.TestCheckResourceAttr(data.ResourceName, "proxy.0.username", "username"), + resource.TestCheckResourceAttr(data.ResourceName, "proxy.0.password", "password"), + resource.TestCheckResourceAttr(data.ResourceName, "tls.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tls.0.validate_certificate_chain", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "tls.0.validate_certificate_name", "true"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -86,9 +81,7 @@ func TestAccAzureRMApiManagementBackend_allProperties(t *testing.T) { } func TestAccAzureRMApiManagementBackend_credentialsNoCertificate(t *testing.T) { - resourceName := "azurerm_api_management_backend.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_backend", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -96,13 +89,13 @@ func TestAccAzureRMApiManagementBackend_credentialsNoCertificate(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementBackendDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementBackend_credentialsNoCertificate(ri, location), + Config: testAccAzureRMApiManagementBackend_credentialsNoCertificate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementBackendExists(resourceName), + testCheckAzureRMApiManagementBackendExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -111,9 +104,7 @@ func TestAccAzureRMApiManagementBackend_credentialsNoCertificate(t *testing.T) { } func TestAccAzureRMApiManagementBackend_update(t *testing.T) { - resourceName := "azurerm_api_management_backend.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_backend", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -121,40 +112,40 @@ func TestAccAzureRMApiManagementBackend_update(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementBackendDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementBackend_basic(ri, "update", location), + Config: testAccAzureRMApiManagementBackend_basic(data, "update"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementBackendExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "protocol", "http"), - resource.TestCheckResourceAttr(resourceName, "url", "https://acctest"), + testCheckAzureRMApiManagementBackendExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "protocol", "http"), + resource.TestCheckResourceAttr(data.ResourceName, "url", "https://acctest"), ), }, { - Config: testAccAzureRMApiManagementBackend_update(ri, location), + Config: testAccAzureRMApiManagementBackend_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementBackendExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "protocol", "soap"), - resource.TestCheckResourceAttr(resourceName, "url", "https://updatedacctest"), - resource.TestCheckResourceAttr(resourceName, "description", "description"), - resource.TestCheckResourceAttr(resourceName, "resource_id", "https://resourceid"), - resource.TestCheckResourceAttr(resourceName, "proxy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "proxy.0.url", "http://192.168.1.1:8080"), - resource.TestCheckResourceAttr(resourceName, "proxy.0.username", "username"), - resource.TestCheckResourceAttr(resourceName, "proxy.0.password", "password"), - resource.TestCheckResourceAttr(resourceName, "tls.#", "1"), - resource.TestCheckResourceAttr(resourceName, "tls.0.validate_certificate_chain", "false"), - resource.TestCheckResourceAttr(resourceName, "tls.0.validate_certificate_name", "true"), + testCheckAzureRMApiManagementBackendExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "protocol", "soap"), + resource.TestCheckResourceAttr(data.ResourceName, "url", "https://updatedacctest"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "description"), + resource.TestCheckResourceAttr(data.ResourceName, "resource_id", "https://resourceid"), + resource.TestCheckResourceAttr(data.ResourceName, "proxy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "proxy.0.url", "http://192.168.1.1:8080"), + resource.TestCheckResourceAttr(data.ResourceName, "proxy.0.username", "username"), + resource.TestCheckResourceAttr(data.ResourceName, "proxy.0.password", "password"), + resource.TestCheckResourceAttr(data.ResourceName, "tls.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tls.0.validate_certificate_chain", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "tls.0.validate_certificate_name", "true"), ), }, { - Config: testAccAzureRMApiManagementBackend_basic(ri, "update", location), + Config: testAccAzureRMApiManagementBackend_basic(data, "update"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementBackendExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "protocol", "http"), - resource.TestCheckResourceAttr(resourceName, "url", "https://acctest"), - resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "resource_id", ""), - resource.TestCheckResourceAttr(resourceName, "proxy.#", "0"), - resource.TestCheckResourceAttr(resourceName, "tls.#", "0"), + testCheckAzureRMApiManagementBackendExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "protocol", "http"), + resource.TestCheckResourceAttr(data.ResourceName, "url", "https://acctest"), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), + resource.TestCheckResourceAttr(data.ResourceName, "resource_id", ""), + resource.TestCheckResourceAttr(data.ResourceName, "proxy.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tls.#", "0"), ), }, }, @@ -162,9 +153,7 @@ func TestAccAzureRMApiManagementBackend_update(t *testing.T) { } func TestAccAzureRMApiManagementBackend_serviceFabric(t *testing.T) { - resourceName := "azurerm_api_management_backend.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_backend", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -172,20 +161,20 @@ func TestAccAzureRMApiManagementBackend_serviceFabric(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementBackendDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementBackend_serviceFabric(ri, location), + Config: testAccAzureRMApiManagementBackend_serviceFabric(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementBackendExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "protocol", "http"), - resource.TestCheckResourceAttr(resourceName, "url", "https://acctest"), - resource.TestCheckResourceAttr(resourceName, "service_fabric_cluster.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "service_fabric_cluster.0.client_certificate_thumbprint"), - resource.TestCheckResourceAttr(resourceName, "service_fabric_cluster.0.max_partition_resolution_retries", "5"), - resource.TestCheckResourceAttr(resourceName, "service_fabric_cluster.0.management_endpoints.#", "1"), - resource.TestCheckResourceAttr(resourceName, "service_fabric_cluster.0.server_certificate_thumbprints.#", "2"), + testCheckAzureRMApiManagementBackendExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "protocol", "http"), + resource.TestCheckResourceAttr(data.ResourceName, "url", "https://acctest"), + resource.TestCheckResourceAttr(data.ResourceName, "service_fabric_cluster.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "service_fabric_cluster.0.client_certificate_thumbprint"), + resource.TestCheckResourceAttr(data.ResourceName, "service_fabric_cluster.0.max_partition_resolution_retries", "5"), + resource.TestCheckResourceAttr(data.ResourceName, "service_fabric_cluster.0.management_endpoints.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "service_fabric_cluster.0.server_certificate_thumbprints.#", "2"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -194,9 +183,7 @@ func TestAccAzureRMApiManagementBackend_serviceFabric(t *testing.T) { } func TestAccAzureRMApiManagementBackend_disappears(t *testing.T) { - resourceName := "azurerm_api_management_backend.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_backend", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -204,10 +191,10 @@ func TestAccAzureRMApiManagementBackend_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementBackendDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementBackend_basic(ri, "disappears", location), + Config: testAccAzureRMApiManagementBackend_basic(data, "disappears"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementBackendExists(resourceName), - testCheckAzureRMApiManagementBackendDisappears(resourceName), + testCheckAzureRMApiManagementBackendExists(data.ResourceName), + testCheckAzureRMApiManagementBackendDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -220,10 +207,7 @@ func TestAccAzureRMApiManagementBackend_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_backend.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_backend", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -231,15 +215,12 @@ func TestAccAzureRMApiManagementBackend_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementBackendDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementBackend_basic(ri, "import", location), + Config: testAccAzureRMApiManagementBackend_basic(data, "import"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementBackendExists(resourceName), + testCheckAzureRMApiManagementBackendExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementBackend_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_backend"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementBackend_requiresImport), }, }) } @@ -330,8 +311,8 @@ func testCheckAzureRMApiManagementBackendDisappears(resourceName string) resourc } } -func testAccAzureRMApiManagementBackend_basic(rInt int, testName string, location string) string { - template := testAccAzureRMApiManagementBackend_template(rInt, testName, location) +func testAccAzureRMApiManagementBackend_basic(data acceptance.TestData, testName string) string { + template := testAccAzureRMApiManagementBackend_template(data, testName) return fmt.Sprintf(` %s @@ -342,11 +323,11 @@ resource "azurerm_api_management_backend" "test" { protocol = "http" url = "https://acctest" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementBackend_update(rInt int, location string) string { - template := testAccAzureRMApiManagementBackend_template(rInt, "update", location) +func testAccAzureRMApiManagementBackend_update(data acceptance.TestData) string { + template := testAccAzureRMApiManagementBackend_template(data, "update") return fmt.Sprintf(` %s @@ -368,11 +349,11 @@ resource "azurerm_api_management_backend" "test" { validate_certificate_name = true } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementBackend_allProperties(rInt int, location string) string { - template := testAccAzureRMApiManagementBackend_template(rInt, "all", location) +func testAccAzureRMApiManagementBackend_allProperties(data acceptance.TestData) string { + template := testAccAzureRMApiManagementBackend_template(data, "all") return fmt.Sprintf(` %s @@ -420,11 +401,11 @@ resource "azurerm_api_management_backend" "test" { validate_certificate_name = true } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementBackend_serviceFabric(rInt int, location string) string { - template := testAccAzureRMApiManagementBackend_template(rInt, "sf", location) +func testAccAzureRMApiManagementBackend_serviceFabric(data acceptance.TestData) string { + template := testAccAzureRMApiManagementBackend_template(data, "sf") return fmt.Sprintf(` %s @@ -454,11 +435,11 @@ resource "azurerm_api_management_backend" "test" { ] } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApiManagementBackend_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementBackend_basic(rInt, "requiresimport", location) +func testAccAzureRMApiManagementBackend_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementBackend_basic(data, "requiresimport") return fmt.Sprintf(` %s @@ -472,7 +453,7 @@ resource "azurerm_api_management_backend" "import" { `, template) } -func testAccAzureRMApiManagementBackend_template(rInt int, testName string, location string) string { +func testAccAzureRMApiManagementBackend_template(data acceptance.TestData, testName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d-%s" @@ -491,11 +472,11 @@ resource "azurerm_api_management" "test" { capacity = 1 } } -`, rInt, testName, location, rInt, testName) +`, data.RandomInteger, testName, data.Locations.Primary, data.RandomInteger, testName) } -func testAccAzureRMApiManagementBackend_credentialsNoCertificate(rInt int, location string) string { - template := testAccAzureRMApiManagementBackend_template(rInt, "all", location) +func testAccAzureRMApiManagementBackend_credentialsNoCertificate(data acceptance.TestData) string { + template := testAccAzureRMApiManagementBackend_template(data, "all") return fmt.Sprintf(` %s @@ -532,5 +513,5 @@ resource "azurerm_api_management_backend" "test" { validate_certificate_name = true } } -`, template, rInt) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_certificate_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_certificate_test.go similarity index 77% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_certificate_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_certificate_test.go index 169a0dd20119..9176713d18a8 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_certificate_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_certificate_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMAPIManagementCertificate_basic(t *testing.T) { - resourceName := "azurerm_api_management_certificate.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +21,16 @@ func TestAccAzureRMAPIManagementCertificate_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementCertificate_basic(ri, location), + Config: testAccAzureRMAPIManagementCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementCertificateExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "expiration"), - resource.TestCheckResourceAttrSet(resourceName, "subject"), - resource.TestCheckResourceAttrSet(resourceName, "thumbprint"), + testCheckAzureRMAPIManagementCertificateExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "expiration"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subject"), + resource.TestCheckResourceAttrSet(data.ResourceName, "thumbprint"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -51,10 +48,7 @@ func TestAccAzureRMAPIManagementCertificate_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_certificate.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -62,15 +56,12 @@ func TestAccAzureRMAPIManagementCertificate_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementCertificate_basic(ri, location), + Config: testAccAzureRMAPIManagementCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementCertificateExists(resourceName), + testCheckAzureRMAPIManagementCertificateExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAPIManagementCertificate_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_certificate"), - }, + data.RequiresImportErrorStep(testAccAzureRMAPIManagementCertificate_requiresImport), }, }) } @@ -125,7 +116,7 @@ func testCheckAzureRMAPIManagementCertificateExists(resourceName string) resourc } } -func testAccAzureRMAPIManagementCertificate_basic(rInt int, location string) string { +func testAccAzureRMAPIManagementCertificate_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -152,11 +143,11 @@ resource "azurerm_api_management_certificate" "test" { data = "${filebase64("testdata/keyvaultcert.pfx")}" password = "" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations, data.RandomInteger) } -func testAccAzureRMAPIManagementCertificate_requiresImport(rInt int, location string) string { - template := testAccAzureRMAPIManagementCertificate_basic(rInt, location) +func testAccAzureRMAPIManagementCertificate_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementCertificate_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_diagnostic_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go similarity index 79% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_diagnostic_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go index 6ec31794f2f9..531161faeb34 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_diagnostic_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,8 @@ import ( ) func TestAccAzureRMApiManagementDiagnostic_basic(t *testing.T) { - resourceName := "azurerm_api_management_diagnostic.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApiManagementDiagnostic_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_api_management_diagnostic", "test") + config := testAccAzureRMApiManagementDiagnostic_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,11 +24,11 @@ func TestAccAzureRMApiManagementDiagnostic_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementDiagnosticExists(resourceName), + testCheckAzureRMApiManagementDiagnosticExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -43,10 +41,7 @@ func TestAccAzureRMApiManagementDiagnostic_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_diagnostic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_diagnostic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,15 +49,12 @@ func TestAccAzureRMApiManagementDiagnostic_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementDiagnostic_basic(ri, location), + Config: testAccAzureRMApiManagementDiagnostic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementDiagnosticExists(resourceName), + testCheckAzureRMApiManagementDiagnosticExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementDiagnostic_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_diagnostic"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementDiagnostic_requiresImport), }, }) } @@ -117,7 +109,7 @@ func testCheckAzureRMApiManagementDiagnosticExists(resourceName string) resource } } -func testAccAzureRMApiManagementDiagnostic_basic(rInt int, location string) string { +func testAccAzureRMApiManagementDiagnostic_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -139,11 +131,11 @@ resource "azurerm_api_management_diagnostic" "test" { api_management_name = "${azurerm_api_management.test.name}" enabled = true } -`, rInt, location, rInt) +`, data.ResourceName, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApiManagementDiagnostic_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementDiagnostic_basic(rInt, location) +func testAccAzureRMApiManagementDiagnostic_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementDiagnostic_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_group_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go similarity index 64% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_group_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go index 710eb7f8e77b..93a9da21050e 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_group_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,8 @@ import ( ) func TestAccAzureRMAPIManagementGroup_basic(t *testing.T) { - resourceName := "azurerm_api_management_group.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAPIManagementGroup_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_api_management_group", "test") + config := testAccAzureRMAPIManagementGroup_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,13 +24,13 @@ func TestAccAzureRMAPIManagementGroup_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", "Test Group"), - resource.TestCheckResourceAttr(resourceName, "type", "custom"), + testCheckAzureRMAPIManagementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Test Group"), + resource.TestCheckResourceAttr(data.ResourceName, "type", "custom"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -45,10 +43,7 @@ func TestAccAzureRMAPIManagementGroup_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,25 +51,22 @@ func TestAccAzureRMAPIManagementGroup_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementGroup_basic(ri, location), + Config: testAccAzureRMAPIManagementGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", "Test Group"), - resource.TestCheckResourceAttr(resourceName, "type", "custom"), + testCheckAzureRMAPIManagementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Test Group"), + resource.TestCheckResourceAttr(data.ResourceName, "type", "custom"), ), }, - { - Config: testAccAzureRMAPIManagementGroup_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_group"), - }, + data.RequiresImportErrorStep(testAccAzureRMAPIManagementGroup_requiresImport), }, }) } func TestAccAzureRMAPIManagementGroup_complete(t *testing.T) { - resourceName := "azurerm_api_management_group.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAPIManagementGroup_complete(ri, acceptance.Location(), "Test Group", "A test description.") + data := acceptance.BuildTestData(t, "azurerm_api_management_group", "test") + + config := testAccAzureRMAPIManagementGroup_complete(data, "Test Group", "A test description.") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,14 +76,14 @@ func TestAccAzureRMAPIManagementGroup_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", "Test Group"), - resource.TestCheckResourceAttr(resourceName, "description", "A test description."), - resource.TestCheckResourceAttr(resourceName, "type", "external"), + testCheckAzureRMAPIManagementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Test Group"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "A test description."), + resource.TestCheckResourceAttr(data.ResourceName, "type", "external"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -100,10 +92,9 @@ func TestAccAzureRMAPIManagementGroup_complete(t *testing.T) { } func TestAccAzureRMAPIManagementGroup_descriptionDisplayNameUpdate(t *testing.T) { - resourceName := "azurerm_api_management_group.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMAPIManagementGroup_complete(ri, acceptance.Location(), "Original Group", "The original description.") - postConfig := testAccAzureRMAPIManagementGroup_complete(ri, acceptance.Location(), "Modified Group", "A modified description.") + data := acceptance.BuildTestData(t, "azurerm_api_management_group", "test") + preConfig := testAccAzureRMAPIManagementGroup_complete(data, "Original Group", "The original description.") + postConfig := testAccAzureRMAPIManagementGroup_complete(data, "Modified Group", "A modified description.") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,28 +104,28 @@ func TestAccAzureRMAPIManagementGroup_descriptionDisplayNameUpdate(t *testing.T) { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", "Original Group"), - resource.TestCheckResourceAttr(resourceName, "description", "The original description."), - resource.TestCheckResourceAttr(resourceName, "type", "external"), + testCheckAzureRMAPIManagementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Original Group"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "The original description."), + resource.TestCheckResourceAttr(data.ResourceName, "type", "external"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", "Modified Group"), - resource.TestCheckResourceAttr(resourceName, "description", "A modified description."), - resource.TestCheckResourceAttr(resourceName, "type", "external"), + testCheckAzureRMAPIManagementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Modified Group"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "A modified description."), + resource.TestCheckResourceAttr(data.ResourceName, "type", "external"), ), }, { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", "Original Group"), - resource.TestCheckResourceAttr(resourceName, "description", "The original description."), - resource.TestCheckResourceAttr(resourceName, "type", "external"), + testCheckAzureRMAPIManagementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Original Group"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "The original description."), + resource.TestCheckResourceAttr(data.ResourceName, "type", "external"), ), }, }, @@ -191,7 +182,7 @@ func testCheckAzureRMAPIManagementGroupExists(resourceName string) resource.Test } } -func testAccAzureRMAPIManagementGroup_basic(rInt int, location string) string { +func testAccAzureRMAPIManagementGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -214,11 +205,11 @@ resource "azurerm_api_management_group" "test" { api_management_name = "${azurerm_api_management.test.name}" display_name = "Test Group" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAPIManagementGroup_requiresImport(rInt int, location string) string { - template := testAccAzureRMAPIManagementGroup_basic(rInt, location) +func testAccAzureRMAPIManagementGroup_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementGroup_basic(data) return fmt.Sprintf(` %s @@ -231,7 +222,7 @@ resource "azurerm_api_management_group" "import" { `, template) } -func testAccAzureRMAPIManagementGroup_complete(rInt int, location string, displayName, description string) string { +func testAccAzureRMAPIManagementGroup_complete(data acceptance.TestData, displayName, description string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -256,5 +247,5 @@ resource "azurerm_api_management_group" "test" { description = "%s" type = "external" } -`, rInt, location, rInt, rInt, displayName, description) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, displayName, description) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_group_user_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go similarity index 81% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_group_user_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go index 58adbcba0cac..f620c37e57da 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_group_user_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMAPIManagementGroupUser_basic(t *testing.T) { - resourceName := "azurerm_api_management_group_user.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_group_user", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMAPIManagementGroupUser_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementGroupUserDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementGroupUser_basic(ri, location), + Config: testAccAzureRMAPIManagementGroupUser_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementGroupUserExists(resourceName), + testCheckAzureRMAPIManagementGroupUserExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -43,10 +40,7 @@ func TestAccAzureRMAPIManagementGroupUser_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_group_user.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_group_user", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,15 +48,12 @@ func TestAccAzureRMAPIManagementGroupUser_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementGroupUserDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementGroupUser_basic(ri, location), + Config: testAccAzureRMAPIManagementGroupUser_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementGroupUserExists(resourceName), + testCheckAzureRMAPIManagementGroupUserExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAPIManagementGroupUser_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_group_user"), - }, + data.RequiresImportErrorStep(testAccAzureRMAPIManagementGroupUser_requiresImport), }, }) } @@ -118,7 +109,7 @@ func testCheckAzureRMAPIManagementGroupUserExists(resourceName string) resource. } } -func testAccAzureRMAPIManagementGroupUser_basic(rInt int, location string) string { +func testAccAzureRMAPIManagementGroupUser_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -157,11 +148,11 @@ resource "azurerm_api_management_group_user" "test" { api_management_name = "${azurerm_api_management.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAPIManagementGroupUser_requiresImport(rInt int, location string) string { - template := testAccAzureRMAPIManagementGroupUser_basic(rInt, location) +func testAccAzureRMAPIManagementGroupUser_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementGroupUser_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_logger_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_logger_test.go similarity index 57% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_logger_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_logger_test.go index dee80e2b314b..c17ff6300710 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_logger_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_logger_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementLogger_basicEventHub(t *testing.T) { - resourceName := "azurerm_api_management_logger.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_logger", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,17 +21,17 @@ func TestAccAzureRMApiManagementLogger_basicEventHub(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), + Config: testAccAzureRMApiManagementLogger_basicEventHub(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), + testCheckAzureRMApiManagementLoggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "buffered", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub.0.name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub.0.connection_string"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"eventhub.0.connection_string"}, @@ -48,10 +45,7 @@ func TestAccAzureRMApiManagementLogger_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_logger.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_logger", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -59,27 +53,22 @@ func TestAccAzureRMApiManagementLogger_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), + Config: testAccAzureRMApiManagementLogger_basicEventHub(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), + testCheckAzureRMApiManagementLoggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "buffered", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub.0.name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub.0.connection_string"), ), }, - { - Config: testAccAzureRMApiManagementLogger_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_logger"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementLogger_requiresImport), }, }) } func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { - resourceName := "azurerm_api_management_logger.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_logger", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,17 +76,17 @@ func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementLogger_basicApplicationInsights(ri, location), + Config: testAccAzureRMApiManagementLogger_basicApplicationInsights(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + testCheckAzureRMApiManagementLoggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "buffered", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_insights.0.instrumentation_key"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"application_insights.#", "application_insights.0.instrumentation_key"}, @@ -107,9 +96,7 @@ func TestAccAzureRMApiManagementLogger_basicApplicationInsights(t *testing.T) { } func TestAccAzureRMApiManagementLogger_complete(t *testing.T) { - resourceName := "azurerm_api_management_logger.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_logger", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -117,18 +104,18 @@ func TestAccAzureRMApiManagementLogger_complete(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform test", "false"), + Config: testAccAzureRMApiManagementLogger_complete(data, "Logger from Terraform test", "false"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), - resource.TestCheckResourceAttr(resourceName, "buffered", "false"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + testCheckAzureRMApiManagementLoggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "Logger from Terraform test"), + resource.TestCheckResourceAttr(data.ResourceName, "buffered", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_insights.0.instrumentation_key"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"application_insights.#", "application_insights.0.instrumentation_key"}, @@ -138,9 +125,7 @@ func TestAccAzureRMApiManagementLogger_complete(t *testing.T) { } func TestAccAzureRMApiManagementLogger_update(t *testing.T) { - resourceName := "azurerm_api_management_logger.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_logger", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -148,69 +133,69 @@ func TestAccAzureRMApiManagementLogger_update(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementLoggerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementLogger_basicApplicationInsights(ri, location), + Config: testAccAzureRMApiManagementLogger_basicApplicationInsights(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + testCheckAzureRMApiManagementLoggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "buffered", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_insights.0.instrumentation_key"), ), }, { - Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), + Config: testAccAzureRMApiManagementLogger_basicEventHub(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), + testCheckAzureRMApiManagementLoggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "buffered", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub.0.name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub.0.connection_string"), ), }, { - Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform test", "false"), + Config: testAccAzureRMApiManagementLogger_complete(data, "Logger from Terraform test", "false"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "false"), - resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + testCheckAzureRMApiManagementLoggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "buffered", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "Logger from Terraform test"), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_insights.0.instrumentation_key"), ), }, { - Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform update test", "true"), + Config: testAccAzureRMApiManagementLogger_complete(data, "Logger from Terraform update test", "true"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform update test"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + testCheckAzureRMApiManagementLoggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "buffered", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "Logger from Terraform update test"), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_insights.0.instrumentation_key"), ), }, { - Config: testAccAzureRMApiManagementLogger_complete(ri, location, "Logger from Terraform test", "false"), + Config: testAccAzureRMApiManagementLogger_complete(data, "Logger from Terraform test", "false"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "false"), - resource.TestCheckResourceAttr(resourceName, "description", "Logger from Terraform test"), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "0"), - resource.TestCheckResourceAttr(resourceName, "application_insights.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_insights.0.instrumentation_key"), + testCheckAzureRMApiManagementLoggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "buffered", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "Logger from Terraform test"), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "application_insights.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_insights.0.instrumentation_key"), ), }, { - Config: testAccAzureRMApiManagementLogger_basicEventHub(ri, location), + Config: testAccAzureRMApiManagementLogger_basicEventHub(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementLoggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "buffered", "true"), - resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "eventhub.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.name"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub.0.connection_string"), + testCheckAzureRMApiManagementLoggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "buffered", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub.0.name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub.0.connection_string"), ), }, }, @@ -267,7 +252,7 @@ func testCheckAzureRMApiManagementLoggerDestroy(s *terraform.State) error { return nil } -func testAccAzureRMApiManagementLogger_basicEventHub(rInt int, location string) string { +func testAccAzureRMApiManagementLogger_basicEventHub(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -309,11 +294,11 @@ resource "azurerm_api_management_logger" "test" { connection_string = "${azurerm_eventhub_namespace.test.default_primary_connection_string}" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementLogger_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementLogger_basicEventHub(rInt, location) +func testAccAzureRMApiManagementLogger_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementLogger_basicEventHub(data) return fmt.Sprintf(` %s @@ -330,7 +315,7 @@ resource "azurerm_api_management_logger" "import" { `, template) } -func testAccAzureRMApiManagementLogger_basicApplicationInsights(rInt int, location string) string { +func testAccAzureRMApiManagementLogger_basicApplicationInsights(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -363,10 +348,10 @@ resource "azurerm_api_management_logger" "test" { instrumentation_key = "${azurerm_application_insights.test.instrumentation_key}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementLogger_complete(rInt int, location string, description, buffered string) string { +func testAccAzureRMApiManagementLogger_complete(data acceptance.TestData, description, buffered string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -401,5 +386,5 @@ resource "azurerm_api_management_logger" "test" { instrumentation_key = "${azurerm_application_insights.test.instrumentation_key}" } } -`, rInt, location, rInt, rInt, rInt, description, buffered) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, description, buffered) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_openid_connect_provider_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go similarity index 79% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_openid_connect_provider_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go index cfc48b505194..06920a5e3b30 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_openid_connect_provider_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementOpenIDConnectProvider_basic(t *testing.T) { - resourceName := "azurerm_api_management_openid_connect_provider.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_openid_connect_provider", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMApiManagementOpenIDConnectProvider_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementOpenIDConnectProviderDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementOpenIDConnectProvider_basic(ri, location), + Config: testAccAzureRMApiManagementOpenIDConnectProvider_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementOpenIDConnectProviderExists(resourceName), + testCheckAzureRMApiManagementOpenIDConnectProviderExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -43,10 +40,7 @@ func TestAccAzureRMApiManagementOpenIDConnectProvider_requiresImport(t *testing. t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_openid_connect_provider.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_openid_connect_provider", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,23 +48,18 @@ func TestAccAzureRMApiManagementOpenIDConnectProvider_requiresImport(t *testing. CheckDestroy: testCheckAzureRMApiManagementOpenIDConnectProviderDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementOpenIDConnectProvider_basic(ri, location), + Config: testAccAzureRMApiManagementOpenIDConnectProvider_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementOpenIDConnectProviderExists(resourceName), + testCheckAzureRMApiManagementOpenIDConnectProviderExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementOpenIDConnectProvider_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_openid_connect_provider"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementOpenIDConnectProvider_requiresImport), }, }) } func TestAccAzureRMApiManagementOpenIDConnectProvider_update(t *testing.T) { - resourceName := "azurerm_api_management_openid_connect_provider.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_openid_connect_provider", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,19 +67,19 @@ func TestAccAzureRMApiManagementOpenIDConnectProvider_update(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementOpenIDConnectProviderDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementOpenIDConnectProvider_basic(ri, location), + Config: testAccAzureRMApiManagementOpenIDConnectProvider_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementOpenIDConnectProviderExists(resourceName), + testCheckAzureRMApiManagementOpenIDConnectProviderExists(data.ResourceName), ), }, { - Config: testAccAzureRMApiManagementOpenIDConnectProvider_complete(ri, location), + Config: testAccAzureRMApiManagementOpenIDConnectProvider_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementOpenIDConnectProviderExists(resourceName), + testCheckAzureRMApiManagementOpenIDConnectProviderExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -148,8 +137,8 @@ func testCheckAzureRMApiManagementOpenIDConnectProviderDestroy(s *terraform.Stat return nil } -func testAccAzureRMApiManagementOpenIDConnectProvider_basic(rInt int, location string) string { - template := testAccAzureRMApiManagementOpenIDConnectProvider_template(rInt, location) +func testAccAzureRMApiManagementOpenIDConnectProvider_basic(data acceptance.TestData) string { + template := testAccAzureRMApiManagementOpenIDConnectProvider_template(data) return fmt.Sprintf(` %s @@ -162,11 +151,11 @@ resource "azurerm_api_management_openid_connect_provider" "test" { display_name = "Initial Name" metadata_endpoint = "https://azacctest.hashicorptest.com/example/foo" } -`, template, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementOpenIDConnectProvider_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementOpenIDConnectProvider_basic(rInt, location) +func testAccAzureRMApiManagementOpenIDConnectProvider_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementOpenIDConnectProvider_basic(data) return fmt.Sprintf(` %s @@ -182,8 +171,8 @@ resource "azurerm_api_management_openid_connect_provider" "import" { `, template) } -func testAccAzureRMApiManagementOpenIDConnectProvider_complete(rInt int, location string) string { - template := testAccAzureRMApiManagementOpenIDConnectProvider_template(rInt, location) +func testAccAzureRMApiManagementOpenIDConnectProvider_complete(data acceptance.TestData) string { + template := testAccAzureRMApiManagementOpenIDConnectProvider_template(data) return fmt.Sprintf(` %s @@ -197,10 +186,10 @@ resource "azurerm_api_management_openid_connect_provider" "test" { description = "Example description" metadata_endpoint = "https://azacctest.hashicorptest.com/example/updated" } -`, template, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementOpenIDConnectProvider_template(rInt int, location string) string { +func testAccAzureRMApiManagementOpenIDConnectProvider_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -219,5 +208,5 @@ resource "azurerm_api_management" "test" { capacity = 1 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_product_api_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go similarity index 82% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_product_api_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go index 6115331212bb..1b861f128a11 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_product_api_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMAPIManagementProductApi_basic(t *testing.T) { - resourceName := "azurerm_api_management_product_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product_api", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMAPIManagementProductApi_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementProductApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementProductApi_basic(ri, location), + Config: testAccAzureRMAPIManagementProductApi_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementProductApiExists(resourceName), + testCheckAzureRMAPIManagementProductApiExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -43,10 +40,7 @@ func TestAccAzureRMAPIManagementProductApi_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_product_api.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product_api", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,15 +48,12 @@ func TestAccAzureRMAPIManagementProductApi_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementProductApiDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementProductApi_basic(ri, location), + Config: testAccAzureRMAPIManagementProductApi_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementProductGroupExists(resourceName), + testCheckAzureRMAPIManagementProductGroupExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAPIManagementProductApi_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_product_api"), - }, + data.RequiresImportErrorStep(testAccAzureRMAPIManagementProductApi_requiresImport), }, }) } @@ -118,7 +109,7 @@ func testCheckAzureRMAPIManagementProductApiExists(resourceName string) resource } } -func testAccAzureRMAPIManagementProductApi_basic(rInt int, location string) string { +func testAccAzureRMAPIManagementProductApi_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -161,11 +152,11 @@ resource "azurerm_api_management_product_api" "test" { api_management_name = "${azurerm_api_management.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAPIManagementProductApi_requiresImport(rInt int, location string) string { - template := testAccAzureRMAPIManagementProductApi_basic(rInt, location) +func testAccAzureRMAPIManagementProductApi_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementProductApi_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_product_group_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go similarity index 81% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_product_group_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go index 2dec64feafb8..400ef7ad8e0b 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_product_group_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMAPIManagementProductGroup_basic(t *testing.T) { - resourceName := "azurerm_api_management_product_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMAPIManagementProductGroup_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementProductGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementProductGroup_basic(ri, location), + Config: testAccAzureRMAPIManagementProductGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementProductGroupExists(resourceName), + testCheckAzureRMAPIManagementProductGroupExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -43,10 +40,7 @@ func TestAccAzureRMAPIManagementProductGroup_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_product_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,15 +48,12 @@ func TestAccAzureRMAPIManagementProductGroup_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementProductGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementProductGroup_basic(ri, location), + Config: testAccAzureRMAPIManagementProductGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementProductGroupExists(resourceName), + testCheckAzureRMAPIManagementProductGroupExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAPIManagementProductGroup_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_product_group"), - }, + data.RequiresImportErrorStep(testAccAzureRMAPIManagementProductGroup_requiresImport), }, }) } @@ -118,7 +109,7 @@ func testCheckAzureRMAPIManagementProductGroupExists(resourceName string) resour } } -func testAccAzureRMAPIManagementProductGroup_basic(rInt int, location string) string { +func testAccAzureRMAPIManagementProductGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -158,11 +149,11 @@ resource "azurerm_api_management_product_group" "test" { api_management_name = "${azurerm_api_management.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAPIManagementProductGroup_requiresImport(rInt int, location string) string { - template := testAccAzureRMAPIManagementProductGroup_basic(rInt, location) +func testAccAzureRMAPIManagementProductGroup_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementProductGroup_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_product_policy_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_policy_test.go similarity index 79% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_product_policy_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_policy_test.go index b4fe14312b8d..41d18ead89d2 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_product_policy_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_policy_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementProductPolicy_basic(t *testing.T) { - resourceName := "azurerm_api_management_product_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +21,13 @@ func TestAccAzureRMApiManagementProductPolicy_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementProductPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementProductPolicy_basic(ri, location), + Config: testAccAzureRMApiManagementProductPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductPolicyExists(resourceName), + testCheckAzureRMApiManagementProductPolicyExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"xml_link"}, @@ -44,10 +41,7 @@ func TestAccAzureRMApiManagementProductPolicy_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_product_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,23 +49,18 @@ func TestAccAzureRMApiManagementProductPolicy_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementProductPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementProductPolicy_basic(ri, location), + Config: testAccAzureRMApiManagementProductPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductPolicyExists(resourceName), + testCheckAzureRMApiManagementProductPolicyExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementProductPolicy_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_product"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementProductPolicy_requiresImport), }, }) } func TestAccAzureRMApiManagementProductPolicy_update(t *testing.T) { - resourceName := "azurerm_api_management_product_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,19 +68,19 @@ func TestAccAzureRMApiManagementProductPolicy_update(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementProductPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementProductPolicy_basic(ri, location), + Config: testAccAzureRMApiManagementProductPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductPolicyExists(resourceName), + testCheckAzureRMApiManagementProductPolicyExists(data.ResourceName), ), }, { - Config: testAccAzureRMApiManagementProductPolicy_updated(ri, location), + Config: testAccAzureRMApiManagementProductPolicy_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductPolicyExists(resourceName), + testCheckAzureRMApiManagementProductPolicyExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"xml_link"}, @@ -154,7 +143,7 @@ func testCheckAzureRMApiManagementProductPolicyDestroy(s *terraform.State) error return nil } -func testAccAzureRMApiManagementProductPolicy_basic(rInt int, location string) string { +func testAccAzureRMApiManagementProductPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -189,11 +178,11 @@ resource "azurerm_api_management_product_policy" "test" { resource_group_name = "${azurerm_resource_group.test.name}" xml_link = "https://gist.githubusercontent.com/riordanp/ca22f8113afae0eb38cc12d718fd048d/raw/d6ac89a2f35a6881a7729f8cb4883179dc88eea1/example.xml" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApiManagementProductPolicy_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementProductPolicy_basic(rInt, location) +func testAccAzureRMApiManagementProductPolicy_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementProductPolicy_basic(data) return fmt.Sprintf(` %s @@ -206,7 +195,7 @@ resource "azurerm_api_management_product_policy" "import" { `, template) } -func testAccAzureRMApiManagementProductPolicy_updated(rInt int, location string) string { +func testAccAzureRMApiManagementProductPolicy_updated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -249,5 +238,5 @@ resource "azurerm_api_management_product_policy" "test" { XML } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_product_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go similarity index 63% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_product_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go index 57a1387e645b..2b630eccb52f 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_product_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,7 @@ import ( ) func TestAccAzureRMApiManagementProduct_basic(t *testing.T) { - resourceName := "azurerm_api_management_product.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,20 +22,20 @@ func TestAccAzureRMApiManagementProduct_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementProductDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementProduct_basic(ri, location), + Config: testAccAzureRMApiManagementProduct_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "approval_required", "false"), - resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "display_name", "Test Product"), - resource.TestCheckResourceAttr(resourceName, "product_id", "test-product"), - resource.TestCheckResourceAttr(resourceName, "published", "false"), - resource.TestCheckResourceAttr(resourceName, "subscription_required", "false"), - resource.TestCheckResourceAttr(resourceName, "terms", ""), + testCheckAzureRMApiManagementProductExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "approval_required", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Test Product"), + resource.TestCheckResourceAttr(data.ResourceName, "product_id", "test-product"), + resource.TestCheckResourceAttr(data.ResourceName, "published", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "terms", ""), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -51,10 +48,7 @@ func TestAccAzureRMApiManagementProduct_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_product.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -62,15 +56,12 @@ func TestAccAzureRMApiManagementProduct_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementProductDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementProduct_basic(ri, location), + Config: testAccAzureRMApiManagementProduct_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductExists(resourceName), + testCheckAzureRMApiManagementProductExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementProduct_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_product"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementProduct_requiresImport), }, }) } @@ -103,9 +94,7 @@ func testCheckAzureRMApiManagementProductDestroy(s *terraform.State) error { } func TestAccAzureRMApiManagementProduct_update(t *testing.T) { - resourceName := "azurerm_api_management_product.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,51 +102,51 @@ func TestAccAzureRMApiManagementProduct_update(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementProductDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementProduct_basic(ri, location), + Config: testAccAzureRMApiManagementProduct_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "approval_required", "false"), - resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "display_name", "Test Product"), - resource.TestCheckResourceAttr(resourceName, "product_id", "test-product"), - resource.TestCheckResourceAttr(resourceName, "published", "false"), - resource.TestCheckResourceAttr(resourceName, "subscription_required", "false"), - resource.TestCheckResourceAttr(resourceName, "terms", ""), + testCheckAzureRMApiManagementProductExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "approval_required", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Test Product"), + resource.TestCheckResourceAttr(data.ResourceName, "product_id", "test-product"), + resource.TestCheckResourceAttr(data.ResourceName, "published", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "terms", ""), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, { - Config: testAccAzureRMApiManagementProduct_updated(ri, location), + Config: testAccAzureRMApiManagementProduct_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "approval_required", "true"), - resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "display_name", "Test Updated Product"), - resource.TestCheckResourceAttr(resourceName, "product_id", "test-product"), - resource.TestCheckResourceAttr(resourceName, "published", "true"), - resource.TestCheckResourceAttr(resourceName, "subscription_required", "true"), - resource.TestCheckResourceAttr(resourceName, "terms", ""), + testCheckAzureRMApiManagementProductExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "approval_required", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Test Updated Product"), + resource.TestCheckResourceAttr(data.ResourceName, "product_id", "test-product"), + resource.TestCheckResourceAttr(data.ResourceName, "published", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "terms", ""), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, { - Config: testAccAzureRMApiManagementProduct_basic(ri, location), + Config: testAccAzureRMApiManagementProduct_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "display_name", "Test Product"), - resource.TestCheckResourceAttr(resourceName, "product_id", "test-product"), - resource.TestCheckResourceAttr(resourceName, "published", "false"), - resource.TestCheckResourceAttr(resourceName, "subscription_required", "false"), - resource.TestCheckResourceAttr(resourceName, "terms", ""), + testCheckAzureRMApiManagementProductExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Test Product"), + resource.TestCheckResourceAttr(data.ResourceName, "product_id", "test-product"), + resource.TestCheckResourceAttr(data.ResourceName, "published", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "terms", ""), ), }, }, @@ -165,9 +154,7 @@ func TestAccAzureRMApiManagementProduct_update(t *testing.T) { } func TestAccAzureRMApiManagementProduct_subscriptionsLimit(t *testing.T) { - resourceName := "azurerm_api_management_product.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -175,16 +162,16 @@ func TestAccAzureRMApiManagementProduct_subscriptionsLimit(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementProductDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementProduct_subscriptionLimits(ri, location), + Config: testAccAzureRMApiManagementProduct_subscriptionLimits(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "approval_required", "true"), - resource.TestCheckResourceAttr(resourceName, "subscription_required", "true"), - resource.TestCheckResourceAttr(resourceName, "subscriptions_limit", "2"), + testCheckAzureRMApiManagementProductExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "approval_required", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "subscriptions_limit", "2"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -193,9 +180,7 @@ func TestAccAzureRMApiManagementProduct_subscriptionsLimit(t *testing.T) { } func TestAccAzureRMApiManagementProduct_complete(t *testing.T) { - resourceName := "azurerm_api_management_product.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -203,21 +188,21 @@ func TestAccAzureRMApiManagementProduct_complete(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementProductDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementProduct_complete(ri, location), + Config: testAccAzureRMApiManagementProduct_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "approval_required", "true"), - resource.TestCheckResourceAttr(resourceName, "description", "This is an example description"), - resource.TestCheckResourceAttr(resourceName, "display_name", "Test Product"), - resource.TestCheckResourceAttr(resourceName, "product_id", "test-product"), - resource.TestCheckResourceAttr(resourceName, "published", "true"), - resource.TestCheckResourceAttr(resourceName, "subscriptions_limit", "2"), - resource.TestCheckResourceAttr(resourceName, "subscription_required", "true"), - resource.TestCheckResourceAttr(resourceName, "terms", "These are some example terms and conditions"), + testCheckAzureRMApiManagementProductExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "approval_required", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This is an example description"), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Test Product"), + resource.TestCheckResourceAttr(data.ResourceName, "product_id", "test-product"), + resource.TestCheckResourceAttr(data.ResourceName, "published", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "subscriptions_limit", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "terms", "These are some example terms and conditions"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -226,9 +211,7 @@ func TestAccAzureRMApiManagementProduct_complete(t *testing.T) { } func TestAccAzureRMApiManagementProduct_approvalRequiredError(t *testing.T) { - resourceName := "azurerm_api_management_product.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_product", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -236,9 +219,9 @@ func TestAccAzureRMApiManagementProduct_approvalRequiredError(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementProductDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementProduct_approvalRequiredError(ri, location), + Config: testAccAzureRMApiManagementProduct_approvalRequiredError(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementProductExists(resourceName)), + testCheckAzureRMApiManagementProductExists(data.ResourceName)), ExpectError: regexp.MustCompile("`subscription_required` must be true and `subscriptions_limit` must be greater than 0 to use `approval_required`"), }, }, @@ -272,7 +255,7 @@ func testCheckAzureRMApiManagementProductExists(resourceName string) resource.Te } } -func testAccAzureRMApiManagementProduct_basic(rInt int, location string) string { +func testAccAzureRMApiManagementProduct_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -297,11 +280,11 @@ resource "azurerm_api_management_product" "test" { subscription_required = false published = false } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApiManagementProduct_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementProduct_basic(rInt, location) +func testAccAzureRMApiManagementProduct_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementProduct_basic(data) return fmt.Sprintf(` %s @@ -317,7 +300,7 @@ resource "azurerm_api_management_product" "import" { `, template) } -func testAccAzureRMApiManagementProduct_updated(rInt int, location string) string { +func testAccAzureRMApiManagementProduct_updated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -344,10 +327,10 @@ resource "azurerm_api_management_product" "test" { subscriptions_limit = 1 published = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApiManagementProduct_subscriptionLimits(rInt int, location string) string { +func testAccAzureRMApiManagementProduct_subscriptionLimits(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -374,10 +357,10 @@ resource "azurerm_api_management_product" "test" { subscriptions_limit = 2 published = false } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApiManagementProduct_complete(rInt int, location string) string { +func testAccAzureRMApiManagementProduct_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -406,10 +389,10 @@ resource "azurerm_api_management_product" "test" { description = "This is an example description" terms = "These are some example terms and conditions" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApiManagementProduct_approvalRequiredError(rInt int, location string) string { +func testAccAzureRMApiManagementProduct_approvalRequiredError(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -440,5 +423,5 @@ resource "azurerm_api_management_product" "test" { description = "This is an example description" terms = "These are some example terms and conditions" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_property_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go similarity index 68% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_property_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go index 6b75700fd85c..bb330151d7d7 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_property_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,16 +6,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMAPIManagementProperty_basic(t *testing.T) { - resourceName := "azurerm_api_management_property.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAPIManagementProperty_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_api_management_property", "test") + config := testAccAzureRMAPIManagementProperty_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,15 +23,15 @@ func TestAccAzureRMAPIManagementProperty_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementPropertyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", fmt.Sprintf("TestProperty%d", ri)), - resource.TestCheckResourceAttr(resourceName, "value", "Test Value"), - resource.TestCheckResourceAttr(resourceName, "tags.0", "tag1"), - resource.TestCheckResourceAttr(resourceName, "tags.1", "tag2"), + testCheckAzureRMAPIManagementPropertyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", fmt.Sprintf("TestProperty%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "value", "Test Value"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.0", "tag1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.1", "tag2"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -42,10 +40,9 @@ func TestAccAzureRMAPIManagementProperty_basic(t *testing.T) { } func TestAccAzureRMAPIManagementProperty_update(t *testing.T) { - resourceName := "azurerm_api_management_property.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAPIManagementProperty_basic(ri, acceptance.Location()) - config2 := testAccAzureRMAPIManagementProperty_update(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_api_management_property", "test") + config := testAccAzureRMAPIManagementProperty_basic(data) + config2 := testAccAzureRMAPIManagementProperty_update(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,26 +52,26 @@ func TestAccAzureRMAPIManagementProperty_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementPropertyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", fmt.Sprintf("TestProperty%d", ri)), - resource.TestCheckResourceAttr(resourceName, "value", "Test Value"), - resource.TestCheckResourceAttr(resourceName, "tags.0", "tag1"), - resource.TestCheckResourceAttr(resourceName, "tags.1", "tag2"), + testCheckAzureRMAPIManagementPropertyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", fmt.Sprintf("TestProperty%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "value", "Test Value"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.0", "tag1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.1", "tag2"), ), }, { Config: config2, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementPropertyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", fmt.Sprintf("TestProperty2%d", ri)), - resource.TestCheckResourceAttr(resourceName, "value", "Test Value2"), - resource.TestCheckResourceAttr(resourceName, "secret", "true"), - resource.TestCheckResourceAttr(resourceName, "tags.0", "tag3"), - resource.TestCheckResourceAttr(resourceName, "tags.1", "tag4"), + testCheckAzureRMAPIManagementPropertyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", fmt.Sprintf("TestProperty2%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "value", "Test Value2"), + resource.TestCheckResourceAttr(data.ResourceName, "secret", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.0", "tag3"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.1", "tag4"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -136,7 +133,7 @@ func testCheckAzureRMAPIManagementPropertyExists(resourceName string) resource.T */ -func testAccAzureRMAPIManagementProperty_basic(rInt int, location string) string { +func testAccAzureRMAPIManagementProperty_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -161,10 +158,10 @@ resource "azurerm_api_management_property" "test" { value = "Test Value" tags = ["tag1", "tag2"] } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAPIManagementProperty_update(rInt int, location string) string { +func testAccAzureRMAPIManagementProperty_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -190,5 +187,5 @@ resource "azurerm_api_management_property" "test" { secret = true tags = ["tag3", "tag4"] } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_subscription_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go similarity index 64% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_subscription_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go index e7b30ef2ef8b..1bbd2a2f9255 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_subscription_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMAPIManagementSubscription_basic(t *testing.T) { - resourceName := "azurerm_api_management_subscription.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_subscription", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +21,16 @@ func TestAccAzureRMAPIManagementSubscription_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementSubscription_basic(ri, location), + Config: testAccAzureRMAPIManagementSubscription_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementSubscriptionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subscription_id"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -46,10 +43,7 @@ func TestAccAzureRMAPIManagementSubscription_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_subscription.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_subscription", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,26 +51,21 @@ func TestAccAzureRMAPIManagementSubscription_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementSubscription_basic(ri, location), + Config: testAccAzureRMAPIManagementSubscription_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementSubscriptionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subscription_id"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), ), }, - { - Config: testAccAzureRMAPIManagementSubscription_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_subscription"), - }, + data.RequiresImportErrorStep(testAccAzureRMAPIManagementSubscription_requiresImport), }, }) } func TestAccAzureRMAPIManagementSubscription_update(t *testing.T) { - resourceName := "azurerm_api_management_subscription.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_subscription", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,34 +73,34 @@ func TestAccAzureRMAPIManagementSubscription_update(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementSubscription_update(ri, location, "submitted"), + Config: testAccAzureRMAPIManagementSubscription_update(data, "submitted"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementSubscriptionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "state", "submitted"), - resource.TestCheckResourceAttrSet(resourceName, "subscription_id"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "state", "submitted"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), ), }, { - Config: testAccAzureRMAPIManagementSubscription_update(ri, location, "active"), + Config: testAccAzureRMAPIManagementSubscription_update(data, "active"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementSubscriptionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "state", "active"), + testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "state", "active"), ), }, { - Config: testAccAzureRMAPIManagementSubscription_update(ri, location, "suspended"), + Config: testAccAzureRMAPIManagementSubscription_update(data, "suspended"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementSubscriptionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "state", "suspended"), + testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "state", "suspended"), ), }, { - Config: testAccAzureRMAPIManagementSubscription_update(ri, location, "cancelled"), + Config: testAccAzureRMAPIManagementSubscription_update(data, "cancelled"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementSubscriptionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "state", "cancelled"), + testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "state", "cancelled"), ), }, }, @@ -119,9 +108,7 @@ func TestAccAzureRMAPIManagementSubscription_update(t *testing.T) { } func TestAccAzureRMAPIManagementSubscription_complete(t *testing.T) { - resourceName := "azurerm_api_management_subscription.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_subscription", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -129,17 +116,17 @@ func TestAccAzureRMAPIManagementSubscription_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAPIManagementSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAPIManagementSubscription_complete(ri, location), + Config: testAccAzureRMAPIManagementSubscription_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAPIManagementSubscriptionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "state", "active"), - resource.TestCheckResourceAttrSet(resourceName, "subscription_id"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "state", "active"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -195,8 +182,8 @@ func testCheckAzureRMAPIManagementSubscriptionExists(resourceName string) resour } } -func testAccAzureRMAPIManagementSubscription_basic(rInt int, location string) string { - template := testAccAzureRMAPIManagementSubscription_template(rInt, location) +func testAccAzureRMAPIManagementSubscription_basic(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementSubscription_template(data) return fmt.Sprintf(` %s @@ -210,8 +197,8 @@ resource "azurerm_api_management_subscription" "test" { `, template) } -func testAccAzureRMAPIManagementSubscription_requiresImport(rInt int, location string) string { - template := testAccAzureRMAPIManagementSubscription_basic(rInt, location) +func testAccAzureRMAPIManagementSubscription_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementSubscription_basic(data) return fmt.Sprintf(` %s @@ -225,8 +212,8 @@ resource "azurerm_api_management_subscription" "import" { `, template) } -func testAccAzureRMAPIManagementSubscription_update(rInt int, location, state string) string { - template := testAccAzureRMAPIManagementSubscription_template(rInt, location) +func testAccAzureRMAPIManagementSubscription_update(data acceptance.TestData, state string) string { + template := testAccAzureRMAPIManagementSubscription_template(data) return fmt.Sprintf(` %s @@ -241,8 +228,8 @@ resource "azurerm_api_management_subscription" "test" { `, template, state) } -func testAccAzureRMAPIManagementSubscription_complete(rInt int, location string) string { - template := testAccAzureRMAPIManagementSubscription_template(rInt, location) +func testAccAzureRMAPIManagementSubscription_complete(data acceptance.TestData) string { + template := testAccAzureRMAPIManagementSubscription_template(data) return fmt.Sprintf(` %s @@ -257,7 +244,7 @@ resource "azurerm_api_management_subscription" "test" { `, template) } -func testAccAzureRMAPIManagementSubscription_template(rInt int, location string) string { +func testAccAzureRMAPIManagementSubscription_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -292,5 +279,5 @@ resource "azurerm_api_management_user" "test" { last_name = "Test" email = "azure-acctest%d@example.com" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go similarity index 78% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go index da8bd773384f..e24401e12e3e 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,8 @@ import ( ) func TestAccAzureRMApiManagement_basic(t *testing.T) { - resourceName := "azurerm_api_management.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApiManagement_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") + config := testAccAzureRMApiManagement_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,11 +25,11 @@ func TestAccAzureRMApiManagement_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementExists(resourceName), + testCheckAzureRMApiManagementExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -41,9 +39,8 @@ func TestAccAzureRMApiManagement_basic(t *testing.T) { // Remove in 2.0 func TestAccAzureRMApiManagement_basicClassic(t *testing.T) { - resourceName := "azurerm_api_management.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApiManagement_basicClassic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") + config := testAccAzureRMApiManagement_basicClassic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,11 +50,11 @@ func TestAccAzureRMApiManagement_basicClassic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementExists(resourceName), + testCheckAzureRMApiManagementExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -67,8 +64,8 @@ func TestAccAzureRMApiManagement_basicClassic(t *testing.T) { // Remove in 2.0 func TestAccAzureRMApiManagement_basicNotDefined(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMApiManagement_basicNotDefined(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") + config := testAccAzureRMApiManagement_basicNotDefined(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -88,10 +85,7 @@ func TestAccAzureRMApiManagement_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -99,23 +93,20 @@ func TestAccAzureRMApiManagement_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagement_basic(ri, location), + Config: testAccAzureRMApiManagement_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementExists(resourceName), + testCheckAzureRMApiManagementExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagement_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagement_requiresImport), }, }) } func TestAccAzureRMApiManagement_customProps(t *testing.T) { - resourceName := "azurerm_api_management.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApiManagement_customProps(ri, acceptance.AltLocation()) + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") + + config := testAccAzureRMApiManagement_customProps(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -125,11 +116,11 @@ func TestAccAzureRMApiManagement_customProps(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementExists(resourceName), + testCheckAzureRMApiManagementExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -138,9 +129,8 @@ func TestAccAzureRMApiManagement_customProps(t *testing.T) { } func TestAccAzureRMApiManagement_complete(t *testing.T) { - resourceName := "azurerm_api_management.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApiManagement_complete(ri, acceptance.Location(), acceptance.AltLocation(), acceptance.AltLocation2()) + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") + config := testAccAzureRMApiManagement_complete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -150,13 +140,13 @@ func TestAccAzureRMApiManagement_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.Acceptance", "Test"), - resource.TestCheckResourceAttrSet(resourceName, "public_ip_addresses.#"), + testCheckAzureRMApiManagementExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Acceptance", "Test"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_ip_addresses.#"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -174,9 +164,7 @@ func TestAccAzureRMApiManagement_complete(t *testing.T) { } func TestAccAzureRMApiManagement_signInSignUpSettings(t *testing.T) { - resourceName := "azurerm_api_management.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -184,13 +172,13 @@ func TestAccAzureRMApiManagement_signInSignUpSettings(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagement_signInSignUpSettings(ri, location), + Config: testAccAzureRMApiManagement_signInSignUpSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementExists(resourceName), + testCheckAzureRMApiManagementExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -199,9 +187,7 @@ func TestAccAzureRMApiManagement_signInSignUpSettings(t *testing.T) { } func TestAccAzureRMApiManagement_policy(t *testing.T) { - resourceName := "azurerm_api_management.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -209,24 +195,24 @@ func TestAccAzureRMApiManagement_policy(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagement_policyXmlContent(ri, location), + Config: testAccAzureRMApiManagement_policyXmlContent(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementExists(resourceName), + testCheckAzureRMApiManagementExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, { - Config: testAccAzureRMApiManagement_policyXmlLink(ri, location), + Config: testAccAzureRMApiManagement_policyXmlLink(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementExists(resourceName), + testCheckAzureRMApiManagementExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -234,13 +220,13 @@ func TestAccAzureRMApiManagement_policy(t *testing.T) { }, }, { - Config: testAccAzureRMApiManagement_policyRemoved(ri, location), + Config: testAccAzureRMApiManagement_policyRemoved(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementExists(resourceName), + testCheckAzureRMApiManagementExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -304,7 +290,7 @@ func testCheckAzureRMApiManagementExists(resourceName string) resource.TestCheck } } -func testAccAzureRMApiManagement_basic(rInt int, location string) string { +func testAccAzureRMApiManagement_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -320,11 +306,11 @@ resource "azurerm_api_management" "test" { sku_name = "Developer_1" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } // Remove in 2.0 -func testAccAzureRMApiManagement_basicClassic(rInt int, location string) string { +func testAccAzureRMApiManagement_basicClassic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -343,11 +329,11 @@ resource "azurerm_api_management" "test" { capacity = 1 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } // Remove in 2.0 -func testAccAzureRMApiManagement_basicNotDefined(rInt int, location string) string { +func testAccAzureRMApiManagement_basicNotDefined(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -361,10 +347,10 @@ resource "azurerm_api_management" "test" { publisher_name = "pub1" publisher_email = "pub1@email.com" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations, data.RandomInteger) } -func testAccAzureRMApiManagement_policyXmlContent(rInt int, location string) string { +func testAccAzureRMApiManagement_policyXmlContent(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -390,10 +376,10 @@ resource "azurerm_api_management" "test" { XML } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApiManagement_policyXmlLink(rInt int, location string) string { +func testAccAzureRMApiManagement_policyXmlLink(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -413,10 +399,10 @@ resource "azurerm_api_management" "test" { xml_link = "https://gist.githubusercontent.com/tombuildsstuff/4f58581599d2c9f64b236f505a361a67/raw/0d29dcb0167af1e5afe4bd52a6d7f69ba1e05e1f/example.xml" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations, data.RandomInteger) } -func testAccAzureRMApiManagement_policyRemoved(rInt int, location string) string { +func testAccAzureRMApiManagement_policyRemoved(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -434,11 +420,11 @@ resource "azurerm_api_management" "test" { policy = [] } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApiManagement_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagement_basic(rInt, location) +func testAccAzureRMApiManagement_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagement_basic(data) return fmt.Sprintf(` %s @@ -454,7 +440,7 @@ resource "azurerm_api_management" "import" { `, template) } -func testAccAzureRMApiManagement_customProps(rInt int, location string) string { +func testAccAzureRMApiManagement_customProps(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -475,10 +461,10 @@ resource "azurerm_api_management" "test" { enable_triple_des_ciphers = true } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Secondary, data.RandomInteger) } -func testAccAzureRMApiManagement_signInSignUpSettings(rInt int, location string) string { +func testAccAzureRMApiManagement_signInSignUpSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -508,10 +494,10 @@ resource "azurerm_api_management" "test" { } } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApiManagement_complete(rInt int, location string, altLocation string, altLocation2 string) string { +func testAccAzureRMApiManagement_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test1" { name = "acctestRG-api1-%d" @@ -596,5 +582,5 @@ resource "azurerm_api_management" "test" { location = "${azurerm_resource_group.test1.location}" resource_group_name = "${azurerm_resource_group.test1.name}" } -`, rInt, location, rInt, altLocation, rInt, altLocation2, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.Locations.Ternary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_user_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go similarity index 65% rename from azurerm/internal/services/apimanagement/resource_arm_api_management_user_test.go rename to azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go index b9b625d8fbdf..956ad2c83ab7 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_user_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go @@ -1,4 +1,4 @@ -package apimanagement +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMApiManagementUser_basic(t *testing.T) { - resourceName := "azurerm_api_management_user.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_user", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,15 +21,15 @@ func TestAccAzureRMApiManagementUser_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementUserDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementUser_basic(ri, location), + Config: testAccAzureRMApiManagementUser_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementUserExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), - resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), + testCheckAzureRMApiManagementUserExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(data.ResourceName, "last_name", "Test"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -45,10 +42,7 @@ func TestAccAzureRMApiManagementUser_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_api_management_user.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_user", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,23 +50,18 @@ func TestAccAzureRMApiManagementUser_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementUserDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementUser_basic(ri, location), + Config: testAccAzureRMApiManagementUser_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementUserExists(resourceName), + testCheckAzureRMApiManagementUserExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApiManagementUser_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_api_management_user"), - }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementUser_requiresImport), }, }) } func TestAccAzureRMApiManagementUser_update(t *testing.T) { - resourceName := "azurerm_api_management_user.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_user", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,30 +69,30 @@ func TestAccAzureRMApiManagementUser_update(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementUserDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementUser_basic(ri, location), + Config: testAccAzureRMApiManagementUser_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementUserExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), - resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), - resource.TestCheckResourceAttr(resourceName, "state", "active"), + testCheckAzureRMApiManagementUserExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(data.ResourceName, "last_name", "Test"), + resource.TestCheckResourceAttr(data.ResourceName, "state", "active"), ), }, { - Config: testAccAzureRMApiManagementUser_updatedBlocked(ri, location), + Config: testAccAzureRMApiManagementUser_updatedBlocked(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementUserExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance Updated"), - resource.TestCheckResourceAttr(resourceName, "last_name", "Test Updated"), - resource.TestCheckResourceAttr(resourceName, "state", "blocked"), + testCheckAzureRMApiManagementUserExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "first_name", "Acceptance Updated"), + resource.TestCheckResourceAttr(data.ResourceName, "last_name", "Test Updated"), + resource.TestCheckResourceAttr(data.ResourceName, "state", "blocked"), ), }, { - Config: testAccAzureRMApiManagementUser_updatedActive(ri, location), + Config: testAccAzureRMApiManagementUser_updatedActive(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementUserExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), - resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), - resource.TestCheckResourceAttr(resourceName, "state", "active"), + testCheckAzureRMApiManagementUserExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(data.ResourceName, "last_name", "Test"), + resource.TestCheckResourceAttr(data.ResourceName, "state", "active"), ), }, }, @@ -111,9 +100,7 @@ func TestAccAzureRMApiManagementUser_update(t *testing.T) { } func TestAccAzureRMApiManagementUser_password(t *testing.T) { - resourceName := "azurerm_api_management_user.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_user", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -121,15 +108,15 @@ func TestAccAzureRMApiManagementUser_password(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementUserDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementUser_password(ri, location), + Config: testAccAzureRMApiManagementUser_password(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementUserExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), - resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), + testCheckAzureRMApiManagementUserExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(data.ResourceName, "last_name", "Test"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"password"}, @@ -139,9 +126,7 @@ func TestAccAzureRMApiManagementUser_password(t *testing.T) { } func TestAccAzureRMApiManagementUser_invite(t *testing.T) { - resourceName := "azurerm_api_management_user.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_user", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -149,13 +134,13 @@ func TestAccAzureRMApiManagementUser_invite(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementUserDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementUser_invited(ri, location), + Config: testAccAzureRMApiManagementUser_invited(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementUserExists(resourceName), + testCheckAzureRMApiManagementUserExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -168,9 +153,7 @@ func TestAccAzureRMApiManagementUser_invite(t *testing.T) { } func TestAccAzureRMApiManagementUser_signup(t *testing.T) { - resourceName := "azurerm_api_management_user.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_user", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -178,13 +161,13 @@ func TestAccAzureRMApiManagementUser_signup(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementUserDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementUser_signUp(ri, location), + Config: testAccAzureRMApiManagementUser_signUp(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementUserExists(resourceName), + testCheckAzureRMApiManagementUserExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -197,9 +180,7 @@ func TestAccAzureRMApiManagementUser_signup(t *testing.T) { } func TestAccAzureRMApiManagementUser_complete(t *testing.T) { - resourceName := "azurerm_api_management_user.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_api_management_user", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -207,16 +188,16 @@ func TestAccAzureRMApiManagementUser_complete(t *testing.T) { CheckDestroy: testCheckAzureRMApiManagementUserDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApiManagementUser_complete(ri, location), + Config: testAccAzureRMApiManagementUser_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApiManagementUserExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "first_name", "Acceptance"), - resource.TestCheckResourceAttr(resourceName, "last_name", "Test"), - resource.TestCheckResourceAttr(resourceName, "note", "Used for testing in dimension C-137."), + testCheckAzureRMApiManagementUserExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "first_name", "Acceptance"), + resource.TestCheckResourceAttr(data.ResourceName, "last_name", "Test"), + resource.TestCheckResourceAttr(data.ResourceName, "note", "Used for testing in dimension C-137."), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -282,8 +263,8 @@ func testCheckAzureRMApiManagementUserExists(resourceName string) resource.TestC } } -func testAccAzureRMApiManagementUser_basic(rInt int, location string) string { - template := testAccAzureRMApiManagementUser_template(rInt, location) +func testAccAzureRMApiManagementUser_basic(data acceptance.TestData) string { + template := testAccAzureRMApiManagementUser_template(data) return fmt.Sprintf(` %s @@ -295,11 +276,11 @@ resource "azurerm_api_management_user" "test" { last_name = "Test" email = "azure-acctest%d@example.com" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementUser_requiresImport(rInt int, location string) string { - template := testAccAzureRMApiManagementUser_basic(rInt, location) +func testAccAzureRMApiManagementUser_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementUser_basic(data) return fmt.Sprintf(` %s @@ -315,8 +296,8 @@ resource "azurerm_api_management_user" "import" { `, template) } -func testAccAzureRMApiManagementUser_password(rInt int, location string) string { - template := testAccAzureRMApiManagementUser_template(rInt, location) +func testAccAzureRMApiManagementUser_password(data acceptance.TestData) string { + template := testAccAzureRMApiManagementUser_template(data) return fmt.Sprintf(` %s @@ -330,11 +311,11 @@ resource "azurerm_api_management_user" "test" { state = "active" password = "3991bb15-282d-4b9b-9de3-3d5fc89eb530" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementUser_updatedActive(rInt int, location string) string { - template := testAccAzureRMApiManagementUser_template(rInt, location) +func testAccAzureRMApiManagementUser_updatedActive(data acceptance.TestData) string { + template := testAccAzureRMApiManagementUser_template(data) return fmt.Sprintf(` %s @@ -347,11 +328,11 @@ resource "azurerm_api_management_user" "test" { email = "azure-acctest%d@example.com" state = "active" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementUser_updatedBlocked(rInt int, location string) string { - template := testAccAzureRMApiManagementUser_template(rInt, location) +func testAccAzureRMApiManagementUser_updatedBlocked(data acceptance.TestData) string { + template := testAccAzureRMApiManagementUser_template(data) return fmt.Sprintf(` %s @@ -364,11 +345,11 @@ resource "azurerm_api_management_user" "test" { email = "azure-acctest%d@example.com" state = "blocked" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementUser_invited(rInt int, location string) string { - template := testAccAzureRMApiManagementUser_template(rInt, location) +func testAccAzureRMApiManagementUser_invited(data acceptance.TestData) string { + template := testAccAzureRMApiManagementUser_template(data) return fmt.Sprintf(` %s @@ -382,11 +363,11 @@ resource "azurerm_api_management_user" "test" { state = "blocked" confirmation = "invite" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementUser_signUp(rInt int, location string) string { - template := testAccAzureRMApiManagementUser_template(rInt, location) +func testAccAzureRMApiManagementUser_signUp(data acceptance.TestData) string { + template := testAccAzureRMApiManagementUser_template(data) return fmt.Sprintf(` %s @@ -400,11 +381,11 @@ resource "azurerm_api_management_user" "test" { state = "blocked" confirmation = "signup" } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementUser_complete(rInt int, location string) string { - template := testAccAzureRMApiManagementUser_template(rInt, location) +func testAccAzureRMApiManagementUser_complete(data acceptance.TestData) string { + template := testAccAzureRMApiManagementUser_template(data) return fmt.Sprintf(` %s @@ -419,10 +400,10 @@ resource "azurerm_api_management_user" "test" { confirmation = "signup" note = "Used for testing in dimension C-137." } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApiManagementUser_template(rInt int, location string) string { +func testAccAzureRMApiManagementUser_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -438,5 +419,5 @@ resource "azurerm_api_management" "test" { sku_name = "Developer_1" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/apimanagement/testdata/api_management_api2_test.pfx b/azurerm/internal/services/apimanagement/tests/testdata/api_management_api2_test.pfx similarity index 100% rename from azurerm/internal/services/apimanagement/testdata/api_management_api2_test.pfx rename to azurerm/internal/services/apimanagement/tests/testdata/api_management_api2_test.pfx diff --git a/azurerm/internal/services/apimanagement/testdata/api_management_api_schema.xml b/azurerm/internal/services/apimanagement/tests/testdata/api_management_api_schema.xml similarity index 100% rename from azurerm/internal/services/apimanagement/testdata/api_management_api_schema.xml rename to azurerm/internal/services/apimanagement/tests/testdata/api_management_api_schema.xml diff --git a/azurerm/internal/services/apimanagement/testdata/api_management_api_swagger.json b/azurerm/internal/services/apimanagement/tests/testdata/api_management_api_swagger.json similarity index 100% rename from azurerm/internal/services/apimanagement/testdata/api_management_api_swagger.json rename to azurerm/internal/services/apimanagement/tests/testdata/api_management_api_swagger.json diff --git a/azurerm/internal/services/apimanagement/testdata/api_management_api_test.pfx b/azurerm/internal/services/apimanagement/tests/testdata/api_management_api_test.pfx similarity index 100% rename from azurerm/internal/services/apimanagement/testdata/api_management_api_test.pfx rename to azurerm/internal/services/apimanagement/tests/testdata/api_management_api_test.pfx diff --git a/azurerm/internal/services/apimanagement/testdata/api_management_api_wsdl.xml b/azurerm/internal/services/apimanagement/tests/testdata/api_management_api_wsdl.xml similarity index 100% rename from azurerm/internal/services/apimanagement/testdata/api_management_api_wsdl.xml rename to azurerm/internal/services/apimanagement/tests/testdata/api_management_api_wsdl.xml diff --git a/azurerm/internal/services/apimanagement/testdata/api_management_portal_test.pfx b/azurerm/internal/services/apimanagement/tests/testdata/api_management_portal_test.pfx similarity index 100% rename from azurerm/internal/services/apimanagement/testdata/api_management_portal_test.pfx rename to azurerm/internal/services/apimanagement/tests/testdata/api_management_portal_test.pfx diff --git a/azurerm/internal/services/apimanagement/testdata/api_management_testdata.sh b/azurerm/internal/services/apimanagement/tests/testdata/api_management_testdata.sh similarity index 100% rename from azurerm/internal/services/apimanagement/testdata/api_management_testdata.sh rename to azurerm/internal/services/apimanagement/tests/testdata/api_management_testdata.sh diff --git a/azurerm/internal/services/apimanagement/testdata/keyvaultcert.pfx b/azurerm/internal/services/apimanagement/tests/testdata/keyvaultcert.pfx similarity index 100% rename from azurerm/internal/services/apimanagement/testdata/keyvaultcert.pfx rename to azurerm/internal/services/apimanagement/tests/testdata/keyvaultcert.pfx From c4b859841dade01ee5d515563f2bf160894d5e90 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Fri, 20 Dec 2019 11:59:21 -0800 Subject: [PATCH 095/203] tests: appconfiguration --- .../data_source_api_management_user_test.go | 2 +- .../resource_arm_app_configuration.go | 4 +- .../resource_arm_app_configuration_test.go | 81 ++++++++----------- 3 files changed, 37 insertions(+), 50 deletions(-) rename azurerm/internal/services/appconfiguration/{ => tests}/resource_arm_app_configuration_test.go (77%) diff --git a/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go index 23251c840887..9299be52682e 100644 --- a/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go @@ -67,5 +67,5 @@ data "azurerm_api_management_user" "test" { api_management_name = "${azurerm_api_management_user.test.api_management_name}" resource_group_name = "${azurerm_api_management_user.test.resource_group_name}" } -`, data.RandomInteger, &data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/appconfiguration/resource_arm_app_configuration.go b/azurerm/internal/services/appconfiguration/resource_arm_app_configuration.go index bccb6a6c9636..3a4b565a23b7 100644 --- a/azurerm/internal/services/appconfiguration/resource_arm_app_configuration.go +++ b/azurerm/internal/services/appconfiguration/resource_arm_app_configuration.go @@ -43,7 +43,7 @@ func resourceArmAppConfiguration() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAppConfigurationName, + ValidateFunc: ValidateAppConfigurationName, }, "location": azure.SchemaLocation(), @@ -378,7 +378,7 @@ func resourceArmAppConfigurationDelete(d *schema.ResourceData, meta interface{}) return nil } -func validateAppConfigurationName(v interface{}, k string) (warnings []string, errors []error) { +func ValidateAppConfigurationName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if matched := regexp.MustCompile(`^[a-zA-Z0-9-]{5,50}$`).Match([]byte(value)); !matched { errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes and must be between 5-50 chars", k)) diff --git a/azurerm/internal/services/appconfiguration/resource_arm_app_configuration_test.go b/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go similarity index 77% rename from azurerm/internal/services/appconfiguration/resource_arm_app_configuration_test.go rename to azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go index 79a0aa7f807e..49ac2ccbe5d1 100644 --- a/azurerm/internal/services/appconfiguration/resource_arm_app_configuration_test.go +++ b/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go @@ -1,13 +1,13 @@ -package appconfiguration +package tests import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appconfiguration" "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/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -62,7 +62,7 @@ func TestAccAzureRMAppConfigurationName_validation(t *testing.T) { } for _, tc := range cases { - _, errors := validateAppConfigurationName(tc.Value, "azurerm_app_configuration") + _, errors := appconfiguration.ValidateAppConfigurationName(tc.Value, "azurerm_app_configuration") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Azure App Configuration Name to trigger a validation error: %v", tc) @@ -71,9 +71,7 @@ func TestAccAzureRMAppConfigurationName_validation(t *testing.T) { } func TestAccAzureAppConfiguration_free(t *testing.T) { - rn := "azurerm_app_configuration.test" - ri := tf.AccRandTimeInt() - l := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,13 +79,13 @@ func TestAccAzureAppConfiguration_free(t *testing.T) { CheckDestroy: testCheckAzureAppConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureAppConfiguration_free(ri, l), + Config: testAccAzureAppConfiguration_free(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureAppConfigurationExists(rn), + testCheckAzureAppConfigurationExists(data.ResourceName), ), }, { - ResourceName: rn, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -96,9 +94,7 @@ func TestAccAzureAppConfiguration_free(t *testing.T) { } func TestAccAzureAppConfiguration_standard(t *testing.T) { - rn := "azurerm_app_configuration.test" - ri := tf.AccRandTimeInt() - l := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -106,13 +102,13 @@ func TestAccAzureAppConfiguration_standard(t *testing.T) { CheckDestroy: testCheckAzureAppConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureAppConfiguration_standard(ri, l), + Config: testAccAzureAppConfiguration_standard(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureAppConfigurationExists(rn), + testCheckAzureAppConfigurationExists(data.ResourceName), ), }, { - ResourceName: rn, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -125,10 +121,7 @@ func TestAccAzureAppConfiguration_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - rn := "azurerm_app_configuration.test" - ri := tf.AccRandTimeInt() - l := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -136,22 +129,18 @@ func TestAccAzureAppConfiguration_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureAppConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureAppConfiguration_free(ri, l), + Config: testAccAzureAppConfiguration_free(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureAppConfigurationExists(rn), + testCheckAzureAppConfigurationExists(data.ResourceName), ), }, - { - Config: testAccAzureAppConfiguration_requiresImport(ri, l), - ExpectError: acceptance.RequiresImportError("azurerm_app_configuration"), - }, + data.RequiresImportErrorStep(testAccAzureAppConfiguration_requiresImport), }, }) } func TestAccAzureAppConfiguration_complete(t *testing.T) { - rn := "azurerm_app_configuration.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_app_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -159,13 +148,13 @@ func TestAccAzureAppConfiguration_complete(t *testing.T) { CheckDestroy: testCheckAzureAppConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureAppConfiguration_complete(ri, acceptance.Location()), + Config: testAccAzureAppConfiguration_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureAppConfigurationExists(rn), + testCheckAzureAppConfigurationExists(data.ResourceName), ), }, { - ResourceName: rn, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -174,9 +163,7 @@ func TestAccAzureAppConfiguration_complete(t *testing.T) { } func TestAccAzureAppConfiguration_update(t *testing.T) { - rn := "azurerm_app_configuration.test" - ri := tf.AccRandTimeInt() - l := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_app_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -184,15 +171,15 @@ func TestAccAzureAppConfiguration_update(t *testing.T) { CheckDestroy: testCheckAzureAppConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureAppConfiguration_complete(ri, l), + Config: testAccAzureAppConfiguration_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureAppConfigurationExists(rn), + testCheckAzureAppConfigurationExists(data.ResourceName), ), }, { - Config: testAccAzureAppConfiguration_completeUpdated(ri, l), + Config: testAccAzureAppConfiguration_completeUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureAppConfigurationExists(rn), + testCheckAzureAppConfigurationExists(data.ResourceName), ), }, }, @@ -254,7 +241,7 @@ func testCheckAzureAppConfigurationExists(resourceName string) resource.TestChec } } -func testAccAzureAppConfiguration_free(rInt int, location string) string { +func testAccAzureAppConfiguration_free(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -267,10 +254,10 @@ resource "azurerm_app_configuration" "test" { location = "${azurerm_resource_group.test.location}" sku = "free" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureAppConfiguration_standard(rInt int, location string) string { +func testAccAzureAppConfiguration_standard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -283,11 +270,11 @@ resource "azurerm_app_configuration" "test" { location = "${azurerm_resource_group.test.location}" sku = "standard" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureAppConfiguration_requiresImport(rInt int, location string) string { - template := testAccAzureAppConfiguration_free(rInt, location) +func testAccAzureAppConfiguration_requiresImport(data acceptance.TestData) string { + template := testAccAzureAppConfiguration_free(data) return fmt.Sprintf(` %s @@ -301,7 +288,7 @@ resource "azurerm_app_configuration" "import" { `, template) } -func testAccAzureAppConfiguration_complete(rInt int, location string) string { +func testAccAzureAppConfiguration_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -318,10 +305,10 @@ resource "azurerm_app_configuration" "test" { environment = "development" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureAppConfiguration_completeUpdated(rInt int, location string) string { +func testAccAzureAppConfiguration_completeUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -338,5 +325,5 @@ resource "azurerm_app_configuration" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 92ba59a5c28f46b693454981cd5e10cbda14a309 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 20 Dec 2019 13:23:17 -0800 Subject: [PATCH 096/203] loganalytics: switching to the new structure --- ...source_arm_log_analytics_linked_service.go | 2 +- .../resource_arm_log_analytics_solution.go | 2 +- .../resource_arm_log_analytics_workspace.go | 4 +- ..._log_analytics_workspace_linked_service.go | 2 +- ...ata_source_log_analytics_workspace_test.go | 17 ++-- ...e_arm_log_analytics_linked_service_test.go | 94 ++++++++----------- ...esource_arm_log_analytics_solution_test.go | 53 ++++------- ...analytics_workspace_linked_service_test.go | 94 ++++++++----------- ...source_arm_log_analytics_workspace_test.go | 54 +++++------ 9 files changed, 128 insertions(+), 194 deletions(-) rename azurerm/internal/services/loganalytics/{ => tests}/data_source_log_analytics_workspace_test.go (59%) rename azurerm/internal/services/loganalytics/{ => tests}/resource_arm_log_analytics_linked_service_test.go (70%) rename azurerm/internal/services/loganalytics/{ => tests}/resource_arm_log_analytics_solution_test.go (80%) rename azurerm/internal/services/loganalytics/{ => tests}/resource_arm_log_analytics_workspace_linked_service_test.go (75%) rename azurerm/internal/services/loganalytics/{ => tests}/resource_arm_log_analytics_workspace_test.go (79%) diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go index 5266d80dc57d..a97b22fc6eda 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service.go @@ -44,7 +44,7 @@ func resourceArmLogAnalyticsLinkedService() *schema.Resource { Required: true, ForceNew: true, DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validateAzureRmLogAnalyticsWorkspaceName, + ValidateFunc: ValidateAzureRmLogAnalyticsWorkspaceName, }, "linked_service_name": { diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution.go index 5fca6cdaa9ca..3b7c63a9cc87 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution.go @@ -48,7 +48,7 @@ func resourceArmLogAnalyticsSolution() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureRmLogAnalyticsWorkspaceName, + ValidateFunc: ValidateAzureRmLogAnalyticsWorkspaceName, }, "workspace_resource_id": { diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace.go index a1021d78adb0..b452fb3dd089 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace.go @@ -41,7 +41,7 @@ func resourceArmLogAnalyticsWorkspace() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureRmLogAnalyticsWorkspaceName, + ValidateFunc: ValidateAzureRmLogAnalyticsWorkspaceName, }, "location": azure.SchemaLocation(), @@ -231,7 +231,7 @@ func resourceArmLogAnalyticsWorkspaceDelete(d *schema.ResourceData, meta interfa return nil } -func validateAzureRmLogAnalyticsWorkspaceName(v interface{}, _ string) (warnings []string, errors []error) { +func ValidateAzureRmLogAnalyticsWorkspaceName(v interface{}, _ string) (warnings []string, errors []error) { value := v.(string) r, _ := regexp.Compile("^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$") diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go index ee061834b634..a4377a5957c9 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go +++ b/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service.go @@ -51,7 +51,7 @@ As such the existing 'azurerm_log_analytics_workspace_linked_service' resource i Required: true, ForceNew: true, DiffSuppressFunc: suppress.CaseDifference, - ValidateFunc: validateAzureRmLogAnalyticsWorkspaceName, + ValidateFunc: ValidateAzureRmLogAnalyticsWorkspaceName, }, "linked_service_name": { diff --git a/azurerm/internal/services/loganalytics/data_source_log_analytics_workspace_test.go b/azurerm/internal/services/loganalytics/tests/data_source_log_analytics_workspace_test.go similarity index 59% rename from azurerm/internal/services/loganalytics/data_source_log_analytics_workspace_test.go rename to azurerm/internal/services/loganalytics/tests/data_source_log_analytics_workspace_test.go index 9e777e753231..56f6b7ce688e 100644 --- a/azurerm/internal/services/loganalytics/data_source_log_analytics_workspace_test.go +++ b/azurerm/internal/services/loganalytics/tests/data_source_log_analytics_workspace_test.go @@ -1,18 +1,15 @@ -package loganalytics +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMLogAnalyticsWorkspace_basic(t *testing.T) { - dataSourceName := "data.azurerm_log_analytics_workspace.test" - ri := tf.AccRandTimeInt() - config := testAccDataSourceAzureRMLogAnalyticsWorkspace_basicWithDataSource(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "data.azurerm_log_analytics_workspace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,18 +17,18 @@ func TestAccDataSourceAzureRMLogAnalyticsWorkspace_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMLogAnalyticsWorkspace_basicWithDataSource(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "sku", "pergb2018"), - resource.TestCheckResourceAttr(dataSourceName, "retention_in_days", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "pergb2018"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_in_days", "30"), ), }, }, }) } -func testAccDataSourceAzureRMLogAnalyticsWorkspace_basicWithDataSource(rInt int, location string) string { - config := testAccAzureRMLogAnalyticsWorkspace_complete(rInt, location) +func testAccDataSourceAzureRMLogAnalyticsWorkspace_basicWithDataSource(data acceptance.TestData) string { + config := testAccAzureRMLogAnalyticsWorkspace_complete(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service_test.go b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go similarity index 70% rename from azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service_test.go rename to azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go index 7031dc832809..ef04153c96da 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_linked_service_test.go +++ b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_linked_service_test.go @@ -1,4 +1,4 @@ -package loganalytics +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMLogAnalyticsLinkedService_basic(t *testing.T) { - resourceName := "azurerm_log_analytics_linked_service.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_linked_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,19 +22,15 @@ func TestAccAzureRMLogAnalyticsLinkedService_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsLinkedService_basic(ri, acceptance.Location()), + Config: testAccAzureRMLogAnalyticsLinkedService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsLinkedServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctestlaw-%d/Automation", ri)), - resource.TestCheckResourceAttr(resourceName, "workspace_name", fmt.Sprintf("acctestlaw-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "linked_service_name", "automation"), + testCheckAzureRMLogAnalyticsLinkedServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctestlaw-%d/Automation", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "workspace_name", fmt.Sprintf("acctestlaw-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "linked_service_name", "automation"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,9 +41,7 @@ func TestAccAzureRMLogAnalyticsLinkedService_requiresImport(t *testing.T) { return } - resourceName := "azurerm_log_analytics_linked_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_linked_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,16 +49,16 @@ func TestAccAzureRMLogAnalyticsLinkedService_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsLinkedService_basic(ri, location), + Config: testAccAzureRMLogAnalyticsLinkedService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsLinkedServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctestlaw-%d/Automation", ri)), - resource.TestCheckResourceAttr(resourceName, "workspace_name", fmt.Sprintf("acctestlaw-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "linked_service_name", "automation"), + testCheckAzureRMLogAnalyticsLinkedServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctestlaw-%d/Automation", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "workspace_name", fmt.Sprintf("acctestlaw-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "linked_service_name", "automation"), ), }, { - Config: testAccAzureRMLogAnalyticsLinkedService_requiresImport(ri, location), + Config: testAccAzureRMLogAnalyticsLinkedService_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_log_analytics_linked_service"), }, }, @@ -74,8 +66,7 @@ func TestAccAzureRMLogAnalyticsLinkedService_requiresImport(t *testing.T) { } func TestAccAzureRMLogAnalyticsLinkedService_complete(t *testing.T) { - resourceName := "azurerm_log_analytics_linked_service.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_linked_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -83,24 +74,20 @@ func TestAccAzureRMLogAnalyticsLinkedService_complete(t *testing.T) { CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsLinkedService_complete(ri, acceptance.Location()), + Config: testAccAzureRMLogAnalyticsLinkedService_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsLinkedServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "linked_service_name", "automation"), + testCheckAzureRMLogAnalyticsLinkedServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "linked_service_name", "automation"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } // Deprecated - remove in 2.0 func TestAccAzureRMLogAnalyticsLinkedService_noResourceID(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "ignored", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -108,7 +95,7 @@ func TestAccAzureRMLogAnalyticsLinkedService_noResourceID(t *testing.T) { CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsLinkedService_noResourceID(ri, acceptance.Location()), + Config: testAccAzureRMLogAnalyticsLinkedService_noResourceID(data), ExpectError: regexp.MustCompile("A `resource_id` must be specified either using the `resource_id` field at the top level or within the `linked_service_properties` block"), }, }, @@ -117,8 +104,7 @@ func TestAccAzureRMLogAnalyticsLinkedService_noResourceID(t *testing.T) { // Deprecated - remove in 2.0 func TestAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(t *testing.T) { - resourceName := "azurerm_log_analytics_linked_service.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_linked_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -126,16 +112,12 @@ func TestAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(t *testing. CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(ri, acceptance.Location()), + Config: testAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsLinkedServiceExists(resourceName), + testCheckAzureRMLogAnalyticsLinkedServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -202,8 +184,8 @@ func testCheckAzureRMLogAnalyticsLinkedServiceExists(resourceName string) resour } } -func testAccAzureRMLogAnalyticsLinkedService_basic(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsLinkedService_template(rInt, location) +func testAccAzureRMLogAnalyticsLinkedService_basic(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsLinkedService_template(data) return fmt.Sprintf(` %s @@ -215,8 +197,8 @@ resource "azurerm_log_analytics_linked_service" "test" { `, template) } -func testAccAzureRMLogAnalyticsLinkedService_requiresImport(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsLinkedService_basic(rInt, location) +func testAccAzureRMLogAnalyticsLinkedService_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsLinkedService_basic(data) return fmt.Sprintf(` %s @@ -228,8 +210,8 @@ resource "azurerm_log_analytics_linked_service" "import" { `, template) } -func testAccAzureRMLogAnalyticsLinkedService_complete(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsLinkedService_template(rInt, location) +func testAccAzureRMLogAnalyticsLinkedService_complete(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsLinkedService_template(data) return fmt.Sprintf(` %s @@ -242,8 +224,8 @@ resource "azurerm_log_analytics_linked_service" "test" { `, template) } -func testAccAzureRMLogAnalyticsLinkedService_noResourceID(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsLinkedService_template(rInt, location) +func testAccAzureRMLogAnalyticsLinkedService_noResourceID(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsLinkedService_template(data) return fmt.Sprintf(` %s @@ -254,8 +236,8 @@ resource "azurerm_log_analytics_linked_service" "test" { `, template) } -func testAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsLinkedService_template(rInt, location) +func testAccAzureRMLogAnalyticsLinkedService_linkedServiceProperties(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsLinkedService_template(data) return fmt.Sprintf(` %s @@ -269,7 +251,7 @@ resource "azurerm_log_analytics_linked_service" "test" { `, template) } -func testAccAzureRMLogAnalyticsLinkedService_template(rInt int, location string) string { +func testAccAzureRMLogAnalyticsLinkedService_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -297,5 +279,5 @@ resource "azurerm_log_analytics_workspace" "test" { sku = "PerGB2018" retention_in_days = 30 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution_test.go b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_solution_test.go similarity index 80% rename from azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution_test.go rename to azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_solution_test.go index 634450f04d22..36d7e28cc293 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_solution_test.go +++ b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_solution_test.go @@ -1,4 +1,4 @@ -package loganalytics +package tests import ( "fmt" @@ -7,32 +7,25 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMLogAnalyticsSolution_basicContainerMonitoring(t *testing.T) { - resourceName := "azurerm_log_analytics_solution.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMLogAnalyticsSolution_containerMonitoring(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_log_analytics_solution", "test") resource.ParallelTest(t, resource.TestCase{ Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogAnalyticsSolutionDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMLogAnalyticsSolution_containerMonitoring(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsSolutionExists(resourceName), + testCheckAzureRMLogAnalyticsSolutionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,22 +36,20 @@ func TestAccAzureRMLogAnalyticsSolution_requiresImport(t *testing.T) { return } - resourceName := "azurerm_log_analytics_solution.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_solution", "test") resource.ParallelTest(t, resource.TestCase{ Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogAnalyticsSolutionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsSolution_containerMonitoring(ri, location), + Config: testAccAzureRMLogAnalyticsSolution_containerMonitoring(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsSolutionExists(resourceName), + testCheckAzureRMLogAnalyticsSolutionExists(data.ResourceName), ), }, { - Config: testAccAzureRMLogAnalyticsSolution_requiresImport(ri, location), + Config: testAccAzureRMLogAnalyticsSolution_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_log_analytics_solution"), }, }, @@ -66,25 +57,19 @@ func TestAccAzureRMLogAnalyticsSolution_requiresImport(t *testing.T) { } func TestAccAzureRMLogAnalyticsSolution_basicSecurity(t *testing.T) { - resourceName := "azurerm_log_analytics_solution.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMLogAnalyticsSolution_security(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_log_analytics_solution", "test") resource.ParallelTest(t, resource.TestCase{ Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogAnalyticsSolutionDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMLogAnalyticsSolution_security(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsSolutionExists(resourceName), + testCheckAzureRMLogAnalyticsSolutionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -145,7 +130,7 @@ func testCheckAzureRMLogAnalyticsSolutionExists(resourceName string) resource.Te } } -func testAccAzureRMLogAnalyticsSolution_containerMonitoring(rInt int, location string) string { +func testAccAzureRMLogAnalyticsSolution_containerMonitoring(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -171,11 +156,11 @@ resource "azurerm_log_analytics_solution" "test" { product = "OMSGallery/ContainerInsights" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLogAnalyticsSolution_requiresImport(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsSolution_containerMonitoring(rInt, location) +func testAccAzureRMLogAnalyticsSolution_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsSolution_containerMonitoring(data) return fmt.Sprintf(` %s @@ -194,7 +179,7 @@ resource "azurerm_log_analytics_solution" "import" { `, template) } -func testAccAzureRMLogAnalyticsSolution_security(rInt int, location string) string { +func testAccAzureRMLogAnalyticsSolution_security(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -220,5 +205,5 @@ resource "azurerm_log_analytics_solution" "test" { product = "OMSGallery/Security" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service_test.go b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_linked_service_test.go similarity index 75% rename from azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service_test.go rename to azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_linked_service_test.go index 226b11261d51..daebc725f3cb 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_linked_service_test.go +++ b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_linked_service_test.go @@ -1,4 +1,4 @@ -package loganalytics +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_basic(t *testing.T) { - resourceName := "azurerm_log_analytics_workspace_linked_service.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace_linked_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,19 +22,15 @@ func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_basic(ri, acceptance.Location()), + Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctestlaw-%d/Automation", ri)), - resource.TestCheckResourceAttr(resourceName, "workspace_name", fmt.Sprintf("acctestlaw-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "linked_service_name", "automation"), + testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctestlaw-%d/Automation", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "workspace_name", fmt.Sprintf("acctestlaw-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "linked_service_name", "automation"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,9 +41,7 @@ func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_requiresImport(t *testing. return } - resourceName := "azurerm_log_analytics_workspace_linked_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace_linked_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,16 +49,16 @@ func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_requiresImport(t *testing. CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_basic(ri, location), + Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctestlaw-%d/Automation", ri)), - resource.TestCheckResourceAttr(resourceName, "workspace_name", fmt.Sprintf("acctestlaw-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "linked_service_name", "automation"), + testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctestlaw-%d/Automation", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "workspace_name", fmt.Sprintf("acctestlaw-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "linked_service_name", "automation"), ), }, { - Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_requiresImport(ri, location), + Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_log_analytics_workspace_linked_service"), }, }, @@ -74,8 +66,7 @@ func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_requiresImport(t *testing. } func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_complete(t *testing.T) { - resourceName := "azurerm_log_analytics_workspace_linked_service.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace_linked_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -83,24 +74,20 @@ func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_complete(t *testing.T) { CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_complete(ri, acceptance.Location()), + Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "linked_service_name", "automation"), + testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "linked_service_name", "automation"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } // Deprecated - remove in 2.0 func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_noResourceID(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "ignored", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -108,7 +95,7 @@ func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_noResourceID(t *testing.T) CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_noResourceID(ri, acceptance.Location()), + Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_noResourceID(data), ExpectError: regexp.MustCompile("A `resource_id` must be specified either using the `resource_id` field at the top level or within the `linked_service_properties` block"), }, }, @@ -117,8 +104,7 @@ func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_noResourceID(t *testing.T) // Deprecated - remove in 2.0 func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_linkedServiceProperties(t *testing.T) { - resourceName := "azurerm_log_analytics_workspace_linked_service.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace_linked_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -126,16 +112,12 @@ func TestAccAzureRMLogAnalyticsWorkspaceLinkedService_linkedServiceProperties(t CheckDestroy: testCheckAzureRMLogAnalyticsLinkedServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_linkedServiceProperties(ri, acceptance.Location()), + Config: testAccAzureRMLogAnalyticsWorkspaceLinkedService_linkedServiceProperties(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceExists(resourceName), + testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -202,8 +184,8 @@ func testCheckAzureRMLogAnalyticsWorkspaceLinkedServiceExists(resourceName strin } } -func testAccAzureRMLogAnalyticsWorkspaceLinkedService_basic(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsWorkspaceLinkedService_template(rInt, location) +func testAccAzureRMLogAnalyticsWorkspaceLinkedService_basic(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsWorkspaceLinkedService_template(data) return fmt.Sprintf(` %s @@ -215,8 +197,8 @@ resource "azurerm_log_analytics_workspace_linked_service" "test" { `, template) } -func testAccAzureRMLogAnalyticsWorkspaceLinkedService_requiresImport(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsWorkspaceLinkedService_basic(rInt, location) +func testAccAzureRMLogAnalyticsWorkspaceLinkedService_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsWorkspaceLinkedService_basic(data) return fmt.Sprintf(` %s @@ -228,8 +210,8 @@ resource "azurerm_log_analytics_workspace_linked_service" "import" { `, template) } -func testAccAzureRMLogAnalyticsWorkspaceLinkedService_complete(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsWorkspaceLinkedService_template(rInt, location) +func testAccAzureRMLogAnalyticsWorkspaceLinkedService_complete(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsWorkspaceLinkedService_template(data) return fmt.Sprintf(` %s @@ -242,8 +224,8 @@ resource "azurerm_log_analytics_workspace_linked_service" "test" { `, template) } -func testAccAzureRMLogAnalyticsWorkspaceLinkedService_noResourceID(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsWorkspaceLinkedService_template(rInt, location) +func testAccAzureRMLogAnalyticsWorkspaceLinkedService_noResourceID(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsWorkspaceLinkedService_template(data) return fmt.Sprintf(` %s resource "azurerm_log_analytics_workspace_linked_service" "test" { @@ -253,8 +235,8 @@ resource "azurerm_log_analytics_workspace_linked_service" "test" { `, template) } -func testAccAzureRMLogAnalyticsWorkspaceLinkedService_linkedServiceProperties(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsWorkspaceLinkedService_template(rInt, location) +func testAccAzureRMLogAnalyticsWorkspaceLinkedService_linkedServiceProperties(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsWorkspaceLinkedService_template(data) return fmt.Sprintf(` %s resource "azurerm_log_analytics_workspace_linked_service" "test" { @@ -267,7 +249,7 @@ resource "azurerm_log_analytics_workspace_linked_service" "test" { `, template) } -func testAccAzureRMLogAnalyticsWorkspaceLinkedService_template(rInt int, location string) string { +func testAccAzureRMLogAnalyticsWorkspaceLinkedService_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -295,5 +277,5 @@ resource "azurerm_log_analytics_workspace" "test" { sku = "PerGB2018" retention_in_days = 30 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_test.go b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_test.go similarity index 79% rename from azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_test.go rename to azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_test.go index 2e58a2408473..b69a4e295058 100644 --- a/azurerm/internal/services/loganalytics/resource_arm_log_analytics_workspace_test.go +++ b/azurerm/internal/services/loganalytics/tests/resource_arm_log_analytics_workspace_test.go @@ -1,4 +1,4 @@ -package loganalytics +package tests import ( "fmt" @@ -8,10 +8,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/loganalytics" ) func TestAccAzureRmLogAnalyticsWorkspaceName_validation(t *testing.T) { @@ -47,7 +47,7 @@ func TestAccAzureRmLogAnalyticsWorkspaceName_validation(t *testing.T) { } for _, tc := range cases { - _, errors := validateAzureRmLogAnalyticsWorkspaceName(tc.Value, "azurerm_log_analytics") + _, errors := loganalytics.ValidateAzureRmLogAnalyticsWorkspaceName(tc.Value, "azurerm_log_analytics") if len(errors) != tc.ErrCount { t.Fatalf("Expected the AzureRM Log Analytics Workspace Name to trigger a validation error for '%s'", tc.Value) @@ -56,8 +56,7 @@ func TestAccAzureRmLogAnalyticsWorkspaceName_validation(t *testing.T) { } func TestAccAzureRMLogAnalyticsWorkspace_basic(t *testing.T) { - resourceName := "azurerm_log_analytics_workspace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -65,16 +64,12 @@ func TestAccAzureRMLogAnalyticsWorkspace_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsWorkspace_basic(ri, acceptance.Location()), + Config: testAccAzureRMLogAnalyticsWorkspace_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsWorkspaceExists(resourceName), + testCheckAzureRMLogAnalyticsWorkspaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -85,9 +80,7 @@ func TestAccAzureRMLogAnalyticsWorkspace_requiresImport(t *testing.T) { return } - resourceName := "azurerm_log_analytics_workspace.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -95,13 +88,13 @@ func TestAccAzureRMLogAnalyticsWorkspace_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsWorkspace_basic(ri, location), + Config: testAccAzureRMLogAnalyticsWorkspace_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsWorkspaceExists(resourceName), + testCheckAzureRMLogAnalyticsWorkspaceExists(data.ResourceName), ), }, { - Config: testAccAzureRMLogAnalyticsWorkspace_requiresImport(ri, location), + Config: testAccAzureRMLogAnalyticsWorkspace_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_log_analytics_workspace"), }, }, @@ -109,8 +102,7 @@ func TestAccAzureRMLogAnalyticsWorkspace_requiresImport(t *testing.T) { } func TestAccAzureRMLogAnalyticsWorkspace_complete(t *testing.T) { - resourceName := "azurerm_log_analytics_workspace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_log_analytics_workspace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -118,16 +110,12 @@ func TestAccAzureRMLogAnalyticsWorkspace_complete(t *testing.T) { CheckDestroy: testCheckAzureRMLogAnalyticsWorkspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogAnalyticsWorkspace_complete(ri, acceptance.Location()), + Config: testAccAzureRMLogAnalyticsWorkspace_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogAnalyticsWorkspaceExists(resourceName), + testCheckAzureRMLogAnalyticsWorkspaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -187,7 +175,7 @@ func testCheckAzureRMLogAnalyticsWorkspaceExists(resourceName string) resource.T return nil } } -func testAccAzureRMLogAnalyticsWorkspace_basic(rInt int, location string) string { +func testAccAzureRMLogAnalyticsWorkspace_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -200,11 +188,11 @@ resource "azurerm_log_analytics_workspace" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "PerGB2018" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLogAnalyticsWorkspace_requiresImport(rInt int, location string) string { - template := testAccAzureRMLogAnalyticsWorkspace_basic(rInt, location) +func testAccAzureRMLogAnalyticsWorkspace_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLogAnalyticsWorkspace_basic(data) return fmt.Sprintf(` %s @@ -217,7 +205,7 @@ resource "azurerm_log_analytics_workspace" "import" { `, template) } -func testAccAzureRMLogAnalyticsWorkspace_complete(rInt int, location string) string { +func testAccAzureRMLogAnalyticsWorkspace_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -235,5 +223,5 @@ resource "azurerm_log_analytics_workspace" "test" { Environment = "Test" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 04a90a97428238363ffb3ba4d3d9aa174733a6d2 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 20 Dec 2019 15:16:30 -0800 Subject: [PATCH 097/203] logic: switching to the new structure --- ...e_arm_logic_app_trigger_recurrence_test.go | 262 ------------------ .../data_source_logic_app_workflow_test.go | 40 ++- .../logic/{ => tests}/logic_apps_test.go | 2 +- ...source_arm_logic_app_action_custom_test.go | 43 ++- ...resource_arm_logic_app_action_http_test.go | 78 +++--- ...ource_arm_logic_app_trigger_custom_test.go | 43 ++- ...arm_logic_app_trigger_http_request_test.go | 122 ++++---- ...e_arm_logic_app_trigger_recurrence_test.go | 229 +++++++++++++++ .../resource_arm_logic_app_workflow_test.go | 80 +++--- 9 files changed, 399 insertions(+), 500 deletions(-) delete mode 100644 azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence_test.go rename azurerm/internal/services/logic/{ => tests}/data_source_logic_app_workflow_test.go (51%) rename azurerm/internal/services/logic/{ => tests}/logic_apps_test.go (99%) rename azurerm/internal/services/logic/{ => tests}/resource_arm_logic_app_action_custom_test.go (68%) rename azurerm/internal/services/logic/{ => tests}/resource_arm_logic_app_action_http_test.go (63%) rename azurerm/internal/services/logic/{ => tests}/resource_arm_logic_app_trigger_custom_test.go (65%) rename azurerm/internal/services/logic/{ => tests}/resource_arm_logic_app_trigger_http_request_test.go (59%) create mode 100644 azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_recurrence_test.go rename azurerm/internal/services/logic/{ => tests}/resource_arm_logic_app_workflow_test.go (67%) diff --git a/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence_test.go b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence_test.go deleted file mode 100644 index dcd908dfa151..000000000000 --- a/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence_test.go +++ /dev/null @@ -1,262 +0,0 @@ -package logic - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" -) - -func TestAccAzureRMLogicAppTriggerRecurrence_month(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_recurrence.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogicAppTriggerRecurrence_basic(ri, location, "Month", 1), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "frequency", "Month"), - resource.TestCheckResourceAttr(resourceName, "interval", "1"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMLogicAppTriggerRecurrence_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - resourceName := "azurerm_logic_app_trigger_recurrence.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogicAppTriggerRecurrence_basic(ri, location, "Month", 1), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "frequency", "Month"), - resource.TestCheckResourceAttr(resourceName, "interval", "1"), - ), - }, - { - Config: testAccAzureRMLogicAppTriggerRecurrence_requiresImport(ri, location, "Month", 1), - ExpectError: acceptance.RequiresImportError("azurerm_logic_app_trigger_recurrence"), - }, - }, - }) -} - -func TestAccAzureRMLogicAppTriggerRecurrence_week(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_recurrence.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogicAppTriggerRecurrence_basic(ri, location, "Week", 2), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "frequency", "Week"), - resource.TestCheckResourceAttr(resourceName, "interval", "2"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMLogicAppTriggerRecurrence_day(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_recurrence.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogicAppTriggerRecurrence_basic(ri, location, "Day", 3), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "frequency", "Day"), - resource.TestCheckResourceAttr(resourceName, "interval", "3"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMLogicAppTriggerRecurrence_minute(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_recurrence.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogicAppTriggerRecurrence_basic(ri, location, "Minute", 4), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "frequency", "Minute"), - resource.TestCheckResourceAttr(resourceName, "interval", "4"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMLogicAppTriggerRecurrence_second(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_recurrence.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogicAppTriggerRecurrence_basic(ri, location, "Second", 30), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "frequency", "Second"), - resource.TestCheckResourceAttr(resourceName, "interval", "30"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMLogicAppTriggerRecurrence_hour(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_recurrence.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogicAppTriggerRecurrence_basic(ri, location, "Hour", 4), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "frequency", "Hour"), - resource.TestCheckResourceAttr(resourceName, "interval", "4"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMLogicAppTriggerRecurrence_update(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_recurrence.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMLogicAppTriggerRecurrence_basic(ri, location, "Month", 1), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "frequency", "Month"), - resource.TestCheckResourceAttr(resourceName, "interval", "1"), - ), - }, - { - Config: testAccAzureRMLogicAppTriggerRecurrence_basic(ri, location, "Month", 3), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "frequency", "Month"), - resource.TestCheckResourceAttr(resourceName, "interval", "3"), - ), - }, - }, - }) -} - -func testAccAzureRMLogicAppTriggerRecurrence_basic(rInt int, location, frequency string, interval int) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_logic_app_workflow" "test" { - name = "acctestlaw-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_logic_app_trigger_recurrence" "test" { - name = "frequency-trigger" - logic_app_id = "${azurerm_logic_app_workflow.test.id}" - frequency = "%s" - interval = %d -} -`, rInt, location, rInt, frequency, interval) -} - -func testAccAzureRMLogicAppTriggerRecurrence_requiresImport(rInt int, location string, frequency string, interval int) string { - template := testAccAzureRMLogicAppTriggerRecurrence_basic(rInt, location, frequency, interval) - return fmt.Sprintf(` -%s - -resource "azurerm_logic_app_trigger_recurrence" "import" { - name = "${azurerm_logic_app_trigger_recurrence.test.name}" - logic_app_id = "${azurerm_logic_app_trigger_recurrence.test.logic_app_id}" - frequency = "${azurerm_logic_app_trigger_recurrence.test.frequency}" - interval = "${azurerm_logic_app_trigger_recurrence.test.interval}" -} -`, template) -} diff --git a/azurerm/internal/services/logic/data_source_logic_app_workflow_test.go b/azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go similarity index 51% rename from azurerm/internal/services/logic/data_source_logic_app_workflow_test.go rename to azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go index c44e7552eeb3..eba10de600f6 100644 --- a/azurerm/internal/services/logic/data_source_logic_app_workflow_test.go +++ b/azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go @@ -1,19 +1,15 @@ -package logic +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMLogicAppWorkflow_basic(t *testing.T) { - dataSourceName := "data.azurerm_logic_app_workflow.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMLogicAppWorkflow_basic(ri, location) + data := acceptance.BuildTestData(t, "data.azurerm_logic_app_workflow", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,11 +17,11 @@ func TestAccDataSourceAzureRMLogicAppWorkflow_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMLogicAppWorkflow_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppWorkflowExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "parameters.%", "0"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + testCheckAzureRMLogicAppWorkflowExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -33,10 +29,8 @@ func TestAccDataSourceAzureRMLogicAppWorkflow_basic(t *testing.T) { } func TestAccDataSourceAzureRMLogicAppWorkflow_tags(t *testing.T) { - dataSourceName := "data.azurerm_logic_app_workflow.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMLogicAppWorkflow_tags(ri, location) + data := acceptance.BuildTestData(t, "data.azurerm_logic_app_workflow", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -44,20 +38,20 @@ func TestAccDataSourceAzureRMLogicAppWorkflow_tags(t *testing.T) { CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMLogicAppWorkflow_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppWorkflowExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "parameters.%", "0"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.Source", "AcceptanceTests"), + testCheckAzureRMLogicAppWorkflowExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Source", "AcceptanceTests"), ), }, }, }) } -func testAccDataSourceAzureRMLogicAppWorkflow_basic(rInt int, location string) string { - r := testAccAzureRMLogicAppWorkflow_empty(rInt, location) +func testAccDataSourceAzureRMLogicAppWorkflow_basic(data acceptance.TestData) string { + r := testAccAzureRMLogicAppWorkflow_empty(data) return fmt.Sprintf(` %s @@ -68,8 +62,8 @@ data "azurerm_logic_app_workflow" "test" { `, r) } -func testAccDataSourceAzureRMLogicAppWorkflow_tags(rInt int, location string) string { - r := testAccAzureRMLogicAppWorkflow_tags(rInt, location) +func testAccDataSourceAzureRMLogicAppWorkflow_tags(data acceptance.TestData) string { + r := testAccAzureRMLogicAppWorkflow_tags(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/logic/logic_apps_test.go b/azurerm/internal/services/logic/tests/logic_apps_test.go similarity index 99% rename from azurerm/internal/services/logic/logic_apps_test.go rename to azurerm/internal/services/logic/tests/logic_apps_test.go index c44ff757ee5b..194d4f26a16f 100644 --- a/azurerm/internal/services/logic/logic_apps_test.go +++ b/azurerm/internal/services/logic/tests/logic_apps_test.go @@ -1,4 +1,4 @@ -package logic +package tests import ( "fmt" diff --git a/azurerm/internal/services/logic/resource_arm_logic_app_action_custom_test.go b/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_custom_test.go similarity index 68% rename from azurerm/internal/services/logic/resource_arm_logic_app_action_custom_test.go rename to azurerm/internal/services/logic/tests/resource_arm_logic_app_action_custom_test.go index 26a3c68edd39..43069e9403c4 100644 --- a/azurerm/internal/services/logic/resource_arm_logic_app_action_custom_test.go +++ b/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_custom_test.go @@ -1,20 +1,18 @@ -package logic +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMLogicAppActionCustom_basic(t *testing.T) { - resourceName := "azurerm_logic_app_action_custom.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMLogicAppActionCustom_basic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_logic_app_action_custom", "test") + + config := testAccAzureRMLogicAppActionCustom_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -23,14 +21,10 @@ func TestAccAzureRMLogicAppActionCustom_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppActionExists(resourceName), + testCheckAzureRMLogicAppActionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -41,30 +35,29 @@ func TestAccAzureRMLogicAppActionCustom_requiresImport(t *testing.T) { return } - resourceName := "azurerm_logic_app_action_custom.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_action_custom", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppActionCustom_basic(ri, location), + Config: testAccAzureRMLogicAppActionCustom_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppActionExists(resourceName), + testCheckAzureRMLogicAppActionExists(data.ResourceName), ), }, { - Config: testAccAzureRMLogicAppActionCustom_requiresImport(ri, location), + Config: testAccAzureRMLogicAppActionCustom_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_logic_app_action_custom"), }, }, }) } -func testAccAzureRMLogicAppActionCustom_basic(rInt int, location string) string { - template := testAccAzureRMLogicAppActionCustom_template(rInt, location) +func testAccAzureRMLogicAppActionCustom_basic(data acceptance.TestData) string { + template := testAccAzureRMLogicAppActionCustom_template(data) return fmt.Sprintf(` %s @@ -89,11 +82,11 @@ resource "azurerm_logic_app_action_custom" "test" { } BODY } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLogicAppActionCustom_requiresImport(rInt int, location string) string { - template := testAccAzureRMLogicAppActionCustom_basic(rInt, location) +func testAccAzureRMLogicAppActionCustom_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLogicAppActionCustom_basic(data) return fmt.Sprintf(` %s @@ -105,7 +98,7 @@ resource "azurerm_logic_app_action_custom" "import" { `, template) } -func testAccAzureRMLogicAppActionCustom_template(rInt int, location string) string { +func testAccAzureRMLogicAppActionCustom_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -117,5 +110,5 @@ resource "azurerm_logic_app_workflow" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/logic/resource_arm_logic_app_action_http_test.go b/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_http_test.go similarity index 63% rename from azurerm/internal/services/logic/resource_arm_logic_app_action_http_test.go rename to azurerm/internal/services/logic/tests/resource_arm_logic_app_action_http_test.go index 628afe4628b1..d8cb86c0bad3 100644 --- a/azurerm/internal/services/logic/resource_arm_logic_app_action_http_test.go +++ b/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_http_test.go @@ -1,19 +1,18 @@ -package logic +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMLogicAppActionHttp_basic(t *testing.T) { - resourceName := "azurerm_logic_app_action_http.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMLogicAppActionHttp_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_logic_app_action_http", "test") + + config := testAccAzureRMLogicAppActionHttp_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -22,14 +21,10 @@ func TestAccAzureRMLogicAppActionHttp_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppActionExists(resourceName), + testCheckAzureRMLogicAppActionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -40,22 +35,21 @@ func TestAccAzureRMLogicAppActionHttp_requiresImport(t *testing.T) { return } - resourceName := "azurerm_logic_app_action_http.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_action_http", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppActionHttp_basic(ri, location), + Config: testAccAzureRMLogicAppActionHttp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppActionExists(resourceName), + testCheckAzureRMLogicAppActionExists(data.ResourceName), ), }, { - Config: testAccAzureRMLogicAppActionHttp_requiresImport(ri, location), + Config: testAccAzureRMLogicAppActionHttp_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_logic_app_action_http"), }, }, @@ -63,52 +57,48 @@ func TestAccAzureRMLogicAppActionHttp_requiresImport(t *testing.T) { } func TestAccAzureRMLogicAppActionHttp_headers(t *testing.T) { - resourceName := "azurerm_logic_app_action_http.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMLogicAppActionHttp_headers(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_logic_app_action_http", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMLogicAppActionHttp_headers(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppActionExists(resourceName), + testCheckAzureRMLogicAppActionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMLogicAppActionHttp_disappears(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_action_http", "test") + + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppActionHttp_basic(ri, location), + Config: testAccAzureRMLogicAppActionHttp_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppActionExists("azurerm_logic_app_action_http.test"), + testCheckAzureRMLogicAppActionExists(data.ResourceName), ), }, { // delete it - Config: testAccAzureRMLogicAppActionHttp_template(ri, location), + Config: testAccAzureRMLogicAppActionHttp_template(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppWorkflowExists("azurerm_logic_app_workflow.test"), + testCheckAzureRMLogicAppWorkflowExists("azurerm_logic_app_workflow"), ), }, { - Config: testAccAzureRMLogicAppActionHttp_basic(ri, location), + Config: testAccAzureRMLogicAppActionHttp_basic(data), PlanOnly: true, ExpectNonEmptyPlan: true, }, @@ -116,8 +106,8 @@ func TestAccAzureRMLogicAppActionHttp_disappears(t *testing.T) { }) } -func testAccAzureRMLogicAppActionHttp_basic(rInt int, location string) string { - template := testAccAzureRMLogicAppActionHttp_template(rInt, location) +func testAccAzureRMLogicAppActionHttp_basic(data acceptance.TestData) string { + template := testAccAzureRMLogicAppActionHttp_template(data) return fmt.Sprintf(` %s @@ -127,11 +117,11 @@ resource "azurerm_logic_app_action_http" "test" { method = "GET" uri = "http://example.com/hello" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLogicAppActionHttp_requiresImport(rInt int, location string) string { - template := testAccAzureRMLogicAppActionHttp_basic(rInt, location) +func testAccAzureRMLogicAppActionHttp_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLogicAppActionHttp_basic(data) return fmt.Sprintf(` %s @@ -144,8 +134,8 @@ resource "azurerm_logic_app_action_http" "import" { `, template) } -func testAccAzureRMLogicAppActionHttp_headers(rInt int, location string) string { - template := testAccAzureRMLogicAppActionHttp_template(rInt, location) +func testAccAzureRMLogicAppActionHttp_headers(data acceptance.TestData) string { + template := testAccAzureRMLogicAppActionHttp_template(data) return fmt.Sprintf(` %s @@ -160,10 +150,10 @@ resource "azurerm_logic_app_action_http" "test" { "Something" = "New" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLogicAppActionHttp_template(rInt int, location string) string { +func testAccAzureRMLogicAppActionHttp_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -175,5 +165,5 @@ resource "azurerm_logic_app_workflow" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/logic/resource_arm_logic_app_trigger_custom_test.go b/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_custom_test.go similarity index 65% rename from azurerm/internal/services/logic/resource_arm_logic_app_trigger_custom_test.go rename to azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_custom_test.go index a72e85e472c2..dbb9452670df 100644 --- a/azurerm/internal/services/logic/resource_arm_logic_app_trigger_custom_test.go +++ b/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_custom_test.go @@ -1,35 +1,29 @@ -package logic +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMLogicAppTriggerCustom_basic(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_custom.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_custom", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppTriggerCustom_basic(ri, location), + Config: testAccAzureRMLogicAppTriggerCustom_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -40,30 +34,29 @@ func TestAccAzureRMLogicAppTriggerCustom_requiresImport(t *testing.T) { return } - resourceName := "azurerm_logic_app_trigger_custom.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_custom", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppTriggerCustom_basic(ri, location), + Config: testAccAzureRMLogicAppTriggerCustom_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), ), }, { - Config: testAccAzureRMLogicAppTriggerCustom_requiresImport(ri, location), + Config: testAccAzureRMLogicAppTriggerCustom_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_logic_app_trigger_custom"), }, }, }) } -func testAccAzureRMLogicAppTriggerCustom_basic(rInt int, location string) string { - template := testAccAzureRMLogicAppTriggerCustom_template(rInt, location) +func testAccAzureRMLogicAppTriggerCustom_basic(data acceptance.TestData) string { + template := testAccAzureRMLogicAppTriggerCustom_template(data) return fmt.Sprintf(` %s @@ -81,11 +74,11 @@ resource "azurerm_logic_app_trigger_custom" "test" { } BODY } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLogicAppTriggerCustom_requiresImport(rInt int, location string) string { - template := testAccAzureRMLogicAppTriggerCustom_basic(rInt, location) +func testAccAzureRMLogicAppTriggerCustom_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLogicAppTriggerCustom_basic(data) return fmt.Sprintf(` %s @@ -97,7 +90,7 @@ resource "azurerm_logic_app_trigger_custom" "import" { `, template) } -func testAccAzureRMLogicAppTriggerCustom_template(rInt int, location string) string { +func testAccAzureRMLogicAppTriggerCustom_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -109,5 +102,5 @@ resource "azurerm_logic_app_workflow" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/logic/resource_arm_logic_app_trigger_http_request_test.go b/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_http_request_test.go similarity index 59% rename from azurerm/internal/services/logic/resource_arm_logic_app_trigger_http_request_test.go rename to azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_http_request_test.go index a805119dfbfc..c9f5fbdb9662 100644 --- a/azurerm/internal/services/logic/resource_arm_logic_app_trigger_http_request_test.go +++ b/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_http_request_test.go @@ -1,36 +1,30 @@ -package logic +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMLogicAppTriggerHttpRequest_basic(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_http_request.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_http_request", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppTriggerHttpRequest_basic(ri, location), + Config: testAccAzureRMLogicAppTriggerHttpRequest_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "schema", "{}"), + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "schema", "{}"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -41,22 +35,21 @@ func TestAccAzureRMLogicAppTriggerHttpRequest_requiresImport(t *testing.T) { return } - resourceName := "azurerm_logic_app_trigger_http_request.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_http_request", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppTriggerHttpRequest_basic(ri, location), + Config: testAccAzureRMLogicAppTriggerHttpRequest_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), ), }, { - Config: testAccAzureRMLogicAppTriggerHttpRequest_requiresImport(ri, location), + Config: testAccAzureRMLogicAppTriggerHttpRequest_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_logic_app_trigger_http_request"), }, }, @@ -64,104 +57,89 @@ func TestAccAzureRMLogicAppTriggerHttpRequest_requiresImport(t *testing.T) { } func TestAccAzureRMLogicAppTriggerHttpRequest_fullSchema(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_http_request.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_http_request", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppTriggerHttpRequest_fullSchema(ri, location), + Config: testAccAzureRMLogicAppTriggerHttpRequest_fullSchema(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "schema"), + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "schema"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMLogicAppTriggerHttpRequest_method(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_http_request.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_http_request", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppTriggerHttpRequest_method(ri, location), + Config: testAccAzureRMLogicAppTriggerHttpRequest_method(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "method", "PUT"), + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "method", "PUT"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMLogicAppTriggerHttpRequest_relativePath(t *testing.T) { - resourceName := "azurerm_logic_app_trigger_http_request.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_http_request", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppTriggerHttpRequest_relativePath(ri, location), + Config: testAccAzureRMLogicAppTriggerHttpRequest_relativePath(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "method", "POST"), - resource.TestCheckResourceAttr(resourceName, "relative_path", "customers/{id}"), + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "method", "POST"), + resource.TestCheckResourceAttr(data.ResourceName, "relative_path", "customers/{id}"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMLogicAppTriggerHttpRequest_disappears(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_http_request", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppTriggerHttpRequest_basic(ri, location), + Config: testAccAzureRMLogicAppTriggerHttpRequest_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppTriggerExists("azurerm_logic_app_trigger_http_request.test"), + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), ), }, { // delete it - Config: testAccAzureRMLogicAppTriggerHttpRequest_template(ri, location), + Config: testAccAzureRMLogicAppTriggerHttpRequest_template(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppWorkflowExists("azurerm_logic_app_workflow.test"), + testCheckAzureRMLogicAppWorkflowExists("azurerm_logic_app_workflow"), ), }, { - Config: testAccAzureRMLogicAppTriggerHttpRequest_basic(ri, location), + Config: testAccAzureRMLogicAppTriggerHttpRequest_basic(data), PlanOnly: true, ExpectNonEmptyPlan: true, }, @@ -169,8 +147,8 @@ func TestAccAzureRMLogicAppTriggerHttpRequest_disappears(t *testing.T) { }) } -func testAccAzureRMLogicAppTriggerHttpRequest_basic(rInt int, location string) string { - template := testAccAzureRMLogicAppTriggerHttpRequest_template(rInt, location) +func testAccAzureRMLogicAppTriggerHttpRequest_basic(data acceptance.TestData) string { + template := testAccAzureRMLogicAppTriggerHttpRequest_template(data) return fmt.Sprintf(` %s @@ -182,8 +160,8 @@ resource "azurerm_logic_app_trigger_http_request" "test" { `, template) } -func testAccAzureRMLogicAppTriggerHttpRequest_requiresImport(rInt int, location string) string { - template := testAccAzureRMLogicAppTriggerHttpRequest_basic(rInt, location) +func testAccAzureRMLogicAppTriggerHttpRequest_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLogicAppTriggerHttpRequest_basic(data) return fmt.Sprintf(` %s @@ -195,8 +173,8 @@ resource "azurerm_logic_app_trigger_http_request" "import" { `, template) } -func testAccAzureRMLogicAppTriggerHttpRequest_fullSchema(rInt int, location string) string { - template := testAccAzureRMLogicAppTriggerHttpRequest_template(rInt, location) +func testAccAzureRMLogicAppTriggerHttpRequest_fullSchema(data acceptance.TestData) string { + template := testAccAzureRMLogicAppTriggerHttpRequest_template(data) return fmt.Sprintf(` %s @@ -218,8 +196,8 @@ SCHEMA `, template) } -func testAccAzureRMLogicAppTriggerHttpRequest_method(rInt int, location string) string { - template := testAccAzureRMLogicAppTriggerHttpRequest_template(rInt, location) +func testAccAzureRMLogicAppTriggerHttpRequest_method(data acceptance.TestData) string { + template := testAccAzureRMLogicAppTriggerHttpRequest_template(data) return fmt.Sprintf(` %s @@ -232,8 +210,8 @@ resource "azurerm_logic_app_trigger_http_request" "test" { `, template) } -func testAccAzureRMLogicAppTriggerHttpRequest_relativePath(rInt int, location string) string { - template := testAccAzureRMLogicAppTriggerHttpRequest_template(rInt, location) +func testAccAzureRMLogicAppTriggerHttpRequest_relativePath(data acceptance.TestData) string { + template := testAccAzureRMLogicAppTriggerHttpRequest_template(data) return fmt.Sprintf(` %s @@ -247,7 +225,7 @@ resource "azurerm_logic_app_trigger_http_request" "test" { `, template) } -func testAccAzureRMLogicAppTriggerHttpRequest_template(rInt int, location string) string { +func testAccAzureRMLogicAppTriggerHttpRequest_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -259,5 +237,5 @@ resource "azurerm_logic_app_workflow" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_recurrence_test.go b/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_recurrence_test.go new file mode 100644 index 000000000000..249124e6e372 --- /dev/null +++ b/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_recurrence_test.go @@ -0,0 +1,229 @@ +package tests + +import ( + "fmt" + "testing" + + "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/features" +) + +func TestAccAzureRMLogicAppTriggerRecurrence_month(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_recurrence", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogicAppTriggerRecurrence_basic(data, "Month", 1), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "Month"), + resource.TestCheckResourceAttr(data.ResourceName, "interval", "1"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMLogicAppTriggerRecurrence_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_recurrence", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogicAppTriggerRecurrence_basic(data, "Month", 1), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "Month"), + resource.TestCheckResourceAttr(data.ResourceName, "interval", "1"), + ), + }, + { + Config: testAccAzureRMLogicAppTriggerRecurrence_requiresImport(data, "Month", 1), + ExpectError: acceptance.RequiresImportError("azurerm_logic_app_trigger_recurrence"), + }, + }, + }) +} + +func TestAccAzureRMLogicAppTriggerRecurrence_week(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_recurrence", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogicAppTriggerRecurrence_basic(data, "Week", 2), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "Week"), + resource.TestCheckResourceAttr(data.ResourceName, "interval", "2"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMLogicAppTriggerRecurrence_day(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_recurrence", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogicAppTriggerRecurrence_basic(data, "Day", 3), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "Day"), + resource.TestCheckResourceAttr(data.ResourceName, "interval", "3"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMLogicAppTriggerRecurrence_minute(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_recurrence", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogicAppTriggerRecurrence_basic(data, "Minute", 4), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "Minute"), + resource.TestCheckResourceAttr(data.ResourceName, "interval", "4"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMLogicAppTriggerRecurrence_second(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_recurrence", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogicAppTriggerRecurrence_basic(data, "Second", 30), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "Second"), + resource.TestCheckResourceAttr(data.ResourceName, "interval", "30"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMLogicAppTriggerRecurrence_hour(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_recurrence", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogicAppTriggerRecurrence_basic(data, "Hour", 4), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "Hour"), + resource.TestCheckResourceAttr(data.ResourceName, "interval", "4"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMLogicAppTriggerRecurrence_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_recurrence", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogicAppTriggerRecurrence_basic(data, "Month", 1), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "Month"), + resource.TestCheckResourceAttr(data.ResourceName, "interval", "1"), + ), + }, + { + Config: testAccAzureRMLogicAppTriggerRecurrence_basic(data, "Month", 3), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "Month"), + resource.TestCheckResourceAttr(data.ResourceName, "interval", "3"), + ), + }, + }, + }) +} + +func testAccAzureRMLogicAppTriggerRecurrence_basic(data acceptance.TestData, frequency string, interval int) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_logic_app_workflow" "test" { + name = "acctestlaw-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_logic_app_trigger_recurrence" "test" { + name = "frequency-trigger" + logic_app_id = "${azurerm_logic_app_workflow.test.id}" + frequency = "%s" + interval = %d +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, frequency, interval) +} + +func testAccAzureRMLogicAppTriggerRecurrence_requiresImport(data acceptance.TestData, frequency string, interval int) string { + template := testAccAzureRMLogicAppTriggerRecurrence_basic(data, frequency, interval) + return fmt.Sprintf(` +%s + +resource "azurerm_logic_app_trigger_recurrence" "import" { + name = "${azurerm_logic_app_trigger_recurrence.test.name}" + logic_app_id = "${azurerm_logic_app_trigger_recurrence.test.logic_app_id}" + frequency = "${azurerm_logic_app_trigger_recurrence.test.frequency}" + interval = "${azurerm_logic_app_trigger_recurrence.test.interval}" +} +`, template) +} diff --git a/azurerm/internal/services/logic/resource_arm_logic_app_workflow_test.go b/azurerm/internal/services/logic/tests/resource_arm_logic_app_workflow_test.go similarity index 67% rename from azurerm/internal/services/logic/resource_arm_logic_app_workflow_test.go rename to azurerm/internal/services/logic/tests/resource_arm_logic_app_workflow_test.go index 0efce3d4385d..fd67dfaad624 100644 --- a/azurerm/internal/services/logic/resource_arm_logic_app_workflow_test.go +++ b/azurerm/internal/services/logic/tests/resource_arm_logic_app_workflow_test.go @@ -1,4 +1,4 @@ -package logic +package tests import ( "fmt" @@ -7,34 +7,28 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMLogicAppWorkflow_empty(t *testing.T) { - resourceName := "azurerm_logic_app_workflow.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMLogicAppWorkflow_empty(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_logic_app_workflow", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMLogicAppWorkflow_empty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppWorkflowExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "0"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMLogicAppWorkflowExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,22 +39,21 @@ func TestAccAzureRMLogicAppWorkflow_requiresImport(t *testing.T) { return } - resourceName := "azurerm_logic_app_workflow.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_workflow", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppWorkflow_empty(ri, location), + Config: testAccAzureRMLogicAppWorkflow_empty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppWorkflowExists(resourceName), + testCheckAzureRMLogicAppWorkflowExists(data.ResourceName), ), }, { - Config: testAccAzureRMLogicAppWorkflow_requiresImport(ri, location), + Config: testAccAzureRMLogicAppWorkflow_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_logic_app_workflow"), }, }, @@ -68,41 +61,32 @@ func TestAccAzureRMLogicAppWorkflow_requiresImport(t *testing.T) { } func TestAccAzureRMLogicAppWorkflow_tags(t *testing.T) { - resourceName := "azurerm_logic_app_workflow.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_logic_app_workflow", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLogicAppWorkflow_empty(ri, location), + Config: testAccAzureRMLogicAppWorkflow_empty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppWorkflowExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "0"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMLogicAppWorkflowExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMLogicAppWorkflow_tags(ri, location), + Config: testAccAzureRMLogicAppWorkflow_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLogicAppWorkflowExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "0"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Source", "AcceptanceTests"), + testCheckAzureRMLogicAppWorkflowExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Source", "AcceptanceTests"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -162,7 +146,7 @@ func testCheckAzureRMLogicAppWorkflowDestroy(s *terraform.State) error { return nil } -func testAccAzureRMLogicAppWorkflow_empty(rInt int, location string) string { +func testAccAzureRMLogicAppWorkflow_empty(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -174,11 +158,11 @@ resource "azurerm_logic_app_workflow" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLogicAppWorkflow_requiresImport(rInt int, location string) string { - template := testAccAzureRMLogicAppWorkflow_empty(rInt, location) +func testAccAzureRMLogicAppWorkflow_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLogicAppWorkflow_empty(data) return fmt.Sprintf(` %s @@ -190,7 +174,7 @@ resource "azurerm_logic_app_workflow" "import" { `, template) } -func testAccAzureRMLogicAppWorkflow_tags(rInt int, location string) string { +func testAccAzureRMLogicAppWorkflow_tags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -206,5 +190,5 @@ resource "azurerm_logic_app_workflow" "test" { "Source" = "AcceptanceTests" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 72edf7c08dcac8ac55667e86447f11f7cd68e133 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 20 Dec 2019 17:24:09 -0800 Subject: [PATCH 098/203] compute: switching to the new structure --- ...a_source_proximity_placement_group_test.go | 44 - .../services/compute/resource_arm_snapshot.go | 4 +- .../data_source_availability_set_test.go | 21 +- .../{ => tests}/data_source_image_test.go | 57 +- .../data_source_managed_disk_test.go | 54 +- .../data_source_platform_image_test.go | 19 +- ...a_source_proximity_placement_group_test.go | 41 + .../data_source_shared_image_gallery_test.go | 33 +- .../data_source_shared_image_version_test.go | 29 +- .../{ => tests}/data_source_snapshot_test.go | 33 +- .../resource_arm_availability_set_test.go | 150 ++-- .../{ => tests}/resource_arm_image_test.go | 163 ++-- ...nux_virtual_machine_scale_set_auth_test.go | 204 ++--- ...irtual_machine_scale_set_disk_data_test.go | 413 +++------ ..._virtual_machine_scale_set_disk_os_test.go | 259 ++---- ...virtual_machine_scale_set_identity_test.go | 257 ++---- ...x_virtual_machine_scale_set_images_test.go | 285 +++--- ..._virtual_machine_scale_set_network_test.go | 801 ++++++----------- ...ux_virtual_machine_scale_set_other_test.go | 545 ++++-------- ..._virtual_machine_scale_set_scaling_test.go | 405 +++------ ...rm_linux_virtual_machine_scale_set_test.go | 6 +- .../resource_arm_managed_disk_test.go | 230 +++-- ...resource_arm_marketplace_agreement_test.go | 20 +- ...urce_arm_proximity_placement_group_test.go | 79 +- .../resource_arm_shared_image_gallery_test.go | 63 +- .../resource_arm_shared_image_version_test.go | 129 ++- .../{ => tests}/resource_arm_snapshot_test.go | 108 +-- ...rtual_machine_data_disk_attachment_test.go | 182 ++-- ...urce_arm_virtual_machine_extension_test.go | 71 +- ..._arm_virtual_machine_managed_disks_test.go | 349 ++++---- ...irtual_machine_scale_set_extension_test.go | 212 ++--- ...urce_arm_virtual_machine_scale_set_test.go | 827 +++++++----------- .../resource_arm_virtual_machine_test.go | 90 +- ...rm_virtual_machine_unmanaged_disks_test.go | 359 ++++---- ...ows_virtual_machine_scale_set_auth_test.go | 29 +- ...irtual_machine_scale_set_disk_data_test.go | 401 +++------ ..._virtual_machine_scale_set_disk_os_test.go | 249 ++---- ...virtual_machine_scale_set_identity_test.go | 255 ++---- ...s_virtual_machine_scale_set_images_test.go | 281 +++--- ..._virtual_machine_scale_set_network_test.go | 777 ++++++---------- ...ws_virtual_machine_scale_set_other_test.go | 691 +++++---------- ..._virtual_machine_scale_set_scaling_test.go | 385 +++----- ..._windows_virtual_machine_scale_set_test.go | 12 +- .../data_source_logic_app_workflow_test.go | 1 - ...resource_arm_logic_app_action_http_test.go | 1 - 45 files changed, 3647 insertions(+), 5977 deletions(-) delete mode 100644 azurerm/internal/services/compute/data_source_proximity_placement_group_test.go rename azurerm/internal/services/compute/{ => tests}/data_source_availability_set_test.go (60%) rename azurerm/internal/services/compute/{ => tests}/data_source_image_test.go (81%) rename azurerm/internal/services/compute/{ => tests}/data_source_managed_disk_test.go (54%) rename azurerm/internal/services/compute/{ => tests}/data_source_platform_image_test.go (53%) create mode 100644 azurerm/internal/services/compute/tests/data_source_proximity_placement_group_test.go rename azurerm/internal/services/compute/{ => tests}/data_source_shared_image_gallery_test.go (54%) rename azurerm/internal/services/compute/{ => tests}/data_source_shared_image_version_test.go (53%) rename azurerm/internal/services/compute/{ => tests}/data_source_snapshot_test.go (78%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_availability_set_test.go (67%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_image_test.go (86%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_linux_virtual_machine_scale_set_auth_test.go (66%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go (62%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go (62%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_linux_virtual_machine_scale_set_identity_test.go (60%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_linux_virtual_machine_scale_set_images_test.go (75%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_linux_virtual_machine_scale_set_network_test.go (72%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_linux_virtual_machine_scale_set_other_test.go (70%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_linux_virtual_machine_scale_set_scaling_test.go (69%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_linux_virtual_machine_scale_set_test.go (95%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_managed_disk_test.go (71%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_marketplace_agreement_test.go (89%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_proximity_placement_group_test.go (73%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_shared_image_gallery_test.go (72%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_shared_image_version_test.go (67%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_snapshot_test.go (83%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_virtual_machine_data_disk_attachment_test.go (81%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_virtual_machine_extension_test.go (87%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_virtual_machine_managed_disks_test.go (85%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_virtual_machine_scale_set_extension_test.go (78%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_virtual_machine_scale_set_test.go (87%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_virtual_machine_test.go (85%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_virtual_machine_unmanaged_disks_test.go (87%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_windows_virtual_machine_scale_set_auth_test.go (69%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go (62%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go (62%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_windows_virtual_machine_scale_set_identity_test.go (59%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_windows_virtual_machine_scale_set_images_test.go (74%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_windows_virtual_machine_scale_set_network_test.go (72%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_windows_virtual_machine_scale_set_other_test.go (71%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_windows_virtual_machine_scale_set_scaling_test.go (69%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_windows_virtual_machine_scale_set_test.go (86%) diff --git a/azurerm/internal/services/compute/data_source_proximity_placement_group_test.go b/azurerm/internal/services/compute/data_source_proximity_placement_group_test.go deleted file mode 100644 index eb94cac9a32a..000000000000 --- a/azurerm/internal/services/compute/data_source_proximity_placement_group_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package compute - -import ( - "fmt" - "testing" - - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" -) - -func TestAccProximityPlacementGroupDataSource_basic(t *testing.T) { - dataSourceName := "data.azurerm_proximity_placement_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccProximityPlacementGroupDataSource_basic(ri, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "2"), - ), - }, - }, - }) -} - -func testAccProximityPlacementGroupDataSource_basic(rInt int, location string) string { - return fmt.Sprintf(` -%s - -data "azurerm_proximity_placement_group" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_proximity_placement_group.test.name}" -} -`, testAccProximityPlacementGroup_withTags(rInt, location)) -} diff --git a/azurerm/internal/services/compute/resource_arm_snapshot.go b/azurerm/internal/services/compute/resource_arm_snapshot.go index f7cf2d0291d2..de7489b40c7f 100644 --- a/azurerm/internal/services/compute/resource_arm_snapshot.go +++ b/azurerm/internal/services/compute/resource_arm_snapshot.go @@ -41,7 +41,7 @@ func resourceArmSnapshot() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateSnapshotName, + ValidateFunc: ValidateSnapshotName, }, "location": azure.SchemaLocation(), @@ -241,7 +241,7 @@ func resourceArmSnapshotDelete(d *schema.ResourceData, meta interface{}) error { return nil } -func validateSnapshotName(v interface{}, _ string) (warnings []string, errors []error) { +func ValidateSnapshotName(v interface{}, _ string) (warnings []string, errors []error) { // a-z, A-Z, 0-9, _ and -. The max name length is 80 value := v.(string) diff --git a/azurerm/internal/services/compute/data_source_availability_set_test.go b/azurerm/internal/services/compute/tests/data_source_availability_set_test.go similarity index 60% rename from azurerm/internal/services/compute/data_source_availability_set_test.go rename to azurerm/internal/services/compute/tests/data_source_availability_set_test.go index 2e35be08c95c..d980c8a595a6 100644 --- a/azurerm/internal/services/compute/data_source_availability_set_test.go +++ b/azurerm/internal/services/compute/tests/data_source_availability_set_test.go @@ -1,38 +1,35 @@ -package compute +package tests import ( "fmt" "testing" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccDataSourceAvailabilitySet_basic(t *testing.T) { - dataSourceName := "data.azurerm_availability_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_availability_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAvailabilitySet_basic(ri, location), + Config: testAccDataSourceAvailabilitySet_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, }, }) } -func testAccDataSourceAvailabilitySet_basic(rInt int, location string) string { +func testAccDataSourceAvailabilitySet_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -53,5 +50,5 @@ data "azurerm_availability_set" "test" { resource_group_name = "${azurerm_resource_group.test.name}" name = "${azurerm_availability_set.test.name}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/compute/data_source_image_test.go b/azurerm/internal/services/compute/tests/data_source_image_test.go similarity index 81% rename from azurerm/internal/services/compute/data_source_image_test.go rename to azurerm/internal/services/compute/tests/data_source_image_test.go index a3f2e3eae26f..92d8c72df277 100644 --- a/azurerm/internal/services/compute/data_source_image_test.go +++ b/azurerm/internal/services/compute/tests/data_source_image_test.go @@ -1,39 +1,35 @@ -package compute +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMImage_basic(t *testing.T) { - dataSourceName := "data.azurerm_image.test" - - config := testAccDataSourceAzureRMImageBasic(tf.AccRandTimeInt(), acctest.RandString(4), acceptance.Location()) + data := acceptance.BuildTestData(t, "data.azurerm_image", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMImageBasic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "os_disk.#", "1"), - resource.TestCheckResourceAttrSet(dataSourceName, "os_disk.0.blob_uri"), - resource.TestCheckResourceAttr(dataSourceName, "os_disk.0.caching", "None"), - resource.TestCheckResourceAttr(dataSourceName, "os_disk.0.os_type", "Linux"), - resource.TestCheckResourceAttr(dataSourceName, "os_disk.0.os_state", "Generalized"), - resource.TestCheckResourceAttr(dataSourceName, "os_disk.0.size_gb", "30"), - resource.TestCheckResourceAttr(dataSourceName, "data_disk.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "Dev"), - resource.TestCheckResourceAttr(dataSourceName, "tags.cost-center", "Ops"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "os_disk.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "os_disk.0.blob_uri"), + resource.TestCheckResourceAttr(data.ResourceName, "os_disk.0.caching", "None"), + resource.TestCheckResourceAttr(data.ResourceName, "os_disk.0.os_type", "Linux"), + resource.TestCheckResourceAttr(data.ResourceName, "os_disk.0.os_state", "Generalized"), + resource.TestCheckResourceAttr(data.ResourceName, "os_disk.0.size_gb", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "data_disk.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Dev"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost-center", "Ops"), ), }, }, @@ -41,33 +37,30 @@ func TestAccDataSourceAzureRMImage_basic(t *testing.T) { } func TestAccDataSourceAzureRMImage_localFilter(t *testing.T) { - ascDataSourceName := "data.azurerm_image.test1" + data := acceptance.BuildTestData(t, "data.azurerm_image", "test") descDataSourceName := "data.azurerm_image.test2" - ri := tf.AccRandTimeInt() - config := testAccDataSourceAzureRMImageLocalFilter(ri, acctest.RandString(4), acceptance.Location()) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMImageLocalFilter(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(ascDataSourceName, "name"), - resource.TestCheckResourceAttrSet(ascDataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(ascDataSourceName, "name", fmt.Sprintf("def-acctest-%d", ri)), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("def-acctest-%d", data.RandomInteger)), resource.TestCheckResourceAttrSet(descDataSourceName, "name"), resource.TestCheckResourceAttrSet(descDataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(descDataSourceName, "name", fmt.Sprintf("def-acctest-%d", ri)), + resource.TestCheckResourceAttr(descDataSourceName, "name", fmt.Sprintf("def-acctest-%d", data.RandomInteger)), ), }, }, }) } -func testAccDataSourceAzureRMImageBasic(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMImageBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -193,10 +186,10 @@ data "azurerm_image" "test" { output "location" { value = "${data.azurerm_image.test.location}" } -`, rInt, location, rInt, rInt, rInt, rInt, rString, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccDataSourceAzureRMImageLocalFilter(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMImageLocalFilter(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -347,5 +340,5 @@ data "azurerm_image" "test2" { output "location" { value = "${data.azurerm_image.test1.location}" } -`, rInt, location, rInt, rInt, rInt, rInt, rString, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/data_source_managed_disk_test.go b/azurerm/internal/services/compute/tests/data_source_managed_disk_test.go similarity index 54% rename from azurerm/internal/services/compute/data_source_managed_disk_test.go rename to azurerm/internal/services/compute/tests/data_source_managed_disk_test.go index cafd141e878d..45474cdd397f 100644 --- a/azurerm/internal/services/compute/data_source_managed_disk_test.go +++ b/azurerm/internal/services/compute/tests/data_source_managed_disk_test.go @@ -1,38 +1,34 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMManagedDisk_basic(t *testing.T) { - dataSourceName := "data.azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_managed_disk", "test") - name := fmt.Sprintf("acctestmanageddisk-%d", ri) - resourceGroupName := fmt.Sprintf("acctestRG-%d", ri) - - config := testAccDataSourceAzureRMManagedDiskBasic(name, resourceGroupName, acceptance.Location()) + name := fmt.Sprintf("acctestmanageddisk-%d", data.RandomInteger) + resourceGroupName := fmt.Sprintf("acctestRG-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMManagedDiskBasic(data, name, resourceGroupName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", name), - resource.TestCheckResourceAttr(dataSourceName, "resource_group_name", resourceGroupName), - resource.TestCheckResourceAttr(dataSourceName, "storage_account_type", "Premium_LRS"), - resource.TestCheckResourceAttr(dataSourceName, "disk_size_gb", "10"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "acctest"), - resource.TestCheckResourceAttr(dataSourceName, "zones.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "zones.0", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "name", name), + resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_account_type", "Premium_LRS"), + resource.TestCheckResourceAttr(data.ResourceName, "disk_size_gb", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "acctest"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.0", "2"), ), }, }, @@ -40,31 +36,27 @@ func TestAccDataSourceAzureRMManagedDisk_basic(t *testing.T) { } func TestAccDataSourceAzureRMManagedDisk_basic_withUltraSSD(t *testing.T) { - dataSourceName := "data.azurerm_managed_disk.test" - location := "eastus2" - ri := tf.AccRandTimeInt() - - name := fmt.Sprintf("acctestmanageddisk-%d", ri) - resourceGroupName := fmt.Sprintf("acctestRG-%d", ri) + data := acceptance.BuildTestData(t, "data.azurerm_managed_disk", "test") - config := testAccDataSourceAzureRMManagedDisk_basic_withUltraSSD(name, resourceGroupName, location) + name := fmt.Sprintf("acctestmanageddisk-%d", data.RandomInteger) + resourceGroupName := fmt.Sprintf("acctestRG-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMManagedDisk_basic_withUltraSSD(data, name, resourceGroupName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "disk_iops_read_write", "101"), - resource.TestCheckResourceAttr(dataSourceName, "disk_mbps_read_write", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "disk_iops_read_write", "101"), + resource.TestCheckResourceAttr(data.ResourceName, "disk_mbps_read_write", "10"), ), }, }, }) } -func testAccDataSourceAzureRMManagedDiskBasic(name string, resourceGroupName string, location string) string { +func testAccDataSourceAzureRMManagedDiskBasic(data acceptance.TestData, name string, resourceGroupName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "%s" @@ -89,10 +81,10 @@ data "azurerm_managed_disk" "test" { name = "${azurerm_managed_disk.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, resourceGroupName, location, name) +`, resourceGroupName, data.Locations.Primary, name) } -func testAccDataSourceAzureRMManagedDisk_basic_withUltraSSD(name string, resourceGroupName string, location string) string { +func testAccDataSourceAzureRMManagedDisk_basic_withUltraSSD(data acceptance.TestData, name string, resourceGroupName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "%s" @@ -119,5 +111,5 @@ data "azurerm_managed_disk" "test" { name = "${azurerm_managed_disk.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, resourceGroupName, location, name) +`, resourceGroupName, data.Locations.Primary, name) } diff --git a/azurerm/internal/services/compute/data_source_platform_image_test.go b/azurerm/internal/services/compute/tests/data_source_platform_image_test.go similarity index 53% rename from azurerm/internal/services/compute/data_source_platform_image_test.go rename to azurerm/internal/services/compute/tests/data_source_platform_image_test.go index 84f4878088cc..4985a8ac7563 100644 --- a/azurerm/internal/services/compute/data_source_platform_image_test.go +++ b/azurerm/internal/services/compute/tests/data_source_platform_image_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -9,27 +9,26 @@ import ( ) func TestAccDataSourceAzureRMPlatformImage_basic(t *testing.T) { - dataSourceName := "data.azurerm_platform_image.test" - config := testAccDataSourceAzureRMPlatformImageBasic(acceptance.Location()) + data := acceptance.BuildTestData(t, "data.azurerm_platform_image", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMPlatformImageBasic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "version"), - resource.TestCheckResourceAttr(dataSourceName, "publisher", "Canonical"), - resource.TestCheckResourceAttr(dataSourceName, "offer", "UbuntuServer"), - resource.TestCheckResourceAttr(dataSourceName, "sku", "16.04-LTS"), + resource.TestCheckResourceAttrSet(data.ResourceName, "version"), + resource.TestCheckResourceAttr(data.ResourceName, "publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "offer", "UbuntuServer"), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "16.04-LTS"), ), }, }, }) } -func testAccDataSourceAzureRMPlatformImageBasic(location string) string { +func testAccDataSourceAzureRMPlatformImageBasic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_platform_image" "test" { location = "%s" @@ -37,5 +36,5 @@ data "azurerm_platform_image" "test" { offer = "UbuntuServer" sku = "16.04-LTS" } -`, location) +`, data.Locations.Primary) } diff --git a/azurerm/internal/services/compute/tests/data_source_proximity_placement_group_test.go b/azurerm/internal/services/compute/tests/data_source_proximity_placement_group_test.go new file mode 100644 index 000000000000..4b0e20fdc795 --- /dev/null +++ b/azurerm/internal/services/compute/tests/data_source_proximity_placement_group_test.go @@ -0,0 +1,41 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccProximityPlacementGroupDataSource_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_proximity_placement_group", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccProximityPlacementGroupDataSource_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + ), + }, + }, + }) +} + +func testAccProximityPlacementGroupDataSource_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_proximity_placement_group" "test" { + resource_group_name = "${azurerm_resource_group.test.name}" + name = "${azurerm_proximity_placement_group.test.name}" +} +`, testAccProximityPlacementGroup_withTags(data)) +} diff --git a/azurerm/internal/services/compute/data_source_shared_image_gallery_test.go b/azurerm/internal/services/compute/tests/data_source_shared_image_gallery_test.go similarity index 54% rename from azurerm/internal/services/compute/data_source_shared_image_gallery_test.go rename to azurerm/internal/services/compute/tests/data_source_shared_image_gallery_test.go index f9e54b988e14..445bde7db845 100644 --- a/azurerm/internal/services/compute/data_source_shared_image_gallery_test.go +++ b/azurerm/internal/services/compute/tests/data_source_shared_image_gallery_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMSharedImageGallery_basic(t *testing.T) { - dataSourceName := "data.azurerm_shared_image_gallery.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_shared_image_gallery", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,9 +17,9 @@ func TestAccDataSourceAzureRMSharedImageGallery_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSharedImageGalleryDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceSharedImageGallery_basic(rInt, location), + Config: testAccDataSourceSharedImageGallery_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -30,9 +27,7 @@ func TestAccDataSourceAzureRMSharedImageGallery_basic(t *testing.T) { } func TestAccDataSourceAzureRMSharedImageGallery_complete(t *testing.T) { - dataSourceName := "data.azurerm_shared_image_gallery.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_shared_image_gallery", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -40,20 +35,20 @@ func TestAccDataSourceAzureRMSharedImageGallery_complete(t *testing.T) { CheckDestroy: testCheckAzureRMSharedImageGalleryDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceSharedImageGallery_complete(rInt, location), + Config: testAccDataSourceSharedImageGallery_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "description", "Shared images and things."), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(dataSourceName, "tags.Hello", "There"), - resource.TestCheckResourceAttr(dataSourceName, "tags.World", "Example"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "Shared images and things."), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "There"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.World", "Example"), ), }, }, }) } -func testAccDataSourceSharedImageGallery_basic(rInt int, location string) string { - template := testAccAzureRMSharedImageGallery_basic(rInt, location) +func testAccDataSourceSharedImageGallery_basic(data acceptance.TestData) string { + template := testAccAzureRMSharedImageGallery_basic(data) return fmt.Sprintf(` %s @@ -64,8 +59,8 @@ data "azurerm_shared_image_gallery" "test" { `, template) } -func testAccDataSourceSharedImageGallery_complete(rInt int, location string) string { - template := testAccAzureRMSharedImageGallery_complete(rInt, location) +func testAccDataSourceSharedImageGallery_complete(data acceptance.TestData) string { + template := testAccAzureRMSharedImageGallery_complete(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/compute/data_source_shared_image_version_test.go b/azurerm/internal/services/compute/tests/data_source_shared_image_version_test.go similarity index 53% rename from azurerm/internal/services/compute/data_source_shared_image_version_test.go rename to azurerm/internal/services/compute/tests/data_source_shared_image_version_test.go index ce0212dc8998..0818fd5a9755 100644 --- a/azurerm/internal/services/compute/data_source_shared_image_version_test.go +++ b/azurerm/internal/services/compute/tests/data_source_shared_image_version_test.go @@ -1,22 +1,19 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMSharedImageVersion_basic(t *testing.T) { - dataSourceName := "data.azurerm_shared_image_version.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_shared_image_version", "test") username := "testadmin" password := "Password1234!" - hostname := fmt.Sprintf("tftestcustomimagesrc%d", rInt) - resourceGroup := fmt.Sprintf("acctestRG-%d", rInt) + hostname := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,28 +22,28 @@ func TestAccDataSourceAzureRMSharedImageVersion_basic(t *testing.T) { Steps: []resource.TestStep{ { // need to create a vm and then reference it in the image creation - Config: testAccAzureRMSharedImageVersion_setup(rInt, location, username, password, hostname), + Config: testAccAzureRMSharedImageVersion_setup(data, username, password, hostname), Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", username, password, hostname, "22", location), + testGeneralizeVMImage(resourceGroup, "testsource", username, password, hostname, "22", data.Locations.Primary), ), }, { - Config: testAccDataSourceSharedImageVersion_basic(rInt, location, username, password, hostname), + Config: testAccDataSourceSharedImageVersion_basic(data, username, password, hostname), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - resource.TestCheckResourceAttrSet(dataSourceName, "managed_image_id"), - resource.TestCheckResourceAttr(dataSourceName, "target_region.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "target_region.0.storage_account_type", "Standard_LRS"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_image_id"), + resource.TestCheckResourceAttr(data.ResourceName, "target_region.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "target_region.0.storage_account_type", "Standard_LRS"), ), }, }, }) } -func testAccDataSourceSharedImageVersion_basic(rInt int, location, username, password, hostname string) string { - template := testAccAzureRMSharedImageVersion_imageVersion(rInt, location, username, password, hostname) +func testAccDataSourceSharedImageVersion_basic(data acceptance.TestData, username, password, hostname string) string { + template := testAccAzureRMSharedImageVersion_imageVersion(data, username, password, hostname) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/compute/data_source_snapshot_test.go b/azurerm/internal/services/compute/tests/data_source_snapshot_test.go similarity index 78% rename from azurerm/internal/services/compute/data_source_snapshot_test.go rename to azurerm/internal/services/compute/tests/data_source_snapshot_test.go index 97b169392772..18eedd4b7a1e 100644 --- a/azurerm/internal/services/compute/data_source_snapshot_test.go +++ b/azurerm/internal/services/compute/tests/data_source_snapshot_test.go @@ -1,28 +1,25 @@ -package compute +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMSnapshot_basic(t *testing.T) { - dataSourceName := "data.azurerm_snapshot.snapshot" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_snapshot", "snapshot") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSnapshot_basic(ri, acceptance.Location()), + Config: testAccDataSourceAzureRMSnapshot_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), ), }, }, @@ -30,27 +27,25 @@ func TestAccDataSourceAzureRMSnapshot_basic(t *testing.T) { } func TestAccDataSourceAzureRMSnapshot_encryption(t *testing.T) { - dataSourceName := "data.azurerm_snapshot.snapshot" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "data.azurerm_snapshot", "snapshot") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSnapshot_encryption(ri, rs, acceptance.Location()), + Config: testAccDataSourceAzureRMSnapshot_encryption(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "encryption_settings.0.enabled", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "encryption_settings.0.enabled", "true"), ), }, }, }) } -func testAccDataSourceAzureRMSnapshot_basic(rInt int, location string) string { +func testAccDataSourceAzureRMSnapshot_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -78,10 +73,10 @@ data "azurerm_snapshot" "snapshot" { name = "${azurerm_snapshot.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccDataSourceAzureRMSnapshot_encryption(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMSnapshot_encryption(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -178,5 +173,5 @@ data "azurerm_snapshot" "snapshot" { name = "${azurerm_snapshot.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_availability_set_test.go b/azurerm/internal/services/compute/tests/resource_arm_availability_set_test.go similarity index 67% rename from azurerm/internal/services/compute/resource_arm_availability_set_test.go rename to azurerm/internal/services/compute/tests/resource_arm_availability_set_test.go index 4a309a218325..f4bbe3b8e925 100644 --- a/azurerm/internal/services/compute/resource_arm_availability_set_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_availability_set_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,9 +15,8 @@ import ( ) func TestAccAzureRMAvailabilitySet_basic(t *testing.T) { - resourceName := "azurerm_availability_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAvailabilitySet_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_availability_set", "test") + config := testAccAzureRMAvailabilitySet_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -28,16 +26,12 @@ func TestAccAzureRMAvailabilitySet_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAvailabilitySetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "platform_update_domain_count", "5"), - resource.TestCheckResourceAttr(resourceName, "platform_fault_domain_count", "3"), + testCheckAzureRMAvailabilitySetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "platform_update_domain_count", "5"), + resource.TestCheckResourceAttr(data.ResourceName, "platform_fault_domain_count", "3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -48,9 +42,7 @@ func TestAccAzureRMAvailabilitySet_requiresImport(t *testing.T) { return } - resourceName := "azurerm_availability_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_availability_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -58,15 +50,15 @@ func TestAccAzureRMAvailabilitySet_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAvailabilitySetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAvailabilitySet_basic(ri, location), + Config: testAccAzureRMAvailabilitySet_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAvailabilitySetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "platform_update_domain_count", "5"), - resource.TestCheckResourceAttr(resourceName, "platform_fault_domain_count", "3"), + testCheckAzureRMAvailabilitySetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "platform_update_domain_count", "5"), + resource.TestCheckResourceAttr(data.ResourceName, "platform_fault_domain_count", "3"), ), }, { - Config: testAccAzureRMAvailabilitySet_requiresImport(ri, location), + Config: testAccAzureRMAvailabilitySet_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_availability_set"), }, }, @@ -74,9 +66,8 @@ func TestAccAzureRMAvailabilitySet_requiresImport(t *testing.T) { } func TestAccAzureRMAvailabilitySet_disappears(t *testing.T) { - resourceName := "azurerm_availability_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAvailabilitySet_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_availability_set", "test") + config := testAccAzureRMAvailabilitySet_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,10 +77,10 @@ func TestAccAzureRMAvailabilitySet_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAvailabilitySetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "platform_update_domain_count", "5"), - resource.TestCheckResourceAttr(resourceName, "platform_fault_domain_count", "3"), - testCheckAzureRMAvailabilitySetDisappears(resourceName), + testCheckAzureRMAvailabilitySetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "platform_update_domain_count", "5"), + resource.TestCheckResourceAttr(data.ResourceName, "platform_fault_domain_count", "3"), + testCheckAzureRMAvailabilitySetDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -98,11 +89,9 @@ func TestAccAzureRMAvailabilitySet_disappears(t *testing.T) { } func TestAccAzureRMAvailabilitySet_withTags(t *testing.T) { - resourceName := "azurerm_availability_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMAvailabilitySet_withTags(ri, location) - postConfig := testAccAzureRMAvailabilitySet_withUpdatedTags(ri, location) + data := acceptance.BuildTestData(t, "azurerm_availability_set", "test") + preConfig := testAccAzureRMAvailabilitySet_withTags(data) + postConfig := testAccAzureRMAvailabilitySet_withUpdatedTags(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -112,33 +101,28 @@ func TestAccAzureRMAvailabilitySet_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAvailabilitySetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMAvailabilitySetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAvailabilitySetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMAvailabilitySetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAvailabilitySet_withPPG(t *testing.T) { - resourceName := "azurerm_availability_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAvailabilitySet_withPPG(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_availability_set", "test") + config := testAccAzureRMAvailabilitySet_withPPG(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -148,23 +132,18 @@ func TestAccAzureRMAvailabilitySet_withPPG(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAvailabilitySetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "proximity_placement_group_id"), + testCheckAzureRMAvailabilitySetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "proximity_placement_group_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAvailabilitySet_withDomainCounts(t *testing.T) { - resourceName := "azurerm_availability_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAvailabilitySet_withDomainCounts(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_availability_set", "test") + config := testAccAzureRMAvailabilitySet_withDomainCounts(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,24 +153,19 @@ func TestAccAzureRMAvailabilitySet_withDomainCounts(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAvailabilitySetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "platform_update_domain_count", "3"), - resource.TestCheckResourceAttr(resourceName, "platform_fault_domain_count", "3"), + testCheckAzureRMAvailabilitySetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "platform_update_domain_count", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "platform_fault_domain_count", "3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAvailabilitySet_managed(t *testing.T) { - resourceName := "azurerm_availability_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMAvailabilitySet_managed(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_availability_set", "test") + config := testAccAzureRMAvailabilitySet_managed(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -201,15 +175,11 @@ func TestAccAzureRMAvailabilitySet_managed(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAvailabilitySetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "managed", "true"), + testCheckAzureRMAvailabilitySetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "managed", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -299,7 +269,7 @@ func testCheckAzureRMAvailabilitySetDestroy(s *terraform.State) error { return nil } -func testAccAzureRMAvailabilitySet_basic(rInt int, location string) string { +func testAccAzureRMAvailabilitySet_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -311,11 +281,11 @@ resource "azurerm_availability_set" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAvailabilitySet_requiresImport(rInt int, location string) string { - template := testAccAzureRMAvailabilitySet_basic(rInt, location) +func testAccAzureRMAvailabilitySet_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAvailabilitySet_basic(data) return fmt.Sprintf(` %s @@ -327,7 +297,7 @@ resource "azurerm_availability_set" "import" { `, template) } -func testAccAzureRMAvailabilitySet_withTags(rInt int, location string) string { +func testAccAzureRMAvailabilitySet_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -344,10 +314,10 @@ resource "azurerm_availability_set" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAvailabilitySet_withUpdatedTags(rInt int, location string) string { +func testAccAzureRMAvailabilitySet_withUpdatedTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -363,10 +333,10 @@ resource "azurerm_availability_set" "test" { environment = "staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAvailabilitySet_withPPG(rInt int, location string) string { +func testAccAzureRMAvailabilitySet_withPPG(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -386,10 +356,10 @@ resource "azurerm_availability_set" "test" { proximity_placement_group_id = "${azurerm_proximity_placement_group.test.id}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAvailabilitySet_withDomainCounts(rInt int, location string) string { +func testAccAzureRMAvailabilitySet_withDomainCounts(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -403,10 +373,10 @@ resource "azurerm_availability_set" "test" { platform_update_domain_count = 3 platform_fault_domain_count = 3 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAvailabilitySet_managed(rInt int, location string) string { +func testAccAzureRMAvailabilitySet_managed(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -421,5 +391,5 @@ resource "azurerm_availability_set" "test" { platform_fault_domain_count = 3 managed = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_image_test.go b/azurerm/internal/services/compute/tests/resource_arm_image_test.go similarity index 86% rename from azurerm/internal/services/compute/resource_arm_image_test.go rename to azurerm/internal/services/compute/tests/resource_arm_image_test.go index de715e97f2fe..84bd6bdc25e7 100644 --- a/azurerm/internal/services/compute/resource_arm_image_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_image_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "bytes" @@ -11,7 +11,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -19,15 +18,15 @@ import ( ) func TestAccAzureRMImage_standaloneImage(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "testsource") + + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" - location := acceptance.Location() - preConfig := testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName, location, "LRS") - postConfig := testAccAzureRMImage_standaloneImage_provision(ri, userName, password, hostName, location, "LRS", "") + preConfig := testAccAzureRMImage_standaloneImage_setup(data, userName, password, hostName, "LRS") + postConfig := testAccAzureRMImage_standaloneImage_provision(data, userName, password, hostName, "LRS", "") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -40,34 +39,29 @@ func TestAccAzureRMImage_standaloneImage(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, location), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMImageExists("azurerm_image.test", true), + testCheckAzureRMImageExists("azurerm_image", true), ), }, - { - ResourceName: "azurerm_image.test", - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMImage_standaloneImage_hyperVGeneration_V2(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "testsource") + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" - location := acceptance.Location() - preConfig := testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName, location, "LRS") - postConfig := testAccAzureRMImage_standaloneImage_provision(ri, userName, password, hostName, location, "LRS", "V2") + preConfig := testAccAzureRMImage_standaloneImage_setup(data, userName, password, hostName, "LRS") + postConfig := testAccAzureRMImage_standaloneImage_provision(data, userName, password, hostName, "LRS", "V2") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,34 +74,29 @@ func TestAccAzureRMImage_standaloneImage_hyperVGeneration_V2(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, location), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMImageExists("azurerm_image.test", true), + testCheckAzureRMImageExists("azurerm_image", true), ), }, - { - ResourceName: "azurerm_image.test", - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMImage_standaloneImageZoneRedundant(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "testsource") + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" - location := acceptance.Location() - preConfig := testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName, location, "ZRS") - postConfig := testAccAzureRMImage_standaloneImage_provision(ri, userName, password, hostName, location, "ZRS", "") + preConfig := testAccAzureRMImage_standaloneImage_setup(data, userName, password, hostName, "ZRS") + postConfig := testAccAzureRMImage_standaloneImage_provision(data, userName, password, hostName, "ZRS", "") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -120,20 +109,16 @@ func TestAccAzureRMImage_standaloneImageZoneRedundant(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, location), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMImageExists("azurerm_image.test", true), + testCheckAzureRMImageExists("azurerm_image", true), ), }, - { - ResourceName: "azurerm_image.test", - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -144,13 +129,13 @@ func TestAccAzureRMImage_requiresImport(t *testing.T) { return } - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "testsource") + + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -159,21 +144,21 @@ func TestAccAzureRMImage_requiresImport(t *testing.T) { Steps: []resource.TestStep{ { //need to create a vm and then reference it in the image creation - Config: testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName, location, "LRS"), + Config: testAccAzureRMImage_standaloneImage_setup(data, userName, password, hostName, "LRS"), Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, location), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { - Config: testAccAzureRMImage_standaloneImage_provision(ri, userName, password, hostName, location, "LRS", ""), + Config: testAccAzureRMImage_standaloneImage_provision(data, userName, password, hostName, "LRS", ""), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMImageExists("azurerm_image.test", true), + testCheckAzureRMImageExists("azurerm_image", true), ), }, { - Config: testAccAzureRMImage_standaloneImage_requiresImport(ri, userName, password, hostName, location), + Config: testAccAzureRMImage_standaloneImage_requiresImport(data, userName, password, hostName), ExpectError: acceptance.RequiresImportError("azurerm_image"), }, }, @@ -181,15 +166,15 @@ func TestAccAzureRMImage_requiresImport(t *testing.T) { } func TestAccAzureRMImage_customImageVMFromVHD(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "testsource") + + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" - location := acceptance.Location() - preConfig := testAccAzureRMImage_customImage_fromVHD_setup(ri, userName, password, hostName, location) - postConfig := testAccAzureRMImage_customImage_fromVHD_provision(ri, userName, password, hostName, location) + preConfig := testAccAzureRMImage_customImage_fromVHD_setup(data, userName, password, hostName, data.Locations.Primary) + postConfig := testAccAzureRMImage_customImage_fromVHD_provision(data, userName, password, hostName, data.Locations.Primary) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -202,7 +187,7 @@ func TestAccAzureRMImage_customImageVMFromVHD(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, location), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { @@ -216,15 +201,15 @@ func TestAccAzureRMImage_customImageVMFromVHD(t *testing.T) { } func TestAccAzureRMImage_customImageVMFromVM(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "testsource") + + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" - location := acceptance.Location() - preConfig := testAccAzureRMImage_customImage_fromVM_sourceVM(ri, userName, password, hostName, location) - postConfig := testAccAzureRMImage_customImage_fromVM_destinationVM(ri, userName, password, hostName, location) + preConfig := testAccAzureRMImage_customImage_fromVM_sourceVM(data, userName, password, hostName, data.Locations.Primary) + postConfig := testAccAzureRMImage_customImage_fromVM_destinationVM(data, userName, password, hostName, data.Locations.Primary) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -237,7 +222,7 @@ func TestAccAzureRMImage_customImageVMFromVM(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, location), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { @@ -251,15 +236,15 @@ func TestAccAzureRMImage_customImageVMFromVM(t *testing.T) { } func TestAccAzureRMImageVMSS_customImageVMSSFromVHD(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "testsource") + + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" - location := acceptance.Location() - preConfig := testAccAzureRMImageVMSS_customImage_fromVHD_setup(ri, userName, password, hostName, location) - postConfig := testAccAzureRMImageVMSS_customImage_fromVHD_provision(ri, userName, password, hostName, location) + preConfig := testAccAzureRMImageVMSS_customImage_fromVHD_setup(data, userName, password, hostName, data.Locations.Primary) + postConfig := testAccAzureRMImageVMSS_customImage_fromVHD_provision(data, userName, password, hostName, data.Locations.Primary) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -272,7 +257,7 @@ func TestAccAzureRMImageVMSS_customImageVMSSFromVHD(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, location), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { @@ -480,7 +465,7 @@ func testCheckAzureRMImageDestroy(s *terraform.State) error { return nil } -func testAccAzureRMImage_standaloneImage_setup(rInt int, userName string, password string, hostName string, location string, storageType string) string { +func testAccAzureRMImage_standaloneImage_setup(data acceptance.TestData, userName string, password string, hostName string, storageType string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -578,10 +563,10 @@ resource "azurerm_virtual_machine" "testsource" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, storageType, userName, password) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, hostName, data.RandomInteger, data.RandomInteger, storageType, userName, password) } -func testAccAzureRMImage_standaloneImage_provision(rInt int, userName string, password string, hostName string, location string, storageType string, hyperVGen string) string { +func testAccAzureRMImage_standaloneImage_provision(data acceptance.TestData, userName string, password string, hostName string, storageType string, hyperVGen string) string { hyperVGenAtt := "" if hyperVGen != "" { hyperVGenAtt = fmt.Sprintf(`hyper_v_generation = "%s"`, hyperVGen) @@ -705,11 +690,11 @@ resource "azurerm_image" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, storageType, userName, password, storageType == "ZRS", hyperVGenAtt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, hostName, data.RandomInteger, data.RandomInteger, storageType, userName, password, storageType == "ZRS", hyperVGenAtt) } -func testAccAzureRMImage_standaloneImage_requiresImport(rInt int, userName string, password string, hostName string, location string) string { - template := testAccAzureRMImage_standaloneImage_provision(rInt, userName, password, hostName, location, "LRS", "") +func testAccAzureRMImage_standaloneImage_requiresImport(data acceptance.TestData, userName string, password string, hostName string) string { + template := testAccAzureRMImage_standaloneImage_provision(data, userName, password, hostName, "LRS", "") return fmt.Sprintf(` %s @@ -734,7 +719,7 @@ resource "azurerm_image" "import" { `, template) } -func testAccAzureRMImage_customImage_fromVHD_setup(rInt int, userName string, password string, hostName string, location string) string { +func testAccAzureRMImage_customImage_fromVHD_setup(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -832,10 +817,10 @@ resource "azurerm_virtual_machine" "testsource" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, userName, password) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, hostName, data.RandomInteger, data.RandomInteger, userName, password) } -func testAccAzureRMImage_customImage_fromVHD_provision(rInt int, userName string, password string, hostName string, location string) string { +func testAccAzureRMImage_customImage_fromVHD_provision(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -997,10 +982,10 @@ resource "azurerm_virtual_machine" "testdestination" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, userName, password, rInt, userName, password) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, hostName, data.RandomInteger, data.RandomInteger, userName, password, data.RandomInteger, userName, password) } -func testAccAzureRMImage_customImage_fromVM_sourceVM(rInt int, userName string, password string, hostName string, location string) string { +func testAccAzureRMImage_customImage_fromVM_sourceVM(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1077,10 +1062,10 @@ resource "azurerm_virtual_machine" "testsource" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, hostName, rInt, userName, password) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, hostName, data.RandomInteger, userName, password) } -func testAccAzureRMImage_customImage_fromVM_destinationVM(rInt int, userName string, password string, hostName string, location string) string { +func testAccAzureRMImage_customImage_fromVM_destinationVM(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1214,10 +1199,10 @@ resource "azurerm_virtual_machine" "testdestination" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, hostName, rInt, userName, password, rInt, rInt, userName, password) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, hostName, data.RandomInteger, userName, password, data.RandomInteger, data.RandomInteger, userName, password) } -func testAccAzureRMImageVMSS_customImage_fromVHD_setup(rInt int, userName string, password string, hostName string, location string) string { +func testAccAzureRMImageVMSS_customImage_fromVHD_setup(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1315,10 +1300,10 @@ resource "azurerm_virtual_machine" "testsource" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, userName, password) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, hostName, data.RandomInteger, data.RandomInteger, userName, password) } -func testAccAzureRMImageVMSS_customImage_fromVHD_provision(rInt int, userName string, password string, hostName string, location string) string { +func testAccAzureRMImageVMSS_customImage_fromVHD_provision(data acceptance.TestData, userName string, password string, hostName string, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1475,5 +1460,5 @@ resource "azurerm_virtual_machine_scale_set" "testdestination" { id = "${azurerm_image.testdestination.id}" } } -`, rInt, location, rInt, rInt, rInt, hostName, rInt, rInt, userName, password, rInt, userName, password, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, hostName, data.RandomInteger, data.RandomInteger, userName, password, data.RandomInteger, userName, password, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_auth_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_auth_test.go similarity index 66% rename from azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_auth_test.go rename to azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_auth_test.go index 6e6f93bab9e1..9ed7dcf7af77 100644 --- a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_auth_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_auth_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMLinuxVirtualMachineScaleSet_authPassword(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,29 +17,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_authPassword(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,27 +39,20 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_authSSHKeyAndPassword(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,29 +60,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_authSSHKeyAndPassword(t *testing. CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKeyAndPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKeyAndPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_authMultipleSSHKeys(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -108,27 +82,20 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_authMultipleSSHKeys(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authMultipleSSHKeys(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authMultipleSSHKeys(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_authUpdatingSSHKeys(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -136,41 +103,29 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_authUpdatingSSHKeys(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKeyUpdated(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKeyUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_authDisablePasswordAuthUpdate(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -179,58 +134,43 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_authDisablePasswordAuthUpdate(t * Steps: []resource.TestStep{ { // disable it - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // enable it - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // disable it - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -268,11 +208,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKey(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -312,11 +252,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKeyUpdated(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKeyUpdated(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -356,11 +296,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKeyAndPassword(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_authSSHKeyAndPassword(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -401,11 +341,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_authMultipleSSHKeys(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_authMultipleSSHKeys(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -450,5 +390,5 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go similarity index 62% rename from azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go rename to azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go index 5277a1a932ba..8648f94439e0 100644 --- a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_data_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskBasic(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,29 +17,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskBasic(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskBasic(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskCaching(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,60 +39,40 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskCaching(t *testing.T CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskCaching(ri, location, "None"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskCaching(data, "None"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskCaching(ri, location, "ReadOnly"), + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskCaching(data, "ReadOnly"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskCaching(ri, location, "ReadWrite"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskCaching(data, "ReadWrite"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskResizing(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -112,46 +81,32 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskResizing(t *testing. Steps: []resource.TestStep{ { // 30GB - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskResize(ri, location, 30), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskResize(data, 30), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // 60GB - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskResize(ri, location, 60), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskResize(data, 60), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskMultiple(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -159,29 +114,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskMultiple(t *testing. CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskMultiple(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskMultiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskRemove(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -189,45 +136,31 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskRemove(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskBasic(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskScaling(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -236,80 +169,54 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskScaling(t *testing.T Steps: []resource.TestStep{ { // no disks - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // one disk - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskBasic(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // two disks - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskMultiple(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskMultiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // no disks - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypeStandardLRS(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -317,29 +224,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypeSt CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountType(ri, location, "Standard_LRS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountType(data, "Standard_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypeStandardSSDLRS(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -347,29 +246,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypeSt CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountType(ri, location, "StandardSSD_LRS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountType(data, "StandardSSD_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypePremiumLRS(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -377,30 +268,22 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypePr CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountType(ri, location, "Premium_LRS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountType(data, "Premium_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUltraSSDLRS(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") // Are supported in East US 2, SouthEast Asia, and North Europe, in two availability zones per region - location := acceptance.AltLocation() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -408,29 +291,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUl CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUltraSSDLRS(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUltraSSDLRS(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnabled(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -438,27 +313,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnab CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnabled(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskBasic(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskBasic(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -503,11 +372,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskCaching(rInt int, location, caching string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskCaching(data acceptance.TestData, caching string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -552,11 +421,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, caching) +`, template, data.RandomInteger, caching) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskResize(rInt int, location string, diskSizeGb int) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskResize(data acceptance.TestData, diskSizeGb int) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -601,11 +470,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, diskSizeGb) +`, template, data.RandomInteger, diskSizeGb) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskMultiple(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskMultiple(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -657,11 +526,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountType(rInt int, location, storageAccountType string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountType(data acceptance.TestData, storageAccountType string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -706,11 +575,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, storageAccountType) +`, template, data.RandomInteger, storageAccountType) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUltraSSDLRS(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUltraSSDLRS(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -759,11 +628,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnabled(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnabled(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -809,5 +678,5 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go similarity index 62% rename from azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go rename to azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go index 8730226ee153..a6e1d0184b92 100644 --- a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_disk_os_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCaching(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,59 +17,39 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCaching(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCaching(ri, location, "None"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCaching(data, "None"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCaching(ri, location, "ReadOnly"), + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCaching(data, "ReadOnly"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCaching(ri, location, "ReadWrite"), + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCaching(data, "ReadWrite"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCustomSize(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,62 +58,42 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCustomSize(t *testing. Steps: []resource.TestStep{ { // unset - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCustomSize(ri, location, 30), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCustomSize(data, 30), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // resize a second time to confirm https://github.com/Azure/azure-rest-api-specs/issues/1906 - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCustomSize(ri, location, 60), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCustomSize(data, 60), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskEphemeral(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -144,29 +101,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskEphemeral(t *testing.T CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskEphemeral(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskEphemeral(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountTypeStandardLRS(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,29 +123,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountTypeStan CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountType(ri, location, "Standard_LRS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountType(data, "Standard_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountTypeStandardSSDLRS(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -204,29 +145,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountTypeStan CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountType(ri, location, "StandardSSD_LRS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountType(data, "StandardSSD_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountTypePremiumLRS(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -234,29 +167,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountTypePrem CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountType(ri, location, "Premium_LRS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountType(data, "Premium_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnabled(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -264,27 +189,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnable CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnabled(ri, location, true), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnabled(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCaching(rInt int, location, caching string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCaching(data acceptance.TestData, caching string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -322,11 +241,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, caching) +`, template, data.RandomInteger, caching) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCustomSize(rInt int, location string, diskSize int) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskCustomSize(data acceptance.TestData, diskSize int) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -365,11 +284,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, diskSize) +`, template, data.RandomInteger, diskSize) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskEphemeral(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskEphemeral(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -411,11 +330,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountType(rInt int, location, storageAccountType string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskStorageAccountType(data acceptance.TestData, storageAccountType string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -453,11 +372,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, storageAccountType) +`, template, data.RandomInteger, storageAccountType) } -func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnabled(rInt int, location string, enabled bool) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnabled(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -496,5 +415,5 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, enabled) +`, template, data.RandomInteger, enabled) } diff --git a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_identity_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_identity_test.go similarity index 60% rename from azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_identity_test.go rename to azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_identity_test.go index 331913d45561..c568a0f49e5d 100644 --- a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_identity_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_identity_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMLinuxVirtualMachineScaleSet_identityNone(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,30 +17,22 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_identityNone(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.%", "0"), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssigned(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,65 +40,45 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssigned(t *testing CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssigned(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.principal_id"), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // disable it - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.%", "0"), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.%", "0"), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssigned(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.principal_id"), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssigned(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -117,80 +86,54 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssigned(t *testing.T CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssigned(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // disable it - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.%", "0"), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.%", "0"), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssigned(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // second - Config: testAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssignedUpdated(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssignedUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssignedUserAssigned(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -198,63 +141,45 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssignedUserAssigne CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssignedUserAssigned(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssignedUserAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.principal_id"), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // disable it - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.%", "0"), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.%", "0"), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssignedUserAssigned(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssignedUserAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.principal_id"), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssigned(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssigned(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -296,11 +221,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { type = "SystemAssigned" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssigned(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssigned(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -351,11 +276,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { ] } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssignedUpdated(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_identityUserAssignedUpdated(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -413,11 +338,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { ] } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssignedUserAssigned(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_identitySystemAssignedUserAssigned(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -468,5 +393,5 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { ] } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_images_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_images_test.go similarity index 75% rename from azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_images_test.go rename to azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_images_test.go index a628719b7e27..15866e697880 100644 --- a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_images_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_images_test.go @@ -1,19 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform/helper/acctest" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesAutomaticUpdate(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,46 +17,31 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesAutomaticUpdate(t *testing. CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesAutomaticUpdate(ri, location, "16.04-LTS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesAutomaticUpdate(data, "16.04-LTS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesAutomaticUpdate(ri, location, "18.04-LTS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesAutomaticUpdate(data, "18.04-LTS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesFromCapturedVirtualMachineImage(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - rString := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -69,58 +50,44 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesFromCapturedVirtualMachineI Steps: []resource.TestStep{ { // provision a standard Virtual Machine with an Unmanaged Disk - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithVM(ri, location, rString), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithVM(data), }, { // then delete the Virtual Machine - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(ri, location, rString), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(data), }, { // then capture two images of the Virtual Machine - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(ri, location, rString), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(data), }, { // then provision a Virtual Machine Scale Set using this image - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachine(ri, location, rString, "first"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachine(data, "first"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // then update the image on this Virtual Machine Scale Set - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachine(ri, location, rString, "second"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachine(data, "second"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdate(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -128,45 +95,31 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdate(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdate(ri, location, "16.04-LTS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdate(data, "16.04-LTS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdate(ri, location, "18.04-LTS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdate(data, "18.04-LTS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdateExternalRoll(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,45 +127,31 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdateExternalRoll(t CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdateExternalRoll(ri, location, "16.04-LTS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdateExternalRoll(data, "16.04-LTS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdateExternalRoll(ri, location, "18.04-LTS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdateExternalRoll(data, "18.04-LTS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesRollingUpdate(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -220,45 +159,31 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesRollingUpdate(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesRollingUpdate(ri, location, "16.04-LTS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesRollingUpdate(data, "16.04-LTS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesRollingUpdate(ri, location, "18.04-LTS"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesRollingUpdate(data, "18.04-LTS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesPlan(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -266,27 +191,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_imagesPlan(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesPlan(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_imagesPlan(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMLinuxVirtualMachineScaleSet_imagesAutomaticUpdate(rInt int, location, version string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_imagesAutomaticUpdate(data acceptance.TestData, version string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -398,11 +317,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { depends_on = ["azurerm_lb_rule.test"] } -`, template, rInt, rInt, rInt, version) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, version) } -func testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(rInt int, location, rString string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -439,11 +358,11 @@ resource "azurerm_storage_container" "test" { storage_account_name = azurerm_storage_account.test.name container_access_type = "blob" } -`, template, rInt, rInt, rString) +`, template, data.RandomInteger, data.RandomInteger, data.RandomString) } -func testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithVM(rInt int, location, rString string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(rInt, location, rString) +func testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithVM(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(data) return fmt.Sprintf(` %s @@ -482,8 +401,8 @@ resource "azurerm_virtual_machine" "source" { `, template) } -func testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(rInt int, location, rString string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(rInt, location, rString) +func testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(data) return fmt.Sprintf(` %s @@ -519,8 +438,8 @@ resource "azurerm_image" "second" { `, template) } -func testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachine(rInt int, location, rString, image string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(rInt, location, rString) +func testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachine(data acceptance.TestData, image string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(data) return fmt.Sprintf(` %s @@ -552,11 +471,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, image) +`, template, data.RandomInteger, image) } -func testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdate(rInt int, location, version string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdate(data acceptance.TestData, version string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -594,11 +513,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, version) +`, template, data.RandomInteger, version) } -func testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdateExternalRoll(rInt int, location, version string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_imagesManualUpdateExternalRoll(data acceptance.TestData, version string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -637,11 +556,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, version) +`, template, data.RandomInteger, version) } -func testAccAzureRMLinuxVirtualMachineScaleSet_imagesRollingUpdate(rInt int, location, version string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_imagesRollingUpdate(data acceptance.TestData, version string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -748,11 +667,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { depends_on = ["azurerm_lb_rule.test"] } -`, template, rInt, rInt, rInt, version) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, version) } -func testAccAzureRMLinuxVirtualMachineScaleSet_imagesPlan(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_imagesPlan(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -802,7 +721,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { publisher = "cloudbees" } - depends_on = ["azurerm_marketplace_agreement.test"] + depends_on = ["azurerm_marketplace_agreement", "test")] } -`, template, rInt) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_network_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_network_test.go similarity index 72% rename from azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_network_test.go rename to azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_network_test.go index 82a9a4fe4f7f..259e8fa3f19f 100644 --- a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_network_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_network_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -6,14 +6,11 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,29 +18,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(t *t CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(ri, location, true), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworkingUpdated(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,61 +40,41 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworkingUpdat CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(ri, location, false), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(ri, location, true), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(ri, location, false), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationGateway(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,29 +82,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationGateway(t *test CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationGateway(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationGateway(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroup(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -143,29 +104,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroup(t CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroup(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroupUpdate(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,80 +127,54 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroupUp Steps: []resource.TestStep{ { // none - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // one - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroup(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // another - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroupUpdated(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroupUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // none - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkDNSServers(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -255,45 +182,31 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkDNSServers(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkDNSServers(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkDNSServers(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkDNSServersUpdated(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkDNSServersUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkIPForwarding(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -302,63 +215,43 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkIPForwarding(t *testing.T) Steps: []resource.TestStep{ { // enabled - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkIPForwarding(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkIPForwarding(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // disabled - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // enabled - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkIPForwarding(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkIPForwarding(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkIPv6(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -366,9 +259,9 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkIPv6(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkIPv6(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkIPv6(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), ExpectError: regexp.MustCompile("Error expanding `network_interface`: An IPv6 Primary IP Configuration is unsupported - instead add a IPv4 IP Configuration as the Primary and make the IPv6 IP Configuration the secondary"), }, @@ -377,9 +270,7 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkIPv6(t *testing.T) { } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkLoadBalancer(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -387,29 +278,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkLoadBalancer(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkLoadBalancer(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkLoadBalancer(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurations(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -417,29 +300,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurations(t CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurations(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurations(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurationsIPv6(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -447,29 +322,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurationsIP CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurationsIPv6(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurationsIPv6(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICs(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -477,29 +344,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICs(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICs(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultipleIPConfigurations(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -507,29 +366,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultipleIPConf CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultipleIPConfigurations(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultipleIPConfigurations(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultiplePublicIPs(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -537,29 +388,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultiplePublic CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultiplePublicIPs(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultiplePublicIPs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsWithDifferentDNSServers(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -567,29 +410,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsWithDifferentD CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsWithDifferentDNSServers(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsWithDifferentDNSServers(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroup(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -597,29 +432,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroup(t *te CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroup(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroupUpdate(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -628,80 +455,54 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroupUpdate Steps: []resource.TestStep{ { // without - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // add one - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroup(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // change it - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroupUpdated(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroupUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // remove it - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -709,29 +510,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIP(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -739,29 +532,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIP(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIP(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIP(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPDomainNameLabel(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -769,29 +554,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPDomainNameLabel(t CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPDomainNameLabel(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPDomainNameLabel(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPFromPrefix(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -799,29 +576,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPFromPrefix(t *test CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPFromPrefix(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPFromPrefix(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPTags(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -829,27 +598,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPTags(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPTags(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(rInt int, location string, enabled bool) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkAcceleratedNetworking(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -888,10 +651,10 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, enabled) +`, template, data.RandomInteger, enabled) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationGateway(rInt int, location string) string { +func testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationGateway(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1025,11 +788,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroup(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroup(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1074,11 +837,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroupUpdated(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkApplicationSecurityGroupUpdated(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1132,11 +895,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkDNSServers(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkDNSServers(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1175,11 +938,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkDNSServersUpdated(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkDNSServersUpdated(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1218,11 +981,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkIPForwarding(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkIPForwarding(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1261,11 +1024,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkIPv6(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkIPv6(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1303,11 +1066,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkLoadBalancer(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkLoadBalancer(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1383,11 +1146,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurations(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurations(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1430,11 +1193,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurationsIPv6(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleIPConfigurationsIPv6(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1478,11 +1241,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICs(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICs(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1530,11 +1293,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultipleIPConfigurations(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultipleIPConfigurations(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1592,11 +1355,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsWithDifferentDNSServers(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsWithDifferentDNSServers(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1646,11 +1409,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultiplePublicIPs(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkMultipleNICsMultiplePublicIPs(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1710,11 +1473,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroup(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroup(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1759,11 +1522,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroupUpdated(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkNetworkSecurityGroupUpdated(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1814,11 +1577,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkPrivate(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1856,11 +1619,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIP(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIP(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1903,11 +1666,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPDomainNameLabel(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPDomainNameLabel(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1951,11 +1714,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPFromPrefix(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPFromPrefix(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -2004,11 +1767,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPTags(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_networkPublicIPTags(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -2055,5 +1818,5 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_other_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_other_test.go similarity index 70% rename from azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_other_test.go rename to azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_other_test.go index 9ec36e3dbe60..64f8a758176f 100644 --- a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_other_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_other_test.go @@ -1,21 +1,16 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform/helper/acctest" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnostics(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,63 +19,43 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnostics(t *testing.T Steps: []resource.TestStep{ { // Enabled - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnostics(ri, location, rs), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnostics(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // Removed - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnosticsDisabled(ri, location, rs), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnosticsDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // Enabled - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnostics(ri, location, rs), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnostics(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherComputerNamePrefix(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -88,29 +63,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherComputerNamePrefix(t *testin CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherComputerNamePrefix(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherComputerNamePrefix(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherCustomData(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -118,65 +85,45 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherCustomData(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherCustomData(ri, location, "/bin/bash"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherCustomData(data, "/bin/bash"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "custom_data", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "custom_data", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherCustomData(ri, location, "/bin/zsh"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherCustomData(data, "/bin/zsh"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "custom_data", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "custom_data", + "terraform_should_roll_instances_when_required", + ), { // removed - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "custom_data", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "custom_data", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProvisionedMachines(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -184,29 +131,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProv CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProvisionedMachines(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProvisionedMachines(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowDeallocate(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -214,29 +153,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowDeallocate(t *tes CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLow(ri, location, "Deallocate"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLow(data, "Deallocate"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowDelete(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -244,29 +175,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowDelete(t *testing CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLow(ri, location, "Delete"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLow(data, "Delete"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -275,45 +198,31 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(t *te Steps: []resource.TestStep{ { // expensive, but guarantees this test will pass - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(ri, location, "0.5000"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(data, "0.5000"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(ri, location, "-1"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(data, "-1"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityRegular(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -321,21 +230,15 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityRegular(t *testing.T CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityRegular(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityRegular(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } @@ -345,9 +248,7 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherRequiresImport(t *testing.T) t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -355,13 +256,13 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherRequiresImport(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherRequiresImport(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherRequiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_linux_virtual_machine_scale_set"), }, }, @@ -369,10 +270,7 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherRequiresImport(t *testing.T) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherSecret(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -380,67 +278,44 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherSecret(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherSecret(ri, location, rs), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherSecret(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // update - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretUpdated(ri, location, rs), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // removed - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretRemoved(ri, location, rs), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretRemoved(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherTags(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -448,63 +323,43 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherTags(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherTags(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // add one - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherTagsUpdated(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherTagsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // remove all - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherVMAgent(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -512,29 +367,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherVMAgent(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherVMAgent(ri, location, true), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherVMAgent(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_otherVMAgentDisabled(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -542,27 +389,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_otherVMAgentDisabled(t *testing.T CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherVMAgent(ri, location, false), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_otherVMAgent(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnostics(rInt int, location string, rString string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnostics(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -612,11 +453,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { storage_account_uri = azurerm_storage_account.test.primary_blob_endpoint } } -`, template, rString, rInt) +`, template, data.RandomString, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnosticsDisabled(rInt int, location string, rString string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherBootDiagnosticsDisabled(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -662,11 +503,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rString, rInt) +`, template, data.RandomString, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherComputerNamePrefix(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherComputerNamePrefix(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -705,11 +546,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherCustomData(rInt int, location, customData string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherCustomData(data acceptance.TestData, customData string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -748,11 +589,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, customData) +`, template, data.RandomInteger, customData) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProvisionedMachines(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProvisionedMachines(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -792,11 +633,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLow(rInt int, location, evictionPolicy string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLow(data acceptance.TestData, evictionPolicy string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -836,11 +677,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, evictionPolicy) +`, template, data.RandomInteger, evictionPolicy) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(rInt int, location, maxBid string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(data acceptance.TestData, maxBid string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -881,11 +722,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, maxBid) +`, template, data.RandomInteger, maxBid) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityRegular(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherPriorityRegular(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -924,11 +765,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherRequiresImport(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherRequiresImport(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data) return fmt.Sprintf(` %s @@ -969,8 +810,8 @@ resource "azurerm_linux_virtual_machine_scale_set" "import" { `, template) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherSecret(rInt int, location string, rString string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretTemplate(rInt, location, rString) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherSecret(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretTemplate(data) return fmt.Sprintf(` %s @@ -1016,11 +857,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretRemoved(rInt int, location string, rString string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretTemplate(rInt, location, rString) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretRemoved(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretTemplate(data) return fmt.Sprintf(` %s @@ -1058,11 +899,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretUpdated(rInt int, location string, rString string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretTemplate(rInt, location, rString) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretUpdated(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretTemplate(data) return fmt.Sprintf(` %s @@ -1112,11 +953,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretTemplate(rInt int, location string, rString string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherSecretTemplate(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1248,11 +1089,11 @@ resource "azurerm_key_vault_certificate" "second" { } } } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherTags(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherTags(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1294,11 +1135,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { artist = "Billy" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherTagsUpdated(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherTagsUpdated(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1341,11 +1182,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { when = "we all fall asleep" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_otherVMAgent(rInt int, location string, enabled bool) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_otherVMAgent(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1384,5 +1225,5 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, enabled) +`, template, data.RandomInteger, enabled) } diff --git a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_scaling_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_scaling_test.go similarity index 69% rename from azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_scaling_test.go rename to azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_scaling_test.go index d948ad12a446..2737b824b156 100644 --- a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_scaling_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_scaling_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingAutoScale(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,29 +17,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingAutoScale(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingAutoScale(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingAutoScale(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,73 +39,49 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(t *testing.T CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(ri, location, 1), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(data, 1), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(ri, location, 3), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(data, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(ri, location, 5), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(data, 5), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // update the count but the `sku` should be ignored - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCountIgnoreUpdatedSku(ri, location, 3), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCountIgnoreUpdatedSku(data, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // confirm that the `sku` hasn't been changed - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(ri, location, 3), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(data, 3), PlanOnly: true, }, }, @@ -124,9 +89,7 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(t *testing.T } func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingOverProvisionDisabled(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -134,29 +97,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingOverProvisionDisabled(t *t CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingOverProvisionDisabled(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingOverProvisionDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingProximityPlacementGroup(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -164,29 +119,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingProximityPlacementGroup(t CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingProximityPlacementGroup(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingProximityPlacementGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -194,29 +141,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingSinglePlacementGroupDisabl CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingSinglePlacementGroupDisabledUpdate(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -224,45 +163,31 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingSinglePlacementGroupDisabl CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -270,62 +195,44 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(t *testing.T) { CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(ri, location, "Standard_F2"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(data, "Standard_F2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(ri, location, "Standard_F4"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(data, "Standard_F4"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(ri, location, "Standard_F2"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(data, "Standard_F2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // confirms that the `instances` count comes from the API - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSkuIgnoredUpdatedCount(ri, location, "Standard_F2"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSkuIgnoredUpdatedCount(data, "Standard_F2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(ri, location, "Standard_F2"), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(data, "Standard_F2"), PlanOnly: true, }, }, @@ -333,9 +240,7 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(t *testing.T) { } func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesSingle(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -343,29 +248,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesSingle(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesSingle(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesSingle(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesMultiple(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -373,29 +270,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesMultiple(t *testing.T CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesMultiple(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesMultiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesBalance(t *testing.T) { - resourceName := "azurerm_linux_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_linux_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -403,27 +292,21 @@ func TestAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesBalance(t *testing.T) CheckDestroy: testCheckAzureRMLinuxVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesBalance(ri, location), + Config: testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesBalance(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMLinuxVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingAutoScale(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingAutoScale(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -519,11 +402,11 @@ resource "azurerm_monitor_autoscale_setting" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(rInt int, location string, instanceCount int) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCount(data acceptance.TestData, instanceCount int) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -561,11 +444,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, instanceCount) +`, template, data.RandomInteger, instanceCount) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCountIgnoreUpdatedSku(rInt int, location string, instanceCount int) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingInstanceCountIgnoreUpdatedSku(data acceptance.TestData, instanceCount int) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -607,11 +490,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { ignore_changes = ["sku"] } } -`, template, rInt, instanceCount) +`, template, data.RandomInteger, instanceCount) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingOverProvisionDisabled(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingOverProvisionDisabled(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -650,11 +533,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingProximityPlacementGroup(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingProximityPlacementGroup(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -699,11 +582,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -742,11 +625,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(rInt int, location, skuName string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSku(data acceptance.TestData, skuName string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -784,11 +667,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt, skuName) +`, template, data.RandomInteger, skuName) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSkuIgnoredUpdatedCount(rInt int, location, skuName string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingUpdateSkuIgnoredUpdatedCount(data acceptance.TestData, skuName string) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -830,11 +713,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { ignore_changes = ["instances"] } } -`, template, rInt, skuName) +`, template, data.RandomInteger, skuName) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesSingle(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesSingle(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -873,11 +756,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesMultiple(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesMultiple(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -916,11 +799,11 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesBalance(rInt int, location string) string { - template := testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMLinuxVirtualMachineScaleSet_scalingZonesBalance(data acceptance.TestData) string { + template := testAccAzureRMLinuxVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -960,5 +843,5 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_test.go similarity index 95% rename from azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_test.go rename to azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_test.go index 88b011f52fd4..64ab33d491d9 100644 --- a/azurerm/internal/services/compute/resource_arm_linux_virtual_machine_scale_set_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -61,7 +61,7 @@ func testCheckAzureRMLinuxVirtualMachineScaleSetExists(resourceName string) reso } } -func testAccAzureRMLinuxVirtualMachineScaleSet_template(rInt int, location string) string { +func testAccAzureRMLinuxVirtualMachineScaleSet_template(data acceptance.TestData) string { return fmt.Sprintf(` # note: whilst these aren't used in all tests, it saves us redefining these everywhere locals { @@ -87,5 +87,5 @@ resource "azurerm_subnet" "test" { virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_managed_disk_test.go b/azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go similarity index 71% rename from azurerm/internal/services/compute/resource_arm_managed_disk_test.go rename to azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go index e6d27cff65c4..6f374562a6d3 100644 --- a/azurerm/internal/services/compute/resource_arm_managed_disk_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_managed_disk_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -6,19 +6,15 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMManagedDisk_empty(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -27,16 +23,12 @@ func TestAccAzureRMManagedDisk_empty(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_empty(ri, location), + Config: testAccAzureRMManagedDisk_empty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,9 +39,7 @@ func TestAccAzureRMManagedDisk_requiresImport(t *testing.T) { return } - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -58,13 +48,13 @@ func TestAccAzureRMManagedDisk_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_empty(ri, location), + Config: testAccAzureRMManagedDisk_empty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, { - Config: testAccAzureRMManagedDisk_requiresImport(ri, location), + Config: testAccAzureRMManagedDisk_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_managed_disk"), }, }, @@ -72,8 +62,7 @@ func TestAccAzureRMManagedDisk_requiresImport(t *testing.T) { } func TestAccAzureRMManagedDisk_zeroGbFromPlatformImage(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -82,9 +71,9 @@ func TestAccAzureRMManagedDisk_zeroGbFromPlatformImage(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_zeroGbFromPlatformImage(ri, acceptance.Location()), + Config: testAccAzureRMManagedDisk_zeroGbFromPlatformImage(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, }, @@ -92,9 +81,7 @@ func TestAccAzureRMManagedDisk_zeroGbFromPlatformImage(t *testing.T) { } func TestAccAzureRMManagedDisk_import(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - location := acceptance.Location() - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var vm compute.VirtualMachine var d compute.Disk @@ -105,18 +92,18 @@ func TestAccAzureRMManagedDisk_import(t *testing.T) { Steps: []resource.TestStep{ { //need to create a vm and then delete it so we can use the vhd to test import - Config: testAccAzureRMVirtualMachine_basicLinuxMachine(ri, location), + Config: testAccAzureRMVirtualMachine_basicLinuxMachine(data), Destroy: false, ExpectNonEmptyPlan: true, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), testDeleteAzureRMVirtualMachine("azurerm_virtual_machine.test"), ), }, { - Config: testAccAzureRMManagedDisk_import(ri, location), + Config: testAccAzureRMManagedDisk_import(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, }, @@ -124,8 +111,7 @@ func TestAccAzureRMManagedDisk_import(t *testing.T) { } func TestAccAzureRMManagedDisk_copy(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -134,9 +120,9 @@ func TestAccAzureRMManagedDisk_copy(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_copy(ri, acceptance.Location()), + Config: testAccAzureRMManagedDisk_copy(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, }, @@ -144,8 +130,7 @@ func TestAccAzureRMManagedDisk_copy(t *testing.T) { } func TestAccAzureRMManagedDisk_fromPlatformImage(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -154,9 +139,9 @@ func TestAccAzureRMManagedDisk_fromPlatformImage(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_platformImage(ri, acceptance.Location()), + Config: testAccAzureRMManagedDisk_platformImage(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, }, @@ -164,8 +149,7 @@ func TestAccAzureRMManagedDisk_fromPlatformImage(t *testing.T) { } func TestAccAzureRMManagedDisk_update(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -174,24 +158,24 @@ func TestAccAzureRMManagedDisk_update(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_empty(ri, acceptance.Location()), + Config: testAccAzureRMManagedDisk_empty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "acctest"), - resource.TestCheckResourceAttr(resourceName, "tags.cost-center", "ops"), - resource.TestCheckResourceAttr(resourceName, "disk_size_gb", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_account_type", string(compute.StorageAccountTypesStandardLRS)), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "acctest"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost-center", "ops"), + resource.TestCheckResourceAttr(data.ResourceName, "disk_size_gb", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_account_type", string(compute.StorageAccountTypesStandardLRS)), ), }, { - Config: testAccAzureRMManagedDisk_empty_updated(ri, acceptance.Location()), + Config: testAccAzureRMManagedDisk_empty_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "acctest"), - resource.TestCheckResourceAttr(resourceName, "disk_size_gb", "2"), - resource.TestCheckResourceAttr(resourceName, "storage_account_type", string(compute.StorageAccountTypesPremiumLRS)), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "acctest"), + resource.TestCheckResourceAttr(data.ResourceName, "disk_size_gb", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_account_type", string(compute.StorageAccountTypesPremiumLRS)), ), }, }, @@ -199,9 +183,7 @@ func TestAccAzureRMManagedDisk_update(t *testing.T) { } func TestAccAzureRMManagedDisk_encryption(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -210,17 +192,17 @@ func TestAccAzureRMManagedDisk_encryption(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_encryption(ri, rs, acceptance.Location()), + Config: testAccAzureRMManagedDisk_encryption(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), - resource.TestCheckResourceAttr(resourceName, "encryption_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "encryption_settings.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "encryption_settings.0.disk_encryption_key.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "encryption_settings.0.disk_encryption_key.0.secret_url"), - resource.TestCheckResourceAttrSet(resourceName, "encryption_settings.0.disk_encryption_key.0.source_vault_id"), - resource.TestCheckResourceAttr(resourceName, "encryption_settings.0.key_encryption_key.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "encryption_settings.0.key_encryption_key.0.key_url"), - resource.TestCheckResourceAttrSet(resourceName, "encryption_settings.0.key_encryption_key.0.source_vault_id"), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), + resource.TestCheckResourceAttr(data.ResourceName, "encryption_settings.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "encryption_settings.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "encryption_settings.0.disk_encryption_key.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "encryption_settings.0.disk_encryption_key.0.secret_url"), + resource.TestCheckResourceAttrSet(data.ResourceName, "encryption_settings.0.disk_encryption_key.0.source_vault_id"), + resource.TestCheckResourceAttr(data.ResourceName, "encryption_settings.0.key_encryption_key.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "encryption_settings.0.key_encryption_key.0.key_url"), + resource.TestCheckResourceAttrSet(data.ResourceName, "encryption_settings.0.key_encryption_key.0.source_vault_id"), ), }, }, @@ -228,11 +210,10 @@ func TestAccAzureRMManagedDisk_encryption(t *testing.T) { } func TestAccAzureRMManagedDisk_NonStandardCasing(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk - config := testAccAzureRMManagedDiskNonStandardCasing(ri, acceptance.Location()) + config := testAccAzureRMManagedDiskNonStandardCasing(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -241,7 +222,7 @@ func TestAccAzureRMManagedDisk_NonStandardCasing(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, { @@ -254,8 +235,7 @@ func TestAccAzureRMManagedDisk_NonStandardCasing(t *testing.T) { } func TestAccAzureRMManagedDisk_importEmpty_withZone(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -264,24 +244,18 @@ func TestAccAzureRMManagedDisk_importEmpty_withZone(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_empty_withZone(ri, acceptance.Location()), + Config: testAccAzureRMManagedDisk_empty_withZone(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMManagedDisk_create_withUltraSSD(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() - location := "eastus2" + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -290,24 +264,18 @@ func TestAccAzureRMManagedDisk_create_withUltraSSD(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_create_withUltraSSD(ri, location), + Config: testAccAzureRMManagedDisk_create_withUltraSSD(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMManagedDisk_update_withUltraSSD(t *testing.T) { - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() - location := "eastus2" + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -316,19 +284,19 @@ func TestAccAzureRMManagedDisk_update_withUltraSSD(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_create_withUltraSSD(ri, location), + Config: testAccAzureRMManagedDisk_create_withUltraSSD(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), - resource.TestCheckResourceAttr(resourceName, "disk_iops_read_write", "101"), - resource.TestCheckResourceAttr(resourceName, "disk_mbps_read_write", "10"), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), + resource.TestCheckResourceAttr(data.ResourceName, "disk_iops_read_write", "101"), + resource.TestCheckResourceAttr(data.ResourceName, "disk_mbps_read_write", "10"), ), }, { - Config: testAccAzureRMManagedDisk_update_withUltraSSD(ri, location), + Config: testAccAzureRMManagedDisk_update_withUltraSSD(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), - resource.TestCheckResourceAttr(resourceName, "disk_iops_read_write", "102"), - resource.TestCheckResourceAttr(resourceName, "disk_mbps_read_write", "11"), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), + resource.TestCheckResourceAttr(data.ResourceName, "disk_iops_read_write", "102"), + resource.TestCheckResourceAttr(data.ResourceName, "disk_mbps_read_write", "11"), ), }, }, @@ -341,9 +309,7 @@ func TestAccAzureRMManagedDisk_import_withUltraSSD(t *testing.T) { return } - resourceName := "azurerm_managed_disk.test" - ri := tf.AccRandTimeInt() - location := "eastus2" + data := acceptance.BuildTestData(t, "azurerm_managed_disk", "test") var d compute.Disk resource.ParallelTest(t, resource.TestCase{ @@ -352,13 +318,13 @@ func TestAccAzureRMManagedDisk_import_withUltraSSD(t *testing.T) { CheckDestroy: testCheckAzureRMManagedDiskDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMManagedDisk_create_withUltraSSD(ri, location), + Config: testAccAzureRMManagedDisk_create_withUltraSSD(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagedDiskExists(resourceName, &d, true), + testCheckAzureRMManagedDiskExists(data.ResourceName, &d, true), ), }, { - Config: testAccAzureRMManagedDisk_import_withUltraSSD(ri, location), + Config: testAccAzureRMManagedDisk_import_withUltraSSD(data), ExpectError: acceptance.RequiresImportError("azurerm_managed_disk"), }, }, @@ -454,7 +420,7 @@ func testDeleteAzureRMVirtualMachine(resourceName string) resource.TestCheckFunc } } -func testAccAzureRMManagedDisk_empty(rInt int, location string) string { +func testAccAzureRMManagedDisk_empty(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -474,11 +440,11 @@ resource "azurerm_managed_disk" "test" { cost-center = "ops" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagedDisk_requiresImport(rInt int, location string) string { - template := testAccAzureRMManagedDisk_empty(rInt, location) +func testAccAzureRMManagedDisk_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMManagedDisk_empty(data) return fmt.Sprintf(` %s @@ -498,7 +464,7 @@ resource "azurerm_managed_disk" "import" { `, template) } -func testAccAzureRMManagedDisk_empty_withZone(rInt int, location string) string { +func testAccAzureRMManagedDisk_empty_withZone(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -519,10 +485,10 @@ resource "azurerm_managed_disk" "test" { cost-center = "ops" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagedDisk_import(rInt int, location string) string { +func testAccAzureRMManagedDisk_import(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -561,10 +527,10 @@ resource "azurerm_managed_disk" "test" { environment = "acctest" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMManagedDisk_copy(rInt int, location string) string { +func testAccAzureRMManagedDisk_copy(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -599,10 +565,10 @@ resource "azurerm_managed_disk" "test" { cost-center = "ops" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMManagedDisk_empty_updated(rInt int, location string) string { +func testAccAzureRMManagedDisk_empty_updated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -621,10 +587,10 @@ resource "azurerm_managed_disk" "test" { environment = "acctest" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagedDiskNonStandardCasing(rInt int, location string) string { +func testAccAzureRMManagedDiskNonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -644,10 +610,10 @@ resource "azurerm_managed_disk" "test" { cost-center = "ops" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagedDisk_platformImage(rInt int, location string) string { +func testAccAzureRMManagedDisk_platformImage(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_platform_image" "test" { location = "%s" @@ -670,10 +636,10 @@ resource "azurerm_managed_disk" "test" { image_reference_id = "${data.azurerm_platform_image.test.id}" storage_account_type = "Standard_LRS" } -`, location, rInt, location, rInt) +`, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagedDisk_zeroGbFromPlatformImage(rInt int, location string) string { +func testAccAzureRMManagedDisk_zeroGbFromPlatformImage(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_platform_image" "test" { location = "%s" @@ -697,10 +663,10 @@ resource "azurerm_managed_disk" "test" { image_reference_id = "${data.azurerm_platform_image.test.id}" storage_account_type = "Standard_LRS" } -`, location, rInt, location, rInt) +`, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagedDisk_encryption(rInt int, rString string, location string) string { +func testAccAzureRMManagedDisk_encryption(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -788,10 +754,10 @@ resource "azurerm_managed_disk" "test" { cost-center = "ops" } } -`, rInt, location, rString, rString, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString, data.RandomInteger) } -func testAccAzureRMManagedDisk_create_withUltraSSD(rInt int, location string) string { +func testAccAzureRMManagedDisk_create_withUltraSSD(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -814,10 +780,10 @@ resource "azurerm_managed_disk" "test" { cost-center = "ops" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagedDisk_update_withUltraSSD(rInt int, location string) string { +func testAccAzureRMManagedDisk_update_withUltraSSD(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -840,11 +806,11 @@ resource "azurerm_managed_disk" "test" { cost-center = "ops" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMManagedDisk_import_withUltraSSD(rInt int, location string) string { - template := testAccAzureRMManagedDisk_create_withUltraSSD(rInt, location) +func testAccAzureRMManagedDisk_import_withUltraSSD(data acceptance.TestData) string { + template := testAccAzureRMManagedDisk_create_withUltraSSD(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/compute/resource_arm_marketplace_agreement_test.go b/azurerm/internal/services/compute/tests/resource_arm_marketplace_agreement_test.go similarity index 89% rename from azurerm/internal/services/compute/resource_arm_marketplace_agreement_test.go rename to azurerm/internal/services/compute/tests/resource_arm_marketplace_agreement_test.go index d3b2c835395b..4db65cb107ed 100644 --- a/azurerm/internal/services/compute/resource_arm_marketplace_agreement_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_marketplace_agreement_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -34,7 +34,7 @@ func TestAccAzureRMMarketplaceAgreement(t *testing.T) { } func testAccAzureRMMarketplaceAgreement_basic(t *testing.T) { - resourceName := "azurerm_marketplace_agreement.test" + data := acceptance.BuildTestData(t, "azurerm_marketplace_agreement", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -44,16 +44,12 @@ func testAccAzureRMMarketplaceAgreement_basic(t *testing.T) { { Config: testAccAzureRMMarketplaceAgreement_basicConfig(), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMarketplaceAgreementExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "license_text_link"), - resource.TestCheckResourceAttrSet(resourceName, "privacy_policy_link"), + testCheckAzureRMMarketplaceAgreementExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "license_text_link"), + resource.TestCheckResourceAttrSet(data.ResourceName, "privacy_policy_link"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -64,7 +60,7 @@ func testAccAzureRMMarketplaceAgreement_requiresImport(t *testing.T) { return } - resourceName := "azurerm_marketplace_agreement.test" + data := acceptance.BuildTestData(t, "azurerm_marketplace_agreement", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,7 +70,7 @@ func testAccAzureRMMarketplaceAgreement_requiresImport(t *testing.T) { { Config: testAccAzureRMMarketplaceAgreement_basicConfig(), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMarketplaceAgreementExists(resourceName), + testCheckAzureRMMarketplaceAgreementExists(data.ResourceName), ), }, { diff --git a/azurerm/internal/services/compute/resource_arm_proximity_placement_group_test.go b/azurerm/internal/services/compute/tests/resource_arm_proximity_placement_group_test.go similarity index 73% rename from azurerm/internal/services/compute/resource_arm_proximity_placement_group_test.go rename to azurerm/internal/services/compute/tests/resource_arm_proximity_placement_group_test.go index 923520b8f0dc..7f23293c7e5e 100644 --- a/azurerm/internal/services/compute/resource_arm_proximity_placement_group_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_proximity_placement_group_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,8 @@ import ( ) func TestAccProximityPlacementGroup_basic(t *testing.T) { - resourceName := "azurerm_proximity_placement_group.test" - ri := tf.AccRandTimeInt() - config := testAccProximityPlacementGroup_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_proximity_placement_group", "test") + config := testAccProximityPlacementGroup_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,14 +25,10 @@ func TestAccProximityPlacementGroup_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMProximityPlacementGroupExists(resourceName), + testCheckAzureRMProximityPlacementGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,9 +39,7 @@ func TestAccProximityPlacementGroup_requiresImport(t *testing.T) { return } - resourceName := "azurerm_proximity_placement_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_proximity_placement_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,13 +47,13 @@ func TestAccProximityPlacementGroup_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMProximityPlacementGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccProximityPlacementGroup_basic(ri, location), + Config: testAccProximityPlacementGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMProximityPlacementGroupExists(resourceName), + testCheckAzureRMProximityPlacementGroupExists(data.ResourceName), ), }, { - Config: testAccProximityPlacementGroup_requiresImport(ri, location), + Config: testAccProximityPlacementGroup_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_proximity_placement_group"), }, }, @@ -69,9 +61,8 @@ func TestAccProximityPlacementGroup_requiresImport(t *testing.T) { } func TestAccProximityPlacementGroup_disappears(t *testing.T) { - resourceName := "azurerm_proximity_placement_group.test" - ri := tf.AccRandTimeInt() - config := testAccProximityPlacementGroup_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_proximity_placement_group", "test") + config := testAccProximityPlacementGroup_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,8 +72,8 @@ func TestAccProximityPlacementGroup_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMProximityPlacementGroupExists(resourceName), - testCheckAzureRMProximityPlacementGroupDisappears(resourceName), + testCheckAzureRMProximityPlacementGroupExists(data.ResourceName), + testCheckAzureRMProximityPlacementGroupDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -91,11 +82,9 @@ func TestAccProximityPlacementGroup_disappears(t *testing.T) { } func TestAccProximityPlacementGroup_withTags(t *testing.T) { - resourceName := "azurerm_proximity_placement_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccProximityPlacementGroup_withTags(ri, location) - postConfig := testAccProximityPlacementGroup_withUpdatedTags(ri, location) + data := acceptance.BuildTestData(t, "azurerm_proximity_placement_group", "test") + preConfig := testAccProximityPlacementGroup_withTags(data) + postConfig := testAccProximityPlacementGroup_withUpdatedTags(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -105,25 +94,21 @@ func TestAccProximityPlacementGroup_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMProximityPlacementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMProximityPlacementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMProximityPlacementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMProximityPlacementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -210,7 +195,7 @@ func testCheckAzureRMProximityPlacementGroupDestroy(s *terraform.State) error { return nil } -func testAccProximityPlacementGroup_basic(rInt int, location string) string { +func testAccProximityPlacementGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -222,11 +207,11 @@ resource "azurerm_proximity_placement_group" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccProximityPlacementGroup_requiresImport(rInt int, location string) string { - template := testAccProximityPlacementGroup_basic(rInt, location) +func testAccProximityPlacementGroup_requiresImport(data acceptance.TestData) string { + template := testAccProximityPlacementGroup_basic(data) return fmt.Sprintf(` %s @@ -238,7 +223,7 @@ resource "azurerm_proximity_placement_group" "import" { `, template) } -func testAccProximityPlacementGroup_withTags(rInt int, location string) string { +func testAccProximityPlacementGroup_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -255,10 +240,10 @@ resource "azurerm_proximity_placement_group" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccProximityPlacementGroup_withUpdatedTags(rInt int, location string) string { +func testAccProximityPlacementGroup_withUpdatedTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -274,5 +259,5 @@ resource "azurerm_proximity_placement_group" "test" { environment = "staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_shared_image_gallery_test.go b/azurerm/internal/services/compute/tests/resource_arm_shared_image_gallery_test.go similarity index 72% rename from azurerm/internal/services/compute/resource_arm_shared_image_gallery_test.go rename to azurerm/internal/services/compute/tests/resource_arm_shared_image_gallery_test.go index ace54dd33144..ba573edaaeaf 100644 --- a/azurerm/internal/services/compute/resource_arm_shared_image_gallery_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_shared_image_gallery_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,7 @@ import ( ) func TestAccAzureRMSharedImageGallery_basic(t *testing.T) { - resourceName := "azurerm_shared_image_gallery.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_shared_image_gallery", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,17 +22,13 @@ func TestAccAzureRMSharedImageGallery_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSharedImageGalleryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSharedImageGallery_basic(ri, location), + Config: testAccAzureRMSharedImageGallery_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageGalleryExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", ""), + testCheckAzureRMSharedImageGalleryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,8 +37,7 @@ func TestAccAzureRMSharedImageGallery_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_shared_image_gallery.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_shared_image_gallery", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,14 +45,14 @@ func TestAccAzureRMSharedImageGallery_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSharedImageGalleryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSharedImageGallery_basic(ri, acceptance.Location()), + Config: testAccAzureRMSharedImageGallery_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageGalleryExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", ""), + testCheckAzureRMSharedImageGalleryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), ), }, { - Config: testAccAzureRMSharedImageGallery_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMSharedImageGallery_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_shared_image_gallery"), }, }, @@ -68,8 +60,7 @@ func TestAccAzureRMSharedImageGallery_requiresImport(t *testing.T) { } func TestAccAzureRMSharedImageGallery_complete(t *testing.T) { - resourceName := "azurerm_shared_image_gallery.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_shared_image_gallery", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -77,20 +68,16 @@ func TestAccAzureRMSharedImageGallery_complete(t *testing.T) { CheckDestroy: testCheckAzureRMSharedImageGalleryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSharedImageGallery_complete(ri, acceptance.Location()), + Config: testAccAzureRMSharedImageGallery_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageGalleryExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "Shared images and things."), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.Hello", "There"), - resource.TestCheckResourceAttr(resourceName, "tags.World", "Example"), + testCheckAzureRMSharedImageGalleryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "Shared images and things."), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "There"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.World", "Example"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -153,7 +140,7 @@ func testCheckAzureRMSharedImageGalleryExists(resourceName string) resource.Test } } -func testAccAzureRMSharedImageGallery_basic(rInt int, location string) string { +func testAccAzureRMSharedImageGallery_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -165,10 +152,10 @@ resource "azurerm_shared_image_gallery" "test" { resource_group_name = "${azurerm_resource_group.test.name}" location = "${azurerm_resource_group.test.location}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMSharedImageGallery_requiresImport(rInt int, location string) string { +func testAccAzureRMSharedImageGallery_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -177,10 +164,10 @@ resource "azurerm_shared_image_gallery" "import" { resource_group_name = "${azurerm_shared_image_gallery.test.resource_group_name}" location = "${azurerm_shared_image_gallery.test.location}" } -`, testAccAzureRMSharedImageGallery_basic(rInt, location)) +`, testAccAzureRMSharedImageGallery_basic(data)) } -func testAccAzureRMSharedImageGallery_complete(rInt int, location string) string { +func testAccAzureRMSharedImageGallery_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -198,5 +185,5 @@ resource "azurerm_shared_image_gallery" "test" { World = "Example" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_shared_image_version_test.go b/azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go similarity index 67% rename from azurerm/internal/services/compute/resource_arm_shared_image_version_test.go rename to azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go index 8ec44953442e..52ebb5644cfe 100644 --- a/azurerm/internal/services/compute/resource_arm_shared_image_version_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,13 +14,12 @@ import ( ) func TestAccAzureRMSharedImageVersion_basic(t *testing.T) { - resourceName := "azurerm_shared_image_version.test" + data := acceptance.BuildTestData(t, "azurerm_shared_image_version", "test") - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" resource.ParallelTest(t, resource.TestCase{ @@ -31,7 +29,7 @@ func TestAccAzureRMSharedImageVersion_basic(t *testing.T) { Steps: []resource.TestStep{ { // need to create a vm and then reference it in the image creation - Config: testAccAzureRMSharedImageVersion_setup(ri, acceptance.Location(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_setup(data, userName, password, hostName), Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), @@ -39,39 +37,34 @@ func TestAccAzureRMSharedImageVersion_basic(t *testing.T) { ), }, { - Config: testAccAzureRMSharedImageVersion_imageVersion(ri, acceptance.Location(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_imageVersion(data, userName, password, hostName), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageVersionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), - resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), + testCheckAzureRMSharedImageVersionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_image_id"), + resource.TestCheckResourceAttr(data.ResourceName, "target_region.#", "1"), ), }, { - Config: testAccAzureRMSharedImageVersion_imageVersionUpdated(ri, acceptance.Location(), acceptance.AltLocation(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_imageVersionUpdated(data, userName, password, hostName), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageVersionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), - resource.TestCheckResourceAttr(resourceName, "target_region.#", "2"), - resource.TestCheckResourceAttr(resourceName, "name", "1234567890.1234567890.1234567890"), + testCheckAzureRMSharedImageVersionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_image_id"), + resource.TestCheckResourceAttr(data.ResourceName, "target_region.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "name", "1234567890.1234567890.1234567890"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSharedImageVersion_storageAccountTypeLrs(t *testing.T) { - resourceName := "azurerm_shared_image_version.test" + data := acceptance.BuildTestData(t, "azurerm_shared_image_version", "test") - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" resource.ParallelTest(t, resource.TestCase{ @@ -81,7 +74,7 @@ func TestAccAzureRMSharedImageVersion_storageAccountTypeLrs(t *testing.T) { Steps: []resource.TestStep{ { // need to create a vm and then reference it in the image creation - Config: testAccAzureRMSharedImageVersion_setup(ri, acceptance.Location(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_setup(data, userName, password, hostName), Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), @@ -89,30 +82,25 @@ func TestAccAzureRMSharedImageVersion_storageAccountTypeLrs(t *testing.T) { ), }, { - Config: testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(ri, acceptance.Location(), userName, password, hostName, "Standard_LRS"), + Config: testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(data, userName, password, hostName, "Standard_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageVersionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), - resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), + testCheckAzureRMSharedImageVersionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_image_id"), + resource.TestCheckResourceAttr(data.ResourceName, "target_region.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSharedImageVersion_storageAccountTypeZrs(t *testing.T) { - resourceName := "azurerm_shared_image_version.test" + data := acceptance.BuildTestData(t, "azurerm_shared_image_version", "test") - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" resource.ParallelTest(t, resource.TestCase{ @@ -122,7 +110,7 @@ func TestAccAzureRMSharedImageVersion_storageAccountTypeZrs(t *testing.T) { Steps: []resource.TestStep{ { // need to create a vm and then reference it in the image creation - Config: testAccAzureRMSharedImageVersion_setup(ri, acceptance.Location(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_setup(data, userName, password, hostName), Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), @@ -130,18 +118,14 @@ func TestAccAzureRMSharedImageVersion_storageAccountTypeZrs(t *testing.T) { ), }, { - Config: testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(ri, acceptance.Location(), userName, password, hostName, "Standard_ZRS"), + Config: testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(data, userName, password, hostName, "Standard_ZRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageVersionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), - resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), + testCheckAzureRMSharedImageVersionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_image_id"), + resource.TestCheckResourceAttr(data.ResourceName, "target_region.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -151,13 +135,12 @@ func TestAccAzureRMSharedImageVersion_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_shared_image_version.test" + data := acceptance.BuildTestData(t, "azurerm_shared_image_version", "test") - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) userName := "testadmin" password := "Password1234!" - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" resource.ParallelTest(t, resource.TestCase{ @@ -167,7 +150,7 @@ func TestAccAzureRMSharedImageVersion_requiresImport(t *testing.T) { Steps: []resource.TestStep{ { // need to create a vm and then reference it in the image creation - Config: testAccAzureRMSharedImageVersion_setup(ri, acceptance.Location(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_setup(data, userName, password, hostName), Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), @@ -175,15 +158,15 @@ func TestAccAzureRMSharedImageVersion_requiresImport(t *testing.T) { ), }, { - Config: testAccAzureRMSharedImageVersion_imageVersion(ri, acceptance.Location(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_imageVersion(data, userName, password, hostName), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageVersionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "managed_image_id"), - resource.TestCheckResourceAttr(resourceName, "target_region.#", "1"), + testCheckAzureRMSharedImageVersionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_image_id"), + resource.TestCheckResourceAttr(data.ResourceName, "target_region.#", "1"), ), }, { - Config: testAccAzureRMSharedImageVersion_requiresImport(ri, acceptance.Location(), userName, password, hostName), + Config: testAccAzureRMSharedImageVersion_requiresImport(data, userName, password, hostName), ExpectError: acceptance.RequiresImportError("azurerm_shared_image_version"), }, }, @@ -251,12 +234,12 @@ func testCheckAzureRMSharedImageVersionExists(resourceName string) resource.Test } } -func testAccAzureRMSharedImageVersion_setup(rInt int, location, username, password, hostname string) string { - return testAccAzureRMImage_standaloneImage_setup(rInt, username, password, hostname, location, "LRS") +func testAccAzureRMSharedImageVersion_setup(data acceptance.TestData, username, password, hostname string) string { + return testAccAzureRMImage_standaloneImage_setup(data, username, password, hostname, "LRS") } -func testAccAzureRMSharedImageVersion_provision(rInt int, location, username, password, hostname string) string { - template := testAccAzureRMImage_standaloneImage_provision(rInt, username, password, hostname, location, "LRS", "") +func testAccAzureRMSharedImageVersion_provision(data acceptance.TestData, username, password, hostname string) string { + template := testAccAzureRMImage_standaloneImage_provision(data, username, password, hostname, "LRS", "") return fmt.Sprintf(` %s @@ -279,11 +262,11 @@ resource "azurerm_shared_image" "test" { sku = "AccTesSku%d" } } -`, template, rInt, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSharedImageVersion_imageVersion(rInt int, location, username, password, hostname string) string { - template := testAccAzureRMSharedImageVersion_provision(rInt, location, username, password, hostname) +func testAccAzureRMSharedImageVersion_imageVersion(data acceptance.TestData, username, password, hostname string) string { + template := testAccAzureRMSharedImageVersion_provision(data, username, password, hostname) return fmt.Sprintf(` %s @@ -303,8 +286,8 @@ resource "azurerm_shared_image_version" "test" { `, template) } -func testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(rInt int, location, username, password, hostname string, storageAccountType string) string { - template := testAccAzureRMSharedImageVersion_provision(rInt, location, username, password, hostname) +func testAccAzureRMSharedImageVersion_imageVersionStorageAccountType(data acceptance.TestData, username, password, hostname string, storageAccountType string) string { + template := testAccAzureRMSharedImageVersion_provision(data, username, password, hostname) return fmt.Sprintf(` %s @@ -325,7 +308,7 @@ resource "azurerm_shared_image_version" "test" { `, template, storageAccountType) } -func testAccAzureRMSharedImageVersion_requiresImport(rInt int, location, username, password, hostname string) string { +func testAccAzureRMSharedImageVersion_requiresImport(data acceptance.TestData, username, password, hostname string) string { return fmt.Sprintf(` %s @@ -342,11 +325,11 @@ resource "azurerm_shared_image_version" "import" { regional_replica_count = 1 } } -`, testAccAzureRMSharedImageVersion_imageVersion(rInt, location, username, password, hostname)) +`, testAccAzureRMSharedImageVersion_imageVersion(data, username, password, hostname)) } -func testAccAzureRMSharedImageVersion_imageVersionUpdated(rInt int, location, altLocation, username, password, hostname string) string { - template := testAccAzureRMSharedImageVersion_provision(rInt, location, username, password, hostname) +func testAccAzureRMSharedImageVersion_imageVersionUpdated(data acceptance.TestData, username, password, hostname string) string { + template := testAccAzureRMSharedImageVersion_provision(data, username, password, hostname) return fmt.Sprintf(` %s @@ -368,5 +351,5 @@ resource "azurerm_shared_image_version" "test" { regional_replica_count = 2 } } -`, template, altLocation) +`, template, data.Locations.Secondary) } diff --git a/azurerm/internal/services/compute/resource_arm_snapshot_test.go b/azurerm/internal/services/compute/tests/resource_arm_snapshot_test.go similarity index 83% rename from azurerm/internal/services/compute/resource_arm_snapshot_test.go rename to azurerm/internal/services/compute/tests/resource_arm_snapshot_test.go index 7ba7b9e990cc..74eac579643f 100644 --- a/azurerm/internal/services/compute/resource_arm_snapshot_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_snapshot_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -7,10 +7,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -55,7 +55,7 @@ func TestSnapshotName_validation(t *testing.T) { } for _, tc := range cases { - _, errors := validateSnapshotName(tc.Value, "azurerm_snapshot") + _, errors := compute.ValidateSnapshotName(tc.Value, "azurerm_snapshot") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Snapshot Name to trigger a validation error for '%s'", tc.Value) @@ -63,8 +63,7 @@ func TestSnapshotName_validation(t *testing.T) { } } func TestAccAzureRMSnapshot_fromManagedDisk(t *testing.T) { - resourceName := "azurerm_snapshot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_snapshot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -72,17 +71,12 @@ func TestAccAzureRMSnapshot_fromManagedDisk(t *testing.T) { CheckDestroy: testCheckAzureRMSnapshotDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSnapshot_fromManagedDisk(ri, acceptance.Location()), + Config: testAccAzureRMSnapshot_fromManagedDisk(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSnapshotExists(resourceName), + testCheckAzureRMSnapshotExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"source_uri"}, - }, + data.ImportStep("source_uri"), }, }) } @@ -91,8 +85,7 @@ func TestAccAzureRMSnapshot_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_snapshot.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_snapshot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -100,13 +93,13 @@ func TestAccAzureRMSnapshot_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSnapshotDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSnapshot_fromManagedDisk(ri, acceptance.Location()), + Config: testAccAzureRMSnapshot_fromManagedDisk(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSnapshotExists(resourceName), + testCheckAzureRMSnapshotExists(data.ResourceName), ), }, { - Config: testAccAzureRMSnapshot_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMSnapshot_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_snapshot"), }, }, @@ -114,10 +107,7 @@ func TestAccAzureRMSnapshot_requiresImport(t *testing.T) { } func TestAccAzureRMSnapshot_encryption(t *testing.T) { - resourceName := "azurerm_snapshot.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - config := testAccAzureRMSnapshot_encryption(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_snapshot", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -125,26 +115,20 @@ func TestAccAzureRMSnapshot_encryption(t *testing.T) { CheckDestroy: testCheckAzureRMSnapshotDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMSnapshot_encryption(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSnapshotExists(resourceName), + testCheckAzureRMSnapshotExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"source_uri"}, - }, + data.ImportStep("source_uri"), }, }) } func TestAccAzureRMSnapshot_update(t *testing.T) { - resourceName := "azurerm_snapshot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSnapshot_fromManagedDisk(ri, acceptance.Location()) - updatedConfig := testAccAzureRMSnapshot_fromManagedDiskUpdated(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_snapshot", "test") + config := testAccAzureRMSnapshot_fromManagedDisk(data) + updatedConfig := testAccAzureRMSnapshot_fromManagedDiskUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -154,13 +138,13 @@ func TestAccAzureRMSnapshot_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSnapshotExists(resourceName), + testCheckAzureRMSnapshotExists(data.ResourceName), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSnapshotExists(resourceName), + testCheckAzureRMSnapshotExists(data.ResourceName), ), }, }, @@ -168,9 +152,8 @@ func TestAccAzureRMSnapshot_update(t *testing.T) { } func TestAccAzureRMSnapshot_extendingManagedDisk(t *testing.T) { - resourceName := "azurerm_snapshot.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSnapshot_extendingManagedDisk(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_snapshot", "test") + config := testAccAzureRMSnapshot_extendingManagedDisk(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -180,7 +163,7 @@ func TestAccAzureRMSnapshot_extendingManagedDisk(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSnapshotExists(resourceName), + testCheckAzureRMSnapshotExists(data.ResourceName), ), }, }, @@ -188,9 +171,8 @@ func TestAccAzureRMSnapshot_extendingManagedDisk(t *testing.T) { } func TestAccAzureRMSnapshot_fromExistingSnapshot(t *testing.T) { - resourceName := "azurerm_snapshot.second" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSnapshot_fromExistingSnapshot(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_snapshot", "second") + config := testAccAzureRMSnapshot_fromExistingSnapshot(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -200,7 +182,7 @@ func TestAccAzureRMSnapshot_fromExistingSnapshot(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSnapshotExists(resourceName), + testCheckAzureRMSnapshotExists(data.ResourceName), ), }, }, @@ -208,10 +190,8 @@ func TestAccAzureRMSnapshot_fromExistingSnapshot(t *testing.T) { } func TestAccAzureRMSnapshot_fromUnmanagedDisk(t *testing.T) { - resourceName := "azurerm_snapshot.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - config := testAccAzureRMSnapshot_fromUnmanagedDisk(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_snapshot", "test") + config := testAccAzureRMSnapshot_fromUnmanagedDisk(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -221,7 +201,7 @@ func TestAccAzureRMSnapshot_fromUnmanagedDisk(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSnapshotExists(resourceName), + testCheckAzureRMSnapshotExists(data.ResourceName), ), }, }, @@ -283,7 +263,7 @@ func testCheckAzureRMSnapshotExists(resourceName string) resource.TestCheckFunc } } -func testAccAzureRMSnapshot_fromManagedDisk(rInt int, location string) string { +func testAccAzureRMSnapshot_fromManagedDisk(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -306,10 +286,10 @@ resource "azurerm_snapshot" "test" { create_option = "Copy" source_uri = "${azurerm_managed_disk.test.id}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSnapshot_requiresImport(rInt int, location string) string { +func testAccAzureRMSnapshot_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -320,10 +300,10 @@ resource "azurerm_snapshot" "import" { create_option = "${azurerm_snapshot.test.create_option}" source_uri = "${azurerm_snapshot.test.source_uri}" } -`, testAccAzureRMSnapshot_fromManagedDisk(rInt, location)) +`, testAccAzureRMSnapshot_fromManagedDisk(data)) } -func testAccAzureRMSnapshot_fromManagedDiskUpdated(rInt int, location string) string { +func testAccAzureRMSnapshot_fromManagedDiskUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -350,10 +330,10 @@ resource "azurerm_snapshot" "test" { Hello = "World" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSnapshot_encryption(rInt int, rString string, location string) string { +func testAccAzureRMSnapshot_encryption(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -445,10 +425,10 @@ resource "azurerm_snapshot" "test" { } } } -`, rInt, location, rInt, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger) } -func testAccAzureRMSnapshot_extendingManagedDisk(rInt int, location string) string { +func testAccAzureRMSnapshot_extendingManagedDisk(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -472,10 +452,10 @@ resource "azurerm_snapshot" "test" { source_uri = "${azurerm_managed_disk.test.id}" disk_size_gb = "20" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSnapshot_fromExistingSnapshot(rInt int, location string) string { +func testAccAzureRMSnapshot_fromExistingSnapshot(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -506,10 +486,10 @@ resource "azurerm_snapshot" "second" { create_option = "Copy" source_resource_id = "${azurerm_snapshot.first.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSnapshot_fromUnmanagedDisk(rInt int, rString string, location string) string { +func testAccAzureRMSnapshot_fromUnmanagedDisk(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -604,7 +584,7 @@ resource "azurerm_snapshot" "test" { resource_group_name = "${azurerm_resource_group.test.name}" create_option = "Import" source_uri = "${azurerm_storage_account.test.primary_blob_endpoint}${azurerm_storage_container.test.name}/myosdisk1.vhd" - depends_on = ["azurerm_virtual_machine.test"] + depends_on = ["azurerm_virtual_machine", "test")] } -`, rInt, location, rInt, rInt, rString, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_virtual_machine_data_disk_attachment_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_data_disk_attachment_test.go similarity index 81% rename from azurerm/internal/services/compute/resource_arm_virtual_machine_data_disk_attachment_test.go rename to azurerm/internal/services/compute/tests/resource_arm_virtual_machine_data_disk_attachment_test.go index 3b0eadb2577d..4551578067b9 100644 --- a/azurerm/internal/services/compute/resource_arm_virtual_machine_data_disk_attachment_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_data_disk_attachment_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,10 +15,8 @@ import ( ) func TestAccAzureRMVirtualMachineDataDiskAttachment_basic(t *testing.T) { - resourceName := "azurerm_virtual_machine_data_disk_attachment.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMVirtualMachineDataDiskAttachment_basic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_data_disk_attachment", "test") + config := testAccAzureRMVirtualMachineDataDiskAttachment_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -28,18 +25,14 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "virtual_machine_id"), - resource.TestCheckResourceAttrSet(resourceName, "managed_disk_id"), - resource.TestCheckResourceAttr(resourceName, "lun", "0"), - resource.TestCheckResourceAttr(resourceName, "caching", "None"), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_machine_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_disk_id"), + resource.TestCheckResourceAttr(data.ResourceName, "lun", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "caching", "None"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -50,22 +43,20 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_requiresImport(t *testing.T) return } - resourceName := "azurerm_virtual_machine_data_disk_attachment.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_data_disk_attachment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineDataDiskAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineDataDiskAttachment_basic(ri, location), + Config: testAccAzureRMVirtualMachineDataDiskAttachment_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), ), }, { - Config: testAccAzureRMVirtualMachineDataDiskAttachment_requiresImport(ri, location), + Config: testAccAzureRMVirtualMachineDataDiskAttachment_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_virtual_machine_data_disk_attachment"), }, }, @@ -73,11 +64,10 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_requiresImport(t *testing.T) } func TestAccAzureRMVirtualMachineDataDiskAttachment_multipleDisks(t *testing.T) { - firstResourceName := "azurerm_virtual_machine_data_disk_attachment.first" + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_data_disk_attachment", "test") + secondResourceName := "azurerm_virtual_machine_data_disk_attachment.second" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMVirtualMachineDataDiskAttachment_multipleDisks(ri, location) + config := testAccAzureRMVirtualMachineDataDiskAttachment_multipleDisks(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -86,11 +76,11 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_multipleDisks(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(firstResourceName), - resource.TestCheckResourceAttrSet(firstResourceName, "virtual_machine_id"), - resource.TestCheckResourceAttrSet(firstResourceName, "managed_disk_id"), - resource.TestCheckResourceAttr(firstResourceName, "lun", "10"), - resource.TestCheckResourceAttr(firstResourceName, "caching", "None"), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_machine_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_disk_id"), + resource.TestCheckResourceAttr(data.ResourceName, "lun", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "caching", "None"), testCheckAzureRMVirtualMachineDataDiskAttachmentExists(secondResourceName), resource.TestCheckResourceAttrSet(secondResourceName, "virtual_machine_id"), @@ -99,11 +89,7 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_multipleDisks(t *testing.T) resource.TestCheckResourceAttr(secondResourceName, "caching", "ReadOnly"), ), }, - { - ResourceName: firstResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { ResourceName: secondResourceName, ImportState: true, @@ -114,33 +100,31 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_multipleDisks(t *testing.T) } func TestAccAzureRMVirtualMachineDataDiskAttachment_updatingCaching(t *testing.T) { - resourceName := "azurerm_virtual_machine_data_disk_attachment.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_data_disk_attachment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineDataDiskAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineDataDiskAttachment_basic(ri, location), + Config: testAccAzureRMVirtualMachineDataDiskAttachment_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "caching", "None"), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "caching", "None"), ), }, { - Config: testAccAzureRMVirtualMachineDataDiskAttachment_readOnly(ri, location), + Config: testAccAzureRMVirtualMachineDataDiskAttachment_readOnly(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "caching", "ReadOnly"), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "caching", "ReadOnly"), ), }, { - Config: testAccAzureRMVirtualMachineDataDiskAttachment_readWrite(ri, location), + Config: testAccAzureRMVirtualMachineDataDiskAttachment_readWrite(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "caching", "ReadWrite"), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "caching", "ReadWrite"), ), }, }, @@ -148,33 +132,31 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_updatingCaching(t *testing.T } func TestAccAzureRMVirtualMachineDataDiskAttachment_updatingWriteAccelerator(t *testing.T) { - resourceName := "azurerm_virtual_machine_data_disk_attachment.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_data_disk_attachment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineDataDiskAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(ri, location, false), + Config: testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "write_accelerator_enabled", "false"), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "write_accelerator_enabled", "false"), ), }, { - Config: testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(ri, location, true), + Config: testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "write_accelerator_enabled", "true"), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "write_accelerator_enabled", "true"), ), }, { - Config: testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(ri, location, false), + Config: testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "write_accelerator_enabled", "false"), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "write_accelerator_enabled", "false"), ), }, }, @@ -182,10 +164,8 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_updatingWriteAccelerator(t * } func TestAccAzureRMVirtualMachineDataDiskAttachment_managedServiceIdentity(t *testing.T) { - resourceName := "azurerm_virtual_machine_data_disk_attachment.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMVirtualMachineDataDiskAttachment_managedServiceIdentity(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_data_disk_attachment", "test") + config := testAccAzureRMVirtualMachineDataDiskAttachment_managedServiceIdentity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -194,40 +174,34 @@ func TestAccAzureRMVirtualMachineDataDiskAttachment_managedServiceIdentity(t *te { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "virtual_machine_id"), - resource.TestCheckResourceAttrSet(resourceName, "managed_disk_id"), - resource.TestCheckResourceAttr(resourceName, "lun", "0"), - resource.TestCheckResourceAttr(resourceName, "caching", "None"), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_machine_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_disk_id"), + resource.TestCheckResourceAttr(data.ResourceName, "lun", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "caching", "None"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtension(t *testing.T) { - resourceName := "azurerm_virtual_machine_data_disk_attachment.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_data_disk_attachment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineDataDiskAttachmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionPrep(ri, location), + Config: testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionPrep(data), }, { - Config: testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionComplete(ri, location), + Config: testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionComplete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineDataDiskAttachmentExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "virtual_machine_id"), - resource.TestCheckResourceAttrSet(resourceName, "managed_disk_id"), + testCheckAzureRMVirtualMachineDataDiskAttachmentExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_machine_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_disk_id"), ), }, }, @@ -328,8 +302,8 @@ func testCheckAzureRMVirtualMachineDataDiskAttachmentDestroy(s *terraform.State) return nil } -func testAccAzureRMVirtualMachineDataDiskAttachment_basic(rInt int, location string) string { - template := testAccAzureRMVirtualMachineDataDiskAttachment_template(rInt, location) +func testAccAzureRMVirtualMachineDataDiskAttachment_basic(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineDataDiskAttachment_template(data) return fmt.Sprintf(` %s @@ -342,8 +316,8 @@ resource "azurerm_virtual_machine_data_disk_attachment" "test" { `, template) } -func testAccAzureRMVirtualMachineDataDiskAttachment_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualMachineDataDiskAttachment_basic(rInt, location) +func testAccAzureRMVirtualMachineDataDiskAttachment_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineDataDiskAttachment_basic(data) return fmt.Sprintf(` %s @@ -356,7 +330,7 @@ resource "azurerm_virtual_machine_data_disk_attachment" "import" { `, template) } -func testAccAzureRMVirtualMachineDataDiskAttachment_managedServiceIdentity(rInt int, location string) string { +func testAccAzureRMVirtualMachineDataDiskAttachment_managedServiceIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -440,11 +414,11 @@ resource "azurerm_virtual_machine_data_disk_attachment" "test" { lun = "0" caching = "None" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineDataDiskAttachment_multipleDisks(rInt int, location string) string { - template := testAccAzureRMVirtualMachineDataDiskAttachment_template(rInt, location) +func testAccAzureRMVirtualMachineDataDiskAttachment_multipleDisks(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineDataDiskAttachment_template(data) return fmt.Sprintf(` %s @@ -470,11 +444,11 @@ resource "azurerm_virtual_machine_data_disk_attachment" "second" { lun = "20" caching = "ReadOnly" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualMachineDataDiskAttachment_readOnly(rInt int, location string) string { - template := testAccAzureRMVirtualMachineDataDiskAttachment_template(rInt, location) +func testAccAzureRMVirtualMachineDataDiskAttachment_readOnly(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineDataDiskAttachment_template(data) return fmt.Sprintf(` %s @@ -487,8 +461,8 @@ resource "azurerm_virtual_machine_data_disk_attachment" "test" { `, template) } -func testAccAzureRMVirtualMachineDataDiskAttachment_readWrite(rInt int, location string) string { - template := testAccAzureRMVirtualMachineDataDiskAttachment_template(rInt, location) +func testAccAzureRMVirtualMachineDataDiskAttachment_readWrite(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineDataDiskAttachment_template(data) return fmt.Sprintf(` %s @@ -501,7 +475,7 @@ resource "azurerm_virtual_machine_data_disk_attachment" "test" { `, template) } -func testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(rInt int, location string, enabled bool) string { +func testAccAzureRMVirtualMachineDataDiskAttachment_writeAccelerator(data acceptance.TestData, enabled bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -582,10 +556,10 @@ resource "azurerm_virtual_machine_data_disk_attachment" "test" { caching = "None" write_accelerator_enabled = %t } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, enabled) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, enabled) } -func testAccAzureRMVirtualMachineDataDiskAttachment_template(rInt int, location string) string { +func testAccAzureRMVirtualMachineDataDiskAttachment_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -658,10 +632,10 @@ resource "azurerm_managed_disk" "test" { create_option = "Empty" disk_size_gb = 10 } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionPrep(rInt int, location string) string { +func testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionPrep(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG%d" @@ -760,11 +734,11 @@ SETTINGS environment = "Production" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionComplete(rInt int, location string) string { - template := testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionPrep(rInt, location) +func testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionComplete(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineDataDiskAttachment_virtualMachineExtensionPrep(data) return fmt.Sprintf(` %s @@ -783,5 +757,5 @@ resource "azurerm_virtual_machine_data_disk_attachment" "test" { lun = "11" caching = "ReadWrite" } -`, template, rInt) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_virtual_machine_extension_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_extension_test.go similarity index 87% rename from azurerm/internal/services/compute/resource_arm_virtual_machine_extension_test.go rename to azurerm/internal/services/compute/tests/resource_arm_virtual_machine_extension_test.go index 5e7efd4296ff..7b245c7aa378 100644 --- a/azurerm/internal/services/compute/resource_arm_virtual_machine_extension_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_extension_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -8,18 +8,15 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMVirtualMachineExtension_basic(t *testing.T) { - resourceName := "azurerm_virtual_machine_extension.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMVirtualMachineExtension_basic(ri, location) - postConfig := testAccAzureRMVirtualMachineExtension_basicUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_extension", "test") + preConfig := testAccAzureRMVirtualMachineExtension_basic(data) + postConfig := testAccAzureRMVirtualMachineExtension_basicUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,21 +26,16 @@ func TestAccAzureRMVirtualMachineExtension_basic(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExtensionExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "settings", regexp.MustCompile("hostname")), + testCheckAzureRMVirtualMachineExtensionExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "settings", regexp.MustCompile("hostname")), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"protected_settings"}, - }, + data.ImportStep("protected_settings"), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExtensionExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "settings", regexp.MustCompile("whoami")), + testCheckAzureRMVirtualMachineExtensionExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "settings", regexp.MustCompile("whoami")), ), }, }, @@ -56,9 +48,7 @@ func TestAccAzureRMVirtualMachineExtension_requiresImport(t *testing.T) { return } - resourceName := "azurerm_virtual_machine_extension.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_extension", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -66,13 +56,13 @@ func TestAccAzureRMVirtualMachineExtension_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualMachineExtensionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineExtension_basic(ri, location), + Config: testAccAzureRMVirtualMachineExtension_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExtensionExists(resourceName), + testCheckAzureRMVirtualMachineExtensionExists(data.ResourceName), ), }, { - Config: testAccAzureRMVirtualMachineExtension_requiresImport(ri, location), + Config: testAccAzureRMVirtualMachineExtension_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_virtual_machine_extension"), }, }, @@ -80,10 +70,9 @@ func TestAccAzureRMVirtualMachineExtension_requiresImport(t *testing.T) { } func TestAccAzureRMVirtualMachineExtension_concurrent(t *testing.T) { - firstResourceName := "azurerm_virtual_machine_extension.test" + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_extension", "test") secondResourceName := "azurerm_virtual_machine_extension.test2" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineExtension_concurrent(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachineExtension_concurrent(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -93,9 +82,9 @@ func TestAccAzureRMVirtualMachineExtension_concurrent(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExtensionExists(firstResourceName), + testCheckAzureRMVirtualMachineExtensionExists(data.ResourceName), testCheckAzureRMVirtualMachineExtensionExists(secondResourceName), - resource.TestMatchResourceAttr(firstResourceName, "settings", regexp.MustCompile("hostname")), + resource.TestMatchResourceAttr(data.ResourceName, "settings", regexp.MustCompile("hostname")), resource.TestMatchResourceAttr(secondResourceName, "settings", regexp.MustCompile("whoami")), ), }, @@ -104,8 +93,8 @@ func TestAccAzureRMVirtualMachineExtension_concurrent(t *testing.T) { } func TestAccAzureRMVirtualMachineExtension_linuxDiagnostics(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineExtension_linuxDiagnostics(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_extension", "test") + config := testAccAzureRMVirtualMachineExtension_linuxDiagnostics(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -115,7 +104,7 @@ func TestAccAzureRMVirtualMachineExtension_linuxDiagnostics(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExtensionExists("azurerm_virtual_machine_extension.test"), + testCheckAzureRMVirtualMachineExtensionExists(data.ResourceName), ), }, }, @@ -177,7 +166,7 @@ func testCheckAzureRMVirtualMachineExtensionDestroy(s *terraform.State) error { return nil } -func testAccAzureRMVirtualMachineExtension_basic(rInt int, location string) string { +func testAccAzureRMVirtualMachineExtension_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -280,11 +269,11 @@ SETTINGS environment = "Production" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineExtension_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualMachineExtension_basic(rInt, location) +func testAccAzureRMVirtualMachineExtension_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineExtension_basic(data) return fmt.Sprintf(` %s @@ -302,7 +291,7 @@ resource "azurerm_virtual_machine_extension" "import" { `, template) } -func testAccAzureRMVirtualMachineExtension_basicUpdate(rInt int, location string) string { +func testAccAzureRMVirtualMachineExtension_basicUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -406,10 +395,10 @@ SETTINGS cost_center = "MSFT" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineExtension_concurrent(rInt int, location string) string { +func testAccAzureRMVirtualMachineExtension_concurrent(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -524,10 +513,10 @@ resource "azurerm_virtual_machine_extension" "test2" { } SETTINGS } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineExtension_linuxDiagnostics(rInt int, location string) string { +func testAccAzureRMVirtualMachineExtension_linuxDiagnostics(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -631,5 +620,5 @@ SETTINGS environment = "Production" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_virtual_machine_managed_disks_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_managed_disks_test.go similarity index 85% rename from azurerm/internal/services/compute/resource_arm_virtual_machine_managed_disks_test.go rename to azurerm/internal/services/compute/tests/resource_arm_virtual_machine_managed_disks_test.go index 019892d5dc6a..0005af912d5d 100644 --- a/azurerm/internal/services/compute/resource_arm_virtual_machine_managed_disks_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_managed_disks_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -9,11 +9,9 @@ import ( "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" @@ -23,10 +21,9 @@ import ( // NOTE: Test `TestAccAzureRMVirtualMachine_enableAnWithVM` requires a machine of size `D8_v3` which is large/expensive - you may wish to ignore this test" func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_standardSSD(t *testing.T) { - resourceName := "azurerm_virtual_machine.test" + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_standardSSD(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_standardSSD(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -35,8 +32,8 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_standardSSD(t *t { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "storage_os_disk.0.managed_disk_type", "StandardSSD_LRS"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "storage_os_disk.0.managed_disk_type", "StandardSSD_LRS"), ), }, }, @@ -49,24 +46,22 @@ func TestAccAzureRMVirtualMachine_requiresImport(t *testing.T) { return } - resourceName := "azurerm_virtual_machine.test" + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_standardSSD(ri, location), + Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_standardSSD(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, { - Config: testAccAzureRMVirtualMachine_requiresImport(ri, location), + Config: testAccAzureRMVirtualMachine_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_virtual_machine"), }, }, @@ -74,9 +69,10 @@ func TestAccAzureRMVirtualMachine_requiresImport(t *testing.T) { } func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -85,7 +81,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(t *test { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -93,9 +89,10 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(t *test } func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -104,7 +101,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit(t *test { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -112,9 +109,10 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit(t *test } func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -123,7 +121,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(t *testin { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -131,10 +129,11 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(t *testin } func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -143,7 +142,7 @@ func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit(t *testing.T { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -151,10 +150,11 @@ func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit(t *testing.T } func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -163,7 +163,7 @@ func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(t *testing.T { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -171,13 +171,13 @@ func TestAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(t *testing.T } func TestAccAzureRMVirtualMachine_deleteManagedDiskOptOut(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine var osd string var dtd string - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(ri, location) - postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM_managedDisk(ri, location) + preConfig := testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(data) + postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM_managedDisk(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -187,7 +187,7 @@ func TestAccAzureRMVirtualMachine_deleteManagedDiskOptOut(t *testing.T) { Destroy: false, Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), testLookupAzureRMVirtualMachineManagedDiskID(&vm, "myosdisk1", &osd), testLookupAzureRMVirtualMachineManagedDiskID(&vm, "mydatadisk1", &dtd), ), @@ -204,13 +204,13 @@ func TestAccAzureRMVirtualMachine_deleteManagedDiskOptOut(t *testing.T) { } func TestAccAzureRMVirtualMachine_deleteManagedDiskOptIn(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine var osd string var dtd string - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksBefore(ri, location) - postConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksAfter(ri, location) + preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksBefore(data) + postConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksAfter(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -220,7 +220,7 @@ func TestAccAzureRMVirtualMachine_deleteManagedDiskOptIn(t *testing.T) { Destroy: false, Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), testLookupAzureRMVirtualMachineManagedDiskID(&vm, "myosdisk1", &osd), testLookupAzureRMVirtualMachineManagedDiskID(&vm, "mydatadisk1", &dtd), ), @@ -237,8 +237,9 @@ func TestAccAzureRMVirtualMachine_deleteManagedDiskOptIn(t *testing.T) { } func TestAccAzureRMVirtualMachine_osDiskTypeConflict(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_osDiskTypeConflict(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + + config := testAccAzureRMVirtualMachine_osDiskTypeConflict(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -253,8 +254,9 @@ func TestAccAzureRMVirtualMachine_osDiskTypeConflict(t *testing.T) { } func TestAccAzureRMVirtualMachine_dataDiskTypeConflict(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_dataDiskTypeConflict(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + + config := testAccAzureRMVirtualMachine_dataDiskTypeConflict(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -269,9 +271,9 @@ func TestAccAzureRMVirtualMachine_dataDiskTypeConflict(t *testing.T) { } func TestAccAzureRMVirtualMachine_bugAzureRM33(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := acctest.RandString(7) - config := testAccAzureRMVirtualMachine_bugAzureRM33(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + + config := testAccAzureRMVirtualMachine_bugAzureRM33(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -286,11 +288,9 @@ func TestAccAzureRMVirtualMachine_bugAzureRM33(t *testing.T) { func TestAccAzureRMVirtualMachine_attachSecondDataDiskWithAttachOption(t *testing.T) { var afterCreate, afterUpdate compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_empty(ri, location) - postConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_empty(data) + postConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -299,17 +299,17 @@ func TestAccAzureRMVirtualMachine_attachSecondDataDiskWithAttachOption(t *testin { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &afterCreate), - resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.create_option", "Empty"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &afterCreate), + resource.TestCheckResourceAttr(data.ResourceName, "storage_data_disk.0.create_option", "Empty"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &afterUpdate), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &afterUpdate), testAccCheckVirtualMachineRecreated(t, &afterCreate, &afterUpdate), - resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.create_option", "Empty"), - resource.TestCheckResourceAttr(resourceName, "storage_data_disk.1.create_option", "Attach"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_data_disk.0.create_option", "Empty"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_data_disk.1.create_option", "Attach"), ), }, }, @@ -317,8 +317,9 @@ func TestAccAzureRMVirtualMachine_attachSecondDataDiskWithAttachOption(t *testin } func TestAccAzureRMVirtualMachine_linuxNoConfig(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_linuxNoConfig(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + + config := testAccAzureRMVirtualMachine_linuxNoConfig(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -333,8 +334,9 @@ func TestAccAzureRMVirtualMachine_linuxNoConfig(t *testing.T) { } func TestAccAzureRMVirtualMachine_windowsNoConfig(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_windowsNoConfig(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + + config := testAccAzureRMVirtualMachine_windowsNoConfig(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -349,15 +351,13 @@ func TestAccAzureRMVirtualMachine_windowsNoConfig(t *testing.T) { } func TestAccAzureRMVirtualMachine_multipleNICs(t *testing.T) { - resourceName := "azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") subscriptionId := os.Getenv("ARM_SUBSCRIPTION_ID") - prefix := fmt.Sprintf("/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/networkInterfaces", subscriptionId, ri) - firstNicName := fmt.Sprintf("%s/acctni1-%d", prefix, ri) - secondNicName := fmt.Sprintf("%s/acctni2-%d", prefix, ri) + prefix := fmt.Sprintf("/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/networkInterfaces", subscriptionId, data.RandomInteger) + firstNicName := fmt.Sprintf("%s/acctni1-%d", prefix, data.RandomInteger) + secondNicName := fmt.Sprintf("%s/acctni2-%d", prefix, data.RandomInteger) - config := testAccAzureRMVirtualMachine_multipleNICs(ri, rs, acceptance.Location()) + config := testAccAzureRMVirtualMachine_multipleNICs(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -367,8 +367,8 @@ func TestAccAzureRMVirtualMachine_multipleNICs(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "network_interface_ids.0", firstNicName), - resource.TestCheckResourceAttr(resourceName, "network_interface_ids.1", secondNicName), + resource.TestCheckResourceAttr(data.ResourceName, "network_interface_ids.0", firstNicName), + resource.TestCheckResourceAttr(data.ResourceName, "network_interface_ids.1", secondNicName), ), }, }, @@ -376,11 +376,10 @@ func TestAccAzureRMVirtualMachine_multipleNICs(t *testing.T) { } func TestAccAzureRMVirtualMachine_managedServiceIdentity(t *testing.T) { - var vm compute.VirtualMachine + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") - resourceName := "azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_withManagedServiceIdentity(ri, acceptance.Location()) + var vm compute.VirtualMachine + config := testAccAzureRMVirtualMachine_withManagedServiceIdentity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -389,9 +388,9 @@ func TestAccAzureRMVirtualMachine_managedServiceIdentity(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), resource.TestMatchOutput("principal_id", validate.UUIDRegExp), ), }, @@ -400,18 +399,18 @@ func TestAccAzureRMVirtualMachine_managedServiceIdentity(t *testing.T) { } func TestAccAzureRMVirtualMachine_enableAnWithVM(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - rInt := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachine_anWithVM(rInt, acceptance.AltLocation()), + Config: testAccAzureRMVirtualMachine_anWithVM(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -419,8 +418,7 @@ func TestAccAzureRMVirtualMachine_enableAnWithVM(t *testing.T) { } func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_changeOsWriteAcceleratorEnabled(t *testing.T) { - resourceName := "azurerm_virtual_machine.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") var vm compute.VirtualMachine resource.ParallelTest(t, resource.TestCase{ @@ -429,17 +427,17 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_changeOsWriteAcc CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withOsWriteAcceleratorEnabled(rInt, acceptance.Location(), "true"), + Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withOsWriteAcceleratorEnabled(data, "true"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "storage_os_disk.0.write_accelerator_enabled", "true"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "storage_os_disk.0.write_accelerator_enabled", "true"), ), }, { - Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withOsWriteAcceleratorEnabled(rInt, acceptance.Location(), "false"), + Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withOsWriteAcceleratorEnabled(data, "false"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "storage_os_disk.0.write_accelerator_enabled", "false"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "storage_os_disk.0.write_accelerator_enabled", "false"), ), }, }, @@ -447,8 +445,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_changeOsWriteAcc } func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(t *testing.T) { - resourceName := "azurerm_virtual_machine.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") var vm compute.VirtualMachine resource.ParallelTest(t, resource.TestCase{ @@ -457,10 +454,10 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceler CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(rInt, acceptance.Location(), "true"), + Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(data, "true"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.write_accelerator_enabled", "true"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "storage_data_disk.0.write_accelerator_enabled", "true"), ), }, }, @@ -468,8 +465,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceler } func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_changeWriteAcceleratorEnabled(t *testing.T) { - resourceName := "azurerm_virtual_machine.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") var vm compute.VirtualMachine resource.ParallelTest(t, resource.TestCase{ @@ -478,17 +474,17 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_changeWriteAccel CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(rInt, acceptance.Location(), "false"), + Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(data, "false"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.write_accelerator_enabled", "false"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "storage_data_disk.0.write_accelerator_enabled", "false"), ), }, { - Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(rInt, acceptance.Location(), "true"), + Config: testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(data, "true"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.write_accelerator_enabled", "true"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "storage_data_disk.0.write_accelerator_enabled", "true"), ), }, }, @@ -496,18 +492,18 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_changeWriteAccel } func TestAccAzureRMVirtualMachine_winRMCerts(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - rString := acctest.RandString(5) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachine_winRMCerts(rString, acceptance.Location()), + Config: testAccAzureRMVirtualMachine_winRMCerts(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -515,10 +511,10 @@ func TestAccAzureRMVirtualMachine_winRMCerts(t *testing.T) { } func TestAccAzureRMVirtualMachine_hasDiskInfoWhenStopped(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - rInt := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_hasDiskInfoWhenStopped(rInt, acceptance.Location()) + config := testAccAzureRMVirtualMachine_hasDiskInfoWhenStopped(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -527,17 +523,17 @@ func TestAccAzureRMVirtualMachine_hasDiskInfoWhenStopped(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "storage_os_disk.0.managed_disk_type", "Standard_LRS"), - resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.disk_size_gb", "64"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "storage_os_disk.0.managed_disk_type", "Standard_LRS"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_data_disk.0.disk_size_gb", "64"), ), }, { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAndStopAzureRMVirtualMachine(&vm), - resource.TestCheckResourceAttr(resourceName, "storage_os_disk.0.managed_disk_type", "Standard_LRS"), - resource.TestCheckResourceAttr(resourceName, "storage_data_disk.0.disk_size_gb", "64"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_os_disk.0.managed_disk_type", "Standard_LRS"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_data_disk.0.disk_size_gb", "64"), ), }, }, @@ -545,10 +541,9 @@ func TestAccAzureRMVirtualMachine_hasDiskInfoWhenStopped(t *testing.T) { } func TestAccAzureRMVirtualMachine_importBasic_withZone(t *testing.T) { - resourceName := "azurerm_virtual_machine.test" + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit_withZone(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit_withZone(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -559,15 +554,10 @@ func TestAccAzureRMVirtualMachine_importBasic_withZone(t *testing.T) { Config: config, }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "delete_data_disks_on_termination", - "delete_os_disk_on_termination", - }, - }, + data.ImportStep( + "delete_data_disks_on_termination", + "delete_os_disk_on_termination", + ), }, }) } @@ -575,9 +565,10 @@ func TestAccAzureRMVirtualMachine_importBasic_withZone(t *testing.T) { // this test requires eastus2 location and availability zone 1 // might be worth creating a `azurerm_compute_zones` resource to get the zones to use? func TestAccAzureRMVirtualMachine_ultraSSD(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_ultraSSD(ri, acceptance.AltLocation()) + config := testAccAzureRMVirtualMachine_ultraSSD(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -586,7 +577,7 @@ func TestAccAzureRMVirtualMachine_ultraSSD(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -619,7 +610,7 @@ func testCheckAndStopAzureRMVirtualMachine(vm *compute.VirtualMachine) resource. } } -func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withOsWriteAcceleratorEnabled(rInt int, location, enabled string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withOsWriteAcceleratorEnabled(data acceptance.TestData, enabled string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -700,10 +691,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, enabled, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, enabled, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(rInt int, location, enabled string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_withWriteAcceleratorEnabled(data acceptance.TestData, enabled string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -784,10 +775,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, enabled, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, enabled, data.RandomInteger) } -func testAccAzureRMVirtualMachine_winRMCerts(rString string, location string) string { +func testAccAzureRMVirtualMachine_winRMCerts(data acceptance.TestData) string { return fmt.Sprintf(` variable "prefix" { default = "acctest%s" @@ -987,10 +978,10 @@ resource "azurerm_virtual_machine" "test" { } } } -`, rString, location) +`, data.RandomString, data.Locations.Primary) } -func testAccAzureRMVirtualMachine_withManagedServiceIdentity(rInt int, location string) string { +func testAccAzureRMVirtualMachine_withManagedServiceIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1068,10 +1059,10 @@ resource "azurerm_virtual_machine" "test" { output "principal_id" { value = "${lookup(azurerm_virtual_machine.test.identity[0], "principal_id")}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_explicit(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1141,10 +1132,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_standardSSD(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_standardSSD(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1214,11 +1205,11 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_standardSSD(rInt, location) +func testAccAzureRMVirtualMachine_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_standardSSD(data) return fmt.Sprintf(` %s @@ -1259,10 +1250,10 @@ resource "azurerm_virtual_machine" "import" { cost-center = "Ops" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1331,10 +1322,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit_withZone(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_implicit_withZone(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1404,10 +1395,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_attach(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1502,10 +1493,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_empty(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_empty(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1585,10 +1576,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksBefore(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksBefore(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1667,10 +1658,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksAfter(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_managedDisk_DestroyDisksAfter(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1702,10 +1693,10 @@ resource "azurerm_network_interface" "test" { private_ip_address_allocation = "Dynamic" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM_managedDisk(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM_managedDisk(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1737,10 +1728,10 @@ resource "azurerm_network_interface" "test" { private_ip_address_allocation = "Dynamic" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit(rInt int, location string) string { +func testAccAzureRMVirtualMachine_withDataDisk_managedDisk_explicit(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1818,10 +1809,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(rInt int, location string) string { +func testAccAzureRMVirtualMachine_withDataDisk_managedDisk_implicit(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1897,10 +1888,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_osDiskTypeConflict(rInt int, location string) string { +func testAccAzureRMVirtualMachine_osDiskTypeConflict(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1980,10 +1971,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_dataDiskTypeConflict(rInt int, location string) string { +func testAccAzureRMVirtualMachine_dataDiskTypeConflict(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2072,10 +2063,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_bugAzureRM33(rInt int, rString string, location string) string { +func testAccAzureRMVirtualMachine_bugAzureRM33(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2142,7 +2133,7 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rString, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomString) } func testCheckAzureRMVirtualMachineManagedDiskExists(managedDiskID *string, shouldExist bool) resource.TestCheckFunc { @@ -2222,7 +2213,7 @@ func testGetAzureRMVirtualMachineManagedDisk(managedDiskID *string) (*compute.Di return &d, nil } -func testAccAzureRMVirtualMachine_linuxNoConfig(rInt int, location string) string { +func testAccAzureRMVirtualMachine_linuxNoConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2282,10 +2273,10 @@ resource "azurerm_virtual_machine" "test" { admin_password = "Password1234!" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_windowsNoConfig(rInt int, location string) string { +func testAccAzureRMVirtualMachine_windowsNoConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2345,10 +2336,10 @@ resource "azurerm_virtual_machine" "test" { admin_password = "Password1234!" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_multipleNICs(rInt int, rString string, location string) string { +func testAccAzureRMVirtualMachine_multipleNICs(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2423,10 +2414,10 @@ resource "azurerm_virtual_machine" "test" { os_profile_windows_config {} } -`, rInt, location, rInt, rInt, rInt, rInt, rString, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomString) } -func testAccAzureRMVirtualMachine_anWithVM(rInt int, location string) string { +func testAccAzureRMVirtualMachine_anWithVM(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -2497,10 +2488,10 @@ resource "azurerm_virtual_machine" "test" { disable_password_authentication = false } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_hasDiskInfoWhenStopped(rInt int, location string) string { +func testAccAzureRMVirtualMachine_hasDiskInfoWhenStopped(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -2572,10 +2563,10 @@ resource "azurerm_virtual_machine" "test" { disable_password_authentication = false } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_ultraSSD(rInt int, location string) string { +func testAccAzureRMVirtualMachine_ultraSSD(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2655,5 +2646,5 @@ resource "azurerm_virtual_machine" "test" { disable_password_authentication = false } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_extension_test.go similarity index 78% rename from azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension_test.go rename to azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_extension_test.go index a971b5b9036a..0cf8e90d9715 100644 --- a/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_extension_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_extension_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -7,58 +7,44 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/hashicorp/terraform/helper/acctest" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/compute" ) func TestAccAzureRMVirtualMachineScaleSetExtension_basicLinux(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set_extension.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_extension", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineScaleSetExtensionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineScaleSetExtension_basicLinux(ri, location), + Config: testAccAzureRMVirtualMachineScaleSetExtension_basicLinux(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExtensionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVirtualMachineScaleSetExtension_basicWindows(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set_extension.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_extension", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineScaleSetExtensionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineScaleSetExtension_basicWindows(ri, rs, location), + Config: testAccAzureRMVirtualMachineScaleSetExtension_basicWindows(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExtensionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -69,22 +55,20 @@ func TestAccAzureRMVirtualMachineScaleSetExtension_requiresImport(t *testing.T) return } - resourceName := "azurerm_virtual_machine_scale_set_extension.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_extension", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineScaleSetExtensionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineScaleSetExtension_basicLinux(ri, location), + Config: testAccAzureRMVirtualMachineScaleSetExtension_basicLinux(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExtensionExists(data.ResourceName), ), }, { - Config: testAccAzureRMVirtualMachineScaleSetExtension_requiresImport(ri, location), + Config: testAccAzureRMVirtualMachineScaleSetExtension_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_virtual_machine_scale_set_extension"), }, }, @@ -92,49 +76,39 @@ func TestAccAzureRMVirtualMachineScaleSetExtension_requiresImport(t *testing.T) } func TestAccAzureRMVirtualMachineScaleSetExtension_autoUpgradeDisabled(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set_extension.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_extension", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineScaleSetExtensionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineScaleSetExtension_autoUpgradeDisabled(ri, location), + Config: testAccAzureRMVirtualMachineScaleSetExtension_autoUpgradeDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExtensionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVirtualMachineScaleSetExtension_extensionChaining(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_extension", "first") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineScaleSetExtensionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineScaleSetExtension_extensionChaining(ri, location), + Config: testAccAzureRMVirtualMachineScaleSetExtension_extensionChaining(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualMachineScaleSetExtensionExists("azurerm_virtual_machine_scale_set_extension.first"), testCheckAzureRMVirtualMachineScaleSetExtensionExists("azurerm_virtual_machine_scale_set_extension.second"), ), }, - { - ResourceName: "azurerm_virtual_machine_scale_set_extension.first", - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { ResourceName: "azurerm_virtual_machine_scale_set_extension.second", ImportState: true, @@ -145,94 +119,68 @@ func TestAccAzureRMVirtualMachineScaleSetExtension_extensionChaining(t *testing. } func TestAccAzureRMVirtualMachineScaleSetExtension_forceUpdateTag(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set_extension.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_extension", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineScaleSetExtensionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineScaleSetExtension_forceUpdateTag(ri, location, "first"), + Config: testAccAzureRMVirtualMachineScaleSetExtension_forceUpdateTag(data, "first"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExtensionExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMVirtualMachineScaleSetExtension_forceUpdateTag(ri, location, "second"), + Config: testAccAzureRMVirtualMachineScaleSetExtension_forceUpdateTag(data, "second"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExtensionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVirtualMachineScaleSetExtension_protectedSettings(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set_extension.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_extension", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineScaleSetExtensionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineScaleSetExtension_protectedSettings(ri, location), + Config: testAccAzureRMVirtualMachineScaleSetExtension_protectedSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExtensionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"protected_settings"}, - }, + data.ImportStep("protected_settings"), }, }) } func TestAccAzureRMVirtualMachineScaleSetExtension_protectedSettingsOnly(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set_extension.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_extension", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineScaleSetExtensionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineScaleSetExtension_protectedSettingsOnly(ri, location), + Config: testAccAzureRMVirtualMachineScaleSetExtension_protectedSettingsOnly(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExtensionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"protected_settings"}, - }, + data.ImportStep("protected_settings"), }, }) } func TestAccAzureRMVirtualMachineScaleSetExtension_updateVersion(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set_extension.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set_extension", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -240,27 +188,19 @@ func TestAccAzureRMVirtualMachineScaleSetExtension_updateVersion(t *testing.T) { Steps: []resource.TestStep{ { // old version - Config: testAccAzureRMVirtualMachineScaleSetExtension_updateVersion(ri, location, "1.2"), + Config: testAccAzureRMVirtualMachineScaleSetExtension_updateVersion(data, "1.2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExtensionExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMVirtualMachineScaleSetExtension_updateVersion(ri, location, "1.3"), + Config: testAccAzureRMVirtualMachineScaleSetExtension_updateVersion(data, "1.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExtensionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -278,7 +218,7 @@ func testCheckAzureRMVirtualMachineScaleSetExtensionExists(resourceName string) name := rs.Primary.Attributes["name"] virtualMachineScaleSetIdRaw := rs.Primary.Attributes["virtual_machine_scale_set_id"] - virtualMachineScaleSetId, err := ParseVirtualMachineScaleSetID(virtualMachineScaleSetIdRaw) + virtualMachineScaleSetId, err := compute.ParseVirtualMachineScaleSetID(virtualMachineScaleSetIdRaw) if err != nil { return err } @@ -307,7 +247,7 @@ func testCheckAzureRMVirtualMachineScaleSetExtensionDestroy(s *terraform.State) name := rs.Primary.Attributes["name"] virtualMachineScaleSetIdRaw := rs.Primary.Attributes["virtual_machine_scale_set_id"] - virtualMachineScaleSetId, err := ParseVirtualMachineScaleSetID(virtualMachineScaleSetIdRaw) + virtualMachineScaleSetId, err := compute.ParseVirtualMachineScaleSetID(virtualMachineScaleSetIdRaw) if err != nil { return err } @@ -326,8 +266,8 @@ func testCheckAzureRMVirtualMachineScaleSetExtensionDestroy(s *terraform.State) return nil } -func testAccAzureRMVirtualMachineScaleSetExtension_basicLinux(rInt int, location string) string { - template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(rInt, location) +func testAccAzureRMVirtualMachineScaleSetExtension_basicLinux(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(data) return fmt.Sprintf(` %s @@ -341,11 +281,11 @@ resource "azurerm_virtual_machine_scale_set_extension" "test" { "commandToExecute" = "echo $HOSTNAME" }) } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualMachineScaleSetExtension_basicWindows(rInt int, rString, location string) string { - template := testAccAzureRMVirtualMachineScaleSetExtension_templateWindows(rInt, rString, location) +func testAccAzureRMVirtualMachineScaleSetExtension_basicWindows(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineScaleSetExtension_templateWindows(data) return fmt.Sprintf(` %s @@ -359,11 +299,11 @@ resource "azurerm_virtual_machine_scale_set_extension" "test" { "commandToExecute" = "Write-Host \"Hello\"" }) } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualMachineScaleSetExtension_autoUpgradeDisabled(rInt int, location string) string { - template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(rInt, location) +func testAccAzureRMVirtualMachineScaleSetExtension_autoUpgradeDisabled(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(data) return fmt.Sprintf(` %s @@ -378,11 +318,11 @@ resource "azurerm_virtual_machine_scale_set_extension" "test" { "commandToExecute" = "echo $HOSTNAME" }) } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualMachineScaleSetExtension_extensionChaining(rInt int, location string) string { - template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(rInt, location) +func testAccAzureRMVirtualMachineScaleSetExtension_extensionChaining(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(data) return fmt.Sprintf(` %s @@ -405,11 +345,11 @@ resource "azurerm_virtual_machine_scale_set_extension" "second" { }) provision_after_extensions = [ azurerm_virtual_machine_scale_set_extension.first.name ] } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineScaleSetExtension_forceUpdateTag(rInt int, location, tag string) string { - template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(rInt, location) +func testAccAzureRMVirtualMachineScaleSetExtension_forceUpdateTag(data acceptance.TestData, tag string) string { + template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(data) return fmt.Sprintf(` %s @@ -424,11 +364,11 @@ resource "azurerm_virtual_machine_scale_set_extension" "test" { "commandToExecute" = "echo $HOSTNAME" }) } -`, template, rInt, tag) +`, template, data.RandomInteger, tag) } -func testAccAzureRMVirtualMachineScaleSetExtension_updateVersion(rInt int, location, version string) string { - template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(rInt, location) +func testAccAzureRMVirtualMachineScaleSetExtension_updateVersion(data acceptance.TestData, version string) string { + template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(data) return fmt.Sprintf(` %s @@ -442,11 +382,11 @@ resource "azurerm_virtual_machine_scale_set_extension" "test" { "commandToExecute" = "echo $HOSTNAME" }) } -`, template, rInt, version) +`, template, data.RandomInteger, version) } -func testAccAzureRMVirtualMachineScaleSetExtension_protectedSettings(rInt int, location string) string { - template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(rInt, location) +func testAccAzureRMVirtualMachineScaleSetExtension_protectedSettings(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(data) return fmt.Sprintf(` %s @@ -463,11 +403,11 @@ resource "azurerm_virtual_machine_scale_set_extension" "test" { "secretValue" = "P@55W0rd1234!" }) } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualMachineScaleSetExtension_protectedSettingsOnly(rInt int, location string) string { - template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(rInt, location) +func testAccAzureRMVirtualMachineScaleSetExtension_protectedSettingsOnly(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(data) return fmt.Sprintf(` %s @@ -482,11 +422,11 @@ resource "azurerm_virtual_machine_scale_set_extension" "test" { "secretValue" = "P@55W0rd1234!" }) } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualMachineScaleSetExtension_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualMachineScaleSetExtension_basicLinux(rInt, location) +func testAccAzureRMVirtualMachineScaleSetExtension_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineScaleSetExtension_basicLinux(data) return fmt.Sprintf(` %s @@ -501,7 +441,7 @@ resource "azurerm_virtual_machine_scale_set_extension" "import" { `, template) } -func testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -559,10 +499,10 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineScaleSetExtension_templateWindows(rInt int, rString, location string) string { +func testAccAzureRMVirtualMachineScaleSetExtension_templateWindows(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -616,5 +556,5 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, rInt, location, rInt, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString) } diff --git a/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_test.go similarity index 87% rename from azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_test.go rename to azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_test.go index 82b5463968bd..233d30de7733 100644 --- a/azurerm/internal/services/compute/resource_arm_virtual_machine_scale_set_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -13,16 +13,13 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) func TestAccAzureRMVirtualMachineScaleSet_basic(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -31,18 +28,13 @@ func TestAccAzureRMVirtualMachineScaleSet_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), // testing default scaleset values - testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(resourceName, true), - resource.TestCheckResourceAttr(resourceName, "eviction_policy", ""), + testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(data.ResourceName, true), + resource.TestCheckResourceAttr(data.ResourceName, "eviction_policy", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } @@ -53,22 +45,20 @@ func TestAccAzureRMVirtualMachineScaleSet_requiresImport(t *testing.T) { return } - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachineScaleSet_basic(ri, location), + Config: testAccAzureRMVirtualMachineScaleSet_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, { - Config: testAccAzureRMVirtualMachineScaleSet_requiresImport(ri, location), + Config: testAccAzureRMVirtualMachineScaleSet_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_virtual_machine_scale_set"), }, }, @@ -76,9 +66,8 @@ func TestAccAzureRMVirtualMachineScaleSet_requiresImport(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_evictionPolicyDelete(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_evictionPolicyDelete(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_evictionPolicyDelete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -87,24 +76,18 @@ func TestAccAzureRMVirtualMachineScaleSet_evictionPolicyDelete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "eviction_policy", "Delete"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "eviction_policy", "Delete"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_standardSSD(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_standardSSD(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_standardSSD(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -113,23 +96,17 @@ func TestAccAzureRMVirtualMachineScaleSet_standardSSD(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_withPPG(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_withPPG(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_withPPG(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -138,8 +115,8 @@ func TestAccAzureRMVirtualMachineScaleSet_withPPG(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "proximity_placement_group_id"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "proximity_placement_group_id"), ), }, }, @@ -147,9 +124,8 @@ func TestAccAzureRMVirtualMachineScaleSet_withPPG(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_basicPublicIP(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basicPublicIP(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicPublicIP(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -158,27 +134,20 @@ func TestAccAzureRMVirtualMachineScaleSet_basicPublicIP(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetIsPrimary(resourceName, true), - testCheckAzureRMVirtualMachineScaleSetPublicIPName(resourceName, "TestPublicIPConfiguration"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetIsPrimary(data.ResourceName, true), + testCheckAzureRMVirtualMachineScaleSetPublicIPName(data.ResourceName, "TestPublicIPConfiguration"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_basicPublicIP_simpleUpdate(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(ri, location) - updatedConfig := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updated_tags(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(data) + updatedConfig := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updated_tags(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -188,39 +157,27 @@ func TestAccAzureRMVirtualMachineScaleSet_basicPublicIP_simpleUpdate(t *testing. { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetIsPrimary(resourceName, true), - testCheckAzureRMVirtualMachineScaleSetPublicIPName(resourceName, "TestPublicIPConfiguration"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetIsPrimary(data.ResourceName, true), + testCheckAzureRMVirtualMachineScaleSetPublicIPName(data.ResourceName, "TestPublicIPConfiguration"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetPublicIPName(resourceName, "TestPublicIPConfiguration"), + testCheckAzureRMVirtualMachineScaleSetPublicIPName(data.ResourceName, "TestPublicIPConfiguration"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_updateNetworkProfile(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(ri, location) - updatedConfig := testAccAzureRMVirtualMachineScaleSet_basicEmptyNetworkProfile_true_ipforwarding(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(data) + updatedConfig := testAccAzureRMVirtualMachineScaleSet_basicEmptyNetworkProfile_true_ipforwarding(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -230,35 +187,28 @@ func TestAccAzureRMVirtualMachineScaleSet_updateNetworkProfile(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetIPForwarding(resourceName, false), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetIPForwarding(data.ResourceName, false), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetIPForwarding(resourceName, true), + testCheckAzureRMVirtualMachineScaleSetIPForwarding(data.ResourceName, true), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_updateNetworkProfile_ipconfiguration_dns_name_label(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(ri, location) - updatedConfig := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updatedDNS_label(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(data) + updatedConfig := testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updatedDNS_label(data) - expectedDNS := fmt.Sprintf("test-domain-label-%[1]d", ri) - updatedDNS := fmt.Sprintf("test-updated-domain-label-%[1]d", ri) + expectedDNS := fmt.Sprintf("test-domain-label-%[1]d", data.RandomInteger) + updatedDNS := fmt.Sprintf("test-updated-domain-label-%[1]d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -268,14 +218,14 @@ func TestAccAzureRMVirtualMachineScaleSet_updateNetworkProfile_ipconfiguration_d { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetDomainNameLabel(resourceName, expectedDNS), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetDomainNameLabel(data.ResourceName, expectedDNS), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetDomainNameLabel(resourceName, updatedDNS), + testCheckAzureRMVirtualMachineScaleSetDomainNameLabel(data.ResourceName, updatedDNS), ), }, }, @@ -283,11 +233,9 @@ func TestAccAzureRMVirtualMachineScaleSet_updateNetworkProfile_ipconfiguration_d } func TestAccAzureRMVirtualMachineScaleSet_verify_key_data_changed(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMVirtualMachineScaleSet_linux(ri, location) - updatedConfig := testAccAzureRMVirtualMachineScaleSet_linuxKeyDataUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_linux(data) + updatedConfig := testAccAzureRMVirtualMachineScaleSet_linuxKeyDataUpdated(data) initialKeyData := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCsTcryUl51Q2VSEHqDRNmceUFo55ZtcIwxl2QITbN1RREti5ml/VTytC0yeBOvnZA4x4CFpdw/lCDPk0yrH9Ei5vVkXmOrExdTlT3qI7YaAzj1tUVlBd4S6LX1F7y6VLActvdHuDDuXZXzCDd/97420jrDfWZqJMlUK/EmCE5ParCeHIRIvmBxcEnGfFIsw8xQZl0HphxWOtJil8qsUWSdMyCiJYYQpMoMliO99X40AUc4/AlsyPyT5ddbKk08YrZ+rKDVHF7o29rh4vi5MmHkVgVQHKiKybWlHq+b71gIAUQk9wrJxD+dqt4igrmDSpIjfjwnd+l5UIn5fJSO5DYV4YT/4hwK7OKmuo7OFHD0WyY5YnkYEMtFgzemnRBdE8ulcT60DQpVgRMXFWHvhyCWy0L6sgj1QWDZlLpvsIvNfHsyhKFMG1frLnMt/nP0+YCcfg+v1JYeCKjeoJxB8DWcRBsjzItY0CGmzP8UYZiYKl/2u+2TgFS5r7NWH11bxoUzjKdaa1NLw+ieA8GlBFfCbfWe6YVB9ggUte4VtYFMZGxOjS2bAiYtfgTKFJv+XqORAwExG6+G2eDxIDyo80/OA9IG7Xv/jwQr7D6KDjDuULFcN/iTxuttoKrHeYz1hf5ZQlBdllwJHYx6fK2g8kha6r2JIQKocvsAXiiONqSfw== hello@world.com" expectedKeyData := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDvXYZAjVUt2aojUV3XIA+PY6gXrgbvktXwf2NoIHGlQFhogpMEyOfqgogCtTBM7MNCS3ELul6SV+mlpH08Ki45ADIQuDXdommCvsMFW096JrsHOJpGfjCsJ1gbbv7brB3Ag+BSGb4qO3pRsEVTtZCeJDwfH5D7vmqP5xXcELKR4UAtKQKUhLvt6mhW90sFLTJeOTiYGbavIKqfCUFSeSMQkUPr8o3uzOfeWyCw7tc7szLuvfwJ5poGHuve73KKAlUnDTPUrhyj7iITZSDl+/i+bpDzPyCyJWDMsC0ON7q2fDr2mEz0L9ACrsI5Nx3lt5fe+IaHSrjivqnL8SqUWSN45o9Qp99sGWFiuTfos8f1jp+AXzC4ArVtKyRg/CnzKRiK0CGSxBJ5s9zAoa7yBBmjCszq89vFa0eMgpEIZFwa6kKJKt9AfRBXgO9YGPV4uaN7topy92/p2pE+vF8IafarbvnTDOQt62mS07tXYqYg1DhecrmBVWKlq9oafBweoeTjoq52SoGsuDc/YAOzIgWVIuvV8yKoh9KbXPWowjLtxDhRIS/d1nMMNdNI8X0TQivgi5+umMgAXhsVAKSNDUauLt4jimYkWAuE+R6KoCqVFdaB9bQDySBjAziruDSe3reToydjzzluvHMjWK8QiDynxs41pi4zZz6gAlca3QPkEQ== hello@world.com" @@ -300,14 +248,14 @@ func TestAccAzureRMVirtualMachineScaleSet_verify_key_data_changed(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetSshKey(resourceName, initialKeyData), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetSshKey(data.ResourceName, initialKeyData), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetSshKey(resourceName, expectedKeyData), + testCheckAzureRMVirtualMachineScaleSetSshKey(data.ResourceName, expectedKeyData), ), }, }, @@ -315,9 +263,8 @@ func TestAccAzureRMVirtualMachineScaleSet_verify_key_data_changed(t *testing.T) } func TestAccAzureRMVirtualMachineScaleSet_basicApplicationSecurity(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basicApplicationSecurity(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicApplicationSecurity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -326,23 +273,17 @@ func TestAccAzureRMVirtualMachineScaleSet_basicApplicationSecurity(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_basicAcceleratedNetworking(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basicAcceleratedNetworking(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicAcceleratedNetworking(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -351,24 +292,18 @@ func TestAccAzureRMVirtualMachineScaleSet_basicAcceleratedNetworking(t *testing. { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetAcceleratedNetworking(resourceName, true), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetAcceleratedNetworking(data.ResourceName, true), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_basicIPForwarding(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basicIPForwarding(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicIPForwarding(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -377,23 +312,17 @@ func TestAccAzureRMVirtualMachineScaleSet_basicIPForwarding(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_basicDNSSettings(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basicDNSSettings(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicDNSSettings(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -402,23 +331,17 @@ func TestAccAzureRMVirtualMachineScaleSet_basicDNSSettings(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_bootDiagnostic(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_bootDiagnostic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_bootDiagnostic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -427,8 +350,8 @@ func TestAccAzureRMVirtualMachineScaleSet_bootDiagnostic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "boot_diagnostics.0.enabled", "true"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "boot_diagnostics.0.enabled", "true"), ), }, }, @@ -436,9 +359,8 @@ func TestAccAzureRMVirtualMachineScaleSet_bootDiagnostic(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_networkSecurityGroup(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_networkSecurityGroup(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_networkSecurityGroup(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -447,7 +369,7 @@ func TestAccAzureRMVirtualMachineScaleSet_networkSecurityGroup(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, }, @@ -455,9 +377,8 @@ func TestAccAzureRMVirtualMachineScaleSet_networkSecurityGroup(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_basicWindows(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basicWindows(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicWindows(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -466,10 +387,10 @@ func TestAccAzureRMVirtualMachineScaleSet_basicWindows(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), // single placement group should default to true - testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(resourceName, true), + testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(data.ResourceName, true), ), }, }, @@ -477,9 +398,8 @@ func TestAccAzureRMVirtualMachineScaleSet_basicWindows(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_singlePlacementGroupFalse(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_singlePlacementGroupFalse(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_singlePlacementGroupFalse(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -488,8 +408,8 @@ func TestAccAzureRMVirtualMachineScaleSet_singlePlacementGroupFalse(t *testing.T { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(resourceName, false), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetSinglePlacementGroup(data.ResourceName, false), ), }, }, @@ -497,11 +417,9 @@ func TestAccAzureRMVirtualMachineScaleSet_singlePlacementGroupFalse(t *testing.T } func TestAccAzureRMVirtualMachineScaleSet_linuxUpdated(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMVirtualMachineScaleSet_linux(ri, location) - updatedConfig := testAccAzureRMVirtualMachineScaleSet_linuxUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_linux(data) + updatedConfig := testAccAzureRMVirtualMachineScaleSet_linuxUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -511,13 +429,13 @@ func TestAccAzureRMVirtualMachineScaleSet_linuxUpdated(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, }, @@ -525,11 +443,9 @@ func TestAccAzureRMVirtualMachineScaleSet_linuxUpdated(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_customDataUpdated(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMVirtualMachineScaleSet_linux(ri, location) - updatedConfig := testAccAzureRMVirtualMachineScaleSet_linuxCustomDataUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_linux(data) + updatedConfig := testAccAzureRMVirtualMachineScaleSet_linuxCustomDataUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -539,13 +455,13 @@ func TestAccAzureRMVirtualMachineScaleSet_customDataUpdated(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, }, @@ -553,9 +469,8 @@ func TestAccAzureRMVirtualMachineScaleSet_customDataUpdated(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -564,23 +479,17 @@ func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(ri, acceptance.Location(), "Standard_D1_v2") + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(data, "Standard_D1_v2") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -589,7 +498,7 @@ func TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, }, @@ -597,10 +506,9 @@ func TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(t *testing.T) } func TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(ri, acceptance.Location(), "Standard_D1_v2") - postConfig := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(ri, acceptance.Location(), "Standard_D2_v2") + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + preConfig := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(data, "Standard_D1_v2") + postConfig := testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(data, "Standard_D2_v2") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -609,13 +517,13 @@ func TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize(t *tes { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, }, @@ -623,9 +531,8 @@ func TestAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk_resize(t *tes } func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -634,7 +541,7 @@ func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(t *testin { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, }, @@ -642,9 +549,8 @@ func TestAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(t *testin } func TestAccAzureRMVirtualMachineScaleSet_basicLinux_disappears(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -653,8 +559,8 @@ func TestAccAzureRMVirtualMachineScaleSet_basicLinux_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetDisappears(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -663,9 +569,8 @@ func TestAccAzureRMVirtualMachineScaleSet_basicLinux_disappears(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_planManagedDisk(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_planManagedDisk(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_planManagedDisk(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -674,7 +579,7 @@ func TestAccAzureRMVirtualMachineScaleSet_planManagedDisk(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, }, @@ -682,15 +587,14 @@ func TestAccAzureRMVirtualMachineScaleSet_planManagedDisk(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_customImage(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - resourceGroup := fmt.Sprintf("acctestRG-%d", ri) - userName := fmt.Sprintf("testadmin%d", ri) - password := fmt.Sprintf("Password1234!%d", ri) - hostName := fmt.Sprintf("tftestcustomimagesrc%d", ri) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) + userName := fmt.Sprintf("testadmin%d", data.RandomInteger) + password := fmt.Sprintf("Password1234!%d", data.RandomInteger) + hostName := fmt.Sprintf("tftestcustomimagesrc%d", data.RandomInteger) sshPort := "22" - config := testAccAzureRMVirtualMachineScaleSet_customImage(ri, acceptance.Location(), userName, password, hostName) - preConfig := testAccAzureRMImage_standaloneImage_setup(ri, userName, password, hostName, acceptance.Location(), "LRS") + config := testAccAzureRMVirtualMachineScaleSet_customImage(data, userName, password, hostName) + preConfig := testAccAzureRMImage_standaloneImage_setup(data, userName, password, hostName, "LRS") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -709,8 +613,8 @@ func TestAccAzureRMVirtualMachineScaleSet_customImage(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMImageExists("azurerm_image.test", true), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMImageExists("azurerm_image", true), ), }, }, @@ -718,9 +622,8 @@ func TestAccAzureRMVirtualMachineScaleSet_customImage(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_applicationGateway(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSetApplicationGatewayTemplate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetApplicationGatewayTemplate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -729,8 +632,8 @@ func TestAccAzureRMVirtualMachineScaleSet_applicationGateway(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetHasApplicationGateway(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetHasApplicationGateway(data.ResourceName), ), }, }, @@ -738,9 +641,8 @@ func TestAccAzureRMVirtualMachineScaleSet_applicationGateway(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_loadBalancer(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSetLoadBalancerTemplate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetLoadBalancerTemplate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -749,24 +651,18 @@ func TestAccAzureRMVirtualMachineScaleSet_loadBalancer(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetHasLoadbalancer(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetHasLoadbalancer(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_loadBalancerManagedDataDisks(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSetLoadBalancerTemplateManagedDataDisks(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetLoadBalancerTemplateManagedDataDisks(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -775,8 +671,8 @@ func TestAccAzureRMVirtualMachineScaleSet_loadBalancerManagedDataDisks(t *testin { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetHasDataDisks(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetHasDataDisks(data.ResourceName), ), }, }, @@ -784,9 +680,8 @@ func TestAccAzureRMVirtualMachineScaleSet_loadBalancerManagedDataDisks(t *testin } func TestAccAzureRMVirtualMachineScaleSet_overprovision(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSetOverProvisionTemplate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetOverProvisionTemplate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -795,24 +690,18 @@ func TestAccAzureRMVirtualMachineScaleSet_overprovision(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetOverprovision(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetOverprovision(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_priority(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSetPriorityTemplate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetPriorityTemplate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -821,9 +710,9 @@ func TestAccAzureRMVirtualMachineScaleSet_priority(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "priority", "Low"), - resource.TestCheckResourceAttr(resourceName, "eviction_policy", "Deallocate"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "Low"), + resource.TestCheckResourceAttr(data.ResourceName, "eviction_policy", "Deallocate"), ), }, }, @@ -831,9 +720,8 @@ func TestAccAzureRMVirtualMachineScaleSet_priority(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_SystemAssignedMSI(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSetSystemAssignedMSI(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetSystemAssignedMSI(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -842,10 +730,10 @@ func TestAccAzureRMVirtualMachineScaleSet_SystemAssignedMSI(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "0"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "0"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), ), }, }, @@ -853,10 +741,8 @@ func TestAccAzureRMVirtualMachineScaleSet_SystemAssignedMSI(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_UserAssignedMSI(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(14) - config := testAccAzureRMVirtualMachineScaleSetUserAssignedMSI(ri, acceptance.Location(), rs) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetUserAssignedMSI(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -865,10 +751,10 @@ func TestAccAzureRMVirtualMachineScaleSet_UserAssignedMSI(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "identity.0.principal_id", ""), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.principal_id", ""), ), }, }, @@ -876,10 +762,8 @@ func TestAccAzureRMVirtualMachineScaleSet_UserAssignedMSI(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_multipleAssignedMSI(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(14) - config := testAccAzureRMVirtualMachineScaleSetMultipleAssignedMSI(ri, acceptance.Location(), rs) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetMultipleAssignedMSI(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -888,10 +772,10 @@ func TestAccAzureRMVirtualMachineScaleSet_multipleAssignedMSI(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned, UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned, UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), ), }, }, @@ -899,9 +783,8 @@ func TestAccAzureRMVirtualMachineScaleSet_multipleAssignedMSI(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_extension(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSetExtensionTemplate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetExtensionTemplate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -910,26 +793,19 @@ func TestAccAzureRMVirtualMachineScaleSet_extension(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetExtension(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetExtension(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_extensionUpdate(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMVirtualMachineScaleSetExtensionTemplate(ri, location) - updatedConfig := testAccAzureRMVirtualMachineScaleSetExtensionTemplateUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetExtensionTemplate(data) + updatedConfig := testAccAzureRMVirtualMachineScaleSetExtensionTemplateUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -938,15 +814,15 @@ func TestAccAzureRMVirtualMachineScaleSet_extensionUpdate(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetExtension(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetExtension(data.ResourceName), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetExtension(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetExtension(data.ResourceName), ), }, }, @@ -954,9 +830,8 @@ func TestAccAzureRMVirtualMachineScaleSet_extensionUpdate(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_multipleExtensions(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -965,24 +840,18 @@ func TestAccAzureRMVirtualMachineScaleSet_multipleExtensions(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetExtension(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetExtension(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_multipleExtensions_provision_after_extension(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate_provision_after_extension(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate_provision_after_extension(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -991,23 +860,18 @@ func TestAccAzureRMVirtualMachineScaleSet_multipleExtensions_provision_after_ext { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - testCheckAzureRMVirtualMachineScaleSetExtension(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + testCheckAzureRMVirtualMachineScaleSetExtension(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } func TestAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -1022,9 +886,8 @@ func TestAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_NonStandardCasing(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSetNonStandardCasing(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSetNonStandardCasing(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -1033,7 +896,7 @@ func TestAccAzureRMVirtualMachineScaleSet_NonStandardCasing(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, { @@ -1046,10 +909,9 @@ func TestAccAzureRMVirtualMachineScaleSet_NonStandardCasing(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_importLinux(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_linux(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachineScaleSet_linux(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1059,26 +921,20 @@ func TestAccAzureRMVirtualMachineScaleSet_importLinux(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "os_profile.0.admin_password", - "os_profile.0.custom_data", - }, - }, + data.ImportStep( + "os_profile.0.admin_password", + "os_profile.0.custom_data", + ), }, }) } func TestAccAzureRMVirtualMachineScaleSet_multipleNetworkProfiles(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_multipleNetworkProfiles(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_multipleNetworkProfiles(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -1087,7 +943,7 @@ func TestAccAzureRMVirtualMachineScaleSet_multipleNetworkProfiles(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, }, @@ -1095,9 +951,8 @@ func TestAccAzureRMVirtualMachineScaleSet_multipleNetworkProfiles(t *testing.T) } func TestAccAzureRMVirtualMachineScaleSet_AutoUpdates(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_rollingAutoUpdates(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + config := testAccAzureRMVirtualMachineScaleSet_rollingAutoUpdates(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -1106,7 +961,7 @@ func TestAccAzureRMVirtualMachineScaleSet_AutoUpdates(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, }, @@ -1114,12 +969,10 @@ func TestAccAzureRMVirtualMachineScaleSet_AutoUpdates(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - manualConfig := testAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(ri, location, "Manual") - automaticConfig := testAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(ri, location, "Automatic") - rollingConfig := testAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(ri, location, "Rolling") + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") + manualConfig := testAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(data, "Manual") + automaticConfig := testAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(data, "Automatic") + rollingConfig := testAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(data, "Rolling") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1129,51 +982,51 @@ func TestAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(t *testing.T) { { Config: manualConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "upgrade_policy_mode", "Manual"), - resource.TestCheckNoResourceAttr(resourceName, "rolling_upgrade_policy.#"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "upgrade_policy_mode", "Manual"), + resource.TestCheckNoResourceAttr(data.ResourceName, "rolling_upgrade_policy.#"), ), }, { Config: automaticConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "upgrade_policy_mode", "Automatic"), - resource.TestCheckNoResourceAttr(resourceName, "rolling_upgrade_policy.#"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "upgrade_policy_mode", "Automatic"), + resource.TestCheckNoResourceAttr(data.ResourceName, "rolling_upgrade_policy.#"), ), }, { Config: rollingConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "upgrade_policy_mode", "Rolling"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.0.max_batch_instance_percent", "21"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.0.max_unhealthy_instance_percent", "22"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.0.max_unhealthy_upgraded_instance_percent", "23"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "upgrade_policy_mode", "Rolling"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.0.max_batch_instance_percent", "21"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.0.max_unhealthy_instance_percent", "22"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.0.max_unhealthy_upgraded_instance_percent", "23"), ), }, { PreConfig: func() { time.Sleep(1 * time.Minute) }, // VM Scale Set updates are not allowed while there is a Rolling Upgrade in progress. Config: automaticConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "upgrade_policy_mode", "Automatic"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.0.max_batch_instance_percent", "20"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.0.max_unhealthy_instance_percent", "20"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.0.max_unhealthy_upgraded_instance_percent", "20"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "upgrade_policy_mode", "Automatic"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.0.max_batch_instance_percent", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.0.max_unhealthy_instance_percent", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.0.max_unhealthy_upgraded_instance_percent", "20"), ), }, { Config: manualConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "upgrade_policy_mode", "Manual"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.0.max_batch_instance_percent", "20"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.0.max_unhealthy_instance_percent", "20"), - resource.TestCheckResourceAttr(resourceName, "rolling_upgrade_policy.0.max_unhealthy_upgraded_instance_percent", "20"), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "upgrade_policy_mode", "Manual"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.0.max_batch_instance_percent", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.0.max_unhealthy_instance_percent", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "rolling_upgrade_policy.0.max_unhealthy_upgraded_instance_percent", "20"), ), }, }, @@ -1181,10 +1034,9 @@ func TestAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(t *testing.T) { } func TestAccAzureRMVirtualMachineScaleSet_importBasic_managedDisk_withZones(t *testing.T) { - resourceName := "azurerm_virtual_machine_scale_set.test" + data := acceptance.BuildTestData(t, "azurerm_virtual_machine_scale_set", "test") - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk_withZones(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk_withZones(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1194,15 +1046,10 @@ func TestAccAzureRMVirtualMachineScaleSet_importBasic_managedDisk_withZones(t *t { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"os_profile.0.admin_password"}, - }, + data.ImportStep("os_profile.0.admin_password"), }, }) } @@ -1570,7 +1417,7 @@ func testCheckAzureRMVirtualMachineScaleSetHasDataDisks(name string) resource.Te } } -func testAccAzureRMVirtualMachineScaleSet_basic(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1654,11 +1501,11 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualMachineScaleSet_basic(rInt, location) +func testAccAzureRMVirtualMachineScaleSet_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualMachineScaleSet_basic(data) return fmt.Sprintf(` %s @@ -1705,10 +1552,10 @@ resource "azurerm_virtual_machine_scale_set" "import" { version = "latest" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineScaleSet_evictionPolicyDelete(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_evictionPolicyDelete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1793,10 +1640,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_standardSSD(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_standardSSD(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1880,10 +1727,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_withPPG(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_withPPG(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1975,10 +1822,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { proximity_placement_group_id = "${azurerm_proximity_placement_group.test.id}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicPublicIP(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicPublicIP(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2067,10 +1914,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2163,10 +2010,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updated_tags(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updated_tags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2259,10 +2106,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicEmptyNetworkProfile_true_ipforwarding(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicEmptyNetworkProfile_true_ipforwarding(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2356,10 +2203,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updatedDNS_label(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicEmptyPublicIP_updatedDNS_label(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2452,10 +2299,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicApplicationSecurity(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicApplicationSecurity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2545,10 +2392,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicAcceleratedNetworking(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicAcceleratedNetworking(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2632,10 +2479,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicIPForwarding(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicIPForwarding(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2719,10 +2566,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicDNSSettings(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicDNSSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2809,10 +2656,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_bootDiagnostic(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_bootDiagnostic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2899,10 +2746,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_networkSecurityGroup(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_networkSecurityGroup(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -2998,10 +2845,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicWindows(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicWindows(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -3093,10 +2940,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_singlePlacementGroupFalse(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_singlePlacementGroupFalse(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -3180,10 +3027,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_linux(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_linux(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -3297,10 +3144,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_linuxUpdated(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_linuxUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -3418,10 +3265,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { ThisIs = "a test" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_linuxCustomDataUpdated(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_linuxCustomDataUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -3535,10 +3382,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_linuxKeyDataUpdated(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_linuxKeyDataUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -3652,10 +3499,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -3719,10 +3566,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk_withZones(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDisk_withZones(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -3786,10 +3633,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(rInt int, location string, vmSize string) string { +func testAccAzureRMVirtualMachineScaleSet_basicWindows_managedDisk(data acceptance.TestData, vmSize string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -3872,10 +3719,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location, vmSize) +`, data.RandomInteger, data.Locations.Primary, vmSize) } -func testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_basicLinux_managedDiskNoName(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -3938,10 +3785,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetApplicationGatewayTemplate(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetApplicationGatewayTemplate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -4134,10 +3981,10 @@ resource "azurerm_application_gateway" "test" { environment = "tf01" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetLoadBalancerTemplate(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetLoadBalancerTemplate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -4248,10 +4095,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetOverProvisionTemplate(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetOverProvisionTemplate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -4331,10 +4178,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetPriorityTemplate(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetPriorityTemplate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -4416,10 +4263,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetSystemAssignedMSI(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetSystemAssignedMSI(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -4511,10 +4358,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetUserAssignedMSI(rInt int, location string, rString string) string { +func testAccAzureRMVirtualMachineScaleSetUserAssignedMSI(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -4614,10 +4461,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMVirtualMachineScaleSetExtensionTemplate(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetExtensionTemplate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -4726,10 +4573,10 @@ SETTINGS SETTINGS } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetExtensionTemplateUpdated(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetExtensionTemplateUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -4839,10 +4686,10 @@ SETTINGS SETTINGS } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -4951,10 +4798,10 @@ SETTINGS auto_upgrade_minor_version = true } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate_provision_after_extension(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetMultipleExtensionsTemplate_provision_after_extension(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -5064,10 +4911,10 @@ SETTINGS provision_after_extensions = ["CustomScript"] } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_osDiskTypeConflict(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -5132,10 +4979,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetLoadBalancerTemplateManagedDataDisks(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetLoadBalancerTemplateManagedDataDisks(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -5226,10 +5073,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSetNonStandardCasing(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSetNonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -5312,10 +5159,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_planManagedDisk(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_planManagedDisk(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -5384,10 +5231,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_customImage(rInt int, location string, userName string, password string, hostName string) string { +func testAccAzureRMVirtualMachineScaleSet_customImage(data acceptance.TestData, userName string, password string, hostName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -5544,10 +5391,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { managed_disk_type = "Standard_LRS" } } -`, rInt, location, hostName, userName, password) +`, data.RandomInteger, data.Locations.Primary, hostName, userName, password) } -func testAccAzureRMVirtualMachineScaleSet_multipleNetworkProfiles(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_multipleNetworkProfiles(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -5641,10 +5488,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_rollingAutoUpdates(rInt int, location string) string { +func testAccAzureRMVirtualMachineScaleSet_rollingAutoUpdates(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -5773,10 +5620,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(rInt int, location string, mode string) string { +func testAccAzureRMVirtualMachineScaleSet_upgradeModeUpdate(data acceptance.TestData, mode string) string { policy := "" if mode == "Rolling" { policy = ` @@ -5909,10 +5756,10 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location, mode, policy) +`, data.RandomInteger, data.Locations.Primary, mode, policy) } -func testAccAzureRMVirtualMachineScaleSetMultipleAssignedMSI(rInt int, location string, rString string) string { +func testAccAzureRMVirtualMachineScaleSetMultipleAssignedMSI(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -6003,5 +5850,5 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/compute/resource_arm_virtual_machine_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_test.go similarity index 85% rename from azurerm/internal/services/compute/resource_arm_virtual_machine_test.go rename to azurerm/internal/services/compute/tests/resource_arm_virtual_machine_test.go index 5a5e78ed5a5f..4f3d37d33eed 100644 --- a/azurerm/internal/services/compute/resource_arm_virtual_machine_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -10,17 +10,15 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) func TestAccAzureRMVirtualMachine_winTimeZone(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_winTimeZone(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_winTimeZone(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -29,8 +27,8 @@ func TestAccAzureRMVirtualMachine_winTimeZone(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "os_profile_windows_config.59207889.timezone", "Pacific Standard Time"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "os_profile_windows_config.59207889.timezone", "Pacific Standard Time"), ), }, }, @@ -38,10 +36,10 @@ func TestAccAzureRMVirtualMachine_winTimeZone(t *testing.T) { } func TestAccAzureRMVirtualMachine_SystemAssignedIdentity(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachineSystemAssignedIdentity(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachineSystemAssignedIdentity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -50,10 +48,10 @@ func TestAccAzureRMVirtualMachine_SystemAssignedIdentity(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "0"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "0"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), ), }, }, @@ -61,11 +59,10 @@ func TestAccAzureRMVirtualMachine_SystemAssignedIdentity(t *testing.T) { } func TestAccAzureRMVirtualMachine_UserAssignedIdentity(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(14) - config := testAccAzureRMVirtualMachineUserAssignedIdentity(ri, acceptance.Location(), rs) + config := testAccAzureRMVirtualMachineUserAssignedIdentity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -74,10 +71,10 @@ func TestAccAzureRMVirtualMachine_UserAssignedIdentity(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "identity.0.principal_id", ""), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.principal_id", ""), ), }, }, @@ -85,11 +82,10 @@ func TestAccAzureRMVirtualMachine_UserAssignedIdentity(t *testing.T) { } func TestAccAzureRMVirtualMachine_multipleAssignedIdentity(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(14) - config := testAccAzureRMVirtualMachineMultipleAssignedIdentity(ri, acceptance.Location(), rs) + config := testAccAzureRMVirtualMachineMultipleAssignedIdentity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -98,10 +94,10 @@ func TestAccAzureRMVirtualMachine_multipleAssignedIdentity(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned, UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned, UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), ), }, }, @@ -109,21 +105,19 @@ func TestAccAzureRMVirtualMachine_multipleAssignedIdentity(t *testing.T) { } func TestAccAzureRMVirtualMachine_withPPG(t *testing.T) { - var vm compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(14) + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachinePPG(ri, acceptance.Location(), rs), + Config: testAccAzureRMVirtualMachinePPG(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttrSet(resourceName, "proximity_placement_group_id"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttrSet(data.ResourceName, "proximity_placement_group_id"), ), }, }, @@ -190,7 +184,7 @@ func testCheckAzureRMVirtualMachineDestroy(s *terraform.State) error { return nil } -func testAccAzureRMVirtualMachine_winTimeZone(rInt int, location string) string { +func testAccAzureRMVirtualMachine_winTimeZone(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -269,10 +263,10 @@ resource "azurerm_virtual_machine" "test" { timezone = "Pacific Standard Time" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineSystemAssignedIdentity(rInt int, location string) string { +func testAccAzureRMVirtualMachineSystemAssignedIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -365,10 +359,10 @@ resource "azurerm_virtual_machine" "test" { type = "SystemAssigned" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineUserAssignedIdentity(rInt int, location string, rString string) string { +func testAccAzureRMVirtualMachineUserAssignedIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -469,10 +463,10 @@ resource "azurerm_virtual_machine" "test" { identity_ids = ["${azurerm_user_assigned_identity.test.id}"] } } -`, rInt, location, rInt, rInt, rInt, rInt, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachineMultipleAssignedIdentity(rInt int, location string, rString string) string { +func testAccAzureRMVirtualMachineMultipleAssignedIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -572,10 +566,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachinePPG(rInt int, location string, rString string) string { +func testAccAzureRMVirtualMachinePPG(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -673,5 +667,5 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/compute/resource_arm_virtual_machine_unmanaged_disks_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_unmanaged_disks_test.go similarity index 87% rename from azurerm/internal/services/compute/resource_arm_virtual_machine_unmanaged_disks_test.go rename to azurerm/internal/services/compute/tests/resource_arm_virtual_machine_unmanaged_disks_test.go index 5ff37fa1215f..058b0c82effc 100644 --- a/azurerm/internal/services/compute/resource_arm_virtual_machine_unmanaged_disks_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_unmanaged_disks_test.go @@ -1,17 +1,14 @@ -package compute +package tests import ( "fmt" "log" "regexp" - "strings" "testing" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -19,10 +16,9 @@ import ( ) func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { - resourceName := "azurerm_virtual_machine.test" + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_basicLinuxMachine(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_basicLinuxMachine(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -31,28 +27,24 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "delete_data_disks_on_termination", - "delete_os_disk_on_termination", - }, - }, + data.ImportStep( + "delete_data_disks_on_termination", + "delete_os_disk_on_termination", + ), }, }) } func TestAccAzureRMVirtualMachine_basicLinuxMachine_storageBlob_attach(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(ri, acceptance.Location()) - prepConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_destroyVM(ri, acceptance.Location()) - config := testAccAzureRMVirtualMachine_basicLinuxMachine_storageBlob_attach(ri, acceptance.Location()) + preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(data) + prepConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_destroyVM(data) + config := testAccAzureRMVirtualMachine_basicLinuxMachine_storageBlob_attach(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -62,7 +54,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_storageBlob_attach(t *testin Config: preConfig, Destroy: false, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, { @@ -72,7 +64,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_storageBlob_attach(t *testin { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -80,9 +72,10 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_storageBlob_attach(t *testin } func TestAccAzureRMVirtualMachine_basicLinuxMachineSSHOnly(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_basicLinuxMachineSSHOnly(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_basicLinuxMachineSSHOnly(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -91,7 +84,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachineSSHOnly(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -99,9 +92,10 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachineSSHOnly(t *testing.T) { } func TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_basicLinuxMachine(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_basicLinuxMachine(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -110,8 +104,8 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), - testCheckAzureRMVirtualMachineDisappears("azurerm_virtual_machine.test"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + testCheckAzureRMVirtualMachineDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -120,9 +114,10 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) { } func TestAccAzureRMVirtualMachine_basicLinuxMachineUseExistingOsDiskImage(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm, mirrorVm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_basicLinuxMachineUseExistingOsDiskImage(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_basicLinuxMachineUseExistingOsDiskImage(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -131,7 +126,7 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachineUseExistingOsDiskImage(t *tes { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.mirror", &mirrorVm), testCheckAzureRMVirtualMachineVHDExistence("myosdisk1.vhd", true), testCheckAzureRMVirtualMachineVHDExistence("mirrorosdisk.vhd", true), @@ -143,10 +138,11 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachineUseExistingOsDiskImage(t *tes } func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_withDataDisk(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_withDataDisk(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -155,7 +151,7 @@ func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -163,13 +159,12 @@ func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) { } func TestAccAzureRMVirtualMachine_tags(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - resourceName := "azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(ri, location) - postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineUpdated(ri, location) + preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(data) + postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -178,19 +173,19 @@ func TestAccAzureRMVirtualMachine_tags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost-center", "Ops"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost-center", "Ops"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), ), }, }, @@ -200,13 +195,11 @@ func TestAccAzureRMVirtualMachine_tags(t *testing.T) { //This is a regression test around https://github.com/hashicorp/terraform/issues/6517 //Because we use CreateUpdate, we were sending an empty password on update requests func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) { - var vm compute.VirtualMachine + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") - resourceName := "azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(ri, location) - postConfig := testAccAzureRMVirtualMachine_updatedLinuxMachine(ri, location) + var vm compute.VirtualMachine + preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(data) + postConfig := testAccAzureRMVirtualMachine_updatedLinuxMachine(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -215,15 +208,15 @@ func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "vm_size", "Standard_D1_v2"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "Standard_D1_v2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists(resourceName, &vm), - resource.TestCheckResourceAttr(resourceName, "vm_size", "Standard_D2_v2"), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "Standard_D2_v2"), ), }, }, @@ -231,9 +224,10 @@ func TestAccAzureRMVirtualMachine_updateMachineSize(t *testing.T) { } func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_basicWindowsMachine(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_basicWindowsMachine(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -242,7 +236,7 @@ func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -250,9 +244,10 @@ func TestAccAzureRMVirtualMachine_basicWindowsMachine(t *testing.T) { } func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_windowsUnattendedConfig(ri, acceptance.Location(), "Standard_D1_v2") + config := testAccAzureRMVirtualMachine_windowsUnattendedConfig(data, "Standard_D1_v2") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -261,7 +256,7 @@ func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -269,10 +264,11 @@ func TestAccAzureRMVirtualMachine_windowsUnattendedConfig(t *testing.T) { } func TestAccAzureRMVirtualMachine_windowsMachineResize(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualMachine_windowsUnattendedConfig(ri, acceptance.Location(), "Standard_D1_v2") - postConfig := testAccAzureRMVirtualMachine_windowsUnattendedConfig(ri, acceptance.Location(), "Standard_D2_v2") + preConfig := testAccAzureRMVirtualMachine_windowsUnattendedConfig(data, "Standard_D1_v2") + postConfig := testAccAzureRMVirtualMachine_windowsUnattendedConfig(data, "Standard_D2_v2") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -281,13 +277,13 @@ func TestAccAzureRMVirtualMachine_windowsMachineResize(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -295,9 +291,10 @@ func TestAccAzureRMVirtualMachine_windowsMachineResize(t *testing.T) { } func TestAccAzureRMVirtualMachine_diagnosticsProfile(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_diagnosticsProfile(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_diagnosticsProfile(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -306,7 +303,7 @@ func TestAccAzureRMVirtualMachine_diagnosticsProfile(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -314,9 +311,10 @@ func TestAccAzureRMVirtualMachine_diagnosticsProfile(t *testing.T) { } func TestAccAzureRMVirtualMachine_winRMConfig(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_winRMConfig(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_winRMConfig(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -325,7 +323,7 @@ func TestAccAzureRMVirtualMachine_winRMConfig(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -333,10 +331,11 @@ func TestAccAzureRMVirtualMachine_winRMConfig(t *testing.T) { } func TestAccAzureRMVirtualMachine_deleteVHDOptOut(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualMachine_withDataDisk(ri, acceptance.Location()) - postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM(ri, acceptance.Location()) + preConfig := testAccAzureRMVirtualMachine_withDataDisk(data) + postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -345,7 +344,7 @@ func TestAccAzureRMVirtualMachine_deleteVHDOptOut(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, { @@ -360,10 +359,11 @@ func TestAccAzureRMVirtualMachine_deleteVHDOptOut(t *testing.T) { } func TestAccAzureRMVirtualMachine_deleteVHDOptIn(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore(ri, acceptance.Location()) - postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter(ri, acceptance.Location()) + preConfig := testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore(data) + postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -372,7 +372,7 @@ func TestAccAzureRMVirtualMachine_deleteVHDOptIn(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, { @@ -387,11 +387,11 @@ func TestAccAzureRMVirtualMachine_deleteVHDOptIn(t *testing.T) { } func TestAccAzureRMVirtualMachine_ChangeComputerName(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") var afterCreate, afterUpdate compute.VirtualMachine - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualMachine_machineNameBeforeUpdate(ri, acceptance.Location()) - postConfig := testAccAzureRMVirtualMachine_updateMachineName(ri, acceptance.Location()) + preConfig := testAccAzureRMVirtualMachine_machineNameBeforeUpdate(data) + postConfig := testAccAzureRMVirtualMachine_updateMachineName(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -400,14 +400,14 @@ func TestAccAzureRMVirtualMachine_ChangeComputerName(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &afterCreate), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &afterUpdate), testAccCheckVirtualMachineRecreated( t, &afterCreate, &afterUpdate), ), @@ -417,11 +417,11 @@ func TestAccAzureRMVirtualMachine_ChangeComputerName(t *testing.T) { } func TestAccAzureRMVirtualMachine_ChangeAvailabilitySet(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") var afterCreate, afterUpdate compute.VirtualMachine - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualMachine_withAvailabilitySet(ri, acceptance.Location()) - postConfig := testAccAzureRMVirtualMachine_updateAvailabilitySet(ri, acceptance.Location()) + preConfig := testAccAzureRMVirtualMachine_withAvailabilitySet(data) + postConfig := testAccAzureRMVirtualMachine_updateAvailabilitySet(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -430,14 +430,14 @@ func TestAccAzureRMVirtualMachine_ChangeAvailabilitySet(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &afterCreate), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &afterUpdate), testAccCheckVirtualMachineRecreated( t, &afterCreate, &afterUpdate), ), @@ -447,11 +447,11 @@ func TestAccAzureRMVirtualMachine_ChangeAvailabilitySet(t *testing.T) { } func TestAccAzureRMVirtualMachine_changeStorageImageReference(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") var afterCreate, afterUpdate compute.VirtualMachine - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore(ri, acceptance.Location()) - postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter(ri, acceptance.Location()) + preConfig := testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore(data) + postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -460,14 +460,14 @@ func TestAccAzureRMVirtualMachine_changeStorageImageReference(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &afterCreate), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &afterUpdate), testAccCheckVirtualMachineRecreated( t, &afterCreate, &afterUpdate), ), @@ -477,11 +477,11 @@ func TestAccAzureRMVirtualMachine_changeStorageImageReference(t *testing.T) { } func TestAccAzureRMVirtualMachine_changeOSDiskVhdUri(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") var afterCreate, afterUpdate compute.VirtualMachine - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(ri, acceptance.Location()) - postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged(ri, acceptance.Location()) + preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(data) + postConfig := testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -490,14 +490,14 @@ func TestAccAzureRMVirtualMachine_changeOSDiskVhdUri(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterCreate), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &afterCreate), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &afterUpdate), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &afterUpdate), testAccCheckVirtualMachineRecreated( t, &afterCreate, &afterUpdate), ), @@ -509,8 +509,9 @@ func TestAccAzureRMVirtualMachine_changeOSDiskVhdUri(t *testing.T) { // to accept terms for config: // get-AzureRmMarketplaceTerms -publisher kemptech -product vlm-azure -name freeloadmaster | Set-AzureRmMarketplaceTerms -accept func TestAccAzureRMVirtualMachine_plan(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -518,9 +519,9 @@ func TestAccAzureRMVirtualMachine_plan(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualMachine_plan(ri, acceptance.Location()), + Config: testAccAzureRMVirtualMachine_plan(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -528,10 +529,11 @@ func TestAccAzureRMVirtualMachine_plan(t *testing.T) { } func TestAccAzureRMVirtualMachine_changeSSHKey(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - rs := strings.ToLower(acctest.RandString(10)) - preConfig := testAccAzureRMVirtualMachine_linuxMachineWithSSH(rs, acceptance.Location()) - postConfig := testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved(rs, acceptance.Location()) + preConfig := testAccAzureRMVirtualMachine_linuxMachineWithSSH(data) + postConfig := testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -540,13 +542,13 @@ func TestAccAzureRMVirtualMachine_changeSSHKey(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -554,13 +556,13 @@ func TestAccAzureRMVirtualMachine_changeSSHKey(t *testing.T) { } func TestAccAzureRMVirtualMachine_optionalOSProfile(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(ri, location) - prepConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_destroy(ri, location) - config := testAccAzureRMVirtualMachine_basicLinuxMachine_attach_without_osProfile(ri, location) + preConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(data) + prepConfig := testAccAzureRMVirtualMachine_basicLinuxMachine_destroy(data) + config := testAccAzureRMVirtualMachine_basicLinuxMachine_attach_without_osProfile(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -570,7 +572,7 @@ func TestAccAzureRMVirtualMachine_optionalOSProfile(t *testing.T) { Destroy: false, Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, { @@ -586,7 +588,7 @@ func TestAccAzureRMVirtualMachine_optionalOSProfile(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, @@ -594,9 +596,10 @@ func TestAccAzureRMVirtualMachine_optionalOSProfile(t *testing.T) { } func TestAccAzureRMVirtualMachine_primaryNetworkInterfaceId(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_machine", "test") + var vm compute.VirtualMachine - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualMachine_primaryNetworkInterfaceId(ri, acceptance.Location()) + config := testAccAzureRMVirtualMachine_primaryNetworkInterfaceId(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -605,14 +608,14 @@ func TestAccAzureRMVirtualMachine_primaryNetworkInterfaceId(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm), + testCheckAzureRMVirtualMachineExists(data.ResourceName, &vm), ), }, }, }) } -func testAccAzureRMVirtualMachine_basicLinuxMachine(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -701,10 +704,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_destroyVM(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_destroyVM(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -755,10 +758,10 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_storageBlob_attach(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_storageBlob_attach(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -865,10 +868,10 @@ resource "azurerm_virtual_machine" "test" { environment = "Production" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachineSSHOnly(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachineSSHOnly(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -961,11 +964,11 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachineUseExistingOsDiskImage(rInt int, location string) string { - baseConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(rInt, location) +func testAccAzureRMVirtualMachine_basicLinuxMachineUseExistingOsDiskImage(data acceptance.TestData) string { + baseConfig := testAccAzureRMVirtualMachine_basicLinuxMachine(data) return fmt.Sprintf(`%s resource "azurerm_network_interface" "mirror" { name = "acctmirrorni-%d" @@ -1005,10 +1008,10 @@ resource "azurerm_virtual_machine" "mirror" { os_type = "Linux" } } -`, baseConfig, rInt, rInt, rInt) +`, baseConfig, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_machineNameBeforeUpdate(rInt int, location string) string { +func testAccAzureRMVirtualMachine_machineNameBeforeUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1097,10 +1100,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksBefore(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1205,10 +1208,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachineDestroyDisksAfter(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1264,10 +1267,10 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachineDeleteVM(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1318,10 +1321,10 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_withDataDisk(rInt int, location string) string { +func testAccAzureRMVirtualMachine_withDataDisk(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1418,10 +1421,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachineUpdated(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachineUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1508,10 +1511,10 @@ resource "azurerm_virtual_machine" "test" { environment = "Production" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_updatedLinuxMachine(rInt int, location string) string { +func testAccAzureRMVirtualMachine_updatedLinuxMachine(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1594,10 +1597,10 @@ resource "azurerm_virtual_machine" "test" { disable_password_authentication = false } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicWindowsMachine(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicWindowsMachine(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1681,10 +1684,10 @@ resource "azurerm_virtual_machine" "test" { provision_vm_agent = true } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_windowsUnattendedConfig(rInt int, location string, vmSize string) string { +func testAccAzureRMVirtualMachine_windowsUnattendedConfig(data acceptance.TestData, vmSize string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1774,10 +1777,10 @@ resource "azurerm_virtual_machine" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, vmSize) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, vmSize) } -func testAccAzureRMVirtualMachine_diagnosticsProfile(rInt int, location string) string { +func testAccAzureRMVirtualMachine_diagnosticsProfile(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1867,10 +1870,10 @@ resource "azurerm_virtual_machine" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_winRMConfig(rInt int, location string) string { +func testAccAzureRMVirtualMachine_winRMConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1955,10 +1958,10 @@ resource "azurerm_virtual_machine" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_withAvailabilitySet(rInt int, location string) string { +func testAccAzureRMVirtualMachine_withAvailabilitySet(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2049,10 +2052,10 @@ resource "azurerm_virtual_machine" "test" { disable_password_authentication = false } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_updateAvailabilitySet(rInt int, location string) string { +func testAccAzureRMVirtualMachine_updateAvailabilitySet(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2143,10 +2146,10 @@ resource "azurerm_virtual_machine" "test" { disable_password_authentication = false } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_updateMachineName(rInt int, location string) string { +func testAccAzureRMVirtualMachine_updateMachineName(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2230,10 +2233,10 @@ resource "azurerm_virtual_machine" "test" { disable_password_authentication = false } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageBefore(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2323,10 +2326,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachineStorageImageAfter(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2416,10 +2419,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachineWithOSDiskVhdUriChanged(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2508,10 +2511,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_plan(rInt int, location string) string { +func testAccAzureRMVirtualMachine_plan(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2606,10 +2609,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_linuxMachineWithSSH(rString string, location string) string { +func testAccAzureRMVirtualMachine_linuxMachineWithSSH(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG%s" @@ -2694,10 +2697,10 @@ resource "azurerm_virtual_machine" "test" { } } } -`, rString, location, rString, rString, rString, rString, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString, data.RandomString, data.RandomString, data.RandomString) } -func testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved(rString string, location string) string { +func testAccAzureRMVirtualMachine_linuxMachineWithSSHRemoved(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG%s" @@ -2777,10 +2780,10 @@ resource "azurerm_virtual_machine" "test" { disable_password_authentication = true } } -`, rString, location, rString, rString, rString, rString, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString, data.RandomString, data.RandomString, data.RandomString) } -func testAccAzureRMVirtualMachine_primaryNetworkInterfaceId(rInt int, location string) string { +func testAccAzureRMVirtualMachine_primaryNetworkInterfaceId(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2882,10 +2885,10 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_destroy(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_destroy(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -2936,10 +2939,10 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualMachine_basicLinuxMachine_attach_without_osProfile(rInt int, location string) string { +func testAccAzureRMVirtualMachine_basicLinuxMachine_attach_without_osProfile(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -3011,7 +3014,7 @@ resource "azurerm_virtual_machine" "test" { cost-center = "Ops" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMVirtualMachineVHDExistence(blobName string, shouldExist bool) resource.TestCheckFunc { diff --git a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_auth_test.go b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_auth_test.go similarity index 69% rename from azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_auth_test.go rename to azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_auth_test.go index 1471bd25c8f5..1649cf171ca9 100644 --- a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_auth_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_auth_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMWindowsVirtualMachineScaleSet_authPassword(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,27 +17,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_authPassword(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go similarity index 62% rename from azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go rename to azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go index 079abf6ed00b..050d4643675c 100644 --- a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_disk_data_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskBasic(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,29 +17,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskBasic(t *testing.T CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskBasic(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskCaching(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,60 +39,40 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskCaching(t *testing CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskCaching(ri, location, "None"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskCaching(data, "None"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskCaching(ri, location, "ReadOnly"), + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskCaching(data, "ReadOnly"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskCaching(ri, location, "ReadWrite"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskCaching(data, "ReadWrite"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskResizing(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -112,46 +81,32 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskResizing(t *testin Steps: []resource.TestStep{ { // 30GB - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskResize(ri, location, 30), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskResize(data, 30), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // 60GB - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskResize(ri, location, 60), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskResize(data, 60), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskMultiple(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -159,29 +114,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskMultiple(t *testin CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskMultiple(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskMultiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskRemove(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -189,45 +136,31 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskRemove(t *testing. CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskBasic(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskScaling(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -236,80 +169,54 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskScaling(t *testing Steps: []resource.TestStep{ { // no disks - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // one disk - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskBasic(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // two disks - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskMultiple(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskMultiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // no disks - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountTypeStandardLRS(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -317,29 +224,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType(ri, location, "Standard_LRS"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType(data, "Standard_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountTypeStandardSSDLRS(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -347,29 +246,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType(ri, location, "StandardSSD_LRS"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType(data, "StandardSSD_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountTypePremiumLRS(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -377,60 +268,44 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType(ri, location, "Premium_LRS"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType(data, "Premium_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUltraSSDLRS(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - // Are supported in East US 2, SouthEast Asia, and North Europe, in two availability zones per region - location := acceptance.AltLocation() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") + // Are supported in East US 2, SouthEast Asia, and North Europe, in two availability zones per region resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUltraSSDLRS(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUltraSSDLRS(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnabled(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -438,27 +313,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEn CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnabled(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskBasic(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskBasic(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -504,8 +373,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskCaching(rInt int, location, caching string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskCaching(data acceptance.TestData, caching string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -551,8 +420,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, caching) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskResize(rInt int, location string, diskSizeGb int) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskResize(data acceptance.TestData, diskSizeGb int) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -598,8 +467,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, diskSizeGb) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskMultiple(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskMultiple(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -652,8 +521,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType(rInt int, location, storageAccountType string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountType(data acceptance.TestData, storageAccountType string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -699,8 +568,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, storageAccountType) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUltraSSDLRS(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskStorageAccountTypeUltraSSDLRS(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -750,8 +619,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnabled(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksDataDiskWriteAcceleratorEnabled(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go similarity index 62% rename from azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go rename to azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go index 4b374cd233e4..a361ec536fbe 100644 --- a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_disk_os_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCaching(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,59 +17,39 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCaching(t *testing.T CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCaching(ri, location, "None"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCaching(data, "None"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCaching(ri, location, "ReadOnly"), + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCaching(data, "ReadOnly"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCaching(ri, location, "ReadWrite"), + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCaching(data, "ReadWrite"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCustomSize(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,62 +58,42 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCustomSize(t *testin Steps: []resource.TestStep{ { // unset - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCustomSize(ri, location, 128), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCustomSize(data, 128), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // resize a second time to confirm https://github.com/Azure/azure-rest-api-specs/issues/1906 - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCustomSize(ri, location, 256), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCustomSize(data, 256), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskEphemeral(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -144,29 +101,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskEphemeral(t *testing CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskEphemeral(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskEphemeral(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountTypeStandardLRS(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,29 +123,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountTypeSt CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountType(ri, location, "Standard_LRS"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountType(data, "Standard_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountTypeStandardSSDLRS(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -204,29 +145,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountTypeSt CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountType(ri, location, "StandardSSD_LRS"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountType(data, "StandardSSD_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountTypePremiumLRS(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -234,29 +167,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountTypePr CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountType(ri, location, "Premium_LRS"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountType(data, "Premium_LRS"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnabled(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -264,27 +189,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnab CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnabled(ri, location, true), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnabled(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCaching(rInt int, location, caching string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCaching(data acceptance.TestData, caching string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -323,8 +242,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, caching) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCustomSize(rInt int, location string, diskSize int) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskCustomSize(data acceptance.TestData, diskSize int) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -364,8 +283,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, diskSize) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskEphemeral(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskEphemeral(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -408,8 +327,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountType(rInt int, location, storageAccountType string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskStorageAccountType(data acceptance.TestData, storageAccountType string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -448,8 +367,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, storageAccountType) } -func testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnabled(rInt int, location string, enabled bool) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_disksOSDiskWriteAcceleratorEnabled(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_identity_test.go b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_identity_test.go similarity index 59% rename from azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_identity_test.go rename to azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_identity_test.go index f0e9f08f9a14..53e2cb241415 100644 --- a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_identity_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_identity_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMWindowsVirtualMachineScaleSet_identityNone(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,30 +17,22 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_identityNone(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.%", "0"), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssigned(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,65 +40,45 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssigned(t *testi CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssigned(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.principal_id"), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // disable it - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.%", "0"), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.%", "0"), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssigned(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.principal_id"), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssigned(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -117,80 +86,54 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssigned(t *testing CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssigned(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // disable it - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.%", "0"), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.%", "0"), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssigned(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // second - Config: testAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssignedUpdated(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssignedUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssignedUserAssigned(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -198,63 +141,45 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssignedUserAssig CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssignedUserAssigned(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssignedUserAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.principal_id"), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // disable it - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.%", "0"), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.%", "0"), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssignedUserAssigned(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssignedUserAssigned(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.principal_id"), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssigned(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssigned(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -297,8 +222,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssigned(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssigned(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -347,11 +272,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { ] } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssignedUpdated(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_identityUserAssignedUpdated(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -407,11 +332,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { ] } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssignedUserAssigned(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_identitySystemAssignedUserAssigned(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -460,5 +385,5 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { ] } } -`, template, rInt) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_images_test.go b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_images_test.go similarity index 74% rename from azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_images_test.go rename to azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_images_test.go index d748a56cafbf..a61933a574ec 100644 --- a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_images_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_images_test.go @@ -1,19 +1,15 @@ -package compute +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesAutomaticUpdate(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,48 +17,33 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesAutomaticUpdate(t *testin CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesAutomaticUpdate(ri, location, "2016-Datacenter"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesAutomaticUpdate(data, "2016-Datacenter"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "enable_automatic_updates", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "enable_automatic_updates", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesAutomaticUpdate(ri, location, "2019-Datacenter"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesAutomaticUpdate(data, "2019-Datacenter"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "enable_automatic_updates", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "enable_automatic_updates", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesFromCapturedVirtualMachineImage(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - rString := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -71,58 +52,44 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesFromCapturedVirtualMachin Steps: []resource.TestStep{ { // provision a standard Virtual Machine with an Unmanaged Disk - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithVM(ri, location, rString), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithVM(data), }, { // then delete the Virtual Machine - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(ri, location, rString), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(data), }, { // then capture two images of the Virtual Machine - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(ri, location, rString), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(data), }, { // then provision a Virtual Machine Scale Set using this image - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachine(ri, location, rString, "first"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachine(data, "first"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // then update the image on this Virtual Machine Scale Set - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachine(ri, location, rString, "second"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachine(data, "second"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdate(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -130,45 +97,31 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdate(t *testing.T CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdate(ri, location, "2016-Datacenter"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdate(data, "2016-Datacenter"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdate(ri, location, "2019-Datacenter"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdate(data, "2019-Datacenter"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdateExternalRoll(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -176,45 +129,31 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdateExternalRoll( CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdateExternalRoll(ri, location, "2016-Datacenter"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdateExternalRoll(data, "2016-Datacenter"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdateExternalRoll(ri, location, "2019-Datacenter"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdateExternalRoll(data, "2019-Datacenter"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesRollingUpdate(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -222,45 +161,31 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesRollingUpdate(t *testing. CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesRollingUpdate(ri, location, "2019-Datacenter"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesRollingUpdate(data, "2019-Datacenter"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesRollingUpdate(ri, location, "2019-Datacenter"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesRollingUpdate(data, "2019-Datacenter"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesPlan(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -268,27 +193,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_imagesPlan(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesPlan(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_imagesPlan(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMWindowsVirtualMachineScaleSet_imagesAutomaticUpdate(rInt int, location, version string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_imagesAutomaticUpdate(data acceptance.TestData, version string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -398,11 +317,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { depends_on = ["azurerm_lb_rule.test"] } -`, template, rInt, rInt, version) +`, template, data.RandomInteger, data.RandomInteger, version) } -func testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(rInt int, location, rString string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -439,11 +358,11 @@ resource "azurerm_storage_container" "test" { storage_account_name = azurerm_storage_account.test.name container_access_type = "blob" } -`, template, rInt, rInt, rString) +`, template, data.RandomInteger, data.RandomInteger, data.RandomString) } -func testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithVM(rInt int, location, rString string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(rInt, location, rString) +func testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithVM(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(data) return fmt.Sprintf(` %s @@ -480,8 +399,8 @@ resource "azurerm_virtual_machine" "source" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(rInt int, location, rString string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(rInt, location, rString) +func testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisites(data) return fmt.Sprintf(` %s @@ -517,8 +436,8 @@ resource "azurerm_image" "second" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachine(rInt int, location, rString, image string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(rInt, location, rString) +func testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachine(data acceptance.TestData, image string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_imagesFromVirtualMachinePrerequisitesWithImage(data) return fmt.Sprintf(` %s @@ -551,8 +470,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, image) } -func testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdate(rInt int, location, version string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdate(data acceptance.TestData, version string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -591,8 +510,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, version) } -func testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdateExternalRoll(rInt int, location, version string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_imagesManualUpdateExternalRoll(data acceptance.TestData, version string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -632,8 +551,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, version) } -func testAccAzureRMWindowsVirtualMachineScaleSet_imagesRollingUpdate(rInt int, location, version string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_imagesRollingUpdate(data acceptance.TestData, version string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -738,11 +657,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { depends_on = ["azurerm_lb_rule.test"] } -`, template, rInt, rInt, version) +`, template, data.RandomInteger, data.RandomInteger, version) } -func testAccAzureRMWindowsVirtualMachineScaleSet_imagesPlan(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_imagesPlan(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -790,7 +709,7 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { publisher = "plesk" } - depends_on = ["azurerm_marketplace_agreement.test"] + depends_on = ["azurerm_marketplace_agreement", "test")] } `, template) } diff --git a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_network_test.go b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_network_test.go similarity index 72% rename from azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_network_test.go rename to azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_network_test.go index 8bf659dd8529..48d9f3ffc093 100644 --- a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_network_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_network_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -6,14 +6,11 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,29 +18,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(t CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(ri, location, true), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworkingUpdated(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,61 +40,41 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworkingUpd CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(ri, location, false), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(ri, location, true), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(ri, location, false), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationGateway(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,29 +82,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationGateway(t *te CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationGateway(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationGateway(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroup(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -143,29 +104,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroup CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroup(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroupUpdate(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,80 +127,54 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroup Steps: []resource.TestStep{ { // none - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // one - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroup(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // another - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroupUpdated(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroupUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // none - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkDNSServers(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -255,45 +182,31 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkDNSServers(t *testing.T) CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkDNSServers(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkDNSServers(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkDNSServersUpdated(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkDNSServersUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkIPForwarding(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -302,63 +215,43 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkIPForwarding(t *testing. Steps: []resource.TestStep{ { // enabled - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkIPForwarding(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkIPForwarding(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // disabled - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // enabled - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkIPForwarding(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkIPForwarding(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkIPv6(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -366,9 +259,9 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkIPv6(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkIPv6(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkIPv6(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), ExpectError: regexp.MustCompile("Error expanding `network_interface`: An IPv6 Primary IP Configuration is unsupported - instead add a IPv4 IP Configuration as the Primary and make the IPv6 IP Configuration the secondary"), }, @@ -377,9 +270,7 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkIPv6(t *testing.T) { } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkLoadBalancer(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -387,29 +278,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkLoadBalancer(t *testing. CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkLoadBalancer(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkLoadBalancer(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurations(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -417,29 +300,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurations CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurations(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurations(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurationsIPv6(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -447,29 +322,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurations CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurationsIPv6(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurationsIPv6(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICs(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -477,29 +344,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICs(t *testing. CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICs(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultipleIPConfigurations(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -507,29 +366,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultipleIPCo CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultipleIPConfigurations(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultipleIPConfigurations(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultiplePublicIPs(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -537,29 +388,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultiplePubl CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultiplePublicIPs(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultiplePublicIPs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsWithDifferentDNSServers(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -567,29 +410,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsWithDifferen CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsWithDifferentDNSServers(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsWithDifferentDNSServers(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroup(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -597,29 +432,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroup(t * CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroup(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroupUpdate(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -628,80 +455,54 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroupUpda Steps: []resource.TestStep{ { // without - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // add one - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroup(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // change it - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroupUpdated(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroupUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // remove it - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -709,29 +510,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIP(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -739,29 +532,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIP(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIP(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIP(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPDomainNameLabel(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -769,29 +554,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPDomainNameLabel( CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPDomainNameLabel(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPDomainNameLabel(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPFromPrefix(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -799,29 +576,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPFromPrefix(t *te CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPFromPrefix(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPFromPrefix(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPTags(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -829,27 +598,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPTags(t *testing. CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPTags(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(rInt int, location string, enabled bool) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkAcceleratedNetworking(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -889,8 +652,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, enabled) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationGateway(rInt int, location string) string { - name := testAccAzureRMWindowsVirtualMachineScaleSet_vmName(rInt) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationGateway(data acceptance.TestData) string { + name := testAccAzureRMWindowsVirtualMachineScaleSet_vmName(data) return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1026,11 +789,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt, name) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, name) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroup(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroup(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1073,11 +836,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroupUpdated(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkApplicationSecurityGroupUpdated(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1129,11 +892,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkDNSServers(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkDNSServers(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1173,8 +936,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkDNSServersUpdated(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkDNSServersUpdated(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1214,8 +977,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkIPForwarding(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkIPForwarding(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1255,8 +1018,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkIPv6(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkIPv6(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1295,8 +1058,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkLoadBalancer(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkLoadBalancer(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1370,11 +1133,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurations(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurations(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1418,8 +1181,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurationsIPv6(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleIPConfigurationsIPv6(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1464,8 +1227,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICs(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICs(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1514,8 +1277,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultipleIPConfigurations(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultipleIPConfigurations(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1574,8 +1337,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsWithDifferentDNSServers(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsWithDifferentDNSServers(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1626,8 +1389,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultiplePublicIPs(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkMultipleNICsMultiplePublicIPs(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1685,11 +1448,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroup(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroup(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1732,11 +1495,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroupUpdated(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkNetworkSecurityGroupUpdated(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1785,11 +1548,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkPrivate(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1828,8 +1591,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIP(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIP(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1873,8 +1636,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPDomainNameLabel(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPDomainNameLabel(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1916,11 +1679,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPFromPrefix(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPFromPrefix(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1967,11 +1730,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPTags(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_networkPublicIPTags(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_other_test.go b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_other_test.go similarity index 71% rename from azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_other_test.go rename to azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_other_test.go index f380e7400ff0..eff638fcc1d6 100644 --- a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_other_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_other_test.go @@ -1,20 +1,16 @@ -package compute +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMWindowsVirtualMachineScaleSet_otherAdditionalUnattendConfig(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,31 +18,22 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherAdditionalUnattendConfig(t CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherAdditionalUnattendConfig(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherAdditionalUnattendConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "additional_unattend_config.0.content", - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "additional_unattend_config.0.content", + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnostics(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,63 +42,43 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnostics(t *testing Steps: []resource.TestStep{ { // Enabled - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnostics(ri, location, rs), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnostics(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // Removed - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnosticsDisabled(ri, location, rs), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnosticsDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // Enabled - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnostics(ri, location, rs), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnostics(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherComputerNamePrefix(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -119,29 +86,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherComputerNamePrefix(t *test CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherComputerNamePrefix(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherComputerNamePrefix(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherCustomData(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -149,65 +108,45 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherCustomData(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherCustomData(ri, location, "/bin/bash"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherCustomData(data, "/bin/bash"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "custom_data", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "custom_data", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherCustomData(ri, location, "/bin/zsh"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherCustomData(data, "/bin/zsh"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "custom_data", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "custom_data", + "terraform_should_roll_instances_when_required", + ), { // removed - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "custom_data", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "custom_data", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProvisionedMachines(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -215,29 +154,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverPr CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProvisionedMachines(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProvisionedMachines(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherEnableAutomaticUpdatesDisabled(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -245,62 +176,42 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherEnableAutomaticUpdatesDisa CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherEnableAutomaticUpdatesDisabled(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherEnableAutomaticUpdatesDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // enabled - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherEnableAutomaticUpdatesDisabled(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherEnableAutomaticUpdatesDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowDeallocate(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -308,29 +219,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowDeallocate(t *t CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLow(ri, location, "Deallocate"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLow(data, "Deallocate"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowDelete(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -338,29 +241,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowDelete(t *testi CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLow(ri, location, "Delete"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLow(data, "Delete"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -369,45 +264,31 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(t * Steps: []resource.TestStep{ { // expensive, but guarantees this test will pass - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(ri, location, "0.5000"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(data, "0.5000"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(ri, location, "-1"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(data, "-1"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityRegular(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -415,21 +296,15 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityRegular(t *testing CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityRegular(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityRegular(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } @@ -439,9 +314,7 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherRequiresImport(t *testing. t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -449,13 +322,13 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherRequiresImport(t *testing. CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherRequiresImport(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherRequiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_windows_virtual_machine_scale_set"), }, }, @@ -463,10 +336,7 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherRequiresImport(t *testing. } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherSecret(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -474,67 +344,44 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherSecret(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherSecret(ri, location, rs), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherSecret(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // update - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretUpdated(ri, location, rs), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // removed - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretRemoved(ri, location, rs), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretRemoved(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherTags(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -542,63 +389,43 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherTags(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherTags(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // add one - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherTagsUpdated(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherTagsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // remove all - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherTimeZone(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -606,29 +433,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherTimeZone(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherTimeZone(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherTimeZone(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherVMAgent(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -636,29 +455,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherVMAgent(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherVMAgent(ri, location, true), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherVMAgent(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherVMAgentDisabled(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -666,29 +477,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherVMAgentDisabled(t *testing CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherVMAgent(ri, location, false), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherVMAgent(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTP(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -696,29 +499,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTP(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTP(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTP(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTPS(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -726,27 +521,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTPS(t *testing.T) { CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTPS(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTPS(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherAdditionalUnattendConfig(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherAdditionalUnattendConfig(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -790,8 +579,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnostics(rInt int, location string, rString string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnostics(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -839,11 +628,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { storage_account_uri = azurerm_storage_account.test.primary_blob_endpoint } } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnosticsDisabled(rInt int, location string, rString string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherBootDiagnosticsDisabled(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -887,11 +676,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherComputerNamePrefix(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherComputerNamePrefix(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -931,8 +720,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherCustomData(rInt int, location, customData string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherCustomData(data acceptance.TestData, customData string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -972,8 +761,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, customData) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProvisionedMachines(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherDoNotRunExtensionsOnOverProvisionedMachines(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1015,8 +804,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherEnableAutomaticUpdatesDisabled(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherEnableAutomaticUpdatesDisabled(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1056,8 +845,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLow(rInt int, location, evictionPolicy string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLow(data acceptance.TestData, evictionPolicy string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1098,8 +887,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, evictionPolicy) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(rInt int, location, maxBid string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityLowMaxBidPrice(data acceptance.TestData, maxBid string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1141,8 +930,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, maxBid) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityRegular(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherPriorityRegular(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1182,8 +971,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherRequiresImport(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherRequiresImport(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data) return fmt.Sprintf(` %s @@ -1222,8 +1011,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "import" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherSecret(rInt int, location string, rString string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretTemplate(rInt, location, rString) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherSecret(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretTemplate(data) return fmt.Sprintf(` %s @@ -1271,8 +1060,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretRemoved(rInt int, location string, rString string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretTemplate(rInt, location, rString) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretRemoved(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretTemplate(data) return fmt.Sprintf(` %s @@ -1311,8 +1100,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretUpdated(rInt int, location string, rString string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretTemplate(rInt, location, rString) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretUpdated(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretTemplate(data) return fmt.Sprintf(` %s @@ -1365,8 +1154,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretTemplate(rInt int, location string, rString string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherSecretTemplate(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1498,11 +1287,11 @@ resource "azurerm_key_vault_certificate" "second" { } } } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherTags(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherTags(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1545,8 +1334,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherTagsUpdated(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherTagsUpdated(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1590,8 +1379,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherTimeZone(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherTimeZone(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1631,8 +1420,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherVMAgent(rInt int, location string, enabled bool) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherVMAgent(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1672,8 +1461,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, enabled) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTP(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTP(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -1716,10 +1505,10 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTPS(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_otherWinRMHTTPS(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) // key vault name can only be up to 24 chars - trimmedName := fmt.Sprintf("%d", rInt)[0:5] + trimmedName := fmt.Sprintf("%d", data.RandomInteger)[0:5] return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_scaling_test.go b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_scaling_test.go similarity index 69% rename from azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_scaling_test.go rename to azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_scaling_test.go index 52a121cd671f..bc2d34bc21f1 100644 --- a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_scaling_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_scaling_test.go @@ -1,18 +1,15 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingAutoScale(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,29 +17,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingAutoScale(t *testing.T) CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingAutoScale(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingAutoScale(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,73 +39,49 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(t *testing CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(ri, location, 1), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(data, 1), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(ri, location, 3), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(data, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(ri, location, 5), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(data, 5), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // update the count but the `sku` should be ignored - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCountIgnoreUpdatedSku(ri, location, 3), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCountIgnoreUpdatedSku(data, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // confirm that the `sku` hasn't been changed - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(ri, location, 3), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(data, 3), PlanOnly: true, }, }, @@ -124,9 +89,7 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(t *testing } func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingOverProvisionDisabled(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -134,29 +97,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingOverProvisionDisabled(t CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingOverProvisionDisabled(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingOverProvisionDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingProximityPlacementGroup(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -164,29 +119,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingProximityPlacementGroup( CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingProximityPlacementGroup(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingProximityPlacementGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -194,29 +141,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingSinglePlacementGroupDisa CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingSinglePlacementGroupDisabledUpdate(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -224,45 +163,31 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingSinglePlacementGroupDisa CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_authPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -270,62 +195,44 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(t *testing.T) CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(ri, location, "Standard_F2"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(data, "Standard_F2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(ri, location, "Standard_F4"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(data, "Standard_F4"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, - { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(ri, location, "Standard_F2"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(data, "Standard_F2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), { // confirms that the `instances` count comes from the API - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSkuIgnoredUpdatedCount(ri, location, "Standard_F2"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSkuIgnoredUpdatedCount(data, "Standard_F2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(ri, location, "Standard_F2"), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(data, "Standard_F2"), PlanOnly: true, }, }, @@ -333,9 +240,7 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(t *testing.T) } func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesSingle(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -343,29 +248,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesSingle(t *testing.T CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesSingle(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesSingle(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesMultiple(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -373,29 +270,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesMultiple(t *testing CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesMultiple(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesMultiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesBalance(t *testing.T) { - resourceName := "azurerm_windows_virtual_machine_scale_set.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_windows_virtual_machine_scale_set", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -403,27 +292,21 @@ func TestAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesBalance(t *testing. CheckDestroy: testCheckAzureRMWindowsVirtualMachineScaleSetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesBalance(ri, location), + Config: testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesBalance(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName), + testCheckAzureRMWindowsVirtualMachineScaleSetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "admin_password", - "terraform_should_roll_instances_when_required", - }, - }, + data.ImportStep( + "admin_password", + "terraform_should_roll_instances_when_required", + ), }, }) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingAutoScale(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingAutoScale(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -520,8 +403,8 @@ resource "azurerm_monitor_autoscale_setting" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(rInt int, location string, instanceCount int) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCount(data acceptance.TestData, instanceCount int) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -560,8 +443,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, instanceCount) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCountIgnoreUpdatedSku(rInt int, location string, instanceCount int) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingInstanceCountIgnoreUpdatedSku(data acceptance.TestData, instanceCount int) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -604,8 +487,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, instanceCount) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingOverProvisionDisabled(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingOverProvisionDisabled(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -645,8 +528,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingProximityPlacementGroup(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingProximityPlacementGroup(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -689,11 +572,11 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingSinglePlacementGroupDisabled(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -733,8 +616,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(rInt int, location, skuName string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSku(data acceptance.TestData, skuName string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -773,8 +656,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, skuName) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSkuIgnoredUpdatedCount(rInt int, location, skuName string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingUpdateSkuIgnoredUpdatedCount(data acceptance.TestData, skuName string) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -817,8 +700,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template, skuName) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesSingle(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesSingle(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -858,8 +741,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesMultiple(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesMultiple(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s @@ -899,8 +782,8 @@ resource "azurerm_windows_virtual_machine_scale_set" "test" { `, template) } -func testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesBalance(rInt int, location string) string { - template := testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt, location) +func testAccAzureRMWindowsVirtualMachineScaleSet_scalingZonesBalance(data acceptance.TestData) string { + template := testAccAzureRMWindowsVirtualMachineScaleSet_template(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_test.go similarity index 86% rename from azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_test.go rename to azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_test.go index 3b89cf061f2d..66953cb2669c 100644 --- a/azurerm/internal/services/compute/resource_arm_windows_virtual_machine_scale_set_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -61,13 +61,13 @@ func testCheckAzureRMWindowsVirtualMachineScaleSetExists(resourceName string) re } } -func testAccAzureRMWindowsVirtualMachineScaleSet_vmName(rInt int) string { +func testAccAzureRMWindowsVirtualMachineScaleSet_vmName(data acceptance.TestData) string { // windows VM names can be up to 15 chars, however the prefix can only be 9 chars - return fmt.Sprintf("acctvm%s", fmt.Sprintf("%d", rInt)[0:2]) + return fmt.Sprintf("acctvm%s", fmt.Sprintf("%d", data.RandomInteger)[0:2]) } -func testAccAzureRMWindowsVirtualMachineScaleSet_template(rInt int, location string) string { - name := testAccAzureRMWindowsVirtualMachineScaleSet_vmName(rInt) +func testAccAzureRMWindowsVirtualMachineScaleSet_template(data acceptance.TestData) string { + name := testAccAzureRMWindowsVirtualMachineScaleSet_vmName(data) return fmt.Sprintf(` locals { vm_name = "%s" @@ -91,5 +91,5 @@ resource "azurerm_subnet" "test" { virtual_network_name = azurerm_virtual_network.test.name address_prefix = "10.0.2.0/24" } -`, name, rInt, location, rInt) +`, name, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go b/azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go index eba10de600f6..f8f039348398 100644 --- a/azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go +++ b/azurerm/internal/services/logic/tests/data_source_logic_app_workflow_test.go @@ -31,7 +31,6 @@ func TestAccDataSourceAzureRMLogicAppWorkflow_basic(t *testing.T) { func TestAccDataSourceAzureRMLogicAppWorkflow_tags(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_logic_app_workflow", "test") - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, diff --git a/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_http_test.go b/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_http_test.go index d8cb86c0bad3..5f20ca451b52 100644 --- a/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_http_test.go +++ b/azurerm/internal/services/logic/tests/resource_arm_logic_app_action_http_test.go @@ -78,7 +78,6 @@ func TestAccAzureRMLogicAppActionHttp_headers(t *testing.T) { func TestAccAzureRMLogicAppActionHttp_disappears(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_logic_app_action_http", "test") - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, From c02e7faca52e2e4d3670be26418a46e2e70e30d5 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 20 Dec 2019 17:38:18 -0800 Subject: [PATCH 099/203] maps: switching to the new test structure --- .../maps/data_source_maps_account_test.go | 49 ----------- .../tests/data_source_maps_account_test.go | 46 ++++++++++ .../resource_arm_maps_account_test.go | 87 +++++++------------ 3 files changed, 79 insertions(+), 103 deletions(-) delete mode 100644 azurerm/internal/services/maps/data_source_maps_account_test.go create mode 100644 azurerm/internal/services/maps/tests/data_source_maps_account_test.go rename azurerm/internal/services/maps/{ => tests}/resource_arm_maps_account_test.go (63%) diff --git a/azurerm/internal/services/maps/data_source_maps_account_test.go b/azurerm/internal/services/maps/data_source_maps_account_test.go deleted file mode 100644 index 1c54695188c6..000000000000 --- a/azurerm/internal/services/maps/data_source_maps_account_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package maps - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMMapsAccount_basic(t *testing.T) { - dataSourceName := "data.azurerm_maps_account.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMMapsAccount_basic(rInt, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "id"), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "testing"), - resource.TestCheckResourceAttr(dataSourceName, "sku_name", "S0"), - resource.TestCheckResourceAttrSet(dataSourceName, "x_ms_client_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(dataSourceName, "secondary_access_key"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMMapsAccount_basic(rInt int, location string) string { - template := testAccAzureRMMapsAccount_tags(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_maps_account" "test" { - name = azurerm_maps_account.test.name - resource_group_name = azurerm_resource_group.test.name -} -`, template) -} diff --git a/azurerm/internal/services/maps/tests/data_source_maps_account_test.go b/azurerm/internal/services/maps/tests/data_source_maps_account_test.go new file mode 100644 index 000000000000..efd647e6721f --- /dev/null +++ b/azurerm/internal/services/maps/tests/data_source_maps_account_test.go @@ -0,0 +1,46 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMMapsAccount_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_maps_account", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMMapsAccount_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "testing"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "S0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "x_ms_client_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMMapsAccount_basic(data acceptance.TestData) string { + template := testAccAzureRMMapsAccount_tags(data) + return fmt.Sprintf(` +%s + +data "azurerm_maps_account" "test" { + name = azurerm_maps_account.test.name + resource_group_name = azurerm_resource_group.test.name +} +`, template) +} diff --git a/azurerm/internal/services/maps/resource_arm_maps_account_test.go b/azurerm/internal/services/maps/tests/resource_arm_maps_account_test.go similarity index 63% rename from azurerm/internal/services/maps/resource_arm_maps_account_test.go rename to azurerm/internal/services/maps/tests/resource_arm_maps_account_test.go index 77b7559a3a46..39be07b89ee3 100644 --- a/azurerm/internal/services/maps/resource_arm_maps_account_test.go +++ b/azurerm/internal/services/maps/tests/resource_arm_maps_account_test.go @@ -1,4 +1,4 @@ -package maps +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMMapsAccount_basic(t *testing.T) { - resourceName := "azurerm_maps_account.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_maps_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,27 +21,22 @@ func TestAccAzureRMMapsAccount_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMapsAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMapsAccount_basic(ri, acceptance.Location()), + Config: testAccAzureRMMapsAccount_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "x_ms_client_id"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttr(resourceName, "sku_name", "S0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "x_ms_client_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "S0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMapsAccount_sku(t *testing.T) { - resourceName := "azurerm_maps_account.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_maps_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,28 +44,22 @@ func TestAccAzureRMMapsAccount_sku(t *testing.T) { CheckDestroy: testCheckAzureRMMapsAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMapsAccount_sku(ri, acceptance.Location()), + Config: testAccAzureRMMapsAccount_sku(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "x_ms_client_id"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttr(resourceName, "sku_name", "S1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "x_ms_client_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "S1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMapsAccount_tags(t *testing.T) { - resourceName := "azurerm_maps_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_maps_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,30 +67,22 @@ func TestAccAzureRMMapsAccount_tags(t *testing.T) { CheckDestroy: testCheckAzureRMMapsAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMapsAccount_basic(ri, location), + Config: testAccAzureRMMapsAccount_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMapsAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMMapsAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMapsAccount_tags(ri, location), + Config: testAccAzureRMMapsAccount_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMapsAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "testing"), + testCheckAzureRMMapsAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "testing"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -160,7 +139,7 @@ func testCheckAzureRMMapsAccountDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMapsAccount_basic(rInt int, location string) string { +func testAccAzureRMMapsAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -172,10 +151,10 @@ resource "azurerm_maps_account" "test" { resource_group_name = azurerm_resource_group.test.name sku_name = "S0" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMapsAccount_sku(rInt int, location string) string { +func testAccAzureRMMapsAccount_sku(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -187,10 +166,10 @@ resource "azurerm_maps_account" "test" { resource_group_name = azurerm_resource_group.test.name sku_name = "S1" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMapsAccount_tags(rInt int, location string) string { +func testAccAzureRMMapsAccount_tags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -206,5 +185,5 @@ resource "azurerm_maps_account" "test" { environment = "testing" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 274f4b049a797944e0a627f7230146bb99dd5c92 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 20 Dec 2019 17:38:52 -0800 Subject: [PATCH 100/203] managementgroup: switching to the new test structure --- .../data_source_management_group_test.go | 16 +++--- .../resource_arm_management_group_test.go | 53 ++++++++----------- 2 files changed, 30 insertions(+), 39 deletions(-) rename azurerm/internal/services/managementgroup/{ => tests}/data_source_management_group_test.go (57%) rename azurerm/internal/services/managementgroup/{ => tests}/resource_arm_management_group_test.go (84%) diff --git a/azurerm/internal/services/managementgroup/data_source_management_group_test.go b/azurerm/internal/services/managementgroup/tests/data_source_management_group_test.go similarity index 57% rename from azurerm/internal/services/managementgroup/data_source_management_group_test.go rename to azurerm/internal/services/managementgroup/tests/data_source_management_group_test.go index a74af54b7e00..ca7b12368de1 100644 --- a/azurerm/internal/services/managementgroup/data_source_management_group_test.go +++ b/azurerm/internal/services/managementgroup/tests/data_source_management_group_test.go @@ -1,34 +1,32 @@ -package managementgroup +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceArmManagementGroup_basic(t *testing.T) { - dataSourceName := "data.azurerm_management_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_management_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceArmManagementGroup_basic(ri), + Config: testAccDataSourceArmManagementGroup_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "display_name", fmt.Sprintf("acctestmg-%d", ri)), - resource.TestCheckResourceAttr(dataSourceName, "subscription_ids.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", fmt.Sprintf("acctestmg-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_ids.#", "0"), ), }, }, }) } -func testAccDataSourceArmManagementGroup_basic(rInt int) string { +func testAccDataSourceArmManagementGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_management_group" "test" { display_name = "acctestmg-%d" @@ -37,5 +35,5 @@ resource "azurerm_management_group" "test" { data "azurerm_management_group" "test" { group_id = "${azurerm_management_group.test.group_id}" } -`, rInt) +`, data.RandomInteger) } diff --git a/azurerm/internal/services/managementgroup/resource_arm_management_group_test.go b/azurerm/internal/services/managementgroup/tests/resource_arm_management_group_test.go similarity index 84% rename from azurerm/internal/services/managementgroup/resource_arm_management_group_test.go rename to azurerm/internal/services/managementgroup/tests/resource_arm_management_group_test.go index bb285e6103f5..4494028a1e1c 100644 --- a/azurerm/internal/services/managementgroup/resource_arm_management_group_test.go +++ b/azurerm/internal/services/managementgroup/tests/resource_arm_management_group_test.go @@ -1,4 +1,4 @@ -package managementgroup +package tests import ( "fmt" @@ -8,14 +8,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMManagementGroup_basic(t *testing.T) { - resourceName := "azurerm_management_group.test" + data := acceptance.BuildTestData(t, "azurerm_management_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,14 +24,10 @@ func TestAccAzureRMManagementGroup_basic(t *testing.T) { { Config: testAzureRMManagementGroup_basic(), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementGroupExists(resourceName), + testCheckAzureRMManagementGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,7 +38,7 @@ func TestAccAzureRMManagementGroup_requiresImport(t *testing.T) { return } - resourceName := "azurerm_management_group.test" + data := acceptance.BuildTestData(t, "azurerm_management_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,7 +48,7 @@ func TestAccAzureRMManagementGroup_requiresImport(t *testing.T) { { Config: testAzureRMManagementGroup_basic(), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementGroupExists(resourceName), + testCheckAzureRMManagementGroupExists(data.ResourceName), ), }, { @@ -135,8 +130,7 @@ func TestAccAzureRMManagementGroup_multiLevelUpdated(t *testing.T) { } func TestAccAzureRMManagementGroup_withName(t *testing.T) { - resourceName := "azurerm_management_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_management_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -144,9 +138,9 @@ func TestAccAzureRMManagementGroup_withName(t *testing.T) { CheckDestroy: testCheckAzureRMManagementGroupDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMManagementGroup_withName(ri), + Config: testAzureRMManagementGroup_withName(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementGroupExists(resourceName), + testCheckAzureRMManagementGroupExists(data.ResourceName), ), }, }, @@ -154,8 +148,7 @@ func TestAccAzureRMManagementGroup_withName(t *testing.T) { } func TestAccAzureRMManagementGroup_updateName(t *testing.T) { - resourceName := "azurerm_management_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_management_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -165,14 +158,14 @@ func TestAccAzureRMManagementGroup_updateName(t *testing.T) { { Config: testAzureRMManagementGroup_basic(), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementGroupExists(resourceName), + testCheckAzureRMManagementGroupExists(data.ResourceName), ), }, { - Config: testAzureRMManagementGroup_withName(ri), + Config: testAzureRMManagementGroup_withName(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", fmt.Sprintf("acctestmg-%d", ri)), + testCheckAzureRMManagementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", fmt.Sprintf("acctestmg-%d", data.RandomInteger)), ), }, }, @@ -180,7 +173,7 @@ func TestAccAzureRMManagementGroup_updateName(t *testing.T) { } func TestAccAzureRMManagementGroup_withSubscriptions(t *testing.T) { - resourceName := "azurerm_management_group.test" + data := acceptance.BuildTestData(t, "azurerm_management_group", "test") subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") resource.ParallelTest(t, resource.TestCase{ @@ -191,22 +184,22 @@ func TestAccAzureRMManagementGroup_withSubscriptions(t *testing.T) { { Config: testAzureRMManagementGroup_basic(), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subscription_ids.#", "0"), + testCheckAzureRMManagementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_ids.#", "0"), ), }, { Config: testAzureRMManagementGroup_withSubscriptions(subscriptionID), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subscription_ids.#", "1"), + testCheckAzureRMManagementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_ids.#", "1"), ), }, { Config: testAzureRMManagementGroup_basic(), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMManagementGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subscription_ids.#", "0"), + testCheckAzureRMManagementGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_ids.#", "0"), ), }, }, @@ -306,12 +299,12 @@ resource "azurerm_management_group" "child" { `) } -func testAzureRMManagementGroup_withName(rInt int) string { +func testAzureRMManagementGroup_withName(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_management_group" "test" { display_name = "acctestmg-%d" } -`, rInt) +`, data.RandomInteger) } // TODO: switch this out for dynamically creating a subscription once that's supported in the future From 3f504a981dd2b80146b056f0c7061fa9b277ea14 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 20 Dec 2019 20:20:56 -0800 Subject: [PATCH 101/203] mariadb: switching to the new test structure --- ...resource_arm_mariadb_configuration_test.go | 74 +++--- .../resource_arm_mariadb_database_test.go | 39 ++-- ...resource_arm_mariadb_firewall_rule_test.go | 33 ++- .../resource_arm_mariadb_server_test.go | 217 +++++++----------- ...e_arm_mariadb_virtual_network_rule_test.go | 74 +++--- 5 files changed, 178 insertions(+), 259 deletions(-) rename azurerm/internal/services/mariadb/{ => tests}/resource_arm_mariadb_configuration_test.go (72%) rename azurerm/internal/services/mariadb/{ => tests}/resource_arm_mariadb_database_test.go (80%) rename azurerm/internal/services/mariadb/{ => tests}/resource_arm_mariadb_firewall_rule_test.go (83%) rename azurerm/internal/services/mariadb/{ => tests}/resource_arm_mariadb_server_test.go (66%) rename azurerm/internal/services/mariadb/{ => tests}/resource_arm_mariadb_virtual_network_rule_test.go (85%) diff --git a/azurerm/internal/services/mariadb/resource_arm_mariadb_configuration_test.go b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_configuration_test.go similarity index 72% rename from azurerm/internal/services/mariadb/resource_arm_mariadb_configuration_test.go rename to azurerm/internal/services/mariadb/tests/resource_arm_mariadb_configuration_test.go index f53d54cfe515..504c07bc1e4a 100644 --- a/azurerm/internal/services/mariadb/resource_arm_mariadb_configuration_test.go +++ b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_configuration_test.go @@ -1,4 +1,4 @@ -package mariadb +package tests import ( "fmt" @@ -6,15 +6,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMMariaDbConfiguration_characterSetServer(t *testing.T) { - resourceName := "azurerm_mariadb_configuration.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mariadb_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMMariaDbConfiguration_characterSetServer(t *testing.T) { CheckDestroy: testCheckAzureRMMariaDbConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMariaDbConfiguration_characterSetServer(ri, acceptance.Location()), + Config: testAccAzureRMMariaDbConfiguration_characterSetServer(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbConfigurationValue(resourceName, "hebrew"), + testCheckAzureRMMariaDbConfigurationValue(data.ResourceName, "hebrew"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMariaDbConfiguration_empty(ri, acceptance.Location()), + Config: testAccAzureRMMariaDbConfiguration_empty(data), Check: resource.ComposeTestCheckFunc( // "delete" resets back to the default value - testCheckAzureRMMariaDbConfigurationValueReset(ri, "character_set_server"), + testCheckAzureRMMariaDbConfigurationValueReset(data.RandomInteger, "character_set_server"), ), }, }, @@ -44,8 +38,7 @@ func TestAccAzureRMMariaDbConfiguration_characterSetServer(t *testing.T) { } func TestAccAzureRMMariaDbConfiguration_interactiveTimeout(t *testing.T) { - resourceName := "azurerm_mariadb_configuration.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mariadb_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,21 +46,17 @@ func TestAccAzureRMMariaDbConfiguration_interactiveTimeout(t *testing.T) { CheckDestroy: testCheckAzureRMMariaDbConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMariaDbConfiguration_interactiveTimeout(ri, acceptance.Location()), + Config: testAccAzureRMMariaDbConfiguration_interactiveTimeout(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbConfigurationValue(resourceName, "30"), + testCheckAzureRMMariaDbConfigurationValue(data.ResourceName, "30"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMariaDbConfiguration_empty(ri, acceptance.Location()), + Config: testAccAzureRMMariaDbConfiguration_empty(data), Check: resource.ComposeTestCheckFunc( // "delete" resets back to the default value - testCheckAzureRMMariaDbConfigurationValueReset(ri, "interactive_timeout"), + testCheckAzureRMMariaDbConfigurationValueReset(data.RandomInteger, "interactive_timeout"), ), }, }, @@ -75,8 +64,7 @@ func TestAccAzureRMMariaDbConfiguration_interactiveTimeout(t *testing.T) { } func TestAccAzureRMMariaDbConfiguration_logSlowAdminStatements(t *testing.T) { - resourceName := "azurerm_mariadb_configuration.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mariadb_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,21 +72,17 @@ func TestAccAzureRMMariaDbConfiguration_logSlowAdminStatements(t *testing.T) { CheckDestroy: testCheckAzureRMMariaDbConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMariaDbConfiguration_logSlowAdminStatements(ri, acceptance.Location()), + Config: testAccAzureRMMariaDbConfiguration_logSlowAdminStatements(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbConfigurationValue(resourceName, "on"), + testCheckAzureRMMariaDbConfigurationValue(data.ResourceName, "on"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMariaDbConfiguration_empty(ri, acceptance.Location()), + Config: testAccAzureRMMariaDbConfiguration_empty(data), Check: resource.ComposeTestCheckFunc( // "delete" resets back to the default value - testCheckAzureRMMariaDbConfigurationValueReset(ri, "log_slow_admin_statements"), + testCheckAzureRMMariaDbConfigurationValueReset(data.RandomInteger, "log_slow_admin_statements"), ), }, }, @@ -194,20 +178,20 @@ func testCheckAzureRMMariaDbConfigurationDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMariaDbConfiguration_characterSetServer(rInt int, location string) string { - return testAccAzureRMMariaDbConfiguration_template(rInt, location, "character_set_server", "hebrew") +func testAccAzureRMMariaDbConfiguration_characterSetServer(data acceptance.TestData) string { + return testAccAzureRMMariaDbConfiguration_template(data, "character_set_server", "hebrew") } -func testAccAzureRMMariaDbConfiguration_interactiveTimeout(rInt int, location string) string { - return testAccAzureRMMariaDbConfiguration_template(rInt, location, "interactive_timeout", "30") +func testAccAzureRMMariaDbConfiguration_interactiveTimeout(data acceptance.TestData) string { + return testAccAzureRMMariaDbConfiguration_template(data, "interactive_timeout", "30") } -func testAccAzureRMMariaDbConfiguration_logSlowAdminStatements(rInt int, location string) string { - return testAccAzureRMMariaDbConfiguration_template(rInt, location, "log_slow_admin_statements", "on") +func testAccAzureRMMariaDbConfiguration_logSlowAdminStatements(data acceptance.TestData) string { + return testAccAzureRMMariaDbConfiguration_template(data, "log_slow_admin_statements", "on") } -func testAccAzureRMMariaDbConfiguration_template(rInt int, location string, name string, value string) string { - server := testAccAzureRMMariaDbConfiguration_empty(rInt, location) +func testAccAzureRMMariaDbConfiguration_template(data acceptance.TestData, name string, value string) string { + server := testAccAzureRMMariaDbConfiguration_empty(data) config := fmt.Sprintf(` resource "azurerm_mariadb_configuration" "test" { name = "%s" @@ -219,7 +203,7 @@ resource "azurerm_mariadb_configuration" "test" { return server + config } -func testAccAzureRMMariaDbConfiguration_empty(rInt int, location string) string { +func testAccAzureRMMariaDbConfiguration_empty(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -249,5 +233,5 @@ resource "azurerm_mariadb_server" "test" { version = "10.2" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/mariadb/resource_arm_mariadb_database_test.go b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_database_test.go similarity index 80% rename from azurerm/internal/services/mariadb/resource_arm_mariadb_database_test.go rename to azurerm/internal/services/mariadb/tests/resource_arm_mariadb_database_test.go index 291590af7605..f56b39eb043c 100644 --- a/azurerm/internal/services/mariadb/resource_arm_mariadb_database_test.go +++ b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_database_test.go @@ -1,4 +1,4 @@ -package mariadb +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMMariaDbDatabase_basic(t *testing.T) { - resourceName := "azurerm_mariadb_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_mariadb_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,18 +21,14 @@ func TestAccAzureRMMariaDbDatabase_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMariaDbDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMariaDbDatabase_basic(ri, location), + Config: testAccAzureRMMariaDbDatabase_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "charset", "utf8"), - resource.TestCheckResourceAttr(resourceName, "collation", "utf8_general_ci"), + testCheckAzureRMMariaDbDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "charset", "utf8"), + resource.TestCheckResourceAttr(data.ResourceName, "collation", "utf8_general_ci"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +39,7 @@ func TestAccAzureRMMariaDbDatabase_requiresImport(t *testing.T) { return } - resourceName := "azurerm_mariadb_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_mariadb_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +47,13 @@ func TestAccAzureRMMariaDbDatabase_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMariaDbDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMariaDbDatabase_basic(ri, location), + Config: testAccAzureRMMariaDbDatabase_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbDatabaseExists(resourceName), + testCheckAzureRMMariaDbDatabaseExists(data.ResourceName), ), }, { - Config: testAccAzureRMMariaDbDatabase_requiresImport(ri, location), + Config: testAccAzureRMMariaDbDatabase_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_mariadb_database"), }, }, @@ -125,7 +116,7 @@ func testCheckAzureRMMariaDbDatabaseDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMariaDbDatabase_basic(rInt int, location string) string { +func testAccAzureRMMariaDbDatabase_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -163,11 +154,11 @@ resource "azurerm_mariadb_database" "test" { charset = "utf8" collation = "utf8_general_ci" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMariaDbDatabase_requiresImport(rInt int, location string) string { - template := testAccAzureRMMariaDbDatabase_basic(rInt, location) +func testAccAzureRMMariaDbDatabase_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMMariaDbDatabase_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/mariadb/resource_arm_mariadb_firewall_rule_test.go b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_firewall_rule_test.go similarity index 83% rename from azurerm/internal/services/mariadb/resource_arm_mariadb_firewall_rule_test.go rename to azurerm/internal/services/mariadb/tests/resource_arm_mariadb_firewall_rule_test.go index 8cc4d57cf13a..34ec8b9c20a2 100644 --- a/azurerm/internal/services/mariadb/resource_arm_mariadb_firewall_rule_test.go +++ b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_firewall_rule_test.go @@ -1,4 +1,4 @@ -package mariadb +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMMariaDBFirewallRule_basic(t *testing.T) { - resourceName := "azurerm_mariadb_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mariadb_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,16 +21,12 @@ func TestAccAzureRMMariaDBFirewallRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMariaDBFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMariaDBFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMMariaDBFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDBFirewallRuleExists(resourceName), + testCheckAzureRMMariaDBFirewallRuleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,8 +37,7 @@ func TestAccAzureRMMariaDBFirewallRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_mariadb_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mariadb_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,13 +45,13 @@ func TestAccAzureRMMariaDBFirewallRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMariaDBFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMariaDBFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMMariaDBFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDBFirewallRuleExists(resourceName), + testCheckAzureRMMariaDBFirewallRuleExists(data.ResourceName), ), }, { - Config: testAccAzureRMMariaDBFirewallRule_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMMariaDBFirewallRule_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_mariadb_firewall_rule"), }, }, @@ -122,7 +115,7 @@ func testCheckAzureRMMariaDBFirewallRuleDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMariaDBFirewallRule_basic(rInt int, location string) string { +func testAccAzureRMMariaDBFirewallRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -160,10 +153,10 @@ resource "azurerm_mariadb_firewall_rule" "test" { start_ip_address = "0.0.0.0" end_ip_address = "255.255.255.255" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMariaDBFirewallRule_requiresImport(rInt int, location string) string { +func testAccAzureRMMariaDBFirewallRule_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -174,5 +167,5 @@ resource "azurerm_mariadb_firewall_rule" "import" { start_ip_address = "${azurerm_mariadb_firewall_rule.test.start_ip_address}" end_ip_address = "${azurerm_mariadb_firewall_rule.test.end_ip_address}" } -`, testAccAzureRMMariaDBFirewallRule_basic(rInt, location)) +`, testAccAzureRMMariaDBFirewallRule_basic(data)) } diff --git a/azurerm/internal/services/mariadb/resource_arm_mariadb_server_test.go b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go similarity index 66% rename from azurerm/internal/services/mariadb/resource_arm_mariadb_server_test.go rename to azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go index d0430170d3ec..24493f2a19a8 100644 --- a/azurerm/internal/services/mariadb/resource_arm_mariadb_server_test.go +++ b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go @@ -1,4 +1,4 @@ -package mariadb +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,8 @@ import ( ) func TestAccAzureRMMariaDbServer_basic(t *testing.T) { - resourceName := "azurerm_mariadb_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMariaDbServer_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test") + config := testAccAzureRMMariaDbServer_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,20 +24,13 @@ func TestAccAzureRMMariaDbServer_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), - resource.TestCheckResourceAttr(resourceName, "version", "10.2"), - resource.TestCheckResourceAttr(resourceName, "ssl_enforcement", "Enabled"), + testCheckAzureRMMariaDbServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "10.2"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_enforcement", "Enabled"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), // not returned as sensitive }, }) } @@ -50,9 +41,7 @@ func TestAccAzureRMMariaDbServer_requiresImport(t *testing.T) { return } - resourceName := "azurerm_mariadb_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -60,13 +49,13 @@ func TestAccAzureRMMariaDbServer_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMariaDbServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMariaDbServer_basic(ri, location), + Config: testAccAzureRMMariaDbServer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), + testCheckAzureRMMariaDbServerExists(data.ResourceName), ), }, { - Config: testAccAzureRMMariaDbServer_requiresImport(ri, location), + Config: testAccAzureRMMariaDbServer_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_mariadb_server"), }, }, @@ -74,9 +63,8 @@ func TestAccAzureRMMariaDbServer_requiresImport(t *testing.T) { } func TestAccAzureRMMariaDbServer_basicMaxStorage(t *testing.T) { - resourceName := "azurerm_mariadb_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMariaDbServer_basicMaxStorage(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test") + config := testAccAzureRMMariaDbServer_basicMaxStorage(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,28 +74,20 @@ func TestAccAzureRMMariaDbServer_basicMaxStorage(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), - resource.TestCheckResourceAttr(resourceName, "version", "10.2"), - resource.TestCheckResourceAttr(resourceName, "ssl_enforcement", "Enabled"), + testCheckAzureRMMariaDbServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "10.2"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_enforcement", "Enabled"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), // not returned as sensitive }, }) } func TestAccAzureRMMariaDbServer_generalPurpose(t *testing.T) { - resourceName := "azurerm_mariadb_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMariaDbServer_generalPurpose(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test") + config := testAccAzureRMMariaDbServer_generalPurpose(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -117,25 +97,17 @@ func TestAccAzureRMMariaDbServer_generalPurpose(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), + testCheckAzureRMMariaDbServerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), // not returned as sensitive }, }) } func TestAccAzureRMMariaDbServer_memoryOptimized(t *testing.T) { - resourceName := "azurerm_mariadb_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMariaDbServer_memoryOptimizedGeoRedundant(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test") + config := testAccAzureRMMariaDbServer_memoryOptimizedGeoRedundant(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -145,27 +117,18 @@ func TestAccAzureRMMariaDbServer_memoryOptimized(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), + testCheckAzureRMMariaDbServerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), // not returned as sensitive }, }) } func TestAccAzureRMMariaDbServer_updatePassword(t *testing.T) { - resourceName := "azurerm_mariadb_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMMariaDbServer_basic(ri, location) - updatedConfig := testAccAzureRMMariaDbServer_basicUpdatedPassword(ri, location) + data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test") + config := testAccAzureRMMariaDbServer_basic(data) + updatedConfig := testAccAzureRMMariaDbServer_basicUpdatedPassword(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -175,13 +138,13 @@ func TestAccAzureRMMariaDbServer_updatePassword(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), + testCheckAzureRMMariaDbServerExists(data.ResourceName), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), + testCheckAzureRMMariaDbServerExists(data.ResourceName), ), }, }, @@ -189,11 +152,9 @@ func TestAccAzureRMMariaDbServer_updatePassword(t *testing.T) { } func TestAccAzureRMMariaDbServer_updated(t *testing.T) { - resourceName := "azurerm_mariadb_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMMariaDbServer_basic(ri, location) - updatedConfig := testAccAzureRMMariaDbServer_basicUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test") + config := testAccAzureRMMariaDbServer_basic(data) + updatedConfig := testAccAzureRMMariaDbServer_basicUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -203,21 +164,21 @@ func TestAccAzureRMMariaDbServer_updated(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "B_Gen5_2"), - resource.TestCheckResourceAttr(resourceName, "version", "10.2"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "51200"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMMariaDbServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "B_Gen5_2"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "10.2"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "51200"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "B_Gen5_1"), - resource.TestCheckResourceAttr(resourceName, "version", "10.2"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "640000"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMMariaDbServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "B_Gen5_1"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "10.2"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "640000"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, }, @@ -225,11 +186,9 @@ func TestAccAzureRMMariaDbServer_updated(t *testing.T) { } func TestAccAzureRMMariaDbServer_updateSKU(t *testing.T) { - resourceName := "azurerm_mariadb_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMMariaDbServer_generalPurpose(ri, location) - updatedConfig := testAccAzureRMMariaDbServer_memoryOptimized(ri, location) + data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test") + config := testAccAzureRMMariaDbServer_generalPurpose(data) + updatedConfig := testAccAzureRMMariaDbServer_memoryOptimized(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -239,25 +198,25 @@ func TestAccAzureRMMariaDbServer_updateSKU(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_32"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "32"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "GeneralPurpose"), - resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen5"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "640000"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMMariaDbServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_32"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "32"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "GeneralPurpose"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "640000"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "MO_Gen5_16"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "16"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "MemoryOptimized"), - resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen5"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "4096000"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMMariaDbServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "MO_Gen5_16"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "16"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "MemoryOptimized"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "4096000"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, }, @@ -265,11 +224,9 @@ func TestAccAzureRMMariaDbServer_updateSKU(t *testing.T) { } func TestAccAzureRMMariaDbServer_storageAutogrow(t *testing.T) { - resourceName := "azurerm_mariadb_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMMariaDbServer_basic(ri, location) - updatedConfig := testAccAzureRMMariaDbServer_storageAutogrowUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test") + config := testAccAzureRMMariaDbServer_basic(data) + updatedConfig := testAccAzureRMMariaDbServer_storageAutogrowUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -279,15 +236,15 @@ func TestAccAzureRMMariaDbServer_storageAutogrow(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Enabled"), + testCheckAzureRMMariaDbServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.auto_grow", "Enabled"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDbServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Disabled"), + testCheckAzureRMMariaDbServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.auto_grow", "Disabled"), ), }, }, @@ -351,7 +308,7 @@ func testCheckAzureRMMariaDbServerDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMariaDbServer_basic(rInt int, location string) string { +func testAccAzureRMMariaDbServer_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -381,11 +338,11 @@ resource "azurerm_mariadb_server" "test" { version = "10.2" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMariaDbServer_requiresImport(rInt int, location string) string { - template := testAccAzureRMMariaDbServer_basic(rInt, location) +func testAccAzureRMMariaDbServer_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMMariaDbServer_basic(data) return fmt.Sprintf(` %s @@ -415,7 +372,7 @@ resource "azurerm_mariadb_server" "import" { `, template) } -func testAccAzureRMMariaDbServer_basicUpdatedPassword(rInt int, location string) string { +func testAccAzureRMMariaDbServer_basicUpdatedPassword(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -445,10 +402,10 @@ resource "azurerm_mariadb_server" "test" { version = "10.2" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMariaDbServer_basicUpdated(rInt int, location string) string { +func testAccAzureRMMariaDbServer_basicUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -478,10 +435,10 @@ resource "azurerm_mariadb_server" "test" { version = "10.2" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMariaDbServer_basicMaxStorage(rInt int, location string) string { +func testAccAzureRMMariaDbServer_basicMaxStorage(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -511,10 +468,10 @@ resource "azurerm_mariadb_server" "test" { version = "10.2" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMariaDbServer_generalPurpose(rInt int, location string) string { +func testAccAzureRMMariaDbServer_generalPurpose(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -544,10 +501,10 @@ resource "azurerm_mariadb_server" "test" { version = "10.2" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMariaDbServer_memoryOptimized(rInt int, location string) string { +func testAccAzureRMMariaDbServer_memoryOptimized(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -577,10 +534,10 @@ resource "azurerm_mariadb_server" "test" { version = "10.2" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMariaDbServer_memoryOptimizedGeoRedundant(rInt int, location string) string { +func testAccAzureRMMariaDbServer_memoryOptimizedGeoRedundant(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -610,10 +567,10 @@ resource "azurerm_mariadb_server" "test" { version = "10.2" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMariaDbServer_storageAutogrowUpdated(rInt int, location string) string { +func testAccAzureRMMariaDbServer_storageAutogrowUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -644,5 +601,5 @@ resource "azurerm_mariadb_server" "test" { version = "10.2" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/mariadb/resource_arm_mariadb_virtual_network_rule_test.go b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_virtual_network_rule_test.go similarity index 85% rename from azurerm/internal/services/mariadb/resource_arm_mariadb_virtual_network_rule_test.go rename to azurerm/internal/services/mariadb/tests/resource_arm_mariadb_virtual_network_rule_test.go index e1465cdbb6a2..8afe17598593 100644 --- a/azurerm/internal/services/mariadb/resource_arm_mariadb_virtual_network_rule_test.go +++ b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_virtual_network_rule_test.go @@ -1,4 +1,4 @@ -package mariadb +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +15,7 @@ import ( ) func TestAccAzureRMMariaDBVirtualNetworkRule_basic(t *testing.T) { - resourceName := "azurerm_mariadb_virtual_network_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mariadb_virtual_network_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,9 +23,9 @@ func TestAccAzureRMMariaDBVirtualNetworkRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMariaDBVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMariaDBVirtualNetworkRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMMariaDBVirtualNetworkRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDBVirtualNetworkRuleExists(resourceName), + testCheckAzureRMMariaDBVirtualNetworkRuleExists(data.ResourceName), ), }, }, @@ -40,8 +38,7 @@ func TestAccAzureRMMariaDBVirtualNetworkRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_mariadb_virtual_network_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mariadb_virtual_network_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -49,13 +46,13 @@ func TestAccAzureRMMariaDBVirtualNetworkRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMariaDBVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMariaDBVirtualNetworkRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMMariaDBVirtualNetworkRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDBVirtualNetworkRuleExists(resourceName), + testCheckAzureRMMariaDBVirtualNetworkRuleExists(data.ResourceName), ), }, { - Config: testAccAzureRMMariaDBVirtualNetworkRule_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMMariaDBVirtualNetworkRule_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_mariadb_virtual_network_rule"), }, }, @@ -63,15 +60,14 @@ func TestAccAzureRMMariaDBVirtualNetworkRule_requiresImport(t *testing.T) { } func TestAccAzureRMMariaDBVirtualNetworkRule_switchSubnets(t *testing.T) { - resourceName := "azurerm_mariadb_virtual_network_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mariadb_virtual_network_rule", "test") - preConfig := testAccAzureRMMariaDBVirtualNetworkRule_subnetSwitchPre(ri, acceptance.Location()) - postConfig := testAccAzureRMMariaDBVirtualNetworkRule_subnetSwitchPost(ri, acceptance.Location()) + preConfig := testAccAzureRMMariaDBVirtualNetworkRule_subnetSwitchPre(data) + postConfig := testAccAzureRMMariaDBVirtualNetworkRule_subnetSwitchPost(data) // Create regex strings that will ensure that one subnet name exists, but not the other - preConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet1%d)$|(subnet[^2]%d)$", ri, ri)) //subnet 1 but not 2 - postConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet2%d)$|(subnet[^1]%d)$", ri, ri)) //subnet 2 but not 1 + preConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet1%d)$|(subnet[^2]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 1 but not 2 + postConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet2%d)$|(subnet[^1]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 2 but not 1 resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,15 +77,15 @@ func TestAccAzureRMMariaDBVirtualNetworkRule_switchSubnets(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDBVirtualNetworkRuleExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "subnet_id", preConfigRegex), + testCheckAzureRMMariaDBVirtualNetworkRuleExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "subnet_id", preConfigRegex), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDBVirtualNetworkRuleExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "subnet_id", postConfigRegex), + testCheckAzureRMMariaDBVirtualNetworkRuleExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "subnet_id", postConfigRegex), ), }, }, @@ -97,9 +93,8 @@ func TestAccAzureRMMariaDBVirtualNetworkRule_switchSubnets(t *testing.T) { } func TestAccAzureRMMariaDBVirtualNetworkRule_disappears(t *testing.T) { - resourceName := "azurerm_mariadb_virtual_network_rule.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMariaDBVirtualNetworkRule_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mariadb_virtual_network_rule", "test") + config := testAccAzureRMMariaDBVirtualNetworkRule_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -109,8 +104,8 @@ func TestAccAzureRMMariaDBVirtualNetworkRule_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDBVirtualNetworkRuleExists(resourceName), - testCheckAzureRMMariaDBVirtualNetworkRuleDisappears(resourceName), + testCheckAzureRMMariaDBVirtualNetworkRuleExists(data.ResourceName), + testCheckAzureRMMariaDBVirtualNetworkRuleDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -119,11 +114,10 @@ func TestAccAzureRMMariaDBVirtualNetworkRule_disappears(t *testing.T) { } func TestAccAzureRMMariaDBVirtualNetworkRule_multipleSubnets(t *testing.T) { - resourceName1 := "azurerm_mariadb_virtual_network_rule.rule1" + data := acceptance.BuildTestData(t, "azurerm_mariadb_virtual_network_rule", "rule1") resourceName2 := "azurerm_mariadb_virtual_network_rule.rule2" resourceName3 := "azurerm_mariadb_virtual_network_rule.rule3" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMariaDBVirtualNetworkRule_multipleSubnets(ri, acceptance.Location()) + config := testAccAzureRMMariaDBVirtualNetworkRule_multipleSubnets(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -133,7 +127,7 @@ func TestAccAzureRMMariaDBVirtualNetworkRule_multipleSubnets(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMariaDBVirtualNetworkRuleExists(resourceName1), + testCheckAzureRMMariaDBVirtualNetworkRuleExists(data.ResourceName), testCheckAzureRMMariaDBVirtualNetworkRuleExists(resourceName2), testCheckAzureRMMariaDBVirtualNetworkRuleExists(resourceName3), ), @@ -236,7 +230,7 @@ func testCheckAzureRMMariaDBVirtualNetworkRuleDisappears(resourceName string) re } } -func testAccAzureRMMariaDBVirtualNetworkRule_basic(rInt int, location string) string { +func testAccAzureRMMariaDBVirtualNetworkRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -287,10 +281,10 @@ resource "azurerm_mariadb_virtual_network_rule" "test" { server_name = "${azurerm_mariadb_server.test.name}" subnet_id = "${azurerm_subnet.test.id}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMariaDBVirtualNetworkRule_requiresImport(rInt int, location string) string { +func testAccAzureRMMariaDBVirtualNetworkRule_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -300,10 +294,10 @@ resource "azurerm_mariadb_virtual_network_rule" "import" { server_name = "${azurerm_mariadb_virtual_network_rule.test.server_name}" subnet_id = "${azurerm_mariadb_virtual_network_rule.test.subnet_id}" } -`, testAccAzureRMMariaDBVirtualNetworkRule_basic(rInt, location)) +`, testAccAzureRMMariaDBVirtualNetworkRule_basic(data)) } -func testAccAzureRMMariaDBVirtualNetworkRule_subnetSwitchPre(rInt int, location string) string { +func testAccAzureRMMariaDBVirtualNetworkRule_subnetSwitchPre(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -362,10 +356,10 @@ resource "azurerm_mariadb_virtual_network_rule" "test" { server_name = "${azurerm_mariadb_server.test.name}" subnet_id = "${azurerm_subnet.test1.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMariaDBVirtualNetworkRule_subnetSwitchPost(rInt int, location string) string { +func testAccAzureRMMariaDBVirtualNetworkRule_subnetSwitchPost(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -424,10 +418,10 @@ resource "azurerm_mariadb_virtual_network_rule" "test" { server_name = "${azurerm_mariadb_server.test.name}" subnet_id = "${azurerm_subnet.test2.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMariaDBVirtualNetworkRule_multipleSubnets(rInt int, location string) string { +func testAccAzureRMMariaDBVirtualNetworkRule_multipleSubnets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -515,5 +509,5 @@ resource "azurerm_mariadb_virtual_network_rule" "rule3" { server_name = "${azurerm_mariadb_server.test.name}" subnet_id = "${azurerm_subnet.vnet2_subnet1.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } From b2aec967c3e8af436efd9da9a100d614fe612548 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Fri, 20 Dec 2019 17:45:51 -0800 Subject: [PATCH 102/203] tests: storage --- ...urce_storage_account_blob_container_sas.go | 4 +- .../data_source_storage_account_sas.go | 12 +- ...a_source_storage_management_policy_test.go | 93 --- azurerm/internal/services/storage/metadata.go | 6 +- .../storage/resource_arm_storage_account.go | 6 +- .../resource_arm_storage_account_migration.go | 2 +- .../storage/resource_arm_storage_blob.go | 2 +- .../resource_arm_storage_blob_migration.go | 2 +- .../storage/resource_arm_storage_container.go | 2 +- ...esource_arm_storage_container_migration.go | 2 +- ...urce_arm_storage_management_policy_test.go | 451 ------------- .../storage/resource_arm_storage_queue.go | 6 +- .../resource_arm_storage_queue_migration.go | 2 +- .../storage/resource_arm_storage_share.go | 4 +- .../resource_arm_storage_share_migration.go | 4 +- .../storage/resource_arm_storage_table.go | 4 +- .../resource_arm_storage_table_entity.go | 2 +- .../resource_arm_storage_table_migration.go | 2 +- ...storage_account_blob_container_sas_test.go | 52 +- .../data_source_storage_account_sas_test.go | 30 +- .../data_source_storage_account_test.go | 64 +- ...a_source_storage_management_policy_test.go | 87 +++ .../storage/{ => tests}/metadata_test.go | 9 +- ...urce_arm_storage_account_migration_test.go | 5 +- ..._arm_storage_account_network_rules_test.go | 68 +- .../resource_arm_storage_account_test.go | 601 +++++++----------- ...esource_arm_storage_blob_migration_test.go | 5 +- .../resource_arm_storage_blob_test.go | 357 +++++------ ...ce_arm_storage_container_migration_test.go | 5 +- .../resource_arm_storage_container_test.go | 179 ++---- ..._storage_data_lake_gen2_filesystem_test.go | 83 +-- ...urce_arm_storage_management_policy_test.go | 423 ++++++++++++ ...source_arm_storage_queue_migration_test.go | 5 +- .../resource_arm_storage_queue_test.go | 88 +-- ...source_arm_storage_share_directory_test.go | 124 ++-- ...source_arm_storage_share_migration_test.go | 7 +- .../resource_arm_storage_share_test.go | 152 ++--- .../resource_arm_storage_table_entity_test.go | 79 +-- ...source_arm_storage_table_migration_test.go | 2 +- .../resource_arm_storage_table_test.go | 83 +-- .../storage/{ => tests}/validation_test.go | 7 +- 41 files changed, 1291 insertions(+), 1830 deletions(-) delete mode 100644 azurerm/internal/services/storage/data_source_storage_management_policy_test.go delete mode 100644 azurerm/internal/services/storage/resource_arm_storage_management_policy_test.go rename azurerm/internal/services/storage/{ => tests}/data_source_storage_account_blob_container_sas_test.go (60%) rename azurerm/internal/services/storage/{ => tests}/data_source_storage_account_sas_test.go (79%) rename azurerm/internal/services/storage/{ => tests}/data_source_storage_account_test.go (53%) create mode 100644 azurerm/internal/services/storage/tests/data_source_storage_management_policy_test.go rename azurerm/internal/services/storage/{ => tests}/metadata_test.go (81%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_account_migration_test.go (88%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_account_network_rules_test.go (74%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_account_test.go (68%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_blob_migration_test.go (91%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_blob_test.go (72%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_container_migration_test.go (91%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_container_test.go (66%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_data_lake_gen2_filesystem_test.go (68%) create mode 100644 azurerm/internal/services/storage/tests/resource_arm_storage_management_policy_test.go rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_queue_migration_test.go (91%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_queue_test.go (71%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_share_directory_test.go (67%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_share_migration_test.go (90%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_share_test.go (68%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_table_entity_test.go (74%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_table_migration_test.go (99%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_table_test.go (81%) rename azurerm/internal/services/storage/{ => tests}/validation_test.go (67%) diff --git a/azurerm/internal/services/storage/data_source_storage_account_blob_container_sas.go b/azurerm/internal/services/storage/data_source_storage_account_blob_container_sas.go index 691af2c924c8..b9a6d1628301 100644 --- a/azurerm/internal/services/storage/data_source_storage_account_blob_container_sas.go +++ b/azurerm/internal/services/storage/data_source_storage_account_blob_container_sas.go @@ -145,7 +145,7 @@ func dataSourceArmStorageContainerSasRead(d *schema.ResourceData, _ interface{}) contentLanguage := d.Get("content_language").(string) contentType := d.Get("content_type").(string) - permissions := buildContainerPermissionsString(permissionsIface[0].(map[string]interface{})) + permissions := BuildContainerPermissionsString(permissionsIface[0].(map[string]interface{})) // Parse the connection string kvp, err := storage.ParseAccountSASConnectionString(connString) @@ -178,7 +178,7 @@ func dataSourceArmStorageContainerSasRead(d *schema.ResourceData, _ interface{}) return nil } -func buildContainerPermissionsString(perms map[string]interface{}) string { +func BuildContainerPermissionsString(perms map[string]interface{}) string { retVal := "" if val, pres := perms["read"].(bool); pres && val { diff --git a/azurerm/internal/services/storage/data_source_storage_account_sas.go b/azurerm/internal/services/storage/data_source_storage_account_sas.go index 0b18b89ec609..ca52e0f1f321 100644 --- a/azurerm/internal/services/storage/data_source_storage_account_sas.go +++ b/azurerm/internal/services/storage/data_source_storage_account_sas.go @@ -195,9 +195,9 @@ func dataSourceArmStorageAccountSasRead(d *schema.ResourceData, _ interface{}) e expiry := d.Get("expiry").(string) permissionsIface := d.Get("permissions").([]interface{}) - resourceTypes := buildResourceTypesString(resourceTypesIface[0].(map[string]interface{})) - services := buildServicesString(servicesIface[0].(map[string]interface{})) - permissions := buildPermissionsString(permissionsIface[0].(map[string]interface{})) + resourceTypes := BuildResourceTypesString(resourceTypesIface[0].(map[string]interface{})) + services := BuildServicesString(servicesIface[0].(map[string]interface{})) + permissions := BuildPermissionsString(permissionsIface[0].(map[string]interface{})) // Parse the connection string kvp, err := storage.ParseAccountSASConnectionString(connString) @@ -231,7 +231,7 @@ func dataSourceArmStorageAccountSasRead(d *schema.ResourceData, _ interface{}) e return nil } -func buildPermissionsString(perms map[string]interface{}) string { +func BuildPermissionsString(perms map[string]interface{}) string { retVal := "" if val, pres := perms["read"].(bool); pres && val { @@ -269,7 +269,7 @@ func buildPermissionsString(perms map[string]interface{}) string { return retVal } -func buildServicesString(services map[string]interface{}) string { +func BuildServicesString(services map[string]interface{}) string { retVal := "" if val, pres := services["blob"].(bool); pres && val { @@ -291,7 +291,7 @@ func buildServicesString(services map[string]interface{}) string { return retVal } -func buildResourceTypesString(resTypes map[string]interface{}) string { +func BuildResourceTypesString(resTypes map[string]interface{}) string { retVal := "" if val, pres := resTypes["service"].(bool); pres && val { diff --git a/azurerm/internal/services/storage/data_source_storage_management_policy_test.go b/azurerm/internal/services/storage/data_source_storage_management_policy_test.go deleted file mode 100644 index e0a305fa9003..000000000000 --- a/azurerm/internal/services/storage/data_source_storage_management_policy_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package storage - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMStorageManagementPolicy_basic(t *testing.T) { - dataSourceName := "data.azurerm_storage_management_policy.testpolicy" - ri := tf.AccRandTimeInt() - - rs := acctest.RandString(4) - location := acceptance.Location() - config := testAccDataSourceAzureRMStorageManagementPolicy_basic(ri, rs, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.name", "rule1"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.enabled", "true"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.filters.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.filters.0.prefix_match.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.filters.0.prefix_match.3439697764", "container1/prefix1"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.filters.0.blob_types.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.filters.0.blob_types.1068358194", "blockBlob"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.actions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.actions.0.base_blob.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "10"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "50"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "100"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.actions.0.snapshot.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "30"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMStorageManagementPolicy_basic(rInt int, rString string, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "testrg" { - name = "acctestRG-storage-%d" - location = "%s" -} - -resource "azurerm_storage_account" "testsa" { - name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.testrg.name}" - - location = "${azurerm_resource_group.testrg.location}" - account_tier = "Standard" - account_replication_type = "LRS" - account_kind = "BlobStorage" -} - -resource "azurerm_storage_management_policy" "testpolicy" { - storage_account_id = "${azurerm_storage_account.testsa.id}" - - rule { - name = "rule1" - enabled = true - filters { - prefix_match = ["container1/prefix1"] - blob_types = ["blockBlob"] - } - actions { - base_blob { - tier_to_cool_after_days_since_modification_greater_than = 10 - tier_to_archive_after_days_since_modification_greater_than = 50 - delete_after_days_since_modification_greater_than = 100 - } - snapshot { - delete_after_days_since_creation_greater_than = 30 - } - } - } -} - -data "azurerm_storage_management_policy" "testpolicy" { - storage_account_id = "${azurerm_storage_management_policy.testpolicy.storage_account_id}" -} -`, rInt, location, rString) -} diff --git a/azurerm/internal/services/storage/metadata.go b/azurerm/internal/services/storage/metadata.go index c54887cac090..d6c1c048a20c 100644 --- a/azurerm/internal/services/storage/metadata.go +++ b/azurerm/internal/services/storage/metadata.go @@ -12,7 +12,7 @@ func MetaDataSchema() *schema.Schema { return &schema.Schema{ Type: schema.TypeMap, Optional: true, - ValidateFunc: validateMetaDataKeys, + ValidateFunc: ValidateMetaDataKeys, } } @@ -21,7 +21,7 @@ func MetaDataComputedSchema() *schema.Schema { Type: schema.TypeMap, Optional: true, Computed: true, - ValidateFunc: validateMetaDataKeys, + ValidateFunc: ValidateMetaDataKeys, } } @@ -45,7 +45,7 @@ func FlattenMetaData(input map[string]string) map[string]interface{} { return output } -func validateMetaDataKeys(value interface{}, _ string) (warnings []string, errors []error) { +func ValidateMetaDataKeys(value interface{}, _ string) (warnings []string, errors []error) { v, ok := value.(map[string]interface{}) if !ok { return diff --git a/azurerm/internal/services/storage/resource_arm_storage_account.go b/azurerm/internal/services/storage/resource_arm_storage_account.go index e45257a259ba..56008fadf933 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account.go @@ -39,7 +39,7 @@ func resourceArmStorageAccount() *schema.Resource { Update: resourceArmStorageAccountUpdate, Delete: resourceArmStorageAccountDelete, - MigrateState: resourceStorageAccountMigrateState, + MigrateState: ResourceStorageAccountMigrateState, SchemaVersion: 2, Importer: &schema.ResourceImporter{ @@ -84,7 +84,7 @@ func resourceArmStorageAccount() *schema.Resource { Optional: true, Computed: true, Deprecated: "This field has been split into `account_tier` and `account_replication_type`", - ValidateFunc: validateArmStorageAccountType, + ValidateFunc: ValidateArmStorageAccountType, DiffSuppressFunc: suppress.CaseDifference, }, @@ -1744,7 +1744,7 @@ func ValidateArmStorageAccountName(v interface{}, _ string) (warnings []string, return warnings, errors } -func validateArmStorageAccountType(v interface{}, _ string) (warnings []string, errors []error) { +func ValidateArmStorageAccountType(v interface{}, _ string) (warnings []string, errors []error) { validAccountTypes := []string{"standard_lrs", "standard_zrs", "standard_grs", "standard_ragrs", "premium_lrs"} diff --git a/azurerm/internal/services/storage/resource_arm_storage_account_migration.go b/azurerm/internal/services/storage/resource_arm_storage_account_migration.go index e8d88fd16c03..5bde764c7ff0 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account_migration.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func resourceStorageAccountMigrateState( +func ResourceStorageAccountMigrateState( v int, is *terraform.InstanceState, _ interface{}) (*terraform.InstanceState, error) { switch v { case 0: diff --git a/azurerm/internal/services/storage/resource_arm_storage_blob.go b/azurerm/internal/services/storage/resource_arm_storage_blob.go index 1c8c89add5a0..2deea7ee94d1 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_blob.go +++ b/azurerm/internal/services/storage/resource_arm_storage_blob.go @@ -25,7 +25,7 @@ func resourceArmStorageBlob() *schema.Resource { Read: resourceArmStorageBlobRead, Update: resourceArmStorageBlobUpdate, Delete: resourceArmStorageBlobDelete, - MigrateState: resourceStorageBlobMigrateState, + MigrateState: ResourceStorageBlobMigrateState, SchemaVersion: 1, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, diff --git a/azurerm/internal/services/storage/resource_arm_storage_blob_migration.go b/azurerm/internal/services/storage/resource_arm_storage_blob_migration.go index 0b5056c6feed..74748885c6b1 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_blob_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_blob_migration.go @@ -8,7 +8,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) -func resourceStorageBlobMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { +func ResourceStorageBlobMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { switch v { case 0: log.Println("[INFO] Found AzureRM Storage Blob State v0; migrating to v1") diff --git a/azurerm/internal/services/storage/resource_arm_storage_container.go b/azurerm/internal/services/storage/resource_arm_storage_container.go index 4de23eeb53c9..0971adb3adaa 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_container.go +++ b/azurerm/internal/services/storage/resource_arm_storage_container.go @@ -23,7 +23,7 @@ func resourceArmStorageContainer() *schema.Resource { Read: resourceArmStorageContainerRead, Delete: resourceArmStorageContainerDelete, Update: resourceArmStorageContainerUpdate, - MigrateState: resourceStorageContainerMigrateState, + MigrateState: ResourceStorageContainerMigrateState, SchemaVersion: 1, Importer: &schema.ResourceImporter{ diff --git a/azurerm/internal/services/storage/resource_arm_storage_container_migration.go b/azurerm/internal/services/storage/resource_arm_storage_container_migration.go index cf0c3f29bdf6..ef5dbae6cdcb 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_container_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_container_migration.go @@ -8,7 +8,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) -func resourceStorageContainerMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { +func ResourceStorageContainerMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { switch v { case 0: log.Println("[INFO] Found AzureRM Storage Container State v0; migrating to v1") diff --git a/azurerm/internal/services/storage/resource_arm_storage_management_policy_test.go b/azurerm/internal/services/storage/resource_arm_storage_management_policy_test.go deleted file mode 100644 index bbc08724071e..000000000000 --- a/azurerm/internal/services/storage/resource_arm_storage_management_policy_test.go +++ /dev/null @@ -1,451 +0,0 @@ -package storage - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "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/clients" - - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" -) - -func TestAccAzureRMStorageManagementPolicy_basic(t *testing.T) { - resourceName := "azurerm_storage_management_policy.testpolicy" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - config := testAccAzureRMStorageManagementPolicy_basic(ri, rs, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountManagementPolicyDestroy(), - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountManagementPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.name", "rule1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.prefix_match.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.prefix_match.3439697764", "container1/prefix1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.blob_types.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.blob_types.1068358194", "blockBlob"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "10"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "50"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "100"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.snapshot.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "30"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMStorageManagementPolicy_multipleRule(t *testing.T) { - resourceName := "azurerm_storage_management_policy.testpolicy" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - config := testAccAzureRMStorageManagementPolicy_multipleRule(ri, rs, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountManagementPolicyDestroy(), - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountManagementPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "rule.#", "2"), - - // Rule1 - resource.TestCheckResourceAttr(resourceName, "rule.0.name", "rule1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.prefix_match.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.prefix_match.3439697764", "container1/prefix1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.blob_types.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.blob_types.1068358194", "blockBlob"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "10"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "50"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "100"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.snapshot.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "30"), - - // Rule2 - resource.TestCheckResourceAttr(resourceName, "rule.1.name", "rule2"), - resource.TestCheckResourceAttr(resourceName, "rule.1.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.prefix_match.#", "2"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.prefix_match.4102595489", "container2/prefix1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.prefix_match.1837232667", "container2/prefix2"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.blob_types.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.blob_types.1068358194", "blockBlob"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "11"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "51"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "101"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.snapshot.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "31"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMStorageManagementPolicy_updateMultipleRule(t *testing.T) { - resourceName := "azurerm_storage_management_policy.testpolicy" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - config1 := testAccAzureRMStorageManagementPolicy_multipleRule(ri, rs, location) - config2 := testAccAzureRMStorageManagementPolicy_multipleRuleUpdated(ri, rs, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMStorageAccountManagementPolicyDestroy(), - Steps: []resource.TestStep{ - { - Config: config1, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountManagementPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "rule.#", "2"), - - // Rule1 - resource.TestCheckResourceAttr(resourceName, "rule.0.name", "rule1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.prefix_match.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.prefix_match.3439697764", "container1/prefix1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.blob_types.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.blob_types.1068358194", "blockBlob"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "10"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "50"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "100"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.snapshot.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "30"), - - // Rule2 - resource.TestCheckResourceAttr(resourceName, "rule.1.name", "rule2"), - resource.TestCheckResourceAttr(resourceName, "rule.1.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.prefix_match.#", "2"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.prefix_match.4102595489", "container2/prefix1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.prefix_match.1837232667", "container2/prefix2"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.blob_types.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.blob_types.1068358194", "blockBlob"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "11"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "51"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "101"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.snapshot.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "31"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: config2, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountManagementPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "rule.#", "2"), - - // Rule1 - resource.TestCheckResourceAttr(resourceName, "rule.0.name", "rule1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.prefix_match.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.prefix_match.3439697764", "container1/prefix1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.blob_types.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.filters.0.blob_types.1068358194", "blockBlob"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "10"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "50"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "100"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.snapshot.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "30"), - - // Rule2 - resource.TestCheckResourceAttr(resourceName, "rule.1.name", "rule2"), - resource.TestCheckResourceAttr(resourceName, "rule.1.enabled", "true"), // check updated - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.prefix_match.#", "2"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.prefix_match.4102595489", "container2/prefix1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.prefix_match.1837232667", "container2/prefix2"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.blob_types.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.filters.0.blob_types.1068358194", "blockBlob"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "12"), // check updated - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "52"), // check updated - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "102"), // check updated - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.snapshot.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "32"), // check updated - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testCheckAzureRMStorageAccountManagementPolicyDestroy() resource.TestCheckFunc { - return func(s *terraform.State) error { - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_storage_management_policy" { - continue - } - storageAccountID := rs.Primary.Attributes["storage_account_id"] - - exists, err := testCheckAzureRMStorageAccountManagementPolicyExistsInternal(storageAccountID) - if err != nil { - return fmt.Errorf("Error checking if item has been destroyed: %s", err) - } - if exists { - return fmt.Errorf("Bad: Storage Account Management Policy '%q' still exists", storageAccountID) - } - } - - return nil - } -} - -func testCheckAzureRMStorageAccountManagementPolicyExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - storageAccountID := rs.Primary.Attributes["storage_account_id"] - - exists, err := testCheckAzureRMStorageAccountManagementPolicyExistsInternal(storageAccountID) - if err != nil { - return fmt.Errorf("Error checking if item exists: %s", err) - } - if !exists { - return fmt.Errorf("Bad: Storage Account Management Policy '%q' does not exist", storageAccountID) - } - - return nil - } -} - -func testCheckAzureRMStorageAccountManagementPolicyExistsInternal(storageAccountID string) (bool, error) { - rid, err := azure.ParseAzureResourceID(storageAccountID) - if err != nil { - return false, fmt.Errorf("Bad: Failed to parse ID (id: %s): %+v", storageAccountID, err) - } - - resourceGroupName := rid.ResourceGroup - storageAccountName := rid.Path["storageAccounts"] - - conn := acceptance.AzureProvider.Meta().(*clients.Client).Storage.ManagementPoliciesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - response, err := conn.Get(ctx, resourceGroupName, storageAccountName) - if err != nil { - if response.Response.IsHTTPStatus(404) { - return false, nil - } - return false, fmt.Errorf("Bad: Get on storageAccount ManagementPolicy client (id: %s): %+v", storageAccountID, err) - } - - return true, nil -} - -func testAccAzureRMStorageManagementPolicy_basic(rInt int, rString string, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "testrg" { - name = "acctestRG-storage-%d" - location = "%s" -} - -resource "azurerm_storage_account" "testsa" { - name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.testrg.name}" - - location = "${azurerm_resource_group.testrg.location}" - account_tier = "Standard" - account_replication_type = "LRS" - account_kind = "BlobStorage" -} - -resource "azurerm_storage_management_policy" "testpolicy" { - storage_account_id = "${azurerm_storage_account.testsa.id}" - - rule { - name = "rule1" - enabled = true - filters { - prefix_match = ["container1/prefix1"] - blob_types = ["blockBlob"] - } - actions { - base_blob { - tier_to_cool_after_days_since_modification_greater_than = 10 - tier_to_archive_after_days_since_modification_greater_than = 50 - delete_after_days_since_modification_greater_than = 100 - } - snapshot { - delete_after_days_since_creation_greater_than = 30 - } - } - } -} -`, rInt, location, rString) -} - -func testAccAzureRMStorageManagementPolicy_multipleRule(rInt int, rString string, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "testrg" { - name = "acctestRG-storage-%d" - location = "%s" -} - -resource "azurerm_storage_account" "testsa" { - name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.testrg.name}" - - location = "${azurerm_resource_group.testrg.location}" - account_tier = "Standard" - account_replication_type = "LRS" - account_kind = "BlobStorage" -} - -resource "azurerm_storage_management_policy" "testpolicy" { - storage_account_id = "${azurerm_storage_account.testsa.id}" - - rule { - name = "rule1" - enabled = true - filters { - prefix_match = ["container1/prefix1"] - blob_types = ["blockBlob"] - } - actions { - base_blob { - tier_to_cool_after_days_since_modification_greater_than = 10 - tier_to_archive_after_days_since_modification_greater_than = 50 - delete_after_days_since_modification_greater_than = 100 - } - snapshot { - delete_after_days_since_creation_greater_than = 30 - } - } - } - rule { - name = "rule2" - enabled = false - filters { - prefix_match = ["container2/prefix1", "container2/prefix2"] - blob_types = ["blockBlob"] - } - actions { - base_blob { - tier_to_cool_after_days_since_modification_greater_than = 11 - tier_to_archive_after_days_since_modification_greater_than = 51 - delete_after_days_since_modification_greater_than = 101 - } - snapshot { - delete_after_days_since_creation_greater_than = 31 - } - } - } -} -`, rInt, location, rString) -} - -func testAccAzureRMStorageManagementPolicy_multipleRuleUpdated(rInt int, rString string, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "testrg" { - name = "acctestRG-storage-%d" - location = "%s" -} - -resource "azurerm_storage_account" "testsa" { - name = "unlikely23exst2acct%s" - resource_group_name = "${azurerm_resource_group.testrg.name}" - - location = "${azurerm_resource_group.testrg.location}" - account_tier = "Standard" - account_replication_type = "LRS" - account_kind = "BlobStorage" -} - -resource "azurerm_storage_management_policy" "testpolicy" { - storage_account_id = "${azurerm_storage_account.testsa.id}" - - rule { - name = "rule1" - enabled = true - filters { - prefix_match = ["container1/prefix1"] - blob_types = ["blockBlob"] - } - actions { - base_blob { - tier_to_cool_after_days_since_modification_greater_than = 10 - tier_to_archive_after_days_since_modification_greater_than = 50 - delete_after_days_since_modification_greater_than = 100 - } - snapshot { - delete_after_days_since_creation_greater_than = 30 - } - } - } - rule { - name = "rule2" - enabled = true - filters { - prefix_match = ["container2/prefix1", "container2/prefix2"] - blob_types = ["blockBlob"] - } - actions { - base_blob { - tier_to_cool_after_days_since_modification_greater_than = 12 - tier_to_archive_after_days_since_modification_greater_than = 52 - delete_after_days_since_modification_greater_than = 102 - } - snapshot { - delete_after_days_since_creation_greater_than = 32 - } - } - } -} -`, rInt, location, rString) -} diff --git a/azurerm/internal/services/storage/resource_arm_storage_queue.go b/azurerm/internal/services/storage/resource_arm_storage_queue.go index 20575ca10d93..b512884cd6fb 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_queue.go +++ b/azurerm/internal/services/storage/resource_arm_storage_queue.go @@ -26,7 +26,7 @@ func resourceArmStorageQueue() *schema.Resource { State: schema.ImportStatePassthrough, }, SchemaVersion: 1, - MigrateState: resourceStorageQueueMigrateState, + MigrateState: ResourceStorageQueueMigrateState, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), @@ -40,7 +40,7 @@ func resourceArmStorageQueue() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageQueueName, + ValidateFunc: ValidateArmStorageQueueName, }, "storage_account_name": { @@ -57,7 +57,7 @@ func resourceArmStorageQueue() *schema.Resource { } } -func validateArmStorageQueueName(v interface{}, k string) (warnings []string, errors []error) { +func ValidateArmStorageQueueName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^[a-z0-9-]+$`).MatchString(value) { diff --git a/azurerm/internal/services/storage/resource_arm_storage_queue_migration.go b/azurerm/internal/services/storage/resource_arm_storage_queue_migration.go index c8d9681c5e25..2bd66b6324c7 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_queue_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_queue_migration.go @@ -8,7 +8,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) -func resourceStorageQueueMigrateState( +func ResourceStorageQueueMigrateState( v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { switch v { case 0: diff --git a/azurerm/internal/services/storage/resource_arm_storage_share.go b/azurerm/internal/services/storage/resource_arm_storage_share.go index 3931a93ff797..d6a21de8ad1d 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_share.go +++ b/azurerm/internal/services/storage/resource_arm_storage_share.go @@ -31,12 +31,12 @@ func resourceArmStorageShare() *schema.Resource { { // this should have been applied from pre-0.12 migration system; backporting just in-case Type: resourceStorageShareStateResourceV0V1().CoreConfigSchema().ImpliedType(), - Upgrade: resourceStorageShareStateUpgradeV0ToV1, + Upgrade: ResourceStorageShareStateUpgradeV0ToV1, Version: 0, }, { Type: resourceStorageShareStateResourceV0V1().CoreConfigSchema().ImpliedType(), - Upgrade: resourceStorageShareStateUpgradeV1ToV2, + Upgrade: ResourceStorageShareStateUpgradeV1ToV2, Version: 1, }, }, diff --git a/azurerm/internal/services/storage/resource_arm_storage_share_migration.go b/azurerm/internal/services/storage/resource_arm_storage_share_migration.go index a6c89ba4734f..dc5aab4ad000 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_share_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_share_migration.go @@ -42,7 +42,7 @@ func resourceStorageShareStateResourceV0V1() *schema.Resource { } } -func resourceStorageShareStateUpgradeV0ToV1(rawState map[string]interface{}, _ interface{}) (map[string]interface{}, error) { +func ResourceStorageShareStateUpgradeV0ToV1(rawState map[string]interface{}, _ interface{}) (map[string]interface{}, error) { shareName := rawState["name"].(string) resourceGroup := rawState["resource_group_name"].(string) accountName := rawState["storage_account_name"].(string) @@ -55,7 +55,7 @@ func resourceStorageShareStateUpgradeV0ToV1(rawState map[string]interface{}, _ i return rawState, nil } -func resourceStorageShareStateUpgradeV1ToV2(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { +func ResourceStorageShareStateUpgradeV1ToV2(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { id := rawState["id"].(string) // name/resourceGroup/accountName diff --git a/azurerm/internal/services/storage/resource_arm_storage_table.go b/azurerm/internal/services/storage/resource_arm_storage_table.go index c41358990ee0..08da3d6d23e1 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table.go @@ -54,7 +54,7 @@ func resourceArmStorageTable() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageTableName, + ValidateFunc: ValidateArmStorageTableName, }, "storage_account_name": { @@ -279,7 +279,7 @@ func resourceArmStorageTableUpdate(d *schema.ResourceData, meta interface{}) err return resourceArmStorageTableRead(d, meta) } -func validateArmStorageTableName(v interface{}, k string) (warnings []string, errors []error) { +func ValidateArmStorageTableName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if value == "table" { errors = append(errors, fmt.Errorf( diff --git a/azurerm/internal/services/storage/resource_arm_storage_table_entity.go b/azurerm/internal/services/storage/resource_arm_storage_table_entity.go index d66ab10f1ead..d1a088ab85ac 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table_entity.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_entity.go @@ -37,7 +37,7 @@ func resourceArmStorageTableEntity() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageTableName, + ValidateFunc: ValidateArmStorageTableName, }, "storage_account_name": { Type: schema.TypeString, diff --git a/azurerm/internal/services/storage/resource_arm_storage_table_migration.go b/azurerm/internal/services/storage/resource_arm_storage_table_migration.go index 423c09309fb9..fea99ca0ad74 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_migration.go @@ -19,7 +19,7 @@ func resourceStorageTableStateResourceV0V1() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmStorageTableName, + ValidateFunc: ValidateArmStorageTableName, }, "storage_account_name": { Type: schema.TypeString, diff --git a/azurerm/internal/services/storage/data_source_storage_account_blob_container_sas_test.go b/azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go similarity index 60% rename from azurerm/internal/services/storage/data_source_storage_account_blob_container_sas_test.go rename to azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go index 8959e41c9a62..337e45cfe28e 100644 --- a/azurerm/internal/services/storage/data_source_storage_account_blob_container_sas_test.go +++ b/azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go @@ -1,21 +1,17 @@ -package storage +package tests import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceArmStorageAccountBlobContainerSas_basic(t *testing.T) { - dataSourceName := "data.azurerm_storage_account_blob_container_sas.test" - rInt := tf.AccRandTimeInt() - rString := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_storage_account_blob_container_sas", "test") utcNow := time.Now().UTC() startDate := utcNow.Format(time.RFC3339) endDate := utcNow.Add(time.Hour * 24).Format(time.RFC3339) @@ -25,32 +21,32 @@ func TestAccDataSourceArmStorageAccountBlobContainerSas_basic(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMStorageAccountBlobContainerSas_basic(rInt, rString, location, startDate, endDate), + Config: testAccDataSourceAzureRMStorageAccountBlobContainerSas_basic(data, startDate, endDate), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "https_only", "true"), - resource.TestCheckResourceAttr(dataSourceName, "start", startDate), - resource.TestCheckResourceAttr(dataSourceName, "expiry", endDate), - resource.TestCheckResourceAttr(dataSourceName, "ip_address", "168.1.5.65"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.read", "true"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.add", "true"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.create", "false"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.write", "false"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.delete", "true"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.list", "true"), - resource.TestCheckResourceAttr(dataSourceName, "cache_control", "max-age=5"), - resource.TestCheckResourceAttr(dataSourceName, "content_disposition", "inline"), - resource.TestCheckResourceAttr(dataSourceName, "content_encoding", "deflate"), - resource.TestCheckResourceAttr(dataSourceName, "content_language", "en-US"), - resource.TestCheckResourceAttr(dataSourceName, "content_type", "application/json"), - resource.TestCheckResourceAttrSet(dataSourceName, "sas"), + resource.TestCheckResourceAttr(data.ResourceName, "https_only", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "start", startDate), + resource.TestCheckResourceAttr(data.ResourceName, "expiry", endDate), + resource.TestCheckResourceAttr(data.ResourceName, "ip_address", "168.1.5.65"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.read", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.add", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.create", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.write", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.delete", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.list", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "cache_control", "max-age=5"), + resource.TestCheckResourceAttr(data.ResourceName, "content_disposition", "inline"), + resource.TestCheckResourceAttr(data.ResourceName, "content_encoding", "deflate"), + resource.TestCheckResourceAttr(data.ResourceName, "content_language", "en-US"), + resource.TestCheckResourceAttr(data.ResourceName, "content_type", "application/json"), + resource.TestCheckResourceAttrSet(data.ResourceName, "sas"), ), }, }, }) } -func testAccDataSourceAzureRMStorageAccountBlobContainerSas_basic(rInt int, rString string, location string, startDate string, endDate string) string { +func testAccDataSourceAzureRMStorageAccountBlobContainerSas_basic(data acceptance.TestData, startDate string, endDate string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-storage-%d" @@ -98,7 +94,7 @@ data "azurerm_storage_account_blob_container_sas" "test" { content_language = "en-US" content_type = "application/json" } -`, rInt, location, rString, startDate, endDate) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, startDate, endDate) } func TestAccDataSourceArmStorageAccountBlobContainerSas_permissionsString(t *testing.T) { @@ -116,7 +112,7 @@ func TestAccDataSourceArmStorageAccountBlobContainerSas_permissionsString(t *tes } for _, test := range testCases { - result := buildContainerPermissionsString(test.input) + result := storage.BuildContainerPermissionsString(test.input) if test.expected != result { t.Fatalf("Failed to build resource type string: expected: %s, result: %s", test.expected, result) } diff --git a/azurerm/internal/services/storage/data_source_storage_account_sas_test.go b/azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go similarity index 79% rename from azurerm/internal/services/storage/data_source_storage_account_sas_test.go rename to azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go index a7a1eb00a023..7039fc31128d 100644 --- a/azurerm/internal/services/storage/data_source_storage_account_sas_test.go +++ b/azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go @@ -1,21 +1,17 @@ -package storage +package tests import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "time" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceArmStorageAccountSas_basic(t *testing.T) { - dataSourceName := "data.azurerm_storage_account_sas.test" - rInt := tf.AccRandTimeInt() - rString := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_storage_account_sas", "test") utcNow := time.Now().UTC() startDate := utcNow.Format(time.RFC3339) endDate := utcNow.Add(time.Hour * 24).Format(time.RFC3339) @@ -25,19 +21,19 @@ func TestAccDataSourceArmStorageAccountSas_basic(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMStorageAccountSas_basic(rInt, rString, location, startDate, endDate), + Config: testAccDataSourceAzureRMStorageAccountSas_basic(data, startDate, endDate), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "https_only", "true"), - resource.TestCheckResourceAttr(dataSourceName, "start", startDate), - resource.TestCheckResourceAttr(dataSourceName, "expiry", endDate), - resource.TestCheckResourceAttrSet(dataSourceName, "sas"), + resource.TestCheckResourceAttr(data.ResourceName, "https_only", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "start", startDate), + resource.TestCheckResourceAttr(data.ResourceName, "expiry", endDate), + resource.TestCheckResourceAttrSet(data.ResourceName, "sas"), ), }, }, }) } -func testAccDataSourceAzureRMStorageAccountSas_basic(rInt int, rString string, location string, startDate string, endDate string) string { +func testAccDataSourceAzureRMStorageAccountSas_basic(data acceptance.TestData, startDate string, endDate string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" @@ -88,7 +84,7 @@ data "azurerm_storage_account_sas" "test" { process = false } } -`, rInt, location, rString, startDate, endDate) +`, data.RandomInteger, data.Locations, data.RandomString, startDate, endDate) } func TestAccDataSourceArmStorageAccountSas_resourceTypesString(t *testing.T) { @@ -103,7 +99,7 @@ func TestAccDataSourceArmStorageAccountSas_resourceTypesString(t *testing.T) { } for _, test := range testCases { - result := buildResourceTypesString(test.input) + result := storage.BuildResourceTypesString(test.input) if test.expected != result { t.Fatalf("Failed to build resource type string: expected: %s, result: %s", test.expected, result) } @@ -123,7 +119,7 @@ func TestAccDataSourceArmStorageAccountSas_servicesString(t *testing.T) { } for _, test := range testCases { - result := buildServicesString(test.input) + result := storage.BuildServicesString(test.input) if test.expected != result { t.Fatalf("Failed to build resource type string: expected: %s, result: %s", test.expected, result) } @@ -147,7 +143,7 @@ func TestAccDataSourceArmStorageAccountSas_permissionsString(t *testing.T) { } for _, test := range testCases { - result := buildPermissionsString(test.input) + result := storage.BuildPermissionsString(test.input) if test.expected != result { t.Fatalf("Failed to build resource type string: expected: %s, result: %s", test.expected, result) } diff --git a/azurerm/internal/services/storage/data_source_storage_account_test.go b/azurerm/internal/services/storage/tests/data_source_storage_account_test.go similarity index 53% rename from azurerm/internal/services/storage/data_source_storage_account_test.go rename to azurerm/internal/services/storage/tests/data_source_storage_account_test.go index 19ed75c26912..1e3bc97703e5 100644 --- a/azurerm/internal/services/storage/data_source_storage_account_test.go +++ b/azurerm/internal/services/storage/tests/data_source_storage_account_test.go @@ -1,22 +1,17 @@ -package storage +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMStorageAccount_basic(t *testing.T) { - dataSourceName := "data.azurerm_storage_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccDataSourceAzureRMStorageAccount_basic(ri, rs, location) - config := testAccDataSourceAzureRMStorageAccount_basicWithDataSource(ri, rs, location) + data := acceptance.BuildTestData(t, "data.azurerm_storage_account", "test") + preConfig := testAccDataSourceAzureRMStorageAccount_basic(data) + config := testAccDataSourceAzureRMStorageAccount_basicWithDataSource(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,10 +24,10 @@ func TestAccDataSourceAzureRMStorageAccount_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "account_tier", "Standard"), - resource.TestCheckResourceAttr(dataSourceName, "account_replication_type", "LRS"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "production"), + resource.TestCheckResourceAttr(data.ResourceName, "account_tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "account_replication_type", "LRS"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), ), }, }, @@ -40,10 +35,7 @@ func TestAccDataSourceAzureRMStorageAccount_basic(t *testing.T) { } func TestAccDataSourceAzureRMStorageAccount_withWriteLock(t *testing.T) { - dataSourceName := "data.azurerm_storage_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_storage_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,26 +43,26 @@ func TestAccDataSourceAzureRMStorageAccount_withWriteLock(t *testing.T) { CheckDestroy: testCheckAzureRMStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMStorageAccount_basicWriteLock(ri, rs, location), + Config: testAccDataSourceAzureRMStorageAccount_basicWriteLock(data), }, { - Config: testAccDataSourceAzureRMStorageAccount_basicWriteLockWithDataSource(ri, rs, location), + Config: testAccDataSourceAzureRMStorageAccount_basicWriteLockWithDataSource(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "account_tier", "Standard"), - resource.TestCheckResourceAttr(dataSourceName, "account_replication_type", "LRS"), - resource.TestCheckResourceAttr(dataSourceName, "primary_connection_string", ""), - resource.TestCheckResourceAttr(dataSourceName, "secondary_connection_string", ""), - resource.TestCheckResourceAttr(dataSourceName, "primary_blob_connection_string", ""), - resource.TestCheckResourceAttr(dataSourceName, "secondary_blob_connection_string", ""), - resource.TestCheckResourceAttr(dataSourceName, "primary_access_key", ""), - resource.TestCheckResourceAttr(dataSourceName, "secondary_access_key", ""), + resource.TestCheckResourceAttr(data.ResourceName, "account_tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "account_replication_type", "LRS"), + resource.TestCheckResourceAttr(data.ResourceName, "primary_connection_string", ""), + resource.TestCheckResourceAttr(data.ResourceName, "secondary_connection_string", ""), + resource.TestCheckResourceAttr(data.ResourceName, "primary_blob_connection_string", ""), + resource.TestCheckResourceAttr(data.ResourceName, "secondary_blob_connection_string", ""), + resource.TestCheckResourceAttr(data.ResourceName, "primary_access_key", ""), + resource.TestCheckResourceAttr(data.ResourceName, "secondary_access_key", ""), ), }, }, }) } -func testAccDataSourceAzureRMStorageAccount_basic(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMStorageAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-storage-%d" @@ -89,11 +81,11 @@ resource "azurerm_storage_account" "test" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccDataSourceAzureRMStorageAccount_basicWriteLock(rInt int, rString string, location string) string { - template := testAccDataSourceAzureRMStorageAccount_basic(rInt, rString, location) +func testAccDataSourceAzureRMStorageAccount_basicWriteLock(data acceptance.TestData) string { + template := testAccDataSourceAzureRMStorageAccount_basic(data) return fmt.Sprintf(` %s @@ -102,11 +94,11 @@ resource "azurerm_management_lock" "test" { scope = "${azurerm_storage_account.test.id}" lock_level = "ReadOnly" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccDataSourceAzureRMStorageAccount_basicWithDataSource(rInt int, rString string, location string) string { - config := testAccDataSourceAzureRMStorageAccount_basic(rInt, rString, location) +func testAccDataSourceAzureRMStorageAccount_basicWithDataSource(data acceptance.TestData) string { + config := testAccDataSourceAzureRMStorageAccount_basic(data) return fmt.Sprintf(` %s @@ -117,8 +109,8 @@ data "azurerm_storage_account" "test" { `, config) } -func testAccDataSourceAzureRMStorageAccount_basicWriteLockWithDataSource(rInt int, rString string, location string) string { - config := testAccDataSourceAzureRMStorageAccount_basicWriteLock(rInt, rString, location) +func testAccDataSourceAzureRMStorageAccount_basicWriteLockWithDataSource(data acceptance.TestData) string { + config := testAccDataSourceAzureRMStorageAccount_basicWriteLock(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/storage/tests/data_source_storage_management_policy_test.go b/azurerm/internal/services/storage/tests/data_source_storage_management_policy_test.go new file mode 100644 index 000000000000..ed74d532f990 --- /dev/null +++ b/azurerm/internal/services/storage/tests/data_source_storage_management_policy_test.go @@ -0,0 +1,87 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMStorageManagementPolicy_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_storage_account", "test") + config := testAccDataSourceAzureRMStorageManagementPolicy_basic(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.name", "rule1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.prefix_match.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.prefix_match.3439697764", "container1/prefix1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.blob_types.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.blob_types.1068358194", "blockBlob"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.snapshot.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "30"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMStorageManagementPolicy_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "testrg" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "testsa" { + name = "unlikely23exst2acct%s" + resource_group_name = "${azurerm_resource_group.testrg.name}" + + location = "${azurerm_resource_group.testrg.location}" + account_tier = "Standard" + account_replication_type = "LRS" + account_kind = "BlobStorage" +} + +resource "azurerm_storage_management_policy" "testpolicy" { + storage_account_id = "${azurerm_storage_account.testsa.id}" + + rule { + name = "rule1" + enabled = true + filters { + prefix_match = ["container1/prefix1"] + blob_types = ["blockBlob"] + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 10 + tier_to_archive_after_days_since_modification_greater_than = 50 + delete_after_days_since_modification_greater_than = 100 + } + snapshot { + delete_after_days_since_creation_greater_than = 30 + } + } + } +} + +data "azurerm_storage_management_policy" "testpolicy" { + storage_account_id = "${azurerm_storage_management_policy.testpolicy.storage_account_id}" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} diff --git a/azurerm/internal/services/storage/metadata_test.go b/azurerm/internal/services/storage/tests/metadata_test.go similarity index 81% rename from azurerm/internal/services/storage/metadata_test.go rename to azurerm/internal/services/storage/tests/metadata_test.go index 84d045f49830..e5f598a67e98 100644 --- a/azurerm/internal/services/storage/metadata_test.go +++ b/azurerm/internal/services/storage/tests/metadata_test.go @@ -1,6 +1,9 @@ -package storage +package tests -import "testing" +import ( + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" + "testing" +) func TestValidateMetaDataKeys(t *testing.T) { testData := []struct { @@ -48,7 +51,7 @@ func TestValidateMetaDataKeys(t *testing.T) { value := map[string]interface{}{ v.Input: "hello", } - warnings, errors := validateMetaDataKeys(value, "field") + warnings, errors := storage.ValidateMetaDataKeys(value, "field") if len(warnings) != 0 { t.Fatalf("Expected no warnings but got %d", len(warnings)) } diff --git a/azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go similarity index 88% rename from azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go index 663dcae4c61d..0ae82e44d707 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go @@ -1,6 +1,7 @@ -package storage +package tests import ( + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -51,7 +52,7 @@ func TestAzureRMStorageAccountMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := resourceStorageAccountMigrateState(tc.StateVersion, is, tc.Meta) + is, err := storage.ResourceStorageAccountMigrateState(tc.StateVersion, is, tc.Meta) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/resource_arm_storage_account_network_rules_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_account_network_rules_test.go similarity index 74% rename from azurerm/internal/services/storage/resource_arm_storage_account_network_rules_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_account_network_rules_test.go index 3a9bb6568cec..efa6216b8198 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account_network_rules_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_account_network_rules_test.go @@ -1,19 +1,15 @@ -package storage +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMStorageAccountNetworkRules_basic(t *testing.T) { - resourceName := "azurerm_storage_account_network_rules.test" - rInt := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_storage_account_network_rules", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,24 +17,18 @@ func TestAccAzureRMStorageAccountNetworkRules_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageAccountNetworkRules_basic(rInt, rs, acceptance.Location()), + Config: testAccAzureRMStorageAccountNetworkRules_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageAccountNetworkRules_update(t *testing.T) { - resourceName := "azurerm_storage_account_network_rules.test" - rInt := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_storage_account_network_rules", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -46,46 +36,32 @@ func TestAccAzureRMStorageAccountNetworkRules_update(t *testing.T) { CheckDestroy: testCheckAzureRMStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageAccountNetworkRules_basic(rInt, rs, acceptance.Location()), + Config: testAccAzureRMStorageAccountNetworkRules_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStorageAccountNetworkRules_update(rInt, rs, acceptance.Location()), + Config: testAccAzureRMStorageAccountNetworkRules_update(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStorageAccountNetworkRules_basic(rInt, rs, acceptance.Location()), + Config: testAccAzureRMStorageAccountNetworkRules_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageAccountNetworkRules_empty(t *testing.T) { - resourceName := "azurerm_storage_account_network_rules.test" - rInt := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_storage_account_network_rules", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -93,21 +69,17 @@ func TestAccAzureRMStorageAccountNetworkRules_empty(t *testing.T) { CheckDestroy: testCheckAzureRMStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageAccountNetworkRules_empty(rInt, rs, acceptance.Location()), + Config: testAccAzureRMStorageAccountNetworkRules_empty(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMStorageAccountNetworkRules_basic(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccountNetworkRules_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -149,10 +121,10 @@ resource "azurerm_storage_account_network_rules" "test" { ip_rules = ["127.0.0.1"] virtual_network_subnet_ids = ["${azurerm_subnet.test.id}"] } -`, rInt, location, rInt, rInt, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomString) } -func testAccAzureRMStorageAccountNetworkRules_update(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccountNetworkRules_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -203,10 +175,10 @@ resource "azurerm_storage_account_network_rules" "test" { virtual_network_subnet_ids = ["${azurerm_subnet.test.id}", "${azurerm_subnet.test2.id}"] bypass = ["Metrics"] } -`, rInt, location, rInt, rInt, rInt, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString) } -func testAccAzureRMStorageAccountNetworkRules_empty(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccountNetworkRules_empty(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -232,5 +204,5 @@ resource "azurerm_storage_account_network_rules" "test" { default_action = "Deny" bypass = ["Metrics"] } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/storage/resource_arm_storage_account_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go similarity index 68% rename from azurerm/internal/services/storage/resource_arm_storage_account_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go index 549a80a49e76..0dd87841e693 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go @@ -1,7 +1,8 @@ -package storage +package tests import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "net/http" "os" "regexp" @@ -12,10 +13,8 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) func TestValidateArmStorageAccountType(t *testing.T) { @@ -28,7 +27,7 @@ func TestValidateArmStorageAccountType(t *testing.T) { } for _, test := range testCases { - _, es := validateArmStorageAccountType(test.input, "account_type") + _, es := storage.ValidateArmStorageAccountType(test.input, "account_type") if test.shouldError && len(es) == 0 { t.Fatalf("Expected validating account_type %q to fail", test.input) @@ -50,7 +49,7 @@ func TestValidateArmStorageAccountName(t *testing.T) { } for _, test := range testCases { - _, es := ValidateArmStorageAccountName(test.input, "name") + _, es := storage.ValidateArmStorageAccountName(test.input, "name") if test.shouldError && len(es) == 0 { t.Fatalf("Expected validating name %q to fail", test.input) @@ -59,12 +58,9 @@ func TestValidateArmStorageAccountName(t *testing.T) { } func TestAccAzureRMStorageAccount_basic(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_basic(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_update(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_basic(data) + postConfig := testAccAzureRMStorageAccount_update(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,26 +70,22 @@ func TestAccAzureRMStorageAccount_basic(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "account_tier", "Standard"), - resource.TestCheckResourceAttr(resourceName, "account_replication_type", "LRS"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "account_tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "account_replication_type", "LRS"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "account_tier", "Standard"), - resource.TestCheckResourceAttr(resourceName, "account_replication_type", "GRS"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "account_tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "account_replication_type", "GRS"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, }, @@ -105,11 +97,7 @@ func TestAccAzureRMStorageAccount_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -117,24 +105,18 @@ func TestAccAzureRMStorageAccount_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageAccount_basic(ri, rs, location), + Config: testAccAzureRMStorageAccount_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStorageAccount_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_storage_account"), - }, + data.RequiresImportErrorStep(testAccAzureRMStorageAccount_requiresImport), }, }) } func TestAccAzureRMStorageAccount_writeLock(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -142,40 +124,33 @@ func TestAccAzureRMStorageAccount_writeLock(t *testing.T) { CheckDestroy: testCheckAzureRMStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageAccount_writeLock(ri, rs, location), + Config: testAccAzureRMStorageAccount_writeLock(data), }, { // works around a bug in the test suite where the Storage Account won't be re-read after the Lock's provisioned - Config: testAccAzureRMStorageAccount_writeLock(ri, rs, location), + Config: testAccAzureRMStorageAccount_writeLock(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "account_tier", "Standard"), - resource.TestCheckResourceAttr(resourceName, "account_replication_type", "LRS"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), - resource.TestCheckResourceAttr(resourceName, "primary_connection_string", ""), - resource.TestCheckResourceAttr(resourceName, "secondary_connection_string", ""), - resource.TestCheckResourceAttr(resourceName, "primary_blob_connection_string", ""), - resource.TestCheckResourceAttr(resourceName, "secondary_blob_connection_string", ""), - resource.TestCheckResourceAttr(resourceName, "primary_access_key", ""), - resource.TestCheckResourceAttr(resourceName, "secondary_access_key", ""), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "account_tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "account_replication_type", "LRS"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), + resource.TestCheckResourceAttr(data.ResourceName, "primary_connection_string", ""), + resource.TestCheckResourceAttr(data.ResourceName, "secondary_connection_string", ""), + resource.TestCheckResourceAttr(data.ResourceName, "primary_blob_connection_string", ""), + resource.TestCheckResourceAttr(data.ResourceName, "secondary_blob_connection_string", ""), + resource.TestCheckResourceAttr(data.ResourceName, "primary_access_key", ""), + resource.TestCheckResourceAttr(data.ResourceName, "secondary_access_key", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageAccount_premium(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_premium(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_premium(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -185,27 +160,21 @@ func TestAccAzureRMStorageAccount_premium(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "account_tier", "Premium"), - resource.TestCheckResourceAttr(resourceName, "account_replication_type", "LRS"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "account_tier", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "account_replication_type", "LRS"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageAccount_disappears(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - preConfig := testAccAzureRMStorageAccount_basic(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -215,12 +184,12 @@ func TestAccAzureRMStorageAccount_disappears(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "account_tier", "Standard"), - resource.TestCheckResourceAttr(resourceName, "account_replication_type", "LRS"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), - testCheckAzureRMStorageAccountDisappears(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "account_tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "account_replication_type", "LRS"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), + testCheckAzureRMStorageAccountDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -229,10 +198,8 @@ func TestAccAzureRMStorageAccount_disappears(t *testing.T) { } func TestAccAzureRMStorageAccount_blobConnectionString(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - preConfig := testAccAzureRMStorageAccount_basic(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -241,7 +208,7 @@ func TestAccAzureRMStorageAccount_blobConnectionString(t *testing.T) { Steps: []resource.TestStep{ { Config: preConfig, - Check: resource.ComposeTestCheckFunc(testCheckAzureRMStorageAccountExists(resourceName), + Check: resource.ComposeTestCheckFunc(testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttrSet("azurerm_storage_account.testsa", "primary_blob_connection_string"), ), }, @@ -254,13 +221,9 @@ func TestAccAzureRMStorageAccount_blobEncryption(t *testing.T) { if !exists { t.Skip("`TF_ACC_STORAGE_ENCRYPTION_DISABLE` isn't specified - skipping since disabling encryption is generally disabled") } - - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_blobEncryption(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_blobEncryptionDisabled(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_blobEncryption(data) + postConfig := testAccAzureRMStorageAccount_blobEncryptionDisabled(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -270,19 +233,15 @@ func TestAccAzureRMStorageAccount_blobEncryption(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "enable_blob_encryption", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "enable_blob_encryption", "false"), ), }, @@ -295,13 +254,9 @@ func TestAccAzureRMStorageAccount_fileEncryption(t *testing.T) { if !exists { t.Skip("`TF_ACC_STORAGE_ENCRYPTION_DISABLE` isn't specified - skipping since disabling encryption is generally disabled") } - - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_fileEncryption(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_fileEncryptionDisabled(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_fileEncryption(data) + postConfig := testAccAzureRMStorageAccount_fileEncryptionDisabled(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -311,19 +266,15 @@ func TestAccAzureRMStorageAccount_fileEncryption(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "enable_file_encryption", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "enable_file_encryption", "false"), ), }, @@ -332,12 +283,9 @@ func TestAccAzureRMStorageAccount_fileEncryption(t *testing.T) { } func TestAccAzureRMStorageAccount_enableHttpsTrafficOnly(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_enableHttpsTrafficOnly(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_enableHttpsTrafficOnlyDisabled(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_enableHttpsTrafficOnly(data) + postConfig := testAccAzureRMStorageAccount_enableHttpsTrafficOnlyDisabled(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -347,19 +295,15 @@ func TestAccAzureRMStorageAccount_enableHttpsTrafficOnly(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "enable_https_traffic_only", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "enable_https_traffic_only", "false"), ), }, @@ -368,12 +312,9 @@ func TestAccAzureRMStorageAccount_enableHttpsTrafficOnly(t *testing.T) { } func TestAccAzureRMStorageAccount_isHnsEnabled(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_isHnsEnabledTrue(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_isHnsEnabledFalse(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_isHnsEnabledTrue(data) + postConfig := testAccAzureRMStorageAccount_isHnsEnabledFalse(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -383,19 +324,15 @@ func TestAccAzureRMStorageAccount_isHnsEnabled(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "is_hns_enabled", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "is_hns_enabled", "false"), ), }, @@ -404,12 +341,9 @@ func TestAccAzureRMStorageAccount_isHnsEnabled(t *testing.T) { } func TestAccAzureRMStorageAccount_blobStorageWithUpdate(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_blobStorage(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_blobStorageUpdate(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_blobStorage(data) + postConfig := testAccAzureRMStorageAccount_blobStorageUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -419,20 +353,16 @@ func TestAccAzureRMStorageAccount_blobStorageWithUpdate(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_kind", "BlobStorage"), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", "Hot"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", "Cool"), ), }, @@ -441,10 +371,7 @@ func TestAccAzureRMStorageAccount_blobStorageWithUpdate(t *testing.T) { } func TestAccAzureRMStorageAccount_blockBlobStorage(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -452,29 +379,22 @@ func TestAccAzureRMStorageAccount_blockBlobStorage(t *testing.T) { CheckDestroy: testCheckAzureRMStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageAccount_blockBlobStorage(ri, rs, location), + Config: testAccAzureRMStorageAccount_blockBlobStorage(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_kind", "BlockBlobStorage"), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageAccount_fileStorageWithUpdate(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_fileStorage(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_fileStorageUpdate(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_fileStorage(data) + postConfig := testAccAzureRMStorageAccount_fileStorageUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -484,21 +404,17 @@ func TestAccAzureRMStorageAccount_fileStorageWithUpdate(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_kind", "FileStorage"), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_tier", "Premium"), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", "Hot"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_tier", "Premium"), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", "Cool"), ), @@ -507,12 +423,9 @@ func TestAccAzureRMStorageAccount_fileStorageWithUpdate(t *testing.T) { }) } func TestAccAzureRMStorageAccount_storageV2WithUpdate(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_storageV2(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_storageV2Update(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_storageV2(data) + postConfig := testAccAzureRMStorageAccount_storageV2Update(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -522,20 +435,16 @@ func TestAccAzureRMStorageAccount_storageV2WithUpdate(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_kind", "StorageV2"), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", "Hot"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "access_tier", "Cool"), ), }, @@ -544,10 +453,8 @@ func TestAccAzureRMStorageAccount_storageV2WithUpdate(t *testing.T) { } func TestAccAzureRMStorageAccount_NonStandardCasing(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - preConfig := testAccAzureRMStorageAccount_nonStandardCasing(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_nonStandardCasing(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -557,14 +464,10 @@ func TestAccAzureRMStorageAccount_NonStandardCasing(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: preConfig, PlanOnly: true, @@ -575,11 +478,8 @@ func TestAccAzureRMStorageAccount_NonStandardCasing(t *testing.T) { } func TestAccAzureRMStorageAccount_enableIdentity(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - config := testAccAzureRMStorageAccount_identity(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + config := testAccAzureRMStorageAccount_identity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -589,10 +489,10 @@ func TestAccAzureRMStorageAccount_enableIdentity(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, }, @@ -600,13 +500,9 @@ func TestAccAzureRMStorageAccount_enableIdentity(t *testing.T) { } func TestAccAzureRMStorageAccount_updateResourceByEnablingIdentity(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - - basicResourceNoManagedIdentity := testAccAzureRMStorageAccount_basic(ri, rs, acceptance.Location()) - managedIdentityEnabled := testAccAzureRMStorageAccount_identity(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + basicResourceNoManagedIdentity := testAccAzureRMStorageAccount_basic(data) + managedIdentityEnabled := testAccAzureRMStorageAccount_identity(data) uuidMatch := regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$") @@ -618,17 +514,17 @@ func TestAccAzureRMStorageAccount_updateResourceByEnablingIdentity(t *testing.T) { Config: basicResourceNoManagedIdentity, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.#", "0"), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.#", "0"), ), }, { Config: managedIdentityEnabled, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", uuidMatch), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", uuidMatch), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", uuidMatch), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", uuidMatch), ), }, }, @@ -636,12 +532,9 @@ func TestAccAzureRMStorageAccount_updateResourceByEnablingIdentity(t *testing.T) } func TestAccAzureRMStorageAccount_networkRules(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_networkRules(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_networkRulesUpdate(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_networkRules(data) + postConfig := testAccAzureRMStorageAccount_networkRulesUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -651,25 +544,21 @@ func TestAccAzureRMStorageAccount_networkRules(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.default_action", "Deny"), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.ip_rules.#", "1"), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.virtual_network_subnet_ids.#", "1"), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.default_action", "Deny"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.ip_rules.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.virtual_network_subnet_ids.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.default_action", "Deny"), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.ip_rules.#", "2"), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.virtual_network_subnet_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.bypass.#", "2"), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.default_action", "Deny"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.ip_rules.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.virtual_network_subnet_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.bypass.#", "2"), ), }, }, @@ -677,12 +566,9 @@ func TestAccAzureRMStorageAccount_networkRules(t *testing.T) { } func TestAccAzureRMStorageAccount_networkRulesDeleted(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_networkRules(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_networkRulesReverted(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_networkRules(data) + postConfig := testAccAzureRMStorageAccount_networkRulesReverted(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -692,17 +578,17 @@ func TestAccAzureRMStorageAccount_networkRulesDeleted(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.default_action", "Deny"), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.ip_rules.#", "1"), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.virtual_network_subnet_ids.#", "1"), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.default_action", "Deny"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.ip_rules.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.virtual_network_subnet_ids.#", "1"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_rules.0.default_action", "Allow"), + testCheckAzureRMStorageAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rules.0.default_action", "Allow"), ), }, }, @@ -710,12 +596,9 @@ func TestAccAzureRMStorageAccount_networkRulesDeleted(t *testing.T) { } func TestAccAzureRMStorageAccount_enableAdvancedThreatProtection(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_enableAdvancedThreatProtection(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_enableAdvancedThreatProtectionDisabled(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_enableAdvancedThreatProtection(data) + postConfig := testAccAzureRMStorageAccount_enableAdvancedThreatProtectionDisabled(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -725,38 +608,27 @@ func TestAccAzureRMStorageAccount_enableAdvancedThreatProtection(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "enable_advanced_threat_protection", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "enable_advanced_threat_protection", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageAccount_blobProperties(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_blobProperties(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_blobPropertiesUpdated(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_blobProperties(data) + postConfig := testAccAzureRMStorageAccount_blobPropertiesUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -766,38 +638,27 @@ func TestAccAzureRMStorageAccount_blobProperties(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "blob_properties.0.delete_retention_policy.0.days", "300"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "blob_properties.0.delete_retention_policy.0.days", "7"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageAccount_queueProperties(t *testing.T) { - resourceName := "azurerm_storage_account.testsa" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - preConfig := testAccAzureRMStorageAccount_queueProperties(ri, rs, location) - postConfig := testAccAzureRMStorageAccount_queuePropertiesUpdated(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_storage_account", "test") + preConfig := testAccAzureRMStorageAccount_queueProperties(data) + postConfig := testAccAzureRMStorageAccount_queuePropertiesUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -807,25 +668,17 @@ func TestAccAzureRMStorageAccount_queueProperties(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageAccountExists(resourceName), + testCheckAzureRMStorageAccountExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -906,7 +759,7 @@ func testCheckAzureRMStorageAccountDestroy(s *terraform.State) error { return nil } -func testAccAzureRMStorageAccount_basic(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -925,11 +778,11 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStorageAccount_basic(rInt, rString, location) +func testAccAzureRMStorageAccount_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStorageAccount_basic(data) return fmt.Sprintf(` %s @@ -943,8 +796,8 @@ resource "azurerm_storage_account" "import" { `, template) } -func testAccAzureRMStorageAccount_writeLock(rInt int, rString, location string) string { - template := testAccAzureRMStorageAccount_basic(rInt, rString, location) +func testAccAzureRMStorageAccount_writeLock(data acceptance.TestData) string { + template := testAccAzureRMStorageAccount_basic(data) return fmt.Sprintf(` %s @@ -953,10 +806,10 @@ resource "azurerm_management_lock" "test" { scope = "${azurerm_storage_account.testsa.id}" lock_level = "ReadOnly" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStorageAccount_premium(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_premium(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -975,10 +828,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_update(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -997,10 +850,10 @@ resource "azurerm_storage_account" "testsa" { environment = "staging" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_blobEncryption(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_blobEncryption(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1020,10 +873,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_blobEncryptionDisabled(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_blobEncryptionDisabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1043,10 +896,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_fileEncryption(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_fileEncryption(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1066,10 +919,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_fileEncryptionDisabled(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_fileEncryptionDisabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1089,10 +942,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_enableHttpsTrafficOnly(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_enableHttpsTrafficOnly(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1112,10 +965,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_enableHttpsTrafficOnlyDisabled(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_enableHttpsTrafficOnlyDisabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1135,10 +988,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_isHnsEnabledTrue(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_isHnsEnabledTrue(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1155,10 +1008,10 @@ resource "azurerm_storage_account" "testsa" { account_replication_type = "LRS" is_hns_enabled = true } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_isHnsEnabledFalse(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_isHnsEnabledFalse(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1175,10 +1028,10 @@ resource "azurerm_storage_account" "testsa" { account_replication_type = "LRS" is_hns_enabled = false } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_blobStorage(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_blobStorage(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1198,10 +1051,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_blobStorageUpdate(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_blobStorageUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1222,10 +1075,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_blockBlobStorage(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_blockBlobStorage(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1245,10 +1098,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_fileStorage(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_fileStorage(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1269,10 +1122,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_fileStorageUpdate(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_fileStorageUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1293,10 +1146,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_storageV2(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_storageV2(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1316,10 +1169,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_storageV2Update(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_storageV2Update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1340,10 +1193,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_nonStandardCasing(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_nonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1361,10 +1214,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_identity(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_identity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1387,10 +1240,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_networkRules(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_networkRules(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1429,10 +1282,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rInt, rInt, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomString) } -func testAccAzureRMStorageAccount_networkRulesUpdate(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_networkRulesUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1471,10 +1324,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rInt, rInt, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomString) } -func testAccAzureRMStorageAccount_networkRulesReverted(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_networkRulesReverted(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1513,10 +1366,10 @@ resource "azurerm_storage_account" "testsa" { environment = "production" } } -`, rInt, location, rInt, rInt, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomString) } -func testAccAzureRMStorageAccount_enableAdvancedThreatProtection(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_enableAdvancedThreatProtection(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1531,10 +1384,10 @@ resource "azurerm_storage_account" "testsa" { account_replication_type = "LRS" enable_advanced_threat_protection = true } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_enableAdvancedThreatProtectionDisabled(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_enableAdvancedThreatProtectionDisabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1549,10 +1402,10 @@ resource "azurerm_storage_account" "testsa" { account_replication_type = "LRS" enable_advanced_threat_protection = false } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_blobProperties(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_blobProperties(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestAzureRMSA-%d" @@ -1573,10 +1426,10 @@ resource "azurerm_storage_account" "testsa" { } } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_blobPropertiesUpdated(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_blobPropertiesUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestAzureRMSA-%d" @@ -1596,10 +1449,10 @@ resource "azurerm_storage_account" "testsa" { } } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_queueProperties(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_queueProperties(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1644,10 +1497,10 @@ resource "azurerm_storage_account" "testsa" { } } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMStorageAccount_queuePropertiesUpdated(rInt int, rString string, location string) string { +func testAccAzureRMStorageAccount_queuePropertiesUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-storage-%d" @@ -1700,5 +1553,5 @@ resource "azurerm_storage_account" "testsa" { } } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go similarity index 91% rename from azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go index 65452307ca8b..ee7a7cd8c6d7 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go @@ -1,8 +1,9 @@ -package storage +package tests import ( "context" "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -62,7 +63,7 @@ func TestAccAzureRMStorageBlobMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := resourceStorageBlobMigrateState(tc.StateVersion, is, client) + is, err := storage.ResourceStorageBlobMigrateState(tc.StateVersion, is, client) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/resource_arm_storage_blob_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_blob_test.go similarity index 72% rename from azurerm/internal/services/storage/resource_arm_storage_blob_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_blob_test.go index 1d5a890857be..266142b69be3 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_blob_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_blob_test.go @@ -1,17 +1,14 @@ -package storage +package tests import ( "crypto/rand" "fmt" "io/ioutil" "os" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -20,10 +17,7 @@ import ( ) func TestAccAzureRMStorageBlob_disappears(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -31,10 +25,10 @@ func TestAccAzureRMStorageBlob_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_blockEmpty(ri, rs, location), + Config: testAccAzureRMStorageBlob_blockEmpty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), - testCheckAzureRMStorageBlobDisappears(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), + testCheckAzureRMStorageBlobDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -43,10 +37,7 @@ func TestAccAzureRMStorageBlob_disappears(t *testing.T) { } func TestAccAzureRMStorageBlob_appendEmpty(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,13 +45,13 @@ func TestAccAzureRMStorageBlob_appendEmpty(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_appendEmpty(ri, rs, location), + Config: testAccAzureRMStorageBlob_appendEmpty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, @@ -70,10 +61,7 @@ func TestAccAzureRMStorageBlob_appendEmpty(t *testing.T) { } func TestAccAzureRMStorageBlob_appendEmptyMetaData(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,13 +69,13 @@ func TestAccAzureRMStorageBlob_appendEmptyMetaData(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_appendEmptyMetaData(ri, rs, location), + Config: testAccAzureRMStorageBlob_appendEmptyMetaData(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, @@ -97,10 +85,7 @@ func TestAccAzureRMStorageBlob_appendEmptyMetaData(t *testing.T) { } func TestAccAzureRMStorageBlob_blockEmpty(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -108,13 +93,13 @@ func TestAccAzureRMStorageBlob_blockEmpty(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_blockEmpty(ri, rs, location), + Config: testAccAzureRMStorageBlob_blockEmpty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, @@ -124,10 +109,7 @@ func TestAccAzureRMStorageBlob_blockEmpty(t *testing.T) { } func TestAccAzureRMStorageBlob_blockEmptyMetaData(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -135,13 +117,13 @@ func TestAccAzureRMStorageBlob_blockEmptyMetaData(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_blockEmptyMetaData(ri, rs, location), + Config: testAccAzureRMStorageBlob_blockEmptyMetaData(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, @@ -151,10 +133,7 @@ func TestAccAzureRMStorageBlob_blockEmptyMetaData(t *testing.T) { } func TestAccAzureRMStorageBlob_blockEmptyAccessTier(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -162,30 +141,30 @@ func TestAccAzureRMStorageBlob_blockEmptyAccessTier(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_blockEmptyAccessTier(ri, rs, location, blobs.Cool), + Config: testAccAzureRMStorageBlob_blockEmptyAccessTier(data, blobs.Cool), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "access_tier", "Cool"), + testCheckAzureRMStorageBlobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "access_tier", "Cool"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, }, { - Config: testAccAzureRMStorageBlob_blockEmptyAccessTier(ri, rs, location, blobs.Hot), + Config: testAccAzureRMStorageBlob_blockEmptyAccessTier(data, blobs.Hot), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "access_tier", "Hot"), + testCheckAzureRMStorageBlobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "access_tier", "Hot"), ), }, { - Config: testAccAzureRMStorageBlob_blockEmptyAccessTier(ri, rs, location, blobs.Cool), + Config: testAccAzureRMStorageBlob_blockEmptyAccessTier(data, blobs.Cool), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "access_tier", "Cool"), + testCheckAzureRMStorageBlobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "access_tier", "Cool"), ), }, }, @@ -193,10 +172,7 @@ func TestAccAzureRMStorageBlob_blockEmptyAccessTier(t *testing.T) { } func TestAccAzureRMStorageBlob_blockFromInlineContent(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -204,13 +180,13 @@ func TestAccAzureRMStorageBlob_blockFromInlineContent(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_blockFromInlineContent(ri, rs, location), + Config: testAccAzureRMStorageBlob_blockFromInlineContent(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source_content", "type"}, @@ -220,10 +196,7 @@ func TestAccAzureRMStorageBlob_blockFromInlineContent(t *testing.T) { } func TestAccAzureRMStorageBlob_blockFromPublicBlob(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -231,13 +204,13 @@ func TestAccAzureRMStorageBlob_blockFromPublicBlob(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_blockFromPublicBlob(ri, rs, location), + Config: testAccAzureRMStorageBlob_blockFromPublicBlob(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source_uri", "type"}, @@ -247,10 +220,7 @@ func TestAccAzureRMStorageBlob_blockFromPublicBlob(t *testing.T) { } func TestAccAzureRMStorageBlob_blockFromPublicFile(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -258,13 +228,13 @@ func TestAccAzureRMStorageBlob_blockFromPublicFile(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_blockFromPublicFile(ri, rs, location), + Config: testAccAzureRMStorageBlob_blockFromPublicFile(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source_uri", "type"}, @@ -274,10 +244,7 @@ func TestAccAzureRMStorageBlob_blockFromPublicFile(t *testing.T) { } func TestAccAzureRMStorageBlob_blockFromExistingBlob(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -285,13 +252,13 @@ func TestAccAzureRMStorageBlob_blockFromExistingBlob(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_blockFromExistingBlob(ri, rs, location), + Config: testAccAzureRMStorageBlob_blockFromExistingBlob(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source_uri", "type"}, @@ -309,11 +276,7 @@ func TestAccAzureRMStorageBlob_blockFromLocalFile(t *testing.T) { if err := testAccAzureRMStorageBlob_populateTempFile(sourceBlob); err != nil { t.Fatalf("Error populating temp file: %s", err) } - - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -321,14 +284,14 @@ func TestAccAzureRMStorageBlob_blockFromLocalFile(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_blockFromLocalBlob(ri, rs, location, sourceBlob.Name()), + Config: testAccAzureRMStorageBlob_blockFromLocalBlob(data, sourceBlob.Name()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), - testCheckAzureRMStorageBlobMatchesFile(resourceName, blobs.BlockBlob, sourceBlob.Name()), + testCheckAzureRMStorageBlobExists(data.ResourceName), + testCheckAzureRMStorageBlobMatchesFile(data.ResourceName, blobs.BlockBlob, sourceBlob.Name()), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source", "type"}, @@ -338,10 +301,7 @@ func TestAccAzureRMStorageBlob_blockFromLocalFile(t *testing.T) { } func TestAccAzureRMStorageBlob_contentType(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -349,25 +309,25 @@ func TestAccAzureRMStorageBlob_contentType(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_contentType(ri, rs, location), + Config: testAccAzureRMStorageBlob_contentType(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, }, { - Config: testAccAzureRMStorageBlob_contentTypeUpdated(ri, rs, location), + Config: testAccAzureRMStorageBlob_contentTypeUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, @@ -377,10 +337,7 @@ func TestAccAzureRMStorageBlob_contentType(t *testing.T) { } func TestAccAzureRMStorageBlob_contentTypePremium(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -388,13 +345,13 @@ func TestAccAzureRMStorageBlob_contentTypePremium(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_contentTypePremium(ri, rs, location), + Config: testAccAzureRMStorageBlob_contentTypePremium(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, @@ -404,10 +361,7 @@ func TestAccAzureRMStorageBlob_contentTypePremium(t *testing.T) { } func TestAccAzureRMStorageBlob_pageEmpty(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -415,13 +369,13 @@ func TestAccAzureRMStorageBlob_pageEmpty(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_pageEmpty(ri, rs, location), + Config: testAccAzureRMStorageBlob_pageEmpty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, @@ -431,10 +385,7 @@ func TestAccAzureRMStorageBlob_pageEmpty(t *testing.T) { } func TestAccAzureRMStorageBlob_pageEmptyPremium(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -442,13 +393,13 @@ func TestAccAzureRMStorageBlob_pageEmptyPremium(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_pageEmptyPremium(ri, rs, location), + Config: testAccAzureRMStorageBlob_pageEmptyPremium(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, @@ -458,10 +409,7 @@ func TestAccAzureRMStorageBlob_pageEmptyPremium(t *testing.T) { } func TestAccAzureRMStorageBlob_pageEmptyMetaData(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -469,13 +417,13 @@ func TestAccAzureRMStorageBlob_pageEmptyMetaData(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_pageEmptyMetaData(ri, rs, location), + Config: testAccAzureRMStorageBlob_pageEmptyMetaData(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, @@ -485,10 +433,7 @@ func TestAccAzureRMStorageBlob_pageEmptyMetaData(t *testing.T) { } func TestAccAzureRMStorageBlob_pageFromExistingBlob(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -496,13 +441,13 @@ func TestAccAzureRMStorageBlob_pageFromExistingBlob(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_pageFromExistingBlob(ri, rs, location), + Config: testAccAzureRMStorageBlob_pageFromExistingBlob(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source_uri", "type"}, @@ -520,11 +465,7 @@ func TestAccAzureRMStorageBlob_pageFromLocalFile(t *testing.T) { if err := testAccAzureRMStorageBlob_populateTempFile(sourceBlob); err != nil { t.Fatalf("Error populating temp file: %s", err) } - - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -532,14 +473,14 @@ func TestAccAzureRMStorageBlob_pageFromLocalFile(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_pageFromLocalBlob(ri, rs, location, sourceBlob.Name()), + Config: testAccAzureRMStorageBlob_pageFromLocalBlob(data, sourceBlob.Name()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), - testCheckAzureRMStorageBlobMatchesFile(resourceName, blobs.PageBlob, sourceBlob.Name()), + testCheckAzureRMStorageBlobExists(data.ResourceName), + testCheckAzureRMStorageBlobMatchesFile(data.ResourceName, blobs.PageBlob, sourceBlob.Name()), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "source", "type"}, @@ -553,11 +494,7 @@ func TestAccAzureRMStorageBlob_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -565,24 +502,18 @@ func TestAccAzureRMStorageBlob_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_blockFromPublicBlob(ri, rs, location), + Config: testAccAzureRMStorageBlob_blockFromPublicBlob(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStorageBlob_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_storage_blob"), - }, + data.RequiresImportErrorStep(testAccAzureRMStorageBlob_requiresImport), }, }) } func TestAccAzureRMStorageBlob_update(t *testing.T) { - resourceName := "azurerm_storage_blob.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_blob", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -590,25 +521,25 @@ func TestAccAzureRMStorageBlob_update(t *testing.T) { CheckDestroy: testCheckAzureRMStorageBlobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageBlob_update(ri, rs, location), + Config: testAccAzureRMStorageBlob_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, }, { - Config: testAccAzureRMStorageBlob_updateUpdated(ri, rs, location), + Config: testAccAzureRMStorageBlob_updateUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageBlobExists(resourceName), + testCheckAzureRMStorageBlobExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"attempts", "parallelism", "size", "type"}, @@ -801,8 +732,8 @@ func testCheckAzureRMStorageBlobDestroy(s *terraform.State) error { return nil } -func testAccAzureRMStorageBlob_appendEmpty(rInt int, rString string, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_appendEmpty(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -816,8 +747,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_appendEmptyMetaData(rInt int, rString string, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_appendEmptyMetaData(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -835,8 +766,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_blockEmpty(rInt int, rString string, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_blockEmpty(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -850,8 +781,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_blockEmptyMetaData(rInt int, rString string, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_blockEmptyMetaData(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -869,8 +800,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_blockEmptyAccessTier(rInt int, rString string, location string, accessTier blobs.AccessTier) string { - template := testAccAzureRMStorageBlob_templateBlockBlobStorage(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_blockEmptyAccessTier(data acceptance.TestData, accessTier blobs.AccessTier) string { + template := testAccAzureRMStorageBlob_templateBlockBlobStorage(data, "private") return fmt.Sprintf(` %s @@ -885,8 +816,8 @@ resource "azurerm_storage_blob" "test" { `, template, string(accessTier)) } -func testAccAzureRMStorageBlob_blockFromInlineContent(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "blob") +func testAccAzureRMStorageBlob_blockFromInlineContent(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "blob") return fmt.Sprintf(` %s @@ -901,8 +832,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_blockFromPublicBlob(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "blob") +func testAccAzureRMStorageBlob_blockFromPublicBlob(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "blob") return fmt.Sprintf(` %s @@ -935,8 +866,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_blockFromPublicFile(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_blockFromPublicFile(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -952,8 +883,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_blockFromExistingBlob(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_blockFromExistingBlob(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -979,8 +910,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_blockFromLocalBlob(rInt int, rString, location, fileName string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_blockFromLocalBlob(data acceptance.TestData, fileName string) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -995,8 +926,8 @@ resource "azurerm_storage_blob" "test" { `, template, fileName) } -func testAccAzureRMStorageBlob_contentType(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_contentType(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -1012,8 +943,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_contentTypePremium(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_templatePremium(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_contentTypePremium(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_templatePremium(data, "private") return fmt.Sprintf(` %s @@ -1029,8 +960,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_contentTypeUpdated(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_contentTypeUpdated(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -1046,8 +977,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_pageEmpty(rInt int, rString string, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_pageEmpty(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -1062,8 +993,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_pageEmptyPremium(rInt int, rString string, location string) string { - template := testAccAzureRMStorageBlob_templatePremium(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_pageEmptyPremium(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_templatePremium(data, "private") return fmt.Sprintf(` %s @@ -1078,8 +1009,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_pageEmptyMetaData(rInt int, rString string, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_pageEmptyMetaData(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -1098,8 +1029,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_pageFromExistingBlob(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_pageFromExistingBlob(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -1125,8 +1056,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_pageFromLocalBlob(rInt int, rString, location, fileName string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_pageFromLocalBlob(data acceptance.TestData, fileName string) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -1173,8 +1104,8 @@ func testAccAzureRMStorageBlob_populateTempFile(input *os.File) error { return nil } -func testAccAzureRMStorageBlob_requiresImport(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_blockFromPublicBlob(rInt, rString, location) +func testAccAzureRMStorageBlob_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_blockFromPublicBlob(data) return fmt.Sprintf(` %s @@ -1189,8 +1120,8 @@ resource "azurerm_storage_blob" "import" { `, template) } -func testAccAzureRMStorageBlob_update(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_update(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -1209,8 +1140,8 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_updateUpdated(rInt int, rString, location string) string { - template := testAccAzureRMStorageBlob_template(rInt, rString, location, "private") +func testAccAzureRMStorageBlob_updateUpdated(data acceptance.TestData) string { + template := testAccAzureRMStorageBlob_template(data, "private") return fmt.Sprintf(` %s @@ -1230,7 +1161,7 @@ resource "azurerm_storage_blob" "test" { `, template) } -func testAccAzureRMStorageBlob_template(rInt int, rString, location, accessLevel string) string { +func testAccAzureRMStorageBlob_template(data acceptance.TestData, accessLevel string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1251,10 +1182,10 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "%s" } -`, rInt, location, rString, accessLevel) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, accessLevel) } -func testAccAzureRMStorageBlob_templateBlockBlobStorage(rInt int, rString, location, accessLevel string) string { +func testAccAzureRMStorageBlob_templateBlockBlobStorage(data acceptance.TestData, accessLevel string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1276,10 +1207,10 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "%s" } -`, rInt, location, rString, accessLevel) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, accessLevel) } -func testAccAzureRMStorageBlob_templatePremium(rInt int, rString, location, accessLevel string) string { +func testAccAzureRMStorageBlob_templatePremium(data acceptance.TestData, accessLevel string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1300,5 +1231,5 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "%s" } -`, rInt, location, rString, accessLevel) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, accessLevel) } diff --git a/azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go similarity index 91% rename from azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go index 21c2100ec091..322d890dc520 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go @@ -1,8 +1,9 @@ -package storage +package tests import ( "context" "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -61,7 +62,7 @@ func TestAccAzureRMStorageContainerMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := resourceStorageContainerMigrateState(tc.StateVersion, is, client) + is, err := storage.ResourceStorageContainerMigrateState(tc.StateVersion, is, client) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/resource_arm_storage_container_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_container_test.go similarity index 66% rename from azurerm/internal/services/storage/resource_arm_storage_container_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_container_test.go index 93d21845df80..af5512ad02de 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_container_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_container_test.go @@ -1,14 +1,12 @@ -package storage +package tests import ( "fmt" "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" @@ -17,11 +15,7 @@ import ( ) func TestAccAzureRMStorageContainer_basic(t *testing.T) { - resourceName := "azurerm_storage_container.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,16 +23,12 @@ func TestAccAzureRMStorageContainer_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageContainer_basic(ri, rs, location), + Config: testAccAzureRMStorageContainer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageContainerExists(resourceName), + testCheckAzureRMStorageContainerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -48,12 +38,7 @@ func TestAccAzureRMStorageContainer_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_storage_container.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -61,25 +46,18 @@ func TestAccAzureRMStorageContainer_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageContainer_basic(ri, rs, location), + Config: testAccAzureRMStorageContainer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageContainerExists(resourceName), + testCheckAzureRMStorageContainerExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStorageContainer_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_storage_container"), - }, + data.RequiresImportErrorStep(testAccAzureRMStorageContainer_requiresImport), }, }) } func TestAccAzureRMStorageContainer_update(t *testing.T) { - resourceName := "azurerm_storage_container.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,34 +65,26 @@ func TestAccAzureRMStorageContainer_update(t *testing.T) { CheckDestroy: testCheckAzureRMStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageContainer_update(ri, rs, location, "private"), + Config: testAccAzureRMStorageContainer_update(data, "private"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageContainerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "container_access_type", "private"), + testCheckAzureRMStorageContainerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "container_access_type", "private"), ), }, { - Config: testAccAzureRMStorageContainer_update(ri, rs, location, "container"), + Config: testAccAzureRMStorageContainer_update(data, "container"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageContainerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "container_access_type", "container"), + testCheckAzureRMStorageContainerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "container_access_type", "container"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageContainer_metaData(t *testing.T) { - resourceName := "azurerm_storage_container.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -122,47 +92,32 @@ func TestAccAzureRMStorageContainer_metaData(t *testing.T) { CheckDestroy: testCheckAzureRMStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageContainer_metaData(ri, rs, location), + Config: testAccAzureRMStorageContainer_metaData(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageContainerExists(resourceName), + testCheckAzureRMStorageContainerExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStorageContainer_metaDataUpdated(ri, rs, location), + Config: testAccAzureRMStorageContainer_metaDataUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageContainerExists(resourceName), + testCheckAzureRMStorageContainerExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStorageContainer_metaDataEmpty(ri, rs, location), + Config: testAccAzureRMStorageContainer_metaDataEmpty(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageContainerExists(resourceName), + testCheckAzureRMStorageContainerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageContainer_disappears(t *testing.T) { - resourceName := "azurerm_storage_container.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -170,10 +125,10 @@ func TestAccAzureRMStorageContainer_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageContainer_basic(ri, rs, location), + Config: testAccAzureRMStorageContainer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageContainerExists(resourceName), - testAccARMStorageContainerDisappears(resourceName), + testCheckAzureRMStorageContainerExists(data.ResourceName), + testAccARMStorageContainerDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -182,11 +137,7 @@ func TestAccAzureRMStorageContainer_disappears(t *testing.T) { } func TestAccAzureRMStorageContainer_root(t *testing.T) { - resourceName := "azurerm_storage_container.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -194,27 +145,19 @@ func TestAccAzureRMStorageContainer_root(t *testing.T) { CheckDestroy: testCheckAzureRMStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageContainer_root(ri, rs, location), + Config: testAccAzureRMStorageContainer_root(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageContainerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "$root"), + testCheckAzureRMStorageContainerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "$root"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageContainer_web(t *testing.T) { - resourceName := "azurerm_storage_container.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -222,17 +165,13 @@ func TestAccAzureRMStorageContainer_web(t *testing.T) { CheckDestroy: testCheckAzureRMStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageContainer_web(ri, rs, location), + Config: testAccAzureRMStorageContainer_web(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageContainerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "$web"), + testCheckAzureRMStorageContainerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "$web"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -346,8 +285,8 @@ func testCheckAzureRMStorageContainerDestroy(s *terraform.State) error { return nil } -func testAccAzureRMStorageContainer_basic(rInt int, rString string, location string) string { - template := testAccAzureRMStorageContainer_template(rInt, rString, location) +func testAccAzureRMStorageContainer_basic(data acceptance.TestData) string { + template := testAccAzureRMStorageContainer_template(data) return fmt.Sprintf(` %s @@ -360,8 +299,8 @@ resource "azurerm_storage_container" "test" { `, template) } -func testAccAzureRMStorageContainer_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStorageContainer_basic(rInt, rString, location) +func testAccAzureRMStorageContainer_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStorageContainer_basic(data) return fmt.Sprintf(` %s @@ -374,8 +313,8 @@ resource "azurerm_storage_container" "import" { `, template) } -func testAccAzureRMStorageContainer_update(rInt int, rString string, location string, accessType string) string { - template := testAccAzureRMStorageContainer_template(rInt, rString, location) +func testAccAzureRMStorageContainer_update(data acceptance.TestData, accessType string) string { + template := testAccAzureRMStorageContainer_template(data) return fmt.Sprintf(` %s @@ -388,8 +327,8 @@ resource "azurerm_storage_container" "test" { `, template, accessType) } -func testAccAzureRMStorageContainer_metaData(rInt int, rString string, location string) string { - template := testAccAzureRMStorageContainer_template(rInt, rString, location) +func testAccAzureRMStorageContainer_metaData(data acceptance.TestData) string { + template := testAccAzureRMStorageContainer_template(data) return fmt.Sprintf(` %s @@ -406,8 +345,8 @@ resource "azurerm_storage_container" "test" { `, template) } -func testAccAzureRMStorageContainer_metaDataUpdated(rInt int, rString string, location string) string { - template := testAccAzureRMStorageContainer_template(rInt, rString, location) +func testAccAzureRMStorageContainer_metaDataUpdated(data acceptance.TestData) string { + template := testAccAzureRMStorageContainer_template(data) return fmt.Sprintf(` %s @@ -425,8 +364,8 @@ resource "azurerm_storage_container" "test" { `, template) } -func testAccAzureRMStorageContainer_metaDataEmpty(rInt int, rString string, location string) string { - template := testAccAzureRMStorageContainer_template(rInt, rString, location) +func testAccAzureRMStorageContainer_metaDataEmpty(data acceptance.TestData) string { + template := testAccAzureRMStorageContainer_template(data) return fmt.Sprintf(` %s @@ -442,8 +381,8 @@ resource "azurerm_storage_container" "test" { `, template) } -func testAccAzureRMStorageContainer_root(rInt int, rString string, location string) string { - template := testAccAzureRMStorageContainer_template(rInt, rString, location) +func testAccAzureRMStorageContainer_root(data acceptance.TestData) string { + template := testAccAzureRMStorageContainer_template(data) return fmt.Sprintf(` %s @@ -456,8 +395,8 @@ resource "azurerm_storage_container" "test" { `, template) } -func testAccAzureRMStorageContainer_web(rInt int, rString string, location string) string { - template := testAccAzureRMStorageContainer_template(rInt, rString, location) +func testAccAzureRMStorageContainer_web(data acceptance.TestData) string { + template := testAccAzureRMStorageContainer_template(data) return fmt.Sprintf(` %s @@ -470,7 +409,7 @@ resource "azurerm_storage_container" "test" { `, template) } -func testAccAzureRMStorageContainer_template(rInt int, rString, location string) string { +func testAccAzureRMStorageContainer_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -488,7 +427,7 @@ resource "azurerm_storage_account" "test" { environment = "staging" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } func TestValidateArmStorageContainerName(t *testing.T) { diff --git a/azurerm/internal/services/storage/resource_arm_storage_data_lake_gen2_filesystem_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_data_lake_gen2_filesystem_test.go similarity index 68% rename from azurerm/internal/services/storage/resource_arm_storage_data_lake_gen2_filesystem_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_data_lake_gen2_filesystem_test.go index 1803d984affd..3d9d34336d98 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_data_lake_gen2_filesystem_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_data_lake_gen2_filesystem_test.go @@ -1,14 +1,11 @@ -package storage +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -17,11 +14,7 @@ import ( ) func TestAccAzureRMStorageDataLakeGen2FileSystem_basic(t *testing.T) { - resourceName := "azurerm_storage_data_lake_gen2_filesystem.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_data_lake_gen2_filesystem", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,16 +22,12 @@ func TestAccAzureRMStorageDataLakeGen2FileSystem_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStorageDataLakeGen2FileSystemDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageDataLakeGen2FileSystem_basic(ri, rs, location), + Config: testAccAzureRMStorageDataLakeGen2FileSystem_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageDataLakeGen2FileSystemExists(resourceName), + testCheckAzureRMStorageDataLakeGen2FileSystemExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -48,12 +37,7 @@ func TestAccAzureRMStorageDataLakeGen2FileSystem_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_storage_data_lake_gen2_filesystem.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_data_lake_gen2_filesystem", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -61,25 +45,18 @@ func TestAccAzureRMStorageDataLakeGen2FileSystem_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStorageDataLakeGen2FileSystemDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageDataLakeGen2FileSystem_basic(ri, rs, location), + Config: testAccAzureRMStorageDataLakeGen2FileSystem_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageDataLakeGen2FileSystemExists(resourceName), + testCheckAzureRMStorageDataLakeGen2FileSystemExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStorageDataLakeGen2FileSystem_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_storage_data_lake_gen2_filesystem"), - }, + data.RequiresImportErrorStep(testAccAzureRMStorageDataLakeGen2FileSystem_requiresImport), }, }) } func TestAccAzureRMStorageDataLakeGen2FileSystem_properties(t *testing.T) { - resourceName := "azurerm_storage_data_lake_gen2_filesystem.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_data_lake_gen2_filesystem", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,27 +64,19 @@ func TestAccAzureRMStorageDataLakeGen2FileSystem_properties(t *testing.T) { CheckDestroy: testCheckAzureRMStorageDataLakeGen2FileSystemDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageDataLakeGen2FileSystem_properties(ri, rs, location, "aGVsbG8="), + Config: testAccAzureRMStorageDataLakeGen2FileSystem_properties(data, "aGVsbG8="), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageDataLakeGen2FileSystemExists(resourceName), + testCheckAzureRMStorageDataLakeGen2FileSystemExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStorageDataLakeGen2FileSystem_properties(ri, rs, location, "ZXll"), + Config: testAccAzureRMStorageDataLakeGen2FileSystem_properties(data, "ZXll"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageDataLakeGen2FileSystemExists(resourceName), + testCheckAzureRMStorageDataLakeGen2FileSystemExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -167,8 +136,8 @@ func testCheckAzureRMStorageDataLakeGen2FileSystemDestroy(s *terraform.State) er return nil } -func testAccAzureRMStorageDataLakeGen2FileSystem_basic(rInt int, rString string, location string) string { - template := testAccAzureRMStorageDataLakeGen2FileSystem_template(rInt, rString, location) +func testAccAzureRMStorageDataLakeGen2FileSystem_basic(data acceptance.TestData) string { + template := testAccAzureRMStorageDataLakeGen2FileSystem_template(data) return fmt.Sprintf(` %s @@ -176,11 +145,11 @@ resource "azurerm_storage_data_lake_gen2_filesystem" "test" { name = "acctest-%d" storage_account_id = azurerm_storage_account.test.id } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStorageDataLakeGen2FileSystem_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStorageDataLakeGen2FileSystem_basic(rInt, rString, location) +func testAccAzureRMStorageDataLakeGen2FileSystem_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStorageDataLakeGen2FileSystem_basic(data) return fmt.Sprintf(` %s @@ -191,8 +160,8 @@ resource "azurerm_storage_data_lake_gen2_filesystem" "import" { `, template) } -func testAccAzureRMStorageDataLakeGen2FileSystem_properties(rInt int, rString, location, value string) string { - template := testAccAzureRMStorageDataLakeGen2FileSystem_template(rInt, rString, location) +func testAccAzureRMStorageDataLakeGen2FileSystem_properties(data acceptance.TestData, value string) string { + template := testAccAzureRMStorageDataLakeGen2FileSystem_template(data) return fmt.Sprintf(` %s @@ -204,10 +173,10 @@ resource "azurerm_storage_data_lake_gen2_filesystem" "test" { key = "%s" } } -`, template, rInt, value) +`, template, data.RandomInteger, value) } -func testAccAzureRMStorageDataLakeGen2FileSystem_template(rInt int, rString, location string) string { +func testAccAzureRMStorageDataLakeGen2FileSystem_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -222,5 +191,5 @@ resource "azurerm_storage_account" "test" { account_tier = "Standard" account_replication_type = "LRS" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_management_policy_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_management_policy_test.go new file mode 100644 index 000000000000..a815457d23d8 --- /dev/null +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_management_policy_test.go @@ -0,0 +1,423 @@ +package tests + +import ( + "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/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" +) + +func TestAccAzureRMStorageManagementPolicy_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_management_policy", "test") + config := testAccAzureRMStorageManagementPolicy_basic(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMStorageAccountManagementPolicyDestroy(), + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountManagementPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.name", "rule1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.prefix_match.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.prefix_match.3439697764", "container1/prefix1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.blob_types.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.blob_types.1068358194", "blockBlob"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.snapshot.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "30"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMStorageManagementPolicy_multipleRule(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_management_policy", "test") + config := testAccAzureRMStorageManagementPolicy_multipleRule(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMStorageAccountManagementPolicyDestroy(), + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountManagementPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "2"), + + // Rule1 + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.name", "rule1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.prefix_match.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.prefix_match.3439697764", "container1/prefix1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.blob_types.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.blob_types.1068358194", "blockBlob"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.snapshot.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "30"), + + // Rule2 + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.name", "rule2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.prefix_match.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.prefix_match.4102595489", "container2/prefix1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.prefix_match.1837232667", "container2/prefix2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.blob_types.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.blob_types.1068358194", "blockBlob"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "51"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "101"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.snapshot.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "31"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMStorageManagementPolicy_updateMultipleRule(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_storage_management_policy", "test") + config1 := testAccAzureRMStorageManagementPolicy_multipleRule(data) + config2 := testAccAzureRMStorageManagementPolicy_multipleRuleUpdated(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMStorageAccountManagementPolicyDestroy(), + Steps: []resource.TestStep{ + { + Config: config1, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountManagementPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "2"), + + // Rule1 + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.name", "rule1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.prefix_match.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.prefix_match.3439697764", "container1/prefix1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.blob_types.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.blob_types.1068358194", "blockBlob"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.snapshot.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "30"), + + // Rule2 + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.name", "rule2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.prefix_match.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.prefix_match.4102595489", "container2/prefix1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.prefix_match.1837232667", "container2/prefix2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.blob_types.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.blob_types.1068358194", "blockBlob"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "51"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "101"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.snapshot.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "31"), + ), + }, + data.ImportStep(), + { + Config: config2, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageAccountManagementPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "2"), + + // Rule1 + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.name", "rule1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.prefix_match.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.prefix_match.3439697764", "container1/prefix1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.blob_types.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.filters.0.blob_types.1068358194", "blockBlob"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.snapshot.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "30"), + + // Rule2 + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.name", "rule2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.enabled", "true"), // check updated + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.prefix_match.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.prefix_match.4102595489", "container2/prefix1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.prefix_match.1837232667", "container2/prefix2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.blob_types.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.filters.0.blob_types.1068358194", "blockBlob"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.0.tier_to_cool_after_days_since_modification_greater_than", "12"), // check updated + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.0.tier_to_archive_after_days_since_modification_greater_than", "52"), // check updated + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.base_blob.0.delete_after_days_since_modification_greater_than", "102"), // check updated + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.snapshot.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1.actions.0.snapshot.0.delete_after_days_since_creation_greater_than", "32"), // check updated + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMStorageAccountManagementPolicyDestroy() resource.TestCheckFunc { + return func(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_storage_management_policy" { + continue + } + storageAccountID := rs.Primary.Attributes["storage_account_id"] + + exists, err := testCheckAzureRMStorageAccountManagementPolicyExistsInternal(storageAccountID) + if err != nil { + return fmt.Errorf("Error checking if item has been destroyed: %s", err) + } + if exists { + return fmt.Errorf("Bad: Storage Account Management Policy '%q' still exists", storageAccountID) + } + } + + return nil + } +} + +func testCheckAzureRMStorageAccountManagementPolicyExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + storageAccountID := rs.Primary.Attributes["storage_account_id"] + + exists, err := testCheckAzureRMStorageAccountManagementPolicyExistsInternal(storageAccountID) + if err != nil { + return fmt.Errorf("Error checking if item exists: %s", err) + } + if !exists { + return fmt.Errorf("Bad: Storage Account Management Policy '%q' does not exist", storageAccountID) + } + + return nil + } +} + +func testCheckAzureRMStorageAccountManagementPolicyExistsInternal(storageAccountID string) (bool, error) { + rid, err := azure.ParseAzureResourceID(storageAccountID) + if err != nil { + return false, fmt.Errorf("Bad: Failed to parse ID (id: %s): %+v", storageAccountID, err) + } + + resourceGroupName := rid.ResourceGroup + storageAccountName := rid.Path["storageAccounts"] + + conn := acceptance.AzureProvider.Meta().(*clients.Client).Storage.ManagementPoliciesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + response, err := conn.Get(ctx, resourceGroupName, storageAccountName) + if err != nil { + if response.Response.IsHTTPStatus(404) { + return false, nil + } + return false, fmt.Errorf("Bad: Get on storageAccount ManagementPolicy client (id: %s): %+v", storageAccountID, err) + } + + return true, nil +} + +func testAccAzureRMStorageManagementPolicy_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "testrg" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "testsa" { + name = "unlikely23exst2acct%s" + resource_group_name = "${azurerm_resource_group.testrg.name}" + + location = "${azurerm_resource_group.testrg.location}" + account_tier = "Standard" + account_replication_type = "LRS" + account_kind = "BlobStorage" +} + +resource "azurerm_storage_management_policy" "testpolicy" { + storage_account_id = "${azurerm_storage_account.testsa.id}" + + rule { + name = "rule1" + enabled = true + filters { + prefix_match = ["container1/prefix1"] + blob_types = ["blockBlob"] + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 10 + tier_to_archive_after_days_since_modification_greater_than = 50 + delete_after_days_since_modification_greater_than = 100 + } + snapshot { + delete_after_days_since_creation_greater_than = 30 + } + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + +func testAccAzureRMStorageManagementPolicy_multipleRule(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "testrg" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "testsa" { + name = "unlikely23exst2acct%s" + resource_group_name = "${azurerm_resource_group.testrg.name}" + + location = "${azurerm_resource_group.testrg.location}" + account_tier = "Standard" + account_replication_type = "LRS" + account_kind = "BlobStorage" +} + +resource "azurerm_storage_management_policy" "testpolicy" { + storage_account_id = "${azurerm_storage_account.testsa.id}" + + rule { + name = "rule1" + enabled = true + filters { + prefix_match = ["container1/prefix1"] + blob_types = ["blockBlob"] + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 10 + tier_to_archive_after_days_since_modification_greater_than = 50 + delete_after_days_since_modification_greater_than = 100 + } + snapshot { + delete_after_days_since_creation_greater_than = 30 + } + } + } + rule { + name = "rule2" + enabled = false + filters { + prefix_match = ["container2/prefix1", "container2/prefix2"] + blob_types = ["blockBlob"] + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 11 + tier_to_archive_after_days_since_modification_greater_than = 51 + delete_after_days_since_modification_greater_than = 101 + } + snapshot { + delete_after_days_since_creation_greater_than = 31 + } + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} + +func testAccAzureRMStorageManagementPolicy_multipleRuleUpdated(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "testrg" { + name = "acctestRG-storage-%d" + location = "%s" +} + +resource "azurerm_storage_account" "testsa" { + name = "unlikely23exst2acct%s" + resource_group_name = "${azurerm_resource_group.testrg.name}" + + location = "${azurerm_resource_group.testrg.location}" + account_tier = "Standard" + account_replication_type = "LRS" + account_kind = "BlobStorage" +} + +resource "azurerm_storage_management_policy" "testpolicy" { + storage_account_id = "${azurerm_storage_account.testsa.id}" + + rule { + name = "rule1" + enabled = true + filters { + prefix_match = ["container1/prefix1"] + blob_types = ["blockBlob"] + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 10 + tier_to_archive_after_days_since_modification_greater_than = 50 + delete_after_days_since_modification_greater_than = 100 + } + snapshot { + delete_after_days_since_creation_greater_than = 30 + } + } + } + rule { + name = "rule2" + enabled = true + filters { + prefix_match = ["container2/prefix1", "container2/prefix2"] + blob_types = ["blockBlob"] + } + actions { + base_blob { + tier_to_cool_after_days_since_modification_greater_than = 12 + tier_to_archive_after_days_since_modification_greater_than = 52 + delete_after_days_since_modification_greater_than = 102 + } + snapshot { + delete_after_days_since_creation_greater_than = 32 + } + } + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} diff --git a/azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go similarity index 91% rename from azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go index eea7f691760f..20f9eff3afe0 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go @@ -1,8 +1,9 @@ -package storage +package tests import ( "context" "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -61,7 +62,7 @@ func TestAccAzureRMStorageQueueMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := resourceStorageQueueMigrateState(tc.StateVersion, is, client) + is, err := storage.ResourceStorageQueueMigrateState(tc.StateVersion, is, client) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/resource_arm_storage_queue_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go similarity index 71% rename from azurerm/internal/services/storage/resource_arm_storage_queue_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go index 772bdd975a7f..dc85b980ca6f 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_queue_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go @@ -1,14 +1,13 @@ -package storage +package tests import ( "fmt" - "strings" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -47,7 +46,7 @@ func TestResourceAzureRMStorageQueueName_Validation(t *testing.T) { } for _, tc := range cases { - _, errors := validateArmStorageQueueName(tc.Value, "azurerm_storage_queue") + _, errors := storage.ValidateArmStorageQueueName(tc.Value, "azurerm_storage_queue") if len(errors) != tc.ErrCount { t.Fatalf("Expected the ARM Storage Queue Name to trigger a validation error") @@ -56,10 +55,7 @@ func TestResourceAzureRMStorageQueueName_Validation(t *testing.T) { } func TestAccAzureRMStorageQueue_basic(t *testing.T) { - resourceName := "azurerm_storage_queue.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -67,16 +63,12 @@ func TestAccAzureRMStorageQueue_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStorageQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageQueue_basic(ri, rs, location), + Config: testAccAzureRMStorageQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageQueueExists(resourceName), + testCheckAzureRMStorageQueueExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -86,11 +78,7 @@ func TestAccAzureRMStorageQueue_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_storage_queue.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -98,24 +86,18 @@ func TestAccAzureRMStorageQueue_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStorageQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageQueue_basic(ri, rs, location), + Config: testAccAzureRMStorageQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageQueueExists(resourceName), + testCheckAzureRMStorageQueueExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStorageQueue_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_storage_queue"), - }, + data.RequiresImportErrorStep(testAccAzureRMStorageQueue_requiresImport), }, }) } func TestAccAzureRMStorageQueue_metaData(t *testing.T) { - resourceName := "azurerm_storage_queue.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -123,27 +105,19 @@ func TestAccAzureRMStorageQueue_metaData(t *testing.T) { CheckDestroy: testCheckAzureRMStorageQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageQueue_metaData(ri, rs, location), + Config: testAccAzureRMStorageQueue_metaData(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageQueueExists(resourceName), + testCheckAzureRMStorageQueueExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStorageQueue_metaDataUpdated(ri, rs, location), + Config: testAccAzureRMStorageQueue_metaDataUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageQueueExists(resourceName), + testCheckAzureRMStorageQueueExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -224,8 +198,8 @@ func testCheckAzureRMStorageQueueDestroy(s *terraform.State) error { return nil } -func testAccAzureRMStorageQueue_basic(rInt int, rString string, location string) string { - template := testAccAzureRMStorageQueue_template(rInt, rString, location) +func testAccAzureRMStorageQueue_basic(data acceptance.TestData) string { + template := testAccAzureRMStorageQueue_template(data) return fmt.Sprintf(` %s @@ -233,11 +207,11 @@ resource "azurerm_storage_queue" "test" { name = "mysamplequeue-%d" storage_account_name = "${azurerm_storage_account.test.name}" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStorageQueue_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStorageQueue_basic(rInt, rString, location) +func testAccAzureRMStorageQueue_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStorageQueue_basic(data) return fmt.Sprintf(` %s @@ -248,8 +222,8 @@ resource "azurerm_storage_queue" "import" { `, template) } -func testAccAzureRMStorageQueue_metaData(rInt int, rString string, location string) string { - template := testAccAzureRMStorageQueue_template(rInt, rString, location) +func testAccAzureRMStorageQueue_metaData(data acceptance.TestData) string { + template := testAccAzureRMStorageQueue_template(data) return fmt.Sprintf(` %s @@ -261,11 +235,11 @@ resource "azurerm_storage_queue" "test" { hello = "world" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStorageQueue_metaDataUpdated(rInt int, rString string, location string) string { - template := testAccAzureRMStorageQueue_template(rInt, rString, location) +func testAccAzureRMStorageQueue_metaDataUpdated(data acceptance.TestData) string { + template := testAccAzureRMStorageQueue_template(data) return fmt.Sprintf(` %s @@ -278,10 +252,10 @@ resource "azurerm_storage_queue" "test" { rick = "M0rty" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMStorageQueue_template(rInt int, rString string, location string) string { +func testAccAzureRMStorageQueue_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -300,5 +274,5 @@ resource "azurerm_storage_account" "test" { } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/storage/resource_arm_storage_share_directory_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go similarity index 67% rename from azurerm/internal/services/storage/resource_arm_storage_share_directory_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go index c7fc1f4d77b4..e4a61f2cc5e2 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_share_directory_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go @@ -1,25 +1,19 @@ -package storage +package tests import ( "fmt" "net/http" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStorageShareDirectory_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(5)) - location := acceptance.Location() - resourceName := "azurerm_storage_share_directory.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share_directory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,25 +21,18 @@ func TestAccAzureRMStorageShareDirectory_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDirectoryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShareDirectory_basic(ri, rs, location), + Config: testAccAzureRMStorageShareDirectory_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareDirectoryExists(resourceName), + testCheckAzureRMStorageShareDirectoryExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageShareDirectory_uppercase(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(5)) - location := acceptance.Location() - resourceName := "azurerm_storage_share_directory.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share_directory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,16 +40,12 @@ func TestAccAzureRMStorageShareDirectory_uppercase(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDirectoryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShareDirectory_uppercase(ri, rs, location), + Config: testAccAzureRMStorageShareDirectory_uppercase(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareDirectoryExists(resourceName), + testCheckAzureRMStorageShareDirectoryExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -72,11 +55,7 @@ func TestAccAzureRMStorageShareDirectory_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(5)) - location := acceptance.Location() - resourceName := "azurerm_storage_share_directory.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share_directory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,24 +63,18 @@ func TestAccAzureRMStorageShareDirectory_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDirectoryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShareDirectory_basic(ri, rs, location), + Config: testAccAzureRMStorageShareDirectory_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareDirectoryExists(resourceName), + testCheckAzureRMStorageShareDirectoryExists(data.ResourceName), ), }, - { - Config: testAccAzureRMStorageShareDirectory_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_storage_share_directory"), - }, + data.RequiresImportErrorStep(testAccAzureRMStorageShareDirectory_requiresImport), }, }) } func TestAccAzureRMStorageShareDirectory_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(5)) - location := acceptance.Location() - resourceName := "azurerm_storage_share_directory.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share_directory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -109,25 +82,18 @@ func TestAccAzureRMStorageShareDirectory_complete(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDirectoryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShareDirectory_complete(ri, rs, location), + Config: testAccAzureRMStorageShareDirectory_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareDirectoryExists(resourceName), + testCheckAzureRMStorageShareDirectoryExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageShareDirectory_update(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(5)) - location := acceptance.Location() - resourceName := "azurerm_storage_share_directory.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share_directory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -135,34 +101,24 @@ func TestAccAzureRMStorageShareDirectory_update(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDirectoryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShareDirectory_complete(ri, rs, location), + Config: testAccAzureRMStorageShareDirectory_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareDirectoryExists(resourceName), + testCheckAzureRMStorageShareDirectoryExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStorageShareDirectory_updated(ri, rs, location), + Config: testAccAzureRMStorageShareDirectory_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareDirectoryExists(resourceName), + testCheckAzureRMStorageShareDirectoryExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageShareDirectory_nested(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(5)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_share_directory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -170,7 +126,7 @@ func TestAccAzureRMStorageShareDirectory_nested(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDirectoryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShareDirectory_nested(ri, rs, location), + Config: testAccAzureRMStorageShareDirectory_nested(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMStorageShareDirectoryExists("azurerm_storage_share_directory.parent"), testCheckAzureRMStorageShareDirectoryExists("azurerm_storage_share_directory.child"), @@ -264,8 +220,8 @@ func testCheckAzureRMStorageShareDirectoryDestroy(s *terraform.State) error { return nil } -func testAccAzureRMStorageShareDirectory_basic(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShareDirectory_template(rInt, rString, location) +func testAccAzureRMStorageShareDirectory_basic(data acceptance.TestData) string { + template := testAccAzureRMStorageShareDirectory_template(data) return fmt.Sprintf(` %s @@ -277,8 +233,8 @@ resource "azurerm_storage_share_directory" "test" { `, template) } -func testAccAzureRMStorageShareDirectory_uppercase(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShareDirectory_template(rInt, rString, location) +func testAccAzureRMStorageShareDirectory_uppercase(data acceptance.TestData) string { + template := testAccAzureRMStorageShareDirectory_template(data) return fmt.Sprintf(` %s @@ -290,8 +246,8 @@ resource "azurerm_storage_share_directory" "test" { `, template) } -func testAccAzureRMStorageShareDirectory_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShareDirectory_basic(rInt, rString, location) +func testAccAzureRMStorageShareDirectory_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStorageShareDirectory_basic(data) return fmt.Sprintf(` %s @@ -303,8 +259,8 @@ resource "azurerm_storage_share_directory" "import" { `, template) } -func testAccAzureRMStorageShareDirectory_complete(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShareDirectory_template(rInt, rString, location) +func testAccAzureRMStorageShareDirectory_complete(data acceptance.TestData) string { + template := testAccAzureRMStorageShareDirectory_template(data) return fmt.Sprintf(` %s @@ -320,8 +276,8 @@ resource "azurerm_storage_share_directory" "test" { `, template) } -func testAccAzureRMStorageShareDirectory_updated(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShareDirectory_template(rInt, rString, location) +func testAccAzureRMStorageShareDirectory_updated(data acceptance.TestData) string { + template := testAccAzureRMStorageShareDirectory_template(data) return fmt.Sprintf(` %s @@ -338,8 +294,8 @@ resource "azurerm_storage_share_directory" "test" { `, template) } -func testAccAzureRMStorageShareDirectory_nested(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShareDirectory_template(rInt, rString, location) +func testAccAzureRMStorageShareDirectory_nested(data acceptance.TestData) string { + template := testAccAzureRMStorageShareDirectory_template(data) return fmt.Sprintf(` %s @@ -357,7 +313,7 @@ resource "azurerm_storage_share_directory" "child" { `, template) } -func testAccAzureRMStorageShareDirectory_template(rInt int, rString string, location string) string { +func testAccAzureRMStorageShareDirectory_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -377,5 +333,5 @@ resource "azurerm_storage_share" "test" { storage_account_name = "${azurerm_storage_account.test.name}" quota = 50 } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go similarity index 90% rename from azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go index 35a811e38925..469a10c28ede 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go @@ -1,7 +1,8 @@ -package storage +package tests import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "reflect" "testing" @@ -40,7 +41,7 @@ func TestAzureRMStorageShareMigrateStateV0ToV1(t *testing.T) { "quota": 5120, } - actual, err := resourceStorageShareStateUpgradeV0ToV1(input, meta) + actual, err := storage.ResourceStorageShareStateUpgradeV0ToV1(input, meta) if err != nil { t.Fatalf("Expected no error but got: %s", err) } @@ -84,7 +85,7 @@ func TestAzureRMStorageShareMigrateStateV1ToV2(t *testing.T) { "quota": 5120, } - actual, err := resourceStorageShareStateUpgradeV1ToV2(input, meta) + actual, err := storage.ResourceStorageShareStateUpgradeV1ToV2(input, meta) if err != nil { t.Fatalf("Expected no error but got: %s", err) } diff --git a/azurerm/internal/services/storage/resource_arm_storage_share_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_share_test.go similarity index 68% rename from azurerm/internal/services/storage/resource_arm_storage_share_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_share_test.go index be469a76a849..13f248b7b913 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_share_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_share_test.go @@ -1,24 +1,18 @@ -package storage +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMStorageShare_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - resourceName := "azurerm_storage_share.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,16 +20,12 @@ func TestAccAzureRMStorageShare_basic(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShare_basic(ri, rs, location), + Config: testAccAzureRMStorageShare_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareExists(resourceName), + testCheckAzureRMStorageShareExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,11 +35,7 @@ func TestAccAzureRMStorageShare_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - resourceName := "azurerm_storage_share.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,13 +43,13 @@ func TestAccAzureRMStorageShare_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShare_basic(ri, rs, location), + Config: testAccAzureRMStorageShare_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareExists(resourceName), + testCheckAzureRMStorageShareExists(data.ResourceName), ), }, { - Config: testAccAzureRMStorageShare_requiresImport(ri, rs, location), + Config: testAccAzureRMStorageShare_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_storage_share"), }, }, @@ -71,10 +57,7 @@ func TestAccAzureRMStorageShare_requiresImport(t *testing.T) { } func TestAccAzureRMStorageShare_disappears(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - resourceName := "azurerm_storage_share.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,10 +65,10 @@ func TestAccAzureRMStorageShare_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShare_basic(ri, rs, location), + Config: testAccAzureRMStorageShare_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareExists(resourceName), - testCheckAzureRMStorageShareDisappears(resourceName), + testCheckAzureRMStorageShareExists(data.ResourceName), + testCheckAzureRMStorageShareDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -94,10 +77,7 @@ func TestAccAzureRMStorageShare_disappears(t *testing.T) { } func TestAccAzureRMStorageShare_metaData(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - resourceName := "azurerm_storage_share.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -105,36 +85,25 @@ func TestAccAzureRMStorageShare_metaData(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShare_metaData(ri, rs, location), + Config: testAccAzureRMStorageShare_metaData(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareExists(resourceName), + testCheckAzureRMStorageShareExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStorageShare_metaDataUpdated(ri, rs, location), + Config: testAccAzureRMStorageShare_metaDataUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareExists(resourceName), + testCheckAzureRMStorageShareExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageShare_acl(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - resourceName := "azurerm_storage_share.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -142,36 +111,25 @@ func TestAccAzureRMStorageShare_acl(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShare_acl(ri, rs, location), + Config: testAccAzureRMStorageShare_acl(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareExists(resourceName), + testCheckAzureRMStorageShareExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStorageShare_aclUpdated(ri, rs, location), + Config: testAccAzureRMStorageShare_aclUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareExists(resourceName), + testCheckAzureRMStorageShareExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMStorageShare_updateQuota(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - resourceName := "azurerm_storage_share.test" + data := acceptance.BuildTestData(t, "azurerm_storage_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -179,16 +137,16 @@ func TestAccAzureRMStorageShare_updateQuota(t *testing.T) { CheckDestroy: testCheckAzureRMStorageShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageShare_basic(ri, rs, location), + Config: testAccAzureRMStorageShare_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareExists(resourceName), + testCheckAzureRMStorageShareExists(data.ResourceName), ), }, { - Config: testAccAzureRMStorageShare_updateQuota(ri, rs, location), + Config: testAccAzureRMStorageShare_updateQuota(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageShareExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "quota", "5"), + testCheckAzureRMStorageShareExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "quota", "5"), ), }, }, @@ -301,8 +259,8 @@ func testCheckAzureRMStorageShareDestroy(s *terraform.State) error { return nil } -func testAccAzureRMStorageShare_basic(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShare_template(rInt, rString, location) +func testAccAzureRMStorageShare_basic(data acceptance.TestData) string { + template := testAccAzureRMStorageShare_template(data) return fmt.Sprintf(` %s @@ -311,11 +269,11 @@ resource "azurerm_storage_share" "test" { resource_group_name = "${azurerm_resource_group.test.name}" storage_account_name = "${azurerm_storage_account.test.name}" } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMStorageShare_metaData(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShare_template(rInt, rString, location) +func testAccAzureRMStorageShare_metaData(data acceptance.TestData) string { + template := testAccAzureRMStorageShare_template(data) return fmt.Sprintf(` %s @@ -328,11 +286,11 @@ resource "azurerm_storage_share" "test" { hello = "world" } } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMStorageShare_metaDataUpdated(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShare_template(rInt, rString, location) +func testAccAzureRMStorageShare_metaDataUpdated(data acceptance.TestData) string { + template := testAccAzureRMStorageShare_template(data) return fmt.Sprintf(` %s @@ -346,11 +304,11 @@ resource "azurerm_storage_share" "test" { happy = "birthday" } } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMStorageShare_acl(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShare_template(rInt, rString, location) +func testAccAzureRMStorageShare_acl(data acceptance.TestData) string { + template := testAccAzureRMStorageShare_template(data) return fmt.Sprintf(` %s @@ -369,11 +327,11 @@ resource "azurerm_storage_share" "test" { } } } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMStorageShare_aclUpdated(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShare_template(rInt, rString, location) +func testAccAzureRMStorageShare_aclUpdated(data acceptance.TestData) string { + template := testAccAzureRMStorageShare_template(data) return fmt.Sprintf(` %s @@ -401,10 +359,10 @@ resource "azurerm_storage_share" "test" { } } } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMStorageShare_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShare_basic(rInt, rString, location) +func testAccAzureRMStorageShare_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStorageShare_basic(data) return fmt.Sprintf(` %s @@ -416,8 +374,8 @@ resource "azurerm_storage_share" "import" { `, template) } -func testAccAzureRMStorageShare_updateQuota(rInt int, rString string, location string) string { - template := testAccAzureRMStorageShare_template(rInt, rString, location) +func testAccAzureRMStorageShare_updateQuota(data acceptance.TestData) string { + template := testAccAzureRMStorageShare_template(data) return fmt.Sprintf(` %s @@ -427,10 +385,10 @@ resource "azurerm_storage_share" "test" { storage_account_name = "${azurerm_storage_account.test.name}" quota = 5 } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMStorageShare_template(rInt int, rString string, location string) string { +func testAccAzureRMStorageShare_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -448,5 +406,5 @@ resource "azurerm_storage_account" "test" { environment = "staging" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/storage/resource_arm_storage_table_entity_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go similarity index 74% rename from azurerm/internal/services/storage/resource_arm_storage_table_entity_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go index ea7278a5b29d..5b1911f4142d 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table_entity_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go @@ -1,15 +1,12 @@ -package storage +package tests import ( "fmt" "net/http" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -17,10 +14,7 @@ import ( ) func TestAccAzureRMTableEntity_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(5)) - location := acceptance.Location() - resourceName := "azurerm_storage_table_entity.test" + data := acceptance.BuildTestData(t, "azurerm_storage_table_entity", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -28,16 +22,12 @@ func TestAccAzureRMTableEntity_basic(t *testing.T) { CheckDestroy: testCheckAzureRMTableEntityDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTableEntity_basic(ri, rs, location), + Config: testAccAzureRMTableEntity_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTableEntityExists(resourceName), + testCheckAzureRMTableEntityExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,11 +37,7 @@ func TestAccAzureRMTableEntity_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(5)) - location := acceptance.Location() - resourceName := "azurerm_storage_table_entity.test" + data := acceptance.BuildTestData(t, "azurerm_storage_table_entity", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -59,13 +45,13 @@ func TestAccAzureRMTableEntity_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMTableEntityDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTableEntity_basic(ri, rs, location), + Config: testAccAzureRMTableEntity_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTableEntityExists(resourceName), + testCheckAzureRMTableEntityExists(data.ResourceName), ), }, { - Config: testAccAzureRMTableEntity_requiresImport(ri, rs, location), + Config: testAccAzureRMTableEntity_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_storage_table_entity"), }, }, @@ -73,10 +59,7 @@ func TestAccAzureRMTableEntity_requiresImport(t *testing.T) { } func TestAccAzureRMTableEntity_update(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(5)) - location := acceptance.Location() - resourceName := "azurerm_storage_table_entity.test" + data := acceptance.BuildTestData(t, "azurerm_storage_table_entity", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,27 +67,19 @@ func TestAccAzureRMTableEntity_update(t *testing.T) { CheckDestroy: testCheckAzureRMTableEntityDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMTableEntity_basic(ri, rs, location), + Config: testAccAzureRMTableEntity_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTableEntityExists(resourceName), + testCheckAzureRMTableEntityExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMTableEntity_updated(ri, rs, location), + Config: testAccAzureRMTableEntity_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMTableEntityExists(resourceName), + testCheckAzureRMTableEntityExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -202,8 +177,8 @@ func testCheckAzureRMTableEntityDestroy(s *terraform.State) error { return nil } -func testAccAzureRMTableEntity_basic(rInt int, rString string, location string) string { - template := testAccAzureRMTableEntity_template(rInt, rString, location) +func testAccAzureRMTableEntity_basic(data acceptance.TestData) string { + template := testAccAzureRMTableEntity_template(data) return fmt.Sprintf(` %s @@ -217,11 +192,11 @@ resource "azurerm_storage_table_entity" "test" { Foo = "Bar" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTableEntity_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMTableEntity_basic(rInt, rString, location) +func testAccAzureRMTableEntity_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMTableEntity_basic(data) return fmt.Sprintf(` %s @@ -235,11 +210,11 @@ resource "azurerm_storage_table_entity" "test" { Foo = "Bar" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTableEntity_updated(rInt int, rString string, location string) string { - template := testAccAzureRMTableEntity_template(rInt, rString, location) +func testAccAzureRMTableEntity_updated(data acceptance.TestData) string { + template := testAccAzureRMTableEntity_template(data) return fmt.Sprintf(` %s @@ -254,10 +229,10 @@ resource "azurerm_storage_table_entity" "test" { Test = "Updated" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMTableEntity_template(rInt int, rString string, location string) string { +func testAccAzureRMTableEntity_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -277,5 +252,5 @@ resource "azurerm_storage_table" "test" { resource_group_name = "${azurerm_resource_group.test.name}" storage_account_name = "${azurerm_storage_account.test.name}" } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go similarity index 99% rename from azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go index f24b171aa7f9..0075ac1604e2 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go @@ -1,4 +1,4 @@ -package storage +package tests import ( "fmt" diff --git a/azurerm/internal/services/storage/resource_arm_storage_table_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go similarity index 81% rename from azurerm/internal/services/storage/resource_arm_storage_table_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go index 8b9f7017664e..79ce2e3fec54 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go @@ -1,14 +1,13 @@ -package storage +package tests import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,11 +15,8 @@ import ( ) func TestAccAzureRMStorageTable_basic(t *testing.T) { - resourceName := "azurerm_storage_table.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMStorageTable_basic(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_storage_table", "test") + config := testAccAzureRMStorageTable_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -30,14 +26,10 @@ func TestAccAzureRMStorageTable_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageTableExists(resourceName), + testCheckAzureRMStorageTableExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,12 +39,7 @@ func TestAccAzureRMStorageTable_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_storage_table.test" - - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_storage_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -60,13 +47,13 @@ func TestAccAzureRMStorageTable_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMStorageTableDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageTable_basic(ri, rs, location), + Config: testAccAzureRMStorageTable_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageTableExists(resourceName), + testCheckAzureRMStorageTableExists(data.ResourceName), ), }, { - Config: testAccAzureRMStorageTable_requiresImport(ri, rs, location), + Config: testAccAzureRMStorageTable_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_storage_table"), }, }, @@ -74,9 +61,8 @@ func TestAccAzureRMStorageTable_requiresImport(t *testing.T) { } func TestAccAzureRMStorageTable_disappears(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMStorageTable_basic(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_storage_table", "test") + config := testAccAzureRMStorageTable_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -96,10 +82,7 @@ func TestAccAzureRMStorageTable_disappears(t *testing.T) { } func TestAccAzureRMStorageTable_acl(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - resourceName := "azurerm_storage_table.test" + data := acceptance.BuildTestData(t, "azurerm_storage_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -107,27 +90,19 @@ func TestAccAzureRMStorageTable_acl(t *testing.T) { CheckDestroy: testCheckAzureRMStorageTableDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMStorageTable_acl(ri, rs, location), + Config: testAccAzureRMStorageTable_acl(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageTableExists(resourceName), + testCheckAzureRMStorageTableExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMStorageTable_aclUpdated(ri, rs, location), + Config: testAccAzureRMStorageTable_aclUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMStorageTableExists(resourceName), + testCheckAzureRMStorageTableExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -260,7 +235,7 @@ func TestValidateArmStorageTableName(t *testing.T) { strings.Repeat("w", 63), } for _, v := range validNames { - _, errors := validateArmStorageTableName(v, "name") + _, errors := storage.ValidateArmStorageTableName(v, "name") if len(errors) != 0 { t.Fatalf("%q should be a valid Storage Table Name: %q", v, errors) } @@ -275,14 +250,14 @@ func TestValidateArmStorageTableName(t *testing.T) { strings.Repeat("w", 64), } for _, v := range invalidNames { - _, errors := validateArmStorageTableName(v, "name") + _, errors := storage.ValidateArmStorageTableName(v, "name") if len(errors) == 0 { t.Fatalf("%q should be an invalid Storage Table Name", v) } } } -func testAccAzureRMStorageTable_basic(rInt int, rString string, location string) string { +func testAccAzureRMStorageTable_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -306,11 +281,11 @@ resource "azurerm_storage_table" "test" { resource_group_name = "${azurerm_resource_group.test.name}" storage_account_name = "${azurerm_storage_account.test.name}" } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMStorageTable_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMStorageTable_basic(rInt, rString, location) +func testAccAzureRMStorageTable_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMStorageTable_basic(data) return fmt.Sprintf(` %s @@ -322,7 +297,7 @@ resource "azurerm_storage_table" "import" { `, template) } -func testAccAzureRMStorageTable_acl(rInt int, rString string, location string) string { +func testAccAzureRMStorageTable_acl(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -355,10 +330,10 @@ resource "azurerm_storage_table" "test" { } } } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMStorageTable_aclUpdated(rInt int, rString string, location string) string { +func testAccAzureRMStorageTable_aclUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -401,5 +376,5 @@ resource "azurerm_storage_table" "test" { } } } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/storage/validation_test.go b/azurerm/internal/services/storage/tests/validation_test.go similarity index 67% rename from azurerm/internal/services/storage/validation_test.go rename to azurerm/internal/services/storage/tests/validation_test.go index 5bfcf02b09a4..66f2de217d7b 100644 --- a/azurerm/internal/services/storage/validation_test.go +++ b/azurerm/internal/services/storage/tests/validation_test.go @@ -1,6 +1,7 @@ -package storage +package tests import ( + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "strings" "testing" ) @@ -11,7 +12,7 @@ func TestValidateArmStorageShareName(t *testing.T) { "valid02-name", } for _, v := range validNames { - _, errors := ValidateArmStorageShareName(v, "name") + _, errors := storage.ValidateArmStorageShareName(v, "name") if len(errors) != 0 { t.Fatalf("%q should be a valid Share Name: %q", v, errors) } @@ -27,7 +28,7 @@ func TestValidateArmStorageShareName(t *testing.T) { strings.Repeat("w", 65), } for _, v := range invalidNames { - if _, errors := ValidateArmStorageShareName(v, "name"); len(errors) == 0 { + if _, errors := storage.ValidateArmStorageShareName(v, "name"); len(errors) == 0 { t.Fatalf("%q should be an invalid Share Name", v) } } From 52489d3a3bbf62adc789c16726c375252226a909 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Fri, 20 Dec 2019 18:27:32 -0800 Subject: [PATCH 103/203] sql --- .../sql/data_source_sql_database_test.go | 127 ----------- .../resource_arm_sql_virtual_network_rule.go | 4 +- .../tests/data_source_sql_database_test.go | 121 ++++++++++ .../data_source_sql_server_test.go | 24 +- .../resource_arm_sql_administrator_test.go | 54 ++--- .../resource_arm_sql_database_test.go | 209 ++++++++---------- .../resource_arm_sql_elasticpool_test.go | 69 +++--- .../resource_arm_sql_failover_group_test.go | 70 +++--- .../resource_arm_sql_firewall_rule_test.go | 65 +++--- .../resource_arm_sql_server_test.go | 105 ++++----- ...ource_arm_sql_virtual_network_rule_test.go | 118 +++++----- .../{ => tests}/testdata/sql_import.bacpac | Bin 12 files changed, 434 insertions(+), 532 deletions(-) delete mode 100644 azurerm/internal/services/sql/data_source_sql_database_test.go create mode 100644 azurerm/internal/services/sql/tests/data_source_sql_database_test.go rename azurerm/internal/services/sql/{ => tests}/data_source_sql_server_test.go (52%) rename azurerm/internal/services/sql/{ => tests}/resource_arm_sql_administrator_test.go (78%) rename azurerm/internal/services/sql/{ => tests}/resource_arm_sql_database_test.go (78%) rename azurerm/internal/services/sql/{ => tests}/resource_arm_sql_elasticpool_test.go (77%) rename azurerm/internal/services/sql/{ => tests}/resource_arm_sql_failover_group_test.go (83%) rename azurerm/internal/services/sql/{ => tests}/resource_arm_sql_firewall_rule_test.go (75%) rename azurerm/internal/services/sql/{ => tests}/resource_arm_sql_server_test.go (73%) rename azurerm/internal/services/sql/{ => tests}/resource_arm_sql_virtual_network_rule_test.go (85%) rename azurerm/internal/services/sql/{ => tests}/testdata/sql_import.bacpac (100%) diff --git a/azurerm/internal/services/sql/data_source_sql_database_test.go b/azurerm/internal/services/sql/data_source_sql_database_test.go deleted file mode 100644 index 2db52455675b..000000000000 --- a/azurerm/internal/services/sql/data_source_sql_database_test.go +++ /dev/null @@ -1,127 +0,0 @@ -package sql - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMSqlDatabase_basic(t *testing.T) { - dataSourceName := "data.azurerm_sql_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMSqlDatabase_basic(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "collation"), - resource.TestCheckResourceAttrSet(dataSourceName, "edition"), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "read_scale"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "server_name"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMSqlDatabase_elasticPool(t *testing.T) { - dataSourceName := "data.azurerm_sql_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMSqlDatabase_elasticPool(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "elastic_pool_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "server_name"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMSqlDatabase_readScale(t *testing.T) { - dataSourceName := "data.azurerm_sql_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMSqlDatabase_readScale(ri, location, true), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "read_scale", "true"), - resource.TestCheckResourceAttrSet(dataSourceName, "server_name"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMSqlDatabase_basic(rInt int, location string) string { - template := testAccAzureRMSqlDatabase_basic(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_sql_database" "test" { - name = "${azurerm_sql_database.test.name}" - server_name = "${azurerm_sql_database.test.server_name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, template) -} - -func testAccDataSourceAzureRMSqlDatabase_elasticPool(rInt int, location string) string { - template := testAccAzureRMSqlDatabase_elasticPool(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_sql_database" "test" { - name = "${azurerm_sql_database.test.name}" - server_name = "${azurerm_sql_database.test.server_name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, template) -} - -func testAccDataSourceAzureRMSqlDatabase_readScale(rInt int, location string, readScale bool) string { - template := testAccAzureRMSqlDatabase_readScale(rInt, location, readScale) - return fmt.Sprintf(` -%s - -data "azurerm_sql_database" "test" { - name = "${azurerm_sql_database.test.name}" - server_name = "${azurerm_sql_database.test.server_name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, template) -} diff --git a/azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule.go b/azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule.go index 33681083dbc0..1028dfccf391 100644 --- a/azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule.go +++ b/azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule.go @@ -42,7 +42,7 @@ func resourceArmSqlVirtualNetworkRule() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateSqlVirtualNetworkRuleName, + ValidateFunc: ValidateSqlVirtualNetworkRuleName, }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -212,7 +212,7 @@ func resourceArmSqlVirtualNetworkRuleDelete(d *schema.ResourceData, meta interfa This function checks the format of the SQL Virtual Network Rule Name to make sure that it does not contain any potentially invalid values. */ -func validateSqlVirtualNetworkRuleName(v interface{}, k string) (warnings []string, errors []error) { +func ValidateSqlVirtualNetworkRuleName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) // Cannot be empty diff --git a/azurerm/internal/services/sql/tests/data_source_sql_database_test.go b/azurerm/internal/services/sql/tests/data_source_sql_database_test.go new file mode 100644 index 000000000000..e7f72236cf67 --- /dev/null +++ b/azurerm/internal/services/sql/tests/data_source_sql_database_test.go @@ -0,0 +1,121 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMSqlDatabase_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_sql_database", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMSqlDatabase_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "collation"), + resource.TestCheckResourceAttrSet(data.ResourceName, "edition"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "read_scale"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMSqlDatabase_elasticPool(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_sql_database", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMSqlDatabase_elasticPool(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "elastic_pool_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_name"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMSqlDatabase_readScale(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_sql_database", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMSqlDatabase_readScale(data, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "read_scale", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_name"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMSqlDatabase_basic(data acceptance.TestData) string { + template := testAccAzureRMSqlDatabase_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_sql_database" "test" { + name = "${azurerm_sql_database.test.name}" + server_name = "${azurerm_sql_database.test.server_name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template) +} + +func testAccDataSourceAzureRMSqlDatabase_elasticPool(data acceptance.TestData) string { + template := testAccAzureRMSqlDatabase_elasticPool(data) + return fmt.Sprintf(` +%s + +data "azurerm_sql_database" "test" { + name = "${azurerm_sql_database.test.name}" + server_name = "${azurerm_sql_database.test.server_name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template) +} + +func testAccDataSourceAzureRMSqlDatabase_readScale(data acceptance.TestData, readScale bool) string { + template := testAccAzureRMSqlDatabase_readScale(data, readScale) + return fmt.Sprintf(` +%s + +data "azurerm_sql_database" "test" { + name = "${azurerm_sql_database.test.name}" + server_name = "${azurerm_sql_database.test.server_name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template) +} diff --git a/azurerm/internal/services/sql/data_source_sql_server_test.go b/azurerm/internal/services/sql/tests/data_source_sql_server_test.go similarity index 52% rename from azurerm/internal/services/sql/data_source_sql_server_test.go rename to azurerm/internal/services/sql/tests/data_source_sql_server_test.go index 2d2d7cd00cc9..901f353e875f 100644 --- a/azurerm/internal/services/sql/data_source_sql_server_test.go +++ b/azurerm/internal/services/sql/tests/data_source_sql_server_test.go @@ -1,4 +1,4 @@ -package sql +package tests import ( "fmt" @@ -10,9 +10,7 @@ import ( ) func TestAccDataSourceAzureRMSqlServer_basic(t *testing.T) { - dataSourceName := "data.azurerm_sql_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_sql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,22 +18,22 @@ func TestAccDataSourceAzureRMSqlServer_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSqlServerDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSqlServer_basic(ri, location), + Config: testAccDataSourceAzureRMSqlServer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlServerExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "fqdn"), - resource.TestCheckResourceAttrSet(dataSourceName, "version"), - resource.TestCheckResourceAttrSet(dataSourceName, "administrator_login"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + testCheckAzureRMSqlServerExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), + resource.TestCheckResourceAttrSet(data.ResourceName, "version"), + resource.TestCheckResourceAttrSet(data.ResourceName, "administrator_login"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, }) } -func testAccDataSourceAzureRMSqlServer_basic(rInt int, location string) string { - template := testAccAzureRMSqlServer_basic(rInt, location) +func testAccDataSourceAzureRMSqlServer_basic(data acceptance.TestData) string { + template := testAccAzureRMSqlServer_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/sql/resource_arm_sql_administrator_test.go b/azurerm/internal/services/sql/tests/resource_arm_sql_administrator_test.go similarity index 78% rename from azurerm/internal/services/sql/resource_arm_sql_administrator_test.go rename to azurerm/internal/services/sql/tests/resource_arm_sql_administrator_test.go index 3d075fff9231..59f87b82efdb 100644 --- a/azurerm/internal/services/sql/resource_arm_sql_administrator_test.go +++ b/azurerm/internal/services/sql/tests/resource_arm_sql_administrator_test.go @@ -1,4 +1,4 @@ -package sql +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMSqlAdministrator_basic(t *testing.T) { - resourceName := "azurerm_sql_active_directory_administrator.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_active_directory_administrator", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,22 +21,18 @@ func TestAccAzureRMSqlAdministrator_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSqlAdministratorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlAdministrator_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlAdministrator_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlAdministratorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "login", "sqladmin"), + testCheckAzureRMSqlAdministratorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "login", "sqladmin"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMSqlAdministrator_withUpdates(ri, acceptance.Location()), + Config: testAccAzureRMSqlAdministrator_withUpdates(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlAdministratorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "login", "sqladmin2"), + testCheckAzureRMSqlAdministratorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "login", "sqladmin2"), ), }, }, @@ -49,8 +43,7 @@ func TestAccAzureRMSqlAdministrator_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_sql_active_directory_administrator.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_active_directory_administrator", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -58,14 +51,14 @@ func TestAccAzureRMSqlAdministrator_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSqlAdministratorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlAdministrator_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlAdministrator_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlAdministratorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "login", "sqladmin"), + testCheckAzureRMSqlAdministratorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "login", "sqladmin"), ), }, { - Config: testAccAzureRMSqlAdministrator_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMSqlAdministrator_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_sql_active_directory_administrator"), }, }, @@ -73,9 +66,8 @@ func TestAccAzureRMSqlAdministrator_requiresImport(t *testing.T) { } func TestAccAzureRMSqlAdministrator_disappears(t *testing.T) { - resourceName := "azurerm_sql_active_directory_administrator.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSqlAdministrator_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_sql_active_directory_administrator", "test") + config := testAccAzureRMSqlAdministrator_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -85,8 +77,8 @@ func TestAccAzureRMSqlAdministrator_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlAdministratorExists(resourceName), - testCheckAzureRMSqlAdministratorDisappears(resourceName), + testCheckAzureRMSqlAdministratorExists(data.ResourceName), + testCheckAzureRMSqlAdministratorDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -160,7 +152,7 @@ func testCheckAzureRMSqlAdministratorDestroy(s *terraform.State) error { return nil } -func testAccAzureRMSqlAdministrator_basic(rInt int, location string) string { +func testAccAzureRMSqlAdministrator_basic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -188,7 +180,7 @@ resource "azurerm_sql_active_directory_administrator" "test" { `, rInt, location, rInt) } -func testAccAzureRMSqlAdministrator_requiresImport(rInt int, location string) string { +func testAccAzureRMSqlAdministrator_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -199,10 +191,10 @@ resource "azurerm_sql_active_directory_administrator" "import" { tenant_id = "${azurerm_sql_active_directory_administrator.test.tenant_id}" object_id = "${azurerm_sql_active_directory_administrator.test.object_id}" } -`, testAccAzureRMSqlAdministrator_basic(rInt, location)) +`, testAccAzureRMSqlAdministrator_basic(data)) } -func testAccAzureRMSqlAdministrator_withUpdates(rInt int, location string) string { +func testAccAzureRMSqlAdministrator_withUpdates(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -227,5 +219,5 @@ resource "azurerm_sql_active_directory_administrator" "test" { tenant_id = "${data.azurerm_client_config.current.tenant_id}" object_id = "${data.azurerm_client_config.current.client_id}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/sql/resource_arm_sql_database_test.go b/azurerm/internal/services/sql/tests/resource_arm_sql_database_test.go similarity index 78% rename from azurerm/internal/services/sql/resource_arm_sql_database_test.go rename to azurerm/internal/services/sql/tests/resource_arm_sql_database_test.go index 1eac5af96115..97679a96b46f 100644 --- a/azurerm/internal/services/sql/resource_arm_sql_database_test.go +++ b/azurerm/internal/services/sql/tests/resource_arm_sql_database_test.go @@ -1,4 +1,4 @@ -package sql +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +14,7 @@ import ( ) func TestAccAzureRMSqlDatabase_basic(t *testing.T) { - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +22,13 @@ func TestAccAzureRMSqlDatabase_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlDatabase_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlDatabase_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"create_mode"}, @@ -43,8 +41,7 @@ func TestAccAzureRMSqlDatabase_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,13 +49,13 @@ func TestAccAzureRMSqlDatabase_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlDatabase_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlDatabase_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), ), }, { - Config: testAccAzureRMSqlDatabase_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMSqlDatabase_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_sql_database"), }, }, @@ -66,8 +63,7 @@ func TestAccAzureRMSqlDatabase_requiresImport(t *testing.T) { } func TestAccAzureRMSqlDatabase_disappears(t *testing.T) { - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -75,10 +71,10 @@ func TestAccAzureRMSqlDatabase_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlDatabase_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlDatabase_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - testCheckAzureRMSqlDatabaseDisappears(resourceName), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + testCheckAzureRMSqlDatabaseDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -87,8 +83,7 @@ func TestAccAzureRMSqlDatabase_disappears(t *testing.T) { } func TestAccAzureRMSqlDatabase_elasticPool(t *testing.T) { - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -96,28 +91,21 @@ func TestAccAzureRMSqlDatabase_elasticPool(t *testing.T) { CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlDatabase_elasticPool(ri, acceptance.Location()), + Config: testAccAzureRMSqlDatabase_elasticPool(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "elastic_pool_name", fmt.Sprintf("acctestep%d", ri)), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "elastic_pool_name", fmt.Sprintf("acctestep%d", data.RandomInteger)), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"create_mode"}, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSqlDatabase_withTags(t *testing.T) { - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMSqlDatabase_withTags(ri, location) - postConfig := testAccAzureRMSqlDatabase_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") + preConfig := testAccAzureRMSqlDatabase_withTags(data) + postConfig := testAccAzureRMSqlDatabase_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -127,15 +115,15 @@ func TestAccAzureRMSqlDatabase_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, }, @@ -143,8 +131,7 @@ func TestAccAzureRMSqlDatabase_withTags(t *testing.T) { } func TestAccAzureRMSqlDatabase_dataWarehouse(t *testing.T) { - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -152,13 +139,13 @@ func TestAccAzureRMSqlDatabase_dataWarehouse(t *testing.T) { CheckDestroy: testCheckAzureRMSqlDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlDatabase_dataWarehouse(ri, acceptance.Location()), + Config: testAccAzureRMSqlDatabase_dataWarehouse(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"create_mode"}, @@ -168,13 +155,11 @@ func TestAccAzureRMSqlDatabase_dataWarehouse(t *testing.T) { } func TestAccAzureRMSqlDatabase_restorePointInTime(t *testing.T) { - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMSqlDatabase_basic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") + preConfig := testAccAzureRMSqlDatabase_basic(data) timeToRestore := time.Now().Add(15 * time.Minute) formattedTime := timeToRestore.UTC().Format(time.RFC3339) - postCongif := testAccAzureRMSqlDatabase_restorePointInTime(ri, formattedTime, acceptance.Location()) + postCongif := testAccAzureRMSqlDatabase_restorePointInTime(data, formattedTime) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -185,14 +170,14 @@ func TestAccAzureRMSqlDatabase_restorePointInTime(t *testing.T) { Config: preConfig, PreventPostDestroyRefresh: true, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), ), }, { PreConfig: func() { time.Sleep(timeToRestore.Sub(time.Now().Add(-1 * time.Minute))) }, Config: postCongif, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), testCheckAzureRMSqlDatabaseExists("azurerm_sql_database.test_restore"), ), }, @@ -201,11 +186,9 @@ func TestAccAzureRMSqlDatabase_restorePointInTime(t *testing.T) { } func TestAccAzureRMSqlDatabase_collation(t *testing.T) { - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMSqlDatabase_basic(ri, location) - postConfig := testAccAzureRMSqlDatabase_collationUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") + preConfig := testAccAzureRMSqlDatabase_basic(data) + postConfig := testAccAzureRMSqlDatabase_collationUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -215,15 +198,15 @@ func TestAccAzureRMSqlDatabase_collation(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "collation", "SQL_Latin1_General_CP1_CI_AS"), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "collation", "SQL_Latin1_General_CP1_CI_AS"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "collation", "Japanese_Bushu_Kakusu_100_CS_AS_KS_WS"), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "collation", "Japanese_Bushu_Kakusu_100_CS_AS_KS_WS"), ), }, }, @@ -231,11 +214,9 @@ func TestAccAzureRMSqlDatabase_collation(t *testing.T) { } func TestAccAzureRMSqlDatabase_requestedServiceObjectiveName(t *testing.T) { - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMSqlDatabase_requestedServiceObjectiveName(ri, location, "S0") - postConfig := testAccAzureRMSqlDatabase_requestedServiceObjectiveName(ri, location, "S1") + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") + preConfig := testAccAzureRMSqlDatabase_requestedServiceObjectiveName(data, "S0") + postConfig := testAccAzureRMSqlDatabase_requestedServiceObjectiveName(data, "S1") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -245,15 +226,15 @@ func TestAccAzureRMSqlDatabase_requestedServiceObjectiveName(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "requested_service_objective_name", "S0"), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "requested_service_objective_name", "S0"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "requested_service_objective_name", "S1"), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "requested_service_objective_name", "S1"), ), }, }, @@ -261,11 +242,9 @@ func TestAccAzureRMSqlDatabase_requestedServiceObjectiveName(t *testing.T) { } func TestAccAzureRMSqlDatabase_threatDetectionPolicy(t *testing.T) { - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMSqlDatabase_threatDetectionPolicy(ri, location, "Enabled") - postConfig := testAccAzureRMSqlDatabase_threatDetectionPolicy(ri, location, "Disabled") + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") + preConfig := testAccAzureRMSqlDatabase_threatDetectionPolicy(data, "Enabled") + postConfig := testAccAzureRMSqlDatabase_threatDetectionPolicy(data, "Disabled") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -275,16 +254,16 @@ func TestAccAzureRMSqlDatabase_threatDetectionPolicy(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "threat_detection_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "threat_detection_policy.0.state", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "threat_detection_policy.0.retention_days", "15"), - resource.TestCheckResourceAttr(resourceName, "threat_detection_policy.0.disabled_alerts.#", "1"), - resource.TestCheckResourceAttr(resourceName, "threat_detection_policy.0.email_account_admins", "Enabled"), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "threat_detection_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "threat_detection_policy.0.state", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "threat_detection_policy.0.retention_days", "15"), + resource.TestCheckResourceAttr(data.ResourceName, "threat_detection_policy.0.disabled_alerts.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "threat_detection_policy.0.email_account_admins", "Enabled"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"create_mode", "threat_detection_policy.0.storage_account_access_key"}, @@ -292,9 +271,9 @@ func TestAccAzureRMSqlDatabase_threatDetectionPolicy(t *testing.T) { { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "threat_detection_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "threat_detection_policy.0.state", "Disabled"), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "threat_detection_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "threat_detection_policy.0.state", "Disabled"), ), }, }, @@ -302,11 +281,9 @@ func TestAccAzureRMSqlDatabase_threatDetectionPolicy(t *testing.T) { } func TestAccAzureRMSqlDatabase_readScale(t *testing.T) { - resourceName := "azurerm_sql_database.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMSqlDatabase_readScale(ri, location, true) - postConfig := testAccAzureRMSqlDatabase_readScale(ri, location, false) + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") + preConfig := testAccAzureRMSqlDatabase_readScale(data, true) + postConfig := testAccAzureRMSqlDatabase_readScale(data, false) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -316,15 +293,15 @@ func TestAccAzureRMSqlDatabase_readScale(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "read_scale", "true"), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "read_scale", "true"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "read_scale", "false"), + testCheckAzureRMSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "read_scale", "false"), ), }, }, @@ -410,8 +387,8 @@ func testCheckAzureRMSqlDatabaseDisappears(resourceName string) resource.TestChe } func TestAccAzureRMSqlDatabase_bacpac(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMSqlDatabase_bacpac(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_sql_database", "test") + config := testAccAzureRMSqlDatabase_bacpac(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -428,7 +405,7 @@ func TestAccAzureRMSqlDatabase_bacpac(t *testing.T) { }) } -func testAccAzureRMSqlDatabase_basic(rInt int, location string) string { +func testAccAzureRMSqlDatabase_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -454,10 +431,10 @@ resource "azurerm_sql_database" "test" { max_size_bytes = "1073741824" requested_service_objective_name = "S0" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSqlDatabase_requiresImport(rInt int, location string) string { +func testAccAzureRMSqlDatabase_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -471,10 +448,10 @@ resource "azurerm_sql_database" "import" { max_size_bytes = "${azurerm_sql_database.test.max_size_bytes}" requested_service_objective_name = "${azurerm_sql_database.test.requested_service_objective_name}" } -`, testAccAzureRMSqlDatabase_basic(rInt, location)) +`, testAccAzureRMSqlDatabase_basic(data)) } -func testAccAzureRMSqlDatabase_withTags(rInt int, location string) string { +func testAccAzureRMSqlDatabase_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -505,10 +482,10 @@ resource "azurerm_sql_database" "test" { database = "test" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSqlDatabase_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMSqlDatabase_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -538,10 +515,10 @@ resource "azurerm_sql_database" "test" { environment = "production" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSqlDatabase_dataWarehouse(rInt int, location string) string { +func testAccAzureRMSqlDatabase_dataWarehouse(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest_rg_%d" @@ -566,10 +543,10 @@ resource "azurerm_sql_database" "test" { collation = "SQL_Latin1_General_CP1_CI_AS" requested_service_objective_name = "DW400" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSqlDatabase_restorePointInTime(rInt int, formattedTime string, location string) string { +func testAccAzureRMSqlDatabase_restorePointInTime(data acceptance.TestData, formattedTime string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -605,10 +582,10 @@ resource "azurerm_sql_database" "test_restore" { source_database_id = "${azurerm_sql_database.test.id}" restore_point_in_time = "%s" } -`, rInt, location, rInt, rInt, rInt, formattedTime) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, formattedTime) } -func testAccAzureRMSqlDatabase_elasticPool(rInt int, location string) string { +func testAccAzureRMSqlDatabase_elasticPool(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -645,10 +622,10 @@ resource "azurerm_sql_database" "test" { elastic_pool_name = "${azurerm_sql_elasticpool.test.name}" requested_service_objective_name = "ElasticPool" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSqlDatabase_collationUpdate(rInt int, location string) string { +func testAccAzureRMSqlDatabase_collationUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -674,10 +651,10 @@ resource "azurerm_sql_database" "test" { max_size_bytes = "1073741824" requested_service_objective_name = "S0" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSqlDatabase_bacpac(rInt int, location string) string { +func testAccAzureRMSqlDatabase_bacpac(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG_%d" @@ -744,10 +721,10 @@ resource "azurerm_sql_database" "test" { authentication_type = "SQL" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSqlDatabase_requestedServiceObjectiveName(rInt int, location, requestedServiceObjectiveName string) string { +func testAccAzureRMSqlDatabase_requestedServiceObjectiveName(data acceptance.TestData, requestedServiceObjectiveName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -773,10 +750,10 @@ resource "azurerm_sql_database" "test" { max_size_bytes = "1073741824" requested_service_objective_name = %q } -`, rInt, location, rInt, rInt, requestedServiceObjectiveName) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, requestedServiceObjectiveName) } -func testAccAzureRMSqlDatabase_threatDetectionPolicy(rInt int, location, state string) string { +func testAccAzureRMSqlDatabase_threatDetectionPolicy(data acceptance.TestData, state string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -819,10 +796,10 @@ resource "azurerm_sql_database" "test" { use_server_default = "Disabled" } } -`, rInt, location, rInt, rInt, rInt, state) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, state) } -func testAccAzureRMSqlDatabase_readScale(rInt int, location string, readScale bool) string { +func testAccAzureRMSqlDatabase_readScale(data acceptance.TestData, readScale bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "readscaletestRG-%d" @@ -848,5 +825,5 @@ resource "azurerm_sql_database" "test" { max_size_bytes = "1073741824" read_scale = %t } -`, rInt, location, rInt, rInt, readScale) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, readScale) } diff --git a/azurerm/internal/services/sql/resource_arm_sql_elasticpool_test.go b/azurerm/internal/services/sql/tests/resource_arm_sql_elasticpool_test.go similarity index 77% rename from azurerm/internal/services/sql/resource_arm_sql_elasticpool_test.go rename to azurerm/internal/services/sql/tests/resource_arm_sql_elasticpool_test.go index 356cf3b755f4..eae91d940c31 100644 --- a/azurerm/internal/services/sql/resource_arm_sql_elasticpool_test.go +++ b/azurerm/internal/services/sql/tests/resource_arm_sql_elasticpool_test.go @@ -1,4 +1,4 @@ -package sql +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMSqlElasticPool_basic(t *testing.T) { - resourceName := "azurerm_sql_elasticpool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_elasticpool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,16 +21,12 @@ func TestAccAzureRMSqlElasticPool_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSqlElasticPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlElasticPool_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlElasticPool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlElasticPoolExists(resourceName), + testCheckAzureRMSqlElasticPoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -41,8 +35,7 @@ func TestAccAzureRMSqlElasticPool_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_sql_elasticpool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_elasticpool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,22 +43,18 @@ func TestAccAzureRMSqlElasticPool_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSqlElasticPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlElasticPool_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlElasticPool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlElasticPoolExists(resourceName), + testCheckAzureRMSqlElasticPoolExists(data.ResourceName), ), }, - { - Config: testAccAzureRMSqlElasticPool_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_sql_elasticpool"), - }, + data.RequiresImportErrorStep(testAccAzureRMSqlElasticPool_requiresImport), }, }) } func TestAccAzureRMSqlElasticPool_disappears(t *testing.T) { - resourceName := "azurerm_sql_elasticpool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_elasticpool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -73,10 +62,10 @@ func TestAccAzureRMSqlElasticPool_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMSqlElasticPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlElasticPool_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlElasticPool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlElasticPoolExists(resourceName), - testCheckAzureRMSqlElasticPoolDisappears(resourceName), + testCheckAzureRMSqlElasticPoolExists(data.ResourceName), + testCheckAzureRMSqlElasticPoolDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -85,11 +74,9 @@ func TestAccAzureRMSqlElasticPool_disappears(t *testing.T) { } func TestAccAzureRMSqlElasticPool_resizeDtu(t *testing.T) { - resourceName := "azurerm_sql_elasticpool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMSqlElasticPool_basic(ri, location) - postConfig := testAccAzureRMSqlElasticPool_resizedDtu(ri, location) + data := acceptance.BuildTestData(t, "azurerm_sql_elasticpool", "test") + preConfig := testAccAzureRMSqlElasticPool_basic(data) + postConfig := testAccAzureRMSqlElasticPool_resizedDtu(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -99,17 +86,17 @@ func TestAccAzureRMSqlElasticPool_resizeDtu(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "dtu", "50"), - resource.TestCheckResourceAttr(resourceName, "pool_size", "5000"), + testCheckAzureRMSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "dtu", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "pool_size", "5000"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "dtu", "100"), - resource.TestCheckResourceAttr(resourceName, "pool_size", "10000"), + testCheckAzureRMSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "dtu", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "pool_size", "10000"), ), }, }, @@ -193,7 +180,7 @@ func testCheckAzureRMSqlElasticPoolDisappears(resourceName string) resource.Test } } -func testAccAzureRMSqlElasticPool_basic(rInt int, location string) string { +func testAccAzureRMSqlElasticPool_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-%[1]d" @@ -218,10 +205,10 @@ resource "azurerm_sql_elasticpool" "test" { dtu = 50 pool_size = 5000 } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMSqlElasticPool_requiresImport(rInt int, location string) string { +func testAccAzureRMSqlElasticPool_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -234,10 +221,10 @@ resource "azurerm_sql_elasticpool" "import" { dtu = "${azurerm_sql_elasticpool.test.dtu}" pool_size = "${azurerm_sql_elasticpool.test.pool_size}" } -`, testAccAzureRMSqlElasticPool_basic(rInt, location)) +`, testAccAzureRMSqlElasticPool_basic(data)) } -func testAccAzureRMSqlElasticPool_resizedDtu(rInt int, location string) string { +func testAccAzureRMSqlElasticPool_resizedDtu(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-%[1]d" @@ -262,5 +249,5 @@ resource "azurerm_sql_elasticpool" "test" { dtu = 100 pool_size = 10000 } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/sql/resource_arm_sql_failover_group_test.go b/azurerm/internal/services/sql/tests/resource_arm_sql_failover_group_test.go similarity index 83% rename from azurerm/internal/services/sql/resource_arm_sql_failover_group_test.go rename to azurerm/internal/services/sql/tests/resource_arm_sql_failover_group_test.go index d4e695e17326..4605354fdeb8 100644 --- a/azurerm/internal/services/sql/resource_arm_sql_failover_group_test.go +++ b/azurerm/internal/services/sql/tests/resource_arm_sql_failover_group_test.go @@ -1,4 +1,4 @@ -package sql +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMSqlFailoverGroup_basic(t *testing.T) { - resourceName := "azurerm_sql_failover_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_failover_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,16 +21,12 @@ func TestAccAzureRMSqlFailoverGroup_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSqlFailoverGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlFailoverGroup_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMSqlFailoverGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlFailoverGroupExists(resourceName), + testCheckAzureRMSqlFailoverGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -42,8 +36,7 @@ func TestAccAzureRMSqlFailoverGroup_requiresImport(t *testing.T) { t.Skip("Skiiping since resources aren't required to be imported") return } - resourceName := "azurerm_sql_failover_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_failover_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,22 +44,18 @@ func TestAccAzureRMSqlFailoverGroup_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSqlFailoverGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlFailoverGroup_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMSqlFailoverGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlFailoverGroupExists(resourceName), + testCheckAzureRMSqlFailoverGroupExists(data.ResourceName), ), }, - { - Config: testAccAzureRMSqlFailoverGroup_requiresImport(ri, acceptance.Location(), acceptance.AltLocation()), - ExpectError: acceptance.RequiresImportError("azurerm_sql_failover_group"), - }, + data.RequiresImportErrorStep(testAccAzureRMSqlFailoverGroup_requiresImport), }, }) } func TestAccAzureRMSqlFailoverGroup_disappears(t *testing.T) { - resourceName := "azurerm_sql_failover_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_failover_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,10 +63,10 @@ func TestAccAzureRMSqlFailoverGroup_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMSqlFailoverGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlFailoverGroup_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMSqlFailoverGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlFailoverGroupExists(resourceName), - testCheckAzureRMSqlFailoverGroupDisappears(resourceName), + testCheckAzureRMSqlFailoverGroupExists(data.ResourceName), + testCheckAzureRMSqlFailoverGroupDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -86,12 +75,9 @@ func TestAccAzureRMSqlFailoverGroup_disappears(t *testing.T) { } func TestAccAzureRMSqlFailoverGroup_withTags(t *testing.T) { - resourceName := "azurerm_sql_failover_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - altLocation := acceptance.AltLocation() - preConfig := testAccAzureRMSqlFailoverGroup_withTags(ri, location, altLocation) - postConfig := testAccAzureRMSqlFailoverGroup_withTagsUpdate(ri, location, altLocation) + data := acceptance.BuildTestData(t, "azurerm_sql_failover_group", "test") + preConfig := testAccAzureRMSqlFailoverGroup_withTags(data) + postConfig := testAccAzureRMSqlFailoverGroup_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -101,15 +87,15 @@ func TestAccAzureRMSqlFailoverGroup_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlFailoverGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMSqlFailoverGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlFailoverGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMSqlFailoverGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, }, @@ -198,7 +184,7 @@ func testCheckAzureRMSqlFailoverGroupDestroy(s *terraform.State) error { return nil } -func testAccAzureRMSqlFailoverGroup_basic(rInt int, location, altlocation string) string { +func testAccAzureRMSqlFailoverGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -249,10 +235,10 @@ resource "azurerm_sql_failover_group" "test" { grace_minutes = 60 } } -`, rInt, location, altlocation) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) } -func testAccAzureRMSqlFailoverGroup_requiresImport(rInt int, location, altlocation string) string { +func testAccAzureRMSqlFailoverGroup_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -271,10 +257,10 @@ resource "azurerm_sql_failover_group" "import" { grace_minutes = "${azurerm_sql_failover_group.test.read_write_endpoint_failover_policy.0.grace_minutes}" } } -`, testAccAzureRMSqlFailoverGroup_basic(rInt, location, altlocation)) +`, testAccAzureRMSqlFailoverGroup_basic(data)) } -func testAccAzureRMSqlFailoverGroup_withTags(rInt int, location, altlocation string) string { +func testAccAzureRMSqlFailoverGroup_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -328,10 +314,10 @@ resource "azurerm_sql_failover_group" "test" { database = "test" } } -`, rInt, location, altlocation) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) } -func testAccAzureRMSqlFailoverGroup_withTagsUpdate(rInt int, location, altlocation string) string { +func testAccAzureRMSqlFailoverGroup_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -384,5 +370,5 @@ resource "azurerm_sql_failover_group" "test" { environment = "production" } } -`, rInt, location, altlocation) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) } diff --git a/azurerm/internal/services/sql/resource_arm_sql_firewall_rule_test.go b/azurerm/internal/services/sql/tests/resource_arm_sql_firewall_rule_test.go similarity index 75% rename from azurerm/internal/services/sql/resource_arm_sql_firewall_rule_test.go rename to azurerm/internal/services/sql/tests/resource_arm_sql_firewall_rule_test.go index 9d40a5063b6c..3641d2d50f25 100644 --- a/azurerm/internal/services/sql/resource_arm_sql_firewall_rule_test.go +++ b/azurerm/internal/services/sql/tests/resource_arm_sql_firewall_rule_test.go @@ -1,4 +1,4 @@ -package sql +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMSqlFirewallRule_basic(t *testing.T) { - resourceName := "azurerm_sql_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,24 +21,20 @@ func TestAccAzureRMSqlFirewallRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSqlFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", "0.0.0.0"), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", "255.255.255.255"), + testCheckAzureRMSqlFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", "0.0.0.0"), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", "255.255.255.255"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMSqlFirewallRule_withUpdates(ri, acceptance.Location()), + Config: testAccAzureRMSqlFirewallRule_withUpdates(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", "10.0.17.62"), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", "10.0.17.62"), + testCheckAzureRMSqlFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", "10.0.17.62"), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", "10.0.17.62"), ), }, }, @@ -51,8 +45,7 @@ func TestAccAzureRMSqlFirewallRule_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_sql_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -60,24 +53,20 @@ func TestAccAzureRMSqlFirewallRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSqlFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", "0.0.0.0"), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", "255.255.255.255"), + testCheckAzureRMSqlFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", "0.0.0.0"), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", "255.255.255.255"), ), }, - { - Config: testAccAzureRMSqlFirewallRule_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_sql_firewall_rule"), - }, + data.RequiresImportErrorStep(testAccAzureRMSqlFirewallRule_requiresImport), }, }) } func TestAccAzureRMSqlFirewallRule_disappears(t *testing.T) { - resourceName := "azurerm_sql_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -85,10 +74,10 @@ func TestAccAzureRMSqlFirewallRule_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMSqlFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlFirewallRuleExists(resourceName), - testCheckAzureRMSqlFirewallRuleDisappears(resourceName), + testCheckAzureRMSqlFirewallRuleExists(data.ResourceName), + testCheckAzureRMSqlFirewallRuleDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -179,7 +168,7 @@ func testCheckAzureRMSqlFirewallRuleDisappears(resourceName string) resource.Tes } } -func testAccAzureRMSqlFirewallRule_basic(rInt int, location string) string { +func testAccAzureRMSqlFirewallRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -202,10 +191,10 @@ resource "azurerm_sql_firewall_rule" "test" { start_ip_address = "0.0.0.0" end_ip_address = "255.255.255.255" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSqlFirewallRule_requiresImport(rInt int, location string) string { +func testAccAzureRMSqlFirewallRule_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -216,10 +205,10 @@ resource "azurerm_sql_firewall_rule" "import" { start_ip_address = "${azurerm_sql_firewall_rule.test.start_ip_address}" end_ip_address = "${azurerm_sql_firewall_rule.test.end_ip_address}" } -`, testAccAzureRMSqlFirewallRule_basic(rInt, location)) +`, testAccAzureRMSqlFirewallRule_basic(data)) } -func testAccAzureRMSqlFirewallRule_withUpdates(rInt int, location string) string { +func testAccAzureRMSqlFirewallRule_withUpdates(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -242,5 +231,5 @@ resource "azurerm_sql_firewall_rule" "test" { start_ip_address = "10.0.17.62" end_ip_address = "10.0.17.62" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/sql/resource_arm_sql_server_test.go b/azurerm/internal/services/sql/tests/resource_arm_sql_server_test.go similarity index 73% rename from azurerm/internal/services/sql/resource_arm_sql_server_test.go rename to azurerm/internal/services/sql/tests/resource_arm_sql_server_test.go index 64c9f62a09c8..4b19850fed90 100644 --- a/azurerm/internal/services/sql/resource_arm_sql_server_test.go +++ b/azurerm/internal/services/sql/tests/resource_arm_sql_server_test.go @@ -1,4 +1,4 @@ -package sql +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" @@ -15,8 +14,7 @@ import ( ) func TestAccAzureRMSqlServer_basic(t *testing.T) { - resourceName := "azurerm_sql_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +22,13 @@ func TestAccAzureRMSqlServer_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSqlServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlServer_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlServer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlServerExists(resourceName), + testCheckAzureRMSqlServerExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"administrator_login_password"}, @@ -43,8 +41,7 @@ func TestAccAzureRMSqlServer_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_sql_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,23 +49,19 @@ func TestAccAzureRMSqlServer_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSqlServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlServer_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlServer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlServerExists(resourceName), + testCheckAzureRMSqlServerExists(data.ResourceName), ), }, - { - Config: testAccAzureRMSqlServer_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_sql_server"), - }, + data.RequiresImportErrorStep(testAccAzureRMSqlServer_requiresImport), }, }) } func TestAccAzureRMSqlServer_disappears(t *testing.T) { - resourceName := "azurerm_sql_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSqlServer_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_sql_server", "test") + config := testAccAzureRMSqlServer_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,8 +71,8 @@ func TestAccAzureRMSqlServer_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlServerExists(resourceName), - testCheckAzureRMSqlServerDisappears(resourceName), + testCheckAzureRMSqlServerExists(data.ResourceName), + testCheckAzureRMSqlServerDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -88,11 +81,9 @@ func TestAccAzureRMSqlServer_disappears(t *testing.T) { } func TestAccAzureRMSqlServer_withTags(t *testing.T) { - resourceName := "azurerm_sql_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMSqlServer_withTags(ri, location) - postConfig := testAccAzureRMSqlServer_withTagsUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_sql_server", "test") + preConfig := testAccAzureRMSqlServer_withTags(data) + postConfig := testAccAzureRMSqlServer_withTagsUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -102,19 +93,19 @@ func TestAccAzureRMSqlServer_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMSqlServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMSqlServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"administrator_login_password"}, @@ -124,8 +115,7 @@ func TestAccAzureRMSqlServer_withTags(t *testing.T) { } func TestAccAzureRMSqlServer_withIdentity(t *testing.T) { - resourceName := "azurerm_sql_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -133,16 +123,16 @@ func TestAccAzureRMSqlServer_withIdentity(t *testing.T) { CheckDestroy: testCheckAzureRMSqlServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlServer_withIdentity(ri, acceptance.Location()), + Config: testAccAzureRMSqlServer_withIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMSqlServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"administrator_login_password"}, @@ -152,8 +142,7 @@ func TestAccAzureRMSqlServer_withIdentity(t *testing.T) { } func TestAccAzureRMSqlServer_updateWithIdentityAdded(t *testing.T) { - resourceName := "azurerm_sql_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -161,22 +150,22 @@ func TestAccAzureRMSqlServer_updateWithIdentityAdded(t *testing.T) { CheckDestroy: testCheckAzureRMSqlServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlServer_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlServer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlServerExists(resourceName), + testCheckAzureRMSqlServerExists(data.ResourceName), ), }, { - Config: testAccAzureRMSqlServer_withIdentity(ri, acceptance.Location()), + Config: testAccAzureRMSqlServer_withIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "identity.0.tenant_id", validate.UUIDRegExp), + testCheckAzureRMSqlServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.tenant_id", validate.UUIDRegExp), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"administrator_login_password"}, @@ -264,7 +253,7 @@ func testCheckAzureRMSqlServerDisappears(resourceName string) resource.TestCheck } } -func testAccAzureRMSqlServer_basic(rInt int, location string) string { +func testAccAzureRMSqlServer_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -279,10 +268,10 @@ resource "azurerm_sql_server" "test" { administrator_login = "mradministrator" administrator_login_password = "thisIsDog11" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMSqlServer_requiresImport(rInt int, location string) string { +func testAccAzureRMSqlServer_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -294,10 +283,10 @@ resource "azurerm_sql_server" "import" { administrator_login = "${azurerm_sql_server.test.administrator_login}" administrator_login_password = "${azurerm_sql_server.test.administrator_login_password}" } -`, testAccAzureRMSqlServer_basic(rInt, location)) +`, testAccAzureRMSqlServer_basic(data)) } -func testAccAzureRMSqlServer_withTags(rInt int, location string) string { +func testAccAzureRMSqlServer_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -317,10 +306,10 @@ resource "azurerm_sql_server" "test" { database = "test" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMSqlServer_withTagsUpdated(rInt int, location string) string { +func testAccAzureRMSqlServer_withTagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -339,10 +328,10 @@ resource "azurerm_sql_server" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMSqlServer_withIdentity(rInt int, location string) string { +func testAccAzureRMSqlServer_withIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -361,5 +350,5 @@ resource "azurerm_sql_server" "test" { type = "SystemAssigned" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule_test.go b/azurerm/internal/services/sql/tests/resource_arm_sql_virtual_network_rule_test.go similarity index 85% rename from azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule_test.go rename to azurerm/internal/services/sql/tests/resource_arm_sql_virtual_network_rule_test.go index b824ae51b72d..7a9fbbb0efd1 100644 --- a/azurerm/internal/services/sql/resource_arm_sql_virtual_network_rule_test.go +++ b/azurerm/internal/services/sql/tests/resource_arm_sql_virtual_network_rule_test.go @@ -1,7 +1,8 @@ -package sql +package tests import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/sql" "regexp" "testing" @@ -9,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -22,8 +22,7 @@ import ( validate that new property is set correctly. */ func TestAccAzureRMSqlVirtualNetworkRule_basic(t *testing.T) { - resourceName := "azurerm_sql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_virtual_network_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -31,22 +30,18 @@ func TestAccAzureRMSqlVirtualNetworkRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSqlVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlVirtualNetworkRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlVirtualNetworkRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlVirtualNetworkRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ignore_missing_vnet_service_endpoint", "false"), + testCheckAzureRMSqlVirtualNetworkRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ignore_missing_vnet_service_endpoint", "false"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMSqlVirtualNetworkRule_withUpdates(ri, acceptance.Location()), + Config: testAccAzureRMSqlVirtualNetworkRule_withUpdates(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlVirtualNetworkRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ignore_missing_vnet_service_endpoint", "true"), + testCheckAzureRMSqlVirtualNetworkRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ignore_missing_vnet_service_endpoint", "true"), ), }, }, @@ -58,8 +53,7 @@ func TestAccAzureRMSqlVirtualNetworkRule_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_sql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_virtual_network_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -67,14 +61,14 @@ func TestAccAzureRMSqlVirtualNetworkRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSqlVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSqlVirtualNetworkRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMSqlVirtualNetworkRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlVirtualNetworkRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ignore_missing_vnet_service_endpoint", "false"), + testCheckAzureRMSqlVirtualNetworkRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ignore_missing_vnet_service_endpoint", "false"), ), }, { - Config: testAccAzureRMSqlVirtualNetworkRule_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMSqlVirtualNetworkRule_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_sql_virtual_network_rule"), }, }, @@ -87,15 +81,14 @@ func TestAccAzureRMSqlVirtualNetworkRule_requiresImport(t *testing.T) { validate that new subnet is set correctly. */ func TestAccAzureRMSqlVirtualNetworkRule_switchSubnets(t *testing.T) { - resourceName := "azurerm_sql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_sql_virtual_network_rule", "test") - preConfig := testAccAzureRMSqlVirtualNetworkRule_subnetSwitchPre(ri, acceptance.Location()) - postConfig := testAccAzureRMSqlVirtualNetworkRule_subnetSwitchPost(ri, acceptance.Location()) + preConfig := testAccAzureRMSqlVirtualNetworkRule_subnetSwitchPre(data) + postConfig := testAccAzureRMSqlVirtualNetworkRule_subnetSwitchPost(data) // Create regex strings that will ensure that one subnet name exists, but not the other - preConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet1%d)$|(subnet[^2]%d)$", ri, ri)) //subnet 1 but not 2 - postConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet2%d)$|(subnet[^1]%d)$", ri, ri)) //subnet 2 but not 1 + preConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet1%d)$|(subnet[^2]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 1 but not 2 + postConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet2%d)$|(subnet[^1]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 2 but not 1 resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -105,15 +98,15 @@ func TestAccAzureRMSqlVirtualNetworkRule_switchSubnets(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlVirtualNetworkRuleExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "subnet_id", preConfigRegex), + testCheckAzureRMSqlVirtualNetworkRuleExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "subnet_id", preConfigRegex), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlVirtualNetworkRuleExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "subnet_id", postConfigRegex), + testCheckAzureRMSqlVirtualNetworkRuleExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "subnet_id", postConfigRegex), ), }, }, @@ -124,9 +117,8 @@ func TestAccAzureRMSqlVirtualNetworkRule_switchSubnets(t *testing.T) { ---Testing for Success--- */ func TestAccAzureRMSqlVirtualNetworkRule_disappears(t *testing.T) { - resourceName := "azurerm_sql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSqlVirtualNetworkRule_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_sql_virtual_network_rule", "test") + config := testAccAzureRMSqlVirtualNetworkRule_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -136,8 +128,8 @@ func TestAccAzureRMSqlVirtualNetworkRule_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlVirtualNetworkRuleExists(resourceName), - testCheckAzureRMSqlVirtualNetworkRuleDisappears(resourceName), + testCheckAzureRMSqlVirtualNetworkRuleExists(data.ResourceName), + testCheckAzureRMSqlVirtualNetworkRuleDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -151,9 +143,8 @@ func TestAccAzureRMSqlVirtualNetworkRule_disappears(t *testing.T) { is still applied since the endpoint validation will be set to false. */ func TestAccAzureRMSqlVirtualNetworkRule_IgnoreEndpointValid(t *testing.T) { - resourceName := "azurerm_sql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSqlVirtualNetworkRule_ignoreEndpointValid(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_sql_virtual_network_rule", "test") + config := testAccAzureRMSqlVirtualNetworkRule_ignoreEndpointValid(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -163,7 +154,7 @@ func TestAccAzureRMSqlVirtualNetworkRule_IgnoreEndpointValid(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlVirtualNetworkRuleExists(resourceName), + testCheckAzureRMSqlVirtualNetworkRuleExists(data.ResourceName), ), }, }, @@ -176,8 +167,8 @@ func TestAccAzureRMSqlVirtualNetworkRule_IgnoreEndpointValid(t *testing.T) { is still applied since the endpoint validation will be set to false. */ func TestAccAzureRMSqlVirtualNetworkRule_IgnoreEndpointInvalid(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMSqlVirtualNetworkRule_ignoreEndpointInvalid(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_sql_virtual_network_rule", "test") + config := testAccAzureRMSqlVirtualNetworkRule_ignoreEndpointInvalid(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -198,11 +189,10 @@ func TestAccAzureRMSqlVirtualNetworkRule_IgnoreEndpointInvalid(t *testing.T) { SQL server. */ func TestAccAzureRMSqlVirtualNetworkRule_multipleSubnets(t *testing.T) { - resourceName1 := "azurerm_sql_virtual_network_rule.rule1" + data := acceptance.BuildTestData(t, "azurerm_sql_virtual_network_rule", "test") resourceName2 := "azurerm_sql_virtual_network_rule.rule2" resourceName3 := "azurerm_sql_virtual_network_rule.rule3" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSqlVirtualNetworkRule_multipleSubnets(ri, acceptance.Location()) + config := testAccAzureRMSqlVirtualNetworkRule_multipleSubnets(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -212,7 +202,7 @@ func TestAccAzureRMSqlVirtualNetworkRule_multipleSubnets(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSqlVirtualNetworkRuleExists(resourceName1), + testCheckAzureRMSqlVirtualNetworkRuleExists(data.ResourceName), testCheckAzureRMSqlVirtualNetworkRuleExists(resourceName2), testCheckAzureRMSqlVirtualNetworkRuleExists(resourceName3), ), @@ -274,7 +264,7 @@ func TestResourceAzureRMSqlVirtualNetworkRule_invalidNameValidation(t *testing.T } for _, tc := range cases { - _, errors := validateSqlVirtualNetworkRuleName(tc.Value, "azurerm_sql_virtual_network_rule") + _, errors := sql.ValidateSqlVirtualNetworkRuleName(tc.Value, "azurerm_sql_virtual_network_rule") if len(errors) != tc.ErrCount { t.Fatalf("Bad: Expected the Azure RM SQL Virtual Network Rule Name to trigger a validation error.") @@ -339,7 +329,7 @@ func TestResourceAzureRMSqlVirtualNetworkRule_validNameValidation(t *testing.T) } for _, tc := range cases { - _, errors := validateSqlVirtualNetworkRuleName(tc.Value, "azurerm_sql_virtual_network_rule") + _, errors := sql.ValidateSqlVirtualNetworkRuleName(tc.Value, "azurerm_sql_virtual_network_rule") if len(errors) != tc.ErrCount { t.Fatalf("Bad: Expected the Azure RM SQL Virtual Network Rule Name pass name validation successfully but triggered a validation error.") @@ -454,7 +444,7 @@ func testCheckAzureRMSqlVirtualNetworkRuleDisappears(resourceName string) resour (This test configuration is intended to succeed.) Basic Provisioning Configuration */ -func testAccAzureRMSqlVirtualNetworkRule_basic(rInt int, location string) string { +func testAccAzureRMSqlVirtualNetworkRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -492,9 +482,9 @@ resource "azurerm_sql_virtual_network_rule" "test" { subnet_id = "${azurerm_subnet.test.id}" ignore_missing_vnet_service_endpoint = false } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSqlVirtualNetworkRule_requiresImport(rInt int, location string) string { +func testAccAzureRMSqlVirtualNetworkRule_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -505,7 +495,7 @@ resource "azurerm_sql_virtual_network_rule" "import" { subnet_id = "${azurerm_sql_virtual_network_rule.test.subnet_id}" ignore_missing_vnet_service_endpoint = "${azurerm_sql_virtual_network_rule.test.ignore_missing_vnet_service_endpoint}" } -`, testAccAzureRMSqlVirtualNetworkRule_basic(rInt, location)) +`, testAccAzureRMSqlVirtualNetworkRule_basic(data)) } /* @@ -513,7 +503,7 @@ resource "azurerm_sql_virtual_network_rule" "import" { Basic Provisioning Update Configuration (all other properties would recreate the rule) ignore_missing_vnet_service_endpoint (false ==> true) */ -func testAccAzureRMSqlVirtualNetworkRule_withUpdates(rInt int, location string) string { +func testAccAzureRMSqlVirtualNetworkRule_withUpdates(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -551,7 +541,7 @@ resource "azurerm_sql_virtual_network_rule" "test" { subnet_id = "${azurerm_subnet.test.id}" ignore_missing_vnet_service_endpoint = true } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } /* @@ -559,7 +549,7 @@ resource "azurerm_sql_virtual_network_rule" "test" { This test is designed to set up a scenario where a user would want to update the subnet on a given SQL virtual network rule. This configuration sets up the resources initially. */ -func testAccAzureRMSqlVirtualNetworkRule_subnetSwitchPre(rInt int, location string) string { +func testAccAzureRMSqlVirtualNetworkRule_subnetSwitchPre(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -604,7 +594,7 @@ resource "azurerm_sql_virtual_network_rule" "test" { server_name = "${azurerm_sql_server.test.name}" subnet_id = "${azurerm_subnet.test1.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } /* @@ -613,7 +603,7 @@ resource "azurerm_sql_virtual_network_rule" "test" { on a given SQL virtual network rule. This configuration contains the update from azurerm_subnet.test1 to azurerm_subnet.test2. */ -func testAccAzureRMSqlVirtualNetworkRule_subnetSwitchPost(rInt int, location string) string { +func testAccAzureRMSqlVirtualNetworkRule_subnetSwitchPost(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -658,7 +648,7 @@ resource "azurerm_sql_virtual_network_rule" "test" { server_name = "${azurerm_sql_server.test.name}" subnet_id = "${azurerm_subnet.test2.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } /* @@ -667,7 +657,7 @@ resource "azurerm_sql_virtual_network_rule" "test" { virtual network rule is set to *not* validate that the service_endpoint includes that value. The endpoint is purposefully set to Microsoft.Storage. */ -func testAccAzureRMSqlVirtualNetworkRule_ignoreEndpointValid(rInt int, location string) string { +func testAccAzureRMSqlVirtualNetworkRule_ignoreEndpointValid(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -705,7 +695,7 @@ resource "azurerm_sql_virtual_network_rule" "test" { subnet_id = "${azurerm_subnet.test.id}" ignore_missing_vnet_service_endpoint = true } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } /* @@ -714,7 +704,7 @@ resource "azurerm_sql_virtual_network_rule" "test" { virtual network rule is set to validate that the service_endpoint includes that value. The endpoint is purposefully set to Microsoft.Storage. */ -func testAccAzureRMSqlVirtualNetworkRule_ignoreEndpointInvalid(rInt int, location string) string { +func testAccAzureRMSqlVirtualNetworkRule_ignoreEndpointInvalid(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -752,7 +742,7 @@ resource "azurerm_sql_virtual_network_rule" "test" { subnet_id = "${azurerm_subnet.test.id}" ignore_missing_vnet_service_endpoint = false } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } /* @@ -760,7 +750,7 @@ resource "azurerm_sql_virtual_network_rule" "test" { This configuration sets up 3 subnets in 2 different virtual networks, and adds SQL virtual network rules for all 3 subnets to the SQL server. */ -func testAccAzureRMSqlVirtualNetworkRule_multipleSubnets(rInt int, location string) string { +func testAccAzureRMSqlVirtualNetworkRule_multipleSubnets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -837,5 +827,5 @@ resource "azurerm_sql_virtual_network_rule" "rule3" { subnet_id = "${azurerm_subnet.vnet2_subnet1.id}" ignore_missing_vnet_service_endpoint = false } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/sql/testdata/sql_import.bacpac b/azurerm/internal/services/sql/tests/testdata/sql_import.bacpac similarity index 100% rename from azurerm/internal/services/sql/testdata/sql_import.bacpac rename to azurerm/internal/services/sql/tests/testdata/sql_import.bacpac From cda964bcdc1d0fbb0ba25a760441cd781090e20c Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Fri, 20 Dec 2019 19:03:14 -0800 Subject: [PATCH 104/203] signalr --- .../resource_arm_signalr_service_test.go | 574 ------------------ .../resource_arm_signalr_service_test.go | 538 ++++++++++++++++ 2 files changed, 538 insertions(+), 574 deletions(-) delete mode 100644 azurerm/internal/services/signalr/resource_arm_signalr_service_test.go create mode 100644 azurerm/internal/services/signalr/tests/resource_arm_signalr_service_test.go diff --git a/azurerm/internal/services/signalr/resource_arm_signalr_service_test.go b/azurerm/internal/services/signalr/resource_arm_signalr_service_test.go deleted file mode 100644 index ba1d89f4ba5e..000000000000 --- a/azurerm/internal/services/signalr/resource_arm_signalr_service_test.go +++ /dev/null @@ -1,574 +0,0 @@ -package signalr - -import ( - "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/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" -) - -func TestAccAzureRMSignalRService_basic(t *testing.T) { - resourceName := "azurerm_signalr_service.test" - ri := tf.AccRandTimeInt() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSignalRServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMSignalRService_basic(ri, acceptance.Location()), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Free_F1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMSignalRService_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - resourceName := "azurerm_signalr_service.test" - ri := tf.AccRandTimeInt() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSignalRServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMSignalRService_basic(ri, acceptance.Location()), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Free_F1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - Config: testAccAzureRMSignalRService_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_signalr_service"), - }, - }, - }) -} - -func TestAccAzureRMSignalRService_standard(t *testing.T) { - resourceName := "azurerm_signalr_service.test" - ri := tf.AccRandTimeInt() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSignalRServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMSignalRService_standardWithCapacity(ri, acceptance.Location(), 1), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_S1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMSignalRService_standardWithCap2(t *testing.T) { - resourceName := "azurerm_signalr_service.test" - ri := tf.AccRandTimeInt() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSignalRServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMSignalRService_standardWithCapacity(ri, acceptance.Location(), 2), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_S1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "2"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMSignalRService_skuUpdate(t *testing.T) { - resourceName := "azurerm_signalr_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - freeConfig := testAccAzureRMSignalRService_basic(ri, location) - standardConfig := testAccAzureRMSignalRService_standardWithCapacity(ri, location, 1) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSignalRServiceDestroy, - Steps: []resource.TestStep{ - { - Config: freeConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Free_F1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - Config: standardConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_S1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - Config: freeConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Free_F1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - }, - }) -} - -func TestAccAzureRMSignalRService_capacityUpdate(t *testing.T) { - resourceName := "azurerm_signalr_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - standardConfig := testAccAzureRMSignalRService_standardWithCapacity(ri, location, 1) - standardCap5Config := testAccAzureRMSignalRService_standardWithCapacity(ri, location, 5) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSignalRServiceDestroy, - Steps: []resource.TestStep{ - { - Config: standardConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_S1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - Config: standardCap5Config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_S1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "5"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - Config: standardConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_S1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - }, - }) -} - -func TestAccAzureRMSignalRService_skuAndCapacityUpdate(t *testing.T) { - resourceName := "azurerm_signalr_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - freeConfig := testAccAzureRMSignalRService_basic(ri, location) - standardConfig := testAccAzureRMSignalRService_standardWithCapacity(ri, location, 2) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSignalRServiceDestroy, - Steps: []resource.TestStep{ - { - Config: freeConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Free_F1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - Config: standardConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_S1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "2"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - Config: freeConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Free_F1"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - }, - }) -} - -func TestAccAzureRMSignalRService_serviceMode(t *testing.T) { - resourceName := "azurerm_signalr_service.test" - ri := tf.AccRandTimeInt() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSignalRServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMSignalRService_withServiceMode(ri, acceptance.Location(), "Serverless"), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "features.#", "1"), - resource.TestCheckResourceAttr(resourceName, "features.0.flag", "ServiceMode"), - resource.TestCheckResourceAttr(resourceName, "features.0.value", "Serverless"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMSignalRService_cors(t *testing.T) { - resourceName := "azurerm_signalr_service.test" - ri := tf.AccRandTimeInt() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMSignalRServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMSignalRService_withCors(ri, acceptance.Location()), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSignalRServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "cors.#", "1"), - resource.TestCheckResourceAttr(resourceName, "cors.0.allowed_origins.#", "2"), - resource.TestCheckResourceAttrSet(resourceName, "hostname"), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "public_port"), - resource.TestCheckResourceAttrSet(resourceName, "server_port"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccAzureRMSignalRService_basic(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_signalr_service" "test" { - name = "acctestSignalR-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "Free_F1" - capacity = 1 - } -} -`, rInt, location, rInt) -} - -func testAccAzureRMSignalRService_requiresImport(rInt int, location string) string { - return fmt.Sprintf(` -%s - -resource "azurerm_signalr_service" "import" { - name = "${azurerm_signalr_service.test.name}" - location = "${azurerm_signalr_service.test.location}" - resource_group_name = "${azurerm_signalr_service.test.resource_group_name}" - - sku { - name = "Free_F1" - capacity = 1 - } -} -`, testAccAzureRMSignalRService_basic(rInt, location)) -} - -func testAccAzureRMSignalRService_standardWithCapacity(rInt int, location string, capacity int) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_signalr_service" "test" { - name = "acctestSignalR-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "Standard_S1" - capacity = %d - } -} -`, rInt, location, rInt, capacity) -} - -func testAccAzureRMSignalRService_withCors(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_signalr_service" "test" { - name = "acctestSignalR-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "Free_F1" - capacity = 1 - } - - cors { - allowed_origins = [ - "https://example.com", - "https://contoso.com", - ] - } -} -`, rInt, location, rInt) -} - -func testAccAzureRMSignalRService_withServiceMode(rInt int, location string, serviceMode string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_signalr_service" "test" { - name = "acctestSignalR-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - - sku { - name = "Free_F1" - capacity = 1 - } - - features { - flag = "ServiceMode" - value = "%s" - } -} -`, rInt, location, rInt, serviceMode) -} - -func testCheckAzureRMSignalRServiceDestroy(s *terraform.State) error { - conn := acceptance.AzureProvider.Meta().(*clients.Client).SignalR.Client - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_signalr_service" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := conn.Get(ctx, resourceGroup, name) - if err != nil { - return nil - } - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("SignalR service still exists:\n%#v", resp) - } - } - return nil -} - -func testCheckAzureRMSignalRServiceExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", 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 SignalR service: %s", name) - } - - conn := acceptance.AzureProvider.Meta().(*clients.Client).SignalR.Client - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - resp, err := conn.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("Bad: Get on signalRClient: %+v", err) - } - if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: SignalR service %q (resource group: %q) does not exist", name, resourceGroup) - } - - return nil - } -} diff --git a/azurerm/internal/services/signalr/tests/resource_arm_signalr_service_test.go b/azurerm/internal/services/signalr/tests/resource_arm_signalr_service_test.go new file mode 100644 index 000000000000..a19851fbba7e --- /dev/null +++ b/azurerm/internal/services/signalr/tests/resource_arm_signalr_service_test.go @@ -0,0 +1,538 @@ +package tests + +import ( + "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/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" +) + +func TestAccAzureRMSignalRService_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSignalRService_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Free_F1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMSignalRService_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSignalRService_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Free_F1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + data.RequiresImportErrorStep(testAccAzureRMSignalRService_requiresImport), + }, + }) +} + +func TestAccAzureRMSignalRService_standard(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSignalRService_standardWithCapacity(data, 1), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_S1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMSignalRService_standardWithCap2(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSignalRService_standardWithCapacity(data, 2), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_S1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "2"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMSignalRService_skuUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test") + freeConfig := testAccAzureRMSignalRService_basic(data) + standardConfig := testAccAzureRMSignalRService_standardWithCapacity(data, 1) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, + Steps: []resource.TestStep{ + { + Config: freeConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Free_F1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + { + Config: standardConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_S1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + { + Config: freeConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Free_F1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + }, + }) +} + +func TestAccAzureRMSignalRService_capacityUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test") + standardConfig := testAccAzureRMSignalRService_standardWithCapacity(data, 1) + standardCap5Config := testAccAzureRMSignalRService_standardWithCapacity(data, 5) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, + Steps: []resource.TestStep{ + { + Config: standardConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_S1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + { + Config: standardCap5Config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_S1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "5"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + { + Config: standardConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_S1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + }, + }) +} + +func TestAccAzureRMSignalRService_skuAndCapacityUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test") + freeConfig := testAccAzureRMSignalRService_basic(data) + standardConfig := testAccAzureRMSignalRService_standardWithCapacity(data, 2) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, + Steps: []resource.TestStep{ + { + Config: freeConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Free_F1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + { + Config: standardConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_S1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "2"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + { + Config: freeConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Free_F1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + }, + }) +} + +func TestAccAzureRMSignalRService_serviceMode(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSignalRService_withServiceMode(data, "Serverless"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "features.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "features.0.flag", "ServiceMode"), + resource.TestCheckResourceAttr(data.ResourceName, "features.0.value", "Serverless"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMSignalRService_cors(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_signalr_service", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMSignalRServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMSignalRService_withCors(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMSignalRServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "cors.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "cors.0.allowed_origins.#", "2"), + resource.TestCheckResourceAttrSet(data.ResourceName, "hostname"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "public_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_port"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + ), + }, + data.ImportStep(), + }, + }) +} + +func testAccAzureRMSignalRService_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_signalr_service" "test" { + name = "acctestSignalR-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku { + name = "Free_F1" + capacity = 1 + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMSignalRService_requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_signalr_service" "import" { + name = "${azurerm_signalr_service.test.name}" + location = "${azurerm_signalr_service.test.location}" + resource_group_name = "${azurerm_signalr_service.test.resource_group_name}" + + sku { + name = "Free_F1" + capacity = 1 + } +} +`, testAccAzureRMSignalRService_basic(data)) +} + +func testAccAzureRMSignalRService_standardWithCapacity(data acceptance.TestData, capacity int) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_signalr_service" "test" { + name = "acctestSignalR-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku { + name = "Standard_S1" + capacity = %d + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, capacity) +} + +func testAccAzureRMSignalRService_withCors(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_signalr_service" "test" { + name = "acctestSignalR-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku { + name = "Free_F1" + capacity = 1 + } + + cors { + allowed_origins = [ + "https://example.com", + "https://contoso.com", + ] + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMSignalRService_withServiceMode(data acceptance.TestData, serviceMode string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_signalr_service" "test" { + name = "acctestSignalR-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku { + name = "Free_F1" + capacity = 1 + } + + features { + flag = "ServiceMode" + value = "%s" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, serviceMode) +} + +func testCheckAzureRMSignalRServiceDestroy(s *terraform.State) error { + conn := acceptance.AzureProvider.Meta().(*clients.Client).SignalR.Client + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_signalr_service" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(ctx, resourceGroup, name) + if err != nil { + return nil + } + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("SignalR service still exists:\n%#v", resp) + } + } + return nil +} + +func testCheckAzureRMSignalRServiceExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", 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 SignalR service: %s", name) + } + + conn := acceptance.AzureProvider.Meta().(*clients.Client).SignalR.Client + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + resp, err := conn.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Bad: Get on signalRClient: %+v", err) + } + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: SignalR service %q (resource group: %q) does not exist", name, resourceGroup) + } + + return nil + } +} From a24ecaf58580003ae5f6dc8f18024bfb860fd727 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Fri, 20 Dec 2019 19:16:20 -0800 Subject: [PATCH 105/203] tests: servicefabric --- ...esource_arm_service_fabric_cluster_test.go | 810 ++++++++---------- 1 file changed, 348 insertions(+), 462 deletions(-) rename azurerm/internal/services/servicefabric/{ => tests}/resource_arm_service_fabric_cluster_test.go (53%) diff --git a/azurerm/internal/services/servicefabric/resource_arm_service_fabric_cluster_test.go b/azurerm/internal/services/servicefabric/tests/resource_arm_service_fabric_cluster_test.go similarity index 53% rename from azurerm/internal/services/servicefabric/resource_arm_service_fabric_cluster_test.go rename to azurerm/internal/services/servicefabric/tests/resource_arm_service_fabric_cluster_test.go index 3dcdd1f87c1d..1c25e372fd23 100644 --- a/azurerm/internal/services/servicefabric/resource_arm_service_fabric_cluster_test.go +++ b/azurerm/internal/services/servicefabric/tests/resource_arm_service_fabric_cluster_test.go @@ -1,22 +1,19 @@ -package servicefabric +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMServiceFabricCluster_basic(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,33 +21,28 @@ func TestAccAzureRMServiceFabricCluster_basic(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_basic(ri, acceptance.Location(), 3), + Config: testAccAzureRMServiceFabricCluster_basic(data, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "http://example:80"), - resource.TestCheckResourceAttr(resourceName, "add_on_features.#", "0"), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.#", "0"), - resource.TestCheckResourceAttr(resourceName, "azure_active_directory.#", "0"), - resource.TestCheckResourceAttr(resourceName, "diagnostics_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "node_type.#", "1"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.instance_count", "3"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "http://example:80"), + resource.TestCheckResourceAttr(data.ResourceName, "add_on_features.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.instance_count", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_basicNodeTypeUpdate(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -58,43 +50,39 @@ func TestAccAzureRMServiceFabricCluster_basicNodeTypeUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_basic(ri, acceptance.Location(), 3), + Config: testAccAzureRMServiceFabricCluster_basic(data, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "http://example:80"), - resource.TestCheckResourceAttr(resourceName, "add_on_features.#", "0"), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.#", "0"), - resource.TestCheckResourceAttr(resourceName, "azure_active_directory.#", "0"), - resource.TestCheckResourceAttr(resourceName, "diagnostics_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "node_type.#", "1"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.is_primary", "true"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "http://example:80"), + resource.TestCheckResourceAttr(data.ResourceName, "add_on_features.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.is_primary", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, { - Config: testAccAzureRMServiceFabricCluster_basicNodeTypeUpdate(ri, acceptance.Location(), 3, 3), + Config: testAccAzureRMServiceFabricCluster_basicNodeTypeUpdate(data, 3, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "http://example:80"), - resource.TestCheckResourceAttr(resourceName, "add_on_features.#", "0"), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.#", "0"), - resource.TestCheckResourceAttr(resourceName, "azure_active_directory.#", "0"), - resource.TestCheckResourceAttr(resourceName, "diagnostics_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "node_type.#", "2"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.is_primary", "true"), - resource.TestCheckResourceAttr(resourceName, "node_type.1.is_primary", "false"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "http://example:80"), + resource.TestCheckResourceAttr(data.ResourceName, "add_on_features.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.is_primary", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.1.is_primary", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -104,9 +92,7 @@ func TestAccAzureRMServiceFabricCluster_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,32 +100,28 @@ func TestAccAzureRMServiceFabricCluster_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_basic(ri, acceptance.Location(), 3), + Config: testAccAzureRMServiceFabricCluster_basic(data, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "http://example:80"), - resource.TestCheckResourceAttr(resourceName, "add_on_features.#", "0"), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.#", "0"), - resource.TestCheckResourceAttr(resourceName, "azure_active_directory.#", "0"), - resource.TestCheckResourceAttr(resourceName, "diagnostics_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "node_type.#", "1"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.instance_count", "3"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "http://example:80"), + resource.TestCheckResourceAttr(data.ResourceName, "add_on_features.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.instance_count", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - Config: testAccAzureRMServiceFabricCluster_requiresImport(ri, acceptance.Location(), 3), - ExpectError: acceptance.RequiresImportError("azurerm_service_fabric_cluster"), - }, + data.RequiresImportErrorStep(testAccAzureRMServiceFabricCluster_requiresImport), }, }) } func TestAccAzureRMServiceFabricCluster_manualClusterCodeVersion(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") codeVersion := "6.4.637.9590" resource.ParallelTest(t, resource.TestCase{ @@ -148,33 +130,28 @@ func TestAccAzureRMServiceFabricCluster_manualClusterCodeVersion(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(ri, acceptance.Location(), codeVersion), + Config: testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(data, codeVersion), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "upgrade_mode", "Manual"), - resource.TestCheckResourceAttr(resourceName, "cluster_code_version", codeVersion), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "upgrade_mode", "Manual"), + resource.TestCheckResourceAttr(data.ResourceName, "cluster_code_version", codeVersion), ), }, { - Config: testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(ri, acceptance.Location(), codeVersion), + Config: testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(data, codeVersion), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "upgrade_mode", "Manual"), - resource.TestCheckResourceAttr(resourceName, "cluster_code_version", codeVersion), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "upgrade_mode", "Manual"), + resource.TestCheckResourceAttr(data.ResourceName, "cluster_code_version", codeVersion), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_manualLatest(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -182,26 +159,21 @@ func TestAccAzureRMServiceFabricCluster_manualLatest(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(ri, acceptance.Location(), ""), + Config: testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(data, ""), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "upgrade_mode", "Manual"), - resource.TestCheckResourceAttrSet(resourceName, "cluster_code_version"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "upgrade_mode", "Manual"), + resource.TestCheckResourceAttrSet(data.ResourceName, "cluster_code_version"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_addOnFeatures(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceFabricCluster_addOnFeatures(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") + config := testAccAzureRMServiceFabricCluster_addOnFeatures(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -211,22 +183,17 @@ func TestAccAzureRMServiceFabricCluster_addOnFeatures(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "add_on_features.#", "2"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "add_on_features.#", "2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_certificate(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -234,29 +201,24 @@ func TestAccAzureRMServiceFabricCluster_certificate(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_certificates(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_certificates(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.name", "Security"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "https://example:80"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.name", "Security"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "https://example:80"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_reverseProxyCertificate(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -264,35 +226,29 @@ func TestAccAzureRMServiceFabricCluster_reverseProxyCertificate(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_reverseProxyCertificates(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_reverseProxyCertificates(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.#", "1"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.name", "Security"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "https://example:80"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.reverse_proxy_endpoint_port", "19081"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.name", "Security"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "https://example:80"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.reverse_proxy_endpoint_port", "19081"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_reverseProxyNotSet(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMServiceFabricCluster_basic(ri, location, 3) + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") + config := testAccAzureRMServiceFabricCluster_basic(data, 3) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -302,35 +258,29 @@ func TestAccAzureRMServiceFabricCluster_reverseProxyNotSet(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "http://example:80"), - resource.TestCheckResourceAttr(resourceName, "add_on_features.#", "0"), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.#", "0"), - resource.TestCheckResourceAttr(resourceName, "azure_active_directory.#", "0"), - resource.TestCheckResourceAttr(resourceName, "diagnostics_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "node_type.#", "1"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.instance_count", "3"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.reverse_proxy_endpoint_port", "0"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "http://example:80"), + resource.TestCheckResourceAttr(data.ResourceName, "add_on_features.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.instance_count", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.reverse_proxy_endpoint_port", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_reverseProxyUpdate(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - configBasic := testAccAzureRMServiceFabricCluster_basic(ri, location, 3) - configProxy := testAccAzureRMServiceFabricCluster_reverseProxyCertificates(ri, location) + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") + configBasic := testAccAzureRMServiceFabricCluster_basic(data, 3) + configProxy := testAccAzureRMServiceFabricCluster_reverseProxyCertificates(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -340,50 +290,50 @@ func TestAccAzureRMServiceFabricCluster_reverseProxyUpdate(t *testing.T) { { Config: configBasic, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "http://example:80"), - resource.TestCheckResourceAttr(resourceName, "add_on_features.#", "0"), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.#", "0"), - resource.TestCheckResourceAttr(resourceName, "azure_active_directory.#", "0"), - resource.TestCheckResourceAttr(resourceName, "diagnostics_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "node_type.#", "1"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.instance_count", "3"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "http://example:80"), + resource.TestCheckResourceAttr(data.ResourceName, "add_on_features.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.instance_count", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, { Config: configProxy, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.#", "1"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.name", "Security"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "https://example:80"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.reverse_proxy_endpoint_port", "19081"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.name", "Security"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "https://example:80"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.reverse_proxy_endpoint_port", "19081"), ), }, { Config: configBasic, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "http://example:80"), - resource.TestCheckResourceAttr(resourceName, "add_on_features.#", "0"), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "reverse_proxy_certificate.#", "0"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.#", "0"), - resource.TestCheckResourceAttr(resourceName, "azure_active_directory.#", "0"), - resource.TestCheckResourceAttr(resourceName, "diagnostics_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "node_type.#", "1"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.instance_count", "3"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.reverse_proxy_endpoint_port", "0"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "http://example:80"), + resource.TestCheckResourceAttr(data.ResourceName, "add_on_features.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "reverse_proxy_certificate.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.instance_count", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.reverse_proxy_endpoint_port", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -391,8 +341,7 @@ func TestAccAzureRMServiceFabricCluster_reverseProxyUpdate(t *testing.T) { } func TestAccAzureRMServiceFabricCluster_clientCertificateThumbprint(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -400,32 +349,27 @@ func TestAccAzureRMServiceFabricCluster_clientCertificateThumbprint(t *testing.T CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_clientCertificateThumbprint(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_clientCertificateThumbprint(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.#", "1"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.0.is_admin", "true"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.name", "Security"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "https://example:80"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.0.is_admin", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.name", "Security"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "https://example:80"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_readerAdminClientCertificateThumbprint(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -433,34 +377,29 @@ func TestAccAzureRMServiceFabricCluster_readerAdminClientCertificateThumbprint(t CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_readerAdminClientCertificateThumbprint(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_readerAdminClientCertificateThumbprint(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.#", "2"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.0.is_admin", "true"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.1.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "client_certificate_thumbprint.1.is_admin", "false"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.name", "Security"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "https://example:80"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.0.is_admin", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.1.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "client_certificate_thumbprint.1.is_admin", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.name", "Security"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "https://example:80"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_certificateCommonNames(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -468,28 +407,23 @@ func TestAccAzureRMServiceFabricCluster_certificateCommonNames(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_certificateCommonNames(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_certificateCommonNames(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "certificate_common_names.0.common_names.2962847220.certificate_common_name", "example"), - resource.TestCheckResourceAttr(resourceName, "certificate_common_names.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.name", "Security"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "https://example:80"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_common_names.0.common_names.2962847220.certificate_common_name", "example"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_common_names.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.name", "Security"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "https://example:80"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_azureActiveDirectory(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -497,33 +431,28 @@ func TestAccAzureRMServiceFabricCluster_azureActiveDirectory(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_azureActiveDirectory(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_azureActiveDirectory(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "azure_active_directory.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "azure_active_directory.0.tenant_id"), - resource.TestCheckResourceAttrSet(resourceName, "azure_active_directory.0.cluster_application_id"), - resource.TestCheckResourceAttrSet(resourceName, "azure_active_directory.0.client_application_id"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.name", "Security"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "https://example:19080"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_active_directory.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "azure_active_directory.0.tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "azure_active_directory.0.cluster_application_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "azure_active_directory.0.client_application_id"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.name", "Security"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "https://example:19080"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_azureActiveDirectoryDelete(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -531,47 +460,41 @@ func TestAccAzureRMServiceFabricCluster_azureActiveDirectoryDelete(t *testing.T) CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_azureActiveDirectory(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_azureActiveDirectory(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "azure_active_directory.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "azure_active_directory.0.tenant_id"), - resource.TestCheckResourceAttrSet(resourceName, "azure_active_directory.0.cluster_application_id"), - resource.TestCheckResourceAttrSet(resourceName, "azure_active_directory.0.client_application_id"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.name", "Security"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "https://example:19080"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_active_directory.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "azure_active_directory.0.tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "azure_active_directory.0.cluster_application_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "azure_active_directory.0.client_application_id"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.name", "Security"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "https://example:19080"), ), }, { - Config: testAccAzureRMServiceFabricCluster_azureActiveDirectoryDelete(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_azureActiveDirectoryDelete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.x509_store_name", "My"), - resource.TestCheckResourceAttr(resourceName, "azure_active_directory.#", "0"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.name", "Security"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), - resource.TestCheckResourceAttr(resourceName, "management_endpoint", "https://example:19080"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.thumbprint", "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.x509_store_name", "My"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.name", "Security"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "EncryptAndSign"), + resource.TestCheckResourceAttr(data.ResourceName, "management_endpoint", "https://example:19080"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_diagnosticsConfig(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -579,30 +502,24 @@ func TestAccAzureRMServiceFabricCluster_diagnosticsConfig(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_diagnosticsConfig(ri, rs, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_diagnosticsConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "diagnostics_config.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics_config.0.storage_account_name"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics_config.0.protected_account_key_name"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics_config.0.blob_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics_config.0.queue_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics_config.0.table_endpoint"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics_config.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics_config.0.storage_account_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics_config.0.protected_account_key_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics_config.0.blob_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics_config.0.queue_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics_config.0.table_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_diagnosticsConfigDelete(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -610,36 +527,31 @@ func TestAccAzureRMServiceFabricCluster_diagnosticsConfigDelete(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_diagnosticsConfig(ri, rs, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_diagnosticsConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "diagnostics_config.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics_config.0.storage_account_name"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics_config.0.protected_account_key_name"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics_config.0.blob_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics_config.0.queue_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics_config.0.table_endpoint"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics_config.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics_config.0.storage_account_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics_config.0.protected_account_key_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics_config.0.blob_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics_config.0.queue_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics_config.0.table_endpoint"), ), }, { - Config: testAccAzureRMServiceFabricCluster_diagnosticsConfigDelete(ri, rs, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_diagnosticsConfigDelete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "diagnostics_config.#", "0"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics_config.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_fabricSettings(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -647,27 +559,22 @@ func TestAccAzureRMServiceFabricCluster_fabricSettings(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_fabricSettings(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_fabricSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.name", "Security"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.%", "1"), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "None"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.name", "Security"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.0.parameters.ClusterProtectionLevel", "None"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_fabricSettingsRemove(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -675,17 +582,17 @@ func TestAccAzureRMServiceFabricCluster_fabricSettingsRemove(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_fabricSettings(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_fabricSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.#", "1"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.#", "1"), ), }, { - Config: testAccAzureRMServiceFabricCluster_basic(ri, acceptance.Location(), 3), + Config: testAccAzureRMServiceFabricCluster_basic(data, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "fabric_settings.#", "0"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "fabric_settings.#", "0"), ), }, }, @@ -693,8 +600,7 @@ func TestAccAzureRMServiceFabricCluster_fabricSettingsRemove(t *testing.T) { } func TestAccAzureRMServiceFabricCluster_nodeTypeCustomPorts(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -702,30 +608,25 @@ func TestAccAzureRMServiceFabricCluster_nodeTypeCustomPorts(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_nodeTypeCustomPorts(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_nodeTypeCustomPorts(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "node_type.#", "1"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.application_ports.#", "1"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.application_ports.0.start_port", "20000"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.application_ports.0.end_port", "29999"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.ephemeral_ports.#", "1"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.ephemeral_ports.0.start_port", "30000"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.ephemeral_ports.0.end_port", "39999"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.application_ports.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.application_ports.0.start_port", "20000"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.application_ports.0.end_port", "29999"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.ephemeral_ports.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.ephemeral_ports.0.start_port", "30000"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.ephemeral_ports.0.end_port", "39999"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_nodeTypesMultiple(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -733,30 +634,25 @@ func TestAccAzureRMServiceFabricCluster_nodeTypesMultiple(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_nodeTypeMultiple(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_nodeTypeMultiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "node_type.#", "2"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.name", "first"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.instance_count", "3"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.is_primary", "true"), - resource.TestCheckResourceAttr(resourceName, "node_type.1.name", "second"), - resource.TestCheckResourceAttr(resourceName, "node_type.1.instance_count", "4"), - resource.TestCheckResourceAttr(resourceName, "node_type.1.is_primary", "false"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.name", "first"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.instance_count", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.is_primary", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.1.name", "second"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.1.instance_count", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.1.is_primary", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_nodeTypesUpdate(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -764,17 +660,17 @@ func TestAccAzureRMServiceFabricCluster_nodeTypesUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_basic(ri, acceptance.Location(), 3), + Config: testAccAzureRMServiceFabricCluster_basic(data, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "node_type.0.instance_count", "3"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.instance_count", "3"), ), }, { - Config: testAccAzureRMServiceFabricCluster_basic(ri, acceptance.Location(), 4), + Config: testAccAzureRMServiceFabricCluster_basic(data, 4), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "node_type.0.instance_count", "4"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.instance_count", "4"), ), }, }, @@ -782,8 +678,7 @@ func TestAccAzureRMServiceFabricCluster_nodeTypesUpdate(t *testing.T) { } func TestAccAzureRMServiceFabricCluster_nodeTypeProperties(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -791,28 +686,23 @@ func TestAccAzureRMServiceFabricCluster_nodeTypeProperties(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_nodeTypeProperties(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_nodeTypeProperties(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "node_type.0.placement_properties.%", "1"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.placement_properties.HasSSD", "true"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.capacities.%", "2"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.capacities.ClientConnections", "20000"), - resource.TestCheckResourceAttr(resourceName, "node_type.0.capacities.MemoryGB", "8"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.placement_properties.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.placement_properties.HasSSD", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.capacities.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.capacities.ClientConnections", "20000"), + resource.TestCheckResourceAttr(data.ResourceName, "node_type.0.capacities.MemoryGB", "8"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceFabricCluster_tags(t *testing.T) { - resourceName := "azurerm_service_fabric_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -820,18 +710,14 @@ func TestAccAzureRMServiceFabricCluster_tags(t *testing.T) { CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceFabricCluster_tags(ri, acceptance.Location()), + Config: testAccAzureRMServiceFabricCluster_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceFabricClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), + testCheckAzureRMServiceFabricClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -892,7 +778,7 @@ func testCheckAzureRMServiceFabricClusterExists(resourceName string) resource.Te } } -func testAccAzureRMServiceFabricCluster_basic(rInt int, location string, count int) string { +func testAccAzureRMServiceFabricCluster_basic(data acceptance.TestData, count int) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -916,10 +802,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, rInt, count) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, count) } -func testAccAzureRMServiceFabricCluster_basicNodeTypeUpdate(rInt int, location string, count int, secondary_count int) string { +func testAccAzureRMServiceFabricCluster_basicNodeTypeUpdate(data acceptance.TestData, count int, secondary_count int) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -951,10 +837,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, rInt, count, secondary_count) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, count, secondary_count) } -func testAccAzureRMServiceFabricCluster_requiresImport(rInt int, location string, count int) string { +func testAccAzureRMServiceFabricCluster_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -969,16 +855,16 @@ resource "azurerm_service_fabric_cluster" "import" { node_type { name = "first" - instance_count = %d + instance_count = 3 is_primary = true client_endpoint_port = 2020 http_endpoint_port = 80 } } -`, testAccAzureRMServiceFabricCluster_basic(rInt, location, count), count) +`, testAccAzureRMServiceFabricCluster_basic(data, 3)) } -func testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(rInt int, location, clusterCodeVersion string) string { +func testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(data acceptance.TestData, clusterCodeVersion string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -1003,10 +889,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, clusterCodeVersion) +`, data.RandomInteger, data.Locations.Primary, clusterCodeVersion) } -func testAccAzureRMServiceFabricCluster_addOnFeatures(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_addOnFeatures(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1031,10 +917,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_certificates(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_certificates(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1071,10 +957,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_reverseProxyCertificates(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_reverseProxyCertificates(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1117,10 +1003,10 @@ resource "azurerm_service_fabric_cluster" "test" { reverse_proxy_endpoint_port = 19081 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_clientCertificateThumbprint(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_clientCertificateThumbprint(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1162,10 +1048,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_readerAdminClientCertificateThumbprint(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_readerAdminClientCertificateThumbprint(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1212,10 +1098,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_certificateCommonNames(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_certificateCommonNames(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1255,10 +1141,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_azureActiveDirectory(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_azureActiveDirectory(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1359,10 +1245,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 19080 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_azureActiveDirectoryDelete(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_azureActiveDirectoryDelete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1401,10 +1287,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 19080 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_diagnosticsConfig(rInt int, rString, location string) string { +func testAccAzureRMServiceFabricCluster_diagnosticsConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1444,10 +1330,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_diagnosticsConfigDelete(rInt int, rString, location string) string { +func testAccAzureRMServiceFabricCluster_diagnosticsConfigDelete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1479,10 +1365,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_fabricSettings(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_fabricSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1514,10 +1400,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 80 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_nodeTypeCustomPorts(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_nodeTypeCustomPorts(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1551,10 +1437,10 @@ resource "azurerm_service_fabric_cluster" "test" { } } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_nodeTypeMultiple(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_nodeTypeMultiple(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1586,10 +1472,10 @@ resource "azurerm_service_fabric_cluster" "test" { http_endpoint_port = 81 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_nodeTypeProperties(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_nodeTypeProperties(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1627,10 +1513,10 @@ resource "azurerm_service_fabric_cluster" "test" { Hello = "World" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceFabricCluster_tags(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_tags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1658,5 +1544,5 @@ resource "azurerm_service_fabric_cluster" "test" { Hello = "World" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 709db97d02895a8a42461c3e9e3f1e0ebc8df36a Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Fri, 20 Dec 2019 20:10:02 -0800 Subject: [PATCH 106/203] test: servicebus --- .../data_source_servicebus_namespace_test.go | 88 --------- .../resource_arm_servicebus_namespace.go | 2 +- ...urce_arm_servicebus_namespace_migration.go | 2 +- ...cebus_namespace_authorization_rule_test.go | 25 ++- .../data_source_servicebus_namespace_test.go | 83 ++++++++ ...cebus_namespace_authorization_rule_test.go | 97 +++++----- ...arm_servicebus_namespace_migration_test.go | 5 +- .../resource_arm_servicebus_namespace_test.go | 121 +++++------- ...ervicebus_queue_authorization_rule_test.go | 99 +++++----- ...e_arm_servicebus_subscription_rule_test.go | 141 ++++++-------- ...source_arm_servicebus_subscription_test.go | 149 ++++++-------- ...ervicebus_topic_authorization_rule_test.go | 97 +++++----- .../resource_arm_servicebus_topic_test.go | 181 +++++++----------- 13 files changed, 465 insertions(+), 625 deletions(-) delete mode 100644 azurerm/internal/services/servicebus/data_source_servicebus_namespace_test.go rename azurerm/internal/services/servicebus/{ => tests}/data_source_servicebus_namespace_authorization_rule_test.go (57%) create mode 100644 azurerm/internal/services/servicebus/tests/data_source_servicebus_namespace_test.go rename azurerm/internal/services/servicebus/{ => tests}/resource_arm_servicebus_namespace_authorization_rule_test.go (68%) rename azurerm/internal/services/servicebus/{ => tests}/resource_arm_servicebus_namespace_migration_test.go (92%) rename azurerm/internal/services/servicebus/{ => tests}/resource_arm_servicebus_namespace_test.go (71%) rename azurerm/internal/services/servicebus/{ => tests}/resource_arm_servicebus_queue_authorization_rule_test.go (66%) rename azurerm/internal/services/servicebus/{ => tests}/resource_arm_servicebus_subscription_rule_test.go (74%) rename azurerm/internal/services/servicebus/{ => tests}/resource_arm_servicebus_subscription_test.go (69%) rename azurerm/internal/services/servicebus/{ => tests}/resource_arm_servicebus_topic_authorization_rule_test.go (67%) rename azurerm/internal/services/servicebus/{ => tests}/resource_arm_servicebus_topic_test.go (71%) diff --git a/azurerm/internal/services/servicebus/data_source_servicebus_namespace_test.go b/azurerm/internal/services/servicebus/data_source_servicebus_namespace_test.go deleted file mode 100644 index 46a71667906f..000000000000 --- a/azurerm/internal/services/servicebus/data_source_servicebus_namespace_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package servicebus - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMServiceBusNamespace_basic(t *testing.T) { - dataSourceName := "data.azurerm_servicebus_namespace.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMServiceBusNamespace_basic(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "sku"), - resource.TestCheckResourceAttrSet(dataSourceName, "capacity"), - resource.TestCheckResourceAttrSet(dataSourceName, "default_primary_connection_string"), - resource.TestCheckResourceAttrSet(dataSourceName, "default_secondary_connection_string"), - resource.TestCheckResourceAttrSet(dataSourceName, "default_primary_key"), - resource.TestCheckResourceAttrSet(dataSourceName, "default_secondary_key"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMServiceBusNamespace_premium(t *testing.T) { - dataSourceName := "data.azurerm_servicebus_namespace.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMServiceBusNamespace_premium(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "sku"), - resource.TestCheckResourceAttrSet(dataSourceName, "capacity"), - resource.TestCheckResourceAttrSet(dataSourceName, "default_primary_connection_string"), - resource.TestCheckResourceAttrSet(dataSourceName, "default_secondary_connection_string"), - resource.TestCheckResourceAttrSet(dataSourceName, "default_primary_key"), - resource.TestCheckResourceAttrSet(dataSourceName, "default_secondary_key"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMServiceBusNamespace_basic(rInt int, location string) string { - template := testAccAzureRMServiceBusNamespace_basic(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_servicebus_namespace" "test" { - name = "${azurerm_servicebus_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, template) -} - -func testAccDataSourceAzureRMServiceBusNamespace_premium(rInt int, location string) string { - template := testAccAzureRMServiceBusNamespace_premium(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_servicebus_namespace" "test" { - name = "${azurerm_servicebus_namespace.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, template) -} diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace.go index 515853a66cce..4146cb24d22e 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace.go @@ -37,7 +37,7 @@ func resourceArmServiceBusNamespace() *schema.Resource { State: schema.ImportStatePassthrough, }, - MigrateState: resourceAzureRMServiceBusNamespaceMigrateState, + MigrateState: ResourceAzureRMServiceBusNamespaceMigrateState, SchemaVersion: 1, Timeouts: &schema.ResourceTimeout{ diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration.go b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration.go index 3e37dcdcc775..70a87bd7e0b6 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration.go +++ b/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func resourceAzureRMServiceBusNamespaceMigrateState( +func ResourceAzureRMServiceBusNamespaceMigrateState( v int, is *terraform.InstanceState, _ interface{}) (*terraform.InstanceState, error) { switch v { case 0: diff --git a/azurerm/internal/services/servicebus/data_source_servicebus_namespace_authorization_rule_test.go b/azurerm/internal/services/servicebus/tests/data_source_servicebus_namespace_authorization_rule_test.go similarity index 57% rename from azurerm/internal/services/servicebus/data_source_servicebus_namespace_authorization_rule_test.go rename to azurerm/internal/services/servicebus/tests/data_source_servicebus_namespace_authorization_rule_test.go index 83302924f702..a61afe208d74 100644 --- a/azurerm/internal/services/servicebus/data_source_servicebus_namespace_authorization_rule_test.go +++ b/azurerm/internal/services/servicebus/tests/data_source_servicebus_namespace_authorization_rule_test.go @@ -1,18 +1,15 @@ -package servicebus +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMServiceBusNamespaceRule_basic(t *testing.T) { - dataSourceName := "data.azurerm_servicebus_namespace_authorization_rule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_servicebus_namespace_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,22 +17,22 @@ func TestAccDataSourceAzureRMServiceBusNamespaceRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusNamespaceAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMServiceBusNamespaceAuthorizationRule_basic(ri, location), + Config: testAccDataSourceAzureRMServiceBusNamespaceAuthorizationRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "id"), - resource.TestCheckResourceAttrSet(dataSourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(dataSourceName, "primary_key"), - resource.TestCheckResourceAttrSet(dataSourceName, "secondary_connection_string"), - resource.TestCheckResourceAttrSet(dataSourceName, "secondary_key"), + testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), ), }, }, }) } -func testAccDataSourceAzureRMServiceBusNamespaceAuthorizationRule_basic(rInt int, location string) string { - template := testAccAzureRMServiceBusNamespaceAuthorizationRule_base(rInt, location, true, true, true) +func testAccDataSourceAzureRMServiceBusNamespaceAuthorizationRule_basic(data acceptance.TestData) string { + template := testAccAzureRMServiceBusNamespaceAuthorizationRule_base(data, true, true, true) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/servicebus/tests/data_source_servicebus_namespace_test.go b/azurerm/internal/services/servicebus/tests/data_source_servicebus_namespace_test.go new file mode 100644 index 000000000000..75c84f302652 --- /dev/null +++ b/azurerm/internal/services/servicebus/tests/data_source_servicebus_namespace_test.go @@ -0,0 +1,83 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMServiceBusNamespace_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_servicebus_namespace", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMServiceBusNamespace_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "sku"), + resource.TestCheckResourceAttrSet(data.ResourceName, "capacity"), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_secondary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_secondary_key"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMServiceBusNamespace_premium(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_servicebus_namespace", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMServiceBusNamespace_premium(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "sku"), + resource.TestCheckResourceAttrSet(data.ResourceName, "capacity"), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_secondary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_secondary_key"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMServiceBusNamespace_basic(data acceptance.TestData) string { + template := testAccAzureRMServiceBusNamespace_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_servicebus_namespace" "test" { + name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template) +} + +func testAccDataSourceAzureRMServiceBusNamespace_premium(data acceptance.TestData) string { + template := testAccAzureRMServiceBusNamespace_premium(data) + return fmt.Sprintf(` +%s + +data "azurerm_servicebus_namespace" "test" { + name = "${azurerm_servicebus_namespace.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template) +} diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_authorization_rule_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_authorization_rule_test.go similarity index 68% rename from azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_authorization_rule_test.go rename to azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_authorization_rule_test.go index 38f1b2aaf943..d3411eb95ff9 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_authorization_rule_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_authorization_rule_test.go @@ -1,4 +1,4 @@ -package servicebus +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -32,7 +31,7 @@ func TestAccAzureRMServiceBusNamespaceAuthorizationRule_manage(t *testing.T) { } func testAccAzureRMServiceBusNamespaceAuthorizationRule(t *testing.T, listen, send, manage bool) { - resourceName := "azurerm_servicebus_namespace_authorization_rule.test" + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -40,32 +39,27 @@ func testAccAzureRMServiceBusNamespaceAuthorizationRule(t *testing.T, listen, se CheckDestroy: testCheckAzureRMServiceBusNamespaceAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusNamespaceAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), listen, send, manage), + Config: testAccAzureRMServiceBusNamespaceAuthorizationRule_base(data, listen, send, manage), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttr(resourceName, "listen", strconv.FormatBool(listen)), - resource.TestCheckResourceAttr(resourceName, "send", strconv.FormatBool(send)), - resource.TestCheckResourceAttr(resourceName, "manage", strconv.FormatBool(manage)), + testCheckAzureRMServiceBusNamespaceAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", strconv.FormatBool(listen)), + resource.TestCheckResourceAttr(data.ResourceName, "send", strconv.FormatBool(send)), + resource.TestCheckResourceAttr(data.ResourceName, "manage", strconv.FormatBool(manage)), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusNamespaceAuthorizationRule_rightsUpdate(t *testing.T) { - resourceName := "azurerm_servicebus_namespace_authorization_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -73,34 +67,30 @@ func TestAccAzureRMServiceBusNamespaceAuthorizationRule_rightsUpdate(t *testing. CheckDestroy: testCheckAzureRMServiceBusNamespaceAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusNamespaceAuthorizationRule_base(ri, acceptance.Location(), true, false, false), + Config: testAccAzureRMServiceBusNamespaceAuthorizationRule_base(data, true, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), + testCheckAzureRMServiceBusNamespaceAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), ), }, { - Config: testAccAzureRMServiceBusNamespaceAuthorizationRule_base(ri, acceptance.Location(), true, true, true), + Config: testAccAzureRMServiceBusNamespaceAuthorizationRule_base(data, true, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "true"), - resource.TestCheckResourceAttr(resourceName, "manage", "true"), + testCheckAzureRMServiceBusNamespaceAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -109,8 +99,7 @@ func TestAccAzureRMServiceBusNamespaceAuthorizationRule_requiresImport(t *testin t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_servicebus_namespace_authorization_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -118,16 +107,16 @@ func TestAccAzureRMServiceBusNamespaceAuthorizationRule_requiresImport(t *testin CheckDestroy: testCheckAzureRMServiceBusNamespaceAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusNamespaceAuthorizationRule_base(ri, acceptance.Location(), true, false, false), + Config: testAccAzureRMServiceBusNamespaceAuthorizationRule_base(data, true, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), + testCheckAzureRMServiceBusNamespaceAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), ), }, { - Config: testAccAzureRMServiceBusNamespaceAuthorizationRule_requiresImport(ri, acceptance.Location(), true, false, false), + Config: testAccAzureRMServiceBusNamespaceAuthorizationRule_requiresImport(data, true, false, false), ExpectError: acceptance.RequiresImportError("azurerm_servicebus_namespace_authorization_rule"), }, }, @@ -188,7 +177,7 @@ func testCheckAzureRMServiceBusNamespaceAuthorizationRuleExists(resourceName str } } -func testAccAzureRMServiceBusNamespaceAuthorizationRule_base(rInt int, location string, listen, send, manage bool) string { +func testAccAzureRMServiceBusNamespaceAuthorizationRule_base(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -211,10 +200,10 @@ resource "azurerm_servicebus_namespace_authorization_rule" "test" { send = %[4]t manage = %[5]t } -`, rInt, location, listen, send, manage) +`, data.RandomInteger, data.Locations.Primary, listen, send, manage) } -func testAccAzureRMServiceBusNamespaceAuthorizationRule_requiresImport(rInt int, location string, listen, send, manage bool) string { +func testAccAzureRMServiceBusNamespaceAuthorizationRule_requiresImport(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` %s @@ -227,5 +216,5 @@ resource "azurerm_servicebus_namespace_authorization_rule" "import" { send = "${azurerm_servicebus_namespace_authorization_rule.test.send}" manage = "${azurerm_servicebus_namespace_authorization_rule.test.manage}" } -`, testAccAzureRMServiceBusNamespaceAuthorizationRule_base(rInt, location, listen, send, manage)) +`, testAccAzureRMServiceBusNamespaceAuthorizationRule_base(data, listen, send, manage)) } diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_migration_test.go similarity index 92% rename from azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration_test.go rename to azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_migration_test.go index 2f4c2762c6b9..a654b230f8bc 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_migration_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_migration_test.go @@ -1,6 +1,7 @@ -package servicebus +package tests import ( + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/servicebus" "reflect" "testing" @@ -103,7 +104,7 @@ func TestAccAzureRMServiceBusNamespaceMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.Attributes, } - is, err := resourceAzureRMServiceBusNamespaceMigrateState(tc.StateVersion, is, nil) + is, err := servicebus.ResourceAzureRMServiceBusNamespaceMigrateState(tc.StateVersion, is, nil) if err != nil { t.Fatalf("bad: %q, err: %#v", tn, err) diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_test.go similarity index 71% rename from azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_test.go rename to azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_test.go index 37070be888ee..7edaf7cd1874 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_namespace_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_test.go @@ -1,4 +1,4 @@ -package servicebus +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMServiceBusNamespace_basic(t *testing.T) { - resourceName := "azurerm_servicebus_namespace.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusNamespace_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") + config := testAccAzureRMServiceBusNamespace_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,14 +25,10 @@ func TestAccAzureRMServiceBusNamespace_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists(resourceName), + testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,8 +37,7 @@ func TestAccAzureRMServiceBusNamespace_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_servicebus_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,23 +45,19 @@ func TestAccAzureRMServiceBusNamespace_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusNamespace_basic(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusNamespace_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists(resourceName), + testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), ), }, - { - Config: testAccAzureRMServiceBusNamespace_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_servicebus_namespace"), - }, + data.RequiresImportErrorStep(testAccAzureRMServiceBusNamespace_requiresImport), }, }) } func TestAccAzureRMServiceBusNamespace_readDefaultKeys(t *testing.T) { - resourceName := "azurerm_servicebus_namespace.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusNamespace_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") + config := testAccAzureRMServiceBusNamespace_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,15 +67,15 @@ func TestAccAzureRMServiceBusNamespace_readDefaultKeys(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists(resourceName), + testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), resource.TestMatchResourceAttr( - resourceName, "default_primary_connection_string", regexp.MustCompile("Endpoint=.+")), + data.ResourceName, "default_primary_connection_string", regexp.MustCompile("Endpoint=.+")), resource.TestMatchResourceAttr( - resourceName, "default_secondary_connection_string", regexp.MustCompile("Endpoint=.+")), + data.ResourceName, "default_secondary_connection_string", regexp.MustCompile("Endpoint=.+")), resource.TestMatchResourceAttr( - resourceName, "default_primary_key", regexp.MustCompile(".+")), + data.ResourceName, "default_primary_key", regexp.MustCompile(".+")), resource.TestMatchResourceAttr( - resourceName, "default_secondary_key", regexp.MustCompile(".+")), + data.ResourceName, "default_secondary_key", regexp.MustCompile(".+")), ), }, }, @@ -94,10 +83,8 @@ func TestAccAzureRMServiceBusNamespace_readDefaultKeys(t *testing.T) { } func TestAccAzureRMServiceBusNamespace_NonStandardCasing(t *testing.T) { - resourceName := "azurerm_servicebus_namespace.test" - - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusNamespaceNonStandardCasing(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") + config := testAccAzureRMServiceBusNamespaceNonStandardCasing(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -107,7 +94,7 @@ func TestAccAzureRMServiceBusNamespace_NonStandardCasing(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists(resourceName), + testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), ), }, { @@ -115,19 +102,14 @@ func TestAccAzureRMServiceBusNamespace_NonStandardCasing(t *testing.T) { PlanOnly: true, ExpectNonEmptyPlan: false, }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusNamespace_premium(t *testing.T) { - resourceName := "azurerm_servicebus_namespace.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusNamespace_premium(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") + config := testAccAzureRMServiceBusNamespace_premium(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -137,21 +119,17 @@ func TestAccAzureRMServiceBusNamespace_premium(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists(resourceName), + testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusNamespace_basicCapacity(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusNamespace_basicCapacity(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") + config := testAccAzureRMServiceBusNamespace_basicCapacity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -167,8 +145,8 @@ func TestAccAzureRMServiceBusNamespace_basicCapacity(t *testing.T) { } func TestAccAzureRMServiceBusNamespace_premiumCapacity(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusNamespace_premiumCapacity(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") + config := testAccAzureRMServiceBusNamespace_premiumCapacity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -184,9 +162,8 @@ func TestAccAzureRMServiceBusNamespace_premiumCapacity(t *testing.T) { } func TestAccAzureRMServiceBusNamespace_zoneRedundant(t *testing.T) { - resourceName := "azurerm_servicebus_namespace.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusNamespace_zoneRedundant(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") + config := testAccAzureRMServiceBusNamespace_zoneRedundant(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -196,15 +173,11 @@ func TestAccAzureRMServiceBusNamespace_zoneRedundant(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusNamespaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "zone_redundant", "true"), + testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "zone_redundant", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -265,7 +238,7 @@ func testCheckAzureRMServiceBusNamespaceExists(resourceName string) resource.Tes } } -func testAccAzureRMServiceBusNamespace_basic(rInt int, location string) string { +func testAccAzureRMServiceBusNamespace_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -278,10 +251,10 @@ resource "azurerm_servicebus_namespace" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "basic" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceBusNamespace_requiresImport(rInt int, location string) string { +func testAccAzureRMServiceBusNamespace_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -291,10 +264,10 @@ resource "azurerm_servicebus_namespace" "import" { resource_group_name = "${azurerm_servicebus_namespace.test.resource_group_name}" sku = "${azurerm_servicebus_namespace.test.sku}" } -`, testAccAzureRMServiceBusNamespace_basic(rInt, location)) +`, testAccAzureRMServiceBusNamespace_basic(data)) } -func testAccAzureRMServiceBusNamespaceNonStandardCasing(rInt int, location string) string { +func testAccAzureRMServiceBusNamespaceNonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -307,10 +280,10 @@ resource "azurerm_servicebus_namespace" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "Basic" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceBusNamespace_premium(rInt int, location string) string { +func testAccAzureRMServiceBusNamespace_premium(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -324,10 +297,10 @@ resource "azurerm_servicebus_namespace" "test" { sku = "Premium" capacity = 1 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceBusNamespace_basicCapacity(rInt int, location string) string { +func testAccAzureRMServiceBusNamespace_basicCapacity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -341,10 +314,10 @@ resource "azurerm_servicebus_namespace" "test" { sku = "Basic" capacity = 1 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceBusNamespace_premiumCapacity(rInt int, location string) string { +func testAccAzureRMServiceBusNamespace_premiumCapacity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -358,10 +331,10 @@ resource "azurerm_servicebus_namespace" "test" { sku = "Premium" capacity = 0 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMServiceBusNamespace_zoneRedundant(rInt int, location string) string { +func testAccAzureRMServiceBusNamespace_zoneRedundant(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -376,5 +349,5 @@ resource "azurerm_servicebus_namespace" "test" { capacity = 1 zone_redundant = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_queue_authorization_rule_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_queue_authorization_rule_test.go similarity index 66% rename from azurerm/internal/services/servicebus/resource_arm_servicebus_queue_authorization_rule_test.go rename to azurerm/internal/services/servicebus/tests/resource_arm_servicebus_queue_authorization_rule_test.go index 84ad347d2669..67e4395790fc 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_queue_authorization_rule_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_queue_authorization_rule_test.go @@ -1,4 +1,4 @@ -package servicebus +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -31,7 +30,7 @@ func TestAccAzureRMServiceBusQueueAuthorizationRule_manage(t *testing.T) { } func testAccAzureRMServiceBusQueueAuthorizationRule(t *testing.T, listen, send, manage bool) { - resourceName := "azurerm_servicebus_queue_authorization_rule.test" + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -39,33 +38,28 @@ func testAccAzureRMServiceBusQueueAuthorizationRule(t *testing.T, listen, send, CheckDestroy: testCheckAzureRMServiceBusQueueAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusQueueAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), listen, send, manage), + Config: testAccAzureRMServiceBusQueueAuthorizationRule_base(data, listen, send, manage), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "queue_name"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttr(resourceName, "listen", strconv.FormatBool(listen)), - resource.TestCheckResourceAttr(resourceName, "send", strconv.FormatBool(send)), - resource.TestCheckResourceAttr(resourceName, "manage", strconv.FormatBool(manage)), + testCheckAzureRMServiceBusQueueAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "queue_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", strconv.FormatBool(listen)), + resource.TestCheckResourceAttr(data.ResourceName, "send", strconv.FormatBool(send)), + resource.TestCheckResourceAttr(data.ResourceName, "manage", strconv.FormatBool(manage)), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusQueueAuthorizationRule_rightsUpdate(t *testing.T) { - resourceName := "azurerm_servicebus_queue_authorization_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -73,34 +67,30 @@ func TestAccAzureRMServiceBusQueueAuthorizationRule_rightsUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusQueueAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusQueueAuthorizationRule_base(ri, acceptance.Location(), true, false, false), + Config: testAccAzureRMServiceBusQueueAuthorizationRule_base(data, true, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), + testCheckAzureRMServiceBusQueueAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), ), }, { - Config: testAccAzureRMServiceBusQueueAuthorizationRule_base(ri, acceptance.Location(), true, true, true), + Config: testAccAzureRMServiceBusQueueAuthorizationRule_base(data, true, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "true"), - resource.TestCheckResourceAttr(resourceName, "manage", "true"), + testCheckAzureRMServiceBusQueueAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -109,8 +99,7 @@ func TestAccAzureRMServiceBusQueueAuthorizationRule_requiresImport(t *testing.T) t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_servicebus_queue_authorization_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -118,16 +107,16 @@ func TestAccAzureRMServiceBusQueueAuthorizationRule_requiresImport(t *testing.T) CheckDestroy: testCheckAzureRMServiceBusQueueAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusQueueAuthorizationRule_base(ri, acceptance.Location(), true, false, false), + Config: testAccAzureRMServiceBusQueueAuthorizationRule_base(data, true, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), + testCheckAzureRMServiceBusQueueAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), ), }, { - Config: testAccAzureRMServiceBusQueueAuthorizationRule_requiresImport(ri, acceptance.Location(), true, false, false), + Config: testAccAzureRMServiceBusQueueAuthorizationRule_requiresImport(data, true, false, false), ExpectError: acceptance.RequiresImportError("azurerm_servicebus_queue_authorization_rule"), }, }, @@ -191,7 +180,7 @@ func testCheckAzureRMServiceBusQueueAuthorizationRuleExists(resourceName string) } } -func testAccAzureRMServiceBusQueueAuthorizationRule_base(rInt int, location string, listen, send, manage bool) string { +func testAccAzureRMServiceBusQueueAuthorizationRule_base(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -223,10 +212,10 @@ resource "azurerm_servicebus_queue_authorization_rule" "test" { send = %[4]t manage = %[5]t } -`, rInt, location, listen, send, manage) +`, data.RandomInteger, data.Locations.Primary, listen, send, manage) } -func testAccAzureRMServiceBusQueueAuthorizationRule_requiresImport(rInt int, location string, listen, send, manage bool) string { +func testAccAzureRMServiceBusQueueAuthorizationRule_requiresImport(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` %s @@ -240,5 +229,5 @@ resource "azurerm_servicebus_queue_authorization_rule" "import" { send = "${azurerm_servicebus_queue_authorization_rule.test.send}" manage = "${azurerm_servicebus_queue_authorization_rule.test.manage}" } -`, testAccAzureRMServiceBusQueueAuthorizationRule_base(rInt, location, listen, send, manage)) +`, testAccAzureRMServiceBusQueueAuthorizationRule_base(data, listen, send, manage)) } diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go similarity index 74% rename from azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule_test.go rename to azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go index 1872b51f9cee..520c2d8e3fbb 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_rule_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_rule_test.go @@ -1,4 +1,4 @@ -package servicebus +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(t *testing.T) { - resourceName := "azurerm_servicebus_subscription_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,9 +21,9 @@ func TestAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), ), }, }, @@ -36,8 +34,7 @@ func TestAccAzureRMServiceBusSubscriptionRule_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_servicebus_subscription_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -45,22 +42,18 @@ func TestAccAzureRMServiceBusSubscriptionRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), ), }, - { - Config: testAccAzureRMServiceBusSubscriptionRule_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_servicebus_subscription_rule"), - }, + data.RequiresImportErrorStep(testAccAzureRMServiceBusSubscriptionRule_requiresImport), }, }) } func TestAccAzureRMServiceBusSubscriptionRule_basicCorrelationFilter(t *testing.T) { - resourceName := "azurerm_servicebus_subscription_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -68,9 +61,9 @@ func TestAccAzureRMServiceBusSubscriptionRule_basicCorrelationFilter(t *testing. CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusSubscriptionRule_basicCorrelationFilter(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusSubscriptionRule_basicCorrelationFilter(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), ), }, }, @@ -78,8 +71,7 @@ func TestAccAzureRMServiceBusSubscriptionRule_basicCorrelationFilter(t *testing. } func TestAccAzureRMServiceBusSubscriptionRule_sqlFilterWithAction(t *testing.T) { - resourceName := "azurerm_servicebus_subscription_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,9 +79,9 @@ func TestAccAzureRMServiceBusSubscriptionRule_sqlFilterWithAction(t *testing.T) CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusSubscriptionRule_sqlFilterWithAction(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusSubscriptionRule_sqlFilterWithAction(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), ), }, }, @@ -97,8 +89,7 @@ func TestAccAzureRMServiceBusSubscriptionRule_sqlFilterWithAction(t *testing.T) } func TestAccAzureRMServiceBusSubscriptionRule_correlationFilterWithAction(t *testing.T) { - resourceName := "azurerm_servicebus_subscription_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -106,9 +97,9 @@ func TestAccAzureRMServiceBusSubscriptionRule_correlationFilterWithAction(t *tes CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusSubscriptionRule_correlationFilterWithAction(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusSubscriptionRule_correlationFilterWithAction(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), ), }, }, @@ -116,11 +107,9 @@ func TestAccAzureRMServiceBusSubscriptionRule_correlationFilterWithAction(t *tes } func TestAccAzureRMServiceBusSubscriptionRule_sqlFilterUpdated(t *testing.T) { - resourceName := "azurerm_servicebus_subscription_rule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(ri, location) - updatedConfig := testAccAzureRMServiceBusSubscriptionRule_basicSqlFilterUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription_rule", "test") + config := testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(data) + updatedConfig := testAccAzureRMServiceBusSubscriptionRule_basicSqlFilterUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -130,15 +119,15 @@ func TestAccAzureRMServiceBusSubscriptionRule_sqlFilterUpdated(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sql_filter", "2=2"), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sql_filter", "2=2"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sql_filter", "3=3"), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sql_filter", "3=3"), ), }, }, @@ -146,11 +135,9 @@ func TestAccAzureRMServiceBusSubscriptionRule_sqlFilterUpdated(t *testing.T) { } func TestAccAzureRMServiceBusSubscriptionRule_correlationFilterUpdated(t *testing.T) { - resourceName := "azurerm_servicebus_subscription_rule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMServiceBusSubscriptionRule_correlationFilter(ri, location) - updatedConfig := testAccAzureRMServiceBusSubscriptionRule_correlationFilterUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription_rule", "test") + config := testAccAzureRMServiceBusSubscriptionRule_correlationFilter(data) + updatedConfig := testAccAzureRMServiceBusSubscriptionRule_correlationFilterUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -160,17 +147,17 @@ func TestAccAzureRMServiceBusSubscriptionRule_correlationFilterUpdated(t *testin { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "correlation_filter.0.message_id", "test_message_id"), - resource.TestCheckResourceAttr(resourceName, "correlation_filter.0.reply_to", ""), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "correlation_filter.0.message_id", "test_message_id"), + resource.TestCheckResourceAttr(data.ResourceName, "correlation_filter.0.reply_to", ""), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "correlation_filter.0.message_id", "test_message_id_updated"), - resource.TestCheckResourceAttr(resourceName, "correlation_filter.0.reply_to", "test_reply_to_added"), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "correlation_filter.0.message_id", "test_message_id_updated"), + resource.TestCheckResourceAttr(data.ResourceName, "correlation_filter.0.reply_to", "test_reply_to_added"), ), }, }, @@ -178,11 +165,9 @@ func TestAccAzureRMServiceBusSubscriptionRule_correlationFilterUpdated(t *testin } func TestAccAzureRMServiceBusSubscriptionRule_updateSqlFilterToCorrelationFilter(t *testing.T) { - resourceName := "azurerm_servicebus_subscription_rule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(ri, location) - updatedConfig := testAccAzureRMServiceBusSubscriptionRule_basicCorrelationFilter(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription_rule", "test") + config := testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(data) + updatedConfig := testAccAzureRMServiceBusSubscriptionRule_basicCorrelationFilter(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -192,13 +177,13 @@ func TestAccAzureRMServiceBusSubscriptionRule_updateSqlFilterToCorrelationFilter { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName), + testCheckAzureRMServiceBusSubscriptionRuleExists(data.ResourceName), ), }, }, @@ -237,8 +222,8 @@ func testCheckAzureRMServiceBusSubscriptionRuleExists(resourceName string) resou } } -func testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(rInt int, location string) string { - template := testAccAzureRMServiceBusSubscriptionRule_template(rInt, location) +func testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(data acceptance.TestData) string { + template := testAccAzureRMServiceBusSubscriptionRule_template(data) return fmt.Sprintf(` %s @@ -251,10 +236,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { filter_type = "SqlFilter" sql_filter = "2=2" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMServiceBusSubscriptionRule_requiresImport(rInt int, location string) string { +func testAccAzureRMServiceBusSubscriptionRule_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -267,11 +252,11 @@ resource "azurerm_servicebus_subscription_rule" "import" { filter_type = "${azurerm_servicebus_subscription_rule.test.filter_type}" sql_filter = "${azurerm_servicebus_subscription_rule.test.sql_filter}" } -`, testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(rInt, location)) +`, testAccAzureRMServiceBusSubscriptionRule_basicSqlFilter(data)) } -func testAccAzureRMServiceBusSubscriptionRule_basicSqlFilterUpdated(rInt int, location string) string { - template := testAccAzureRMServiceBusSubscriptionRule_template(rInt, location) +func testAccAzureRMServiceBusSubscriptionRule_basicSqlFilterUpdated(data acceptance.TestData) string { + template := testAccAzureRMServiceBusSubscriptionRule_template(data) return fmt.Sprintf(` %s @@ -284,11 +269,11 @@ resource "azurerm_servicebus_subscription_rule" "test" { filter_type = "SqlFilter" sql_filter = "3=3" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMServiceBusSubscriptionRule_sqlFilterWithAction(rInt int, location string) string { - template := testAccAzureRMServiceBusSubscriptionRule_template(rInt, location) +func testAccAzureRMServiceBusSubscriptionRule_sqlFilterWithAction(data acceptance.TestData) string { + template := testAccAzureRMServiceBusSubscriptionRule_template(data) return fmt.Sprintf(` %s @@ -302,11 +287,11 @@ resource "azurerm_servicebus_subscription_rule" "test" { sql_filter = "2=2" action = "SET Test='true'" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMServiceBusSubscriptionRule_basicCorrelationFilter(rInt int, location string) string { - template := testAccAzureRMServiceBusSubscriptionRule_template(rInt, location) +func testAccAzureRMServiceBusSubscriptionRule_basicCorrelationFilter(data acceptance.TestData) string { + template := testAccAzureRMServiceBusSubscriptionRule_template(data) return fmt.Sprintf(` %s @@ -329,11 +314,11 @@ resource "azurerm_servicebus_subscription_rule" "test" { content_type = "test_content_type" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMServiceBusSubscriptionRule_correlationFilter(rInt int, location string) string { - template := testAccAzureRMServiceBusSubscriptionRule_template(rInt, location) +func testAccAzureRMServiceBusSubscriptionRule_correlationFilter(data acceptance.TestData) string { + template := testAccAzureRMServiceBusSubscriptionRule_template(data) return fmt.Sprintf(` %s @@ -350,11 +335,11 @@ resource "azurerm_servicebus_subscription_rule" "test" { message_id = "test_message_id" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMServiceBusSubscriptionRule_correlationFilterUpdated(rInt int, location string) string { - template := testAccAzureRMServiceBusSubscriptionRule_template(rInt, location) +func testAccAzureRMServiceBusSubscriptionRule_correlationFilterUpdated(data acceptance.TestData) string { + template := testAccAzureRMServiceBusSubscriptionRule_template(data) return fmt.Sprintf(` %s @@ -372,11 +357,11 @@ resource "azurerm_servicebus_subscription_rule" "test" { reply_to = "test_reply_to_added" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMServiceBusSubscriptionRule_correlationFilterWithAction(rInt int, location string) string { - template := testAccAzureRMServiceBusSubscriptionRule_template(rInt, location) +func testAccAzureRMServiceBusSubscriptionRule_correlationFilterWithAction(data acceptance.TestData) string { + template := testAccAzureRMServiceBusSubscriptionRule_template(data) return fmt.Sprintf(` %s @@ -394,10 +379,10 @@ resource "azurerm_servicebus_subscription_rule" "test" { message_id = "test_message_id" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMServiceBusSubscriptionRule_template(rInt int, location string) string { +func testAccAzureRMServiceBusSubscriptionRule_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -424,5 +409,5 @@ resource "azurerm_servicebus_subscription" "test" { resource_group_name = "${azurerm_resource_group.test.name}" max_delivery_count = 10 } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_test.go similarity index 69% rename from azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_test.go rename to azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_test.go index adf30315e3f1..99864caef42b 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_subscription_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_subscription_test.go @@ -1,4 +1,4 @@ -package servicebus +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +14,7 @@ import ( ) func TestAccAzureRMServiceBusSubscription_basic(t *testing.T) { - resourceName := "azurerm_servicebus_subscription.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +22,12 @@ func TestAccAzureRMServiceBusSubscription_basic(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusSubscription_basic(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusSubscription_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionExists(resourceName), + testCheckAzureRMServiceBusSubscriptionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,8 +37,7 @@ func TestAccAzureRMServiceBusSubscription_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_servicebus_subscription.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,23 +45,19 @@ func TestAccAzureRMServiceBusSubscription_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusSubscription_basic(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusSubscription_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionExists(resourceName), + testCheckAzureRMServiceBusSubscriptionExists(data.ResourceName), ), }, - { - Config: testAccAzureRMServiceBusSubscription_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_servicebus_subscription"), - }, + data.RequiresImportErrorStep(testAccAzureRMServiceBusSubscription_requiresImport), }, }) } func TestAccAzureRMServiceBusSubscription_defaultTtl(t *testing.T) { - resourceName := "azurerm_servicebus_subscription.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusSubscription_withDefaultTtl(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription", "test") + config := testAccAzureRMServiceBusSubscription_withDefaultTtl(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,25 +67,19 @@ func TestAccAzureRMServiceBusSubscription_defaultTtl(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionExists(resourceName), + testCheckAzureRMServiceBusSubscriptionExists(data.ResourceName), resource.TestCheckResourceAttr("azurerm_servicebus_subscription.test", "default_message_ttl", "PT1H"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusSubscription_updateEnableBatched(t *testing.T) { - resourceName := "azurerm_servicebus_subscription.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusSubscription_basic(ri, location) - postConfig := testAccAzureRMServiceBusSubscription_updateEnableBatched(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription", "test") + preConfig := testAccAzureRMServiceBusSubscription_basic(data) + postConfig := testAccAzureRMServiceBusSubscription_updateEnableBatched(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -106,30 +89,24 @@ func TestAccAzureRMServiceBusSubscription_updateEnableBatched(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionExists(resourceName), + testCheckAzureRMServiceBusSubscriptionExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "enable_batched_operations", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_batched_operations", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusSubscription_updateRequiresSession(t *testing.T) { - resourceName := "azurerm_servicebus_subscription.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusSubscription_basic(ri, location) - postConfig := testAccAzureRMServiceBusSubscription_updateRequiresSession(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription", "test") + preConfig := testAccAzureRMServiceBusSubscription_basic(data) + postConfig := testAccAzureRMServiceBusSubscription_updateRequiresSession(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -139,32 +116,26 @@ func TestAccAzureRMServiceBusSubscription_updateRequiresSession(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionExists(resourceName), + testCheckAzureRMServiceBusSubscriptionExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "requires_session", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "requires_session", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusSubscription_updateForwardTo(t *testing.T) { - resourceName := "azurerm_servicebus_subscription.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusSubscription_basic(ri, location) - postConfig := testAccAzureRMServiceBusSubscription_updateForwardTo(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription", "test") + preConfig := testAccAzureRMServiceBusSubscription_basic(data) + postConfig := testAccAzureRMServiceBusSubscription_updateForwardTo(data) - expectedValue := fmt.Sprintf("acctestservicebustopic-forward_to-%d", ri) + expectedValue := fmt.Sprintf("acctestservicebustopic-forward_to-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,32 +145,26 @@ func TestAccAzureRMServiceBusSubscription_updateForwardTo(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionExists(resourceName), + testCheckAzureRMServiceBusSubscriptionExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "forward_to", expectedValue), + resource.TestCheckResourceAttr(data.ResourceName, "forward_to", expectedValue), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusSubscription_updateForwardDeadLetteredMessagesTo(t *testing.T) { - resourceName := "azurerm_servicebus_subscription.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusSubscription_basic(ri, location) - postConfig := testAccAzureRMServiceBusSubscription_updateForwardDeadLetteredMessagesTo(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_subscription", "test") + preConfig := testAccAzureRMServiceBusSubscription_basic(data) + postConfig := testAccAzureRMServiceBusSubscription_updateForwardDeadLetteredMessagesTo(data) - expectedValue := fmt.Sprintf("acctestservicebustopic-forward_dl_messages_to-%d", ri) + expectedValue := fmt.Sprintf("acctestservicebustopic-forward_dl_messages_to-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -209,20 +174,16 @@ func TestAccAzureRMServiceBusSubscription_updateForwardDeadLetteredMessagesTo(t { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusSubscriptionExists(resourceName), + testCheckAzureRMServiceBusSubscriptionExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "forward_dead_lettered_messages_to", expectedValue), + resource.TestCheckResourceAttr(data.ResourceName, "forward_dead_lettered_messages_to", expectedValue), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -318,11 +279,11 @@ resource "azurerm_servicebus_subscription" "test" { } ` -func testAccAzureRMServiceBusSubscription_basic(rInt int, location string) string { - return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, rInt, location, rInt, rInt, rInt, "") +func testAccAzureRMServiceBusSubscription_basic(data acceptance.TestData) string { + return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, "") } -func testAccAzureRMServiceBusSubscription_requiresImport(rInt int, location string) string { +func testAccAzureRMServiceBusSubscription_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -334,25 +295,25 @@ resource "azurerm_servicebus_subscription" "import" { resource_group_name = "${azurerm_servicebus_subscription.test.resource_group_name}" max_delivery_count = "${azurerm_servicebus_subscription.test.max_delivery_count}" } -`, testAccAzureRMServiceBusSubscription_basic(rInt, location)) +`, testAccAzureRMServiceBusSubscription_basic(data)) } -func testAccAzureRMServiceBusSubscription_withDefaultTtl(rInt int, location string) string { - return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, rInt, location, rInt, rInt, rInt, +func testAccAzureRMServiceBusSubscription_withDefaultTtl(data acceptance.TestData) string { + return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, "default_message_ttl = \"PT1H\"\n") } -func testAccAzureRMServiceBusSubscription_updateEnableBatched(rInt int, location string) string { - return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, rInt, location, rInt, rInt, rInt, +func testAccAzureRMServiceBusSubscription_updateEnableBatched(data acceptance.TestData) string { + return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, "enable_batched_operations = true\n") } -func testAccAzureRMServiceBusSubscription_updateRequiresSession(rInt int, location string) string { - return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, rInt, location, rInt, rInt, rInt, +func testAccAzureRMServiceBusSubscription_updateRequiresSession(data acceptance.TestData) string { + return fmt.Sprintf(testAccAzureRMServiceBusSubscription_tfTemplate, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, "requires_session = true\n") } -func testAccAzureRMServiceBusSubscription_updateForwardTo(rInt int, location string) string { +func testAccAzureRMServiceBusSubscription_updateForwardTo(data acceptance.TestData) string { forwardToTf := testAccAzureRMServiceBusSubscription_tfTemplate + ` resource "azurerm_servicebus_topic" "forward_to" { @@ -362,11 +323,11 @@ resource "azurerm_servicebus_topic" "forward_to" { } ` - return fmt.Sprintf(forwardToTf, rInt, location, rInt, rInt, rInt, - "forward_to = \"${azurerm_servicebus_topic.forward_to.name}\"\n", rInt) + return fmt.Sprintf(forwardToTf, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, + "forward_to = \"${azurerm_servicebus_topic.forward_to.name}\"\n", data.RandomInteger) } -func testAccAzureRMServiceBusSubscription_updateForwardDeadLetteredMessagesTo(rInt int, location string) string { +func testAccAzureRMServiceBusSubscription_updateForwardDeadLetteredMessagesTo(data acceptance.TestData) string { forwardToTf := testAccAzureRMServiceBusSubscription_tfTemplate + ` resource "azurerm_servicebus_topic" "forward_dl_messages_to" { @@ -376,6 +337,6 @@ resource "azurerm_servicebus_topic" "forward_dl_messages_to" { } ` - return fmt.Sprintf(forwardToTf, rInt, location, rInt, rInt, rInt, - "forward_dead_lettered_messages_to = \"${azurerm_servicebus_topic.forward_dl_messages_to.name}\"\n", rInt) + return fmt.Sprintf(forwardToTf, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, + "forward_dead_lettered_messages_to = \"${azurerm_servicebus_topic.forward_dl_messages_to.name}\"\n", data.RandomInteger) } diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_topic_authorization_rule_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_topic_authorization_rule_test.go similarity index 67% rename from azurerm/internal/services/servicebus/resource_arm_servicebus_topic_authorization_rule_test.go rename to azurerm/internal/services/servicebus/tests/resource_arm_servicebus_topic_authorization_rule_test.go index 662d6df6fec0..f3344df845eb 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_topic_authorization_rule_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_topic_authorization_rule_test.go @@ -1,4 +1,4 @@ -package servicebus +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -31,7 +30,7 @@ func TestAccAzureRMServiceBusTopicAuthorizationRule_manage(t *testing.T) { } func testAccAzureRMServiceBusTopicAuthorizationRule(t *testing.T, listen, send, manage bool) { - resourceName := "azurerm_servicebus_topic_authorization_rule.test" + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -39,25 +38,21 @@ func testAccAzureRMServiceBusTopicAuthorizationRule(t *testing.T, listen, send, CheckDestroy: testCheckAzureRMServiceBusTopicAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusTopicAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), listen, send, manage), + Config: testAccAzureRMServiceBusTopicAuthorizationRule_base(data, listen, send, manage), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttr(resourceName, "listen", strconv.FormatBool(listen)), - resource.TestCheckResourceAttr(resourceName, "send", strconv.FormatBool(send)), - resource.TestCheckResourceAttr(resourceName, "manage", strconv.FormatBool(manage)), + testCheckAzureRMServiceBusTopicAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", strconv.FormatBool(listen)), + resource.TestCheckResourceAttr(data.ResourceName, "send", strconv.FormatBool(send)), + resource.TestCheckResourceAttr(data.ResourceName, "manage", strconv.FormatBool(manage)), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -67,8 +62,7 @@ func TestAccAzureRMServiceBusTopicAuthorizationRule_requiresImport(t *testing.T) t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_servicebus_topic_authorization_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -76,16 +70,16 @@ func TestAccAzureRMServiceBusTopicAuthorizationRule_requiresImport(t *testing.T) CheckDestroy: testCheckAzureRMServiceBusTopicAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusTopicAuthorizationRule_base(ri, acceptance.Location(), true, false, false), + Config: testAccAzureRMServiceBusTopicAuthorizationRule_base(data, true, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), + testCheckAzureRMServiceBusTopicAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), ), }, { - Config: testAccAzureRMServiceBusTopicAuthorizationRule_requiresImport(ri, acceptance.Location(), true, false, false), + Config: testAccAzureRMServiceBusTopicAuthorizationRule_requiresImport(data, true, false, false), ExpectError: acceptance.RequiresImportError("azurerm_servicebus_topic_authorization_rule"), }, }, @@ -93,8 +87,7 @@ func TestAccAzureRMServiceBusTopicAuthorizationRule_requiresImport(t *testing.T) } func TestAccAzureRMServiceBusTopicAuthorizationRule_rightsUpdate(t *testing.T) { - resourceName := "azurerm_servicebus_topic_authorization_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -102,34 +95,30 @@ func TestAccAzureRMServiceBusTopicAuthorizationRule_rightsUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusTopicAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusTopicAuthorizationRule_base(ri, acceptance.Location(), true, false, false), + Config: testAccAzureRMServiceBusTopicAuthorizationRule_base(data, true, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), + testCheckAzureRMServiceBusTopicAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), ), }, { - Config: testAccAzureRMServiceBusTopicAuthorizationRule_base(ri, acceptance.Location(), true, true, true), + Config: testAccAzureRMServiceBusTopicAuthorizationRule_base(data, true, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "true"), - resource.TestCheckResourceAttr(resourceName, "manage", "true"), + testCheckAzureRMServiceBusTopicAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -190,7 +179,7 @@ func testCheckAzureRMServiceBusTopicAuthorizationRuleExists(resourceName string) } } -func testAccAzureRMServiceBusTopicAuthorizationRule_base(rInt int, location string, listen, send, manage bool) string { +func testAccAzureRMServiceBusTopicAuthorizationRule_base(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -220,10 +209,10 @@ resource "azurerm_servicebus_topic_authorization_rule" "test" { send = %[4]t manage = %[5]t } -`, rInt, location, listen, send, manage) +`, data.RandomInteger, data.Locations.Primary, listen, send, manage) } -func testAccAzureRMServiceBusTopicAuthorizationRule_requiresImport(rInt int, location string, listen, send, manage bool) string { +func testAccAzureRMServiceBusTopicAuthorizationRule_requiresImport(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` %s @@ -237,5 +226,5 @@ resource "azurerm_servicebus_topic_authorization_rule" "import" { send = "${azurerm_servicebus_topic_authorization_rule.test.send}" manage = "${azurerm_servicebus_topic_authorization_rule.test.manage}" } -`, testAccAzureRMServiceBusTopicAuthorizationRule_base(rInt, location, listen, send, manage)) +`, testAccAzureRMServiceBusTopicAuthorizationRule_base(data, listen, send, manage)) } diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_topic_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_topic_test.go similarity index 71% rename from azurerm/internal/services/servicebus/resource_arm_servicebus_topic_test.go rename to azurerm/internal/services/servicebus/tests/resource_arm_servicebus_topic_test.go index 76ffee51b078..f65cea83a197 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_topic_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_topic_test.go @@ -1,4 +1,4 @@ -package servicebus +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +14,7 @@ import ( ) func TestAccAzureRMServiceBusTopic_basic(t *testing.T) { - resourceName := "azurerm_servicebus_topic.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +22,12 @@ func TestAccAzureRMServiceBusTopic_basic(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusTopic_basic(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusTopic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -42,8 +36,7 @@ func TestAccAzureRMServiceBusTopic_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_servicebus_topic.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,13 +44,13 @@ func TestAccAzureRMServiceBusTopic_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusTopic_basic(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusTopic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), ), }, { - Config: testAccAzureRMServiceBusTopic_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusTopic_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_service_fabric_cluster"), }, }, @@ -65,8 +58,7 @@ func TestAccAzureRMServiceBusTopic_requiresImport(t *testing.T) { } func TestAccAzureRMServiceBusTopic_basicDisabled(t *testing.T) { - resourceName := "azurerm_servicebus_topic.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,26 +66,20 @@ func TestAccAzureRMServiceBusTopic_basicDisabled(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusTopic_basicDisabled(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusTopic_basicDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusTopic_basicDisableEnable(t *testing.T) { - resourceName := "azurerm_servicebus_topic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - enabledConfig := testAccAzureRMServiceBusTopic_basic(ri, location) - disabledConfig := testAccAzureRMServiceBusTopic_basicDisabled(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic", "test") + enabledConfig := testAccAzureRMServiceBusTopic_basic(data) + disabledConfig := testAccAzureRMServiceBusTopic_basicDisabled(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -103,19 +89,19 @@ func TestAccAzureRMServiceBusTopic_basicDisableEnable(t *testing.T) { { Config: enabledConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), ), }, { Config: disabledConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), ), }, { Config: enabledConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), ), }, }, @@ -123,11 +109,9 @@ func TestAccAzureRMServiceBusTopic_basicDisableEnable(t *testing.T) { } func TestAccAzureRMServiceBusTopic_update(t *testing.T) { - resourceName := "azurerm_servicebus_topic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusTopic_basic(ri, location) - postConfig := testAccAzureRMServiceBusTopic_update(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic", "test") + preConfig := testAccAzureRMServiceBusTopic_basic(data) + postConfig := testAccAzureRMServiceBusTopic_update(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -137,14 +121,14 @@ func TestAccAzureRMServiceBusTopic_update(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "enable_batched_operations", "true"), - resource.TestCheckResourceAttr(resourceName, "enable_express", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_batched_operations", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_express", "true"), ), }, }, @@ -152,11 +136,9 @@ func TestAccAzureRMServiceBusTopic_update(t *testing.T) { } func TestAccAzureRMServiceBusTopic_enablePartitioningStandard(t *testing.T) { - resourceName := "azurerm_servicebus_topic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusTopic_basic(ri, location) - postConfig := testAccAzureRMServiceBusTopic_enablePartitioningStandard(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic", "test") + preConfig := testAccAzureRMServiceBusTopic_basic(data) + postConfig := testAccAzureRMServiceBusTopic_enablePartitioningStandard(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -166,32 +148,26 @@ func TestAccAzureRMServiceBusTopic_enablePartitioningStandard(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_partitioning", "true"), // Ensure size is read back in it's original value and not the x16 value returned by Azure - resource.TestCheckResourceAttr(resourceName, "max_size_in_megabytes", "5120"), + resource.TestCheckResourceAttr(data.ResourceName, "max_size_in_megabytes", "5120"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusTopic_enablePartitioningPremium(t *testing.T) { - resourceName := "azurerm_servicebus_topic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusTopic_basicPremium(ri, location) - postConfig := testAccAzureRMServiceBusTopic_enablePartitioningPremium(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic", "test") + preConfig := testAccAzureRMServiceBusTopic_basicPremium(data) + postConfig := testAccAzureRMServiceBusTopic_enablePartitioningPremium(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -201,31 +177,25 @@ func TestAccAzureRMServiceBusTopic_enablePartitioningPremium(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "false"), - resource.TestCheckResourceAttr(resourceName, "max_size_in_megabytes", "81920"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_partitioning", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "max_size_in_megabytes", "81920"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusTopic_enableDuplicateDetection(t *testing.T) { - resourceName := "azurerm_servicebus_topic.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusTopic_basic(ri, location) - postConfig := testAccAzureRMServiceBusTopic_enableDuplicateDetection(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic", "test") + preConfig := testAccAzureRMServiceBusTopic_basic(data) + postConfig := testAccAzureRMServiceBusTopic_enableDuplicateDetection(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -235,28 +205,23 @@ func TestAccAzureRMServiceBusTopic_enableDuplicateDetection(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "requires_duplicate_detection", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "requires_duplicate_detection", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusTopic_isoTimeSpanAttributes(t *testing.T) { - resourceName := "azurerm_servicebus_topic.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusTopic_isoTimeSpanAttributes(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_servicebus_topic", "test") + config := testAccAzureRMServiceBusTopic_isoTimeSpanAttributes(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -266,18 +231,14 @@ func TestAccAzureRMServiceBusTopic_isoTimeSpanAttributes(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusTopicExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_delete_on_idle", "PT10M"), - resource.TestCheckResourceAttr(resourceName, "default_message_ttl", "PT30M"), - resource.TestCheckResourceAttr(resourceName, "requires_duplicate_detection", "true"), - resource.TestCheckResourceAttr(resourceName, "duplicate_detection_history_time_window", "PT15M"), + testCheckAzureRMServiceBusTopicExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_delete_on_idle", "PT10M"), + resource.TestCheckResourceAttr(data.ResourceName, "default_message_ttl", "PT30M"), + resource.TestCheckResourceAttr(data.ResourceName, "requires_duplicate_detection", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "duplicate_detection_history_time_window", "PT15M"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -342,7 +303,7 @@ func testCheckAzureRMServiceBusTopicExists(resourceName string) resource.TestChe } } -func testAccAzureRMServiceBusTopic_basic(rInt int, location string) string { +func testAccAzureRMServiceBusTopic_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -361,10 +322,10 @@ resource "azurerm_servicebus_topic" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusTopic_requiresImport(rInt int, location string) string { +func testAccAzureRMServiceBusTopic_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -373,10 +334,10 @@ resource "azurerm_servicebus_topic" "import" { namespace_name = "${azurerm_servicebus_topic.test.namespace_name}" resource_group_name = "${azurerm_servicebus_topic.test.resource_group_name}" } -`, testAccAzureRMServiceBusTopic_basic(rInt, location)) +`, testAccAzureRMServiceBusTopic_basic(data)) } -func testAccAzureRMServiceBusTopic_basicDisabled(rInt int, location string) string { +func testAccAzureRMServiceBusTopic_basicDisabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -396,10 +357,10 @@ resource "azurerm_servicebus_topic" "test" { resource_group_name = "${azurerm_resource_group.test.name}" status = "disabled" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusTopic_update(rInt int, location string) string { +func testAccAzureRMServiceBusTopic_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -420,10 +381,10 @@ resource "azurerm_servicebus_topic" "test" { enable_batched_operations = true enable_express = true } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusTopic_basicPremium(rInt int, location string) string { +func testAccAzureRMServiceBusTopic_basicPremium(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -444,10 +405,10 @@ resource "azurerm_servicebus_topic" "test" { resource_group_name = "${azurerm_resource_group.test.name}" enable_partitioning = false } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusTopic_enablePartitioningStandard(rInt int, location string) string { +func testAccAzureRMServiceBusTopic_enablePartitioningStandard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -468,10 +429,10 @@ resource "azurerm_servicebus_topic" "test" { enable_partitioning = true max_size_in_megabytes = 5120 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusTopic_enablePartitioningPremium(rInt int, location string) string { +func testAccAzureRMServiceBusTopic_enablePartitioningPremium(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -493,10 +454,10 @@ resource "azurerm_servicebus_topic" "test" { enable_partitioning = false max_size_in_megabytes = 81920 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusTopic_enableDuplicateDetection(rInt int, location string) string { +func testAccAzureRMServiceBusTopic_enableDuplicateDetection(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -516,10 +477,10 @@ resource "azurerm_servicebus_topic" "test" { resource_group_name = "${azurerm_resource_group.test.name}" requires_duplicate_detection = true } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusTopic_isoTimeSpanAttributes(rInt int, location string) string { +func testAccAzureRMServiceBusTopic_isoTimeSpanAttributes(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -542,5 +503,5 @@ resource "azurerm_servicebus_topic" "test" { requires_duplicate_detection = true duplicate_detection_history_time_window = "PT15M" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } From 62f59d2c99b09d498826aabfcba64b7fb314e895 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 20 Dec 2019 20:29:29 -0800 Subject: [PATCH 107/203] media: switching to the new test structure --- ...esource_arm_media_services_account_test.go | 71 ++++++++----------- 1 file changed, 28 insertions(+), 43 deletions(-) rename azurerm/internal/services/media/{ => tests}/resource_arm_media_services_account_test.go (77%) diff --git a/azurerm/internal/services/media/resource_arm_media_services_account_test.go b/azurerm/internal/services/media/tests/resource_arm_media_services_account_test.go similarity index 77% rename from azurerm/internal/services/media/resource_arm_media_services_account_test.go rename to azurerm/internal/services/media/tests/resource_arm_media_services_account_test.go index 3cc9c052ad3e..6e9066b1a64b 100644 --- a/azurerm/internal/services/media/resource_arm_media_services_account_test.go +++ b/azurerm/internal/services/media/tests/resource_arm_media_services_account_test.go @@ -1,4 +1,4 @@ -package media +package tests import ( "fmt" @@ -6,18 +6,14 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMMediaServicesAccount_basic(t *testing.T) { - resourceName := "azurerm_media_services_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) + data := acceptance.BuildTestData(t, "azurerm_media_services_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,25 +21,18 @@ func TestAccAzureRMMediaServicesAccount_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMediaServicesAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMediaServicesAccount_basic(ri, rs, acceptance.Location()), + Config: testAccAzureRMMediaServicesAccount_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "storage_account.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_account.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMediaServicesAccount_multipleAccounts(t *testing.T) { - resourceName := "azurerm_media_services_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_media_services_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,35 +40,31 @@ func TestAccAzureRMMediaServicesAccount_multipleAccounts(t *testing.T) { CheckDestroy: testCheckAzureRMMediaServicesAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMediaServicesAccount_multipleAccounts(ri, rs, location), + Config: testAccAzureRMMediaServicesAccount_multipleAccounts(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMMediaServicesAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_account.#", "2"), + testCheckAzureRMMediaServicesAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_account.#", "2"), ), }, { - Config: testAccAzureRMMediaServicesAccount_multipleAccountsUpdated(ri, rs, location), + Config: testAccAzureRMMediaServicesAccount_multipleAccountsUpdated(data), PlanOnly: true, }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMediaServicesAccount_multiplePrimaries(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) + data := acceptance.BuildTestData(t, "azurerm_media_services_account", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMMediaServicesAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMediaServicesAccount_multiplePrimaries(ri, rs, acceptance.Location()), + Config: testAccAzureRMMediaServicesAccount_multiplePrimaries(data), ExpectError: regexp.MustCompile("Only one Storage Account can be set as Primary"), }, }, @@ -142,8 +127,8 @@ func testCheckAzureRMMediaServicesAccountDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMediaServicesAccount_basic(rInt int, rString, location string) string { - template := testAccAzureRMMediaServicesAccount_template(rInt, rString, location) +func testAccAzureRMMediaServicesAccount_basic(data acceptance.TestData) string { + template := testAccAzureRMMediaServicesAccount_template(data) return fmt.Sprintf(` %s @@ -157,11 +142,11 @@ resource "azurerm_media_services_account" "test" { is_primary = true } } -`, template, rString) +`, template, data.RandomString) } -func testAccAzureRMMediaServicesAccount_multipleAccounts(rInt int, rString, location string) string { - template := testAccAzureRMMediaServicesAccount_template(rInt, rString, location) +func testAccAzureRMMediaServicesAccount_multipleAccounts(data acceptance.TestData) string { + template := testAccAzureRMMediaServicesAccount_template(data) return fmt.Sprintf(` %s @@ -188,11 +173,11 @@ resource "azurerm_media_services_account" "test" { is_primary = false } } -`, template, rString, rString) +`, template, data.RandomString, data.RandomString) } -func testAccAzureRMMediaServicesAccount_multipleAccountsUpdated(rInt int, rString, location string) string { - template := testAccAzureRMMediaServicesAccount_template(rInt, rString, location) +func testAccAzureRMMediaServicesAccount_multipleAccountsUpdated(data acceptance.TestData) string { + template := testAccAzureRMMediaServicesAccount_template(data) return fmt.Sprintf(` %s @@ -219,11 +204,11 @@ resource "azurerm_media_services_account" "test" { is_primary = true } } -`, template, rString, rString) +`, template, data.RandomString, data.RandomString) } -func testAccAzureRMMediaServicesAccount_multiplePrimaries(rInt int, rString, location string) string { - template := testAccAzureRMMediaServicesAccount_template(rInt, rString, location) +func testAccAzureRMMediaServicesAccount_multiplePrimaries(data acceptance.TestData) string { + template := testAccAzureRMMediaServicesAccount_template(data) return fmt.Sprintf(` %s @@ -250,10 +235,10 @@ resource "azurerm_media_services_account" "test" { is_primary = true } } -`, template, rString, rString) +`, template, data.RandomString, data.RandomString) } -func testAccAzureRMMediaServicesAccount_template(rInt int, rString, location string) string { +func testAccAzureRMMediaServicesAccount_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-media-%d" @@ -267,5 +252,5 @@ resource "azurerm_storage_account" "first" { account_tier = "Standard" account_replication_type = "GRS" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } From 1f81e8b23179dc0e9c166110c8453a2f25791641 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 20 Dec 2019 20:51:35 -0800 Subject: [PATCH 108/203] monitor: switching to the new test structure --- .../monitor/resource_arm_metric_alertrule.go | 4 +- .../resource_arm_monitor_metric_alert_test.go | 410 ----------------- .../resource_arm_monitor_metric_alertrule.go | 4 +- .../data_source_monitor_action_group_test.go | 180 ++++---- ...urce_monitor_diagnostic_categories_test.go | 32 +- .../data_source_monitor_log_profile_test.go | 56 ++- .../resource_arm_autoscale_setting_test.go | 319 ++++++------- .../resource_arm_metric_alertrule_test.go | 62 ++- .../resource_arm_monitor_action_group_test.go | 418 ++++++------------ ...rce_arm_monitor_activity_log_alert_test.go | 208 ++++----- ...urce_arm_monitor_autoscale_setting_test.go | 319 ++++++------- ...rce_arm_monitor_diagnostic_setting_test.go | 137 +++--- .../resource_arm_monitor_log_profile_test.go | 72 ++- .../resource_arm_monitor_metric_alert_test.go | 385 ++++++++++++++++ ...ource_arm_monitor_metric_alertrule_test.go | 62 ++- 15 files changed, 1167 insertions(+), 1501 deletions(-) delete mode 100644 azurerm/internal/services/monitor/resource_arm_monitor_metric_alert_test.go rename azurerm/internal/services/monitor/{ => tests}/data_source_monitor_action_group_test.go (50%) rename azurerm/internal/services/monitor/{ => tests}/data_source_monitor_diagnostic_categories_test.go (73%) rename azurerm/internal/services/monitor/{ => tests}/data_source_monitor_log_profile_test.go (60%) rename azurerm/internal/services/monitor/{ => tests}/resource_arm_autoscale_setting_test.go (62%) rename azurerm/internal/services/monitor/{ => tests}/resource_arm_metric_alertrule_test.go (83%) rename azurerm/internal/services/monitor/{ => tests}/resource_arm_monitor_action_group_test.go (69%) rename azurerm/internal/services/monitor/{ => tests}/resource_arm_monitor_activity_log_alert_test.go (53%) rename azurerm/internal/services/monitor/{ => tests}/resource_arm_monitor_autoscale_setting_test.go (62%) rename azurerm/internal/services/monitor/{ => tests}/resource_arm_monitor_diagnostic_setting_test.go (72%) rename azurerm/internal/services/monitor/{ => tests}/resource_arm_monitor_log_profile_test.go (79%) create mode 100644 azurerm/internal/services/monitor/tests/resource_arm_monitor_metric_alert_test.go rename azurerm/internal/services/monitor/{ => tests}/resource_arm_monitor_metric_alertrule_test.go (85%) diff --git a/azurerm/internal/services/monitor/resource_arm_metric_alertrule.go b/azurerm/internal/services/monitor/resource_arm_metric_alertrule.go index 847ad62d70bc..dba743c5cbdc 100644 --- a/azurerm/internal/services/monitor/resource_arm_metric_alertrule.go +++ b/azurerm/internal/services/monitor/resource_arm_metric_alertrule.go @@ -166,7 +166,7 @@ As such the existing 'azurerm_metric_alertrule' resource is deprecated and will Type: schema.TypeMap, Optional: true, Computed: true, - ValidateFunc: validateMetricAlertRuleTags, + ValidateFunc: ValidateMetricAlertRuleTags, Elem: &schema.Schema{ Type: schema.TypeString, }, @@ -449,7 +449,7 @@ func expandAzureRmMetricThresholdAlertRule(d *schema.ResourceData) (*insights.Al return &alertRule, nil } -func validateMetricAlertRuleTags(v interface{}, f string) (warnings []string, errors []error) { +func ValidateMetricAlertRuleTags(v interface{}, f string) (warnings []string, errors []error) { // Normal validation required by any AzureRM resource. warnings, errors = tags.Validate(v, f) diff --git a/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert_test.go b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert_test.go deleted file mode 100644 index e949dcd62e17..000000000000 --- a/azurerm/internal/services/monitor/resource_arm_monitor_metric_alert_test.go +++ /dev/null @@ -1,410 +0,0 @@ -package monitor - -import ( - "fmt" - "net/http" - "strings" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" -) - -func TestAccAzureRMMonitorMetricAlert_basic(t *testing.T) { - resourceName := "azurerm_monitor_metric_alert.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMonitorMetricAlertDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMMonitorMetricAlert_basic(ri, rs, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorMetricAlertExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "scopes.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.metric_namespace", "Microsoft.Storage/storageAccounts"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.metric_name", "UsedCapacity"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.aggregation", "Average"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.operator", "GreaterThan"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.threshold", "55.5"), - resource.TestCheckResourceAttr(resourceName, "action.#", "0"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMMonitorMetricAlert_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - resourceName := "azurerm_monitor_metric_alert.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMonitorMetricAlertDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMMonitorMetricAlert_basic(ri, rs, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorMetricAlertExists(resourceName), - ), - }, - { - Config: testAccAzureRMMonitorMetricAlert_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_monitor_metric_alert"), - }, - }, - }) -} - -func TestAccAzureRMMonitorMetricAlert_complete(t *testing.T) { - resourceName := "azurerm_monitor_metric_alert.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - config := testAccAzureRMMonitorMetricAlert_complete(ri, rs, acceptance.Location()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMonitorMetricAlertDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorMetricAlertExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auto_mitigate", "true"), - resource.TestCheckResourceAttr(resourceName, "severity", "4"), - resource.TestCheckResourceAttr(resourceName, "description", "This is a complete metric alert resource."), - resource.TestCheckResourceAttr(resourceName, "frequency", "PT30M"), - resource.TestCheckResourceAttr(resourceName, "window_size", "PT12H"), - resource.TestCheckResourceAttr(resourceName, "scopes.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.#", "2"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.metric_namespace", "Microsoft.Storage/storageAccounts"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.metric_name", "Transactions"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.aggregation", "Maximum"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.operator", "Equals"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.threshold", "99"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.#", "2"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.0.name", "GeoType"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.0.operator", "Include"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.0.values.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.0.values.0", "*"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.1.name", "ApiName"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.1.operator", "Include"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.1.values.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.1.values.0", "*"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.metric_namespace", "Microsoft.Storage/storageAccounts"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.metric_name", "UsedCapacity"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.aggregation", "Total"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.operator", "GreaterThanOrEqual"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.threshold", "66.6"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.dimension.#", "0"), - resource.TestCheckResourceAttr(resourceName, "action.#", "2"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMMonitorMetricAlert_basicAndCompleteUpdate(t *testing.T) { - resourceName := "azurerm_monitor_metric_alert.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - basicConfig := testAccAzureRMMonitorMetricAlert_basic(ri, rs, location) - completeConfig := testAccAzureRMMonitorMetricAlert_complete(ri, rs, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMMonitorMetricAlertDestroy, - Steps: []resource.TestStep{ - { - Config: basicConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorMetricAlertExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auto_mitigate", "false"), - resource.TestCheckResourceAttr(resourceName, "severity", "3"), - resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "frequency", "PT1M"), - resource.TestCheckResourceAttr(resourceName, "window_size", "PT5M"), - resource.TestCheckResourceAttr(resourceName, "scopes.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.metric_namespace", "Microsoft.Storage/storageAccounts"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.metric_name", "UsedCapacity"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.aggregation", "Average"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.operator", "GreaterThan"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.threshold", "55.5"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.#", "0"), - resource.TestCheckResourceAttr(resourceName, "action.#", "0"), - ), - }, - { - Config: completeConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorMetricAlertExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auto_mitigate", "true"), - resource.TestCheckResourceAttr(resourceName, "severity", "4"), - resource.TestCheckResourceAttr(resourceName, "description", "This is a complete metric alert resource."), - resource.TestCheckResourceAttr(resourceName, "frequency", "PT30M"), - resource.TestCheckResourceAttr(resourceName, "window_size", "PT12H"), - resource.TestCheckResourceAttr(resourceName, "scopes.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.#", "2"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.metric_namespace", "Microsoft.Storage/storageAccounts"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.metric_name", "Transactions"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.aggregation", "Maximum"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.operator", "Equals"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.threshold", "99"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.#", "2"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.0.name", "GeoType"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.0.operator", "Include"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.0.values.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.0.values.0", "*"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.1.name", "ApiName"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.1.operator", "Include"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.1.values.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.1.values.0", "*"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.metric_namespace", "Microsoft.Storage/storageAccounts"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.metric_name", "UsedCapacity"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.aggregation", "Total"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.operator", "GreaterThanOrEqual"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.threshold", "66.6"), - resource.TestCheckResourceAttr(resourceName, "criteria.1.dimension.#", "0"), - resource.TestCheckResourceAttr(resourceName, "action.#", "2"), - ), - }, - { - Config: basicConfig, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorMetricAlertExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "auto_mitigate", "false"), - resource.TestCheckResourceAttr(resourceName, "severity", "3"), - resource.TestCheckResourceAttr(resourceName, "description", ""), - resource.TestCheckResourceAttr(resourceName, "frequency", "PT1M"), - resource.TestCheckResourceAttr(resourceName, "window_size", "PT5M"), - resource.TestCheckResourceAttr(resourceName, "scopes.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.#", "1"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.metric_namespace", "Microsoft.Storage/storageAccounts"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.metric_name", "UsedCapacity"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.aggregation", "Average"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.operator", "GreaterThan"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.threshold", "55.5"), - resource.TestCheckResourceAttr(resourceName, "criteria.0.dimension.#", "0"), - resource.TestCheckResourceAttr(resourceName, "action.#", "0"), - ), - }, - }, - }) -} - -func testAccAzureRMMonitorMetricAlert_basic(rInt int, rString, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "acctestsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_monitor_metric_alert" "test" { - name = "acctestMetricAlert-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - scopes = ["${azurerm_storage_account.test.id}"] - - criteria { - metric_namespace = "Microsoft.Storage/storageAccounts" - metric_name = "UsedCapacity" - aggregation = "Average" - operator = "GreaterThan" - threshold = 55.5 - } -} -`, rInt, location, rString, rInt) -} - -func testAccAzureRMMonitorMetricAlert_requiresImport(rInt int, rString, location string) string { - template := testAccAzureRMMonitorMetricAlert_basic(rInt, rString, location) - return fmt.Sprintf(` -%s - -resource "azurerm_monitor_metric_alert" "import" { - name = "${azurerm_monitor_metric_alert.test.name}" - resource_group_name = "${azurerm_monitor_metric_alert.test.resource_group_name}" - scopes = "${azurerm_monitor_metric_alert.test.scopes}" - - criteria { - metric_namespace = "Microsoft.Storage/storageAccounts" - metric_name = "UsedCapacity" - aggregation = "Average" - operator = "GreaterThan" - threshold = 55.5 - } -} -`, template) -} - -func testAccAzureRMMonitorMetricAlert_complete(rInt int, rString, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" - location = "%[2]s" -} - -resource "azurerm_storage_account" "test" { - name = "acctestsa1%[3]s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_monitor_action_group" "test1" { - name = "acctestActionGroup1-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - short_name = "acctestag1" -} - -resource "azurerm_monitor_action_group" "test2" { - name = "acctestActionGroup2-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - short_name = "acctestag2" -} - -resource "azurerm_monitor_metric_alert" "test" { - name = "acctestMetricAlert-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - scopes = ["${azurerm_storage_account.test.id}"] - enabled = true - auto_mitigate = true - severity = 4 - description = "This is a complete metric alert resource." - frequency = "PT30M" - window_size = "PT12H" - - criteria { - metric_namespace = "Microsoft.Storage/storageAccounts" - metric_name = "Transactions" - aggregation = "Maximum" - operator = "Equals" - threshold = 99 - - dimension { - name = "GeoType" - operator = "Include" - values = ["*"] - } - - dimension { - name = "ApiName" - operator = "Include" - values = ["*"] - } - } - - criteria { - metric_namespace = "Microsoft.Storage/storageAccounts" - metric_name = "UsedCapacity" - aggregation = "Total" - operator = "GreaterThanOrEqual" - threshold = 66.6 - } - - action { - action_group_id = "${azurerm_monitor_action_group.test1.id}" - } - - action { - action_group_id = "${azurerm_monitor_action_group.test2.id}" - } -} -`, rInt, location, rString) -} - -func testCheckAzureRMMonitorMetricAlertDestroy(s *terraform.State) error { - conn := acceptance.AzureProvider.Meta().(*clients.Client).Monitor.MetricAlertsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_monitor_metric_alert" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := conn.Get(ctx, resourceGroup, name) - if err != nil { - return nil - } - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("Metric alert still exists:\n%#v", resp) - } - } - return nil -} - -func testCheckAzureRMMonitorMetricAlertExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", 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 Metric Alert Instance: %s", name) - } - - conn := acceptance.AzureProvider.Meta().(*clients.Client).Monitor.MetricAlertsClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - resp, err := conn.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("Bad: Get on monitorMetricAlertsClient: %+v", err) - } - if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: Metric Alert Instance %q (resource group: %q) does not exist", name, resourceGroup) - } - - return nil - } -} diff --git a/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule.go b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule.go index 7e1f6889064d..efbaae8559d5 100644 --- a/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule.go +++ b/azurerm/internal/services/monitor/resource_arm_monitor_metric_alertrule.go @@ -159,7 +159,7 @@ func resourceArmMonitorMetricAlertRule() *schema.Resource { Type: schema.TypeMap, Optional: true, Computed: true, - ValidateFunc: validateMetricAlertRuleTags, + ValidateFunc: ValidateMetricAlertRuleTags, Elem: &schema.Schema{ Type: schema.TypeString, }, @@ -446,7 +446,7 @@ func expandAzureRmMonitorMetricThresholdAlertRule(d *schema.ResourceData) (*insi return &alertRule, nil } -func validateMonitorMetricAlertRuleTags(v interface{}, f string) (warnings []string, errors []error) { +func ValidateMonitorMetricAlertRuleTags(v interface{}, f string) (warnings []string, errors []error) { // Normal validation required by any AzureRM resource. warnings, errors = tags.Validate(v, f) diff --git a/azurerm/internal/services/monitor/data_source_monitor_action_group_test.go b/azurerm/internal/services/monitor/tests/data_source_monitor_action_group_test.go similarity index 50% rename from azurerm/internal/services/monitor/data_source_monitor_action_group_test.go rename to azurerm/internal/services/monitor/tests/data_source_monitor_action_group_test.go index 28cf1bb8cfbf..9fd14104366c 100644 --- a/azurerm/internal/services/monitor/data_source_monitor_action_group_test.go +++ b/azurerm/internal/services/monitor/tests/data_source_monitor_action_group_test.go @@ -1,20 +1,17 @@ -package monitor +package tests import ( "fmt" "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceArmMonitorActionGroup_basic(t *testing.T) { - dataSourceName := "data.azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - config := testAccDataSourceArmMonitorActionGroup_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "data.azurerm_monitor_action_group", "test") + config := testAccDataSourceArmMonitorActionGroup_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,19 +20,19 @@ func TestAccDataSourceArmMonitorActionGroup_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "id"), - resource.TestCheckResourceAttr(dataSourceName, "enabled", "true"), - resource.TestCheckResourceAttr(dataSourceName, "short_name", "acctestag"), - resource.TestCheckResourceAttr(dataSourceName, "email_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "itsm_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "azure_app_push_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "automation_runbook_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "voice_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "logic_app_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "azure_function_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "arm_role_receiver.#", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "short_name", "acctestag"), + resource.TestCheckResourceAttr(data.ResourceName, "email_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "itsm_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_app_push_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "sms_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "webhook_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "automation_runbook_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "voice_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "logic_app_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_function_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "arm_role_receiver.#", "0"), ), }, }, @@ -43,9 +40,8 @@ func TestAccDataSourceArmMonitorActionGroup_basic(t *testing.T) { } func TestAccDataSourceArmMonitorActionGroup_disabledBasic(t *testing.T) { - dataSourceName := "data.azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - config := testAccDataSourceArmMonitorActionGroup_disabledBasic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "data.azurerm_monitor_action_group", "test") + config := testAccDataSourceArmMonitorActionGroup_disabledBasic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,19 +50,19 @@ func TestAccDataSourceArmMonitorActionGroup_disabledBasic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "id"), - resource.TestCheckResourceAttr(dataSourceName, "enabled", "false"), - resource.TestCheckResourceAttr(dataSourceName, "short_name", "acctestag"), - resource.TestCheckResourceAttr(dataSourceName, "email_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "itsm_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "azure_app_push_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "automation_runbook_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "voice_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "logic_app_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "azure_function_receiver.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "arm_role_receiver.#", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "short_name", "acctestag"), + resource.TestCheckResourceAttr(data.ResourceName, "email_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "itsm_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_app_push_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "sms_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "webhook_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "automation_runbook_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "voice_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "logic_app_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_function_receiver.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "arm_role_receiver.#", "0"), ), }, }, @@ -74,16 +70,14 @@ func TestAccDataSourceArmMonitorActionGroup_disabledBasic(t *testing.T) { } func TestAccDataSourceArmMonitorActionGroup_complete(t *testing.T) { - dataSourceName := "data.azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - config := testAccDataSourceArmMonitorActionGroup_complete(ri, rs, acceptance.Location()) - - aaName := fmt.Sprintf("acctestAA-%d", ri) - faName := fmt.Sprintf("acctestFA-%d", ri) - laName := fmt.Sprintf("acctestLA-%d", ri) + data := acceptance.BuildTestData(t, "data.azurerm_monitor_action_group", "test") + config := testAccDataSourceArmMonitorActionGroup_complete(data) + + aaName := fmt.Sprintf("acctestAA-%d", data.RandomInteger) + faName := fmt.Sprintf("acctestFA-%d", data.RandomInteger) + laName := fmt.Sprintf("acctestLA-%d", data.RandomInteger) webhookName := "webhook_alert" - resGroup := fmt.Sprintf("acctestRG-%d", ri) + resGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) aaResourceID := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Automation/AutomationAccounts/%s", os.Getenv("ARM_SUBSCRIPTION_ID"), resGroup, aaName) aaWebhookResourceID := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Automation/AutomationAccounts/%s/webhooks/%s", os.Getenv("ARM_SUBSCRIPTION_ID"), resGroup, aaName, webhookName) faResourceID := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/sites/%s", os.Getenv("ARM_SUBSCRIPTION_ID"), resGroup, faName) @@ -96,56 +90,56 @@ func TestAccDataSourceArmMonitorActionGroup_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "id"), - resource.TestCheckResourceAttr(dataSourceName, "enabled", "true"), - resource.TestCheckResourceAttr(dataSourceName, "email_receiver.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "email_receiver.0.email_address", "admin@contoso.com"), - resource.TestCheckResourceAttr(dataSourceName, "email_receiver.1.email_address", "devops@contoso.com"), - resource.TestCheckResourceAttr(dataSourceName, "email_receiver.1.use_common_alert_schema", "false"), - resource.TestCheckResourceAttr(dataSourceName, "itsm_receiver.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "itsm_receiver.0.workspace_id", "6eee3a18-aac3-40e4-b98e-1f309f329816"), - resource.TestCheckResourceAttr(dataSourceName, "itsm_receiver.0.connection_id", "53de6956-42b4-41ba-be3c-b154cdf17b13"), - resource.TestCheckResourceAttr(dataSourceName, "itsm_receiver.0.ticket_configuration", "{}"), - resource.TestCheckResourceAttr(dataSourceName, "itsm_receiver.0.region", "southcentralus"), - resource.TestCheckResourceAttr(dataSourceName, "azure_app_push_receiver.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "azure_app_push_receiver.0.email_address", "admin@contoso.com"), - resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.0.country_code", "1"), - resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.0.phone_number", "1231231234"), - resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.1.country_code", "86"), - resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.1.phone_number", "13888888888"), - resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.0.service_uri", "http://example.com/alert"), - resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.1.service_uri", "https://backup.example.com/warning"), - resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.1.use_common_alert_schema", "false"), - resource.TestCheckResourceAttr(dataSourceName, "automation_runbook_receiver.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "automation_runbook_receiver.0.automation_account_id", aaResourceID), - resource.TestCheckResourceAttr(dataSourceName, "automation_runbook_receiver.0.runbook_name", webhookName), - resource.TestCheckResourceAttr(dataSourceName, "automation_runbook_receiver.0.webhook_resource_id", aaWebhookResourceID), - resource.TestCheckResourceAttr(dataSourceName, "automation_runbook_receiver.0.service_uri", "https://s13events.azure-automation.net/webhooks?token=randomtoken"), - resource.TestCheckResourceAttr(dataSourceName, "automation_runbook_receiver.0.use_common_alert_schema", "false"), - resource.TestCheckResourceAttr(dataSourceName, "voice_receiver.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "voice_receiver.0.country_code", "1"), - resource.TestCheckResourceAttr(dataSourceName, "voice_receiver.0.phone_number", "1231231234"), - resource.TestCheckResourceAttr(dataSourceName, "logic_app_receiver.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "logic_app_receiver.0.resource_id", laResourceID), - resource.TestCheckResourceAttr(dataSourceName, "logic_app_receiver.0.callback_url", "http://test-host:100/workflows/fb9c8d79b15f41ce9b12861862f43546/versions/08587100027316071865/triggers/manualTrigger/paths/invoke?api-version=2015-08-01-preview&sp=%2Fversions%2F08587100027316071865%2Ftriggers%2FmanualTrigger%2Frun&sv=1.0&sig=IxEQ_ygZf6WNEQCbjV0Vs6p6Y4DyNEJVAa86U5B4xhk"), - resource.TestCheckResourceAttr(dataSourceName, "logic_app_receiver.0.use_common_alert_schema", "false"), - resource.TestCheckResourceAttr(dataSourceName, "azure_function_receiver.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "azure_function_receiver.0.function_app_resource_id", faResourceID), - resource.TestCheckResourceAttr(dataSourceName, "azure_function_receiver.0.function_name", "myfunc"), - resource.TestCheckResourceAttr(dataSourceName, "azure_function_receiver.0.http_trigger_url", "https://example.com/trigger"), - resource.TestCheckResourceAttr(dataSourceName, "azure_function_receiver.0.use_common_alert_schema", "false"), - resource.TestCheckResourceAttr(dataSourceName, "arm_role_receiver.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "arm_role_receiver.0.role_id", "43d0d8ad-25c7-4714-9337-8ba259a9fe05"), - resource.TestCheckResourceAttr(dataSourceName, "arm_role_receiver.0.use_common_alert_schema", "false"), + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "email_receiver.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "email_receiver.0.email_address", "admin@contoso.com"), + resource.TestCheckResourceAttr(data.ResourceName, "email_receiver.1.email_address", "devops@contoso.com"), + resource.TestCheckResourceAttr(data.ResourceName, "email_receiver.1.use_common_alert_schema", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "itsm_receiver.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "itsm_receiver.0.workspace_id", "6eee3a18-aac3-40e4-b98e-1f309f329816"), + resource.TestCheckResourceAttr(data.ResourceName, "itsm_receiver.0.connection_id", "53de6956-42b4-41ba-be3c-b154cdf17b13"), + resource.TestCheckResourceAttr(data.ResourceName, "itsm_receiver.0.ticket_configuration", "{}"), + resource.TestCheckResourceAttr(data.ResourceName, "itsm_receiver.0.region", "southcentralus"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_app_push_receiver.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_app_push_receiver.0.email_address", "admin@contoso.com"), + resource.TestCheckResourceAttr(data.ResourceName, "sms_receiver.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "sms_receiver.0.country_code", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "sms_receiver.0.phone_number", "1231231234"), + resource.TestCheckResourceAttr(data.ResourceName, "sms_receiver.1.country_code", "86"), + resource.TestCheckResourceAttr(data.ResourceName, "sms_receiver.1.phone_number", "13888888888"), + resource.TestCheckResourceAttr(data.ResourceName, "webhook_receiver.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "webhook_receiver.0.service_uri", "http://example.com/alert"), + resource.TestCheckResourceAttr(data.ResourceName, "webhook_receiver.1.service_uri", "https://backup.example.com/warning"), + resource.TestCheckResourceAttr(data.ResourceName, "webhook_receiver.1.use_common_alert_schema", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "automation_runbook_receiver.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "automation_runbook_receiver.0.automation_account_id", aaResourceID), + resource.TestCheckResourceAttr(data.ResourceName, "automation_runbook_receiver.0.runbook_name", webhookName), + resource.TestCheckResourceAttr(data.ResourceName, "automation_runbook_receiver.0.webhook_resource_id", aaWebhookResourceID), + resource.TestCheckResourceAttr(data.ResourceName, "automation_runbook_receiver.0.service_uri", "https://s13events.azure-automation.net/webhooks?token=randomtoken"), + resource.TestCheckResourceAttr(data.ResourceName, "automation_runbook_receiver.0.use_common_alert_schema", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "voice_receiver.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "voice_receiver.0.country_code", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "voice_receiver.0.phone_number", "1231231234"), + resource.TestCheckResourceAttr(data.ResourceName, "logic_app_receiver.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "logic_app_receiver.0.resource_id", laResourceID), + resource.TestCheckResourceAttr(data.ResourceName, "logic_app_receiver.0.callback_url", "http://test-host:100/workflows/fb9c8d79b15f41ce9b12861862f43546/versions/08587100027316071865/triggers/manualTrigger/paths/invoke?api-version=2015-08-01-preview&sp=%2Fversions%2F08587100027316071865%2Ftriggers%2FmanualTrigger%2Frun&sv=1.0&sig=IxEQ_ygZf6WNEQCbjV0Vs6p6Y4DyNEJVAa86U5B4xhk"), + resource.TestCheckResourceAttr(data.ResourceName, "logic_app_receiver.0.use_common_alert_schema", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_function_receiver.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_function_receiver.0.function_app_resource_id", faResourceID), + resource.TestCheckResourceAttr(data.ResourceName, "azure_function_receiver.0.function_name", "myfunc"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_function_receiver.0.http_trigger_url", "https://example.com/trigger"), + resource.TestCheckResourceAttr(data.ResourceName, "azure_function_receiver.0.use_common_alert_schema", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "arm_role_receiver.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "arm_role_receiver.0.role_id", "43d0d8ad-25c7-4714-9337-8ba259a9fe05"), + resource.TestCheckResourceAttr(data.ResourceName, "arm_role_receiver.0.use_common_alert_schema", "false"), ), }, }, }) } -func testAccDataSourceArmMonitorActionGroup_basic(rInt int, location string) string { +func testAccDataSourceArmMonitorActionGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -162,10 +156,10 @@ data "azurerm_monitor_action_group" "test" { resource_group_name = "${azurerm_resource_group.test.name}" name = "${azurerm_monitor_action_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceArmMonitorActionGroup_disabledBasic(rInt int, location string) string { +func testAccDataSourceArmMonitorActionGroup_disabledBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -183,10 +177,10 @@ data "azurerm_monitor_action_group" "test" { resource_group_name = "${azurerm_resource_group.test.name}" name = "${azurerm_monitor_action_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceArmMonitorActionGroup_complete(rInt int, rString, location string) string { +func testAccDataSourceArmMonitorActionGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -365,5 +359,5 @@ data "azurerm_monitor_action_group" "test" { resource_group_name = "${azurerm_resource_group.test.name}" name = "${azurerm_monitor_action_group.test.name}" } -`, rInt, location, rInt, rInt, rInt, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/monitor/data_source_monitor_diagnostic_categories_test.go b/azurerm/internal/services/monitor/tests/data_source_monitor_diagnostic_categories_test.go similarity index 73% rename from azurerm/internal/services/monitor/data_source_monitor_diagnostic_categories_test.go rename to azurerm/internal/services/monitor/tests/data_source_monitor_diagnostic_categories_test.go index 6db8a54e630b..81f78a3eb8c3 100644 --- a/azurerm/internal/services/monitor/data_source_monitor_diagnostic_categories_test.go +++ b/azurerm/internal/services/monitor/tests/data_source_monitor_diagnostic_categories_test.go @@ -1,29 +1,25 @@ -package monitor +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceArmMonitorDiagnosticCategories_appService(t *testing.T) { - dataSourceName := "data.azurerm_monitor_diagnostic_categories.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_monitor_diagnostic_categories", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceArmMonitorDiagnosticCategories_appService(ri, location), + Config: testAccDataSourceArmMonitorDiagnosticCategories_appService(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "metrics.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "logs.#", "6"), + resource.TestCheckResourceAttr(data.ResourceName, "metrics.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "logs.#", "6"), ), }, }, @@ -31,26 +27,24 @@ func TestAccDataSourceArmMonitorDiagnosticCategories_appService(t *testing.T) { } func TestAccDataSourceArmMonitorDiagnosticCategories_storageAccount(t *testing.T) { - dataSourceName := "data.azurerm_monitor_diagnostic_categories.test" - rs := acctest.RandString(8) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_monitor_diagnostic_categories", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceArmMonitorDiagnosticCategories_storageAccount(rs, location), + Config: testAccDataSourceArmMonitorDiagnosticCategories_storageAccount(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "metrics.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "logs.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "metrics.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "logs.#", "0"), ), }, }, }) } -func testAccDataSourceArmMonitorDiagnosticCategories_appService(rInt int, location string) string { +func testAccDataSourceArmMonitorDiagnosticCategories_appService(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -78,10 +72,10 @@ resource "azurerm_app_service" "test" { data "azurerm_monitor_diagnostic_categories" "test" { resource_id = "${azurerm_app_service.test.id}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccDataSourceArmMonitorDiagnosticCategories_storageAccount(rString, location string) string { +func testAccDataSourceArmMonitorDiagnosticCategories_storageAccount(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%s" @@ -103,5 +97,5 @@ resource "azurerm_storage_account" "test" { data "azurerm_monitor_diagnostic_categories" "test" { resource_id = "${azurerm_storage_account.test.id}" } -`, rString, location, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/monitor/data_source_monitor_log_profile_test.go b/azurerm/internal/services/monitor/tests/data_source_monitor_log_profile_test.go similarity index 60% rename from azurerm/internal/services/monitor/data_source_monitor_log_profile_test.go rename to azurerm/internal/services/monitor/tests/data_source_monitor_log_profile_test.go index 951e3c562688..46f4a0f90e6b 100644 --- a/azurerm/internal/services/monitor/data_source_monitor_log_profile_test.go +++ b/azurerm/internal/services/monitor/tests/data_source_monitor_log_profile_test.go @@ -1,12 +1,10 @@ -package monitor +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) @@ -15,9 +13,7 @@ import ( // (which our test suite can't easily workaround) func testAccDataSourceAzureRMMonitorLogProfile_storageaccount(t *testing.T) { - dataSourceName := "data.azurerm_monitor_log_profile.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(10) + data := acceptance.BuildTestData(t, "data.azurerm_monitor_log_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,16 +21,16 @@ func testAccDataSourceAzureRMMonitorLogProfile_storageaccount(t *testing.T) { CheckDestroy: testCheckAzureRMLogProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMMonitorLogProfile_storageaccountConfig(ri, rs, acceptance.Location()), + Config: testAccDataSourceAzureRMMonitorLogProfile_storageaccountConfig(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "categories.#"), - resource.TestCheckResourceAttrSet(dataSourceName, "locations.#"), - resource.TestCheckResourceAttrSet(dataSourceName, "storage_account_id"), - resource.TestCheckResourceAttr(dataSourceName, "servicebus_rule_id", ""), - resource.TestCheckResourceAttr(dataSourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttrSet(dataSourceName, "retention_policy.0.enabled"), - resource.TestCheckResourceAttrSet(dataSourceName, "retention_policy.0.days"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "categories.#"), + resource.TestCheckResourceAttrSet(data.ResourceName, "locations.#"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "servicebus_rule_id", ""), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "retention_policy.0.enabled"), + resource.TestCheckResourceAttrSet(data.ResourceName, "retention_policy.0.days"), ), }, }, @@ -42,9 +38,7 @@ func testAccDataSourceAzureRMMonitorLogProfile_storageaccount(t *testing.T) { } func testAccDataSourceAzureRMMonitorLogProfile_eventhub(t *testing.T) { - dataSourceName := "data.azurerm_monitor_log_profile.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(10) + data := acceptance.BuildTestData(t, "data.azurerm_monitor_log_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,23 +46,23 @@ func testAccDataSourceAzureRMMonitorLogProfile_eventhub(t *testing.T) { CheckDestroy: testCheckAzureRMLogProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMMonitorLogProfile_eventhubConfig(ri, rs, acceptance.Location()), + Config: testAccDataSourceAzureRMMonitorLogProfile_eventhubConfig(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "categories.#"), - resource.TestCheckResourceAttrSet(dataSourceName, "locations.#"), - resource.TestCheckResourceAttr(dataSourceName, "storage_account_id", ""), - resource.TestCheckResourceAttrSet(dataSourceName, "servicebus_rule_id"), - resource.TestCheckResourceAttr(dataSourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttrSet(dataSourceName, "retention_policy.0.enabled"), - resource.TestCheckResourceAttrSet(dataSourceName, "retention_policy.0.days"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "categories.#"), + resource.TestCheckResourceAttrSet(data.ResourceName, "locations.#"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_account_id", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "servicebus_rule_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "retention_policy.0.enabled"), + resource.TestCheckResourceAttrSet(data.ResourceName, "retention_policy.0.days"), ), }, }, }) } -func testAccDataSourceAzureRMMonitorLogProfile_storageaccountConfig(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMMonitorLogProfile_storageaccountConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -105,10 +99,10 @@ resource "azurerm_monitor_log_profile" "test" { data "azurerm_monitor_log_profile" "test" { name = "${azurerm_monitor_log_profile.test.name}" } -`, rInt, location, rString, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.Locations.Primary) } -func testAccDataSourceAzureRMMonitorLogProfile_eventhubConfig(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMMonitorLogProfile_eventhubConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -146,5 +140,5 @@ resource "azurerm_monitor_log_profile" "test" { data "azurerm_monitor_log_profile" "test" { name = "${azurerm_monitor_log_profile.test.name}" } -`, rInt, location, rString, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/monitor/resource_arm_autoscale_setting_test.go b/azurerm/internal/services/monitor/tests/resource_arm_autoscale_setting_test.go similarity index 62% rename from azurerm/internal/services/monitor/resource_arm_autoscale_setting_test.go rename to azurerm/internal/services/monitor/tests/resource_arm_autoscale_setting_test.go index e96d2da7962c..fa7595c42339 100644 --- a/azurerm/internal/services/monitor/resource_arm_autoscale_setting_test.go +++ b/azurerm/internal/services/monitor/tests/resource_arm_autoscale_setting_test.go @@ -1,4 +1,4 @@ -package monitor +package tests import ( "fmt" @@ -7,17 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMAutoScaleSetting_basic(t *testing.T) { - resourceName := "azurerm_autoscale_setting.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMAutoScaleSetting_basic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") + config := testAccAzureRMAutoScaleSetting_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,20 +24,16 @@ func TestAccAzureRMAutoScaleSetting_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.name", "metricRules"), - resource.TestCheckResourceAttr(resourceName, "profile.0.rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "notification.#", "0"), - resource.TestCheckNoResourceAttr(resourceName, "tags.$type"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "metricRules"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "0"), + resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -51,9 +44,7 @@ func TestAccAzureRMAutoScaleSetting_requiresImport(t *testing.T) { return } - resourceName := "azurerm_autoscale_setting.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -61,13 +52,13 @@ func TestAccAzureRMAutoScaleSetting_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutoScaleSetting_basic(ri, location), + Config: testAccAzureRMAutoScaleSetting_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), ), }, { - Config: testAccAzureRMAutoScaleSetting_requiresImport(ri, location), + Config: testAccAzureRMAutoScaleSetting_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_autoscale_setting"), }, }, @@ -75,10 +66,8 @@ func TestAccAzureRMAutoScaleSetting_requiresImport(t *testing.T) { } func TestAccAzureRMAutoScaleSetting_multipleProfiles(t *testing.T) { - resourceName := "azurerm_autoscale_setting.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMAutoScaleSetting_multipleProfiles(ri, location) + data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") + config := testAccAzureRMAutoScaleSetting_multipleProfiles(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -88,11 +77,11 @@ func TestAccAzureRMAutoScaleSetting_multipleProfiles(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "profile.#", "2"), - resource.TestCheckResourceAttr(resourceName, "profile.0.name", "primary"), - resource.TestCheckResourceAttr(resourceName, "profile.1.name", "secondary"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "primary"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.1.name", "secondary"), ), }, }, @@ -100,9 +89,7 @@ func TestAccAzureRMAutoScaleSetting_multipleProfiles(t *testing.T) { } func TestAccAzureRMAutoScaleSetting_update(t *testing.T) { - resourceName := "azurerm_autoscale_setting.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -110,36 +97,36 @@ func TestAccAzureRMAutoScaleSetting_update(t *testing.T) { CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutoScaleSetting_capacity(ri, location, 1, 3, 2), + Config: testAccAzureRMAutoScaleSetting_capacity(data, 1, 3, 2), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.minimum", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.maximum", "3"), - resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.default", "2"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.minimum", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.maximum", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.default", "2"), ), }, { - Config: testAccAzureRMAutoScaleSetting_capacity(ri, location, 0, 400, 0), + Config: testAccAzureRMAutoScaleSetting_capacity(data, 0, 400, 0), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.minimum", "0"), - resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.maximum", "400"), - resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.default", "0"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.minimum", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.maximum", "400"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.default", "0"), ), }, { - Config: testAccAzureRMAutoScaleSetting_capacity(ri, location, 2, 45, 3), + Config: testAccAzureRMAutoScaleSetting_capacity(data, 2, 45, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.minimum", "2"), - resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.maximum", "45"), - resource.TestCheckResourceAttr(resourceName, "profile.0.capacity.0.default", "3"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.minimum", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.maximum", "45"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.capacity.0.default", "3"), ), }, }, @@ -147,9 +134,7 @@ func TestAccAzureRMAutoScaleSetting_update(t *testing.T) { } func TestAccAzureRMAutoScaleSetting_multipleRules(t *testing.T) { - resourceName := "azurerm_autoscale_setting.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -157,28 +142,28 @@ func TestAccAzureRMAutoScaleSetting_multipleRules(t *testing.T) { CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutoScaleSetting_basic(ri, location), + Config: testAccAzureRMAutoScaleSetting_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.name", "metricRules"), - resource.TestCheckResourceAttr(resourceName, "profile.0.rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.rule.0.scale_action.0.direction", "Increase"), - resource.TestCheckResourceAttr(resourceName, "notification.#", "0"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "metricRules"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.0.scale_action.0.direction", "Increase"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "0"), ), }, { - Config: testAccAzureRMAutoScaleSetting_multipleRules(ri, location), + Config: testAccAzureRMAutoScaleSetting_multipleRules(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.name", "metricRules"), - resource.TestCheckResourceAttr(resourceName, "profile.0.rule.#", "2"), - resource.TestCheckResourceAttr(resourceName, "profile.0.rule.0.scale_action.0.direction", "Increase"), - resource.TestCheckResourceAttr(resourceName, "profile.0.rule.1.scale_action.0.direction", "Decrease"), - resource.TestCheckResourceAttr(resourceName, "notification.#", "0"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "metricRules"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.0.scale_action.0.direction", "Increase"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.rule.1.scale_action.0.direction", "Decrease"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "0"), ), }, }, @@ -186,9 +171,7 @@ func TestAccAzureRMAutoScaleSetting_multipleRules(t *testing.T) { } func TestAccAzureRMAutoScaleSetting_customEmails(t *testing.T) { - resourceName := "azurerm_autoscale_setting.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -196,24 +179,24 @@ func TestAccAzureRMAutoScaleSetting_customEmails(t *testing.T) { CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutoScaleSetting_email(ri, location), + Config: testAccAzureRMAutoScaleSetting_email(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "notification.#", "1"), - resource.TestCheckResourceAttr(resourceName, "notification.0.email.#", "1"), - resource.TestCheckResourceAttr(resourceName, "notification.0.email.0.custom_emails.#", "1"), - resource.TestCheckResourceAttr(resourceName, "notification.0.email.0.custom_emails.0", fmt.Sprintf("acctest1-%d@example.com", ri)), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.0.custom_emails.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.0.custom_emails.0", fmt.Sprintf("acctest1-%d@example.com", data.RandomInteger)), ), }, { - Config: testAccAzureRMAutoScaleSetting_emailUpdated(ri, location), + Config: testAccAzureRMAutoScaleSetting_emailUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "notification.#", "1"), - resource.TestCheckResourceAttr(resourceName, "notification.0.email.#", "1"), - resource.TestCheckResourceAttr(resourceName, "notification.0.email.0.custom_emails.#", "2"), - resource.TestCheckResourceAttr(resourceName, "notification.0.email.0.custom_emails.0", fmt.Sprintf("acctest1-%d@example.com", ri)), - resource.TestCheckResourceAttr(resourceName, "notification.0.email.0.custom_emails.1", fmt.Sprintf("acctest2-%d@example.com", ri)), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.0.custom_emails.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.0.custom_emails.0", fmt.Sprintf("acctest1-%d@example.com", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "notification.0.email.0.custom_emails.1", fmt.Sprintf("acctest2-%d@example.com", data.RandomInteger)), ), }, }, @@ -221,10 +204,8 @@ func TestAccAzureRMAutoScaleSetting_customEmails(t *testing.T) { } func TestAccAzureRMAutoScaleSetting_recurrence(t *testing.T) { - resourceName := "azurerm_autoscale_setting.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMAutoScaleSetting_recurrence(ri, location) + data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") + config := testAccAzureRMAutoScaleSetting_recurrence(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -234,27 +215,21 @@ func TestAccAzureRMAutoScaleSetting_recurrence(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.name", "recurrence"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.#", "1"), - resource.TestCheckResourceAttr(resourceName, "notification.#", "1"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "recurrence"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAutoScaleSetting_recurrenceUpdate(t *testing.T) { - resourceName := "azurerm_autoscale_setting.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -262,29 +237,29 @@ func TestAccAzureRMAutoScaleSetting_recurrenceUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMAutoScaleSettingDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutoScaleSetting_recurrence(ri, location), + Config: testAccAzureRMAutoScaleSetting_recurrence(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "notification.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.days.#", "3"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.days.0", "Monday"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.days.1", "Wednesday"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.days.2", "Friday"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.hours.0", "18"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.minutes.0", "0"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.0", "Monday"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.1", "Wednesday"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.2", "Friday"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.hours.0", "18"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.minutes.0", "0"), ), }, { - Config: testAccAzureRMAutoScaleSetting_recurrenceUpdated(ri, location), + Config: testAccAzureRMAutoScaleSetting_recurrenceUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.days.#", "3"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.days.0", "Monday"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.days.1", "Tuesday"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.days.2", "Wednesday"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.hours.0", "20"), - resource.TestCheckResourceAttr(resourceName, "profile.0.recurrence.0.minutes.0", "15"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.0", "Monday"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.1", "Tuesday"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.days.2", "Wednesday"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.hours.0", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.recurrence.0.minutes.0", "15"), ), }, }, @@ -292,10 +267,8 @@ func TestAccAzureRMAutoScaleSetting_recurrenceUpdate(t *testing.T) { } func TestAccAzureRMAutoScaleSetting_fixedDate(t *testing.T) { - resourceName := "azurerm_autoscale_setting.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMAutoScaleSetting_fixedDate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_autoscale_setting", "test") + config := testAccAzureRMAutoScaleSetting_fixedDate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -305,19 +278,15 @@ func TestAccAzureRMAutoScaleSetting_fixedDate(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutoScaleSettingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "profile.#", "1"), - resource.TestCheckResourceAttr(resourceName, "profile.0.name", "fixedDate"), - resource.TestCheckResourceAttr(resourceName, "profile.0.fixed_date.#", "1"), - resource.TestCheckResourceAttr(resourceName, "notification.#", "0"), + testCheckAzureRMAutoScaleSettingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.name", "fixedDate"), + resource.TestCheckResourceAttr(data.ResourceName, "profile.0.fixed_date.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -377,8 +346,8 @@ func testCheckAzureRMAutoScaleSettingDestroy(s *terraform.State) error { return nil } -func testAccAzureRMAutoScaleSetting_basic(rInt int, location string) string { - template := testAccAzureRMAutoScaleSetting_template(rInt, location) +func testAccAzureRMAutoScaleSetting_basic(data acceptance.TestData) string { + template := testAccAzureRMAutoScaleSetting_template(data) return fmt.Sprintf(` %s @@ -418,11 +387,11 @@ resource "azurerm_autoscale_setting" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAutoScaleSetting_requiresImport(rInt int, location string) string { - template := testAccAzureRMAutoScaleSetting_basic(rInt, location) +func testAccAzureRMAutoScaleSetting_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAutoScaleSetting_basic(data) return fmt.Sprintf(` %s @@ -465,8 +434,8 @@ resource "azurerm_autoscale_setting" "import" { `, template) } -func testAccAzureRMAutoScaleSetting_multipleProfiles(rInt int, location string) string { - template := testAccAzureRMAutoScaleSetting_template(rInt, location) +func testAccAzureRMAutoScaleSetting_multipleProfiles(data acceptance.TestData) string { + template := testAccAzureRMAutoScaleSetting_template(data) return fmt.Sprintf(` %s @@ -549,11 +518,11 @@ resource "azurerm_autoscale_setting" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAutoScaleSetting_multipleRules(rInt int, location string) string { - template := testAccAzureRMAutoScaleSetting_template(rInt, location) +func testAccAzureRMAutoScaleSetting_multipleRules(data acceptance.TestData) string { + template := testAccAzureRMAutoScaleSetting_template(data) return fmt.Sprintf(` %s @@ -614,11 +583,11 @@ resource "azurerm_autoscale_setting" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAutoScaleSetting_capacity(rInt int, location string, min int, max int, defaultVal int) string { - template := testAccAzureRMAutoScaleSetting_template(rInt, location) +func testAccAzureRMAutoScaleSetting_capacity(data acceptance.TestData, min int, max int, defaultVal int) string { + template := testAccAzureRMAutoScaleSetting_template(data) return fmt.Sprintf(` %s @@ -659,11 +628,11 @@ resource "azurerm_autoscale_setting" "test" { } } } -`, template, rInt, defaultVal, min, max) +`, template, data.RandomInteger, defaultVal, min, max) } -func testAccAzureRMAutoScaleSetting_email(rInt int, location string) string { - template := testAccAzureRMAutoScaleSetting_template(rInt, location) +func testAccAzureRMAutoScaleSetting_email(data acceptance.TestData) string { + template := testAccAzureRMAutoScaleSetting_template(data) return fmt.Sprintf(` %s @@ -711,11 +680,11 @@ resource "azurerm_autoscale_setting" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAutoScaleSetting_emailUpdated(rInt int, location string) string { - template := testAccAzureRMAutoScaleSetting_template(rInt, location) +func testAccAzureRMAutoScaleSetting_emailUpdated(data acceptance.TestData) string { + template := testAccAzureRMAutoScaleSetting_template(data) return fmt.Sprintf(` %s @@ -763,11 +732,11 @@ resource "azurerm_autoscale_setting" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAutoScaleSetting_recurrence(rInt int, location string) string { - template := testAccAzureRMAutoScaleSetting_template(rInt, location) +func testAccAzureRMAutoScaleSetting_recurrence(data acceptance.TestData) string { + template := testAccAzureRMAutoScaleSetting_template(data) return fmt.Sprintf(` %s @@ -807,11 +776,11 @@ resource "azurerm_autoscale_setting" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAutoScaleSetting_recurrenceUpdated(rInt int, location string) string { - template := testAccAzureRMAutoScaleSetting_template(rInt, location) +func testAccAzureRMAutoScaleSetting_recurrenceUpdated(data acceptance.TestData) string { + template := testAccAzureRMAutoScaleSetting_template(data) return fmt.Sprintf(` %s @@ -851,11 +820,11 @@ resource "azurerm_autoscale_setting" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAutoScaleSetting_fixedDate(rInt int, location string) string { - template := testAccAzureRMAutoScaleSetting_template(rInt, location) +func testAccAzureRMAutoScaleSetting_fixedDate(data acceptance.TestData) string { + template := testAccAzureRMAutoScaleSetting_template(data) return fmt.Sprintf(` %s @@ -881,10 +850,10 @@ resource "azurerm_autoscale_setting" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAutoScaleSetting_template(rInt int, location string) string { +func testAccAzureRMAutoScaleSetting_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -949,5 +918,5 @@ resource "azurerm_virtual_machine_scale_set" "test" { version = "latest" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go b/azurerm/internal/services/monitor/tests/resource_arm_metric_alertrule_test.go similarity index 83% rename from azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go rename to azurerm/internal/services/monitor/tests/resource_arm_metric_alertrule_test.go index d2d9ce2a346e..988f678a6fa0 100644 --- a/azurerm/internal/services/monitor/resource_arm_metric_alertrule_test.go +++ b/azurerm/internal/services/monitor/tests/resource_arm_metric_alertrule_test.go @@ -1,4 +1,4 @@ -package monitor +package tests import ( "fmt" @@ -6,10 +6,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/monitor" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -59,7 +59,7 @@ func TestValidateMetricAlertRuleTags(t *testing.T) { } for _, tc := range cases { - _, errors := validateMetricAlertRuleTags(tc.Value, "azurerm_metric_alert_rule") + _, errors := monitor.ValidateMetricAlertRuleTags(tc.Value, "azurerm_metric_alert_rule") if len(errors) != tc.ErrCount { t.Fatalf("Expected %q to return %d errors but returned %d", tc.Name, tc.ErrCount, len(errors)) @@ -68,10 +68,9 @@ func TestValidateMetricAlertRuleTags(t *testing.T) { } func TestAccAzureRMMetricAlertRule_virtualMachineCpu(t *testing.T) { - resourceName := "azurerm_metric_alertrule.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMMetricAlertRule_virtualMachineCpu(ri, acceptance.Location(), true) - postConfig := testAccAzureRMMetricAlertRule_virtualMachineCpu(ri, acceptance.Location(), false) + data := acceptance.BuildTestData(t, "azurerm_metric_alertrule", "test") + preConfig := testAccAzureRMMetricAlertRule_virtualMachineCpu(data, true) + postConfig := testAccAzureRMMetricAlertRule_virtualMachineCpu(data, false) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,26 +80,26 @@ func TestAccAzureRMMetricAlertRule_virtualMachineCpu(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMetricAlertRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckNoResourceAttr(resourceName, "tags.$type"), + testCheckAzureRMMetricAlertRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMetricAlertRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), - resource.TestCheckNoResourceAttr(resourceName, "tags.$type"), + testCheckAzureRMMetricAlertRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), + resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMetricAlertRuleExists(resourceName), - resource.TestCheckNoResourceAttr(resourceName, "tags.$type"), + testCheckAzureRMMetricAlertRuleExists(data.ResourceName), + resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), ), }, }, @@ -113,9 +112,7 @@ func TestAccAzureRMMetricAlertRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_metric_alertrule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_metric_alertrule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -123,13 +120,13 @@ func TestAccAzureRMMetricAlertRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMetricAlertRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMetricAlertRule_virtualMachineCpu(ri, location, true), + Config: testAccAzureRMMetricAlertRule_virtualMachineCpu(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMetricAlertRuleExists(resourceName), + testCheckAzureRMMetricAlertRuleExists(data.ResourceName), ), }, { - Config: testAccAzureRMMetricAlertRule_requiresImport(ri, location, true), + Config: testAccAzureRMMetricAlertRule_requiresImport(data, true), ExpectError: acceptance.RequiresImportError("azurerm_metric_alertrule"), }, }, @@ -137,9 +134,8 @@ func TestAccAzureRMMetricAlertRule_requiresImport(t *testing.T) { } func TestAccAzureRMMetricAlertRule_sqlDatabaseStorage(t *testing.T) { - resourceName := "azurerm_metric_alertrule.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMetricAlertRule_sqlDatabaseStorage(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_metric_alertrule", "test") + config := testAccAzureRMMetricAlertRule_sqlDatabaseStorage(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -149,8 +145,8 @@ func TestAccAzureRMMetricAlertRule_sqlDatabaseStorage(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMetricAlertRuleExists(resourceName), - resource.TestCheckNoResourceAttr(resourceName, "tags.$type"), + testCheckAzureRMMetricAlertRuleExists(data.ResourceName), + resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), ), }, }, @@ -215,7 +211,7 @@ func testCheckAzureRMMetricAlertRuleDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMetricAlertRule_virtualMachineCpu(rInt int, location string, enabled bool) string { +func testAccAzureRMMetricAlertRule_virtualMachineCpu(data acceptance.TestData, enabled bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -319,11 +315,11 @@ resource "azurerm_metric_alertrule" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, enabled) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, enabled) } -func testAccAzureRMMetricAlertRule_requiresImport(rInt int, location string, enabled bool) string { - template := testAccAzureRMMetricAlertRule_virtualMachineCpu(rInt, location, enabled) +func testAccAzureRMMetricAlertRule_requiresImport(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMMetricAlertRule_virtualMachineCpu(data, enabled) return fmt.Sprintf(` %s @@ -361,7 +357,7 @@ resource "azurerm_metric_alertrule" "import" { `, template) } -func testAccAzureRMMetricAlertRule_sqlDatabaseStorage(rInt int, location string) string { +func testAccAzureRMMetricAlertRule_sqlDatabaseStorage(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -465,5 +461,5 @@ resource "azurerm_metric_alertrule" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/monitor/resource_arm_monitor_action_group_test.go b/azurerm/internal/services/monitor/tests/resource_arm_monitor_action_group_test.go similarity index 69% rename from azurerm/internal/services/monitor/resource_arm_monitor_action_group_test.go rename to azurerm/internal/services/monitor/tests/resource_arm_monitor_action_group_test.go index 2d32deb55dea..b0223d201767 100644 --- a/azurerm/internal/services/monitor/resource_arm_monitor_action_group_test.go +++ b/azurerm/internal/services/monitor/tests/resource_arm_monitor_action_group_test.go @@ -1,23 +1,19 @@ -package monitor +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMMonitorActionGroup_basic(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,16 +21,12 @@ func TestAccAzureRMMonitorActionGroup_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_basic(ri, location), + Config: testAccAzureRMMonitorActionGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,9 +37,7 @@ func TestAccAzureRMMonitorActionGroup_requiresImport(t *testing.T) { return } - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,13 +45,13 @@ func TestAccAzureRMMonitorActionGroup_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_basic(ri, location), + Config: testAccAzureRMMonitorActionGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, { - Config: testAccAzureRMMonitorActionGroup_requiresImport(ri, location), + Config: testAccAzureRMMonitorActionGroup_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_app_service_custom_hostname_binding"), }, }, @@ -69,9 +59,7 @@ func TestAccAzureRMMonitorActionGroup_requiresImport(t *testing.T) { } func TestAccAzureRMMonitorActionGroup_emailReceiver(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,24 +67,18 @@ func TestAccAzureRMMonitorActionGroup_emailReceiver(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_emailReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_emailReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_itsmReceiver(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,24 +86,18 @@ func TestAccAzureRMMonitorActionGroup_itsmReceiver(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_itsmReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_itsmReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_azureAppPushReceiver(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -129,24 +105,18 @@ func TestAccAzureRMMonitorActionGroup_azureAppPushReceiver(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_azureAppPushReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_azureAppPushReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_smsReceiver(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -154,24 +124,18 @@ func TestAccAzureRMMonitorActionGroup_smsReceiver(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_smsReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_smsReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_webhookReceiver(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -179,24 +143,18 @@ func TestAccAzureRMMonitorActionGroup_webhookReceiver(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_webhookReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_webhookReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_automationRunbookReceiver(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -204,24 +162,18 @@ func TestAccAzureRMMonitorActionGroup_automationRunbookReceiver(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_automationRunbookReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_automationRunbookReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_voiceReceiver(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -229,24 +181,18 @@ func TestAccAzureRMMonitorActionGroup_voiceReceiver(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_voiceReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_voiceReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_logicAppReceiver(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -254,25 +200,18 @@ func TestAccAzureRMMonitorActionGroup_logicAppReceiver(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_logicAppReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_logicAppReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_azureFunctionReceiver(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -280,24 +219,18 @@ func TestAccAzureRMMonitorActionGroup_azureFunctionReceiver(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_azureFunctionReceiver(ri, rs, location), + Config: testAccAzureRMMonitorActionGroup_azureFunctionReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_armRoleReceiver(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -305,25 +238,18 @@ func TestAccAzureRMMonitorActionGroup_armRoleReceiver(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_armRoleReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_armRoleReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_complete(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -331,26 +257,20 @@ func TestAccAzureRMMonitorActionGroup_complete(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_complete(ri, rs, location), + Config: testAccAzureRMMonitorActionGroup_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_disabledUpdate(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMMonitorActionGroup_disabledBasic(ri, location) - postConfig := testAccAzureRMMonitorActionGroup_basic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") + preConfig := testAccAzureRMMonitorActionGroup_disabledBasic(data) + postConfig := testAccAzureRMMonitorActionGroup_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -360,48 +280,33 @@ func TestAccAzureRMMonitorActionGroup_disabledUpdate(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_singleReceiverUpdate(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -409,124 +314,81 @@ func TestAccAzureRMMonitorActionGroup_singleReceiverUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_emailReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_emailReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_itsmReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_itsmReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_azureAppPushReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_azureAppPushReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_smsReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_smsReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_webhookReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_webhookReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_automationRunbookReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_automationRunbookReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_voiceReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_voiceReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_logicAppReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_logicAppReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_azureFunctionReceiver(ri, rs, location), + Config: testAccAzureRMMonitorActionGroup_azureFunctionReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_armRoleReceiver(ri, location), + Config: testAccAzureRMMonitorActionGroup_armRoleReceiver(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMonitorActionGroup_multipleReceiversUpdate(t *testing.T) { - resourceName := "azurerm_monitor_action_group.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -534,43 +396,31 @@ func TestAccAzureRMMonitorActionGroup_multipleReceiversUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMMonitorActionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMonitorActionGroup_basic(ri, location), + Config: testAccAzureRMMonitorActionGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_complete(ri, rs, location), + Config: testAccAzureRMMonitorActionGroup_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMonitorActionGroup_basic(ri, location), + Config: testAccAzureRMMonitorActionGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMonitorActionGroupExists(resourceName), + testCheckAzureRMMonitorActionGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMMonitorActionGroup_basic(rInt int, location string) string { +func testAccAzureRMMonitorActionGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -582,11 +432,11 @@ resource "azurerm_monitor_action_group" "test" { resource_group_name = "${azurerm_resource_group.test.name}" short_name = "acctestag" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMonitorActionGroup_requiresImport(rInt int, location string) string { - template := testAccAzureRMMonitorActionGroup_basic(rInt, location) +func testAccAzureRMMonitorActionGroup_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMMonitorActionGroup_basic(data) return fmt.Sprintf(` %s @@ -598,7 +448,7 @@ resource "azurerm_monitor_action_group" "import" { `, template) } -func testAccAzureRMMonitorActionGroup_emailReceiver(rInt int, location string) string { +func testAccAzureRMMonitorActionGroup_emailReceiver(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -616,10 +466,10 @@ resource "azurerm_monitor_action_group" "test" { use_common_alert_schema = false } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMonitorActionGroup_itsmReceiver(rInt int, location string) string { +func testAccAzureRMMonitorActionGroup_itsmReceiver(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -639,10 +489,10 @@ resource "azurerm_monitor_action_group" "test" { region = "eastus" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMonitorActionGroup_azureAppPushReceiver(rInt int, location string) string { +func testAccAzureRMMonitorActionGroup_azureAppPushReceiver(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -659,10 +509,10 @@ resource "azurerm_monitor_action_group" "test" { email_address = "admin@contoso.com" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMonitorActionGroup_smsReceiver(rInt int, location string) string { +func testAccAzureRMMonitorActionGroup_smsReceiver(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -680,10 +530,10 @@ resource "azurerm_monitor_action_group" "test" { phone_number = "1231231234" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMonitorActionGroup_webhookReceiver(rInt int, location string) string { +func testAccAzureRMMonitorActionGroup_webhookReceiver(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -701,10 +551,10 @@ resource "azurerm_monitor_action_group" "test" { use_common_alert_schema = true } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMonitorActionGroup_automationRunbookReceiver(rInt int, location string) string { +func testAccAzureRMMonitorActionGroup_automationRunbookReceiver(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -751,10 +601,10 @@ resource "azurerm_automation_runbook" "test" { uri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-automation-runbook-getvms/Runbooks/Get-AzureVMTutorial.ps1" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMonitorActionGroup_voiceReceiver(rInt int, location string) string { +func testAccAzureRMMonitorActionGroup_voiceReceiver(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -772,10 +622,10 @@ resource "azurerm_monitor_action_group" "test" { phone_number = "1231231234" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMonitorActionGroup_logicAppReceiver(rInt int, location string) string { +func testAccAzureRMMonitorActionGroup_logicAppReceiver(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -816,10 +666,10 @@ schema = < Date: Fri, 20 Dec 2019 21:02:35 -0800 Subject: [PATCH 109/203] msi: switching to the new test structure --- ...data_source_user_assigned_identity_test.go | 33 ++++++-------- ...esource_arm_user_assigned_identity_test.go | 44 +++++++------------ 2 files changed, 30 insertions(+), 47 deletions(-) rename azurerm/internal/services/msi/{ => tests}/data_source_user_assigned_identity_test.go (60%) rename azurerm/internal/services/msi/{ => tests}/resource_arm_user_assigned_identity_test.go (72%) diff --git a/azurerm/internal/services/msi/data_source_user_assigned_identity_test.go b/azurerm/internal/services/msi/tests/data_source_user_assigned_identity_test.go similarity index 60% rename from azurerm/internal/services/msi/data_source_user_assigned_identity_test.go rename to azurerm/internal/services/msi/tests/data_source_user_assigned_identity_test.go index a890aa30de20..0b0afe660257 100644 --- a/azurerm/internal/services/msi/data_source_user_assigned_identity_test.go +++ b/azurerm/internal/services/msi/tests/data_source_user_assigned_identity_test.go @@ -1,4 +1,4 @@ -package msi +package tests import ( "fmt" @@ -8,35 +8,28 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) func TestAccDataSourceAzureRMUserAssignedIdentity_basic(t *testing.T) { - dataSourceName := "data.azurerm_user_assigned_identity.test" - resourceName := "azurerm_user_assigned_identity.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_user_assigned_identity", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMUserAssignedIdentity_basic(ri, acceptance.Location(), rs), + Config: testAccDataSourceAzureRMUserAssignedIdentity_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("acctest%s-uai", rs)), - resource.TestCheckResourceAttr(dataSourceName, "resource_group_name", fmt.Sprintf("acctest%d-rg", ri)), - resource.TestCheckResourceAttr(dataSourceName, "location", azure.NormalizeLocation(location)), - resource.TestMatchResourceAttr(dataSourceName, "principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(dataSourceName, "client_id", validate.UUIDRegExp), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - testEqualResourceAttr(dataSourceName, resourceName, "principal_id"), - testEqualResourceAttr(dataSourceName, resourceName, "client_id"), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctest%s-uai", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", fmt.Sprintf("acctest%d-rg", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestMatchResourceAttr(data.ResourceName, "principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "client_id", validate.UUIDRegExp), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + testEqualResourceAttr(data.ResourceName, "data."+data.ResourceName, "principal_id"), + testEqualResourceAttr(data.ResourceName, "data."+data.ResourceName, "client_id"), ), }, }, @@ -67,7 +60,7 @@ func testEqualResourceAttr(dataSourceName string, resourceName string, attrName } } -func testAccDataSourceAzureRMUserAssignedIdentity_basic(rInt int, location string, rString string) string { +func testAccDataSourceAzureRMUserAssignedIdentity_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest%d-rg" @@ -88,5 +81,5 @@ data "azurerm_user_assigned_identity" "test" { name = "${azurerm_user_assigned_identity.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/msi/resource_arm_user_assigned_identity_test.go b/azurerm/internal/services/msi/tests/resource_arm_user_assigned_identity_test.go similarity index 72% rename from azurerm/internal/services/msi/resource_arm_user_assigned_identity_test.go rename to azurerm/internal/services/msi/tests/resource_arm_user_assigned_identity_test.go index 1aa19d34f07f..bdd7707c6545 100644 --- a/azurerm/internal/services/msi/resource_arm_user_assigned_identity_test.go +++ b/azurerm/internal/services/msi/tests/resource_arm_user_assigned_identity_test.go @@ -1,4 +1,4 @@ -package msi +package tests import ( "fmt" @@ -6,10 +6,8 @@ import ( "net/http" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" @@ -17,9 +15,7 @@ import ( ) func TestAccAzureRMUserAssignedIdentity_basic(t *testing.T) { - resourceName := "azurerm_user_assigned_identity.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(14) + data := acceptance.BuildTestData(t, "azurerm_user_assigned_identity", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,18 +23,14 @@ func TestAccAzureRMUserAssignedIdentity_basic(t *testing.T) { CheckDestroy: testCheckAzureRMUserAssignedIdentityDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMUserAssignedIdentity_basic(ri, acceptance.Location(), rs), + Config: testAccAzureRMUserAssignedIdentity_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMUserAssignedIdentityExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "client_id", validate.UUIDRegExp), + testCheckAzureRMUserAssignedIdentityExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "client_id", validate.UUIDRegExp), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -48,9 +40,7 @@ func TestAccAzureRMUserAssignedIdentity_requiresImport(t *testing.T) { return } - resourceName := "azurerm_user_assigned_identity.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(14) + data := acceptance.BuildTestData(t, "azurerm_user_assigned_identity", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -58,15 +48,15 @@ func TestAccAzureRMUserAssignedIdentity_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMUserAssignedIdentityDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMUserAssignedIdentity_basic(ri, acceptance.Location(), rs), + Config: testAccAzureRMUserAssignedIdentity_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMUserAssignedIdentityExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "principal_id", validate.UUIDRegExp), - resource.TestMatchResourceAttr(resourceName, "client_id", validate.UUIDRegExp), + testCheckAzureRMUserAssignedIdentityExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "principal_id", validate.UUIDRegExp), + resource.TestMatchResourceAttr(data.ResourceName, "client_id", validate.UUIDRegExp), ), }, { - Config: testAccAzureRMUserAssignedIdentity_requiresImport(ri, acceptance.Location(), rs), + Config: testAccAzureRMUserAssignedIdentity_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_user_assigned_identity"), }, }, @@ -131,7 +121,7 @@ func testCheckAzureRMUserAssignedIdentityDestroy(s *terraform.State) error { return nil } -func testAccAzureRMUserAssignedIdentity_basic(rInt int, location string, rString string) string { +func testAccAzureRMUserAssignedIdentity_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -143,10 +133,10 @@ resource "azurerm_user_assigned_identity" "test" { resource_group_name = "${azurerm_resource_group.test.name}" location = "${azurerm_resource_group.test.location}" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMUserAssignedIdentity_requiresImport(rInt int, location string, rString string) string { +func testAccAzureRMUserAssignedIdentity_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -155,5 +145,5 @@ resource "azurerm_user_assigned_identity" "import" { resource_group_name = "${azurerm_user_assigned_identity.test.resource_group_name}" location = "${azurerm_user_assigned_identity.test.location}" } -`, testAccAzureRMUserAssignedIdentity_basic(rInt, location, rString)) +`, testAccAzureRMUserAssignedIdentity_basic(data)) } From 02a7f08f9577ee7f099c4ca3bd9f60d637378303 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 20 Dec 2019 21:16:25 -0800 Subject: [PATCH 110/203] mssql: switching to the new test structure --- .../data_source_mssql_elasticpool_test.go | 33 ++- ...erability_assessment_rule_baseline_test.go | 73 ++---- .../resource_arm_mssql_elasticpool_test.go | 248 ++++++++---------- ...mssql_server_security_alert_policy_test.go | 84 +++--- ...ql_server_vulnerability_assessment_test.go | 60 ++--- 5 files changed, 205 insertions(+), 293 deletions(-) rename azurerm/internal/services/mssql/{ => tests}/data_source_mssql_elasticpool_test.go (61%) rename azurerm/internal/services/mssql/{ => tests}/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go (81%) rename azurerm/internal/services/mssql/{ => tests}/resource_arm_mssql_elasticpool_test.go (52%) rename azurerm/internal/services/mssql/{ => tests}/resource_arm_mssql_server_security_alert_policy_test.go (61%) rename azurerm/internal/services/mssql/{ => tests}/resource_arm_mssql_server_vulnerability_assessment_test.go (75%) diff --git a/azurerm/internal/services/mssql/data_source_mssql_elasticpool_test.go b/azurerm/internal/services/mssql/tests/data_source_mssql_elasticpool_test.go similarity index 61% rename from azurerm/internal/services/mssql/data_source_mssql_elasticpool_test.go rename to azurerm/internal/services/mssql/tests/data_source_mssql_elasticpool_test.go index 7cdff4ed43d9..41d2e55a26fe 100644 --- a/azurerm/internal/services/mssql/data_source_mssql_elasticpool_test.go +++ b/azurerm/internal/services/mssql/tests/data_source_mssql_elasticpool_test.go @@ -1,18 +1,15 @@ -package mssql +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMMsSqlElasticPool_basic(t *testing.T) { - dataSourceName := "data.azurerm_mssql_elasticpool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_mssql_elasticpool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,25 +17,25 @@ func TestAccDataSourceAzureRMMsSqlElasticPool_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMsSqlElasticPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMMsSqlElasticPool_basic(ri, location), + Config: testAccDataSourceAzureRMMsSqlElasticPool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "server_name"), - resource.TestCheckResourceAttr(dataSourceName, "location", location), - resource.TestCheckResourceAttr(dataSourceName, "max_size_gb", "50"), - resource.TestCheckResourceAttr(dataSourceName, "per_db_min_capacity", "0"), - resource.TestCheckResourceAttr(dataSourceName, "per_db_max_capacity", "4"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - resource.TestCheckResourceAttr(dataSourceName, "zone_redundant", "false"), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "server_name"), + resource.TestCheckResourceAttr(data.ResourceName, "location", data.Locations.Primary), + resource.TestCheckResourceAttr(data.ResourceName, "max_size_gb", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "per_db_min_capacity", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "per_db_max_capacity", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "zone_redundant", "false"), ), }, }, }) } -func testAccDataSourceAzureRMMsSqlElasticPool_basic(rInt int, location string) string { +func testAccDataSourceAzureRMMsSqlElasticPool_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -80,5 +77,5 @@ data "azurerm_mssql_elasticpool" "test" { resource_group_name = "${azurerm_resource_group.test.name}" server_name = "${azurerm_sql_server.test.name}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go b/azurerm/internal/services/mssql/tests/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go similarity index 81% rename from azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go rename to azurerm/internal/services/mssql/tests/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go index ebe7e6a7ff0a..c8c47f12402f 100644 --- a/azurerm/internal/services/mssql/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go +++ b/azurerm/internal/services/mssql/tests/resource_arm_mssql_database_vulnerability_assessment_rule_baseline_test.go @@ -1,4 +1,4 @@ -package mssql +package tests import ( "fmt" @@ -9,15 +9,13 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_basic(t *testing.T) { - resourceName := "azurerm_mssql_database_vulnerability_assessment_rule_baseline.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mssql_database_vulnerability_assessment_rule_baseline", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,59 +23,46 @@ func TestAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_basic(t *tes CheckDestroy: testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_basic(ri, acceptance.Location()), + Config: testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "rule_id", "VA2002"), - resource.TestCheckResourceAttr(resourceName, "baseline_name", "default"), - resource.TestCheckResourceAttr(resourceName, "baseline_result.#", "2"), + testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "rule_id", "VA2002"), + resource.TestCheckResourceAttr(data.ResourceName, "baseline_name", "default"), + resource.TestCheckResourceAttr(data.ResourceName, "baseline_result.#", "2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_master(t *testing.T) { - resourceName := "azurerm_mssql_database_vulnerability_assessment_rule_baseline.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mssql_database_vulnerability_assessment_rule_baseline", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_master(ri, acceptance.Location()), + Config: testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_master(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "rule_id", "VA2065"), - resource.TestCheckResourceAttr(resourceName, "baseline_name", "master"), - resource.TestCheckResourceAttr(resourceName, "baseline_result.#", "1"), + testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "rule_id", "VA2065"), + resource.TestCheckResourceAttr(data.ResourceName, "baseline_name", "master"), + resource.TestCheckResourceAttr(data.ResourceName, "baseline_result.#", "1"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMDatabaseVulnerabilityAssessmentRuleBaseline_update(ri, acceptance.Location()), + Config: testAccAzureRMDatabaseVulnerabilityAssessmentRuleBaseline_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "rule_id", "VA2065"), - resource.TestCheckResourceAttr(resourceName, "baseline_name", "master"), - resource.TestCheckResourceAttr(resourceName, "baseline_result.#", "2"), + testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "rule_id", "VA2065"), + resource.TestCheckResourceAttr(data.ResourceName, "baseline_name", "master"), + resource.TestCheckResourceAttr(data.ResourceName, "baseline_result.#", "2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -151,8 +136,8 @@ func testCheckAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaselineDestroy(s * return nil } -func testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_basic(rInt int, location string) string { - database := testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_database(rInt, location) +func testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_basic(data acceptance.TestData) string { + database := testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_database(data) return fmt.Sprintf(` %s @@ -184,8 +169,8 @@ resource "azurerm_mssql_database_vulnerability_assessment_rule_baseline" "test" `, database) } -func testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_master(rInt int, location string) string { - database := testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_database(rInt, location) +func testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_master(data acceptance.TestData) string { + database := testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_database(data) return fmt.Sprintf(` %s @@ -206,8 +191,8 @@ resource "azurerm_mssql_database_vulnerability_assessment_rule_baseline" "test" `, database) } -func testAccAzureRMDatabaseVulnerabilityAssessmentRuleBaseline_update(rInt int, location string) string { - database := testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_database(rInt, location) +func testAccAzureRMDatabaseVulnerabilityAssessmentRuleBaseline_update(data acceptance.TestData) string { + database := testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_database(data) return fmt.Sprintf(` %s @@ -235,7 +220,7 @@ resource "azurerm_mssql_database_vulnerability_assessment_rule_baseline" "test" `, database) } -func testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_database(rInt int, location string) string { +func testAccAzureRMMssqlDatabaseVulnerabilityAssessmentRuleBaseline_database(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-mssql-%d" @@ -284,5 +269,5 @@ resource "azurerm_sql_database" "test" { location = azurerm_resource_group.test.location edition = "Standard" } -`, rInt, location, rInt, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/mssql/resource_arm_mssql_elasticpool_test.go b/azurerm/internal/services/mssql/tests/resource_arm_mssql_elasticpool_test.go similarity index 52% rename from azurerm/internal/services/mssql/resource_arm_mssql_elasticpool_test.go rename to azurerm/internal/services/mssql/tests/resource_arm_mssql_elasticpool_test.go index e4177a483e88..bab1a84cdd1b 100644 --- a/azurerm/internal/services/mssql/resource_arm_mssql_elasticpool_test.go +++ b/azurerm/internal/services/mssql/tests/resource_arm_mssql_elasticpool_test.go @@ -1,4 +1,4 @@ -package mssql +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,7 @@ import ( // TODO: add import tests func TestAccAzureRMMsSqlElasticPool_basic_DTU(t *testing.T) { - resourceName := "azurerm_mssql_elasticpool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,15 +22,15 @@ func TestAccAzureRMMsSqlElasticPool_basic_DTU(t *testing.T) { CheckDestroy: testCheckAzureRMMsSqlElasticPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMsSqlElasticPool_basic_DTU(ri, location), + Config: testAccAzureRMMsSqlElasticPool_basic_DTU(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "BasicPool"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "50"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "5"), - resource.TestCheckResourceAttrSet(resourceName, "max_size_gb"), - resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "BasicPool"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.min_capacity", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.max_capacity", "5"), + resource.TestCheckResourceAttrSet(data.ResourceName, "max_size_gb"), + resource.TestCheckResourceAttrSet(data.ResourceName, "zone_redundant"), ), }, }, @@ -46,9 +43,7 @@ func TestAccAzureRMMsSqlElasticPool_requiresImport(t *testing.T) { return } - resourceName := "azurerm_mssql_elasticpool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +51,13 @@ func TestAccAzureRMMsSqlElasticPool_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMsSqlElasticPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMsSqlElasticPool_basic_DTU(ri, location), + Config: testAccAzureRMMsSqlElasticPool_basic_DTU(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), ), }, { - Config: testAccAzureRMMsSqlElasticPool_requiresImport(ri, location), + Config: testAccAzureRMMsSqlElasticPool_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_mssql_elasticpool"), }, }, @@ -70,9 +65,8 @@ func TestAccAzureRMMsSqlElasticPool_requiresImport(t *testing.T) { } func TestAccAzureRMMsSqlElasticPool_standard_DTU(t *testing.T) { - resourceName := "azurerm_mssql_elasticpool.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMsSqlElasticPool_standard_DTU(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test") + config := testAccAzureRMMsSqlElasticPool_standard_DTU(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,29 +76,23 @@ func TestAccAzureRMMsSqlElasticPool_standard_DTU(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "StandardPool"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "50"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "50"), - resource.TestCheckResourceAttrSet(resourceName, "max_size_gb"), - resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "StandardPool"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.min_capacity", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.max_capacity", "50"), + resource.TestCheckResourceAttrSet(data.ResourceName, "max_size_gb"), + resource.TestCheckResourceAttrSet(data.ResourceName, "zone_redundant"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"max_size_gb"}, - }, + data.ImportStep("max_size_gb"), }, }) } func TestAccAzureRMMsSqlElasticPool_premium_DTU_zone_redundant(t *testing.T) { - resourceName := "azurerm_mssql_elasticpool.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMsSqlElasticPool_premium_DTU_zone_redundant(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test") + config := testAccAzureRMMsSqlElasticPool_premium_DTU_zone_redundant(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,25 +102,19 @@ func TestAccAzureRMMsSqlElasticPool_premium_DTU_zone_redundant(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "PremiumPool"), - resource.TestCheckResourceAttr(resourceName, "zone_redundant", "true"), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "PremiumPool"), + resource.TestCheckResourceAttr(data.ResourceName, "zone_redundant", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"max_size_gb"}, - }, + data.ImportStep("max_size_gb"), }, }) } func TestAccAzureRMMsSqlElasticPool_basic_vCore(t *testing.T) { - resourceName := "azurerm_mssql_elasticpool.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMsSqlElasticPool_basic_vCore(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test") + config := testAccAzureRMMsSqlElasticPool_basic_vCore(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -142,29 +124,23 @@ func TestAccAzureRMMsSqlElasticPool_basic_vCore(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "4"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0.25"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "4"), - resource.TestCheckResourceAttrSet(resourceName, "max_size_gb"), - resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.min_capacity", "0.25"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.max_capacity", "4"), + resource.TestCheckResourceAttrSet(data.ResourceName, "max_size_gb"), + resource.TestCheckResourceAttrSet(data.ResourceName, "zone_redundant"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"max_size_gb"}, - }, + data.ImportStep("max_size_gb"), }, }) } func TestAccAzureRMMsSqlElasticPool_basic_vCore_MaxSizeBytes(t *testing.T) { - resourceName := "azurerm_mssql_elasticpool.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMsSqlElasticPool_basic_vCore_MaxSizeBytes(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test") + config := testAccAzureRMMsSqlElasticPool_basic_vCore_MaxSizeBytes(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,29 +150,23 @@ func TestAccAzureRMMsSqlElasticPool_basic_vCore_MaxSizeBytes(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "4"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0.25"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "4"), - resource.TestCheckResourceAttr(resourceName, "max_size_bytes", "214748364800"), - resource.TestCheckResourceAttrSet(resourceName, "max_size_gb"), - resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.min_capacity", "0.25"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.max_capacity", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "max_size_bytes", "214748364800"), + resource.TestCheckResourceAttrSet(data.ResourceName, "max_size_gb"), + resource.TestCheckResourceAttrSet(data.ResourceName, "zone_redundant"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"max_size_gb"}, - }, + data.ImportStep("max_size_gb"), }, }) } func TestAccAzureRMMsSqlElasticPool_disappears(t *testing.T) { - resourceName := "azurerm_mssql_elasticpool.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMsSqlElasticPool_standard_DTU(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test") + config := testAccAzureRMMsSqlElasticPool_standard_DTU(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -206,12 +176,12 @@ func TestAccAzureRMMsSqlElasticPool_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "StandardPool"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "50"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "50"), - testCheckAzureRMMsSqlElasticPoolDisappears(resourceName), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "StandardPool"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.min_capacity", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.max_capacity", "50"), + testCheckAzureRMMsSqlElasticPoolDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -220,11 +190,9 @@ func TestAccAzureRMMsSqlElasticPool_disappears(t *testing.T) { } func TestAccAzureRMMsSqlElasticPool_resize_DTU(t *testing.T) { - resourceName := "azurerm_mssql_elasticpool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMMsSqlElasticPool_standard_DTU(ri, location) - postConfig := testAccAzureRMMsSqlElasticPool_resize_DTU(ri, location) + data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test") + preConfig := testAccAzureRMMsSqlElasticPool_standard_DTU(data) + postConfig := testAccAzureRMMsSqlElasticPool_resize_DTU(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -234,21 +202,21 @@ func TestAccAzureRMMsSqlElasticPool_resize_DTU(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "StandardPool"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "50"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "50"), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "StandardPool"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.min_capacity", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.max_capacity", "50"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "StandardPool"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "100"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "50"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "100"), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "StandardPool"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.min_capacity", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.max_capacity", "100"), ), }, }, @@ -256,11 +224,9 @@ func TestAccAzureRMMsSqlElasticPool_resize_DTU(t *testing.T) { } func TestAccAzureRMMsSqlElasticPool_resize_vCore(t *testing.T) { - resourceName := "azurerm_mssql_elasticpool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMMsSqlElasticPool_basic_vCore(ri, location) - postConfig := testAccAzureRMMsSqlElasticPool_resize_vCore(ri, location) + data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test") + preConfig := testAccAzureRMMsSqlElasticPool_basic_vCore(data) + postConfig := testAccAzureRMMsSqlElasticPool_resize_vCore(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -270,21 +236,21 @@ func TestAccAzureRMMsSqlElasticPool_resize_vCore(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "4"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0.25"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "4"), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.min_capacity", "0.25"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.max_capacity", "4"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMsSqlElasticPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "8"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0"), - resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "8"), + testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "8"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.min_capacity", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "per_database_settings.0.max_capacity", "8"), ), }, }, @@ -367,12 +333,12 @@ func testCheckAzureRMMsSqlElasticPoolDisappears(resourceName string) resource.Te } } -func testAccAzureRMMsSqlElasticPool_basic_DTU(rInt int, location string) string { - return testAccAzureRMMsSqlElasticPool_DTU_Template(rInt, location, "BasicPool", "Basic", 50, 4.8828125, 0, 5, false) +func testAccAzureRMMsSqlElasticPool_basic_DTU(data acceptance.TestData) string { + return testAccAzureRMMsSqlElasticPool_DTU_Template(data, "BasicPool", "Basic", 50, 4.8828125, 0, 5, false) } -func testAccAzureRMMsSqlElasticPool_requiresImport(rInt int, location string) string { - template := testAccAzureRMMsSqlElasticPool_DTU_Template(rInt, location, "BasicPool", "Basic", 50, 5242880000, 0, 5, false) +func testAccAzureRMMsSqlElasticPool_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMMsSqlElasticPool_DTU_Template(data, "BasicPool", "Basic", 50, 5242880000, 0, 5, false) return fmt.Sprintf(` %s @@ -388,31 +354,31 @@ resource "azurerm_mssql_elasticpool" "import" { `, template) } -func testAccAzureRMMsSqlElasticPool_premium_DTU_zone_redundant(rInt int, location string) string { - return testAccAzureRMMsSqlElasticPool_DTU_Template(rInt, location, "PremiumPool", "Premium", 125, 50, 0, 50, true) +func testAccAzureRMMsSqlElasticPool_premium_DTU_zone_redundant(data acceptance.TestData) string { + return testAccAzureRMMsSqlElasticPool_DTU_Template(data, "PremiumPool", "Premium", 125, 50, 0, 50, true) } -func testAccAzureRMMsSqlElasticPool_standard_DTU(rInt int, location string) string { - return testAccAzureRMMsSqlElasticPool_DTU_Template(rInt, location, "StandardPool", "Standard", 50, 50, 0, 50, false) +func testAccAzureRMMsSqlElasticPool_standard_DTU(data acceptance.TestData) string { + return testAccAzureRMMsSqlElasticPool_DTU_Template(data, "StandardPool", "Standard", 50, 50, 0, 50, false) } -func testAccAzureRMMsSqlElasticPool_resize_DTU(rInt int, location string) string { - return testAccAzureRMMsSqlElasticPool_DTU_Template(rInt, location, "StandardPool", "Standard", 100, 100, 50, 100, false) +func testAccAzureRMMsSqlElasticPool_resize_DTU(data acceptance.TestData) string { + return testAccAzureRMMsSqlElasticPool_DTU_Template(data, "StandardPool", "Standard", 100, 100, 50, 100, false) } -func testAccAzureRMMsSqlElasticPool_basic_vCore(rInt int, location string) string { - return testAccAzureRMMsSqlElasticPool_vCore_Template(rInt, location, "GP_Gen5", "GeneralPurpose", 4, "Gen5", 0.25, 4) +func testAccAzureRMMsSqlElasticPool_basic_vCore(data acceptance.TestData) string { + return testAccAzureRMMsSqlElasticPool_vCore_Template(data, "GP_Gen5", "GeneralPurpose", 4, "Gen5", 0.25, 4) } -func testAccAzureRMMsSqlElasticPool_basic_vCore_MaxSizeBytes(rInt int, location string) string { - return testAccAzureRMMsSqlElasticPool_vCore_MaxSizeBytes_Template(rInt, location, "GP_Gen5", "GeneralPurpose", 4, "Gen5", 0.25, 4) +func testAccAzureRMMsSqlElasticPool_basic_vCore_MaxSizeBytes(data acceptance.TestData) string { + return testAccAzureRMMsSqlElasticPool_vCore_MaxSizeBytes_Template(data, "GP_Gen5", "GeneralPurpose", 4, "Gen5", 0.25, 4) } -func testAccAzureRMMsSqlElasticPool_resize_vCore(rInt int, location string) string { - return testAccAzureRMMsSqlElasticPool_vCore_Template(rInt, location, "GP_Gen5", "GeneralPurpose", 8, "Gen5", 0, 8) +func testAccAzureRMMsSqlElasticPool_resize_vCore(data acceptance.TestData) string { + return testAccAzureRMMsSqlElasticPool_vCore_Template(data, "GP_Gen5", "GeneralPurpose", 8, "Gen5", 0, 8) } -func testAccAzureRMMsSqlElasticPool_vCore_Template(rInt int, location string, skuName string, skuTier string, skuCapacity int, skuFamily string, databaseSettingsMin float64, databaseSettingsMax float64) string { +func testAccAzureRMMsSqlElasticPool_vCore_Template(data acceptance.TestData, skuName string, skuTier string, skuCapacity int, skuFamily string, databaseSettingsMin float64, databaseSettingsMax float64) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -447,10 +413,10 @@ resource "azurerm_mssql_elasticpool" "test" { max_capacity = %.2[8]f } } -`, rInt, location, skuName, skuTier, skuCapacity, skuFamily, databaseSettingsMin, databaseSettingsMax) +`, data.RandomInteger, data.Locations.Primary, skuName, skuTier, skuCapacity, skuFamily, databaseSettingsMin, databaseSettingsMax) } -func testAccAzureRMMsSqlElasticPool_vCore_MaxSizeBytes_Template(rInt int, location string, skuName string, skuTier string, skuCapacity int, skuFamily string, databaseSettingsMin float64, databaseSettingsMax float64) string { +func testAccAzureRMMsSqlElasticPool_vCore_MaxSizeBytes_Template(data acceptance.TestData, skuName string, skuTier string, skuCapacity int, skuFamily string, databaseSettingsMin float64, databaseSettingsMax float64) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -485,10 +451,10 @@ resource "azurerm_mssql_elasticpool" "test" { max_capacity = %.2[8]f } } -`, rInt, location, skuName, skuTier, skuCapacity, skuFamily, databaseSettingsMin, databaseSettingsMax) +`, data.RandomInteger, data.Locations.Primary, skuName, skuTier, skuCapacity, skuFamily, databaseSettingsMin, databaseSettingsMax) } -func testAccAzureRMMsSqlElasticPool_DTU_Template(rInt int, location string, skuName string, skuTier string, skuCapacity int, maxSizeGB float64, databaseSettingsMin int, databaseSettingsMax int, zoneRedundant bool) string { +func testAccAzureRMMsSqlElasticPool_DTU_Template(data acceptance.TestData, skuName string, skuTier string, skuCapacity int, maxSizeGB float64, databaseSettingsMin int, databaseSettingsMax int, zoneRedundant bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -523,5 +489,5 @@ resource "azurerm_mssql_elasticpool" "test" { max_capacity = %[8]d } } -`, rInt, location, skuName, skuTier, skuCapacity, maxSizeGB, databaseSettingsMin, databaseSettingsMax, zoneRedundant) +`, data.RandomInteger, data.Locations.Primary, skuName, skuTier, skuCapacity, maxSizeGB, databaseSettingsMin, databaseSettingsMax, zoneRedundant) } diff --git a/azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy_test.go b/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_security_alert_policy_test.go similarity index 61% rename from azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy_test.go rename to azurerm/internal/services/mssql/tests/resource_arm_mssql_server_security_alert_policy_test.go index 6f3d3c51c6c6..c240ee6632ad 100644 --- a/azurerm/internal/services/mssql/resource_arm_mssql_server_security_alert_policy_test.go +++ b/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_security_alert_policy_test.go @@ -1,4 +1,4 @@ -package mssql +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMMssqlServerSecurityAlertPolicy_basic(t *testing.T) { - resourceName := "azurerm_mssql_server_security_alert_policy.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mssql_server_security_alert_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,29 +21,23 @@ func TestAccAzureRMMssqlServerSecurityAlertPolicy_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMssqlServerSecurityAlertPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMssqlServerSecurityAlertPolicy_basic(ri, acceptance.Location()), + Config: testAccAzureRMMssqlServerSecurityAlertPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMssqlServerSecurityAlertPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "state", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "disabled_alerts.#", "2"), - resource.TestCheckResourceAttr(resourceName, "email_account_admins", "false"), - resource.TestCheckResourceAttr(resourceName, "retention_days", "20"), - resource.TestCheckResourceAttr(resourceName, "email_addresses.#", "0"), + testCheckAzureRMMssqlServerSecurityAlertPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "state", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "disabled_alerts.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "email_account_admins", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_days", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "email_addresses.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"storage_account_access_key"}, - }, + data.ImportStep("storage_account_access_key"), }, }) } func TestAccAzureRMMssqlServerSecurityAlertPolicy_update(t *testing.T) { - resourceName := "azurerm_mssql_server_security_alert_policy.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mssql_server_security_alert_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,39 +45,29 @@ func TestAccAzureRMMssqlServerSecurityAlertPolicy_update(t *testing.T) { CheckDestroy: testCheckAzureRMMssqlServerSecurityAlertPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMssqlServerSecurityAlertPolicy_basic(ri, acceptance.Location()), + Config: testAccAzureRMMssqlServerSecurityAlertPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMssqlServerSecurityAlertPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "state", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "disabled_alerts.#", "2"), - resource.TestCheckResourceAttr(resourceName, "email_account_admins", "false"), - resource.TestCheckResourceAttr(resourceName, "retention_days", "20"), - resource.TestCheckResourceAttr(resourceName, "email_addresses.#", "0"), + testCheckAzureRMMssqlServerSecurityAlertPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "state", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "disabled_alerts.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "email_account_admins", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_days", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "email_addresses.#", "0"), ), }, + data.ImportStep("storage_account_access_key"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"storage_account_access_key"}, - }, - { - Config: testAccAzureRMMssqlServerSecurityAlertPolicy_update(ri, acceptance.Location()), + Config: testAccAzureRMMssqlServerSecurityAlertPolicy_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMssqlServerSecurityAlertPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "state", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "disabled_alerts.#", "0"), - resource.TestCheckResourceAttr(resourceName, "email_account_admins", "true"), - resource.TestCheckResourceAttr(resourceName, "retention_days", "30"), - resource.TestCheckResourceAttr(resourceName, "email_addresses.#", "0"), + testCheckAzureRMMssqlServerSecurityAlertPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "state", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "disabled_alerts.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "email_account_admins", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_days", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "email_addresses.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"storage_account_access_key"}, - }, + data.ImportStep("storage_account_access_key"), }, }) } @@ -142,8 +124,8 @@ func testCheckAzureRMMssqlServerSecurityAlertPolicyDestroy(s *terraform.State) e return nil } -func testAccAzureRMMssqlServerSecurityAlertPolicy_basic(rInt int, location string) string { - server := testAccAzureRMMssqlServerSecurityAlertPolicy_server(rInt, location) +func testAccAzureRMMssqlServerSecurityAlertPolicy_basic(data acceptance.TestData) string { + server := testAccAzureRMMssqlServerSecurityAlertPolicy_server(data) return fmt.Sprintf(` %s @@ -163,8 +145,8 @@ resource "azurerm_mssql_server_security_alert_policy" "test" { `, server) } -func testAccAzureRMMssqlServerSecurityAlertPolicy_update(rInt int, location string) string { - server := testAccAzureRMMssqlServerSecurityAlertPolicy_server(rInt, location) +func testAccAzureRMMssqlServerSecurityAlertPolicy_update(data acceptance.TestData) string { + server := testAccAzureRMMssqlServerSecurityAlertPolicy_server(data) return fmt.Sprintf(` %s @@ -179,7 +161,7 @@ resource "azurerm_mssql_server_security_alert_policy" "test" { `, server) } -func testAccAzureRMMssqlServerSecurityAlertPolicy_server(rInt int, location string) string { +func testAccAzureRMMssqlServerSecurityAlertPolicy_server(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-mssql-%d" @@ -202,5 +184,5 @@ resource "azurerm_storage_account" "test" { account_tier = "Standard" account_replication_type = "GRS" } -`, rInt, location, rInt, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment_test.go b/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_vulnerability_assessment_test.go similarity index 75% rename from azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment_test.go rename to azurerm/internal/services/mssql/tests/resource_arm_mssql_server_vulnerability_assessment_test.go index 165a42b04332..4efbee7536b2 100644 --- a/azurerm/internal/services/mssql/resource_arm_mssql_server_vulnerability_assessment_test.go +++ b/azurerm/internal/services/mssql/tests/resource_arm_mssql_server_vulnerability_assessment_test.go @@ -1,4 +1,4 @@ -package mssql +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMMssqlServerVulnerabilityAssessment_basic(t *testing.T) { - resourceName := "azurerm_mssql_server_vulnerability_assessment.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mssql_server_vulnerability_assessment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,24 +22,18 @@ func TestAccAzureRMMssqlServerVulnerabilityAssessment_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMssqlServerVulnerabilityAssessmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMssqlServerVulnerabilityAssessment_basic(ri, acceptance.Location()), + Config: testAccAzureRMMssqlServerVulnerabilityAssessment_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMssqlServerVulnerabilityAssessmentExists(resourceName), + testCheckAzureRMMssqlServerVulnerabilityAssessmentExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"storage_account_access_key"}, - }, + data.ImportStep("storage_account_access_key"), }, }) } func TestAccAzureRMMssqlServerVulnerabilityAssessment_update(t *testing.T) { - resourceName := "azurerm_mssql_server_vulnerability_assessment.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mssql_server_vulnerability_assessment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -49,32 +41,22 @@ func TestAccAzureRMMssqlServerVulnerabilityAssessment_update(t *testing.T) { CheckDestroy: testCheckAzureRMMssqlServerVulnerabilityAssessmentDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMssqlServerVulnerabilityAssessment_basic(ri, acceptance.Location()), + Config: testAccAzureRMMssqlServerVulnerabilityAssessment_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMssqlServerVulnerabilityAssessmentExists(resourceName), + testCheckAzureRMMssqlServerVulnerabilityAssessmentExists(data.ResourceName), ), }, + data.ImportStep("storage_account_access_key"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"storage_account_access_key"}, - }, - { - Config: testAccAzureRMMssqlServerVulnerabilityAssessment_update(ri, acceptance.Location()), + Config: testAccAzureRMMssqlServerVulnerabilityAssessment_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMssqlServerVulnerabilityAssessmentExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "recurring_scans.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "recurring_scans.0.emails.#", "2"), - resource.TestCheckResourceAttr(resourceName, "recurring_scans.0.email_subscription_admins", "true"), + testCheckAzureRMMssqlServerVulnerabilityAssessmentExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "recurring_scans.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "recurring_scans.0.emails.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "recurring_scans.0.email_subscription_admins", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"storage_account_access_key"}, - }, + data.ImportStep("storage_account_access_key"), }, }) } @@ -141,8 +123,8 @@ func testCheckAzureRMMssqlServerVulnerabilityAssessmentDestroy(s *terraform.Stat return nil } -func testAccAzureRMMssqlServerVulnerabilityAssessment_basic(rInt int, location string) string { - server := testAccAzureRMMssqlServerVulnerabilityAssessment_server(rInt, location) +func testAccAzureRMMssqlServerVulnerabilityAssessment_basic(data acceptance.TestData) string { + server := testAccAzureRMMssqlServerVulnerabilityAssessment_server(data) return fmt.Sprintf(` %s @@ -155,8 +137,8 @@ resource "azurerm_mssql_server_vulnerability_assessment" "test" { `, server) } -func testAccAzureRMMssqlServerVulnerabilityAssessment_update(rInt int, location string) string { - server := testAccAzureRMMssqlServerVulnerabilityAssessment_server(rInt, location) +func testAccAzureRMMssqlServerVulnerabilityAssessment_update(data acceptance.TestData) string { + server := testAccAzureRMMssqlServerVulnerabilityAssessment_server(data) return fmt.Sprintf(` %s @@ -178,7 +160,7 @@ resource "azurerm_mssql_server_vulnerability_assessment" "test" { `, server) } -func testAccAzureRMMssqlServerVulnerabilityAssessment_server(rInt int, location string) string { +func testAccAzureRMMssqlServerVulnerabilityAssessment_server(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-mssql-%d" @@ -213,5 +195,5 @@ resource "azurerm_mssql_server_security_alert_policy" "test" { server_name = azurerm_sql_server.test.name state = "Enabled" } -`, rInt, location, rInt, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 8034366ef5ae779898a3ae05039cf58388f0dc2f Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 20 Dec 2019 21:25:05 -0800 Subject: [PATCH 111/203] mysql: switching to the new test structure --- .../resource_arm_mysql_configuration_test.go | 80 +++---- .../resource_arm_mysql_database_test.go | 71 +++--- .../resource_arm_mysql_firewall_rule_test.go | 33 ++- .../resource_arm_mysql_server_test.go | 217 +++++++----------- ...rce_arm_mysql_virtual_network_rule_test.go | 75 +++--- 5 files changed, 188 insertions(+), 288 deletions(-) rename azurerm/internal/services/mysql/{ => tests}/resource_arm_mysql_configuration_test.go (70%) rename azurerm/internal/services/mysql/{ => tests}/resource_arm_mysql_database_test.go (79%) rename azurerm/internal/services/mysql/{ => tests}/resource_arm_mysql_firewall_rule_test.go (84%) rename azurerm/internal/services/mysql/{ => tests}/resource_arm_mysql_server_test.go (66%) rename azurerm/internal/services/mysql/{ => tests}/resource_arm_mysql_virtual_network_rule_test.go (85%) diff --git a/azurerm/internal/services/mysql/resource_arm_mysql_configuration_test.go b/azurerm/internal/services/mysql/tests/resource_arm_mysql_configuration_test.go similarity index 70% rename from azurerm/internal/services/mysql/resource_arm_mysql_configuration_test.go rename to azurerm/internal/services/mysql/tests/resource_arm_mysql_configuration_test.go index f6d2fe367adc..76ee8229a45d 100644 --- a/azurerm/internal/services/mysql/resource_arm_mysql_configuration_test.go +++ b/azurerm/internal/services/mysql/tests/resource_arm_mysql_configuration_test.go @@ -1,4 +1,4 @@ -package mysql +package tests import ( "fmt" @@ -6,15 +6,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMMySQLConfiguration_characterSetServer(t *testing.T) { - resourceName := "azurerm_mysql_configuration.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMMySQLConfiguration_characterSetServer(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLConfiguration_characterSetServer(ri, acceptance.Location()), + Config: testAccAzureRMMySQLConfiguration_characterSetServer(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLConfigurationValue(resourceName, "hebrew"), + testCheckAzureRMMySQLConfigurationValue(data.ResourceName, "hebrew"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMySQLConfiguration_empty(ri, acceptance.Location()), + Config: testAccAzureRMMySQLConfiguration_empty(data), Check: resource.ComposeTestCheckFunc( // "delete" resets back to the default value - testCheckAzureRMMySQLConfigurationValueReset(ri, "character_set_server"), + testCheckAzureRMMySQLConfigurationValueReset(data, "character_set_server"), ), }, }, @@ -44,8 +38,7 @@ func TestAccAzureRMMySQLConfiguration_characterSetServer(t *testing.T) { } func TestAccAzureRMMySQLConfiguration_interactiveTimeout(t *testing.T) { - resourceName := "azurerm_mysql_configuration.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,21 +46,17 @@ func TestAccAzureRMMySQLConfiguration_interactiveTimeout(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLConfiguration_interactiveTimeout(ri, acceptance.Location()), + Config: testAccAzureRMMySQLConfiguration_interactiveTimeout(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLConfigurationValue(resourceName, "30"), + testCheckAzureRMMySQLConfigurationValue(data.ResourceName, "30"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMySQLConfiguration_empty(ri, acceptance.Location()), + Config: testAccAzureRMMySQLConfiguration_empty(data), Check: resource.ComposeTestCheckFunc( // "delete" resets back to the default value - testCheckAzureRMMySQLConfigurationValueReset(ri, "interactive_timeout"), + testCheckAzureRMMySQLConfigurationValueReset(data, "interactive_timeout"), ), }, }, @@ -75,8 +64,7 @@ func TestAccAzureRMMySQLConfiguration_interactiveTimeout(t *testing.T) { } func TestAccAzureRMMySQLConfiguration_logSlowAdminStatements(t *testing.T) { - resourceName := "azurerm_mysql_configuration.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,21 +72,17 @@ func TestAccAzureRMMySQLConfiguration_logSlowAdminStatements(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLConfiguration_logSlowAdminStatements(ri, acceptance.Location()), + Config: testAccAzureRMMySQLConfiguration_logSlowAdminStatements(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLConfigurationValue(resourceName, "on"), + testCheckAzureRMMySQLConfigurationValue(data.ResourceName, "on"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMMySQLConfiguration_empty(ri, acceptance.Location()), + Config: testAccAzureRMMySQLConfiguration_empty(data), Check: resource.ComposeTestCheckFunc( // "delete" resets back to the default value - testCheckAzureRMMySQLConfigurationValueReset(ri, "log_slow_admin_statements"), + testCheckAzureRMMySQLConfigurationValueReset(data, "log_slow_admin_statements"), ), }, }, @@ -140,10 +124,10 @@ func testCheckAzureRMMySQLConfigurationValue(resourceName string, value string) } } -func testCheckAzureRMMySQLConfigurationValueReset(rInt int, configurationName string) resource.TestCheckFunc { +func testCheckAzureRMMySQLConfigurationValueReset(data acceptance.TestData, configurationName string) resource.TestCheckFunc { return func(s *terraform.State) error { - resourceGroup := fmt.Sprintf("acctestRG-%d", rInt) - serverName := fmt.Sprintf("acctestmysqlsvr-%d", rInt) + resourceGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) + serverName := fmt.Sprintf("acctestmysqlsvr-%d", data.RandomInteger) client := acceptance.AzureProvider.Meta().(*clients.Client).MySQL.ConfigurationsClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -194,20 +178,20 @@ func testCheckAzureRMMySQLConfigurationDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMySQLConfiguration_characterSetServer(rInt int, location string) string { - return testAccAzureRMMySQLConfiguration_template(rInt, location, "character_set_server", "hebrew") +func testAccAzureRMMySQLConfiguration_characterSetServer(data acceptance.TestData) string { + return testAccAzureRMMySQLConfiguration_template(data, "character_set_server", "hebrew") } -func testAccAzureRMMySQLConfiguration_interactiveTimeout(rInt int, location string) string { - return testAccAzureRMMySQLConfiguration_template(rInt, location, "interactive_timeout", "30") +func testAccAzureRMMySQLConfiguration_interactiveTimeout(data acceptance.TestData) string { + return testAccAzureRMMySQLConfiguration_template(data, "interactive_timeout", "30") } -func testAccAzureRMMySQLConfiguration_logSlowAdminStatements(rInt int, location string) string { - return testAccAzureRMMySQLConfiguration_template(rInt, location, "log_slow_admin_statements", "on") +func testAccAzureRMMySQLConfiguration_logSlowAdminStatements(data acceptance.TestData) string { + return testAccAzureRMMySQLConfiguration_template(data, "log_slow_admin_statements", "on") } -func testAccAzureRMMySQLConfiguration_template(rInt int, location string, name string, value string) string { - server := testAccAzureRMMySQLConfiguration_empty(rInt, location) +func testAccAzureRMMySQLConfiguration_template(data acceptance.TestData, name string, value string) string { + server := testAccAzureRMMySQLConfiguration_empty(data) config := fmt.Sprintf(` resource "azurerm_mysql_configuration" "test" { name = "%s" @@ -219,7 +203,7 @@ resource "azurerm_mysql_configuration" "test" { return server + config } -func testAccAzureRMMySQLConfiguration_empty(rInt int, location string) string { +func testAccAzureRMMySQLConfiguration_empty(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -249,5 +233,5 @@ resource "azurerm_mysql_server" "test" { version = "5.7" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/mysql/resource_arm_mysql_database_test.go b/azurerm/internal/services/mysql/tests/resource_arm_mysql_database_test.go similarity index 79% rename from azurerm/internal/services/mysql/resource_arm_mysql_database_test.go rename to azurerm/internal/services/mysql/tests/resource_arm_mysql_database_test.go index 5a5cf2ac8236..f5b3fb5ab01e 100644 --- a/azurerm/internal/services/mysql/resource_arm_mysql_database_test.go +++ b/azurerm/internal/services/mysql/tests/resource_arm_mysql_database_test.go @@ -1,4 +1,4 @@ -package mysql +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMMySQLDatabase_basic(t *testing.T) { - resourceName := "azurerm_mysql_database.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,16 +21,12 @@ func TestAccAzureRMMySQLDatabase_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLDatabase_basic(ri, acceptance.Location()), + Config: testAccAzureRMMySQLDatabase_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLDatabaseExists(resourceName), + testCheckAzureRMMySQLDatabaseExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,8 +37,7 @@ func TestAccAzureRMMySQLDatabase_requiresImport(t *testing.T) { return } - resourceName := "azurerm_mysql_database.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,13 +45,13 @@ func TestAccAzureRMMySQLDatabase_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLDatabase_basic(ri, acceptance.Location()), + Config: testAccAzureRMMySQLDatabase_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLDatabaseExists(resourceName), + testCheckAzureRMMySQLDatabaseExists(data.ResourceName), ), }, { - Config: testAccAzureRMMySQLDatabase_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMMySQLDatabase_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_mysql_database"), }, }, @@ -66,9 +59,8 @@ func TestAccAzureRMMySQLDatabase_requiresImport(t *testing.T) { } func TestAccAzureRMMySQLDatabase_charsetUppercase(t *testing.T) { - resourceName := "azurerm_mysql_database.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMySQLDatabase_charsetUppercase(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mysql_database", "test") + config := testAccAzureRMMySQLDatabase_charsetUppercase(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,23 +70,18 @@ func TestAccAzureRMMySQLDatabase_charsetUppercase(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "charset", "utf8"), + testCheckAzureRMMySQLDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "charset", "utf8"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMMySQLDatabase_charsetMixedcase(t *testing.T) { - resourceName := "azurerm_mysql_database.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMySQLDatabase_charsetMixedcase(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mysql_database", "test") + config := testAccAzureRMMySQLDatabase_charsetMixedcase(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,15 +91,11 @@ func TestAccAzureRMMySQLDatabase_charsetMixedcase(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "charset", "utf8"), + testCheckAzureRMMySQLDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "charset", "utf8"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -173,7 +156,7 @@ func testCheckAzureRMMySQLDatabaseDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMySQLDatabase_basic(rInt int, location string) string { +func testAccAzureRMMySQLDatabase_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -211,10 +194,10 @@ resource "azurerm_mysql_database" "test" { charset = "utf8" collation = "utf8_unicode_ci" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMySQLDatabase_requiresImport(rInt int, location string) string { +func testAccAzureRMMySQLDatabase_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -225,10 +208,10 @@ resource "azurerm_mysql_database" "import" { charset = "${azurerm_mysql_database.test.charset}" collation = "${azurerm_mysql_database.test.collation}" } -`, testAccAzureRMMySQLDatabase_basic(rInt, location)) +`, testAccAzureRMMySQLDatabase_basic(data)) } -func testAccAzureRMMySQLDatabase_charsetUppercase(rInt int, location string) string { +func testAccAzureRMMySQLDatabase_charsetUppercase(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -266,10 +249,10 @@ resource "azurerm_mysql_database" "test" { charset = "UTF8" collation = "utf8_unicode_ci" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMySQLDatabase_charsetMixedcase(rInt int, location string) string { +func testAccAzureRMMySQLDatabase_charsetMixedcase(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -307,5 +290,5 @@ resource "azurerm_mysql_database" "test" { charset = "Utf8" collation = "utf8_unicode_ci" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/mysql/resource_arm_mysql_firewall_rule_test.go b/azurerm/internal/services/mysql/tests/resource_arm_mysql_firewall_rule_test.go similarity index 84% rename from azurerm/internal/services/mysql/resource_arm_mysql_firewall_rule_test.go rename to azurerm/internal/services/mysql/tests/resource_arm_mysql_firewall_rule_test.go index ead0c6aef8b2..920bce91247e 100644 --- a/azurerm/internal/services/mysql/resource_arm_mysql_firewall_rule_test.go +++ b/azurerm/internal/services/mysql/tests/resource_arm_mysql_firewall_rule_test.go @@ -1,4 +1,4 @@ -package mysql +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMMySQLFirewallRule_basic(t *testing.T) { - resourceName := "azurerm_mysql_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,16 +21,12 @@ func TestAccAzureRMMySQLFirewallRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMMySQLFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLFirewallRuleExists(resourceName), + testCheckAzureRMMySQLFirewallRuleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,8 +37,7 @@ func TestAccAzureRMMySQLFirewallRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_mysql_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,13 +45,13 @@ func TestAccAzureRMMySQLFirewallRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMMySQLFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLFirewallRuleExists(resourceName), + testCheckAzureRMMySQLFirewallRuleExists(data.ResourceName), ), }, { - Config: testAccAzureRMMySQLFirewallRule_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMMySQLFirewallRule_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_mysql_firewall_rule"), }, }, @@ -122,7 +115,7 @@ func testCheckAzureRMMySQLFirewallRuleDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMySQLFirewallRule_basic(rInt int, location string) string { +func testAccAzureRMMySQLFirewallRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -160,10 +153,10 @@ resource "azurerm_mysql_firewall_rule" "test" { start_ip_address = "0.0.0.0" end_ip_address = "255.255.255.255" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMySQLFirewallRule_requiresImport(rInt int, location string) string { +func testAccAzureRMMySQLFirewallRule_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -174,5 +167,5 @@ resource "azurerm_mysql_firewall_rule" "import" { start_ip_address = "${azurerm_mysql_firewall_rule.test.start_ip_address}" end_ip_address = "${azurerm_mysql_firewall_rule.test.end_ip_address}" } -`, testAccAzureRMMySQLFirewallRule_basic(rInt, location)) +`, testAccAzureRMMySQLFirewallRule_basic(data)) } diff --git a/azurerm/internal/services/mysql/resource_arm_mysql_server_test.go b/azurerm/internal/services/mysql/tests/resource_arm_mysql_server_test.go similarity index 66% rename from azurerm/internal/services/mysql/resource_arm_mysql_server_test.go rename to azurerm/internal/services/mysql/tests/resource_arm_mysql_server_test.go index 5bd17e8dd238..3b57921aa9cf 100644 --- a/azurerm/internal/services/mysql/resource_arm_mysql_server_test.go +++ b/azurerm/internal/services/mysql/tests/resource_arm_mysql_server_test.go @@ -1,4 +1,4 @@ -package mysql +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMMySQLServer_basicFiveSix(t *testing.T) { - resourceName := "azurerm_mysql_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,19 +21,12 @@ func TestAccAzureRMMySQLServer_basicFiveSix(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLServer_basicFiveSix(ri, acceptance.Location()), + Config: testAccAzureRMMySQLServer_basicFiveSix(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), + testCheckAzureRMMySQLServerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), // not returned as sensitive }, }) } @@ -46,8 +37,7 @@ func TestAccAzureRMMySQLServer_requiresImport(t *testing.T) { return } - resourceName := "azurerm_mysql_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,13 +45,13 @@ func TestAccAzureRMMySQLServer_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLServer_basicFiveSevenUpdated(ri, acceptance.Location()), + Config: testAccAzureRMMySQLServer_basicFiveSevenUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), + testCheckAzureRMMySQLServerExists(data.ResourceName), ), }, { - Config: testAccAzureRMMySQLServer_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMMySQLServer_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_mysql_server"), }, }, @@ -74,9 +64,8 @@ func TestAccAzureRMMySQLServer_basicFiveSeven(t *testing.T) { return } - resourceName := "azurerm_mysql_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMySQLServer_basicFiveSeven(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") + config := testAccAzureRMMySQLServer_basicFiveSeven(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,24 +75,16 @@ func TestAccAzureRMMySQLServer_basicFiveSeven(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), + testCheckAzureRMMySQLServerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), // not returned as sensitive }, }) } func TestAccAzureRMMySQLServer_basicEightZero(t *testing.T) { - resourceName := "azurerm_mysql_server.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,27 +92,19 @@ func TestAccAzureRMMySQLServer_basicEightZero(t *testing.T) { CheckDestroy: testCheckAzureRMMySQLServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySQLServer_basicEightZero(ri, acceptance.Location()), + Config: testAccAzureRMMySQLServer_basicEightZero(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), + testCheckAzureRMMySQLServerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), // not returned as sensitive }, }) } func TestAccAzureRMMySqlServer_generalPurpose(t *testing.T) { - resourceName := "azurerm_mysql_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMySQLServer_generalPurpose(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") + config := testAccAzureRMMySQLServer_generalPurpose(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -141,25 +114,17 @@ func TestAccAzureRMMySqlServer_generalPurpose(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), + testCheckAzureRMMySQLServerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), // not returned as sensitive }, }) } func TestAccAzureRMMySqlServer_memoryOptimized(t *testing.T) { - resourceName := "azurerm_mysql_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMySQLServer_memoryOptimizedGeoRedundant(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") + config := testAccAzureRMMySQLServer_memoryOptimizedGeoRedundant(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -169,26 +134,17 @@ func TestAccAzureRMMySqlServer_memoryOptimized(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), + testCheckAzureRMMySQLServerExists(data.ResourceName), ), - }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + }, data.ImportStep("administrator_login_password"), // not returned as sensitive }, }) } func TestAccAzureRMMySQLServer_basicFiveSevenUpdated(t *testing.T) { - resourceName := "azurerm_mysql_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMMySQLServer_basicFiveSeven(ri, location) - updatedConfig := testAccAzureRMMySQLServer_basicFiveSevenUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") + config := testAccAzureRMMySQLServer_basicFiveSeven(data) + updatedConfig := testAccAzureRMMySQLServer_basicFiveSevenUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -198,41 +154,32 @@ func TestAccAzureRMMySQLServer_basicFiveSevenUpdated(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_2"), - resource.TestCheckResourceAttr(resourceName, "version", "5.7"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "51200"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMMySQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_2"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "5.7"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "51200"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_4"), - resource.TestCheckResourceAttr(resourceName, "version", "5.7"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "640000"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMMySQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_4"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "5.7"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "640000"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), // not returned as sensitive }, }) } func TestAccAzureRMMySQLServer_updateSKU(t *testing.T) { - resourceName := "azurerm_mysql_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMMySQLServer_generalPurpose(ri, location) - updatedConfig := testAccAzureRMMySQLServer_memoryOptimized(ri, location) + data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") + config := testAccAzureRMMySQLServer_generalPurpose(data) + updatedConfig := testAccAzureRMMySQLServer_memoryOptimized(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -242,25 +189,25 @@ func TestAccAzureRMMySQLServer_updateSKU(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_32"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "32"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "GeneralPurpose"), - resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen5"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "640000"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMMySQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_32"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "32"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "GeneralPurpose"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "640000"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "MO_Gen5_16"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "16"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "MemoryOptimized"), - resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen5"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "4194304"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMMySQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "MO_Gen5_16"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "16"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "MemoryOptimized"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "4194304"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, }, @@ -268,11 +215,9 @@ func TestAccAzureRMMySQLServer_updateSKU(t *testing.T) { } func TestAccAzureRMMySQLServer_storageAutogrow(t *testing.T) { - resourceName := "azurerm_mysql_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMMySQLServer_basicFiveSeven(ri, location) - updatedConfig := testAccAzureRMMySQLServer_autogrow(ri, location) + data := acceptance.BuildTestData(t, "azurerm_mysql_server", "test") + config := testAccAzureRMMySQLServer_basicFiveSeven(data) + updatedConfig := testAccAzureRMMySQLServer_autogrow(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -282,15 +227,15 @@ func TestAccAzureRMMySQLServer_storageAutogrow(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Enabled"), + testCheckAzureRMMySQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.auto_grow", "Enabled"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Disabled"), + testCheckAzureRMMySQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.auto_grow", "Disabled"), ), }, }, @@ -354,7 +299,7 @@ func testCheckAzureRMMySQLServerDestroy(s *terraform.State) error { return nil } -func testAccAzureRMMySQLServer_basicFiveSix(rInt int, location string) string { +func testAccAzureRMMySQLServer_basicFiveSix(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -384,10 +329,10 @@ resource "azurerm_mysql_server" "test" { version = "5.6" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMySQLServer_basicFiveSeven(rInt int, location string) string { +func testAccAzureRMMySQLServer_basicFiveSeven(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -417,10 +362,10 @@ resource "azurerm_mysql_server" "test" { version = "5.7" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMySQLServer_basicEightZero(rInt int, location string) string { +func testAccAzureRMMySQLServer_basicEightZero(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -450,10 +395,10 @@ resource "azurerm_mysql_server" "test" { version = "8.0" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMySQLServer_requiresImport(rInt int, location string) string { +func testAccAzureRMMySQLServer_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -480,10 +425,10 @@ resource "azurerm_mysql_server" "import" { version = "5.7" ssl_enforcement = "Enabled" } -`, testAccAzureRMMySQLServer_basicFiveSevenUpdated(rInt, location)) +`, testAccAzureRMMySQLServer_basicFiveSevenUpdated(data)) } -func testAccAzureRMMySQLServer_basicFiveSevenUpdated(rInt int, location string) string { +func testAccAzureRMMySQLServer_basicFiveSevenUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -513,10 +458,10 @@ resource "azurerm_mysql_server" "test" { version = "5.7" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMySQLServer_generalPurpose(rInt int, location string) string { +func testAccAzureRMMySQLServer_generalPurpose(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -546,10 +491,10 @@ resource "azurerm_mysql_server" "test" { version = "5.7" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMySQLServer_memoryOptimized(rInt int, location string) string { +func testAccAzureRMMySQLServer_memoryOptimized(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -579,10 +524,10 @@ resource "azurerm_mysql_server" "test" { version = "5.7" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMySQLServer_memoryOptimizedGeoRedundant(rInt int, location string) string { +func testAccAzureRMMySQLServer_memoryOptimizedGeoRedundant(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -612,10 +557,10 @@ resource "azurerm_mysql_server" "test" { version = "5.7" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMMySQLServer_autogrow(rInt int, location string) string { +func testAccAzureRMMySQLServer_autogrow(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -646,5 +591,5 @@ resource "azurerm_mysql_server" "test" { version = "5.7" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule_test.go b/azurerm/internal/services/mysql/tests/resource_arm_mysql_virtual_network_rule_test.go similarity index 85% rename from azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule_test.go rename to azurerm/internal/services/mysql/tests/resource_arm_mysql_virtual_network_rule_test.go index 318428607aff..3a9701b6b4cd 100644 --- a/azurerm/internal/services/mysql/resource_arm_mysql_virtual_network_rule_test.go +++ b/azurerm/internal/services/mysql/tests/resource_arm_mysql_virtual_network_rule_test.go @@ -1,4 +1,4 @@ -package mysql +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +15,7 @@ import ( ) func TestAccAzureRMMySqlVirtualNetworkRule_basic(t *testing.T) { - resourceName := "azurerm_mysql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_virtual_network_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,9 +23,9 @@ func TestAccAzureRMMySqlVirtualNetworkRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMMySqlVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySqlVirtualNetworkRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMMySqlVirtualNetworkRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySqlVirtualNetworkRuleExists(resourceName), + testCheckAzureRMMySqlVirtualNetworkRuleExists(data.ResourceName), ), }, }, @@ -40,8 +38,7 @@ func TestAccAzureRMMySqlVirtualNetworkRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_mysql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_virtual_network_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -49,13 +46,13 @@ func TestAccAzureRMMySqlVirtualNetworkRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMMySqlVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMMySqlVirtualNetworkRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMMySqlVirtualNetworkRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySqlVirtualNetworkRuleExists(resourceName), + testCheckAzureRMMySqlVirtualNetworkRuleExists(data.ResourceName), ), }, { - Config: testAccAzureRMMySqlVirtualNetworkRule_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMMySqlVirtualNetworkRule_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_mysql_virtual_network_rule"), }, }, @@ -63,15 +60,14 @@ func TestAccAzureRMMySqlVirtualNetworkRule_requiresImport(t *testing.T) { } func TestAccAzureRMMySqlVirtualNetworkRule_switchSubnets(t *testing.T) { - resourceName := "azurerm_mysql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_mysql_virtual_network_rule", "test") - preConfig := testAccAzureRMMySqlVirtualNetworkRule_subnetSwitchPre(ri, acceptance.Location()) - postConfig := testAccAzureRMMySqlVirtualNetworkRule_subnetSwitchPost(ri, acceptance.Location()) + preConfig := testAccAzureRMMySqlVirtualNetworkRule_subnetSwitchPre(data) + postConfig := testAccAzureRMMySqlVirtualNetworkRule_subnetSwitchPost(data) // Create regex strings that will ensure that one subnet name exists, but not the other - preConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet1%d)$|(subnet[^2]%d)$", ri, ri)) //subnet 1 but not 2 - postConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet2%d)$|(subnet[^1]%d)$", ri, ri)) //subnet 2 but not 1 + preConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet1%d)$|(subnet[^2]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 1 but not 2 + postConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet2%d)$|(subnet[^1]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 2 but not 1 resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,15 +77,15 @@ func TestAccAzureRMMySqlVirtualNetworkRule_switchSubnets(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySqlVirtualNetworkRuleExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "subnet_id", preConfigRegex), + testCheckAzureRMMySqlVirtualNetworkRuleExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "subnet_id", preConfigRegex), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySqlVirtualNetworkRuleExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "subnet_id", postConfigRegex), + testCheckAzureRMMySqlVirtualNetworkRuleExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "subnet_id", postConfigRegex), ), }, }, @@ -97,9 +93,8 @@ func TestAccAzureRMMySqlVirtualNetworkRule_switchSubnets(t *testing.T) { } func TestAccAzureRMMySqlVirtualNetworkRule_disappears(t *testing.T) { - resourceName := "azurerm_mysql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMySqlVirtualNetworkRule_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_mysql_virtual_network_rule", "test") + config := testAccAzureRMMySqlVirtualNetworkRule_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -109,8 +104,8 @@ func TestAccAzureRMMySqlVirtualNetworkRule_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySqlVirtualNetworkRuleExists(resourceName), - testCheckAzureRMMySqlVirtualNetworkRuleDisappears(resourceName), + testCheckAzureRMMySqlVirtualNetworkRuleExists(data.ResourceName), + testCheckAzureRMMySqlVirtualNetworkRuleDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -119,11 +114,11 @@ func TestAccAzureRMMySqlVirtualNetworkRule_disappears(t *testing.T) { } func TestAccAzureRMMySqlVirtualNetworkRule_multipleSubnets(t *testing.T) { - resourceName1 := "azurerm_mysql_virtual_network_rule.rule1" + data := acceptance.BuildTestData(t, "azurerm_mysql_server", "rule1") + resourceName2 := "azurerm_mysql_virtual_network_rule.rule2" resourceName3 := "azurerm_mysql_virtual_network_rule.rule3" - ri := tf.AccRandTimeInt() - config := testAccAzureRMMySqlVirtualNetworkRule_multipleSubnets(ri, acceptance.Location()) + config := testAccAzureRMMySqlVirtualNetworkRule_multipleSubnets(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -133,7 +128,7 @@ func TestAccAzureRMMySqlVirtualNetworkRule_multipleSubnets(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMMySqlVirtualNetworkRuleExists(resourceName1), + testCheckAzureRMMySqlVirtualNetworkRuleExists(data.ResourceName), testCheckAzureRMMySqlVirtualNetworkRuleExists(resourceName2), testCheckAzureRMMySqlVirtualNetworkRuleExists(resourceName3), ), @@ -236,7 +231,7 @@ func testCheckAzureRMMySqlVirtualNetworkRuleDisappears(resourceName string) reso } } -func testAccAzureRMMySqlVirtualNetworkRule_basic(rInt int, location string) string { +func testAccAzureRMMySqlVirtualNetworkRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -287,10 +282,10 @@ resource "azurerm_mysql_virtual_network_rule" "test" { server_name = "${azurerm_mysql_server.test.name}" subnet_id = "${azurerm_subnet.test.id}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMySqlVirtualNetworkRule_requiresImport(rInt int, location string) string { +func testAccAzureRMMySqlVirtualNetworkRule_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -300,10 +295,10 @@ resource "azurerm_mysql_virtual_network_rule" "import" { server_name = "${azurerm_mysql_virtual_network_rule.test.server_name}" subnet_id = "${azurerm_mysql_virtual_network_rule.test.subnet_id}" } -`, testAccAzureRMMySqlVirtualNetworkRule_basic(rInt, location)) +`, testAccAzureRMMySqlVirtualNetworkRule_basic(data)) } -func testAccAzureRMMySqlVirtualNetworkRule_subnetSwitchPre(rInt int, location string) string { +func testAccAzureRMMySqlVirtualNetworkRule_subnetSwitchPre(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -362,10 +357,10 @@ resource "azurerm_mysql_virtual_network_rule" "test" { server_name = "${azurerm_mysql_server.test.name}" subnet_id = "${azurerm_subnet.test1.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMySqlVirtualNetworkRule_subnetSwitchPost(rInt int, location string) string { +func testAccAzureRMMySqlVirtualNetworkRule_subnetSwitchPost(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -424,10 +419,10 @@ resource "azurerm_mysql_virtual_network_rule" "test" { server_name = "${azurerm_mysql_server.test.name}" subnet_id = "${azurerm_subnet.test2.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMMySqlVirtualNetworkRule_multipleSubnets(rInt int, location string) string { +func testAccAzureRMMySqlVirtualNetworkRule_multipleSubnets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -515,5 +510,5 @@ resource "azurerm_mysql_virtual_network_rule" "rule3" { server_name = "${azurerm_mysql_server.test.name}" subnet_id = "${azurerm_subnet.vnet2_subnet1.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } From aa418a74295a00057ce5689b43c1d4e8488c78f1 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 08:17:16 +0100 Subject: [PATCH 112/203] fixing the tests --- .../tests/data_source_api_management_user_test.go | 2 +- .../tests/resource_arm_api_management_diagnostic_test.go | 2 +- .../services/sql/tests/data_source_sql_database_test.go | 1 - .../services/sql/tests/data_source_sql_server_test.go | 1 - .../sql/tests/resource_arm_sql_administrator_test.go | 2 +- .../resource_arm_storage_account_migration_test.go | 5 ++--- .../resource_arm_storage_blob_migration_test.go | 5 ++--- .../resource_arm_storage_container_migration_test.go | 5 ++--- .../resource_arm_storage_queue_migration_test.go | 5 ++--- .../resource_arm_storage_share_migration_test.go | 7 +++---- .../resource_arm_storage_table_migration_test.go | 2 +- 11 files changed, 15 insertions(+), 22 deletions(-) rename azurerm/internal/services/storage/{tests => }/resource_arm_storage_account_migration_test.go (88%) rename azurerm/internal/services/storage/{tests => }/resource_arm_storage_blob_migration_test.go (91%) rename azurerm/internal/services/storage/{tests => }/resource_arm_storage_container_migration_test.go (91%) rename azurerm/internal/services/storage/{tests => }/resource_arm_storage_queue_migration_test.go (91%) rename azurerm/internal/services/storage/{tests => }/resource_arm_storage_share_migration_test.go (90%) rename azurerm/internal/services/storage/{tests => }/resource_arm_storage_table_migration_test.go (99%) diff --git a/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go b/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go index 9299be52682e..d418a69cc6f5 100644 --- a/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go +++ b/azurerm/internal/services/apimanagement/tests/data_source_api_management_user_test.go @@ -21,7 +21,7 @@ func TestAccDataSourceAzureRMApiManagementUser_basic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "user_id", "test-user"), resource.TestCheckResourceAttr(data.ResourceName, "first_name", "Acceptance"), resource.TestCheckResourceAttr(data.ResourceName, "last_name", "Test"), - resource.TestCheckResourceAttr(data.ResourceName, "email", fmt.Sprintf("azure-acctest%d@example.com", rInt)), + resource.TestCheckResourceAttr(data.ResourceName, "email", fmt.Sprintf("azure-acctest%d@example.com", data.RandomInteger)), resource.TestCheckResourceAttr(data.ResourceName, "state", "active"), resource.TestCheckResourceAttr(data.ResourceName, "note", "Used for testing in dimension C-137."), ), diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go index 531161faeb34..f219e1f6204b 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go @@ -131,7 +131,7 @@ resource "azurerm_api_management_diagnostic" "test" { api_management_name = "${azurerm_api_management.test.name}" enabled = true } -`, data.ResourceName, data.Locations.Primary, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMApiManagementDiagnostic_requiresImport(data acceptance.TestData) string { diff --git a/azurerm/internal/services/sql/tests/data_source_sql_database_test.go b/azurerm/internal/services/sql/tests/data_source_sql_database_test.go index e7f72236cf67..ae35070e16d6 100644 --- a/azurerm/internal/services/sql/tests/data_source_sql_database_test.go +++ b/azurerm/internal/services/sql/tests/data_source_sql_database_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) diff --git a/azurerm/internal/services/sql/tests/data_source_sql_server_test.go b/azurerm/internal/services/sql/tests/data_source_sql_server_test.go index 901f353e875f..d472b9203511 100644 --- a/azurerm/internal/services/sql/tests/data_source_sql_server_test.go +++ b/azurerm/internal/services/sql/tests/data_source_sql_server_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) diff --git a/azurerm/internal/services/sql/tests/resource_arm_sql_administrator_test.go b/azurerm/internal/services/sql/tests/resource_arm_sql_administrator_test.go index 59f87b82efdb..9653d7ed9aaa 100644 --- a/azurerm/internal/services/sql/tests/resource_arm_sql_administrator_test.go +++ b/azurerm/internal/services/sql/tests/resource_arm_sql_administrator_test.go @@ -177,7 +177,7 @@ resource "azurerm_sql_active_directory_administrator" "test" { tenant_id = "${data.azurerm_client_config.current.tenant_id}" object_id = "${data.azurerm_client_config.current.client_id}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMSqlAdministrator_requiresImport(data acceptance.TestData) string { diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go similarity index 88% rename from azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go index 0ae82e44d707..78370892d34a 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go @@ -1,7 +1,6 @@ -package tests +package storage import ( - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -52,7 +51,7 @@ func TestAzureRMStorageAccountMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := storage.ResourceStorageAccountMigrateState(tc.StateVersion, is, tc.Meta) + is, err := ResourceStorageAccountMigrateState(tc.StateVersion, is, tc.Meta) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go similarity index 91% rename from azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go index ee7a7cd8c6d7..18bf52c93b28 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go @@ -1,9 +1,8 @@ -package tests +package storage import ( "context" "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -63,7 +62,7 @@ func TestAccAzureRMStorageBlobMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := storage.ResourceStorageBlobMigrateState(tc.StateVersion, is, client) + is, err := ResourceStorageBlobMigrateState(tc.StateVersion, is, client) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go similarity index 91% rename from azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go index 322d890dc520..46d074082087 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go @@ -1,9 +1,8 @@ -package tests +package storage import ( "context" "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -62,7 +61,7 @@ func TestAccAzureRMStorageContainerMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := storage.ResourceStorageContainerMigrateState(tc.StateVersion, is, client) + is, err := ResourceStorageContainerMigrateState(tc.StateVersion, is, client) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go similarity index 91% rename from azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go index 20f9eff3afe0..76bae71a7c59 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go @@ -1,9 +1,8 @@ -package tests +package storage import ( "context" "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" @@ -62,7 +61,7 @@ func TestAccAzureRMStorageQueueMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := storage.ResourceStorageQueueMigrateState(tc.StateVersion, is, client) + is, err := ResourceStorageQueueMigrateState(tc.StateVersion, is, client) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go similarity index 90% rename from azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go index 469a10c28ede..c16ae17734f4 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go @@ -1,8 +1,7 @@ -package tests +package storage import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "reflect" "testing" @@ -41,7 +40,7 @@ func TestAzureRMStorageShareMigrateStateV0ToV1(t *testing.T) { "quota": 5120, } - actual, err := storage.ResourceStorageShareStateUpgradeV0ToV1(input, meta) + actual, err := ResourceStorageShareStateUpgradeV0ToV1(input, meta) if err != nil { t.Fatalf("Expected no error but got: %s", err) } @@ -85,7 +84,7 @@ func TestAzureRMStorageShareMigrateStateV1ToV2(t *testing.T) { "quota": 5120, } - actual, err := storage.ResourceStorageShareStateUpgradeV1ToV2(input, meta) + actual, err := ResourceStorageShareStateUpgradeV1ToV2(input, meta) if err != nil { t.Fatalf("Expected no error but got: %s", err) } diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go b/azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go similarity index 99% rename from azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go rename to azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go index 0075ac1604e2..f24b171aa7f9 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go @@ -1,4 +1,4 @@ -package tests +package storage import ( "fmt" From fe5dfffb3e5b8ef1be4dd8e5e752cd44f61740e3 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 08:21:40 +0100 Subject: [PATCH 113/203] removing a circular reference in the provider tests --- .../required_resource_providers_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) rename azurerm/internal/{provider => acceptance}/required_resource_providers_test.go (82%) diff --git a/azurerm/internal/provider/required_resource_providers_test.go b/azurerm/internal/acceptance/required_resource_providers_test.go similarity index 82% rename from azurerm/internal/provider/required_resource_providers_test.go rename to azurerm/internal/acceptance/required_resource_providers_test.go index a53b03d48075..7ac04991d3d7 100644 --- a/azurerm/internal/provider/required_resource_providers_test.go +++ b/azurerm/internal/acceptance/required_resource_providers_test.go @@ -1,4 +1,4 @@ -package provider +package acceptance import ( "context" @@ -6,12 +6,15 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/hashicorp/go-azure-helpers/resourceproviders" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/provider" ) +// since this depends on GetAuthConfig which lives in this package +// unfortunately this has to live in a different package to the other func + func TestAccAzureRMEnsureRequiredResourceProvidersAreRegistered(t *testing.T) { - config := acceptance.GetAuthConfig(t) + config := GetAuthConfig(t) if config == nil { return } @@ -31,7 +34,7 @@ func TestAccAzureRMEnsureRequiredResourceProvidersAreRegistered(t *testing.T) { } client := armClient.Resource.ProvidersClient - ctx := acceptance.AzureProvider.StopContext() + ctx := AzureProvider.StopContext() providerList, err := client.List(ctx, nil, "") if err != nil { t.Fatalf("Unable to list provider registration status, it is possible that this is due to invalid "+ @@ -40,8 +43,8 @@ func TestAccAzureRMEnsureRequiredResourceProvidersAreRegistered(t *testing.T) { } availableResourceProviders := providerList.Values() - requiredResourceProviders := RequiredResourceProviders() - err = EnsureResourceProvidersAreRegistered(ctx, *client, availableResourceProviders, requiredResourceProviders) + requiredResourceProviders := provider.RequiredResourceProviders() + err = provider.EnsureResourceProvidersAreRegistered(ctx, *client, availableResourceProviders, requiredResourceProviders) if err != nil { t.Fatalf("Error registering Resource Providers: %+v", err) } From 7d27e233b6d9a8cf81a45b2b6918eaccf20982cb Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 08:51:24 +0100 Subject: [PATCH 114/203] securitycenter: switching over to the new test structure --- ...rce_arm_advanced_threat_protection_test.go | 161 +++++++----------- ...source_arm_security_center_contact_test.go | 91 +++++----- ...curity_center_subscription_pricing_test.go | 24 +-- .../resource_arm_security_center_test.go | 2 +- ...urce_arm_security_center_workspace_test.go | 106 +++++------- 5 files changed, 157 insertions(+), 227 deletions(-) rename azurerm/internal/services/securitycenter/{ => tests}/resource_arm_advanced_threat_protection_test.go (61%) rename azurerm/internal/services/securitycenter/{ => tests}/resource_arm_security_center_contact_test.go (67%) rename azurerm/internal/services/securitycenter/{ => tests}/resource_arm_security_center_subscription_pricing_test.go (76%) rename azurerm/internal/services/securitycenter/{ => tests}/resource_arm_security_center_test.go (97%) rename azurerm/internal/services/securitycenter/{ => tests}/resource_arm_security_center_workspace_test.go (62%) diff --git a/azurerm/internal/services/securitycenter/resource_arm_advanced_threat_protection_test.go b/azurerm/internal/services/securitycenter/tests/resource_arm_advanced_threat_protection_test.go similarity index 61% rename from azurerm/internal/services/securitycenter/resource_arm_advanced_threat_protection_test.go rename to azurerm/internal/services/securitycenter/tests/resource_arm_advanced_threat_protection_test.go index c9ded2bd5f1d..312ff630f3c5 100644 --- a/azurerm/internal/services/securitycenter/resource_arm_advanced_threat_protection_test.go +++ b/azurerm/internal/services/securitycenter/tests/resource_arm_advanced_threat_protection_test.go @@ -1,23 +1,19 @@ -package securitycenter +package tests import ( "fmt" "net/http" "testing" - "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMAdvancedThreatProtection_storageAccount(t *testing.T) { - rn := "azurerm_advanced_threat_protection.test" - ri := tf.AccRandTimeInt() - var id AdvancedThreatProtectionResourceID + data := acceptance.BuildTestData(t, "azurerm_advanced_threat_protection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,33 +21,25 @@ func TestAccAzureRMAdvancedThreatProtection_storageAccount(t *testing.T) { CheckDestroy: testCheckAzureRMAdvancedThreatProtectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAdvancedThreatProtection_storageAccount(ri, acceptance.Location(), true, true), + Config: testAccAzureRMAdvancedThreatProtection_storageAccount(data, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAdvancedThreatProtectionExists(rn, &id), - resource.TestCheckResourceAttr(rn, "enabled", "true"), + testCheckAzureRMAdvancedThreatProtectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), ), }, + data.ImportStep(), { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAdvancedThreatProtection_storageAccount(ri, acceptance.Location(), true, false), + Config: testAccAzureRMAdvancedThreatProtection_storageAccount(data, true, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAdvancedThreatProtectionExists(rn, &id), - resource.TestCheckResourceAttr(rn, "enabled", "false"), + testCheckAzureRMAdvancedThreatProtectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), ), }, + data.ImportStep(), { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAdvancedThreatProtection_storageAccount(ri, acceptance.Location(), false, false), + Config: testAccAzureRMAdvancedThreatProtection_storageAccount(data, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAdvancedThreatProtectionIsFalse(&id), + testCheckAzureRMAdvancedThreatProtectionIsFalse(data.ResourceName), ), }, }, @@ -59,9 +47,7 @@ func TestAccAzureRMAdvancedThreatProtection_storageAccount(t *testing.T) { } func TestAccAzureRMAdvancedThreatProtection_cosmosAccount(t *testing.T) { - rn := "azurerm_advanced_threat_protection.test" - ri := tf.AccRandTimeInt() - var id AdvancedThreatProtectionResourceID + data := acceptance.BuildTestData(t, "azurerm_advanced_threat_protection", "test") // the API errors on deleting the cosmos DB account some of the time so lets skip this test for now // TODO: remove once this is fixed: https://github.com/Azure/azure-sdk-for-go/issues/6310 @@ -74,33 +60,25 @@ func TestAccAzureRMAdvancedThreatProtection_cosmosAccount(t *testing.T) { CheckDestroy: testCheckAzureRMAdvancedThreatProtectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAdvancedThreatProtection_cosmosAccount(ri, acceptance.Location(), true, true), + Config: testAccAzureRMAdvancedThreatProtection_cosmosAccount(data, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAdvancedThreatProtectionExists(rn, &id), - resource.TestCheckResourceAttr(rn, "enabled", "true"), + testCheckAzureRMAdvancedThreatProtectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), ), }, + data.ImportStep(), { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAdvancedThreatProtection_cosmosAccount(ri, acceptance.Location(), true, false), + Config: testAccAzureRMAdvancedThreatProtection_cosmosAccount(data, true, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAdvancedThreatProtectionExists(rn, &id), - resource.TestCheckResourceAttr(rn, "enabled", "false"), + testCheckAzureRMAdvancedThreatProtectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), ), }, + data.ImportStep(), { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAdvancedThreatProtection_cosmosAccount(ri, acceptance.Location(), false, false), + Config: testAccAzureRMAdvancedThreatProtection_cosmosAccount(data, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAdvancedThreatProtectionIsFalse(&id), + testCheckAzureRMAdvancedThreatProtectionIsFalse(data.ResourceName), ), }, }, @@ -113,9 +91,7 @@ func TestAccAzureRMAdvancedThreatProtection_requiresImport(t *testing.T) { return } - rn := "azurerm_advanced_threat_protection.test" - ri := tf.AccRandTimeInt() - var id AdvancedThreatProtectionResourceID + data := acceptance.BuildTestData(t, "azurerm_advanced_threat_protection", "import") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -123,26 +99,19 @@ func TestAccAzureRMAdvancedThreatProtection_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAdvancedThreatProtectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAdvancedThreatProtection_storageAccount(ri, acceptance.Location(), true, true), + Config: testAccAzureRMAdvancedThreatProtection_storageAccount(data, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAdvancedThreatProtectionExists(rn, &id), - resource.TestCheckResourceAttr(rn, "enabled", "true"), + testCheckAzureRMAdvancedThreatProtectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), ), }, - { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAdvancedThreatProtection_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_advanced_threat_protection"), - }, + data.ImportStep(), + data.RequiresImportErrorStep(testAccAzureRMAdvancedThreatProtection_requiresImport), }, }) } -func testCheckAzureRMAdvancedThreatProtectionExists(resourceName string, idToReturn *AdvancedThreatProtectionResourceID) resource.TestCheckFunc { +func testCheckAzureRMAdvancedThreatProtectionExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { // Ensure resource group exists in API client := acceptance.AzureProvider.Meta().(*clients.Client).SecurityCenter.AdvancedThreatProtectionClient @@ -154,40 +123,43 @@ func testCheckAzureRMAdvancedThreatProtectionExists(resourceName string, idToRet return fmt.Errorf("Not found: %s", resourceName) } - id, err := ParseAdvancedThreatProtectionID(rs.Primary.ID) - if err != nil { - return err - } + targetResourceId := rs.Primary.Attributes["target_resource_id"] - resp, err := client.Get(ctx, id.TargetResourceID) + resp, err := client.Get(ctx, targetResourceId) if err != nil { return fmt.Errorf("Bad: Get on AdvancedThreatProtectionClient: %+v", err) } if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Advanced Threat Protection for resource %q not found", id.TargetResourceID) + return fmt.Errorf("Advanced Threat Protection for resource %q not found", targetResourceId) } - *idToReturn = *id - return nil } } -func testCheckAzureRMAdvancedThreatProtectionIsFalse(id *AdvancedThreatProtectionResourceID) resource.TestCheckFunc { +func testCheckAzureRMAdvancedThreatProtectionIsFalse(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).SecurityCenter.AdvancedThreatProtectionClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - resp, err := client.Get(ctx, id.TargetResourceID) + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + targetResourceId := rs.Primary.Attributes["target_resource_id"] + + resp, err := client.Get(ctx, targetResourceId) if err != nil { - return fmt.Errorf("Failed reading Advanced Threat Protection for resource %q: %+v", id.TargetResourceID, err) + return fmt.Errorf("Failed reading Advanced Threat Protection for resource %q: %+v", targetResourceId, err) } if props := resp.AdvancedThreatProtectionProperties; props != nil { if props.IsEnabled != nil { if *props.IsEnabled { - return fmt.Errorf("Advanced Threat Protection is still true for resource %q: %+v", id.TargetResourceID, err) + return fmt.Errorf("Advanced Threat Protection is still true for resource %q: %+v", targetResourceId, err) } } } @@ -205,12 +177,8 @@ func testCheckAzureRMAdvancedThreatProtectionDestroy(s *terraform.State) error { continue } - id, err := ParseAdvancedThreatProtectionID(rs.Primary.ID) - if err != nil { - return err - } - - resp, err := client.Get(ctx, id.TargetResourceID) + targetResourceId := rs.Primary.Attributes["target_resource_id"] + resp, err := client.Get(ctx, targetResourceId) if err != nil { return nil } @@ -223,18 +191,19 @@ func testCheckAzureRMAdvancedThreatProtectionDestroy(s *terraform.State) error { return nil } -func testAccAzureRMAdvancedThreatProtection_requiresImport(rInt int, location string) string { +func testAccAzureRMAdvancedThreatProtection_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAdvancedThreatProtection_storageAccount(data, true, true) return fmt.Sprintf(` -%[1]s +%s -resource "azurerm_advanced_threat_protection" "requireimport" { +resource "azurerm_advanced_threat_protection" "import" { target_resource_id = "${azurerm_advanced_threat_protection.test.target_resource_id}" enabled = "${azurerm_advanced_threat_protection.test.enabled}" } -`, testAccAzureRMAdvancedThreatProtection_storageAccount(rInt, location, true, true)) +`, template) } -func testAccAzureRMAdvancedThreatProtection_storageAccount(rInt int, location string, hasResource, enabled bool) string { +func testAccAzureRMAdvancedThreatProtection_storageAccount(data acceptance.TestData, hasResource, enabled bool) string { atp := "" if hasResource { atp = fmt.Sprintf(` @@ -247,12 +216,12 @@ resource "azurerm_advanced_threat_protection" "test" { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-ATP-%[1]d" - location = "%[2]s" + name = "acctestRG-ATP-%d" + location = "%s" } resource "azurerm_storage_account" "test" { - name = "acctest%[3]d" + name = "acctest%s" resource_group_name = "${azurerm_resource_group.test.name}" location = "${azurerm_resource_group.test.location}" @@ -264,11 +233,11 @@ resource "azurerm_storage_account" "test" { } } -%[4]s -`, rInt, location, rInt/10, atp) +%s +`, data.RandomInteger, data.Locations.Primary, data.RandomString, atp) } -func testAccAzureRMAdvancedThreatProtection_cosmosAccount(rInt int, location string, hasResource, enabled bool) string { +func testAccAzureRMAdvancedThreatProtection_cosmosAccount(data acceptance.TestData, hasResource, enabled bool) string { atp := "" if hasResource { atp = fmt.Sprintf(` @@ -281,18 +250,18 @@ resource "azurerm_advanced_threat_protection" "test" { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-ATP-%[1]d" - location = "%[2]s" + name = "acctestRG-ATP-%d" + location = "%s" } resource "azurerm_cosmosdb_account" "test" { - name = "acctest-%[1]d" + name = "acctest-%s" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" offer_type = "Standard" consistency_policy { - consistency_level = "%[3]s" + consistency_level = "Eventual" } geo_location { @@ -301,6 +270,6 @@ resource "azurerm_cosmosdb_account" "test" { } } -%[4]s -`, rInt, location, string(documentdb.Eventual), atp) +%s +`, data.RandomInteger, data.Locations.Primary, data.RandomString, atp) } diff --git a/azurerm/internal/services/securitycenter/resource_arm_security_center_contact_test.go b/azurerm/internal/services/securitycenter/tests/resource_arm_security_center_contact_test.go similarity index 67% rename from azurerm/internal/services/securitycenter/resource_arm_security_center_contact_test.go rename to azurerm/internal/services/securitycenter/tests/resource_arm_security_center_contact_test.go index aacede40f7dd..311dfc2620f8 100644 --- a/azurerm/internal/services/securitycenter/resource_arm_security_center_contact_test.go +++ b/azurerm/internal/services/securitycenter/tests/resource_arm_security_center_contact_test.go @@ -1,4 +1,4 @@ -package securitycenter +package tests import ( "fmt" @@ -37,7 +37,7 @@ func TestAccAzureRMSecurityCenter_contact(t *testing.T) { } func testAccAzureRMSecurityCenterContact_basic(t *testing.T) { - resourceName := "azurerm_security_center_contact.test" + data := acceptance.BuildTestData(t, "azurerm_security_center_contact", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -47,18 +47,14 @@ func testAccAzureRMSecurityCenterContact_basic(t *testing.T) { { Config: testAccAzureRMSecurityCenterContact_template("basic@example.com", "+1-555-555-5555", true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterContactExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "email", "basic@example.com"), - resource.TestCheckResourceAttr(resourceName, "phone", "+1-555-555-5555"), - resource.TestCheckResourceAttr(resourceName, "alert_notifications", "true"), - resource.TestCheckResourceAttr(resourceName, "alerts_to_admins", "true"), + testCheckAzureRMSecurityCenterContactExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "email", "basic@example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "phone", "+1-555-555-5555"), + resource.TestCheckResourceAttr(data.ResourceName, "alert_notifications", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "alerts_to_admins", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -69,8 +65,7 @@ func testAccAzureRMSecurityCenterContact_requiresImport(t *testing.T) { return } - resourceName := "azurerm_security_center_contact.test" - + data := acceptance.BuildTestData(t, "azurerm_security_center_contact", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -79,23 +74,22 @@ func testAccAzureRMSecurityCenterContact_requiresImport(t *testing.T) { { Config: testAccAzureRMSecurityCenterContact_template("require@example.com", "+1-555-555-5555", true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterContactExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "email", "require@example.com"), - resource.TestCheckResourceAttr(resourceName, "phone", "+1-555-555-5555"), - resource.TestCheckResourceAttr(resourceName, "alert_notifications", "true"), - resource.TestCheckResourceAttr(resourceName, "alerts_to_admins", "true"), + testCheckAzureRMSecurityCenterContactExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "email", "require@example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "phone", "+1-555-555-5555"), + resource.TestCheckResourceAttr(data.ResourceName, "alert_notifications", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "alerts_to_admins", "true"), ), }, - { - Config: testAccAzureRMSecurityCenterContact_requiresImportCfg("email1@example.com", "+1-555-555-5555", true, true), - ExpectError: acceptance.RequiresImportError("azurerm_security_center_contact"), - }, + data.RequiresImportErrorStep(func(data acceptance.TestData) string { + return testAccAzureRMSecurityCenterContact_requiresImportCfg("email1@example.com", "+1-555-555-5555", true, true) + }), }, }) } func testAccAzureRMSecurityCenterContact_update(t *testing.T) { - resourceName := "azurerm_security_center_contact.test" + data := acceptance.BuildTestData(t, "azurerm_security_center_contact", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -105,34 +99,30 @@ func testAccAzureRMSecurityCenterContact_update(t *testing.T) { { Config: testAccAzureRMSecurityCenterContact_template("update@example.com", "+1-555-555-5555", true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterContactExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "email", "update@example.com"), - resource.TestCheckResourceAttr(resourceName, "phone", "+1-555-555-5555"), - resource.TestCheckResourceAttr(resourceName, "alert_notifications", "true"), - resource.TestCheckResourceAttr(resourceName, "alerts_to_admins", "true"), + testCheckAzureRMSecurityCenterContactExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "email", "update@example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "phone", "+1-555-555-5555"), + resource.TestCheckResourceAttr(data.ResourceName, "alert_notifications", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "alerts_to_admins", "true"), ), }, { Config: testAccAzureRMSecurityCenterContact_template("updated@example.com", "+1-555-678-6789", false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterContactExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "email", "updated@example.com"), - resource.TestCheckResourceAttr(resourceName, "phone", "+1-555-678-6789"), - resource.TestCheckResourceAttr(resourceName, "alert_notifications", "false"), - resource.TestCheckResourceAttr(resourceName, "alerts_to_admins", "false"), + testCheckAzureRMSecurityCenterContactExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "email", "updated@example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "phone", "+1-555-678-6789"), + resource.TestCheckResourceAttr(data.ResourceName, "alert_notifications", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "alerts_to_admins", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMSecurityCenterContact_phoneOptional(t *testing.T) { - resourceName := "azurerm_security_center_contact.test" + data := acceptance.BuildTestData(t, "azurerm_security_center_contact", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -142,18 +132,14 @@ func testAccAzureRMSecurityCenterContact_phoneOptional(t *testing.T) { { Config: testAccAzureRMSecurityCenterContact_templateWithoutPhone("basic@example.com", true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterContactExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "email", "basic@example.com"), - resource.TestCheckResourceAttr(resourceName, "phone", ""), - resource.TestCheckResourceAttr(resourceName, "alert_notifications", "true"), - resource.TestCheckResourceAttr(resourceName, "alerts_to_admins", "true"), + testCheckAzureRMSecurityCenterContactExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "email", "basic@example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "phone", ""), + resource.TestCheckResourceAttr(data.ResourceName, "alert_notifications", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "alerts_to_admins", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -190,7 +176,7 @@ func testCheckAzureRMSecurityCenterContactDestroy(s *terraform.State) error { if res.Type != "azurerm_security_center_contact" { continue } - resp, err := client.Get(ctx, securityCenterContactName) + resp, err := client.Get(ctx, "default1") if err != nil { if utils.ResponseWasNotFound(resp.Response) { return nil @@ -226,6 +212,7 @@ resource "azurerm_security_center_contact" "test" { } func testAccAzureRMSecurityCenterContact_requiresImportCfg(email, phone string, notifications, adminAlerts bool) string { + template := testAccAzureRMSecurityCenterContact_template(email, phone, notifications, adminAlerts) return fmt.Sprintf(` %s @@ -236,5 +223,5 @@ resource "azurerm_security_center_contact" "import" { alert_notifications = "${azurerm_security_center_contact.test.alert_notifications}" alerts_to_admins = "${azurerm_security_center_contact.test.alerts_to_admins}" } -`, testAccAzureRMSecurityCenterContact_template(email, phone, notifications, adminAlerts)) +`, template) } diff --git a/azurerm/internal/services/securitycenter/resource_arm_security_center_subscription_pricing_test.go b/azurerm/internal/services/securitycenter/tests/resource_arm_security_center_subscription_pricing_test.go similarity index 76% rename from azurerm/internal/services/securitycenter/resource_arm_security_center_subscription_pricing_test.go rename to azurerm/internal/services/securitycenter/tests/resource_arm_security_center_subscription_pricing_test.go index 44b9045fb52c..9e4347f230e4 100644 --- a/azurerm/internal/services/securitycenter/resource_arm_security_center_subscription_pricing_test.go +++ b/azurerm/internal/services/securitycenter/tests/resource_arm_security_center_subscription_pricing_test.go @@ -1,4 +1,4 @@ -package securitycenter +package tests import ( "fmt" @@ -12,7 +12,7 @@ import ( ) func testAccAzureRMSecurityCenterSubscriptionPricing_update(t *testing.T) { - resourceName := "azurerm_security_center_subscription_pricing.test" + data := acceptance.BuildTestData(t, "azurerm_security_center_subscription_pricing", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,27 +21,19 @@ func testAccAzureRMSecurityCenterSubscriptionPricing_update(t *testing.T) { { Config: testAccAzureRMSecurityCenterSubscriptionPricing_tier("Standard"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterSubscriptionPricingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tier", "Standard"), + testCheckAzureRMSecurityCenterSubscriptionPricingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "Standard"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: testAccAzureRMSecurityCenterSubscriptionPricing_tier("Free"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterSubscriptionPricingExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tier", "Free"), + testCheckAzureRMSecurityCenterSubscriptionPricingExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "Free"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/securitycenter/resource_arm_security_center_test.go b/azurerm/internal/services/securitycenter/tests/resource_arm_security_center_test.go similarity index 97% rename from azurerm/internal/services/securitycenter/resource_arm_security_center_test.go rename to azurerm/internal/services/securitycenter/tests/resource_arm_security_center_test.go index c02dbdf7b708..3e3db3d90d9d 100644 --- a/azurerm/internal/services/securitycenter/resource_arm_security_center_test.go +++ b/azurerm/internal/services/securitycenter/tests/resource_arm_security_center_test.go @@ -1,4 +1,4 @@ -package securitycenter +package tests import ( "testing" diff --git a/azurerm/internal/services/securitycenter/resource_arm_security_center_workspace_test.go b/azurerm/internal/services/securitycenter/tests/resource_arm_security_center_workspace_test.go similarity index 62% rename from azurerm/internal/services/securitycenter/resource_arm_security_center_workspace_test.go rename to azurerm/internal/services/securitycenter/tests/resource_arm_security_center_workspace_test.go index 2cf4aa7bb720..122ec74070bf 100644 --- a/azurerm/internal/services/securitycenter/resource_arm_security_center_workspace_test.go +++ b/azurerm/internal/services/securitycenter/tests/resource_arm_security_center_workspace_test.go @@ -1,4 +1,4 @@ -package securitycenter +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +14,7 @@ import ( ) func testAccAzureRMSecurityCenterWorkspace_basic(t *testing.T) { - resourceName := "azurerm_security_center_workspace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_security_center_workspace", "test") scope := fmt.Sprintf("/subscriptions/%s", os.Getenv("ARM_SUBSCRIPTION_ID")) @@ -26,17 +24,13 @@ func testAccAzureRMSecurityCenterWorkspace_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSecurityCenterWorkspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSecurityCenterWorkspace_basicCfg(ri, acceptance.Location(), scope), + Config: testAccAzureRMSecurityCenterWorkspace_basicCfg(data, scope), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterWorkspaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "scope", scope), + testCheckAzureRMSecurityCenterWorkspaceExists(), + resource.TestCheckResourceAttr(data.ResourceName, "scope", scope), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { //reset pricing to free Config: testAccAzureRMSecurityCenterSubscriptionPricing_tier("Free"), @@ -51,9 +45,7 @@ func testAccAzureRMSecurityCenterWorkspace_requiresImport(t *testing.T) { return } - resourceName := "azurerm_security_center_workspace.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_security_center_workspace", "test") scope := fmt.Sprintf("/subscriptions/%s", os.Getenv("ARM_SUBSCRIPTION_ID")) resource.Test(t, resource.TestCase{ @@ -62,14 +54,14 @@ func testAccAzureRMSecurityCenterWorkspace_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSecurityCenterWorkspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSecurityCenterWorkspace_basicCfg(ri, acceptance.Location(), scope), + Config: testAccAzureRMSecurityCenterWorkspace_basicCfg(data, scope), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterWorkspaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "scope", scope), + testCheckAzureRMSecurityCenterWorkspaceExists(), + resource.TestCheckResourceAttr(data.ResourceName, "scope", scope), ), }, { - Config: testAccAzureRMSecurityCenterWorkspace_requiresImportCfg(ri, acceptance.Location(), scope), + Config: testAccAzureRMSecurityCenterWorkspace_requiresImportCfg(data, scope), ExpectError: acceptance.RequiresImportError("azurerm_security_center_workspace"), }, { @@ -81,9 +73,7 @@ func testAccAzureRMSecurityCenterWorkspace_requiresImport(t *testing.T) { } func testAccAzureRMSecurityCenterWorkspace_update(t *testing.T) { - resourceName := "azurerm_security_center_workspace.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_security_center_workspace", "test") scope := fmt.Sprintf("/subscriptions/%s", os.Getenv("ARM_SUBSCRIPTION_ID")) resource.Test(t, resource.TestCase{ @@ -91,24 +81,20 @@ func testAccAzureRMSecurityCenterWorkspace_update(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccAzureRMSecurityCenterWorkspace_basicCfg(ri, acceptance.Location(), scope), + Config: testAccAzureRMSecurityCenterWorkspace_basicCfg(data, scope), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterWorkspaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "scope", scope), + testCheckAzureRMSecurityCenterWorkspaceExists(), + resource.TestCheckResourceAttr(data.ResourceName, "scope", scope), ), }, { - Config: testAccAzureRMSecurityCenterWorkspace_differentWorkspaceCfg(ri, acceptance.Location(), scope), + Config: testAccAzureRMSecurityCenterWorkspace_differentWorkspaceCfg(data, scope), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSecurityCenterWorkspaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "scope", scope), + testCheckAzureRMSecurityCenterWorkspaceExists(), + resource.TestCheckResourceAttr(data.ResourceName, "scope", scope), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { //reset pricing to free Config: testAccAzureRMSecurityCenterSubscriptionPricing_tier("Free"), @@ -117,25 +103,19 @@ func testAccAzureRMSecurityCenterWorkspace_update(t *testing.T) { }) } -func testCheckAzureRMSecurityCenterWorkspaceExists(resourceName string) resource.TestCheckFunc { +func testCheckAzureRMSecurityCenterWorkspaceExists() resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).SecurityCenter.WorkspaceClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - contactName := rs.Primary.Attributes["workspaceSettings"] - - resp, err := client.Get(ctx, contactName) + workspaceSettingName := "default" + resp, err := client.Get(ctx, workspaceSettingName) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Security Center Subscription Workspace %q was not found: %+v", contactName, err) + return fmt.Errorf("Security Center Subscription Workspace %q was not found: %+v", workspaceSettingName, err) } - return fmt.Errorf("Bad: GetWorkspace: %+v", err) + return fmt.Errorf("Bad: Get: %+v", err) } return nil @@ -146,12 +126,13 @@ func testCheckAzureRMSecurityCenterWorkspaceDestroy(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).SecurityCenter.WorkspaceClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - for _, res := range s.RootModule().Resources { - if res.Type != "azurerm_security_center_workspace" { + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_security_center_workspace" { continue } - resp, err := client.Get(ctx, securityCenterWorkspaceName) + workspaceSettingName := "default" + resp, err := client.Get(ctx, workspaceSettingName) if err != nil { if utils.ResponseWasNotFound(resp.Response) { return nil @@ -160,38 +141,39 @@ func testCheckAzureRMSecurityCenterWorkspaceDestroy(s *terraform.State) error { return err } - return fmt.Errorf("security center worspace settings still exists") + return fmt.Errorf("security center workspace settings still exists") } return nil } -func testAccAzureRMSecurityCenterWorkspace_basicCfg(rInt int, location, scope string) string { +func testAccAzureRMSecurityCenterWorkspace_basicCfg(data acceptance.TestData, scope string) string { return fmt.Sprintf(` resource "azurerm_security_center_subscription_pricing" "test" { tier = "Standard" } resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" - location = "%[2]s" + name = "acctestRG-%d" + location = "%s" } resource "azurerm_log_analytics_workspace" "test" { - name = "acctest-%[1]d-1" + name = "acctest-%d-1" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "PerGB2018" } resource "azurerm_security_center_workspace" "test" { - scope = "%[3]s" + scope = "%s" workspace_id = "${azurerm_log_analytics_workspace.test.id}" } -`, rInt, location, scope) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, scope) } -func testAccAzureRMSecurityCenterWorkspace_requiresImportCfg(rInt int, location, scope string) string { +func testAccAzureRMSecurityCenterWorkspace_requiresImportCfg(data acceptance.TestData, scope string) string { + template := testAccAzureRMSecurityCenterWorkspace_basicCfg(data, scope) return fmt.Sprintf(` %s @@ -199,30 +181,30 @@ resource "azurerm_security_center_workspace" "import" { scope = "${azurerm_security_center_workspace.test.scope}" workspace_id = "${azurerm_security_center_workspace.test.workspace_id}" } -`, testAccAzureRMSecurityCenterWorkspace_basicCfg(rInt, location, scope)) +`, template) } -func testAccAzureRMSecurityCenterWorkspace_differentWorkspaceCfg(rInt int, location, scope string) string { +func testAccAzureRMSecurityCenterWorkspace_differentWorkspaceCfg(data acceptance.TestData, scope string) string { return fmt.Sprintf(` resource "azurerm_security_center_subscription_pricing" "test" { tier = "Standard" } resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" - location = "%[2]s" + name = "acctestRG-%d" + location = "%s" } resource "azurerm_log_analytics_workspace" "test2" { - name = "acctest-%[1]d-2" + name = "acctest-%d-2" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "PerGB2018" } resource "azurerm_security_center_workspace" "test" { - scope = "%[3]s" + scope = "%s" workspace_id = "${azurerm_log_analytics_workspace.test2.id}" } -`, rInt, location, scope) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, scope) } From 1e49901f29e182e973c603e1a9eedbea1749f045 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 08:55:03 +0100 Subject: [PATCH 115/203] search: switching to use the new structure --- .../resource_arm_search_service_test.go | 92 ++++++++----------- 1 file changed, 38 insertions(+), 54 deletions(-) rename azurerm/internal/services/search/{ => tests}/resource_arm_search_service_test.go (63%) diff --git a/azurerm/internal/services/search/resource_arm_search_service_test.go b/azurerm/internal/services/search/tests/resource_arm_search_service_test.go similarity index 63% rename from azurerm/internal/services/search/resource_arm_search_service_test.go rename to azurerm/internal/services/search/tests/resource_arm_search_service_test.go index 469fcbd56de6..810e083371b2 100644 --- a/azurerm/internal/services/search/resource_arm_search_service_test.go +++ b/azurerm/internal/services/search/tests/resource_arm_search_service_test.go @@ -1,4 +1,4 @@ -package search +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMSearchService_basic(t *testing.T) { - resourceName := "azurerm_search_service.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_search_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,17 +21,13 @@ func TestAccAzureRMSearchService_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSearchServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSearchService_basic(ri, acceptance.Location()), + Config: testAccAzureRMSearchService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSearchServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMSearchServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,32 +38,26 @@ func TestAccAzureRMSearchService_requiresImport(t *testing.T) { return } - resourceName := "azurerm_search_service.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_search_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMSearchServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSearchService_basic(ri, acceptance.Location()), + Config: testAccAzureRMSearchService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSearchServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMSearchServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - Config: testAccAzureRMSearchService_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_search_service"), - }, + data.RequiresImportErrorStep(testAccAzureRMSearchService_requiresImport), }, }) } func TestAccAzureRMSearchService_complete(t *testing.T) { - resourceName := "azurerm_search_service.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_search_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -77,28 +65,23 @@ func TestAccAzureRMSearchService_complete(t *testing.T) { CheckDestroy: testCheckAzureRMSearchServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSearchService_complete(ri, acceptance.Location()), + Config: testAccAzureRMSearchService_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSearchServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "replica_count", "2"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttr(resourceName, "query_keys.#", "1"), + testCheckAzureRMSearchServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "replica_count", "2"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttr(data.ResourceName, "query_keys.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSearchService_tagUpdate(t *testing.T) { - resourceName := "azurerm_search_service.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_search_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -106,19 +89,19 @@ func TestAccAzureRMSearchService_tagUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMSearchServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSearchService_withCustomTagValue(ri, acceptance.Location(), "staging"), + Config: testAccAzureRMSearchService_withCustomTagValue(data, "staging"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSearchServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMSearchServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, { - Config: testAccAzureRMSearchService_withCustomTagValue(ri, acceptance.Location(), "production"), + Config: testAccAzureRMSearchService_withCustomTagValue(data, "production"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSearchServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), + testCheckAzureRMSearchServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), ), }, }, @@ -178,7 +161,7 @@ func testCheckAzureRMSearchServiceDestroy(s *terraform.State) error { return nil } -func testAccAzureRMSearchService_withCustomTagValue(rInt int, location string, tagValue string) string { +func testAccAzureRMSearchService_withCustomTagValue(data acceptance.TestData, tagValue string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -195,14 +178,15 @@ resource "azurerm_search_service" "test" { environment = "%s" } } -`, rInt, location, rInt, tagValue) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, tagValue) } -func testAccAzureRMSearchService_basic(rInt int, location string) string { - return testAccAzureRMSearchService_withCustomTagValue(rInt, location, "staging") +func testAccAzureRMSearchService_basic(data acceptance.TestData) string { + return testAccAzureRMSearchService_withCustomTagValue(data, "staging") } -func testAccAzureRMSearchService_requiresImport(rInt int, location string) string { +func testAccAzureRMSearchService_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMSearchService_basic(data) return fmt.Sprintf(` %s resource "azurerm_search_service" "import" { @@ -215,10 +199,10 @@ resource "azurerm_search_service" "import" { environment = "staging" } } -`, testAccAzureRMSearchService_basic(rInt, location)) +`, template) } -func testAccAzureRMSearchService_complete(rInt int, location string) string { +func testAccAzureRMSearchService_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -236,5 +220,5 @@ resource "azurerm_search_service" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From e25e5639dfc18a8d304ec84d9d451df0cc1cd1fd Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 09:24:07 +0100 Subject: [PATCH 116/203] scheduler: fixing up the tests --- ...ta_source_scheduler_job_collection_test.go | 27 +- ...ource_arm_scheduler_job_collection_test.go | 60 +-- .../resource_arm_scheduler_job_test.go | 508 ++++++++---------- .../testdata/application_gateway_test.pfx | Bin 4 files changed, 264 insertions(+), 331 deletions(-) rename azurerm/internal/services/scheduler/{ => tests}/data_source_scheduler_job_collection_test.go (56%) rename azurerm/internal/services/scheduler/{ => tests}/resource_arm_scheduler_job_collection_test.go (75%) rename azurerm/internal/services/scheduler/{ => tests}/resource_arm_scheduler_job_test.go (52%) rename azurerm/internal/services/scheduler/{ => tests}/testdata/application_gateway_test.pfx (100%) diff --git a/azurerm/internal/services/scheduler/data_source_scheduler_job_collection_test.go b/azurerm/internal/services/scheduler/tests/data_source_scheduler_job_collection_test.go similarity index 56% rename from azurerm/internal/services/scheduler/data_source_scheduler_job_collection_test.go rename to azurerm/internal/services/scheduler/tests/data_source_scheduler_job_collection_test.go index 16a536978463..94a8f07bf2ac 100644 --- a/azurerm/internal/services/scheduler/data_source_scheduler_job_collection_test.go +++ b/azurerm/internal/services/scheduler/tests/data_source_scheduler_job_collection_test.go @@ -1,47 +1,45 @@ -package scheduler +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMSchedulerJobCollection_basic(t *testing.T) { - dataSourceName := "data.azurerm_scheduler_job_collection.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_scheduler_job_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceSchedulerJobCollection_basic(ri, acceptance.Location()), - Check: checkAccAzureRMSchedulerJobCollection_basic(dataSourceName), + Config: testAccDataSourceSchedulerJobCollection_basic(data), + Check: checkAccAzureRMSchedulerJobCollection_basic(data.ResourceName), }, }, }) } func TestAccDataSourceAzureRMSchedulerJobCollection_complete(t *testing.T) { - dataSourceName := "data.azurerm_scheduler_job_collection.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_scheduler_job_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceSchedulerJobCollection_complete(ri, acceptance.Location()), - Check: checkAccAzureRMSchedulerJobCollection_complete(dataSourceName), + Config: testAccDataSourceSchedulerJobCollection_complete(data), + Check: checkAccAzureRMSchedulerJobCollection_complete(data.ResourceName), }, }, }) } -func testAccDataSourceSchedulerJobCollection_basic(rInt int, location string) string { +func testAccDataSourceSchedulerJobCollection_basic(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJobCollection_basic(data, "") return fmt.Sprintf(` %s @@ -49,10 +47,11 @@ data "azurerm_scheduler_job_collection" "test" { name = "${azurerm_scheduler_job_collection.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, testAccAzureRMSchedulerJobCollection_basic(rInt, location, "")) +`, template) } -func testAccDataSourceSchedulerJobCollection_complete(rInt int, location string) string { +func testAccDataSourceSchedulerJobCollection_complete(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJobCollection_complete(data) return fmt.Sprintf(` %s @@ -60,5 +59,5 @@ data "azurerm_scheduler_job_collection" "test" { name = "${azurerm_scheduler_job_collection.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, testAccAzureRMSchedulerJobCollection_complete(rInt, location)) +`, template) } diff --git a/azurerm/internal/services/scheduler/resource_arm_scheduler_job_collection_test.go b/azurerm/internal/services/scheduler/tests/resource_arm_scheduler_job_collection_test.go similarity index 75% rename from azurerm/internal/services/scheduler/resource_arm_scheduler_job_collection_test.go rename to azurerm/internal/services/scheduler/tests/resource_arm_scheduler_job_collection_test.go index b30d6a8a2b76..a419ce5a7779 100644 --- a/azurerm/internal/services/scheduler/resource_arm_scheduler_job_collection_test.go +++ b/azurerm/internal/services/scheduler/tests/resource_arm_scheduler_job_collection_test.go @@ -1,6 +1,6 @@ // nolint: megacheck // entire automation SDK has been depreciated in v21.3 in favor of logic apps, an entirely different service. -package scheduler +package tests import ( "fmt" @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -18,8 +17,7 @@ import ( ) func TestAccAzureRMSchedulerJobCollection_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_scheduler_job_collection.test" + data := acceptance.BuildTestData(t, "azurerm_scheduler_job_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,14 +25,10 @@ func TestAccAzureRMSchedulerJobCollection_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobCollectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJobCollection_basic(ri, acceptance.Location(), ""), - Check: checkAccAzureRMSchedulerJobCollection_basic(resourceName), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMSchedulerJobCollection_basic(data, ""), + Check: checkAccAzureRMSchedulerJobCollection_basic(data.ResourceName), }, + data.ImportStep(), }, }) } @@ -45,8 +39,7 @@ func TestAccAzureRMSchedulerJobCollection_requiresImport(t *testing.T) { return } - ri := tf.AccRandTimeInt() - resourceName := "azurerm_scheduler_job_collection.test" + data := acceptance.BuildTestData(t, "azurerm_scheduler_job_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,20 +47,18 @@ func TestAccAzureRMSchedulerJobCollection_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobCollectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJobCollection_basic(ri, acceptance.Location(), ""), - Check: checkAccAzureRMSchedulerJobCollection_basic(resourceName), - }, - { - Config: testAccAzureRMSchedulerJobCollection_requiresImport(ri, acceptance.Location(), ""), - ExpectError: acceptance.RequiresImportError("azurerm_scheduler_job_collection"), + Config: testAccAzureRMSchedulerJobCollection_basic(data, ""), + Check: checkAccAzureRMSchedulerJobCollection_basic(data.ResourceName), }, + data.RequiresImportErrorStep(func(data acceptance.TestData) string { + return testAccAzureRMSchedulerJobCollection_requiresImport(data, "") + }), }, }) } func TestAccAzureRMSchedulerJobCollection_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_scheduler_job_collection.test" + data := acceptance.BuildTestData(t, "azurerm_scheduler_job_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -75,18 +66,14 @@ func TestAccAzureRMSchedulerJobCollection_complete(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobCollectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJobCollection_basic(ri, acceptance.Location(), ""), - Check: checkAccAzureRMSchedulerJobCollection_basic(resourceName), - }, - { - Config: testAccAzureRMSchedulerJobCollection_complete(ri, acceptance.Location()), - Check: checkAccAzureRMSchedulerJobCollection_complete(resourceName), + Config: testAccAzureRMSchedulerJobCollection_basic(data, ""), + Check: checkAccAzureRMSchedulerJobCollection_basic(data.ResourceName), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMSchedulerJobCollection_complete(data), + Check: checkAccAzureRMSchedulerJobCollection_complete(data.ResourceName), }, + data.ImportStep(), }, }) } @@ -149,7 +136,7 @@ func testCheckAzureRMSchedulerJobCollectionExists(resourceName string) resource. } } -func testAccAzureRMSchedulerJobCollection_basic(rInt int, location string, additional string) string { +func testAccAzureRMSchedulerJobCollection_basic(data acceptance.TestData, additional string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -163,10 +150,11 @@ resource "azurerm_scheduler_job_collection" "test" { sku = "Standard" %s } -`, rInt, location, rInt, additional) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, additional) } -func testAccAzureRMSchedulerJobCollection_requiresImport(rInt int, location string, additional string) string { +func testAccAzureRMSchedulerJobCollection_requiresImport(data acceptance.TestData, additional string) string { + template := testAccAzureRMSchedulerJobCollection_basic(data, additional) return fmt.Sprintf(` %s @@ -178,11 +166,11 @@ resource "azurerm_scheduler_job_collection" "import" { %s } -`, testAccAzureRMSchedulerJobCollection_basic(rInt, location, additional), additional) +`, template, additional) } -func testAccAzureRMSchedulerJobCollection_complete(rInt int, location string) string { - return testAccAzureRMSchedulerJobCollection_basic(rInt, location, ` +func testAccAzureRMSchedulerJobCollection_complete(data acceptance.TestData) string { + return testAccAzureRMSchedulerJobCollection_basic(data, ` state = "disabled" quota { max_recurrence_frequency = "Hour" diff --git a/azurerm/internal/services/scheduler/resource_arm_scheduler_job_test.go b/azurerm/internal/services/scheduler/tests/resource_arm_scheduler_job_test.go similarity index 52% rename from azurerm/internal/services/scheduler/resource_arm_scheduler_job_test.go rename to azurerm/internal/services/scheduler/tests/resource_arm_scheduler_job_test.go index 0b35e2c36870..18c2264ce0df 100644 --- a/azurerm/internal/services/scheduler/resource_arm_scheduler_job_test.go +++ b/azurerm/internal/services/scheduler/tests/resource_arm_scheduler_job_test.go @@ -1,16 +1,14 @@ // nolint: megacheck // entire automation SDK has been depreciated in v21.3 in favor of logic apps, an entirely different service. -package scheduler +package tests import ( "fmt" "os" - "strconv" "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/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -18,8 +16,7 @@ import ( ) func TestAccAzureRMSchedulerJob_web_basic(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,18 +24,14 @@ func TestAccAzureRMSchedulerJob_web_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_basic(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "http://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "http://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -49,8 +42,7 @@ func TestAccAzureRMSchedulerJob_web_requiresImport(t *testing.T) { return } - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -58,24 +50,20 @@ func TestAccAzureRMSchedulerJob_web_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_basic(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "http://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "http://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), ), }, - { - Config: testAccAzureRMSchedulerJob_web_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_scheduler_job"), - }, + data.RequiresImportErrorStep(testAccAzureRMSchedulerJob_web_requiresImport), }, }) } func TestAccAzureRMSchedulerJob_storageQueue(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -83,28 +71,22 @@ func TestAccAzureRMSchedulerJob_storageQueue(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_storageQueue(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_storageQueue(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "action_storage_queue.0.storage_account_name"), - resource.TestCheckResourceAttrSet(resourceName, "action_storage_queue.0.storage_queue_name"), - resource.TestCheckResourceAttrSet(resourceName, "action_storage_queue.0.sas_token"), - resource.TestCheckResourceAttr(resourceName, "action_storage_queue.0.message", "storage message"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "action_storage_queue.0.storage_account_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "action_storage_queue.0.storage_queue_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "action_storage_queue.0.sas_token"), + resource.TestCheckResourceAttr(data.ResourceName, "action_storage_queue.0.message", "storage message"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"action_storage_queue.0.sas_token"}, - }, + data.ImportStep("action_storage_queue.0.sas_token"), }, }) } func TestAccAzureRMSchedulerJob_storageQueue_errorAction(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -112,30 +94,24 @@ func TestAccAzureRMSchedulerJob_storageQueue_errorAction(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_storageQueue_errorAction(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_storageQueue_errorAction(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "http://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttrSet(resourceName, "error_action_storage_queue.0.storage_account_name"), - resource.TestCheckResourceAttrSet(resourceName, "error_action_storage_queue.0.storage_queue_name"), - resource.TestCheckResourceAttrSet(resourceName, "error_action_storage_queue.0.sas_token"), - resource.TestCheckResourceAttr(resourceName, "error_action_storage_queue.0.message", "storage message"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "http://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttrSet(data.ResourceName, "error_action_storage_queue.0.storage_account_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "error_action_storage_queue.0.storage_queue_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "error_action_storage_queue.0.sas_token"), + resource.TestCheckResourceAttr(data.ResourceName, "error_action_storage_queue.0.message", "storage message"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"error_action_storage_queue.0.sas_token"}, - }, + data.ImportStep("error_action_storage_queue.0.sas_token"), }, }) } func TestAccAzureRMSchedulerJob_web_put(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -143,26 +119,21 @@ func TestAccAzureRMSchedulerJob_web_put(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_put(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_put(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "http://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "put"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.body", "this is some text"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "http://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "put"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.body", "this is some text"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSchedulerJob_web_authBasic(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -170,27 +141,21 @@ func TestAccAzureRMSchedulerJob_web_authBasic(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_authBasic(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_authBasic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.authentication_basic.0.username", "login"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.authentication_basic.0.username", "login"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"action_web.0.authentication_basic.0.password"}, - }, + data.ImportStep("action_web.0.authentication_basic.0.password"), }, }) } func TestAccAzureRMSchedulerJob_web_authCert(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -198,24 +163,17 @@ func TestAccAzureRMSchedulerJob_web_authCert(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_authCert(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_authCert(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.authentication_certificate.0.thumbprint", "42C107874FD0E4A9583292A2F1098E8FE4B2EDDA"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.authentication_certificate.0.subject_name", "CN=Terraform App Gateway, OU=Azure, O=Terraform Tests, S=Some-State, C=US"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.authentication_certificate.0.thumbprint", "42C107874FD0E4A9583292A2F1098E8FE4B2EDDA"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.authentication_certificate.0.subject_name", "CN=Terraform App Gateway, OU=Azure, O=Terraform Tests, S=Some-State, C=US"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "action_web.0.authentication_certificate.0.pfx", - "action_web.0.authentication_certificate.0.password", - }, - }, + data.ImportStep("action_web.0.authentication_certificate.0.pfx", + "action_web.0.authentication_certificate.0.password"), }, }) } @@ -226,8 +184,7 @@ func TestAccAzureRMSchedulerJob_web_authAd(t *testing.T) { return } - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") clientId := os.Getenv("ARM_CLIENT_ID") tenantId := os.Getenv("ARM_TENANT_ID") @@ -246,29 +203,23 @@ func TestAccAzureRMSchedulerJob_web_authAd(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_authAd(ri, acceptance.Location(), tenantId, clientId, secret, audience), + Config: testAccAzureRMSchedulerJob_web_authAd(data, tenantId, clientId, secret, audience), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.authentication_active_directory.0.tenant_id", tenantId), - resource.TestCheckResourceAttr(resourceName, "action_web.0.authentication_active_directory.0.client_id", clientId), - resource.TestCheckResourceAttrSet(resourceName, "action_web.0.authentication_active_directory.0.audience"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.authentication_active_directory.0.tenant_id", tenantId), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.authentication_active_directory.0.client_id", clientId), + resource.TestCheckResourceAttrSet(data.ResourceName, "action_web.0.authentication_active_directory.0.audience"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"action_web.0.authentication_active_directory.0.secret"}, - }, + data.ImportStep("action_web.0.authentication_active_directory.0.secret"), }, }) } func TestAccAzureRMSchedulerJob_web_retry(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -276,27 +227,22 @@ func TestAccAzureRMSchedulerJob_web_retry(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_retry(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_retry(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttr(resourceName, "retry.0.interval", "00:05:00"), - resource.TestCheckResourceAttr(resourceName, "retry.0.count", "10"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "retry.0.interval", "00:05:00"), + resource.TestCheckResourceAttr(data.ResourceName, "retry.0.count", "10"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSchedulerJob_web_recurring(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -304,28 +250,23 @@ func TestAccAzureRMSchedulerJob_web_recurring(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_recurring(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_recurring(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.frequency", "minute"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.interval", "5"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.count", "10"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.frequency", "minute"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.interval", "5"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.count", "10"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSchedulerJob_web_recurringDaily(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -333,29 +274,24 @@ func TestAccAzureRMSchedulerJob_web_recurringDaily(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_recurringDaily(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_recurringDaily(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.frequency", "day"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.count", "100"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.hours.#", "2"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.minutes.#", "4"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.frequency", "day"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.count", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.hours.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.minutes.#", "4"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSchedulerJob_web_recurringWeekly(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -363,28 +299,23 @@ func TestAccAzureRMSchedulerJob_web_recurringWeekly(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_recurringWeekly(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_recurringWeekly(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.frequency", "week"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.count", "100"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.week_days.#", "2"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.frequency", "week"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.count", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.week_days.#", "2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSchedulerJob_web_recurringMonthly(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -392,28 +323,23 @@ func TestAccAzureRMSchedulerJob_web_recurringMonthly(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_recurringMonthly(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_recurringMonthly(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.frequency", "month"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.count", "100"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.month_days.#", "4"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.frequency", "month"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.count", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.month_days.#", "4"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSchedulerJob_web_recurringMonthlyOccurrences(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -421,34 +347,29 @@ func TestAccAzureRMSchedulerJob_web_recurringMonthlyOccurrences(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_recurringMonthlyOccurrences(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_recurringMonthlyOccurrences(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.frequency", "month"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.count", "100"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.monthly_occurrences.#", "3"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.monthly_occurrences.2181640481.day", "sunday"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.monthly_occurrences.2181640481.occurrence", "1"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.monthly_occurrences.2956940195.day", "sunday"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.monthly_occurrences.2956940195.occurrence", "3"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.monthly_occurrences.679325150.day", "sunday"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.monthly_occurrences.679325150.occurrence", "-1"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.frequency", "month"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.count", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.monthly_occurrences.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.monthly_occurrences.2181640481.day", "sunday"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.monthly_occurrences.2181640481.occurrence", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.monthly_occurrences.2956940195.day", "sunday"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.monthly_occurrences.2956940195.occurrence", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.monthly_occurrences.679325150.day", "sunday"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.monthly_occurrences.679325150.occurrence", "-1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSchedulerJob_web_errorAction(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -456,27 +377,22 @@ func TestAccAzureRMSchedulerJob_web_errorAction(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_errorAction(ri, acceptance.Location()), + Config: testAccAzureRMSchedulerJob_web_errorAction(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "get"), - resource.TestCheckResourceAttr(resourceName, "error_action_web.0.url", "https://example.com"), - resource.TestCheckResourceAttr(resourceName, "error_action_web.0.method", "get"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "error_action_web.0.url", "https://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "error_action_web.0.method", "get"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSchedulerJob_web_complete(t *testing.T) { - resourceName := "azurerm_scheduler_job.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_scheduler_job", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -484,25 +400,21 @@ func TestAccAzureRMSchedulerJob_web_complete(t *testing.T) { CheckDestroy: testCheckAzureRMSchedulerJobDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSchedulerJob_web_complete(ri, acceptance.Location(), "2019-07-07T07:07:07-07:00"), + Config: testAccAzureRMSchedulerJob_web_complete(data, "2019-07-07T07:07:07-07:00"), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMSchedulerJobExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "action_web.0.url", "http://example.com"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.method", "put"), - resource.TestCheckResourceAttr(resourceName, "action_web.0.body", "this is some text"), - resource.TestCheckResourceAttr(resourceName, "retry.0.interval", "00:05:00"), - resource.TestCheckResourceAttr(resourceName, "retry.0.count", "10"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.frequency", "month"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.count", "100"), - resource.TestCheckResourceAttr(resourceName, "recurrence.0.month_days.#", "4"), - resource.TestCheckResourceAttr(resourceName, "start_time", "2019-07-07T14:07:07Z"), + testCheckAzureRMSchedulerJobExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.url", "http://example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.method", "put"), + resource.TestCheckResourceAttr(data.ResourceName, "action_web.0.body", "this is some text"), + resource.TestCheckResourceAttr(data.ResourceName, "retry.0.interval", "00:05:00"), + resource.TestCheckResourceAttr(data.ResourceName, "retry.0.count", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.frequency", "month"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.count", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "recurrence.0.month_days.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "start_time", "2019-07-07T14:07:07Z"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -567,23 +479,24 @@ func testCheckAzureRMSchedulerJobExists(resourceName string) resource.TestCheckF } } -func testAccAzureRMSchedulerJob_template(rInt int, location string) string { +func testAccAzureRMSchedulerJob_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" - location = "%[2]s" + name = "acctestRG-%d" + location = "%s" } resource "azurerm_scheduler_job_collection" "test" { - name = "acctest-%[1]d-job_collection" + name = "acctest-%d-job_collection" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_basic(rInt int, location string) string { +func testAccAzureRMSchedulerJob_web_basic(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) //need a valid URL here otherwise on a slow connection job might fault before the test check return fmt.Sprintf(` %s @@ -598,10 +511,11 @@ resource "azurerm_scheduler_job" "test" { method = "get" } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_requiresImport(rInt int, location string) string { +func testAccAzureRMSchedulerJob_web_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_web_basic(data) //need a valid URL here otherwise on a slow connection job might fault before the test check return fmt.Sprintf(` %s @@ -616,11 +530,14 @@ resource "azurerm_scheduler_job" "import" { method = "get" } } -`, testAccAzureRMSchedulerJob_web_basic(rInt, location)) +`, template) } -func testAccAzureRMSchedulerJob_web_put(rInt int, location string) string { - return fmt.Sprintf(`%s +func testAccAzureRMSchedulerJob_web_put(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) + return fmt.Sprintf(` +%s + resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" @@ -636,11 +553,14 @@ resource "azurerm_scheduler_job" "test" { } } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_authBasic(rInt int, location string) string { - return fmt.Sprintf(`%s +func testAccAzureRMSchedulerJob_web_authBasic(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) + return fmt.Sprintf(` +%s + resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" @@ -656,10 +576,11 @@ resource "azurerm_scheduler_job" "test" { } } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_authCert(rInt int, location string) string { +func testAccAzureRMSchedulerJob_web_authCert(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" @@ -676,10 +597,11 @@ resource "azurerm_scheduler_job" "test" { } } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_authAd(rInt int, location, tenantId, clientId, secret, audience string) string { +func testAccAzureRMSchedulerJob_web_authAd(data acceptance.TestData, tenantId, clientId, secret, audience string) string { + template := testAccAzureRMSchedulerJob_template(data) return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" @@ -698,11 +620,14 @@ resource "azurerm_scheduler_job" "test" { } } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt, tenantId, clientId, secret, audience) +`, template, data.RandomInteger, tenantId, clientId, secret, audience) } -func testAccAzureRMSchedulerJob_web_retry(rInt int, location string) string { - return fmt.Sprintf(`%s +func testAccAzureRMSchedulerJob_web_retry(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) + return fmt.Sprintf(` +%s + resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" @@ -718,11 +643,14 @@ resource "azurerm_scheduler_job" "test" { count = 10 } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_recurring(rInt int, location string) string { - return fmt.Sprintf(`%s +func testAccAzureRMSchedulerJob_web_recurring(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) + return fmt.Sprintf(` +%s + resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" @@ -739,11 +667,14 @@ resource "azurerm_scheduler_job" "test" { count = 10 } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_recurringDaily(rInt int, location string) string { - return fmt.Sprintf(`%s +func testAccAzureRMSchedulerJob_web_recurringDaily(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) + return fmt.Sprintf(` +%s + resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" @@ -761,11 +692,14 @@ resource "azurerm_scheduler_job" "test" { minutes = [0, 15, 30, 45] } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_recurringWeekly(rInt int, location string) string { - return fmt.Sprintf(`%s +func testAccAzureRMSchedulerJob_web_recurringWeekly(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) + return fmt.Sprintf(` +%s + resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" @@ -782,11 +716,14 @@ resource "azurerm_scheduler_job" "test" { week_days = ["Sunday", "Saturday"] } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_recurringMonthly(rInt int, location string) string { - return fmt.Sprintf(`%s +func testAccAzureRMSchedulerJob_web_recurringMonthly(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) + return fmt.Sprintf(` +%s + resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" @@ -803,10 +740,11 @@ resource "azurerm_scheduler_job" "test" { month_days = [-11, -1, 1, 11] } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_recurringMonthlyOccurrences(rInt int, location string) string { +func testAccAzureRMSchedulerJob_web_recurringMonthlyOccurrences(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" @@ -838,11 +776,14 @@ resource "azurerm_scheduler_job" "test" { } } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_errorAction(rInt int, location string) string { - return fmt.Sprintf(`%s +func testAccAzureRMSchedulerJob_web_errorAction(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) + return fmt.Sprintf(` +%s + resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" @@ -858,10 +799,11 @@ resource "azurerm_scheduler_job" "test" { method = "get" } } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMSchedulerJob_web_complete(rInt int, location, time string) string { +func testAccAzureRMSchedulerJob_web_complete(data acceptance.TestData, time string) string { + template := testAccAzureRMSchedulerJob_template(data) return fmt.Sprintf(`%s resource "azurerm_scheduler_job" "test" { name = "acctest-%d-job" @@ -891,10 +833,11 @@ resource "azurerm_scheduler_job" "test" { start_time = "%s" } -`, testAccAzureRMSchedulerJob_template(rInt, location), rInt, time) +`, template, data.RandomInteger, time) } -func testAccAzureRMSchedulerJob_storageQueue(rInt int, location string) string { +func testAccAzureRMSchedulerJob_storageQueue(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) //need a valid URL here otherwise on a slow connection job might fault before the test check return fmt.Sprintf(`%[1]s resource "azurerm_storage_account" "test" { @@ -923,14 +866,17 @@ resource "azurerm_scheduler_job" "test" { message = "storage message" } } -`, testAccAzureRMSchedulerJob_template(rInt, location), strconv.Itoa(rInt)[12:17], rInt) +`, template, data.RandomString, data.RandomInteger) } -func testAccAzureRMSchedulerJob_storageQueue_errorAction(rInt int, location string) string { +func testAccAzureRMSchedulerJob_storageQueue_errorAction(data acceptance.TestData) string { + template := testAccAzureRMSchedulerJob_template(data) //need a valid URL here otherwise on a slow connection job might fault before the test check - return fmt.Sprintf(`%[1]s + return fmt.Sprintf(` +%s + resource "azurerm_storage_account" "test" { - name = "acctest%[2]s" + name = "acctest%s" resource_group_name = "${azurerm_resource_group.test.name}" location = "${azurerm_resource_group.test.location}" account_tier = "Standard" @@ -938,13 +884,13 @@ resource "azurerm_storage_account" "test" { } resource "azurerm_storage_queue" "test" { - name = "acctest-%[3]d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" storage_account_name = "${azurerm_storage_account.test.name}" } resource "azurerm_scheduler_job" "test" { - name = "acctest-%[3]d-job" + name = "acctest-%d-job" resource_group_name = "${azurerm_resource_group.test.name}" job_collection_name = "${azurerm_scheduler_job_collection.test.name}" @@ -960,5 +906,5 @@ resource "azurerm_scheduler_job" "test" { message = "storage message" } } -`, testAccAzureRMSchedulerJob_template(rInt, location), strconv.Itoa(rInt)[12:17], rInt) +`, template, data.RandomString, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/scheduler/testdata/application_gateway_test.pfx b/azurerm/internal/services/scheduler/tests/testdata/application_gateway_test.pfx similarity index 100% rename from azurerm/internal/services/scheduler/testdata/application_gateway_test.pfx rename to azurerm/internal/services/scheduler/tests/testdata/application_gateway_test.pfx From 6b81a1468b59c4b60915c952d2238c516500fd5f Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 09:41:53 +0100 Subject: [PATCH 117/203] relay: fixing up the tests --- ...source_arm_relay_hybrid_connection_test.go | 83 +++++------- .../resource_arm_relay_namespace_test.go | 125 ++++++++---------- 2 files changed, 87 insertions(+), 121 deletions(-) rename azurerm/internal/services/relay/{ => tests}/resource_arm_relay_hybrid_connection_test.go (69%) rename azurerm/internal/services/relay/{ => tests}/resource_arm_relay_namespace_test.go (60%) diff --git a/azurerm/internal/services/relay/resource_arm_relay_hybrid_connection_test.go b/azurerm/internal/services/relay/tests/resource_arm_relay_hybrid_connection_test.go similarity index 69% rename from azurerm/internal/services/relay/resource_arm_relay_hybrid_connection_test.go rename to azurerm/internal/services/relay/tests/resource_arm_relay_hybrid_connection_test.go index b43d63e8ee63..b8ce0881eebd 100644 --- a/azurerm/internal/services/relay/resource_arm_relay_hybrid_connection_test.go +++ b/azurerm/internal/services/relay/tests/resource_arm_relay_hybrid_connection_test.go @@ -1,4 +1,4 @@ -package relay +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMRelayHybridConnection_basic(t *testing.T) { - resourceName := "azurerm_relay_hybrid_connection.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_relay_hybrid_connection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,24 +21,19 @@ func TestAccAzureRMRelayHybridConnection_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRelayHybridConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRelayHybridConnection_basic(ri, acceptance.Location()), + Config: testAccAzureRMRelayHybridConnection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRelayHybridConnectionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), + testCheckAzureRMRelayHybridConnectionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "requires_client_authorization"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRelayHybridConnection_full(t *testing.T) { - resourceName := "azurerm_relay_hybrid_connection.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_relay_hybrid_connection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -48,43 +41,38 @@ func TestAccAzureRMRelayHybridConnection_full(t *testing.T) { CheckDestroy: testCheckAzureRMRelayHybridConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRelayHybridConnection_full(ri, acceptance.Location()), + Config: testAccAzureRMRelayHybridConnection_full(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRelayHybridConnectionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), - resource.TestCheckResourceAttr(resourceName, "user_metadata", "metadatatest"), + testCheckAzureRMRelayHybridConnectionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "requires_client_authorization"), + resource.TestCheckResourceAttr(data.ResourceName, "user_metadata", "metadatatest"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRelayHybridConnection_update(t *testing.T) { - resourceName := "azurerm_relay_hybrid_connection.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_relay_hybrid_connection", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMRelayHybridConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRelayHybridConnection_basic(rInt, location), + Config: testAccAzureRMRelayHybridConnection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRelayHybridConnectionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), + testCheckAzureRMRelayHybridConnectionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "requires_client_authorization"), ), }, { - Config: testAccAzureRMRelayHybridConnection_update(rInt, location), + Config: testAccAzureRMRelayHybridConnection_update(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "requires_client_authorization", "false"), - resource.TestCheckResourceAttr(resourceName, "user_metadata", "metadataupdated"), + resource.TestCheckResourceAttr(data.ResourceName, "requires_client_authorization", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "user_metadata", "metadataupdated"), ), }, }, @@ -97,8 +85,7 @@ func TestAccAzureRMRelayHybridConnection_requiresImport(t *testing.T) { return } - resourceName := "azurerm_relay_hybrid_connection.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_relay_hybrid_connection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -106,21 +93,18 @@ func TestAccAzureRMRelayHybridConnection_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMRelayHybridConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRelayHybridConnection_basic(ri, acceptance.Location()), + Config: testAccAzureRMRelayHybridConnection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRelayHybridConnectionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "requires_client_authorization"), + testCheckAzureRMRelayHybridConnectionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "requires_client_authorization"), ), }, - { - Config: testAccAzureRMRelayHybridConnection_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_relay_hybrid_connection"), - }, + data.RequiresImportErrorStep(testAccAzureRMRelayHybridConnection_requiresImport), }, }) } -func testAccAzureRMRelayHybridConnection_basic(rInt int, location string) string { +func testAccAzureRMRelayHybridConnection_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -140,10 +124,10 @@ resource "azurerm_relay_hybrid_connection" "test" { resource_group_name = "${azurerm_resource_group.test.name}" relay_namespace_name = "${azurerm_relay_namespace.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRelayHybridConnection_full(rInt int, location string) string { +func testAccAzureRMRelayHybridConnection_full(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -164,10 +148,10 @@ resource "azurerm_relay_hybrid_connection" "test" { relay_namespace_name = "${azurerm_relay_namespace.test.name}" user_metadata = "metadatatest" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRelayHybridConnection_update(rInt int, location string) string { +func testAccAzureRMRelayHybridConnection_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -189,10 +173,11 @@ resource "azurerm_relay_hybrid_connection" "test" { requires_client_authorization = false user_metadata = "metadataupdated" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRelayHybridConnection_requiresImport(rInt int, location string) string { +func testAccAzureRMRelayHybridConnection_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMRelayHybridConnection_basic(data) return fmt.Sprintf(` %s @@ -201,7 +186,7 @@ resource "azurerm_relay_namespace" "import" { resource_group_name = "${azurerm_resource_group.test.name}" relay_namespace_name = "${azurerm_relay_namespace.test.name}" } -`, testAccAzureRMRelayHybridConnection_basic(rInt, location), rInt) +`, template, data.RandomInteger) } func testCheckAzureRMRelayHybridConnectionExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/relay/resource_arm_relay_namespace_test.go b/azurerm/internal/services/relay/tests/resource_arm_relay_namespace_test.go similarity index 60% rename from azurerm/internal/services/relay/resource_arm_relay_namespace_test.go rename to azurerm/internal/services/relay/tests/resource_arm_relay_namespace_test.go index 3a71cf0a9b27..b18f59cc09fe 100644 --- a/azurerm/internal/services/relay/resource_arm_relay_namespace_test.go +++ b/azurerm/internal/services/relay/tests/resource_arm_relay_namespace_test.go @@ -1,4 +1,4 @@ -package relay +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMRelayNamespace_basic(t *testing.T) { - resourceName := "azurerm_relay_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_relay_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,30 +22,25 @@ func TestAccAzureRMRelayNamespace_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRelayNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRelayNamespace_basic(ri, acceptance.Location()), + Config: testAccAzureRMRelayNamespace_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRelayNamespaceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "metric_id"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttr(resourceName, "sku_name", "Standard"), + testCheckAzureRMRelayNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "metric_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "Standard"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -// Remove in 2.0 +// TODO: Remove in 2.0 func TestAccAzureRMRelayNamespace_basicClassic(t *testing.T) { - resourceName := "azurerm_relay_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_relay_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,29 +48,25 @@ func TestAccAzureRMRelayNamespace_basicClassic(t *testing.T) { CheckDestroy: testCheckAzureRMRelayNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRelayNamespace_basicClassic(ri, acceptance.Location()), + Config: testAccAzureRMRelayNamespace_basicClassic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRelayNamespaceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "metric_id"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard"), + testCheckAzureRMRelayNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "metric_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } // Remove in 2.0 func TestAccAzureRMRelayNamespace_basicNotDefined(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_relay_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -85,7 +74,7 @@ func TestAccAzureRMRelayNamespace_basicNotDefined(t *testing.T) { CheckDestroy: testCheckAzureRMRelayNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRelayNamespace_basicNotDefined(ri, acceptance.Location()), + Config: testAccAzureRMRelayNamespace_basicNotDefined(data), ExpectError: regexp.MustCompile("either 'sku_name' or 'sku' must be defined in the configuration file"), }, }, @@ -98,8 +87,7 @@ func TestAccAzureRMRelayNamespace_requiresImport(t *testing.T) { return } - resourceName := "azurerm_relay_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_relay_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -107,27 +95,23 @@ func TestAccAzureRMRelayNamespace_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMRelayNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRelayNamespace_basic(ri, acceptance.Location()), + Config: testAccAzureRMRelayNamespace_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRelayNamespaceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "metric_id"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + testCheckAzureRMRelayNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "metric_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), ), }, - { - Config: testAccAzureRMRelayNamespace_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_relay_namespace"), - }, + data.RequiresImportErrorStep(testAccAzureRMRelayNamespace_requiresImport), }, }) } func TestAccAzureRMRelayNamespace_complete(t *testing.T) { - resourceName := "azurerm_relay_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_relay_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -135,21 +119,17 @@ func TestAccAzureRMRelayNamespace_complete(t *testing.T) { CheckDestroy: testCheckAzureRMRelayNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRelayNamespace_complete(ri, acceptance.Location()), + Config: testAccAzureRMRelayNamespace_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRelayNamespaceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "metric_id"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), + testCheckAzureRMRelayNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "metric_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -207,7 +187,7 @@ func testCheckAzureRMRelayNamespaceDestroy(s *terraform.State) error { return nil } -func testAccAzureRMRelayNamespace_basic(rInt int, location string) string { +func testAccAzureRMRelayNamespace_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -221,11 +201,11 @@ resource "azurerm_relay_namespace" "test" { sku_name = "Standard" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } // Remove in 2.0 -func testAccAzureRMRelayNamespace_basicClassic(rInt int, location string) string { +func testAccAzureRMRelayNamespace_basicClassic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -241,10 +221,10 @@ resource "azurerm_relay_namespace" "test" { name = "Standard" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRelayNamespace_basicNotDefined(rInt int, location string) string { +func testAccAzureRMRelayNamespace_basicNotDefined(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -256,10 +236,11 @@ resource "azurerm_relay_namespace" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRelayNamespace_requiresImport(rInt int, location string) string { +func testAccAzureRMRelayNamespace_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMRelayNamespace_basic(data) return fmt.Sprintf(` %s @@ -270,10 +251,10 @@ resource "azurerm_relay_namespace" "import" { sku_name = "Standard" } -`, testAccAzureRMRelayNamespace_basic(rInt, location)) +`, template) } -func testAccAzureRMRelayNamespace_complete(rInt int, location string) string { +func testAccAzureRMRelayNamespace_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -291,5 +272,5 @@ resource "azurerm_relay_namespace" "test" { Hello = "World" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 73264893ed5c05e907d34665f2b0c36d0fe8947a Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 11:40:58 +0100 Subject: [PATCH 118/203] redis: switching to use the new test structure --- .../data_source_redis_cache_test.go | 25 +- .../resource_arm_redis_cache_test.go | 478 ++++++------------ .../resource_arm_redis_firewall_rule_test.go | 113 +---- .../services/redis/validation_test.go | 136 +++++ 4 files changed, 321 insertions(+), 431 deletions(-) rename azurerm/internal/services/redis/{ => tests}/data_source_redis_cache_test.go (50%) rename azurerm/internal/services/redis/{ => tests}/resource_arm_redis_cache_test.go (68%) rename azurerm/internal/services/redis/{ => tests}/resource_arm_redis_firewall_rule_test.go (70%) create mode 100644 azurerm/internal/services/redis/validation_test.go diff --git a/azurerm/internal/services/redis/data_source_redis_cache_test.go b/azurerm/internal/services/redis/tests/data_source_redis_cache_test.go similarity index 50% rename from azurerm/internal/services/redis/data_source_redis_cache_test.go rename to azurerm/internal/services/redis/tests/data_source_redis_cache_test.go index 55c801789b00..cd494389d2b2 100644 --- a/azurerm/internal/services/redis/data_source_redis_cache_test.go +++ b/azurerm/internal/services/redis/tests/data_source_redis_cache_test.go @@ -1,4 +1,4 @@ -package redis +package tests import ( "fmt" @@ -6,17 +6,14 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMRedisCache_standard(t *testing.T) { - dataSourceName := "data.azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_redis_cache", "test") - name := fmt.Sprintf("acctestRedis-%d", ri) - resourceGroupName := fmt.Sprintf("acctestRG-%d", ri) - location := acceptance.Location() + name := fmt.Sprintf("acctestRedis-%d", data.RandomInteger) + resourceGroupName := fmt.Sprintf("acctestRG-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,20 +21,20 @@ func TestAccDataSourceAzureRMRedisCache_standard(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMRedisCache_standardWithDataSource(ri, location), + Config: testAccDataSourceAzureRMRedisCache_standardWithDataSource(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", name), - resource.TestCheckResourceAttr(dataSourceName, "resource_group_name", resourceGroupName), - resource.TestCheckResourceAttr(dataSourceName, "ssl_port", "6380"), - resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "production"), + resource.TestCheckResourceAttr(data.ResourceName, "name", name), + resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_port", "6380"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), ), }, }, }) } -func testAccDataSourceAzureRMRedisCache_standardWithDataSource(rInt int, location string) string { - config := testAccAzureRMRedisCache_standard(rInt, location) +func testAccDataSourceAzureRMRedisCache_standardWithDataSource(data acceptance.TestData) string { + config := testAccAzureRMRedisCache_standard(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/redis/resource_arm_redis_cache_test.go b/azurerm/internal/services/redis/tests/resource_arm_redis_cache_test.go similarity index 68% rename from azurerm/internal/services/redis/resource_arm_redis_cache_test.go rename to azurerm/internal/services/redis/tests/resource_arm_redis_cache_test.go index cd8f88adf6c6..84998dce62ce 100644 --- a/azurerm/internal/services/redis/resource_arm_redis_cache_test.go +++ b/azurerm/internal/services/redis/tests/resource_arm_redis_cache_test.go @@ -1,115 +1,19 @@ -package redis +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) -func TestAccAzureRMRedisCacheFamily_validation(t *testing.T) { - cases := []struct { - Value string - ErrCount int - }{ - { - Value: "C", - ErrCount: 0, - }, - { - Value: "P", - ErrCount: 0, - }, - { - Value: "c", - ErrCount: 0, - }, - { - Value: "p", - ErrCount: 0, - }, - { - Value: "a", - ErrCount: 1, - }, - { - Value: "b", - ErrCount: 1, - }, - { - Value: "D", - ErrCount: 1, - }, - } - - for _, tc := range cases { - _, errors := validateRedisFamily(tc.Value, "azurerm_redis_cache") - - if len(errors) != tc.ErrCount { - t.Fatalf("Expected the Azure RM Redis Cache Family to trigger a validation error") - } - } -} - -func TestAccAzureRMRedisCacheMaxMemoryPolicy_validation(t *testing.T) { - cases := []struct { - Value string - ErrCount int - }{ - {Value: "noeviction", ErrCount: 0}, - {Value: "allkeys-lru", ErrCount: 0}, - {Value: "volatile-lru", ErrCount: 0}, - {Value: "allkeys-random", ErrCount: 0}, - {Value: "volatile-random", ErrCount: 0}, - {Value: "volatile-ttl", ErrCount: 0}, - {Value: "something-else", ErrCount: 1}, - } - - for _, tc := range cases { - _, errors := validateRedisMaxMemoryPolicy(tc.Value, "azurerm_redis_cache") - - if len(errors) != tc.ErrCount { - t.Fatalf("Expected the Azure RM Redis Cache Max Memory Policy to trigger a validation error") - } - } -} - -func TestAccAzureRMRedisCacheBackupFrequency_validation(t *testing.T) { - cases := []struct { - Value int - ErrCount int - }{ - {Value: 1, ErrCount: 1}, - {Value: 15, ErrCount: 0}, - {Value: 30, ErrCount: 0}, - {Value: 45, ErrCount: 1}, - {Value: 60, ErrCount: 0}, - {Value: 120, ErrCount: 1}, - {Value: 240, ErrCount: 1}, - {Value: 360, ErrCount: 0}, - {Value: 720, ErrCount: 0}, - {Value: 1440, ErrCount: 0}, - } - - for _, tc := range cases { - _, errors := validateRedisBackupFrequency(tc.Value, "azurerm_redis_cache") - - if len(errors) != tc.ErrCount { - t.Fatalf("Expected the AzureRM Redis Cache Backup Frequency to trigger a validation error for '%d'", tc.Value) - } - } -} - func TestAccAzureRMRedisCache_basic(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -117,17 +21,13 @@ func TestAccAzureRMRedisCache_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRedisCache_basic(ri, acceptance.Location()), + Config: testAccAzureRMRedisCache_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "minimum_tls_version"), + testCheckAzureRMRedisCacheExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "minimum_tls_version"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -138,8 +38,7 @@ func TestAccAzureRMRedisCache_requiresImport(t *testing.T) { return } - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -147,22 +46,18 @@ func TestAccAzureRMRedisCache_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRedisCache_basic(ri, acceptance.Location()), + Config: testAccAzureRMRedisCache_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, - { - Config: testAccAzureRMRedisCache_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_redis_cache"), - }, + data.RequiresImportErrorStep(testAccAzureRMRedisCache_requiresImport), }, }) } func TestAccAzureRMRedisCache_standard(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -170,23 +65,18 @@ func TestAccAzureRMRedisCache_standard(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRedisCache_standard(ri, acceptance.Location()), + Config: testAccAzureRMRedisCache_standard(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRedisCache_premium(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -194,23 +84,18 @@ func TestAccAzureRMRedisCache_premium(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRedisCache_premium(ri, acceptance.Location()), + Config: testAccAzureRMRedisCache_premium(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRedisCache_premiumSharded(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -218,25 +103,18 @@ func TestAccAzureRMRedisCache_premiumSharded(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRedisCache_premiumSharded(ri, acceptance.Location()), + Config: testAccAzureRMRedisCache_premiumSharded(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRedisCache_premiumShardedScaling(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMRedisCache_premiumSharded(ri, acceptance.Location()) - config_scaled := testAccAzureRMRedisCache_premiumShardedScaled(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -244,15 +122,15 @@ func TestAccAzureRMRedisCache_premiumShardedScaling(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCache_premiumSharded(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, { - Config: config_scaled, + Config: testAccAzureRMRedisCache_premiumShardedScaled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, }, @@ -260,9 +138,7 @@ func TestAccAzureRMRedisCache_premiumShardedScaling(t *testing.T) { } func TestAccAzureRMRedisCache_NonStandardCasing(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMRedisCacheNonStandardCasing(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -270,14 +146,13 @@ func TestAccAzureRMRedisCache_NonStandardCasing(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCacheNonStandardCasing(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, - { - Config: config, + Config: testAccAzureRMRedisCacheNonStandardCasing(data), PlanOnly: true, ExpectNonEmptyPlan: false, }, @@ -286,9 +161,7 @@ func TestAccAzureRMRedisCache_NonStandardCasing(t *testing.T) { } func TestAccAzureRMRedisCache_BackupDisabled(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMRedisCacheBackupDisabled(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -296,9 +169,9 @@ func TestAccAzureRMRedisCache_BackupDisabled(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCacheBackupDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, }, @@ -306,10 +179,7 @@ func TestAccAzureRMRedisCache_BackupDisabled(t *testing.T) { } func TestAccAzureRMRedisCache_BackupEnabled(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - config := testAccAzureRMRedisCacheBackupEnabled(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -317,9 +187,9 @@ func TestAccAzureRMRedisCache_BackupEnabled(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCacheBackupEnabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), // `redis_configuration.0.rdb_storage_connection_string` is returned as: // "...;AccountKey=[key hidden]" rather than "...;AccountKey=fsjfvjnfnf" @@ -327,23 +197,13 @@ func TestAccAzureRMRedisCache_BackupEnabled(t *testing.T) { // https://github.com/Azure/azure-rest-api-specs/issues/3037 ExpectNonEmptyPlan: true, }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"redis_configuration.0.rdb_storage_connection_string"}, - }, + data.ImportStep("redis_configuration.0.rdb_storage_connection_string"), }, }) } func TestAccAzureRMRedisCache_BackupEnabledDisabled(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - config := testAccAzureRMRedisCacheBackupEnabled(ri, rs, location) - updatedConfig := testAccAzureRMRedisCacheBackupDisabled(ri, location) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -351,9 +211,9 @@ func TestAccAzureRMRedisCache_BackupEnabledDisabled(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCacheBackupEnabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), // `redis_configuration.0.rdb_storage_connection_string` is returned as: // "...;AccountKey=[key hidden]" rather than "...;AccountKey=fsjfvjnfnf" @@ -362,9 +222,9 @@ func TestAccAzureRMRedisCache_BackupEnabledDisabled(t *testing.T) { ExpectNonEmptyPlan: true, }, { - Config: updatedConfig, + Config: testAccAzureRMRedisCacheBackupDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), // `redis_configuration.0.rdb_storage_connection_string` is returned as: // "...;AccountKey=[key hidden]" rather than "...;AccountKey=fsjfvjnfnf" @@ -377,10 +237,7 @@ func TestAccAzureRMRedisCache_BackupEnabledDisabled(t *testing.T) { } func TestAccAzureRMRedisCache_AOFBackupEnabled(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - config := testAccAzureRMRedisCacheAOFBackupEnabled(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -388,29 +245,20 @@ func TestAccAzureRMRedisCache_AOFBackupEnabled(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCacheAOFBackupEnabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), ExpectNonEmptyPlan: true, }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"redis_configuration.0.aof_storage_connection_string_0", "redis_configuration.0.aof_storage_connection_string_1"}, - }, + data.ImportStep("redis_configuration.0.aof_storage_connection_string_0", + "redis_configuration.0.aof_storage_connection_string_1"), }, }) } func TestAccAzureRMRedisCache_AOFBackupEnabledDisabled(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - config := testAccAzureRMRedisCacheAOFBackupEnabled(ri, rs, location) - updatedConfig := testAccAzureRMRedisCacheAOFBackupDisabled(ri, location) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -418,16 +266,16 @@ func TestAccAzureRMRedisCache_AOFBackupEnabledDisabled(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCacheAOFBackupEnabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), ExpectNonEmptyPlan: true, }, { - Config: updatedConfig, + Config: testAccAzureRMRedisCacheAOFBackupDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -435,10 +283,7 @@ func TestAccAzureRMRedisCache_AOFBackupEnabledDisabled(t *testing.T) { }) } func TestAccAzureRMRedisCache_PatchSchedule(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMRedisCachePatchSchedule(ri, location) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -446,26 +291,18 @@ func TestAccAzureRMRedisCache_PatchSchedule(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCachePatchSchedule(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRedisCache_PatchScheduleUpdated(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMRedisCachePatchSchedule(ri, location) - updatedConfig := testAccAzureRMRedisCache_premium(ri, location) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -473,15 +310,15 @@ func TestAccAzureRMRedisCache_PatchScheduleUpdated(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCachePatchSchedule(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, { - Config: updatedConfig, + Config: testAccAzureRMRedisCache_premium(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, }, @@ -489,9 +326,7 @@ func TestAccAzureRMRedisCache_PatchScheduleUpdated(t *testing.T) { } func TestAccAzureRMRedisCache_InternalSubnet(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMRedisCache_internalSubnet(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -499,24 +334,18 @@ func TestAccAzureRMRedisCache_InternalSubnet(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCache_internalSubnet(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRedisCache_InternalSubnetStaticIP(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMRedisCache_internalSubnetStaticIP(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -524,25 +353,18 @@ func TestAccAzureRMRedisCache_InternalSubnetStaticIP(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCache_internalSubnetStaticIP(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), + testCheckAzureRMRedisCacheExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRedisCache_InternalSubnet_withZone(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - - config := testAccAzureRMRedisCache_internalSubnet_withZone(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -550,22 +372,54 @@ func TestAccAzureRMRedisCache_InternalSubnet_withZone(t *testing.T) { CheckDestroy: testCheckAzureRMRedisCacheDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisCache_internalSubnet_withZone(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "zones.#", "1"), - resource.TestCheckResourceAttr(resourceName, "zones.0", "1"), + testCheckAzureRMRedisCacheExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "zones.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.0", "1"), ), }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMRedisCache_SubscribeAllEvents(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMRedisCacheDestroy, + Steps: []resource.TestStep{ { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMRedisCacheSubscribeAllEvents(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMRedisCacheExists(data.ResourceName), + ), }, }, }) } +func TestAccAzureRMRedisCache_WithoutAuth(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_redis_cache", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMRedisCacheDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMRedisCacheWithoutAuth(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMRedisCacheExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "redis_configuration.0.enable_authentication", "false"), + ), + }, + }, + }) +} func testCheckAzureRMRedisCacheExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { // Ensure we have enough information in state to look up in API @@ -622,49 +476,7 @@ func testCheckAzureRMRedisCacheDestroy(s *terraform.State) error { return nil } -func TestAccAzureRMRedisCache_SubscribeAllEvents(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - config := testAccAzureRMRedisCacheSubscribeAllEvents(ri, rs, acceptance.Location()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRedisCacheDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), - ), - }, - }, - }) -} - -func TestAccAzureRMRedisCache_WithoutAuth(t *testing.T) { - resourceName := "azurerm_redis_cache.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMRedisCacheWithoutAuth(ri, acceptance.Location()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRedisCacheDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisCacheExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "redis_configuration.0.enable_authentication", "false"), - ), - }, - }, - }) -} - -func testAccAzureRMRedisCache_basic(rInt int, location string) string { +func testAccAzureRMRedisCache_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -683,10 +495,11 @@ resource "azurerm_redis_cache" "test" { redis_configuration {} } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRedisCache_requiresImport(rInt int, location string) string { +func testAccAzureRMRedisCache_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMRedisCache_basic(data) return fmt.Sprintf(` %s @@ -701,10 +514,10 @@ resource "azurerm_redis_cache" "import" { redis_configuration {} } -`, testAccAzureRMRedisCache_basic(rInt, location)) +`, template) } -func testAccAzureRMRedisCache_standard(rInt int, location string) string { +func testAccAzureRMRedisCache_standard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -725,10 +538,10 @@ resource "azurerm_redis_cache" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRedisCache_premium(rInt int, location string) string { +func testAccAzureRMRedisCache_premium(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -751,10 +564,10 @@ resource "azurerm_redis_cache" "test" { maxmemory_policy = "allkeys-lru" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRedisCache_premiumSharded(rInt int, location string) string { +func testAccAzureRMRedisCache_premiumSharded(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -778,10 +591,10 @@ resource "azurerm_redis_cache" "test" { maxmemory_policy = "allkeys-lru" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRedisCache_premiumShardedScaled(rInt int, location string) string { +func testAccAzureRMRedisCache_premiumShardedScaled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -805,10 +618,10 @@ resource "azurerm_redis_cache" "test" { maxmemory_policy = "allkeys-lru" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRedisCacheNonStandardCasing(ri int, location string) string { +func testAccAzureRMRedisCacheNonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -825,10 +638,10 @@ resource "azurerm_redis_cache" "test" { enable_non_ssl_port = false redis_configuration {} } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRedisCacheBackupDisabled(ri int, location string) string { +func testAccAzureRMRedisCacheBackupDisabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -848,10 +661,10 @@ resource "azurerm_redis_cache" "test" { rdb_backup_enabled = false } } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRedisCacheBackupEnabled(rInt int, rString string, location string) string { +func testAccAzureRMRedisCacheBackupEnabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -886,10 +699,10 @@ resource "azurerm_redis_cache" "test" { rdb_storage_connection_string = "DefaultEndpointsProtocol=https;BlobEndpoint=${azurerm_storage_account.test.primary_blob_endpoint};AccountName=${azurerm_storage_account.test.name};AccountKey=${azurerm_storage_account.test.primary_access_key}" } } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMRedisCacheAOFBackupDisabled(ri int, location string) string { +func testAccAzureRMRedisCacheAOFBackupDisabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -909,10 +722,10 @@ resource "azurerm_redis_cache" "test" { aof_backup_enabled = false } } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRedisCacheAOFBackupEnabled(rInt int, rString string, location string) string { +func testAccAzureRMRedisCacheAOFBackupEnabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -946,10 +759,10 @@ resource "azurerm_redis_cache" "test" { aof_storage_connection_string_1 = "DefaultEndpointsProtocol=https;BlobEndpoint=${azurerm_storage_account.test.primary_blob_endpoint};AccountName=${azurerm_storage_account.test.name};AccountKey=${azurerm_storage_account.test.secondary_access_key}" } } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMRedisCachePatchSchedule(rInt int, location string) string { +func testAccAzureRMRedisCachePatchSchedule(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -976,10 +789,10 @@ resource "azurerm_redis_cache" "test" { start_hour_utc = 8 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRedisCacheSubscribeAllEvents(rInt int, rString string, location string) string { +func testAccAzureRMRedisCacheSubscribeAllEvents(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1011,9 +824,10 @@ resource "azurerm_redis_cache" "test" { notify_keyspace_events = "KAE" } } -`, rInt, location, rString, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMRedisCache_internalSubnet(ri int, location string) string { + +func testAccAzureRMRedisCache_internalSubnet(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1045,10 +859,10 @@ resource "azurerm_redis_cache" "test" { subnet_id = "${azurerm_subnet.test.id}" redis_configuration {} } -`, ri, location, ri, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRedisCache_internalSubnetStaticIP(ri int, location string) string { +func testAccAzureRMRedisCache_internalSubnetStaticIP(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1081,10 +895,10 @@ resource "azurerm_redis_cache" "test" { private_static_ip_address = "10.0.1.20" redis_configuration {} } -`, ri, location, ri, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRedisCache_internalSubnet_withZone(ri int, location string) string { +func testAccAzureRMRedisCache_internalSubnet_withZone(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1117,10 +931,10 @@ resource "azurerm_redis_cache" "test" { redis_configuration {} zones = ["1"] } -`, ri, location, ri, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRedisCacheWithoutAuth(ri int, location string) string { +func testAccAzureRMRedisCacheWithoutAuth(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1154,5 +968,5 @@ resource "azurerm_redis_cache" "test" { enable_authentication = false } } -`, ri, location, ri, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/redis/resource_arm_redis_firewall_rule_test.go b/azurerm/internal/services/redis/tests/resource_arm_redis_firewall_rule_test.go similarity index 70% rename from azurerm/internal/services/redis/resource_arm_redis_firewall_rule_test.go rename to azurerm/internal/services/redis/tests/resource_arm_redis_firewall_rule_test.go index 6d3cea5908d9..dd22a942b204 100644 --- a/azurerm/internal/services/redis/resource_arm_redis_firewall_rule_test.go +++ b/azurerm/internal/services/redis/tests/resource_arm_redis_firewall_rule_test.go @@ -1,4 +1,4 @@ -package redis +package tests import ( "fmt" @@ -7,56 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAzureRMRedisFirewallRuleName_validation(t *testing.T) { - cases := []struct { - Value string - ErrCount int - }{ - { - Value: "ab", - ErrCount: 0, - }, - { - Value: "abc", - ErrCount: 0, - }, - { - Value: "webapp1", - ErrCount: 0, - }, - { - Value: "hello-world", - ErrCount: 1, - }, - { - Value: "hello_world", - ErrCount: 0, - }, - { - Value: "helloworld21!", - ErrCount: 1, - }, - } - - for _, tc := range cases { - _, errors := validateRedisFirewallRuleName(tc.Value, "azurerm_redis_firewall_rule") - - if len(errors) != tc.ErrCount { - t.Fatalf("Expected the Redis Firewall Rule Name to trigger a validation error for '%s'", tc.Value) - } - } -} - func TestAccAzureRMRedisFirewallRule_basic(t *testing.T) { - resourceName := "azurerm_redis_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_redis_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -64,24 +22,19 @@ func TestAccAzureRMRedisFirewallRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRedisFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRedisFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMRedisFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisFirewallRuleExists(resourceName), + testCheckAzureRMRedisFirewallRuleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRedisFirewallRule_multi(t *testing.T) { - ruleOne := "azurerm_redis_firewall_rule.test" + data := acceptance.BuildTestData(t, "azurerm_redis_firewall_rule", "test") ruleTwo := "azurerm_redis_firewall_rule.double" - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -89,17 +42,13 @@ func TestAccAzureRMRedisFirewallRule_multi(t *testing.T) { CheckDestroy: testCheckAzureRMRedisFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRedisFirewallRule_multi(ri, acceptance.Location()), + Config: testAccAzureRMRedisFirewallRule_multi(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisFirewallRuleExists(ruleOne), + testCheckAzureRMRedisFirewallRuleExists(data.ResourceName), testCheckAzureRMRedisFirewallRuleExists(ruleTwo), ), }, - { - ResourceName: ruleOne, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { ResourceName: ruleTwo, ImportState: true, @@ -115,33 +64,25 @@ func TestAccAzureRMRedisFirewallRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_redis_firewall_rule.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_redis_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMRedisFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRedisFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMRedisFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisFirewallRuleExists(resourceName), + testCheckAzureRMRedisFirewallRuleExists(data.ResourceName), ), }, - { - Config: testAccAzureRMRedisFirewallRule_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_redis_firewall_rule"), - }, + data.RequiresImportErrorStep(testAccAzureRMRedisFirewallRule_requiresImport), }, }) } func TestAccAzureRMRedisFirewallRule_update(t *testing.T) { - resourceName := "azurerm_redis_firewall_rule.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMRedisFirewallRule_basic(ri, acceptance.Location()) - updatedConfig := testAccAzureRMRedisFirewallRule_update(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_redis_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -149,15 +90,15 @@ func TestAccAzureRMRedisFirewallRule_update(t *testing.T) { CheckDestroy: testCheckAzureRMRedisFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRedisFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisFirewallRuleExists(resourceName), + testCheckAzureRMRedisFirewallRuleExists(data.ResourceName), ), }, { - Config: updatedConfig, + Config: testAccAzureRMRedisFirewallRule_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRedisFirewallRuleExists(resourceName), + testCheckAzureRMRedisFirewallRuleExists(data.ResourceName), ), }, }, @@ -214,7 +155,7 @@ func testCheckAzureRMRedisFirewallRuleDestroy(s *terraform.State) error { return nil } -func testAccAzureRMRedisFirewallRule_basic(rInt int, location string) string { +func testAccAzureRMRedisFirewallRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -244,10 +185,11 @@ resource "azurerm_redis_firewall_rule" "test" { start_ip = "1.2.3.4" end_ip = "2.3.4.5" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRedisFirewallRule_multi(rInt int, location string) string { +func testAccAzureRMRedisFirewallRule_multi(data acceptance.TestData) string { + template := testAccAzureRMRedisFirewallRule_basic(data) return fmt.Sprintf(` %s @@ -258,10 +200,11 @@ resource "azurerm_redis_firewall_rule" "double" { start_ip = "4.5.6.7" end_ip = "8.9.0.1" } -`, testAccAzureRMRedisFirewallRule_basic(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMRedisFirewallRule_requiresImport(rInt int, location string) string { +func testAccAzureRMRedisFirewallRule_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMRedisFirewallRule_basic(data) return fmt.Sprintf(` %s @@ -272,10 +215,10 @@ resource "azurerm_redis_firewall_rule" "import" { start_ip = "${azurerm_redis_firewall_rule.test.start_ip}" end_ip = "${azurerm_redis_firewall_rule.test.end_ip}" } -`, testAccAzureRMRedisFirewallRule_basic(rInt, location)) +`, template) } -func testAccAzureRMRedisFirewallRule_update(rInt int, location string) string { +func testAccAzureRMRedisFirewallRule_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -305,5 +248,5 @@ resource "azurerm_redis_firewall_rule" "test" { start_ip = "2.3.4.5" end_ip = "6.7.8.9" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/redis/validation_test.go b/azurerm/internal/services/redis/validation_test.go new file mode 100644 index 000000000000..769c5e58ea15 --- /dev/null +++ b/azurerm/internal/services/redis/validation_test.go @@ -0,0 +1,136 @@ +package redis + +import "testing" + +func TestAccAzureRMRedisCacheFamily_validation(t *testing.T) { + cases := []struct { + Value string + ErrCount int + }{ + { + Value: "C", + ErrCount: 0, + }, + { + Value: "P", + ErrCount: 0, + }, + { + Value: "c", + ErrCount: 0, + }, + { + Value: "p", + ErrCount: 0, + }, + { + Value: "a", + ErrCount: 1, + }, + { + Value: "b", + ErrCount: 1, + }, + { + Value: "D", + ErrCount: 1, + }, + } + + for _, tc := range cases { + _, errors := validateRedisFamily(tc.Value, "azurerm_redis_cache") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the Azure RM Redis Cache Family to trigger a validation error") + } + } +} + +func TestAccAzureRMRedisCacheMaxMemoryPolicy_validation(t *testing.T) { + cases := []struct { + Value string + ErrCount int + }{ + {Value: "noeviction", ErrCount: 0}, + {Value: "allkeys-lru", ErrCount: 0}, + {Value: "volatile-lru", ErrCount: 0}, + {Value: "allkeys-random", ErrCount: 0}, + {Value: "volatile-random", ErrCount: 0}, + {Value: "volatile-ttl", ErrCount: 0}, + {Value: "something-else", ErrCount: 1}, + } + + for _, tc := range cases { + _, errors := validateRedisMaxMemoryPolicy(tc.Value, "azurerm_redis_cache") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the Azure RM Redis Cache Max Memory Policy to trigger a validation error") + } + } +} + +func TestAccAzureRMRedisCacheBackupFrequency_validation(t *testing.T) { + cases := []struct { + Value int + ErrCount int + }{ + {Value: 1, ErrCount: 1}, + {Value: 15, ErrCount: 0}, + {Value: 30, ErrCount: 0}, + {Value: 45, ErrCount: 1}, + {Value: 60, ErrCount: 0}, + {Value: 120, ErrCount: 1}, + {Value: 240, ErrCount: 1}, + {Value: 360, ErrCount: 0}, + {Value: 720, ErrCount: 0}, + {Value: 1440, ErrCount: 0}, + } + + for _, tc := range cases { + _, errors := validateRedisBackupFrequency(tc.Value, "azurerm_redis_cache") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the AzureRM Redis Cache Backup Frequency to trigger a validation error for '%d'", tc.Value) + } + } +} + +func TestAzureRMRedisFirewallRuleName_validation(t *testing.T) { + cases := []struct { + Value string + ErrCount int + }{ + { + Value: "ab", + ErrCount: 0, + }, + { + Value: "abc", + ErrCount: 0, + }, + { + Value: "webapp1", + ErrCount: 0, + }, + { + Value: "hello-world", + ErrCount: 1, + }, + { + Value: "hello_world", + ErrCount: 0, + }, + { + Value: "helloworld21!", + ErrCount: 1, + }, + } + + for _, tc := range cases { + _, errors := validateRedisFirewallRuleName(tc.Value, "azurerm_redis_firewall_rule") + + if len(errors) != tc.ErrCount { + t.Fatalf("Expected the Redis Firewall Rule Name to trigger a validation error for '%s'", tc.Value) + } + } +} From e3475143259d24ca2ec1bfa2257aa2da3257894f Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 13:32:32 +0100 Subject: [PATCH 119/203] recoveryservices: fixing the tests --- ...ata_source_recovery_services_vault_test.go | 45 ---- ...very_services_protection_policy_vm_test.go | 23 +-- ...ata_source_recovery_services_vault_test.go | 43 ++++ ...m_backup_container_storage_account_test.go | 22 +- ...ource_arm_backup_policy_file_share_test.go | 77 +++---- .../resource_arm_backup_policy_vm_test.go | 195 +++++++----------- ...ce_arm_backup_protected_file_share_test.go | 70 +++---- .../resource_arm_backup_protected_vm_test.go | 180 ++++++++-------- ...ource_arm_recovery_services_fabric_test.go | 20 +- ..._recovery_services_network_mapping_test.go | 20 +- ...arm_recovery_services_protected_vm_test.go | 180 ++++++++-------- ...vices_protection_container_mapping_test.go | 20 +- ...very_services_protection_container_test.go | 20 +- ...very_services_protection_policy_vm_test.go | 195 +++++++----------- ...rm_recovery_services_replicated_vm_test.go | 20 +- ...covery_services_replication_policy_test.go | 20 +- ...source_arm_recovery_services_vault_test.go | 57 +++-- .../resource_arm_site_recovery_fabric_test.go | 20 +- ..._arm_site_recovery_network_mapping_test.go | 20 +- ...overy_protection_container_mapping_test.go | 20 +- ...site_recovery_protection_container_test.go | 20 +- ...ce_arm_site_recovery_replicated_vm_test.go | 20 +- ...m_site_recovery_replication_policy_test.go | 20 +- 23 files changed, 551 insertions(+), 776 deletions(-) delete mode 100644 azurerm/internal/services/recoveryservices/data_source_recovery_services_vault_test.go rename azurerm/internal/services/recoveryservices/{ => tests}/data_source_recovery_services_protection_policy_vm_test.go (56%) create mode 100644 azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_vault_test.go rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_backup_container_storage_account_test.go (90%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_backup_policy_file_share_test.go (79%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_backup_policy_vm_test.go (77%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_backup_protected_file_share_test.go (80%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_backup_protected_vm_test.go (78%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_recovery_services_fabric_test.go (85%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_recovery_services_network_mapping_test.go (89%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_recovery_services_protected_vm_test.go (79%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_recovery_services_protection_container_mapping_test.go (90%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_recovery_services_protection_container_test.go (86%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_recovery_services_protection_policy_vm_test.go (81%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_recovery_services_replicated_vm_test.go (92%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_recovery_services_replication_policy_test.go (85%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_recovery_services_vault_test.go (68%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_site_recovery_fabric_test.go (85%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_site_recovery_network_mapping_test.go (89%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_site_recovery_protection_container_mapping_test.go (92%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_site_recovery_protection_container_test.go (87%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_site_recovery_replicated_vm_test.go (92%) rename azurerm/internal/services/recoveryservices/{ => tests}/resource_arm_site_recovery_replication_policy_test.go (85%) diff --git a/azurerm/internal/services/recoveryservices/data_source_recovery_services_vault_test.go b/azurerm/internal/services/recoveryservices/data_source_recovery_services_vault_test.go deleted file mode 100644 index 7d8e08f3ea16..000000000000 --- a/azurerm/internal/services/recoveryservices/data_source_recovery_services_vault_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package recoveryservices - -import ( - "fmt" - "testing" - - "github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-01/recoveryservices" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMRecoveryServicesVault_basic(t *testing.T) { - dataSourceName := "data.azurerm_recovery_services_vault.test" - ri := tf.AccRandTimeInt() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceRecoveryServicesVault_basic(ri, acceptance.Location()), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesVaultExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - resource.TestCheckResourceAttr(dataSourceName, "sku", string(recoveryservices.Standard)), - ), - }, - }, - }) -} - -func testAccDataSourceRecoveryServicesVault_basic(rInt int, location string) string { - return fmt.Sprintf(` -%s - -data "azurerm_recovery_services_vault" "test" { - name = "${azurerm_recovery_services_vault.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, testAccAzureRMRecoveryServicesVault_basic(rInt, location)) -} diff --git a/azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm_test.go b/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_protection_policy_vm_test.go similarity index 56% rename from azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm_test.go rename to azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_protection_policy_vm_test.go index c2678cf3a60b..03af8b3759ef 100644 --- a/azurerm/internal/services/recoveryservices/data_source_recovery_services_protection_policy_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_protection_policy_vm_test.go @@ -1,37 +1,36 @@ -package recoveryservices +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMRecoveryServicesProtectionPolicyVm_basic(t *testing.T) { - dataSourceName := "data.azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_recovery_services_protection_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceRecoveryServicesProtectionPolicyVm_basic(ri, acceptance.Location()), + Config: testAccDataSourceRecoveryServicesProtectionPolicyVm_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "recovery_vault_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "recovery_vault_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, }) } -func testAccDataSourceRecoveryServicesProtectionPolicyVm_basic(rInt int, location string) string { +func testAccDataSourceRecoveryServicesProtectionPolicyVm_basic(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data) return fmt.Sprintf(` %s @@ -40,5 +39,5 @@ data "azurerm_recovery_services_protection_policy_vm" "test" { recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(rInt, location)) +`, template) } diff --git a/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_vault_test.go b/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_vault_test.go new file mode 100644 index 000000000000..0a6bae126319 --- /dev/null +++ b/azurerm/internal/services/recoveryservices/tests/data_source_recovery_services_vault_test.go @@ -0,0 +1,43 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMRecoveryServicesVault_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_recovery_services_vault", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceRecoveryServicesVault_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMRecoveryServicesVaultExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), + ), + }, + }, + }) +} + +func testAccDataSourceRecoveryServicesVault_basic(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesVault_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_recovery_services_vault" "test" { + name = "${azurerm_recovery_services_vault.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template) +} diff --git a/azurerm/internal/services/recoveryservices/resource_arm_backup_container_storage_account_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_container_storage_account_test.go similarity index 90% rename from azurerm/internal/services/recoveryservices/resource_arm_backup_container_storage_account_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_backup_container_storage_account_test.go index 691e56e36b8e..a60156c06319 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_backup_container_storage_account_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_container_storage_account_test.go @@ -1,23 +1,19 @@ -package recoveryservices +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMBackupProtectionContainerStorageAccount_basic(t *testing.T) { - resourceName := "azurerm_backup_container_storage_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_backup_container_storage_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,21 +21,17 @@ func TestAccAzureRMBackupProtectionContainerStorageAccount_basic(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectionContainerStorageAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionContainerStorageAccount_basic(ri, rs, acceptance.Location()), + Config: testAccAzureRMBackupProtectionContainerStorageAccount_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBackupProtectionContainerStorageAccountExists(resourceName), + testCheckAzureRMBackupProtectionContainerStorageAccountExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMBackupProtectionContainerStorageAccount_basic(rInt int, rString string, location string) string { +func testAccAzureRMBackupProtectionContainerStorageAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "testrg" { name = "acctestRG-backup-%d" @@ -67,7 +59,7 @@ resource "azurerm_backup_container_storage_account" "test" { recovery_vault_name = "${azurerm_recovery_services_vault.testvlt.name}" storage_account_id = "${azurerm_storage_account.testsa.id}" } -`, rInt, location, rInt, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString) } func testCheckAzureRMBackupProtectionContainerStorageAccountExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_file_share_test.go similarity index 79% rename from azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_file_share_test.go index 9c46e43e45c5..a212d4b91005 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_file_share_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_file_share_test.go @@ -1,13 +1,11 @@ -package recoveryservices +package tests import ( "fmt" - "strconv" "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/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +13,7 @@ import ( ) func TestAccAzureRMBackupProtectionPolicyFileShare_basicDaily(t *testing.T) { - resourceName := "azurerm_backup_policy_file_share.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_file_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,14 +21,10 @@ func TestAccAzureRMBackupProtectionPolicyFileShare_basicDaily(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectionPolicyFileShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyFileShare_basicDaily(resourceName, ri), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyFileShare_basicDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } @@ -42,8 +35,7 @@ func TestAccAzureRMBackupProtectionPolicyFileShare_requiresImport(t *testing.T) return } - resourceName := "azurerm_backup_policy_file_share.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_file_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,20 +43,16 @@ func TestAccAzureRMBackupProtectionPolicyFileShare_requiresImport(t *testing.T) CheckDestroy: testCheckAzureRMBackupProtectionPolicyFileShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyFileShare_basicDaily(resourceName, ri), - }, - { - Config: testAccAzureRMBackupProtectionPolicyFileShare_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_backup_policy_file_share"), + Config: testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyFileShare_basicDaily(data.ResourceName, data.RandomInteger), }, + data.RequiresImportErrorStep(testAccAzureRMBackupProtectionPolicyFileShare_requiresImport), }, }) } func TestAccAzureRMBackupProtectionPolicyFileShare_updateDaily(t *testing.T) { - resourceName := "azurerm_backup_policy_file_share.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_file_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -72,23 +60,15 @@ func TestAccAzureRMBackupProtectionPolicyFileShare_updateDaily(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectionPolicyFileShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyFileShare_basicDaily(resourceName, ri), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMBackupProtectionPolicyFileShare_updateDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyFileShare_updateDaily(resourceName, ri), + Config: testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyFileShare_basicDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyFileShare_updateDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyFileShare_updateDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } @@ -152,23 +132,24 @@ func testCheckAzureRMBackupProtectionPolicyFileShareExists(resourceName string) } } -func testAccAzureRMBackupProtectionPolicyFileShare_base(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyFileShare_base(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-backup-%[1]d" - location = "%[2]s" + name = "acctestRG-backup-%d" + location = "%s" } resource "azurerm_recovery_services_vault" "test" { - name = "acctest-RSV-%[1]d" + name = "acctest-RSV-%s" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } -`, rInt, location, strconv.Itoa(rInt)[12:17]) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectionPolicyFileShare_base(data) return fmt.Sprintf(` %s @@ -186,10 +167,11 @@ resource "azurerm_backup_policy_file_share" "test" { count = 10 } } -`, testAccAzureRMBackupProtectionPolicyFileShare_base(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMBackupProtectionPolicyFileShare_updateDaily(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyFileShare_updateDaily(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectionPolicyFileShare_base(data) return fmt.Sprintf(` %s @@ -207,10 +189,11 @@ resource "azurerm_backup_policy_file_share" "test" { count = 180 } } -`, testAccAzureRMBackupProtectionPolicyFileShare_base(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMBackupProtectionPolicyFileShare_requiresImport(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyFileShare_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(data) return fmt.Sprintf(` %s @@ -228,7 +211,7 @@ resource "azurerm_backup_policy_file_share" "import" { count = 10 } } -`, testAccAzureRMBackupProtectionPolicyFileShare_basicDaily(rInt, location)) +`, template) } func checkAccAzureRMBackupProtectionPolicyFileShare_basicDaily(resourceName string, ri int) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go similarity index 77% rename from azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go index 2cdae67211fd..00f32459ed68 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_backup_policy_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go @@ -1,13 +1,11 @@ -package recoveryservices +package tests import ( "fmt" - "strconv" "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/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +13,7 @@ import ( ) func TestAccAzureRMBackupProtectionPolicyVM_basicDaily(t *testing.T) { - resourceName := "azurerm_backup_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,14 +21,10 @@ func TestAccAzureRMBackupProtectionPolicyVM_basicDaily(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(resourceName, ri), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } @@ -42,8 +35,7 @@ func TestAccAzureRMBackupProtectionPolicyVM_requiresImport(t *testing.T) { return } - resourceName := "azurerm_backup_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,20 +43,16 @@ func TestAccAzureRMBackupProtectionPolicyVM_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(resourceName, ri), - }, - { - Config: testAccAzureRMBackupProtectionPolicyVM_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_backup_policy_vm"), + Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(data.ResourceName, data.RandomInteger), }, + data.RequiresImportErrorStep(testAccAzureRMBackupProtectionPolicyVM_requiresImport), }, }) } func TestAccAzureRMBackupProtectionPolicyVM_basicWeekly(t *testing.T) { - resourceName := "azurerm_backup_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -72,21 +60,16 @@ func TestAccAzureRMBackupProtectionPolicyVM_basicWeekly(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(resourceName, ri), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMBackupProtectionPolicyVM_completeDaily(t *testing.T) { - resourceName := "azurerm_backup_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -94,21 +77,16 @@ func TestAccAzureRMBackupProtectionPolicyVM_completeDaily(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyVM_completeDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeDaily(resourceName, ri), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyVM_completeDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_completeDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMBackupProtectionPolicyVM_completeWeekly(t *testing.T) { - resourceName := "azurerm_backup_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -116,21 +94,16 @@ func TestAccAzureRMBackupProtectionPolicyVM_completeWeekly(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyVM_completeWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(resourceName, ri), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyVM_completeWeekly(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMBackupProtectionPolicyVM_updateDaily(t *testing.T) { - resourceName := "azurerm_backup_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -138,25 +111,20 @@ func TestAccAzureRMBackupProtectionPolicyVM_updateDaily(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(resourceName, ri), - }, - { - Config: testAccAzureRMBackupProtectionPolicyVM_completeDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeDaily(resourceName, ri), + Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(data.ResourceName, data.RandomInteger), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyVM_completeDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_completeDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMBackupProtectionPolicyVM_updateWeekly(t *testing.T) { - resourceName := "azurerm_backup_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -164,75 +132,62 @@ func TestAccAzureRMBackupProtectionPolicyVM_updateWeekly(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(resourceName, ri), - }, - { - Config: testAccAzureRMBackupProtectionPolicyVM_completeWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(resourceName, ri), + Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(data.ResourceName, data.RandomInteger), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyVM_completeWeekly(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMBackupProtectionPolicyVM_updateDailyToWeekly(t *testing.T) { - resourceName := "azurerm_backup_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_vm", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMBackupProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(resourceName, ri), - }, - { - Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(resourceName, ri), + Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(data.ResourceName, data.RandomInteger), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMBackupProtectionPolicyVM_updateWeeklyToDaily(t *testing.T) { - resourceName := "azurerm_backup_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_vm", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMBackupProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(resourceName, ri), - }, - { - Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(resourceName, ri), + Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(data.ResourceName, data.RandomInteger), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMBackupProtectionPolicyVM_updateWeeklyToPartial(t *testing.T) { - resourceName := "azurerm_backup_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -240,18 +195,14 @@ func TestAccAzureRMBackupProtectionPolicyVM_updateWeeklyToPartial(t *testing.T) CheckDestroy: testCheckAzureRMBackupProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectionPolicyVM_completeWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(resourceName, ri), - }, - { - Config: testAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(ri, acceptance.Location()), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(resourceName, ri), + Config: testAccAzureRMBackupProtectionPolicyVM_completeWeekly(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(data.ResourceName, data.RandomInteger), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(data), + Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } @@ -315,23 +266,24 @@ func testCheckAzureRMBackupProtectionPolicyVmExists(resourceName string) resourc } } -func testAccAzureRMBackupProtectionPolicyVM_base(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyVM_base(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" - location = "%[2]s" + name = "acctestRG-%d" + location = "%s" } resource "azurerm_recovery_services_vault" "test" { - name = "acctest-%[1]d" + name = "acctest-%s" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } -`, rInt, location, strconv.Itoa(rInt)[12:17]) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMBackupProtectionPolicyVM_basicDaily(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyVM_basicDaily(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectionPolicyVM_base(data) return fmt.Sprintf(` %s @@ -349,10 +301,11 @@ resource "azurerm_backup_policy_vm" "test" { count = 10 } } -`, testAccAzureRMBackupProtectionPolicyVM_base(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMBackupProtectionPolicyVM_requiresImport(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyVM_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectionPolicyVM_basicDaily(data) return fmt.Sprintf(` %s @@ -370,7 +323,7 @@ resource "azurerm_backup_policy_vm" "import" { count = 10 } } -`, testAccAzureRMBackupProtectionPolicyVM_basicDaily(rInt, location)) +`, template) } func checkAccAzureRMBackupProtectionPolicyVM_basicDaily(resourceName string, ri int) resource.TestCheckFunc { @@ -385,7 +338,8 @@ func checkAccAzureRMBackupProtectionPolicyVM_basicDaily(resourceName string, ri ) } -func testAccAzureRMBackupProtectionPolicyVM_basicWeekly(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectionPolicyVM_base(data) return fmt.Sprintf(` %s @@ -405,7 +359,7 @@ resource "azurerm_backup_policy_vm" "test" { weekdays = ["Sunday", "Wednesday"] } } -`, testAccAzureRMBackupProtectionPolicyVM_base(rInt, location), rInt) +`, template, data.RandomInteger) } func checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(resourceName string, ri int) resource.TestCheckFunc { @@ -421,7 +375,8 @@ func checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(resourceName string, ri ) } -func testAccAzureRMBackupProtectionPolicyVM_completeDaily(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyVM_completeDaily(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectionPolicyVM_base(data) return fmt.Sprintf(` %s @@ -457,7 +412,7 @@ resource "azurerm_backup_policy_vm" "test" { months = ["January", "July"] } } -`, testAccAzureRMBackupProtectionPolicyVM_base(rInt, location), rInt) +`, template, data.RandomInteger) } func checkAccAzureRMBackupProtectionPolicyVM_completeDaily(resourceName string, ri int) resource.TestCheckFunc { @@ -481,7 +436,8 @@ func checkAccAzureRMBackupProtectionPolicyVM_completeDaily(resourceName string, ) } -func testAccAzureRMBackupProtectionPolicyVM_completeWeekly(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyVM_completeWeekly(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectionPolicyVM_base(data) return fmt.Sprintf(` %s @@ -514,7 +470,7 @@ resource "azurerm_backup_policy_vm" "test" { months = ["January", "July"] } } -`, testAccAzureRMBackupProtectionPolicyVM_base(rInt, location), rInt) +`, template, data.RandomInteger) } func checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(resourceName string, ri int) resource.TestCheckFunc { @@ -538,7 +494,8 @@ func checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(resourceName string, ) } -func testAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(rInt int, location string) string { +func testAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectionPolicyVM_base(data) return fmt.Sprintf(` %s @@ -571,7 +528,7 @@ resource "azurerm_backup_policy_vm" "test" { months = ["January"] } } -`, testAccAzureRMBackupProtectionPolicyVM_base(rInt, location), rInt) +`, template, data.RandomInteger) } func checkAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(resourceName string, ri int) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go similarity index 80% rename from azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go index 849063daad2f..a4dc1fc03830 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_file_share_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_file_share_test.go @@ -1,14 +1,12 @@ -package recoveryservices +package tests import ( "fmt" - "strconv" "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -17,8 +15,7 @@ import ( // TODO: These tests fail because enabling backup on file shares with no content func TestAccAzureRMBackupProtectedFileShare_basic(t *testing.T) { - resourceName := "azurerm_backup_protected_file_share.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_protected_file_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,19 +23,15 @@ func TestAccAzureRMBackupProtectedFileShare_basic(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectedFileShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectedFileShare_basic(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedFileShare_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBackupProtectedFileShareExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), + testCheckAzureRMBackupProtectedFileShareExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMBackupProtectedFileShare_base(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedFileShare_base(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -51,8 +44,7 @@ func TestAccAzureRMBackupProtectedFileShare_requiresImport(t *testing.T) { return } - resourceName := "azurerm_backup_protected_file_share.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_protected_file_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -60,18 +52,15 @@ func TestAccAzureRMBackupProtectedFileShare_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectedFileShareDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectedFileShare_basic(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedFileShare_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBackupProtectedFileShareExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), + testCheckAzureRMBackupProtectedFileShareExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), ), }, - { - Config: testAccAzureRMBackupProtectedFileShare_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_backup_protected_file_share"), - }, + data.RequiresImportErrorStep(testAccAzureRMBackupProtectedFileShare_requiresImport), { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMBackupProtectedFileShare_base(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedFileShare_base(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -79,11 +68,10 @@ func TestAccAzureRMBackupProtectedFileShare_requiresImport(t *testing.T) { } func TestAccAzureRMBackupProtectedFileShare_updateBackupPolicyId(t *testing.T) { - protectedFileShareResourceName := "azurerm_backup_protected_file_share.test" fBackupPolicyResourceName := "azurerm_backup_policy_file_share.test1" sBackupPolicyResourceName := "azurerm_backup_policy_file_share.test2" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_protected_file_share", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -91,20 +79,20 @@ func TestAccAzureRMBackupProtectedFileShare_updateBackupPolicyId(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectedFileShareDestroy, Steps: []resource.TestStep{ { // Create resources and link first backup policy id - Config: testAccAzureRMBackupProtectedFileShare_basic(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedFileShare_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(protectedFileShareResourceName, "backup_policy_id", fBackupPolicyResourceName, "id"), + resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", fBackupPolicyResourceName, "id"), ), }, { // Modify backup policy id to the second one // Set Destroy false to prevent error from cleaning up dangling resource - Config: testAccAzureRMBackupProtectedFileShare_updatePolicy(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedFileShare_updatePolicy(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(protectedFileShareResourceName, "backup_policy_id", sBackupPolicyResourceName, "id"), + resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", sBackupPolicyResourceName, "id"), ), }, { // Remove protected items first before the associated policies are deleted - Config: testAccAzureRMBackupProtectedFileShare_base(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedFileShare_base(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -197,8 +185,7 @@ func testCheckAzureRMBackupProtectedFileShareExists(resourceName string) resourc } } -func testAccAzureRMBackupProtectedFileShare_base(rInt int, location string) string { - rstr := strconv.Itoa(rInt) +func testAccAzureRMBackupProtectedFileShare_base(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-backup-%[1]d" @@ -244,10 +231,11 @@ resource "azurerm_backup_policy_file_share" "test1" { count = 10 } } -`, rInt, location, rstr[len(rstr)-5:]) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMBackupProtectedFileShare_basic(rInt int, location string) string { +func testAccAzureRMBackupProtectedFileShare_basic(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedFileShare_base(data) return fmt.Sprintf(` %s @@ -264,10 +252,11 @@ resource "azurerm_backup_protected_file_share" "test" { source_file_share_name = "${azurerm_storage_share.test.name}" backup_policy_id = "${azurerm_backup_policy_file_share.test1.id}" } -`, testAccAzureRMBackupProtectedFileShare_base(rInt, location)) +`, template) } -func testAccAzureRMBackupProtectedFileShare_updatePolicy(rInt int, location string) string { +func testAccAzureRMBackupProtectedFileShare_updatePolicy(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedFileShare_base(data) return fmt.Sprintf(` %s @@ -299,10 +288,11 @@ resource "azurerm_backup_protected_file_share" "test" { source_file_share_name = "${azurerm_storage_share.test.name}" backup_policy_id = "${azurerm_backup_policy_file_share.test2.id}" } -`, testAccAzureRMBackupProtectedFileShare_base(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMBackupProtectedFileShare_requiresImport(rInt int, location string) string { +func testAccAzureRMBackupProtectedFileShare_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedFileShare_basic(data) return fmt.Sprintf(` %s @@ -313,5 +303,5 @@ resource "azurerm_backup_protected_file_share" "test_import" { source_file_share_name = "${azurerm_storage_share.test.name}" backup_policy_id = "${azurerm_backup_policy_file_share.test1.id}" } -`, testAccAzureRMBackupProtectedFileShare_basic(rInt, location)) +`, template) } diff --git a/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_vm_test.go similarity index 78% rename from azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_vm_test.go index 532943eab0bc..a165aed7c503 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_backup_protected_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_protected_vm_test.go @@ -1,14 +1,12 @@ -package recoveryservices +package tests import ( "fmt" - "strconv" "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +14,7 @@ import ( ) func TestAccAzureRMBackupProtectedVm_basic(t *testing.T) { - resourceName := "azurerm_backup_protected_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_protected_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,19 +22,15 @@ func TestAccAzureRMBackupProtectedVm_basic(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectedVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectedVm_basic(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedVm_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBackupProtectedVmExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), + testCheckAzureRMBackupProtectedVmExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMBackupProtectedVm_base(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedVm_base(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -50,8 +43,7 @@ func TestAccAzureRMBackupProtectedVm_requiresImport(t *testing.T) { return } - resourceName := "azurerm_backup_protected_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_protected_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -59,18 +51,15 @@ func TestAccAzureRMBackupProtectedVm_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectedVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectedVm_basic(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedVm_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBackupProtectedVmExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), + testCheckAzureRMBackupProtectedVmExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), ), }, - { - Config: testAccAzureRMBackupProtectedVm_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_backup_protected_vm"), - }, + data.RequiresImportErrorStep(testAccAzureRMBackupProtectedVm_requiresImport), { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMBackupProtectedVm_base(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedVm_base(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -78,8 +67,7 @@ func TestAccAzureRMBackupProtectedVm_requiresImport(t *testing.T) { } func TestAccAzureRMBackupProtectedVm_separateResourceGroups(t *testing.T) { - resourceName := "azurerm_backup_protected_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_protected_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,19 +75,15 @@ func TestAccAzureRMBackupProtectedVm_separateResourceGroups(t *testing.T) { CheckDestroy: testCheckAzureRMBackupProtectedVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBackupProtectedVm_separateResourceGroups(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedVm_separateResourceGroups(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBackupProtectedVmExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), + testCheckAzureRMBackupProtectedVmExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMBackupProtectedVm_additionalVault(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedVm_additionalVault(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -108,11 +92,9 @@ func TestAccAzureRMBackupProtectedVm_separateResourceGroups(t *testing.T) { func TestAccAzureRMBackupProtectedVm_updateBackupPolicyId(t *testing.T) { virtualMachine := "azurerm_virtual_machine.test" - protectedVmResourceName := "azurerm_backup_protected_vm.test" fBackupPolicyResourceName := "azurerm_backup_policy_vm.test" sBackupPolicyResourceName := "azurerm_backup_policy_vm.test_change_backup" - - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_backup_protected_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -121,34 +103,34 @@ func TestAccAzureRMBackupProtectedVm_updateBackupPolicyId(t *testing.T) { Steps: []resource.TestStep{ { // Create resources and link first backup policy id ResourceName: fBackupPolicyResourceName, - Config: testAccAzureRMBackupProtectedVm_linkFirstBackupPolicy(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedVm_linkFirstBackupPolicy(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(protectedVmResourceName, "backup_policy_id", fBackupPolicyResourceName, "id"), + resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", fBackupPolicyResourceName, "id"), ), }, { // Modify backup policy id to the second one // Set Destroy false to prevent error from cleaning up dangling resource ResourceName: sBackupPolicyResourceName, - Config: testAccAzureRMBackupProtectedVm_linkSecondBackupPolicy(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedVm_linkSecondBackupPolicy(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(protectedVmResourceName, "backup_policy_id", sBackupPolicyResourceName, "id"), + resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", sBackupPolicyResourceName, "id"), ), }, { // Remove backup policy link // Backup policy link will need to be removed first so the VM's backup policy subsequently reverts to Default // Azure API is quite sensitive, adding the step to control resource cleanup order ResourceName: fBackupPolicyResourceName, - Config: testAccAzureRMBackupProtectedVm_withVM(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedVm_withVM(data), Check: resource.ComposeTestCheckFunc(), }, { // Then VM can be removed ResourceName: virtualMachine, - Config: testAccAzureRMBackupProtectedVm_withSecondPolicy(ri, acceptance.Location()), + Config: testAccAzureRMBackupProtectedVm_withSecondPolicy(data), Check: resource.ComposeTestCheckFunc(), }, { // Remove backup policies and vault - ResourceName: protectedVmResourceName, - Config: testAccAzureRMBackupProtectedVm_basePolicyTest(ri, acceptance.Location()), + ResourceName: data.ResourceName, + Config: testAccAzureRMBackupProtectedVm_basePolicyTest(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -240,12 +222,11 @@ func testCheckAzureRMBackupProtectedVmExists(resourceName string) resource.TestC } } -func testAccAzureRMBackupProtectedVm_base(rInt int, location string) string { - rstr := strconv.Itoa(rInt) +func testAccAzureRMBackupProtectedVm_base(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" - location = "%[2]s" + name = "acctestRG-%d" + location = "%s" } resource "azurerm_virtual_network" "test" { @@ -280,11 +261,11 @@ resource "azurerm_public_ip" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" allocation_method = "Dynamic" - domain_name_label = "acctestip%[1]d" + domain_name_label = "acctestip%d" } resource "azurerm_storage_account" "test" { - name = "acctest%[3]s" + name = "acctest%s" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" account_tier = "Standard" @@ -347,14 +328,14 @@ resource "azurerm_virtual_machine" "test" { } resource "azurerm_recovery_services_vault" "test" { - name = "acctest-%[1]d" + name = "acctest-%d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } resource "azurerm_backup_policy_vm" "test" { - name = "acctest-%[1]d" + name = "acctest-%d" resource_group_name = "${azurerm_resource_group.test.name}" recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" @@ -367,10 +348,11 @@ resource "azurerm_backup_policy_vm" "test" { count = 10 } } -`, rInt, location, rstr[len(rstr)-5:]) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMBackupProtectedVm_basic(rInt int, location string) string { +func testAccAzureRMBackupProtectedVm_basic(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedVm_base(data) return fmt.Sprintf(` %s @@ -380,16 +362,15 @@ resource "azurerm_backup_protected_vm" "test" { source_vm_id = "${azurerm_virtual_machine.test.id}" backup_policy_id = "${azurerm_backup_policy_vm.test.id}" } -`, testAccAzureRMBackupProtectedVm_base(rInt, location)) +`, template) } // For update backup policy id test -func testAccAzureRMBackupProtectedVm_basePolicyTest(rInt int, location string) string { - rstr := strconv.Itoa(rInt) +func testAccAzureRMBackupProtectedVm_basePolicyTest(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-recovery1-%[1]d" - location = "%[2]s" + name = "acctestRG-recovery1-%d" + location = "%s" } resource "azurerm_virtual_network" "test" { @@ -424,11 +405,11 @@ resource "azurerm_public_ip" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" allocation_method = "Dynamic" - domain_name_label = "acctestip%[1]d" + domain_name_label = "acctestip%d" } resource "azurerm_storage_account" "test" { - name = "acctest%[3]s" + name = "acctest%s" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" account_tier = "Standard" @@ -443,30 +424,32 @@ resource "azurerm_managed_disk" "test" { create_option = "Empty" disk_size_gb = "1023" } -`, rInt, location, rstr[len(rstr)-5:]) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString) } // For update backup policy id test -func testAccAzureRMBackupProtectedVm_withVault(rInt int, location string) string { +func testAccAzureRMBackupProtectedVm_withVault(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedVm_basePolicyTest(data) return fmt.Sprintf(` -%[1]s +%s resource "azurerm_recovery_services_vault" "test" { - name = "acctest-%[2]d" + name = "acctest-%d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } -`, testAccAzureRMBackupProtectedVm_basePolicyTest(rInt, location), rInt) +`, template, data.RandomInteger) } // For update backup policy id test -func testAccAzureRMBackupProtectedVm_withFirstPolicy(rInt int, location string) string { +func testAccAzureRMBackupProtectedVm_withFirstPolicy(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedVm_withVault(data) return fmt.Sprintf(` -%[1]s +%s resource "azurerm_backup_policy_vm" "test" { - name = "acctest-%[2]d" + name = "acctest-%d" resource_group_name = "${azurerm_resource_group.test.name}" recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" @@ -479,16 +462,17 @@ resource "azurerm_backup_policy_vm" "test" { count = 10 } } -`, testAccAzureRMBackupProtectedVm_withVault(rInt, location), rInt) +`, template, data.RandomInteger) } // For update backup policy id test -func testAccAzureRMBackupProtectedVm_withSecondPolicy(rInt int, location string) string { +func testAccAzureRMBackupProtectedVm_withSecondPolicy(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedVm_withFirstPolicy(data) return fmt.Sprintf(` -%[1]s +%s resource "azurerm_backup_policy_vm" "test_change_backup" { - name = "acctest2-%[2]d" + name = "acctest2-%d" resource_group_name = "${azurerm_resource_group.test.name}" recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" @@ -501,16 +485,17 @@ resource "azurerm_backup_policy_vm" "test_change_backup" { count = 15 } } -`, testAccAzureRMBackupProtectedVm_withFirstPolicy(rInt, location), rInt) +`, template, data.RandomInteger) } // For update backup policy id test -func testAccAzureRMBackupProtectedVm_withVM(rInt int, location string) string { +func testAccAzureRMBackupProtectedVm_withVM(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedVm_withSecondPolicy(data) return fmt.Sprintf(` -%[1]s +%s resource "azurerm_virtual_machine" "test" { - name = "acctestvm-%[2]d" + name = "acctestvm-%d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" vm_size = "Standard_A0" @@ -555,11 +540,12 @@ resource "azurerm_virtual_machine" "test" { storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}" } } -`, testAccAzureRMBackupProtectedVm_withSecondPolicy(rInt, location), rInt) +`, template, data.RandomInteger) } // For update backup policy id test -func testAccAzureRMBackupProtectedVm_linkFirstBackupPolicy(rInt int, location string) string { +func testAccAzureRMBackupProtectedVm_linkFirstBackupPolicy(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedVm_withVM(data) return fmt.Sprintf(` %s @@ -569,11 +555,12 @@ resource "azurerm_backup_protected_vm" "test" { source_vm_id = "${azurerm_virtual_machine.test.id}" backup_policy_id = "${azurerm_backup_policy_vm.test.id}" } -`, testAccAzureRMBackupProtectedVm_withVM(rInt, location)) +`, template) } // For update backup policy id test -func testAccAzureRMBackupProtectedVm_linkSecondBackupPolicy(rInt int, location string) string { +func testAccAzureRMBackupProtectedVm_linkSecondBackupPolicy(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedVm_withVM(data) return fmt.Sprintf(` %s @@ -583,10 +570,11 @@ resource "azurerm_backup_protected_vm" "test" { source_vm_id = "${azurerm_virtual_machine.test.id}" backup_policy_id = "${azurerm_backup_policy_vm.test_change_backup.id}" } -`, testAccAzureRMBackupProtectedVm_withVM(rInt, location)) +`, template) } -func testAccAzureRMBackupProtectedVm_requiresImport(rInt int, location string) string { +func testAccAzureRMBackupProtectedVm_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedVm_basic(data) return fmt.Sprintf(` %s @@ -596,27 +584,28 @@ resource "azurerm_backup_protected_vm" "import" { source_vm_id = "${azurerm_backup_protected_vm.test.source_vm_id}" backup_policy_id = "${azurerm_backup_protected_vm.test.backup_policy_id}" } -`, testAccAzureRMBackupProtectedVm_basic(rInt, location)) +`, template) } -func testAccAzureRMBackupProtectedVm_additionalVault(rInt int, location string) string { +func testAccAzureRMBackupProtectedVm_additionalVault(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedVm_base(data) return fmt.Sprintf(` -%[1]s +%s resource "azurerm_resource_group" "test2" { - name = "acctestRG-recovery2-%[2]d" - location = "%[3]s" + name = "acctestRG-recovery2-%d" + location = "%s" } resource "azurerm_recovery_services_vault" "test2" { - name = "acctest2-%[2]d" + name = "acctest2-%d" location = "${azurerm_resource_group.test2.location}" resource_group_name = "${azurerm_resource_group.test2.name}" sku = "Standard" } resource "azurerm_backup_policy_vm" "test2" { - name = "acctest2-%[2]d" + name = "acctest2-%d" resource_group_name = "${azurerm_resource_group.test2.name}" recovery_vault_name = "${azurerm_recovery_services_vault.test2.name}" @@ -629,10 +618,11 @@ resource "azurerm_backup_policy_vm" "test2" { count = 10 } } -`, testAccAzureRMBackupProtectedVm_base(rInt, location), rInt, location) +`, template, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMBackupProtectedVm_separateResourceGroups(rInt int, location string) string { +func testAccAzureRMBackupProtectedVm_separateResourceGroups(data acceptance.TestData) string { + template := testAccAzureRMBackupProtectedVm_additionalVault(data) return fmt.Sprintf(` %s @@ -642,5 +632,5 @@ resource "azurerm_backup_protected_vm" "test" { backup_policy_id = "${azurerm_backup_policy_vm.test2.id}" source_vm_id = "${azurerm_virtual_machine.test.id}" } -`, testAccAzureRMBackupProtectedVm_additionalVault(rInt, location)) +`, template) } diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_fabric_test.go similarity index 85% rename from azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_fabric_test.go index ea0d1a446895..d52dd6ed1166 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_fabric_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_fabric_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -7,14 +7,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMRecoveryFabric_basic(t *testing.T) { - resourceName := "azurerm_recovery_services_fabric.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_fabric", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMRecoveryFabric_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryFabricDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryFabric_basic(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryFabric_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryFabricExists(resourceName), + testCheckAzureRMRecoveryFabricExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMRecoveryFabric_basic(rInt int, location string) string { +func testAccAzureRMRecoveryFabric_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -56,7 +50,7 @@ resource "azurerm_recovery_services_fabric" "test" { name = "acctest-fabric-%d" location = "${azurerm_resource_group.test.location}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMRecoveryFabricExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_network_mapping_test.go similarity index 89% rename from azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_network_mapping_test.go index 6d7371e53519..f023f3ff583d 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_network_mapping_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_network_mapping_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -8,14 +8,12 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMRecoveryNetworkMapping_basic(t *testing.T) { - resourceName := "azurerm_recovery_network_mapping.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_network_mapping", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,21 +21,17 @@ func TestAccAzureRMRecoveryNetworkMapping_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryNetworkMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryNetworkMapping_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMRecoveryNetworkMapping_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryNetworkMappingExists(resourceName), + testCheckAzureRMRecoveryNetworkMappingExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMRecoveryNetworkMapping_basic(rInt int, location string, altLocation string) string { +func testAccAzureRMRecoveryNetworkMapping_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-recovery1-%d" @@ -89,7 +83,7 @@ resource "azurerm_recovery_network_mapping" "test" { source_network_id = "${azurerm_virtual_network.test1.id}" target_network_id = "${azurerm_virtual_network.test2.id}" } -`, rInt, location, rInt, rInt, rInt, altLocation, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMRecoveryNetworkMappingExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protected_vm_test.go similarity index 79% rename from azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protected_vm_test.go index 41861ca7830d..8c6c127c665b 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protected_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protected_vm_test.go @@ -1,14 +1,12 @@ -package recoveryservices +package tests import ( "fmt" - "strconv" "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +14,7 @@ import ( ) func TestAccAzureRMRecoveryServicesProtectedVm_basic(t *testing.T) { - resourceName := "azurerm_recovery_services_protected_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protected_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,19 +22,15 @@ func TestAccAzureRMRecoveryServicesProtectedVm_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryServicesProtectedVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectedVm_basic(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesProtectedVm_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectedVmExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), + testCheckAzureRMRecoveryServicesProtectedVmExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMRecoveryServicesProtectedVm_base(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesProtectedVm_base(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -50,8 +43,7 @@ func TestAccAzureRMRecoveryServicesProtectedVm_requiresImport(t *testing.T) { return } - resourceName := "azurerm_recovery_services_protected_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protected_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -59,18 +51,15 @@ func TestAccAzureRMRecoveryServicesProtectedVm_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryServicesProtectedVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectedVm_basic(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesProtectedVm_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectedVmExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), + testCheckAzureRMRecoveryServicesProtectedVmExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), ), }, - { - Config: testAccAzureRMRecoveryServicesProtectedVm_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_recovery_services_protected_vm"), - }, + data.RequiresImportErrorStep(testAccAzureRMRecoveryServicesProtectedVm_requiresImport), { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMRecoveryServicesProtectedVm_base(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesProtectedVm_base(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -78,8 +67,7 @@ func TestAccAzureRMRecoveryServicesProtectedVm_requiresImport(t *testing.T) { } func TestAccAzureRMRecoveryServicesProtectedVm_separateResourceGroups(t *testing.T) { - resourceName := "azurerm_recovery_services_protected_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protected_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,19 +75,15 @@ func TestAccAzureRMRecoveryServicesProtectedVm_separateResourceGroups(t *testing CheckDestroy: testCheckAzureRMRecoveryServicesProtectedVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectedVm_separateResourceGroups(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesProtectedVm_separateResourceGroups(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesProtectedVmExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), + testCheckAzureRMRecoveryServicesProtectedVmExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { //vault cannot be deleted unless we unregister all backups - Config: testAccAzureRMRecoveryServicesProtectedVm_additionalVault(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesProtectedVm_additionalVault(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -108,11 +92,9 @@ func TestAccAzureRMRecoveryServicesProtectedVm_separateResourceGroups(t *testing func TestAccAzureRMRecoveryServicesProtectedVm_updateBackupPolicyId(t *testing.T) { virtualMachine := "azurerm_virtual_machine.test" - protectedVmResourceName := "azurerm_recovery_services_protected_vm.test" fBackupPolicyResourceName := "azurerm_recovery_services_protection_policy_vm.test" sBackupPolicyResourceName := "azurerm_recovery_services_protection_policy_vm.test_change_backup" - - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protected_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -121,34 +103,34 @@ func TestAccAzureRMRecoveryServicesProtectedVm_updateBackupPolicyId(t *testing.T Steps: []resource.TestStep{ { // Create resources and link first backup policy id ResourceName: fBackupPolicyResourceName, - Config: testAccAzureRMRecoveryServicesProtectedVm_linkFirstBackupPolicy(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesProtectedVm_linkFirstBackupPolicy(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(protectedVmResourceName, "backup_policy_id", fBackupPolicyResourceName, "id"), + resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", fBackupPolicyResourceName, "id"), ), }, { // Modify backup policy id to the second one // Set Destroy false to prevent error from cleaning up dangling resource ResourceName: sBackupPolicyResourceName, - Config: testAccAzureRMRecoveryServicesProtectedVm_linkSecondBackupPolicy(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesProtectedVm_linkSecondBackupPolicy(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrPair(protectedVmResourceName, "backup_policy_id", sBackupPolicyResourceName, "id"), + resource.TestCheckResourceAttrPair(data.ResourceName, "backup_policy_id", sBackupPolicyResourceName, "id"), ), }, { // Remove backup policy link // Backup policy link will need to be removed first so the VM's backup policy subsequently reverts to Default // Azure API is quite sensitive, adding the step to control resource cleanup order ResourceName: fBackupPolicyResourceName, - Config: testAccAzureRMRecoveryServicesProtectedVm_withVM(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesProtectedVm_withVM(data), Check: resource.ComposeTestCheckFunc(), }, { // Then VM can be removed ResourceName: virtualMachine, - Config: testAccAzureRMRecoveryServicesProtectedVm_withSecondPolicy(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesProtectedVm_withSecondPolicy(data), Check: resource.ComposeTestCheckFunc(), }, { // Remove backup policies and vault - ResourceName: protectedVmResourceName, - Config: testAccAzureRMRecoveryServicesProtectedVm_basePolicyTest(ri, acceptance.Location()), + ResourceName: data.ResourceName, + Config: testAccAzureRMRecoveryServicesProtectedVm_basePolicyTest(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -240,12 +222,11 @@ func testCheckAzureRMRecoveryServicesProtectedVmExists(resourceName string) reso } } -func testAccAzureRMRecoveryServicesProtectedVm_base(rInt int, location string) string { - rstr := strconv.Itoa(rInt) +func testAccAzureRMRecoveryServicesProtectedVm_base(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" - location = "%[2]s" + name = "acctestRG-%d" + location = "%s" } resource "azurerm_virtual_network" "test" { @@ -280,11 +261,11 @@ resource "azurerm_public_ip" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" allocation_method = "Dynamic" - domain_name_label = "acctestip%[1]d" + domain_name_label = "acctestip%d" } resource "azurerm_storage_account" "test" { - name = "acctest%[3]s" + name = "acctest%s" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" account_tier = "Standard" @@ -347,14 +328,14 @@ resource "azurerm_virtual_machine" "test" { } resource "azurerm_recovery_services_vault" "test" { - name = "acctest-%[1]d" + name = "acctest-%d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } resource "azurerm_recovery_services_protection_policy_vm" "test" { - name = "acctest-%[1]d" + name = "acctest-%d" resource_group_name = "${azurerm_resource_group.test.name}" recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" @@ -367,10 +348,11 @@ resource "azurerm_recovery_services_protection_policy_vm" "test" { count = 10 } } -`, rInt, location, rstr[len(rstr)-5:]) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRecoveryServicesProtectedVm_basic(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectedVm_basic(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectedVm_base(data) return fmt.Sprintf(` %s @@ -380,16 +362,15 @@ resource "azurerm_recovery_services_protected_vm" "test" { source_vm_id = "${azurerm_virtual_machine.test.id}" backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.test.id}" } -`, testAccAzureRMRecoveryServicesProtectedVm_base(rInt, location)) +`, template) } // For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_basePolicyTest(rInt int, location string) string { - rstr := strconv.Itoa(rInt) +func testAccAzureRMRecoveryServicesProtectedVm_basePolicyTest(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-recovery1-%[1]d" - location = "%[2]s" + name = "acctestRG-recovery1-%d" + location = "%s" } resource "azurerm_virtual_network" "test" { @@ -424,11 +405,11 @@ resource "azurerm_public_ip" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" allocation_method = "Dynamic" - domain_name_label = "acctestip%[1]d" + domain_name_label = "acctestip%d" } resource "azurerm_storage_account" "test" { - name = "acctest%[3]s" + name = "acctest%s" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" account_tier = "Standard" @@ -443,30 +424,32 @@ resource "azurerm_managed_disk" "test" { create_option = "Empty" disk_size_gb = "1023" } -`, rInt, location, rstr[len(rstr)-5:]) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString) } // For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_withVault(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectedVm_withVault(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectedVm_basePolicyTest(data) return fmt.Sprintf(` -%[1]s +%s resource "azurerm_recovery_services_vault" "test" { - name = "acctest-%[2]d" + name = "acctest-%d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } -`, testAccAzureRMRecoveryServicesProtectedVm_basePolicyTest(rInt, location), rInt) +`, template, data.RandomInteger) } // For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_withFirstPolicy(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectedVm_withFirstPolicy(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectedVm_withVault(data) return fmt.Sprintf(` -%[1]s +%s resource "azurerm_recovery_services_protection_policy_vm" "test" { - name = "acctest-%[2]d" + name = "acctest-%d" resource_group_name = "${azurerm_resource_group.test.name}" recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" @@ -479,16 +462,17 @@ resource "azurerm_recovery_services_protection_policy_vm" "test" { count = 10 } } -`, testAccAzureRMRecoveryServicesProtectedVm_withVault(rInt, location), rInt) +`, template, data.RandomInteger) } // For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_withSecondPolicy(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectedVm_withSecondPolicy(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectedVm_withFirstPolicy(data) return fmt.Sprintf(` -%[1]s +%s resource "azurerm_recovery_services_protection_policy_vm" "test_change_backup" { - name = "acctest2-%[2]d" + name = "acctest2-%d" resource_group_name = "${azurerm_resource_group.test.name}" recovery_vault_name = "${azurerm_recovery_services_vault.test.name}" @@ -501,16 +485,17 @@ resource "azurerm_recovery_services_protection_policy_vm" "test_change_backup" { count = 15 } } -`, testAccAzureRMRecoveryServicesProtectedVm_withFirstPolicy(rInt, location), rInt) +`, template, data.RandomInteger) } // For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_withVM(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectedVm_withVM(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectedVm_withSecondPolicy(data) return fmt.Sprintf(` -%[1]s +%s resource "azurerm_virtual_machine" "test" { - name = "acctestvm-%[2]d" + name = "acctestvm-%d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" vm_size = "Standard_A0" @@ -555,11 +540,12 @@ resource "azurerm_virtual_machine" "test" { storage_uri = "${azurerm_storage_account.test.primary_blob_endpoint}" } } -`, testAccAzureRMRecoveryServicesProtectedVm_withSecondPolicy(rInt, location), rInt) +`, template, data.RandomInteger) } // For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_linkFirstBackupPolicy(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectedVm_linkFirstBackupPolicy(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectedVm_withVM(data) return fmt.Sprintf(` %s @@ -569,11 +555,12 @@ resource "azurerm_recovery_services_protected_vm" "test" { source_vm_id = "${azurerm_virtual_machine.test.id}" backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.test.id}" } -`, testAccAzureRMRecoveryServicesProtectedVm_withVM(rInt, location)) +`, template) } // For update backup policy id test -func testAccAzureRMRecoveryServicesProtectedVm_linkSecondBackupPolicy(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectedVm_linkSecondBackupPolicy(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectedVm_withVM(data) return fmt.Sprintf(` %s @@ -583,10 +570,11 @@ resource "azurerm_recovery_services_protected_vm" "test" { source_vm_id = "${azurerm_virtual_machine.test.id}" backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.test_change_backup.id}" } -`, testAccAzureRMRecoveryServicesProtectedVm_withVM(rInt, location)) +`, template) } -func testAccAzureRMRecoveryServicesProtectedVm_requiresImport(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectedVm_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectedVm_basic(data) return fmt.Sprintf(` %s @@ -596,27 +584,28 @@ resource "azurerm_recovery_services_protected_vm" "import" { source_vm_id = "${azurerm_recovery_services_protected_vm.test.source_vm_id}" backup_policy_id = "${azurerm_recovery_services_protected_vm.test.backup_policy_id}" } -`, testAccAzureRMRecoveryServicesProtectedVm_basic(rInt, location)) +`, template) } -func testAccAzureRMRecoveryServicesProtectedVm_additionalVault(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectedVm_additionalVault(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectedVm_base(data) return fmt.Sprintf(` -%[1]s +%s resource "azurerm_resource_group" "test2" { - name = "acctestRG-recovery2-%[2]d" - location = "%[3]s" + name = "acctestRG-recovery2-%d" + location = "%s" } resource "azurerm_recovery_services_vault" "test2" { - name = "acctest2-%[2]d" + name = "acctest2-%d" location = "${azurerm_resource_group.test2.location}" resource_group_name = "${azurerm_resource_group.test2.name}" sku = "Standard" } resource "azurerm_recovery_services_protection_policy_vm" "test2" { - name = "acctest2-%[2]d" + name = "acctest2-%d" resource_group_name = "${azurerm_resource_group.test2.name}" recovery_vault_name = "${azurerm_recovery_services_vault.test2.name}" @@ -629,10 +618,11 @@ resource "azurerm_recovery_services_protection_policy_vm" "test2" { count = 10 } } -`, testAccAzureRMRecoveryServicesProtectedVm_base(rInt, location), rInt, location) +`, template, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRecoveryServicesProtectedVm_separateResourceGroups(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectedVm_separateResourceGroups(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectedVm_additionalVault(data) return fmt.Sprintf(` %s @@ -642,5 +632,5 @@ resource "azurerm_recovery_services_protected_vm" "test" { backup_policy_id = "${azurerm_recovery_services_protection_policy_vm.test2.id}" source_vm_id = "${azurerm_virtual_machine.test.id}" } -`, testAccAzureRMRecoveryServicesProtectedVm_additionalVault(rInt, location)) +`, template) } diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_mapping_test.go similarity index 90% rename from azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_mapping_test.go index ef090b3f6d71..cf62f691e40d 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_mapping_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_mapping_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -7,14 +7,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMRecoveryProtectionContainerMapping_basic(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_container_mapping.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_container_mapping", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMRecoveryProtectionContainerMapping_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryProtectionContainerMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryProtectionContainerMapping_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMRecoveryProtectionContainerMapping_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryProtectionContainerMappingExists(resourceName), + testCheckAzureRMRecoveryProtectionContainerMappingExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMRecoveryProtectionContainerMapping_basic(rInt int, location string, altLocation string) string { +func testAccAzureRMRecoveryProtectionContainerMapping_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test1" { name = "acctestRG-recovery1-%d" @@ -96,7 +90,7 @@ resource "azurerm_recovery_services_protection_container_mapping" "test" { recovery_replication_policy_id = "${azurerm_recovery_services_replication_policy.test.id}" name = "mapping-%d" } -`, rInt, location, rInt, rInt, rInt, altLocation, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMRecoveryProtectionContainerMappingExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_test.go similarity index 86% rename from azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_test.go index bee0ef0930d5..28697fbfe270 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_container_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_container_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -7,14 +7,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMRecoveryProtectionContainer_basic(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_container.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMRecoveryProtectionContainer_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryProtectionContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryProtectionContainer_basic(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryProtectionContainer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryProtectionContainerExists(resourceName), + testCheckAzureRMRecoveryProtectionContainerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMRecoveryProtectionContainer_basic(rInt int, location string) string { +func testAccAzureRMRecoveryProtectionContainer_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -64,7 +58,7 @@ resource "azurerm_recovery_services_protection_container" "test" { name = "acctest-protection-cont-%d" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMRecoveryProtectionContainerExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_policy_vm_test.go similarity index 81% rename from azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_policy_vm_test.go index f9b27a6ba5b3..38ae218490df 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_protection_policy_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_protection_policy_vm_test.go @@ -1,13 +1,11 @@ -package recoveryservices +package tests import ( "fmt" - "strconv" "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/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +13,7 @@ import ( ) func TestAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,14 +21,10 @@ func TestAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(resourceName, ri), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } @@ -42,8 +35,7 @@ func TestAccAzureRMRecoveryServicesProtectionPolicyVm_requiresImport(t *testing. return } - resourceName := "azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,20 +43,16 @@ func TestAccAzureRMRecoveryServicesProtectionPolicyVm_requiresImport(t *testing. CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(resourceName, ri), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_recovery_services_protection_policy_vm"), + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data.ResourceName, data.RandomInteger), }, + data.RequiresImportErrorStep(testAccAzureRMRecoveryServicesProtectionPolicyVm_requiresImport), }, }) } func TestAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -72,21 +60,16 @@ func TestAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(t *testing.T) CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(resourceName, ri), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -94,21 +77,16 @@ func TestAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(t *testing.T CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(resourceName, ri), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -116,21 +94,16 @@ func TestAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(t *testing. CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(resourceName, ri), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateDaily(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -138,25 +111,20 @@ func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateDaily(t *testing.T) CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(resourceName, ri), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(resourceName, ri), + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data.ResourceName, data.RandomInteger), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateWeekly(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -164,75 +132,62 @@ func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateWeekly(t *testing.T) CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(resourceName, ri), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(resourceName, ri), + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data.ResourceName, data.RandomInteger), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateDailyToWeekly(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(resourceName, ri), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(resourceName, ri), + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data.ResourceName, data.RandomInteger), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateWeeklyToDaily(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(resourceName, ri), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(resourceName, ri), + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data.ResourceName, data.RandomInteger), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateWeeklyToPartial(t *testing.T) { - resourceName := "azurerm_recovery_services_protection_policy_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_protection_policy_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -240,18 +195,14 @@ func TestAccAzureRMRecoveryServicesProtectionPolicyVm_updateWeeklyToPartial(t *t CheckDestroy: testCheckAzureRMRecoveryServicesProtectionPolicyVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(resourceName, ri), - }, - { - Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(ri, acceptance.Location()), - Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(resourceName, ri), + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data.ResourceName, data.RandomInteger), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(data), + Check: checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(data.ResourceName, data.RandomInteger), }, + data.ImportStep(), }, }) } @@ -315,23 +266,24 @@ func testCheckAzureRMRecoveryServicesProtectionPolicyVmExists(resourceName strin } } -func testAccAzureRMRecoveryServicesProtectionPolicyVm_base(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-%[1]d" - location = "%[2]s" + name = "acctestRG-%d" + location = "%s" } resource "azurerm_recovery_services_vault" "test" { - name = "acctest-%[1]d" + name = "acctest-%s" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } -`, rInt, location, strconv.Itoa(rInt)[12:17]) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data) return fmt.Sprintf(` %s @@ -349,10 +301,11 @@ resource "azurerm_recovery_services_protection_policy_vm" "test" { count = 10 } } -`, testAccAzureRMRecoveryServicesProtectionPolicyVm_base(rInt, location), rInt) +`, template, data.RandomInteger) } -func testAccAzureRMRecoveryServicesProtectionPolicyVm_requiresImport(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectionPolicyVm_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(data) return fmt.Sprintf(` %s @@ -370,7 +323,7 @@ resource "azurerm_recovery_services_protection_policy_vm" "import" { count = 10 } } -`, testAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(rInt, location)) +`, template) } func checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(resourceName string, ri int) resource.TestCheckFunc { @@ -385,7 +338,8 @@ func checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicDaily(resourceName s ) } -func testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data) return fmt.Sprintf(` %s @@ -405,7 +359,7 @@ resource "azurerm_recovery_services_protection_policy_vm" "test" { weekdays = ["Sunday", "Wednesday"] } } -`, testAccAzureRMRecoveryServicesProtectionPolicyVm_base(rInt, location), rInt) +`, template, data.RandomInteger) } func checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(resourceName string, ri int) resource.TestCheckFunc { @@ -421,7 +375,8 @@ func checkAccAzureRMRecoveryServicesProtectionPolicyVm_basicWeekly(resourceName ) } -func testAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data) return fmt.Sprintf(` %s @@ -457,7 +412,7 @@ resource "azurerm_recovery_services_protection_policy_vm" "test" { months = ["January", "July"] } } -`, testAccAzureRMRecoveryServicesProtectionPolicyVm_base(rInt, location), rInt) +`, template, data.RandomInteger) } func checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(resourceName string, ri int) resource.TestCheckFunc { @@ -481,7 +436,8 @@ func checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeDaily(resourceNam ) } -func testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data) return fmt.Sprintf(` %s @@ -514,7 +470,7 @@ resource "azurerm_recovery_services_protection_policy_vm" "test" { months = ["January", "July"] } } -`, testAccAzureRMRecoveryServicesProtectionPolicyVm_base(rInt, location), rInt) +`, template, data.RandomInteger) } func checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(resourceName string, ri int) resource.TestCheckFunc { @@ -538,7 +494,8 @@ func checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeekly(resourceNa ) } -func testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(rInt int, location string) string { +func testAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesProtectionPolicyVm_base(data) return fmt.Sprintf(` %s @@ -571,7 +528,7 @@ resource "azurerm_recovery_services_protection_policy_vm" "test" { months = ["January"] } } -`, testAccAzureRMRecoveryServicesProtectionPolicyVm_base(rInt, location), rInt) +`, template, data.RandomInteger) } func checkAccAzureRMRecoveryServicesProtectionPolicyVm_completeWeeklyPartial(resourceName string, ri int) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replicated_vm_test.go similarity index 92% rename from azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replicated_vm_test.go index d04b28684004..b1841a33c1af 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replicated_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replicated_vm_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -7,14 +7,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMRecoveryReplicatedVm_basic(t *testing.T) { - replicationName := "azurerm_recovery_replicated_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_replicated_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMRecoveryReplicatedVm_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryReplicatedVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryReplicatedVm_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMRecoveryReplicatedVm_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryReplicatedVmExists(replicationName), + testCheckAzureRMRecoveryReplicatedVmExists(data.ResourceName), ), }, - { - ResourceName: replicationName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMRecoveryReplicatedVm_basic(rInt int, location string, altLocation string) string { +func testAccAzureRMRecoveryReplicatedVm_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-recovery1-%d" @@ -210,7 +204,7 @@ resource "azurerm_recovery_replicated_vm" "test" { } depends_on = ["azurerm_recovery_services_protection_container_mapping.test", "azurerm_recovery_network_mapping.test"] } -`, rInt, location, rInt, altLocation, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMRecoveryReplicatedVmExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replication_policy_test.go similarity index 85% rename from azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replication_policy_test.go index 289e3e9be16b..c597ccf1d42b 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_replication_policy_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_replication_policy_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -7,14 +7,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMRecoveryReplicationPolicy_basic(t *testing.T) { - resourceName := "azurerm_recovery_services_replication_policy.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_recovery_services_replication_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMRecoveryReplicationPolicy_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryReplicationPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryReplicationPolicy_basic(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryReplicationPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryReplicationPolicyExists(resourceName), + testCheckAzureRMRecoveryReplicationPolicyExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMRecoveryReplicationPolicy_basic(rInt int, location string) string { +func testAccAzureRMRecoveryReplicationPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -57,7 +51,7 @@ resource "azurerm_recovery_services_replication_policy" "test" { recovery_point_retention_in_minutes = "${24 * 60}" application_consistent_snapshot_frequency_in_minutes = "${4 * 60}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMRecoveryReplicationPolicyExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_vault_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_vault_test.go similarity index 68% rename from azurerm/internal/services/recoveryservices/resource_arm_recovery_services_vault_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_vault_test.go index 01acf72c4328..de65ad9a34ee 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_recovery_services_vault_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_recovery_services_vault_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMRecoveryServicesVault_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_recovery_services_vault.test" + data := acceptance.BuildTestData(t, "azurerm_recovery_services_vault", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,21 +21,17 @@ func TestAccAzureRMRecoveryServicesVault_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryServicesVaultDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesVault_basic(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesVault_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesVaultExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "location"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttr(resourceName, "sku", "Standard"), + testCheckAzureRMRecoveryServicesVaultExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -48,8 +42,7 @@ func TestAccAzureRMRecoveryServicesVault_requiresImport(t *testing.T) { return } - ri := tf.AccRandTimeInt() - resourceName := "azurerm_recovery_services_vault.test" + data := acceptance.BuildTestData(t, "azurerm_recovery_services_vault", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,20 +50,17 @@ func TestAccAzureRMRecoveryServicesVault_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMRecoveryServicesVaultDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRecoveryServicesVault_basic(ri, acceptance.Location()), + Config: testAccAzureRMRecoveryServicesVault_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRecoveryServicesVaultExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "location"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttr(resourceName, "sku", "Standard"), + testCheckAzureRMRecoveryServicesVaultExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), ), }, - { - Config: testAccAzureRMRecoveryServicesVault_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_recovery_services_vault"), - }, + data.RequiresImportErrorStep(testAccAzureRMRecoveryServicesVault_requiresImport), }, }) } @@ -132,7 +122,7 @@ func testCheckAzureRMRecoveryServicesVaultExists(resourceName string) resource.T } } -func testAccAzureRMRecoveryServicesVault_basic(rInt int, location string) string { +func testAccAzureRMRecoveryServicesVault_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -145,10 +135,11 @@ resource "azurerm_recovery_services_vault" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRecoveryServicesVault_requiresImport(rInt int, location string) string { +func testAccAzureRMRecoveryServicesVault_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMRecoveryServicesVault_basic(data) return fmt.Sprintf(` %s @@ -158,5 +149,5 @@ resource "azurerm_recovery_services_vault" "import" { resource_group_name = "${azurerm_recovery_services_vault.test.resource_group_name}" sku = "${azurerm_recovery_services_vault.test.sku}" } -`, testAccAzureRMRecoveryServicesVault_basic(rInt, location)) +`, template) } diff --git a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_fabric_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_fabric_test.go similarity index 85% rename from azurerm/internal/services/recoveryservices/resource_arm_site_recovery_fabric_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_fabric_test.go index 5ea01cdff8e2..f250e5e95b86 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_fabric_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_fabric_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -7,14 +7,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMSiteRecoveryFabric_basic(t *testing.T) { - resourceName := "azurerm_site_recovery_fabric.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_site_recovery_fabric", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMSiteRecoveryFabric_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSiteRecoveryFabricDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSiteRecoveryFabric_basic(ri, acceptance.Location()), + Config: testAccAzureRMSiteRecoveryFabric_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSiteRecoveryFabricExists(resourceName), + testCheckAzureRMSiteRecoveryFabricExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMSiteRecoveryFabric_basic(rInt int, location string) string { +func testAccAzureRMSiteRecoveryFabric_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -56,7 +50,7 @@ resource "azurerm_site_recovery_fabric" "test" { name = "acctest-fabric-%d" location = "${azurerm_resource_group.test.location}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMSiteRecoveryFabricExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_network_mapping_test.go similarity index 89% rename from azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_network_mapping_test.go index 8564422e9f1a..2432161fb66e 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_network_mapping_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_network_mapping_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -8,14 +8,12 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMSiteRecoveryNetworkMapping_basic(t *testing.T) { - resourceName := "azurerm_site_recovery_network_mapping.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_site_recovery_network_mapping", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,21 +21,17 @@ func TestAccAzureRMSiteRecoveryNetworkMapping_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSiteRecoveryNetworkMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSiteRecoveryNetworkMapping_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMSiteRecoveryNetworkMapping_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSiteRecoveryNetworkMappingExists(resourceName), + testCheckAzureRMSiteRecoveryNetworkMappingExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMSiteRecoveryNetworkMapping_basic(rInt int, location string, altLocation string) string { +func testAccAzureRMSiteRecoveryNetworkMapping_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-recovery1-%d" @@ -89,7 +83,7 @@ resource "azurerm_site_recovery_network_mapping" "test" { source_network_id = "${azurerm_virtual_network.test1.id}" target_network_id = "${azurerm_virtual_network.test2.id}" } -`, rInt, location, rInt, rInt, rInt, altLocation, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMSiteRecoveryNetworkMappingExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_mapping_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_mapping_test.go similarity index 92% rename from azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_mapping_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_mapping_test.go index 875f8551f9e5..332a008b8320 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_mapping_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_mapping_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -7,14 +7,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMSiteRecoveryProtectionContainerMapping_basic(t *testing.T) { - resourceName := "azurerm_site_recovery_protection_container_mapping.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_site_recovery_protection_container_mapping", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMSiteRecoveryProtectionContainerMapping_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSiteRecoveryProtectionContainerMappingDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSiteRecoveryProtectionContainerMapping_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMSiteRecoveryProtectionContainerMapping_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSiteRecoveryProtectionContainerMappingExists(resourceName), + testCheckAzureRMSiteRecoveryProtectionContainerMappingExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMSiteRecoveryProtectionContainerMapping_basic(rInt int, location string, altLocation string) string { +func testAccAzureRMSiteRecoveryProtectionContainerMapping_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test1" { name = "acctestRG-recovery1-%d" @@ -96,7 +90,7 @@ resource "azurerm_site_recovery_protection_container_mapping" "test" { recovery_replication_policy_id = "${azurerm_site_recovery_replication_policy.test.id}" name = "mapping-%d" } -`, rInt, location, rInt, rInt, rInt, altLocation, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMSiteRecoveryProtectionContainerMappingExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_test.go similarity index 87% rename from azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_test.go index c13df2a239e8..4008083c1288 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_protection_container_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_protection_container_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -7,14 +7,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMSiteRecoveryProtectionContainer_basic(t *testing.T) { - resourceName := "azurerm_site_recovery_protection_container.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_site_recovery_protection_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMSiteRecoveryProtectionContainer_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSiteRecoveryProtectionContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSiteRecoveryProtectionContainer_basic(ri, acceptance.Location()), + Config: testAccAzureRMSiteRecoveryProtectionContainer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSiteRecoveryProtectionContainerExists(resourceName), + testCheckAzureRMSiteRecoveryProtectionContainerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMSiteRecoveryProtectionContainer_basic(rInt int, location string) string { +func testAccAzureRMSiteRecoveryProtectionContainer_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -64,7 +58,7 @@ resource "azurerm_site_recovery_protection_container" "test" { name = "acctest-protection-cont-%d" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMSiteRecoveryProtectionContainerExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replicated_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replicated_vm_test.go similarity index 92% rename from azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replicated_vm_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replicated_vm_test.go index dcbb91aeb5ef..ff2cafe23b3b 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replicated_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replicated_vm_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -7,14 +7,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMSiteRecoveryReplicatedVm_basic(t *testing.T) { - replicationName := "azurerm_site_recovery_replicated_vm.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_site_recovery_replicated_vm", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMSiteRecoveryReplicatedVm_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSiteRecoveryReplicatedVmDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSiteRecoveryReplicatedVm_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMSiteRecoveryReplicatedVm_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSiteRecoveryReplicatedVmExists(replicationName), + testCheckAzureRMSiteRecoveryReplicatedVmExists(data.ResourceName), ), }, - { - ResourceName: replicationName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMSiteRecoveryReplicatedVm_basic(rInt int, location string, altLocation string) string { +func testAccAzureRMSiteRecoveryReplicatedVm_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-recovery1-%d" @@ -210,7 +204,7 @@ resource "azurerm_site_recovery_replicated_vm" "test" { } depends_on = ["azurerm_site_recovery_protection_container_mapping.test", "azurerm_site_recovery_network_mapping.test"] } -`, rInt, location, rInt, altLocation, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMSiteRecoveryReplicatedVmExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replication_policy_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replication_policy_test.go similarity index 85% rename from azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replication_policy_test.go rename to azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replication_policy_test.go index 11a6cfc745ad..b9c072e926e8 100644 --- a/azurerm/internal/services/recoveryservices/resource_arm_site_recovery_replication_policy_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_site_recovery_replication_policy_test.go @@ -1,4 +1,4 @@ -package recoveryservices +package tests import ( "fmt" @@ -7,14 +7,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMSiteRecoveryReplicationPolicy_basic(t *testing.T) { - resourceName := "azurerm_site_recovery_replication_policy.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_site_recovery_replication_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,21 +20,17 @@ func TestAccAzureRMSiteRecoveryReplicationPolicy_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSiteRecoveryReplicationPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSiteRecoveryReplicationPolicy_basic(ri, acceptance.Location()), + Config: testAccAzureRMSiteRecoveryReplicationPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSiteRecoveryReplicationPolicyExists(resourceName), + testCheckAzureRMSiteRecoveryReplicationPolicyExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMSiteRecoveryReplicationPolicy_basic(rInt int, location string) string { +func testAccAzureRMSiteRecoveryReplicationPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -57,7 +51,7 @@ resource "azurerm_site_recovery_replication_policy" "test" { recovery_point_retention_in_minutes = "${24 * 60}" application_consistent_snapshot_frequency_in_minutes = "${4 * 60}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMSiteRecoveryReplicationPolicyExists(resourceName string) resource.TestCheckFunc { From b878ad333dff5dc211ed4772b78737972a5bdb18 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 14:01:11 +0100 Subject: [PATCH 120/203] privatedns: fixing the tests --- .../resource_arm_private_dns_a_record_test.go | 95 ++++++--------- ...source_arm_private_dns_aaaa_record_test.go | 95 ++++++--------- ...ource_arm_private_dns_cname_record_test.go | 113 ++++++----------- ...resource_arm_private_dns_mx_record_test.go | 115 ++++++------------ ...esource_arm_private_dns_ptr_record_test.go | 96 ++++++--------- ...esource_arm_private_dns_srv_record_test.go | 96 ++++++--------- .../resource_arm_private_dns_zone_test.go | 73 ++++------- ...vate_dns_zone_virtual_network_link_test.go | 72 ++++------- 8 files changed, 265 insertions(+), 490 deletions(-) rename azurerm/internal/services/privatedns/{ => tests}/resource_arm_private_dns_a_record_test.go (71%) rename azurerm/internal/services/privatedns/{ => tests}/resource_arm_private_dns_aaaa_record_test.go (72%) rename azurerm/internal/services/privatedns/{ => tests}/resource_arm_private_dns_cname_record_test.go (71%) rename azurerm/internal/services/privatedns/{ => tests}/resource_arm_private_dns_mx_record_test.go (72%) rename azurerm/internal/services/privatedns/{ => tests}/resource_arm_private_dns_ptr_record_test.go (71%) rename azurerm/internal/services/privatedns/{ => tests}/resource_arm_private_dns_srv_record_test.go (74%) rename azurerm/internal/services/privatedns/{ => tests}/resource_arm_private_dns_zone_test.go (70%) rename azurerm/internal/services/privatedns/{ => tests}/resource_arm_private_dns_zone_virtual_network_link_test.go (79%) diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_a_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_a_record_test.go similarity index 71% rename from azurerm/internal/services/privatedns/resource_arm_private_dns_a_record_test.go rename to azurerm/internal/services/privatedns/tests/resource_arm_private_dns_a_record_test.go index d4c9092adb8d..6b3a01e0307c 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_a_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_a_record_test.go @@ -1,4 +1,4 @@ -package privatedns +package tests import ( "fmt" @@ -8,16 +8,13 @@ import ( "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMPrivateDnsARecord_basic(t *testing.T) { - resourceName := "azurerm_private_dns_a_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPrivateDnsARecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_private_dns_a_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,16 +22,12 @@ func TestAccAzureRMPrivateDnsARecord_basic(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateDnsARecordDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPrivateDnsARecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsARecordExists(resourceName), + testCheckAzureRMPrivateDnsARecordExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,53 +38,42 @@ func TestAccAzureRMPrivateDnsARecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_private_dns_a_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_private_dns_a_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsARecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateDnsARecord_basic(ri, location), + Config: testAccAzureRMPrivateDnsARecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsARecordExists(resourceName), + testCheckAzureRMPrivateDnsARecordExists(data.ResourceName), ), }, - { - Config: testAccAzureRMPrivateDnsARecord_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_private_dns_a_record"), - }, + data.RequiresImportErrorStep(testAccAzureRMPrivateDnsARecord_requiresImport), }, }) } func TestAccAzureRMPrivateDnsARecord_updateRecords(t *testing.T) { - resourceName := "azurerm_private_dns_a_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsARecord_basic(ri, location) - postConfig := testAccAzureRMPrivateDnsARecord_updateRecords(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_a_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsARecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsARecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsARecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), + testCheckAzureRMPrivateDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsARecord_updateRecords(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsARecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "3"), + testCheckAzureRMPrivateDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "3"), ), }, }, @@ -99,36 +81,27 @@ func TestAccAzureRMPrivateDnsARecord_updateRecords(t *testing.T) { } func TestAccAzureRMPrivateDnsARecord_withTags(t *testing.T) { - resourceName := "azurerm_private_dns_a_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsARecord_withTags(ri, location) - postConfig := testAccAzureRMPrivateDnsARecord_withTagsUpdate(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_a_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsARecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsARecord_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsARecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMPrivateDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsARecord_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsARecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMPrivateDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -192,7 +165,7 @@ func testCheckAzureRMPrivateDnsARecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPrivateDnsARecord_basic(rInt int, location string) string { +func testAccAzureRMPrivateDnsARecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -211,11 +184,11 @@ resource "azurerm_private_dns_a_record" "test" { ttl = 300 records = ["1.2.3.4", "1.2.4.5"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsARecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMPrivateDnsARecord_basic(rInt, location) +func testAccAzureRMPrivateDnsARecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPrivateDnsARecord_basic(data) return fmt.Sprintf(` %s @@ -229,7 +202,7 @@ resource "azurerm_private_dns_a_record" "import" { `, template) } -func testAccAzureRMPrivateDnsARecord_updateRecords(rInt int, location string) string { +func testAccAzureRMPrivateDnsARecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -248,10 +221,10 @@ resource "azurerm_private_dns_a_record" "test" { ttl = 300 records = ["1.2.3.4", "1.2.4.5", "1.2.3.7"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsARecord_withTags(rInt int, location string) string { +func testAccAzureRMPrivateDnsARecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -275,10 +248,10 @@ resource "azurerm_private_dns_a_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsARecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMPrivateDnsARecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -301,5 +274,5 @@ resource "azurerm_private_dns_a_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_aaaa_record_test.go similarity index 72% rename from azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record_test.go rename to azurerm/internal/services/privatedns/tests/resource_arm_private_dns_aaaa_record_test.go index a23e86f06a31..350ed3cb5da1 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_aaaa_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_aaaa_record_test.go @@ -1,4 +1,4 @@ -package privatedns +package tests import ( "fmt" @@ -8,16 +8,13 @@ import ( "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMPrivateDnsAaaaRecord_basic(t *testing.T) { - resourceName := "azurerm_private_dns_aaaa_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPrivateDnsAaaaRecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_private_dns_aaaa_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,16 +22,12 @@ func TestAccAzureRMPrivateDnsAaaaRecord_basic(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateDnsAaaaRecordDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPrivateDnsAaaaRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsAaaaRecordExists(resourceName), + testCheckAzureRMPrivateDnsAaaaRecordExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,53 +38,42 @@ func TestAccAzureRMPrivateDnsAaaaRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_private_dns_aaaa_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_private_dns_aaaa_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsAaaaRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateDnsAaaaRecord_basic(ri, location), + Config: testAccAzureRMPrivateDnsAaaaRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsAaaaRecordExists(resourceName), + testCheckAzureRMPrivateDnsAaaaRecordExists(data.ResourceName), ), }, - { - Config: testAccAzureRMPrivateDnsAaaaRecord_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_private_dns_aaaa_record"), - }, + data.RequiresImportErrorStep(testAccAzureRMPrivateDnsAaaaRecord_requiresImport), }, }) } func TestAccAzureRMPrivateDnsAaaaRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_private_dns_aaaa_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsAaaaRecord_basic(ri, location) - postConfig := testAccAzureRMPrivateDnsAaaaRecord_updateRecords(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_aaaa_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsAaaaRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsAaaaRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), + testCheckAzureRMPrivateDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsAaaaRecord_updateRecords(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "3"), + testCheckAzureRMPrivateDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "3"), ), }, }, @@ -99,36 +81,27 @@ func TestAccAzureRMPrivateDnsAaaaRecord_updateRecords(t *testing.T) { } func TestAccAzureRMPrivateDnsAaaaRecord_withTags(t *testing.T) { - resourceName := "azurerm_private_dns_aaaa_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsAaaaRecord_withTags(ri, location) - postConfig := testAccAzureRMPrivateDnsAaaaRecord_withTagsUpdate(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_aaaa_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsAaaaRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsAaaaRecord_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMPrivateDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsAaaaRecord_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMPrivateDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -192,7 +165,7 @@ func testCheckAzureRMPrivateDnsAaaaRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPrivateDnsAaaaRecord_basic(rInt int, location string) string { +func testAccAzureRMPrivateDnsAaaaRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -211,11 +184,11 @@ resource "azurerm_private_dns_aaaa_record" "test" { ttl = 300 records = ["fd5d:70bc:930e:d008:0000:0000:0000:7334", "fd5d:70bc:930e:d008::7335"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsAaaaRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMPrivateDnsAaaaRecord_basic(rInt, location) +func testAccAzureRMPrivateDnsAaaaRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPrivateDnsAaaaRecord_basic(data) return fmt.Sprintf(` %s @@ -229,7 +202,7 @@ resource "azurerm_private_dns_aaaa_record" "import" { `, template) } -func testAccAzureRMPrivateDnsAaaaRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMPrivateDnsAaaaRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -248,10 +221,10 @@ resource "azurerm_private_dns_aaaa_record" "test" { ttl = 300 records = ["fd5d:70bc:930e:d008:0000:0000:0000:7334", "fd5d:70bc:930e:d008::7335", "fd73:5e76:3ab5:d2e9::1"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsAaaaRecord_withTags(rInt int, location string) string { +func testAccAzureRMPrivateDnsAaaaRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -275,10 +248,10 @@ resource "azurerm_private_dns_aaaa_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsAaaaRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMPrivateDnsAaaaRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -301,5 +274,5 @@ resource "azurerm_private_dns_aaaa_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_cname_record_test.go similarity index 71% rename from azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record_test.go rename to azurerm/internal/services/privatedns/tests/resource_arm_private_dns_cname_record_test.go index 66533d992c33..08425ed41d36 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_cname_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_cname_record_test.go @@ -1,4 +1,4 @@ -package privatedns +package tests import ( "fmt" @@ -8,33 +8,25 @@ import ( "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMPrivateDnsCNameRecord_basic(t *testing.T) { - resourceName := "azurerm_private_dns_cname_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPrivateDnsCNameRecord_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_cname_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsCNameRecordDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPrivateDnsCNameRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsCNameRecordExists(resourceName), + testCheckAzureRMPrivateDnsCNameRecordExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,77 +37,59 @@ func TestAccAzureRMPrivateDnsCNameRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_private_dns_cname_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_private_dns_cname_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsCNameRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateDnsCNameRecord_basic(ri, location), + Config: testAccAzureRMPrivateDnsCNameRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsCNameRecordExists(resourceName), + testCheckAzureRMPrivateDnsCNameRecordExists(data.ResourceName), ), }, - { - Config: testAccAzureRMPrivateDnsCNameRecord_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_private_dns_cname_record"), - }, + data.RequiresImportErrorStep(testAccAzureRMPrivateDnsCNameRecord_requiresImport), }, }) } func TestAccAzureRMPrivateDnsCNameRecord_subdomain(t *testing.T) { - resourceName := "azurerm_private_dns_cname_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPrivateDnsCNameRecord_subdomain(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_cname_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsCNameRecordDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPrivateDnsCNameRecord_subdomain(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record", "test.contoso.com"), + testCheckAzureRMPrivateDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record", "test.contoso.com"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPrivateDnsCNameRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_private_dns_cname_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsCNameRecord_basic(ri, location) - postConfig := testAccAzureRMPrivateDnsCNameRecord_updateRecords(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_cname_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsCNameRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsCNameRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsCNameRecordExists(resourceName), + testCheckAzureRMPrivateDnsCNameRecordExists(data.ResourceName), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsCNameRecord_updateRecords(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsCNameRecordExists(resourceName), + testCheckAzureRMPrivateDnsCNameRecordExists(data.ResourceName), ), }, }, @@ -123,36 +97,27 @@ func TestAccAzureRMPrivateDnsCNameRecord_updateRecords(t *testing.T) { } func TestAccAzureRMPrivateDnsCNameRecord_withTags(t *testing.T) { - resourceName := "azurerm_private_dns_cname_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsCNameRecord_withTags(ri, location) - postConfig := testAccAzureRMPrivateDnsCNameRecord_withTagsUpdate(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_cname_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsCNameRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsCNameRecord_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMPrivateDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsCNameRecord_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMPrivateDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -216,7 +181,7 @@ func testCheckAzureRMPrivateDnsCNameRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPrivateDnsCNameRecord_basic(rInt int, location string) string { +func testAccAzureRMPrivateDnsCNameRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -235,11 +200,11 @@ resource "azurerm_private_dns_cname_record" "test" { ttl = 300 record = "contoso.com" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsCNameRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMPrivateDnsCNameRecord_basic(rInt, location) +func testAccAzureRMPrivateDnsCNameRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPrivateDnsCNameRecord_basic(data) return fmt.Sprintf(` %s @@ -253,7 +218,7 @@ resource "azurerm_private_dns_cname_record" "import" { `, template) } -func testAccAzureRMPrivateDnsCNameRecord_subdomain(rInt int, location string) string { +func testAccAzureRMPrivateDnsCNameRecord_subdomain(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -272,10 +237,10 @@ resource "azurerm_private_dns_cname_record" "test" { ttl = 300 record = "test.contoso.com" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsCNameRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMPrivateDnsCNameRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -294,10 +259,10 @@ resource "azurerm_private_dns_cname_record" "test" { ttl = 300 record = "contoso.com" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsCNameRecord_withTags(rInt int, location string) string { +func testAccAzureRMPrivateDnsCNameRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -321,10 +286,10 @@ resource "azurerm_private_dns_cname_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsCNameRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMPrivateDnsCNameRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -347,5 +312,5 @@ resource "azurerm_private_dns_cname_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_mx_record_test.go similarity index 72% rename from azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record_test.go rename to azurerm/internal/services/privatedns/tests/resource_arm_private_dns_mx_record_test.go index 5628bda6ecce..c8a096c29177 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_mx_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_mx_record_test.go @@ -1,4 +1,4 @@ -package privatedns +package tests import ( "fmt" @@ -8,33 +8,25 @@ import ( "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMPrivateDnsMxRecord_basic(t *testing.T) { - resourceName := "azurerm_private_dns_mx_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPrivateDnsMxRecord_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_mx_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsMxRecordDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPrivateDnsMxRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsMxRecordExists(resourceName), + testCheckAzureRMPrivateDnsMxRecordExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,53 +37,42 @@ func TestAccAzureRMPrivateDnsMxRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_private_dns_mx_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_private_dns_mx_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsMxRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateDnsMxRecord_basic(ri, location), + Config: testAccAzureRMPrivateDnsMxRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsMxRecordExists(resourceName), + testCheckAzureRMPrivateDnsMxRecordExists(data.ResourceName), ), }, - { - Config: testAccAzureRMPrivateDnsMxRecord_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_private_dns_mx_record"), - }, + data.RequiresImportErrorStep(testAccAzureRMPrivateDnsMxRecord_requiresImport), }, }) } func TestAccAzureRMPrivateDnsMxRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_private_dns_mx_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsMxRecord_basic(ri, location) - postConfig := testAccAzureRMPrivateDnsMxRecord_updateRecords(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_mx_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsMxRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsMxRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsMxRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "2"), + testCheckAzureRMPrivateDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsMxRecord_updateRecords(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsMxRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "3"), + testCheckAzureRMPrivateDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "3"), ), }, }, @@ -99,61 +80,45 @@ func TestAccAzureRMPrivateDnsMxRecord_updateRecords(t *testing.T) { } func TestAccAzureRMPrivateDnsMxRecord_withTags(t *testing.T) { - resourceName := "azurerm_private_dns_mx_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsMxRecord_withTags(ri, location) - postConfig := testAccAzureRMPrivateDnsMxRecord_withTagsUpdate(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_mx_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsMxRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsMxRecord_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsMxRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMPrivateDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsMxRecord_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsMxRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMPrivateDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPrivateDnsMxRecord_emptyName(t *testing.T) { - resourceName := "azurerm_private_dns_mx_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPrivateDnsMxRecord_emptyName(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_mx_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsMxRecordDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPrivateDnsMxRecord_emptyName(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsMxRecordExists(resourceName), + testCheckAzureRMPrivateDnsMxRecordExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -217,7 +182,7 @@ func testCheckAzureRMPrivateDnsMxRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPrivateDnsMxRecord_basic(rInt int, location string) string { +func testAccAzureRMPrivateDnsMxRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" @@ -244,10 +209,10 @@ resource "azurerm_private_dns_mx_record" "test" { exchange = "mx2.contoso.com" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsMxRecord_emptyName(rInt int, location string) string { +func testAccAzureRMPrivateDnsMxRecord_emptyName(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" @@ -273,11 +238,11 @@ resource "azurerm_private_dns_mx_record" "test" { exchange = "mx2.contoso.com" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPrivateDnsMxRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMPrivateDnsMxRecord_basic(rInt, location) +func testAccAzureRMPrivateDnsMxRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPrivateDnsMxRecord_basic(data) return fmt.Sprintf(` %s @@ -298,7 +263,7 @@ resource "azurerm_private_dns_mx_record" "import" { `, template) } -func testAccAzureRMPrivateDnsMxRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMPrivateDnsMxRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" @@ -328,10 +293,10 @@ resource "azurerm_private_dns_mx_record" "test" { exchange = "backupmx.contoso.com" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsMxRecord_withTags(rInt int, location string) string { +func testAccAzureRMPrivateDnsMxRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" @@ -362,10 +327,10 @@ resource "azurerm_private_dns_mx_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsMxRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMPrivateDnsMxRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" @@ -395,5 +360,5 @@ resource "azurerm_private_dns_mx_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_ptr_record_test.go similarity index 71% rename from azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record_test.go rename to azurerm/internal/services/privatedns/tests/resource_arm_private_dns_ptr_record_test.go index 5e8aede1cb23..2f2b49657529 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_ptr_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_ptr_record_test.go @@ -1,4 +1,4 @@ -package privatedns +package tests import ( "fmt" @@ -8,33 +8,25 @@ import ( "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMPrivateDnsPtrRecord_basic(t *testing.T) { - resourceName := "azurerm_private_dns_ptr_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPrivateDnsPtrRecord_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_ptr_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsPtrRecordDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPrivateDnsPtrRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsPtrRecordExists(resourceName), + testCheckAzureRMPrivateDnsPtrRecordExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,53 +37,42 @@ func TestAccAzureRMPrivateDnsPtrRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_private_dns_ptr_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_private_dns_ptr_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsPtrRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateDnsPtrRecord_basic(ri, location), + Config: testAccAzureRMPrivateDnsPtrRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsPtrRecordExists(resourceName), + testCheckAzureRMPrivateDnsPtrRecordExists(data.ResourceName), ), }, - { - Config: testAccAzureRMPrivateDnsPtrRecord_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_private_dns_ptr_record"), - }, + data.RequiresImportErrorStep(testAccAzureRMPrivateDnsPtrRecord_requiresImport), }, }) } func TestAccAzureRMPrivateDnsPtrRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_private_dns_ptr_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsPtrRecord_basic(ri, location) - postConfig := testAccAzureRMPrivateDnsPtrRecord_updateRecords(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_ptr_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsPtrRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsPtrRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsPtrRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), + testCheckAzureRMPrivateDnsPtrRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsPtrRecord_updateRecords(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsPtrRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "3"), + testCheckAzureRMPrivateDnsPtrRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "3"), ), }, }, @@ -99,36 +80,27 @@ func TestAccAzureRMPrivateDnsPtrRecord_updateRecords(t *testing.T) { } func TestAccAzureRMPrivateDnsPtrRecord_withTags(t *testing.T) { - resourceName := "azurerm_private_dns_ptr_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsPtrRecord_withTags(ri, location) - postConfig := testAccAzureRMPrivateDnsPtrRecord_withTagsUpdate(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_ptr_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsPtrRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsPtrRecord_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsPtrRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMPrivateDnsPtrRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsPtrRecord_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsPtrRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMPrivateDnsPtrRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -192,7 +164,7 @@ func testCheckAzureRMPrivateDnsPtrRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPrivateDnsPtrRecord_basic(rInt int, location string) string { +func testAccAzureRMPrivateDnsPtrRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -211,11 +183,11 @@ resource "azurerm_private_dns_ptr_record" "test" { ttl = 300 records = ["test.contoso.com", "test2.contoso.com"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsPtrRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMPrivateDnsPtrRecord_basic(rInt, location) +func testAccAzureRMPrivateDnsPtrRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPrivateDnsPtrRecord_basic(data) return fmt.Sprintf(` %s @@ -229,7 +201,7 @@ resource "azurerm_private_dns_ptr_record" "import" { `, template) } -func testAccAzureRMPrivateDnsPtrRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMPrivateDnsPtrRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -248,10 +220,10 @@ resource "azurerm_private_dns_ptr_record" "test" { ttl = 300 records = ["test.contoso.com", "test2.contoso.com", "test3.contoso.com"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsPtrRecord_withTags(rInt int, location string) string { +func testAccAzureRMPrivateDnsPtrRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -275,10 +247,10 @@ resource "azurerm_private_dns_ptr_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsPtrRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMPrivateDnsPtrRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -301,5 +273,5 @@ resource "azurerm_private_dns_ptr_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_srv_record_test.go similarity index 74% rename from azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record_test.go rename to azurerm/internal/services/privatedns/tests/resource_arm_private_dns_srv_record_test.go index bf7a85faee81..7b58eb7a2fd0 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_srv_record_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_srv_record_test.go @@ -1,4 +1,4 @@ -package privatedns +package tests import ( "fmt" @@ -8,33 +8,25 @@ import ( "github.com/Azure/azure-sdk-for-go/services/privatedns/mgmt/2018-09-01/privatedns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMPrivateDnsSrvRecord_basic(t *testing.T) { - resourceName := "azurerm_private_dns_srv_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPrivateDnsSrvRecord_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_srv_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsSrvRecordDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPrivateDnsSrvRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsSrvRecordExists(resourceName), + testCheckAzureRMPrivateDnsSrvRecordExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,53 +37,42 @@ func TestAccAzureRMPrivateDnsSrvRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_private_dns_srv_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_private_dns_srv_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsSrvRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateDnsSrvRecord_basic(ri, location), + Config: testAccAzureRMPrivateDnsSrvRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsSrvRecordExists(resourceName), + testCheckAzureRMPrivateDnsSrvRecordExists(data.ResourceName), ), }, - { - Config: testAccAzureRMPrivateDnsSrvRecord_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_private_dns_srv_record"), - }, + data.RequiresImportErrorStep(testAccAzureRMPrivateDnsSrvRecord_requiresImport), }, }) } func TestAccAzureRMPrivateDnsSrvRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_private_dns_srv_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsSrvRecord_basic(ri, location) - postConfig := testAccAzureRMPrivateDnsSrvRecord_updateRecords(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_srv_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsSrvRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsSrvRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsSrvRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "2"), + testCheckAzureRMPrivateDnsSrvRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsSrvRecord_updateRecords(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsSrvRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "3"), + testCheckAzureRMPrivateDnsSrvRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "3"), ), }, }, @@ -99,36 +80,27 @@ func TestAccAzureRMPrivateDnsSrvRecord_updateRecords(t *testing.T) { } func TestAccAzureRMPrivateDnsSrvRecord_withTags(t *testing.T) { - resourceName := "azurerm_private_dns_srv_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsSrvRecord_withTags(ri, location) - postConfig := testAccAzureRMPrivateDnsSrvRecord_withTagsUpdate(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_srv_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsSrvRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsSrvRecord_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsSrvRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMPrivateDnsSrvRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsSrvRecord_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsSrvRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMPrivateDnsSrvRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -192,7 +164,7 @@ func testCheckAzureRMPrivateDnsSrvRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPrivateDnsSrvRecord_basic(rInt int, location string) string { +func testAccAzureRMPrivateDnsSrvRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-prvdns-%d" @@ -223,11 +195,11 @@ resource "azurerm_private_dns_srv_record" "test" { target = "target2.contoso.com" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsSrvRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMPrivateDnsSrvRecord_basic(rInt, location) +func testAccAzureRMPrivateDnsSrvRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPrivateDnsSrvRecord_basic(data) return fmt.Sprintf(` %s @@ -252,7 +224,7 @@ resource "azurerm_private_dns_srv_record" "import" { `, template) } -func testAccAzureRMPrivateDnsSrvRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMPrivateDnsSrvRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -288,10 +260,10 @@ resource "azurerm_private_dns_srv_record" "test" { target = "target3.contoso.com" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsSrvRecord_withTags(rInt int, location string) string { +func testAccAzureRMPrivateDnsSrvRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -326,10 +298,10 @@ resource "azurerm_private_dns_srv_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsSrvRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMPrivateDnsSrvRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -363,5 +335,5 @@ resource "azurerm_private_dns_srv_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_zone_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_test.go similarity index 70% rename from azurerm/internal/services/privatedns/resource_arm_private_dns_zone_test.go rename to azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_test.go index c657da7ef0ca..608a9545973a 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_zone_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_test.go @@ -1,4 +1,4 @@ -package privatedns +package tests import ( "fmt" @@ -7,33 +7,25 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMPrivateDnsZone_basic(t *testing.T) { - resourceName := "azurerm_private_dns_zone.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPrivateDnsZone_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_zone", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsZoneDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPrivateDnsZone_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsZoneExists(resourceName), + testCheckAzureRMPrivateDnsZoneExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,60 +36,45 @@ func TestAccAzureRMPrivateDnsZone_requiresImport(t *testing.T) { return } - resourceName := "azurerm_private_dns_zone.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_private_dns_zone", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateDnsZone_basic(ri, location), + Config: testAccAzureRMPrivateDnsZone_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsZoneExists(resourceName), + testCheckAzureRMPrivateDnsZoneExists(data.ResourceName), ), }, - { - Config: testAccAzureRMPrivateDnsZone_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_private_dns_zone"), - }, + data.RequiresImportErrorStep(testAccAzureRMPrivateDnsZone_requiresImport), }, }) } func TestAccAzureRMPrivateDnsZone_withTags(t *testing.T) { - resourceName := "azurerm_private_dns_zone.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsZone_withTags(ri, location) - postConfig := testAccAzureRMPrivateDnsZone_withTagsUpdate(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_zone", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsZoneDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMPrivateDnsZone_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsZoneExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMPrivateDnsZoneExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsZone_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsZoneExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMPrivateDnsZoneExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -158,7 +135,7 @@ func testCheckAzureRMPrivateDnsZoneDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPrivateDnsZone_basic(rInt int, location string) string { +func testAccAzureRMPrivateDnsZone_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -169,11 +146,11 @@ resource "azurerm_private_dns_zone" "test" { name = "acctestzone%d.com" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPrivateDnsZone_requiresImport(rInt int, location string) string { - template := testAccAzureRMPrivateDnsZone_basic(rInt, location) +func testAccAzureRMPrivateDnsZone_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPrivateDnsZone_basic(data) return fmt.Sprintf(` %s @@ -184,7 +161,7 @@ resource "azurerm_private_dns_zone" "import" { `, template) } -func testAccAzureRMPrivateDnsZone_withTags(rInt int, location string) string { +func testAccAzureRMPrivateDnsZone_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -200,10 +177,10 @@ resource "azurerm_private_dns_zone" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPrivateDnsZone_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMPrivateDnsZone_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -218,5 +195,5 @@ resource "azurerm_private_dns_zone" "test" { environment = "staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/privatedns/resource_arm_private_dns_zone_virtual_network_link_test.go b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_virtual_network_link_test.go similarity index 79% rename from azurerm/internal/services/privatedns/resource_arm_private_dns_zone_virtual_network_link_test.go rename to azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_virtual_network_link_test.go index fb67b5bbed31..01dc536dac24 100644 --- a/azurerm/internal/services/privatedns/resource_arm_private_dns_zone_virtual_network_link_test.go +++ b/azurerm/internal/services/privatedns/tests/resource_arm_private_dns_zone_virtual_network_link_test.go @@ -1,4 +1,4 @@ -package privatedns +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,26 +14,19 @@ import ( ) func TestAccAzureRMPrivateDnsZoneVirtualNetworkLink_basic(t *testing.T) { - resourceName := "azurerm_private_dns_zone_virtual_network_link.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPrivateDnsZoneVirtualNetworkLink_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_zone_virtual_network_link", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPrivateDnsZoneVirtualNetworkLink_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkExists(resourceName), + testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,36 +37,26 @@ func TestAccAzureRMPrivateDnsZoneVirtualNetworkLink_requiresImport(t *testing.T) return } - resourceName := "azurerm_private_dns_zone_virtual_network_link.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_private_dns_zone_virtual_network_link", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateDnsZoneVirtualNetworkLink_basic(ri, location), + Config: testAccAzureRMPrivateDnsZoneVirtualNetworkLink_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkExists(resourceName), + testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkExists(data.ResourceName), ), }, - { - Config: testAccAzureRMPrivateDnsZoneVirtualNetworkLink_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_private_dns_zone_virtual_network_link"), - }, + data.RequiresImportErrorStep(testAccAzureRMPrivateDnsZoneVirtualNetworkLink_requiresImport), }, }) } func TestAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTags(t *testing.T) { - resourceName := "azurerm_private_dns_zone_virtual_network_link.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTags(ri, location) - postConfig := testAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTagsUpdate(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_private_dns_zone_virtual_network_link", "test") + preConfig := testAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTags(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -83,22 +65,18 @@ func TestAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -163,7 +141,7 @@ func testCheckAzureRMPrivateDnsZoneVirtualNetworkLinkDestroy(s *terraform.State) return nil } -func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_basic(rInt int, location string) string { +func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -194,11 +172,11 @@ resource "azurerm_private_dns_zone_virtual_network_link" "test" { resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_requiresImport(rInt int, location string) string { - template := testAccAzureRMPrivateDnsZoneVirtualNetworkLink_basic(rInt, location) +func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPrivateDnsZoneVirtualNetworkLink_basic(data) return fmt.Sprintf(` %s @@ -211,7 +189,7 @@ resource "azurerm_private_dns_zone_virtual_network_link" "import" { `, template) } -func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTags(rInt int, location string) string { +func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -246,10 +224,10 @@ resource "azurerm_private_dns_zone_virtual_network_link" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMPrivateDnsZoneVirtualNetworkLink_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -283,5 +261,5 @@ resource "azurerm_private_dns_zone_virtual_network_link" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } From 00cfa63c0b891f0290f638e89909b21661aac45f Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 17:02:01 +0100 Subject: [PATCH 121/203] postgres: fixing the tests --- .../data_source_postgresql_server_test.go | 48 --- .../data_source_postgresql_server_test.go | 45 +++ ...ource_arm_postgresql_configuration_test.go | 90 ++--- .../resource_arm_postgresql_database_test.go | 89 +++-- ...ource_arm_postgresql_firewall_rule_test.go | 47 +-- .../resource_arm_postgresql_server_test.go | 314 +++++++----------- ...rm_postgresql_virtual_network_rule_test.go | 106 +++--- 7 files changed, 289 insertions(+), 450 deletions(-) delete mode 100644 azurerm/internal/services/postgres/data_source_postgresql_server_test.go create mode 100644 azurerm/internal/services/postgres/tests/data_source_postgresql_server_test.go rename azurerm/internal/services/postgres/{ => tests}/resource_arm_postgresql_configuration_test.go (69%) rename azurerm/internal/services/postgres/{ => tests}/resource_arm_postgresql_database_test.go (76%) rename azurerm/internal/services/postgres/{ => tests}/resource_arm_postgresql_firewall_rule_test.go (76%) rename azurerm/internal/services/postgres/{ => tests}/resource_arm_postgresql_server_test.go (56%) rename azurerm/internal/services/postgres/{ => tests}/resource_arm_postgresql_virtual_network_rule_test.go (84%) diff --git a/azurerm/internal/services/postgres/data_source_postgresql_server_test.go b/azurerm/internal/services/postgres/data_source_postgresql_server_test.go deleted file mode 100644 index a96eb825e1f0..000000000000 --- a/azurerm/internal/services/postgres/data_source_postgresql_server_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package postgres - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMPPostgreSqlServer_basic(t *testing.T) { - dataSourceName := "data.azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - version := "9.5" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMPostgreSqlServer_basic(ri, location, version), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "fqdn"), - resource.TestCheckResourceAttrSet(dataSourceName, "version"), - resource.TestCheckResourceAttrSet(dataSourceName, "administrator_login"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMPostgreSqlServer_basic(rInt int, location string, version string) string { - template := testAccAzureRMPostgreSQLServer_basic(rInt, location, version) - return fmt.Sprintf(` -%s - -data "azurerm_postgresql_server" "test" { - name = "${azurerm_postgresql_server.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, template) -} diff --git a/azurerm/internal/services/postgres/tests/data_source_postgresql_server_test.go b/azurerm/internal/services/postgres/tests/data_source_postgresql_server_test.go new file mode 100644 index 000000000000..58452aa667b4 --- /dev/null +++ b/azurerm/internal/services/postgres/tests/data_source_postgresql_server_test.go @@ -0,0 +1,45 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMPPostgreSqlServer_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_postgresql_server", "test") + version := "9.5" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMPostgreSqlServer_basic(data, version), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), + resource.TestCheckResourceAttrSet(data.ResourceName, "version"), + resource.TestCheckResourceAttrSet(data.ResourceName, "administrator_login"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMPostgreSqlServer_basic(data acceptance.TestData, version string) string { + template := testAccAzureRMPostgreSQLServer_basic(data, version) + return fmt.Sprintf(` +%s + +data "azurerm_postgresql_server" "test" { + name = "${azurerm_postgresql_server.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template) +} diff --git a/azurerm/internal/services/postgres/resource_arm_postgresql_configuration_test.go b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_configuration_test.go similarity index 69% rename from azurerm/internal/services/postgres/resource_arm_postgresql_configuration_test.go rename to azurerm/internal/services/postgres/tests/resource_arm_postgresql_configuration_test.go index c1ebbb9b79a5..a0a28000172d 100644 --- a/azurerm/internal/services/postgres/resource_arm_postgresql_configuration_test.go +++ b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_configuration_test.go @@ -1,4 +1,4 @@ -package postgres +package tests import ( "fmt" @@ -6,37 +6,30 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMPostgreSQLConfiguration_backslashQuote(t *testing.T) { - resourceName := "azurerm_postgresql_configuration.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLConfiguration_backslashQuote(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLConfiguration_backslashQuote(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLConfigurationValue(resourceName, "on"), + testCheckAzureRMPostgreSQLConfigurationValue(data.ResourceName, "on"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMPostgreSQLConfiguration_empty(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLConfiguration_empty(data), Check: resource.ComposeTestCheckFunc( // "delete" resets back to the default value - testCheckAzureRMPostgreSQLConfigurationValueReset(ri, "backslash_quote"), + testCheckAzureRMPostgreSQLConfigurationValueReset(data.RandomInteger, "backslash_quote"), ), }, }, @@ -44,33 +37,24 @@ func TestAccAzureRMPostgreSQLConfiguration_backslashQuote(t *testing.T) { } func TestAccAzureRMPostgreSQLConfiguration_clientMinMessages(t *testing.T) { - resourceName := "azurerm_postgresql_configuration.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMPostgreSQLConfiguration_clientMinMessages(ri, location) - serverOnlyConfig := testAccAzureRMPostgreSQLConfiguration_empty(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLConfigurationDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLConfiguration_clientMinMessages(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLConfigurationValue(resourceName, "DEBUG5"), + testCheckAzureRMPostgreSQLConfigurationValue(data.ResourceName, "DEBUG5"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: serverOnlyConfig, + Config: testAccAzureRMPostgreSQLConfiguration_empty(data), Check: resource.ComposeTestCheckFunc( // "delete" resets back to the default value - testCheckAzureRMPostgreSQLConfigurationValueReset(ri, "client_min_messages"), + testCheckAzureRMPostgreSQLConfigurationValueReset(data.RandomInteger, "client_min_messages"), ), }, }, @@ -78,33 +62,24 @@ func TestAccAzureRMPostgreSQLConfiguration_clientMinMessages(t *testing.T) { } func TestAccAzureRMPostgreSQLConfiguration_deadlockTimeout(t *testing.T) { - resourceName := "azurerm_postgresql_configuration.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMPostgreSQLConfiguration_deadlockTimeout(ri, location) - serverOnlyConfig := testAccAzureRMPostgreSQLConfiguration_empty(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLConfigurationDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLConfiguration_deadlockTimeout(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLConfigurationValue(resourceName, "5000"), + testCheckAzureRMPostgreSQLConfigurationValue(data.ResourceName, "5000"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: serverOnlyConfig, + Config: testAccAzureRMPostgreSQLConfiguration_empty(data), Check: resource.ComposeTestCheckFunc( // "delete" resets back to the default value - testCheckAzureRMPostgreSQLConfigurationValueReset(ri, "deadlock_timeout"), + testCheckAzureRMPostgreSQLConfigurationValueReset(data.RandomInteger, "deadlock_timeout"), ), }, }, @@ -200,32 +175,33 @@ func testCheckAzureRMPostgreSQLConfigurationDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPostgreSQLConfiguration_backslashQuote(rInt int, location string) string { - return testAccAzureRMPostgreSQLConfiguration_template(rInt, location, "backslash_quote", "on") +func testAccAzureRMPostgreSQLConfiguration_backslashQuote(data acceptance.TestData) string { + return testAccAzureRMPostgreSQLConfiguration_template(data, "backslash_quote", "on") } -func testAccAzureRMPostgreSQLConfiguration_clientMinMessages(rInt int, location string) string { - return testAccAzureRMPostgreSQLConfiguration_template(rInt, location, "client_min_messages", "DEBUG5") +func testAccAzureRMPostgreSQLConfiguration_clientMinMessages(data acceptance.TestData) string { + return testAccAzureRMPostgreSQLConfiguration_template(data, "client_min_messages", "DEBUG5") } -func testAccAzureRMPostgreSQLConfiguration_deadlockTimeout(rInt int, location string) string { - return testAccAzureRMPostgreSQLConfiguration_template(rInt, location, "deadlock_timeout", "5000") +func testAccAzureRMPostgreSQLConfiguration_deadlockTimeout(data acceptance.TestData) string { + return testAccAzureRMPostgreSQLConfiguration_template(data, "deadlock_timeout", "5000") } -func testAccAzureRMPostgreSQLConfiguration_template(rInt int, location string, name string, value string) string { - server := testAccAzureRMPostgreSQLConfiguration_empty(rInt, location) - config := fmt.Sprintf(` +func testAccAzureRMPostgreSQLConfiguration_template(data acceptance.TestData, name string, value string) string { + server := testAccAzureRMPostgreSQLConfiguration_empty(data) + return fmt.Sprintf(` +%s + resource "azurerm_postgresql_configuration" "test" { name = "%s" resource_group_name = "${azurerm_resource_group.test.name}" server_name = "${azurerm_postgresql_server.test.name}" value = "%s" } -`, name, value) - return server + config +`, server, name, value) } -func testAccAzureRMPostgreSQLConfiguration_empty(rInt int, location string) string { +func testAccAzureRMPostgreSQLConfiguration_empty(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -255,5 +231,5 @@ resource "azurerm_postgresql_server" "test" { version = "9.6" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/postgres/resource_arm_postgresql_database_test.go b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_database_test.go similarity index 76% rename from azurerm/internal/services/postgres/resource_arm_postgresql_database_test.go rename to azurerm/internal/services/postgres/tests/resource_arm_postgresql_database_test.go index 0fb2631ff966..c03319d7def3 100644 --- a/azurerm/internal/services/postgres/resource_arm_postgresql_database_test.go +++ b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_database_test.go @@ -1,4 +1,4 @@ -package postgres +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,20 +13,18 @@ import ( ) func TestAccAzureRMPostgreSQLDatabase_basic(t *testing.T) { - resourceName := "azurerm_postgresql_database.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLDatabase_basic(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLDatabase_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "charset", "UTF8"), - resource.TestCheckResourceAttr(resourceName, "collation", "English_United States.1252"), + testCheckAzureRMPostgreSQLDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "charset", "UTF8"), + resource.TestCheckResourceAttr(data.ResourceName, "collation", "English_United States.1252"), ), }, }, @@ -40,45 +37,38 @@ func TestAccAzureRMPostgreSQLDatabase_requiresImport(t *testing.T) { return } - resourceName := "azurerm_postgresql_database.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLDatabase_basic(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLDatabase_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "charset", "UTF8"), - resource.TestCheckResourceAttr(resourceName, "collation", "English_United States.1252"), + testCheckAzureRMPostgreSQLDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "charset", "UTF8"), + resource.TestCheckResourceAttr(data.ResourceName, "collation", "English_United States.1252"), ), }, - { - Config: testAccAzureRMPostgreSQLDatabase_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_postgresql_database"), - }, + data.RequiresImportErrorStep(testAccAzureRMPostgreSQLDatabase_requiresImport), }, }) } func TestAccAzureRMPostgreSQLDatabase_collationWithHyphen(t *testing.T) { - resourceName := "azurerm_postgresql_database.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLDatabase_collationWithHyphen(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLDatabase_collationWithHyphen(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "charset", "UTF8"), - resource.TestCheckResourceAttr(resourceName, "collation", "En-US"), + testCheckAzureRMPostgreSQLDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "charset", "UTF8"), + resource.TestCheckResourceAttr(data.ResourceName, "collation", "En-US"), ), }, }, @@ -86,20 +76,18 @@ func TestAccAzureRMPostgreSQLDatabase_collationWithHyphen(t *testing.T) { } func TestAccAzureRMPostgreSQLDatabase_charsetLowercase(t *testing.T) { - resourceName := "azurerm_postgresql_database.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLDatabase_charsetLowercase(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLDatabase_charsetLowercase(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "charset", "UTF8"), - resource.TestCheckResourceAttr(resourceName, "collation", "English_United States.1252"), + testCheckAzureRMPostgreSQLDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "charset", "UTF8"), + resource.TestCheckResourceAttr(data.ResourceName, "collation", "English_United States.1252"), ), }, }, @@ -107,20 +95,18 @@ func TestAccAzureRMPostgreSQLDatabase_charsetLowercase(t *testing.T) { } func TestAccAzureRMPostgreSQLDatabase_charsetMixedcase(t *testing.T) { - resourceName := "azurerm_postgresql_database.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLDatabase_charsetMixedcase(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLDatabase_charsetMixedcase(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "charset", "UTF8"), - resource.TestCheckResourceAttr(resourceName, "collation", "English_United States.1252"), + testCheckAzureRMPostgreSQLDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "charset", "UTF8"), + resource.TestCheckResourceAttr(data.ResourceName, "collation", "English_United States.1252"), ), }, }, @@ -186,7 +172,7 @@ func testCheckAzureRMPostgreSQLDatabaseDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPostgreSQLDatabase_basic(rInt int, location string) string { +func testAccAzureRMPostgreSQLDatabase_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -224,10 +210,11 @@ resource "azurerm_postgresql_database" "test" { charset = "UTF8" collation = "English_United States.1252" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPostgreSQLDatabase_requiresImport(rInt int, location string) string { +func testAccAzureRMPostgreSQLDatabase_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPostgreSQLDatabase_basic(data) return fmt.Sprintf(` %s @@ -238,10 +225,10 @@ resource "azurerm_postgresql_database" "import" { charset = "${azurerm_postgresql_database.test.charset}" collation = "${azurerm_postgresql_database.test.collation}" } -`, testAccAzureRMPostgreSQLDatabase_basic(rInt, location)) +`, template) } -func testAccAzureRMPostgreSQLDatabase_collationWithHyphen(rInt int, location string) string { +func testAccAzureRMPostgreSQLDatabase_collationWithHyphen(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -279,10 +266,10 @@ resource "azurerm_postgresql_database" "test" { charset = "UTF8" collation = "En-US" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPostgreSQLDatabase_charsetLowercase(rInt int, location string) string { +func testAccAzureRMPostgreSQLDatabase_charsetLowercase(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -320,10 +307,10 @@ resource "azurerm_postgresql_database" "test" { charset = "utf8" collation = "English_United States.1252" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPostgreSQLDatabase_charsetMixedcase(rInt int, location string) string { +func testAccAzureRMPostgreSQLDatabase_charsetMixedcase(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -361,5 +348,5 @@ resource "azurerm_postgresql_database" "test" { charset = "Utf8" collation = "English_United States.1252" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/postgres/resource_arm_postgresql_firewall_rule_test.go b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_firewall_rule_test.go similarity index 76% rename from azurerm/internal/services/postgres/resource_arm_postgresql_firewall_rule_test.go rename to azurerm/internal/services/postgres/tests/resource_arm_postgresql_firewall_rule_test.go index 6c9bea10c710..8ba8df15cf5f 100644 --- a/azurerm/internal/services/postgres/resource_arm_postgresql_firewall_rule_test.go +++ b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_firewall_rule_test.go @@ -1,4 +1,4 @@ -package postgres +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,27 +13,21 @@ import ( ) func TestAccAzureRMPostgreSQLFirewallRule_basic(t *testing.T) { - resourceName := "azurerm_postgresql_firewall_rule.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", "0.0.0.0"), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", "255.255.255.255"), + testCheckAzureRMPostgreSQLFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", "0.0.0.0"), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", "255.255.255.255"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,26 +38,21 @@ func TestAccAzureRMPostgreSQLFirewallRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_postgresql_firewall_rule.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLFirewallRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLFirewallRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", "0.0.0.0"), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", "255.255.255.255"), + testCheckAzureRMPostgreSQLFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", "0.0.0.0"), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", "255.255.255.255"), ), }, - { - Config: testAccAzureRMPostgreSQLFirewallRule_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_postgresql_firewall_rule"), - }, + data.RequiresImportErrorStep(testAccAzureRMPostgreSQLFirewallRule_requiresImport), }, }) } @@ -129,7 +117,7 @@ func testCheckAzureRMPostgreSQLFirewallRuleDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPostgreSQLFirewallRule_basic(rInt int, location string) string { +func testAccAzureRMPostgreSQLFirewallRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -167,10 +155,11 @@ resource "azurerm_postgresql_firewall_rule" "test" { start_ip_address = "0.0.0.0" end_ip_address = "255.255.255.255" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPostgreSQLFirewallRule_requiresImport(rInt int, location string) string { +func testAccAzureRMPostgreSQLFirewallRule_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPostgreSQLFirewallRule_basic(data) return fmt.Sprintf(` %s @@ -181,5 +170,5 @@ resource "azurerm_postgresql_firewall_rule" "import" { start_ip_address = "${azurerm_postgresql_firewall_rule.test.start_ip_address}" end_ip_address = "${azurerm_postgresql_firewall_rule.test.end_ip_address}" } -`, testAccAzureRMPostgreSQLFirewallRule_basic(rInt, location)) +`, template) } diff --git a/azurerm/internal/services/postgres/resource_arm_postgresql_server_test.go b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_server_test.go similarity index 56% rename from azurerm/internal/services/postgres/resource_arm_postgresql_server_test.go rename to azurerm/internal/services/postgres/tests/resource_arm_postgresql_server_test.go index e592c3c870bc..5893f078c375 100644 --- a/azurerm/internal/services/postgres/resource_arm_postgresql_server_test.go +++ b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_server_test.go @@ -1,4 +1,4 @@ -package postgres +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,123 +13,85 @@ import ( ) func TestAccAzureRMPostgreSQLServer_basicNinePointFive(t *testing.T) { - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPostgreSQLServer_basicNinePointFive(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLServer_basicNinePointFive(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), - resource.TestCheckResourceAttr(resourceName, "version", "9.5"), - resource.TestCheckResourceAttr(resourceName, "ssl_enforcement", "Enabled"), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "9.5"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_enforcement", "Enabled"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), }, }) } func TestAccAzureRMPostgreSQLServer_basicNinePointSix(t *testing.T) { - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPostgreSQLServer_basicNinePointSix(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLServer_basicNinePointSix(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), - resource.TestCheckResourceAttr(resourceName, "version", "9.6"), - resource.TestCheckResourceAttr(resourceName, "ssl_enforcement", "Enabled"), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "9.6"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_enforcement", "Enabled"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), }, }) } func TestAccAzureRMPostgreSQLServer_basicTenPointZero(t *testing.T) { - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLServer_basicTenPointZero(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLServer_basicTenPointZero(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), - resource.TestCheckResourceAttr(resourceName, "version", "10.0"), - resource.TestCheckResourceAttr(resourceName, "ssl_enforcement", "Enabled"), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "10.0"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_enforcement", "Enabled"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), }, }) } func TestAccAzureRMPostgreSQLServer_basicEleven(t *testing.T) { - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLServer_basicEleven(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLServer_basicEleven(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), - resource.TestCheckResourceAttr(resourceName, "version", "11"), - resource.TestCheckResourceAttr(resourceName, "ssl_enforcement", "Enabled"), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_enforcement", "Enabled"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), }, }) } @@ -141,140 +102,100 @@ func TestAccAzureRMPostgreSQLServer_requiresImport(t *testing.T) { return } - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLServer_basicTenPointZero(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLServer_basicTenPointZero(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), - resource.TestCheckResourceAttr(resourceName, "version", "10.0"), - resource.TestCheckResourceAttr(resourceName, "ssl_enforcement", "Enabled"), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "10.0"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_enforcement", "Enabled"), ), }, - { - Config: testAccAzureRMPostgreSQLServer_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_postgresql_server"), - }, + data.RequiresImportErrorStep(testAccAzureRMPostgreSQLServer_requiresImport), }, }) } func TestAccAzureRMPostgreSQLServer_basicMaxStorage(t *testing.T) { - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPostgreSQLServer_basicMaxStorage(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLServer_basicMaxStorage(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), - resource.TestCheckResourceAttr(resourceName, "version", "9.6"), - resource.TestCheckResourceAttr(resourceName, "ssl_enforcement", "Enabled"), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "9.6"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_enforcement", "Enabled"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), }, }) } func TestAccAzureRMPostgreSQLServer_generalPurpose(t *testing.T) { - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPostgreSQLServer_generalPurpose(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLServer_generalPurpose(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), }, }) } func TestAccAzureRMPostgreSQLServer_memoryOptimized(t *testing.T) { - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPostgreSQLServer_memoryOptimizedGeoRedundant(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLServer_memoryOptimizedGeoRedundant(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "administrator_login_password", // not returned as sensitive - }, - }, + data.ImportStep("administrator_login_password"), }, }) } func TestAccAzureRMPostgreSQLServer_updatePassword(t *testing.T) { - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMPostgreSQLServer_basicNinePointSix(ri, location) - updatedConfig := testAccAzureRMPostgreSQLServer_basicNinePointSixUpdatedPassword(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLServer_basicNinePointSix(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), ), }, { - Config: updatedConfig, + Config: testAccAzureRMPostgreSQLServer_basicNinePointSixUpdatedPassword(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), ), }, }, @@ -282,37 +203,32 @@ func TestAccAzureRMPostgreSQLServer_updatePassword(t *testing.T) { } func TestAccAzureRMPostgreSQLServer_updated(t *testing.T) { - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMPostgreSQLServer_basicNinePointSix(ri, location) - updatedConfig := testAccAzureRMPostgreSQLServer_basicNinePointSixUpdated(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLServer_basicNinePointSix(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_2"), - resource.TestCheckResourceAttr(resourceName, "version", "9.6"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "51200"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Disabled"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_2"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "9.6"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "51200"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.auto_grow", "Disabled"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMPostgreSQLServer_basicNinePointSixUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_4"), - resource.TestCheckResourceAttr(resourceName, "version", "9.6"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "640000"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.auto_grow", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_4"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "9.6"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "640000"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.auto_grow", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, }, @@ -320,39 +236,34 @@ func TestAccAzureRMPostgreSQLServer_updated(t *testing.T) { } func TestAccAzureRMPostgreSQLServer_updateSKU(t *testing.T) { - resourceName := "azurerm_postgresql_server.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMPostgreSQLServer_generalPurpose(ri, location) - updatedConfig := testAccAzureRMPostgreSQLServer_memoryOptimized(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLServerDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLServer_generalPurpose(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "GP_Gen5_32"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "32"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "GeneralPurpose"), - resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen5"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "640000"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "GP_Gen5_32"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "32"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "GeneralPurpose"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "640000"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMPostgreSQLServer_memoryOptimized(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "MO_Gen5_16"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "16"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "MemoryOptimized"), - resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen5"), - resource.TestCheckResourceAttr(resourceName, "storage_profile.0.storage_mb", "4194304"), - resource.TestCheckResourceAttr(resourceName, "administrator_login", "acctestun"), + testCheckAzureRMPostgreSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "MO_Gen5_16"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "16"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "MemoryOptimized"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "Gen5"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_profile.0.storage_mb", "4194304"), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), ), }, }, @@ -419,7 +330,7 @@ func testCheckAzureRMPostgreSQLServerDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPostgreSQLServer_basic(rInt int, location string, version string) string { +func testAccAzureRMPostgreSQLServer_basic(data acceptance.TestData, version string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -450,26 +361,27 @@ resource "azurerm_postgresql_server" "test" { version = "%s" ssl_enforcement = "Enabled" } -`, rInt, location, rInt, version) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, version) } -func testAccAzureRMPostgreSQLServer_basicNinePointFive(rInt int, location string) string { - return testAccAzureRMPostgreSQLServer_basic(rInt, location, "9.5") +func testAccAzureRMPostgreSQLServer_basicNinePointFive(data acceptance.TestData) string { + return testAccAzureRMPostgreSQLServer_basic(data, "9.5") } -func testAccAzureRMPostgreSQLServer_basicNinePointSix(rInt int, location string) string { - return testAccAzureRMPostgreSQLServer_basic(rInt, location, "9.6") +func testAccAzureRMPostgreSQLServer_basicNinePointSix(data acceptance.TestData) string { + return testAccAzureRMPostgreSQLServer_basic(data, "9.6") } -func testAccAzureRMPostgreSQLServer_basicTenPointZero(rInt int, location string) string { - return testAccAzureRMPostgreSQLServer_basic(rInt, location, "10.0") +func testAccAzureRMPostgreSQLServer_basicTenPointZero(data acceptance.TestData) string { + return testAccAzureRMPostgreSQLServer_basic(data, "10.0") } -func testAccAzureRMPostgreSQLServer_basicEleven(rInt int, location string) string { - return testAccAzureRMPostgreSQLServer_basic(rInt, location, "11") +func testAccAzureRMPostgreSQLServer_basicEleven(data acceptance.TestData) string { + return testAccAzureRMPostgreSQLServer_basic(data, "11") } -func testAccAzureRMPostgreSQLServer_requiresImport(rInt int, location string) string { +func testAccAzureRMPostgreSQLServer_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPostgreSQLServer_basicTenPointZero(data) return fmt.Sprintf(` %s @@ -496,10 +408,10 @@ resource "azurerm_postgresql_server" "import" { version = "10.0" ssl_enforcement = "Enabled" } -`, testAccAzureRMPostgreSQLServer_basicTenPointZero(rInt, location)) +`, template) } -func testAccAzureRMPostgreSQLServer_basicNinePointSixUpdatedPassword(rInt int, location string) string { +func testAccAzureRMPostgreSQLServer_basicNinePointSixUpdatedPassword(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -529,10 +441,10 @@ resource "azurerm_postgresql_server" "test" { version = "9.6" ssl_enforcement = "Disabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPostgreSQLServer_basicNinePointSixUpdated(rInt int, location string) string { +func testAccAzureRMPostgreSQLServer_basicNinePointSixUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -562,10 +474,10 @@ resource "azurerm_postgresql_server" "test" { version = "9.6" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPostgreSQLServer_basicMaxStorage(rInt int, location string) string { +func testAccAzureRMPostgreSQLServer_basicMaxStorage(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -596,10 +508,10 @@ resource "azurerm_postgresql_server" "test" { version = "9.6" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPostgreSQLServer_generalPurpose(rInt int, location string) string { +func testAccAzureRMPostgreSQLServer_generalPurpose(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -629,10 +541,10 @@ resource "azurerm_postgresql_server" "test" { version = "9.6" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPostgreSQLServer_memoryOptimized(rInt int, location string) string { +func testAccAzureRMPostgreSQLServer_memoryOptimized(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -662,10 +574,10 @@ resource "azurerm_postgresql_server" "test" { version = "9.6" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPostgreSQLServer_memoryOptimizedGeoRedundant(rInt int, location string) string { +func testAccAzureRMPostgreSQLServer_memoryOptimizedGeoRedundant(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -695,5 +607,5 @@ resource "azurerm_postgresql_server" "test" { version = "9.6" ssl_enforcement = "Enabled" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule_test.go b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_virtual_network_rule_test.go similarity index 84% rename from azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule_test.go rename to azurerm/internal/services/postgres/tests/resource_arm_postgresql_virtual_network_rule_test.go index 082f5762aa65..fbdd341c87fe 100644 --- a/azurerm/internal/services/postgres/resource_arm_postgresql_virtual_network_rule_test.go +++ b/azurerm/internal/services/postgres/tests/resource_arm_postgresql_virtual_network_rule_test.go @@ -1,4 +1,4 @@ -package postgres +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,25 +15,19 @@ import ( ) func TestAccAzureRMPostgreSQLVirtualNetworkRule_basic(t *testing.T) { - resourceName := "azurerm_postgresql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_virtual_network_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLVirtualNetworkRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLVirtualNetworkRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(resourceName), + testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,38 +38,31 @@ func TestAccAzureRMPostgreSQLVirtualNetworkRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_postgresql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_postgresql_virtual_network_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPostgreSQLVirtualNetworkRule_basic(ri, acceptance.Location()), + Config: testAccAzureRMPostgreSQLVirtualNetworkRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(resourceName), + testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(data.ResourceName), ), }, - { - Config: testAccAzureRMPostgreSQLVirtualNetworkRule_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_postgresql_virtual_network_rule"), - }, + data.RequiresImportErrorStep(testAccAzureRMPostgreSQLVirtualNetworkRule_requiresImport), }, }) } func TestAccAzureRMPostgreSQLVirtualNetworkRule_switchSubnets(t *testing.T) { - resourceName := "azurerm_postgresql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() - - preConfig := testAccAzureRMPostgreSQLVirtualNetworkRule_subnetSwitchPre(ri, acceptance.Location()) - postConfig := testAccAzureRMPostgreSQLVirtualNetworkRule_subnetSwitchPost(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_postgresql_virtual_network_rule", "test") + preConfig := testAccAzureRMPostgreSQLVirtualNetworkRule_subnetSwitchPre(data) + postConfig := testAccAzureRMPostgreSQLVirtualNetworkRule_subnetSwitchPost(data) // Create regex strings that will ensure that one subnet name exists, but not the other - preConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet1%d)$|(subnet[^2]%d)$", ri, ri)) //subnet 1 but not 2 - postConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet2%d)$|(subnet[^1]%d)$", ri, ri)) //subnet 2 but not 1 + preConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet1%d)$|(subnet[^2]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 1 but not 2 + postConfigRegex := regexp.MustCompile(fmt.Sprintf("(subnet2%d)$|(subnet[^1]%d)$", data.RandomInteger, data.RandomInteger)) //subnet 2 but not 1 resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,15 +72,15 @@ func TestAccAzureRMPostgreSQLVirtualNetworkRule_switchSubnets(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "subnet_id", preConfigRegex), + testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "subnet_id", preConfigRegex), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "subnet_id", postConfigRegex), + testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "subnet_id", postConfigRegex), ), }, }, @@ -102,20 +88,17 @@ func TestAccAzureRMPostgreSQLVirtualNetworkRule_switchSubnets(t *testing.T) { } func TestAccAzureRMPostgreSQLVirtualNetworkRule_disappears(t *testing.T) { - resourceName := "azurerm_postgresql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPostgreSQLVirtualNetworkRule_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_virtual_network_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLVirtualNetworkRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(resourceName), - testCheckAzureRMPostgreSQLVirtualNetworkRuleDisappears(resourceName), + testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(data.ResourceName), + testCheckAzureRMPostgreSQLVirtualNetworkRuleDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -124,21 +107,18 @@ func TestAccAzureRMPostgreSQLVirtualNetworkRule_disappears(t *testing.T) { } func TestAccAzureRMPostgreSQLVirtualNetworkRule_multipleSubnets(t *testing.T) { - resourceName1 := "azurerm_postgresql_virtual_network_rule.rule1" + data := acceptance.BuildTestData(t, "azurerm_postgresql_virtual_network_rule", "rule1") resourceName2 := "azurerm_postgresql_virtual_network_rule.rule2" resourceName3 := "azurerm_postgresql_virtual_network_rule.rule3" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPostgreSQLVirtualNetworkRule_multipleSubnets(ri, acceptance.Location()) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLVirtualNetworkRule_multipleSubnets(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(resourceName1), + testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(data.ResourceName), testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(resourceName2), testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(resourceName3), ), @@ -148,20 +128,17 @@ func TestAccAzureRMPostgreSQLVirtualNetworkRule_multipleSubnets(t *testing.T) { } func TestAccAzureRMPostgreSQLVirtualNetworkRule_IgnoreEndpointValid(t *testing.T) { - resourceName := "azurerm_postgresql_virtual_network_rule.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPostgreSQLVirtualNetworkRule_ignoreEndpointValid(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_postgresql_virtual_network_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPostgreSQLVirtualNetworkRuleDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMPostgreSQLVirtualNetworkRule_ignoreEndpointValid(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ignore_missing_vnet_service_endpoint", "true"), + testCheckAzureRMPostgreSQLVirtualNetworkRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ignore_missing_vnet_service_endpoint", "true"), ), }, }, @@ -262,7 +239,7 @@ func testCheckAzureRMPostgreSQLVirtualNetworkRuleDisappears(resourceName string) } } -func testAccAzureRMPostgreSQLVirtualNetworkRule_basic(rInt int, location string) string { +func testAccAzureRMPostgreSQLVirtualNetworkRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -313,10 +290,11 @@ resource "azurerm_postgresql_virtual_network_rule" "test" { server_name = "${azurerm_postgresql_server.test.name}" subnet_id = "${azurerm_subnet.test.id}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPostgreSQLVirtualNetworkRule_requiresImport(rInt int, location string) string { +func testAccAzureRMPostgreSQLVirtualNetworkRule_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPostgreSQLVirtualNetworkRule_basic(data) return fmt.Sprintf(` %s @@ -326,10 +304,10 @@ resource "azurerm_postgresql_virtual_network_rule" "import" { server_name = "${azurerm_postgresql_virtual_network_rule.test.server_name}" subnet_id = "${azurerm_postgresql_virtual_network_rule.test.subnet_id}" } -`, testAccAzureRMPostgreSQLVirtualNetworkRule_basic(rInt, location)) +`, template) } -func testAccAzureRMPostgreSQLVirtualNetworkRule_subnetSwitchPre(rInt int, location string) string { +func testAccAzureRMPostgreSQLVirtualNetworkRule_subnetSwitchPre(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -388,10 +366,10 @@ resource "azurerm_postgresql_virtual_network_rule" "test" { server_name = "${azurerm_postgresql_server.test.name}" subnet_id = "${azurerm_subnet.test1.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPostgreSQLVirtualNetworkRule_subnetSwitchPost(rInt int, location string) string { +func testAccAzureRMPostgreSQLVirtualNetworkRule_subnetSwitchPost(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -450,10 +428,10 @@ resource "azurerm_postgresql_virtual_network_rule" "test" { server_name = "${azurerm_postgresql_server.test.name}" subnet_id = "${azurerm_subnet.test2.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPostgreSQLVirtualNetworkRule_multipleSubnets(rInt int, location string) string { +func testAccAzureRMPostgreSQLVirtualNetworkRule_multipleSubnets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -544,10 +522,10 @@ resource "azurerm_postgresql_virtual_network_rule" "rule3" { subnet_id = "${azurerm_subnet.vnet2_subnet1.id}" ignore_missing_vnet_service_endpoint = false } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPostgreSQLVirtualNetworkRule_ignoreEndpointValid(rInt int, location string) string { +func testAccAzureRMPostgreSQLVirtualNetworkRule_ignoreEndpointValid(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -600,5 +578,5 @@ resource "azurerm_postgresql_virtual_network_rule" "test" { subnet_id = "${azurerm_subnet.test.id}" ignore_missing_vnet_service_endpoint = true } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } From d488702d6cb7dc373875bb60bebab97e15215b77 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 17:04:14 +0100 Subject: [PATCH 122/203] portal: fixing the tests --- .../resource_arm_dashboard_test.go | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) rename azurerm/internal/services/portal/{ => tests}/resource_arm_dashboard_test.go (87%) diff --git a/azurerm/internal/services/portal/resource_arm_dashboard_test.go b/azurerm/internal/services/portal/tests/resource_arm_dashboard_test.go similarity index 87% rename from azurerm/internal/services/portal/resource_arm_dashboard_test.go rename to azurerm/internal/services/portal/tests/resource_arm_dashboard_test.go index bd144c95aa45..82509107869d 100644 --- a/azurerm/internal/services/portal/resource_arm_dashboard_test.go +++ b/azurerm/internal/services/portal/tests/resource_arm_dashboard_test.go @@ -1,4 +1,4 @@ -package portal +package tests import ( "fmt" @@ -7,32 +7,24 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccResourceArmDashboard_basic(t *testing.T) { - resourceName := "azurerm_dashboard.test" - ri := tf.AccRandTimeInt() - config := testResourceArmDashboard_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_dashboard", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMDashboardDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testResourceArmDashboard_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDashboardExists(resourceName), + testCheckAzureRMDashboardExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -93,7 +85,7 @@ func testCheckAzureRMDashboardDestroy(s *terraform.State) error { return nil } -func testResourceArmDashboard_basic(rInt int, location string) string { +func testResourceArmDashboard_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test-group" { name = "acctestRG-%d" @@ -137,5 +129,5 @@ resource "azurerm_dashboard" "test" { } DASH } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } From a48795dd38b999e4ff9933e1489f4381df335ba8 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 17:25:24 +0100 Subject: [PATCH 123/203] policy: fixing the tests --- .../data_source_policy_definition_test.go | 50 ++++------ .../resource_arm_policy_assignment_test.go | 98 ++++++------------- .../resource_arm_policy_definition_test.go | 76 +++++--------- ...resource_arm_policy_set_definition_test.go | 80 +++++---------- 4 files changed, 103 insertions(+), 201 deletions(-) rename azurerm/internal/services/policy/{ => tests}/data_source_policy_definition_test.go (51%) rename azurerm/internal/services/policy/{ => tests}/resource_arm_policy_assignment_test.go (79%) rename azurerm/internal/services/policy/{ => tests}/resource_arm_policy_definition_test.go (79%) rename azurerm/internal/services/policy/{ => tests}/resource_arm_policy_set_definition_test.go (82%) diff --git a/azurerm/internal/services/policy/data_source_policy_definition_test.go b/azurerm/internal/services/policy/tests/data_source_policy_definition_test.go similarity index 51% rename from azurerm/internal/services/policy/data_source_policy_definition_test.go rename to azurerm/internal/services/policy/tests/data_source_policy_definition_test.go index e68725a332cb..cfa7a800d3eb 100644 --- a/azurerm/internal/services/policy/data_source_policy_definition_test.go +++ b/azurerm/internal/services/policy/tests/data_source_policy_definition_test.go @@ -1,17 +1,15 @@ -package policy +package tests import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMPolicyDefinition_builtIn(t *testing.T) { - dataSourceName := "data.azurerm_policy_definition.test" + data := acceptance.BuildTestData(t, "data.azurerm_policy_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -19,11 +17,11 @@ func TestAccDataSourceAzureRMPolicyDefinition_builtIn(t *testing.T) { { Config: testAccDataSourceBuiltInPolicyDefinition("Allowed resource types"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "/providers/Microsoft.Authorization/policyDefinitions/a08ec900-254a-4555-9bf5-e42af04b5c5c"), - resource.TestCheckResourceAttr(dataSourceName, "name", "a08ec900-254a-4555-9bf5-e42af04b5c5c"), - resource.TestCheckResourceAttr(dataSourceName, "display_name", "Allowed resource types"), - resource.TestCheckResourceAttr(dataSourceName, "type", "Microsoft.Authorization/policyDefinitions"), - resource.TestCheckResourceAttr(dataSourceName, "description", "This policy enables you to specify the resource types that your organization can deploy. Only resource types that support 'tags' and 'location' will be affected by this policy. To restrict all resources please duplicate this policy and change the 'mode' to 'All'."), + resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/policyDefinitions/a08ec900-254a-4555-9bf5-e42af04b5c5c"), + resource.TestCheckResourceAttr(data.ResourceName, "name", "a08ec900-254a-4555-9bf5-e42af04b5c5c"), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", "Allowed resource types"), + resource.TestCheckResourceAttr(data.ResourceName, "type", "Microsoft.Authorization/policyDefinitions"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This policy enables you to specify the resource types that your organization can deploy. Only resource types that support 'tags' and 'location' will be affected by this policy. To restrict all resources please duplicate this policy and change the 'mode' to 'All'."), ), }, }, @@ -31,7 +29,7 @@ func TestAccDataSourceAzureRMPolicyDefinition_builtIn(t *testing.T) { } func TestAccDataSourceAzureRMPolicyDefinition_builtIn_AtManagementGroup(t *testing.T) { - dataSourceName := "data.azurerm_policy_definition.test" + data := acceptance.BuildTestData(t, "data.azurerm_policy_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -39,7 +37,7 @@ func TestAccDataSourceAzureRMPolicyDefinition_builtIn_AtManagementGroup(t *testi { Config: testAccDataSourceBuiltInPolicyDefinitionAtManagementGroup("Allowed resource types"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "/providers/Microsoft.Authorization/policyDefinitions/a08ec900-254a-4555-9bf5-e42af04b5c5c"), + resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/policyDefinitions/a08ec900-254a-4555-9bf5-e42af04b5c5c"), ), }, }, @@ -47,23 +45,21 @@ func TestAccDataSourceAzureRMPolicyDefinition_builtIn_AtManagementGroup(t *testi } func TestAccDataSourceAzureRMPolicyDefinition_custom(t *testing.T) { - ri := tf.AccRandTimeInt() - dataSourceName := "data.azurerm_policy_definition.test" + data := acceptance.BuildTestData(t, "data.azurerm_policy_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceCustomPolicyDefinition(ri), + Config: testAccDataSourceCustomPolicyDefinition(data), Check: resource.ComposeTestCheckFunc( - testAzureRMAttrExists(dataSourceName, "id"), - resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("acctestpol-%d", ri)), - resource.TestCheckResourceAttr(dataSourceName, "display_name", fmt.Sprintf("acctestpol-%d", ri)), - resource.TestCheckResourceAttr(dataSourceName, "type", "Microsoft.Authorization/policyDefinitions"), - resource.TestCheckResourceAttr(dataSourceName, "policy_type", "Custom"), - resource.TestCheckResourceAttr(dataSourceName, "policy_rule", "{\"if\":{\"not\":{\"field\":\"location\",\"in\":\"[parameters('allowedLocations')]\"}},\"then\":{\"effect\":\"audit\"}}"), - resource.TestCheckResourceAttr(dataSourceName, "parameters", "{\"allowedLocations\":{\"metadata\":{\"description\":\"The list of allowed locations for resources.\",\"displayName\":\"Allowed locations\",\"strongType\":\"location\"},\"type\":\"Array\"}}"), - resource.TestCheckResourceAttrSet(dataSourceName, "metadata"), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctestpol-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", fmt.Sprintf("acctestpol-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "type", "Microsoft.Authorization/policyDefinitions"), + resource.TestCheckResourceAttr(data.ResourceName, "policy_type", "Custom"), + resource.TestCheckResourceAttr(data.ResourceName, "policy_rule", "{\"if\":{\"not\":{\"field\":\"location\",\"in\":\"[parameters('allowedLocations')]\"}},\"then\":{\"effect\":\"audit\"}}"), + resource.TestCheckResourceAttr(data.ResourceName, "parameters", "{\"allowedLocations\":{\"metadata\":{\"description\":\"The list of allowed locations for resources.\",\"displayName\":\"Allowed locations\",\"strongType\":\"location\"},\"type\":\"Array\"}}"), + resource.TestCheckResourceAttrSet(data.ResourceName, "metadata"), ), }, }, @@ -89,7 +85,7 @@ data "azurerm_policy_definition" "test" { `, name) } -func testAccDataSourceCustomPolicyDefinition(ri int) string { +func testAccDataSourceCustomPolicyDefinition(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_policy_definition" "test_policy" { name = "acctestpol-%d" @@ -134,11 +130,5 @@ METADATA data "azurerm_policy_definition" "test" { display_name = "${azurerm_policy_definition.test_policy.display_name}" } -`, ri, ri) -} - -func testAzureRMAttrExists(name, key string) resource.TestCheckFunc { - return func(s *terraform.State) error { - return resource.TestCheckResourceAttrSet(name, key)(s) - } +`, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/policy/resource_arm_policy_assignment_test.go b/azurerm/internal/services/policy/tests/resource_arm_policy_assignment_test.go similarity index 79% rename from azurerm/internal/services/policy/resource_arm_policy_assignment_test.go rename to azurerm/internal/services/policy/tests/resource_arm_policy_assignment_test.go index 3598bf3c9ec7..f08cc2b0ce46 100644 --- a/azurerm/internal/services/policy/resource_arm_policy_assignment_test.go +++ b/azurerm/internal/services/policy/tests/resource_arm_policy_assignment_test.go @@ -1,4 +1,4 @@ -package policy +package tests import ( "fmt" @@ -7,32 +7,25 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMPolicyAssignment_basic(t *testing.T) { - resourceName := "azurerm_policy_assignment.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_assignment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicyAssignmentDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicyAssignment_basic(ri, acceptance.Location()), + Config: testAzureRMPolicyAssignment_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicyAssignmentExists(resourceName), + testCheckAzureRMPolicyAssignmentExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,101 +36,73 @@ func TestAccAzureRMPolicyAssignment_requiresImport(t *testing.T) { return } - resourceName := "azurerm_policy_assignment.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_assignment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicyAssignmentDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicyAssignment_basic(ri, acceptance.Location()), + Config: testAzureRMPolicyAssignment_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicyAssignmentExists(resourceName), + testCheckAzureRMPolicyAssignmentExists(data.ResourceName), ), }, - { - Config: testAzureRMPolicyAssignment_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_policy_assignment"), - }, + data.RequiresImportErrorStep(testAzureRMPolicyAssignment_requiresImport), }, }) } func TestAccAzureRMPolicyAssignment_deployIfNotExists_policy(t *testing.T) { - resourceName := "azurerm_policy_assignment.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_assignment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicyAssignmentDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicyAssignment_deployIfNotExists_policy(ri, acceptance.Location()), + Config: testAzureRMPolicyAssignment_deployIfNotExists_policy(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicyAssignmentExists(resourceName), + testCheckAzureRMPolicyAssignmentExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPolicyAssignment_complete(t *testing.T) { - resourceName := "azurerm_policy_assignment.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_policy_assignment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicyAssignmentDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicyAssignment_complete(ri, location), + Config: testAzureRMPolicyAssignment_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicyAssignmentExists(resourceName), + testCheckAzureRMPolicyAssignmentExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPolicyAssignment_not_scopes(t *testing.T) { - resourceName := "azurerm_policy_assignment.test" - - ri := tf.AccRandTimeInt() - - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_policy_assignment", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicyAssignmentDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicyAssignment_not_scopes(ri, location), + Config: testAzureRMPolicyAssignment_not_scopes(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicyAssignmentExists(resourceName), + testCheckAzureRMPolicyAssignmentExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -190,7 +155,7 @@ func testCheckAzureRMPolicyAssignmentDestroy(s *terraform.State) error { return nil } -func testAzureRMPolicyAssignment_basic(ri int, location string) string { +func testAzureRMPolicyAssignment_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_policy_definition" "test" { name = "acctestpol-%d" @@ -223,10 +188,11 @@ resource "azurerm_policy_assignment" "test" { scope = "${azurerm_resource_group.test.id}" policy_definition_id = "${azurerm_policy_definition.test.id}" } -`, ri, ri, location, ri, location, ri) +`, data.RandomInteger, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAzureRMPolicyAssignment_requiresImport(ri int, location string) string { +func testAzureRMPolicyAssignment_requiresImport(data acceptance.TestData) string { + template := testAzureRMPolicyAssignment_basic(data) return fmt.Sprintf(` %s @@ -235,10 +201,10 @@ resource "azurerm_policy_assignment" "import" { scope = "${azurerm_policy_assignment.test.scope}" policy_definition_id = "${azurerm_policy_assignment.test.policy_definition_id}" } -`, testAzureRMPolicyAssignment_basic(ri, location)) +`, template) } -func testAzureRMPolicyAssignment_deployIfNotExists_policy(ri int, location string) string { +func testAzureRMPolicyAssignment_deployIfNotExists_policy(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_policy_definition" "test" { name = "acctestpol-%d" @@ -313,10 +279,10 @@ resource "azurerm_policy_assignment" "test" { location = "%s" } -`, ri, ri, ri, location, ri, location) +`, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAzureRMPolicyAssignment_complete(ri int, location string) string { +func testAzureRMPolicyAssignment_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_policy_definition" "test" { name = "acctestpol-%d" @@ -372,10 +338,10 @@ resource "azurerm_policy_assignment" "test" { } PARAMETERS } -`, ri, ri, ri, location, ri, ri, location) +`, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.Locations.Primary) } -func testAzureRMPolicyAssignment_not_scopes(ri int, location string) string { +func testAzureRMPolicyAssignment_not_scopes(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_subscription" "current" {} @@ -434,5 +400,5 @@ resource "azurerm_policy_assignment" "test" { } PARAMETERS } -`, ri, ri, ri, location, ri, ri, location) +`, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/policy/resource_arm_policy_definition_test.go b/azurerm/internal/services/policy/tests/resource_arm_policy_definition_test.go similarity index 79% rename from azurerm/internal/services/policy/resource_arm_policy_definition_test.go rename to azurerm/internal/services/policy/tests/resource_arm_policy_definition_test.go index 644f337de7a7..825e44de20bd 100644 --- a/azurerm/internal/services/policy/resource_arm_policy_definition_test.go +++ b/azurerm/internal/services/policy/tests/resource_arm_policy_definition_test.go @@ -1,4 +1,4 @@ -package policy +package tests import ( "fmt" @@ -7,32 +7,25 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMPolicyDefinition_basic(t *testing.T) { - resourceName := "azurerm_policy_definition.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicyDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicyDefinition_basic(ri), + Config: testAzureRMPolicyDefinition_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicyDefinitionExists(resourceName), + testCheckAzureRMPolicyDefinitionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,74 +36,55 @@ func TestAccAzureRMPolicyDefinition_requiresImport(t *testing.T) { return } - resourceName := "azurerm_policy_definition.test" - - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicyDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicyDefinition_basic(ri), + Config: testAzureRMPolicyDefinition_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicyDefinitionExists(resourceName), + testCheckAzureRMPolicyDefinitionExists(data.ResourceName), ), }, - { - Config: testAzureRMPolicyDefinition_requiresImport(ri), - ExpectError: acceptance.RequiresImportError("azurerm_policy_definition"), - }, + data.RequiresImportErrorStep(testAzureRMPolicyDefinition_requiresImport), }, }) } func TestAccAzureRMPolicyDefinition_computedMetadata(t *testing.T) { - resourceName := "azurerm_policy_definition.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicyDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicyDefinition_computedMetadata(ri), + Config: testAzureRMPolicyDefinition_computedMetadata(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicyDefinitionExists(resourceName), + testCheckAzureRMPolicyDefinitionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPolicyDefinitionAtMgmtGroup_basic(t *testing.T) { - resourceName := "azurerm_policy_definition.test" - - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicyDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicyDefinition_ManagementGroup(ri), + Config: testAzureRMPolicyDefinition_ManagementGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicyDefinitionExistsInMgmtGroup(resourceName), + testCheckAzureRMPolicyDefinitionExistsInMgmtGroup(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -191,7 +165,7 @@ func testCheckAzureRMPolicyDefinitionDestroy(s *terraform.State) error { return nil } -func testAzureRMPolicyDefinition_basic(ri int) string { +func testAzureRMPolicyDefinition_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_policy_definition" "test" { name = "acctestpol-%d" @@ -226,11 +200,11 @@ POLICY_RULE } PARAMETERS } -`, ri, ri) +`, data.RandomInteger, data.RandomInteger) } -func testAzureRMPolicyDefinition_requiresImport(ri int) string { - template := testAzureRMPolicyDefinition_basic(ri) +func testAzureRMPolicyDefinition_requiresImport(data acceptance.TestData) string { + template := testAzureRMPolicyDefinition_basic(data) return fmt.Sprintf(` %s @@ -245,7 +219,7 @@ resource "azurerm_policy_definition" "import" { `, template) } -func testAzureRMPolicyDefinition_computedMetadata(rInt int) string { +func testAzureRMPolicyDefinition_computedMetadata(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_policy_definition" "test" { name = "acctest-%d" @@ -276,10 +250,10 @@ resource "azurerm_policy_definition" "test" { } POLICY_RULE } -`, rInt) +`, data.RandomInteger) } -func testAzureRMPolicyDefinition_ManagementGroup(ri int) string { +func testAzureRMPolicyDefinition_ManagementGroup(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_management_group" "test" { display_name = "acctestmg-%d" @@ -319,5 +293,5 @@ POLICY_RULE } PARAMETERS } -`, ri, ri, ri) +`, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/policy/resource_arm_policy_set_definition_test.go b/azurerm/internal/services/policy/tests/resource_arm_policy_set_definition_test.go similarity index 82% rename from azurerm/internal/services/policy/resource_arm_policy_set_definition_test.go rename to azurerm/internal/services/policy/tests/resource_arm_policy_set_definition_test.go index 2cda395c9610..ae5ac4b3142c 100644 --- a/azurerm/internal/services/policy/resource_arm_policy_set_definition_test.go +++ b/azurerm/internal/services/policy/tests/resource_arm_policy_set_definition_test.go @@ -1,4 +1,4 @@ -package policy +package tests import ( "fmt" @@ -13,30 +13,22 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" ) func TestAccAzureRMPolicySetDefinition_builtIn(t *testing.T) { - resourceName := "azurerm_policy_set_definition.test" - - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_set_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicySetDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicySetDefinition_builtIn(ri), + Config: testAzureRMPolicySetDefinition_builtIn(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicySetDefinitionExists(resourceName), + testCheckAzureRMPolicySetDefinitionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,80 +39,60 @@ func TestAccAzureRMPolicySetDefinition_requiresImport(t *testing.T) { return } - resourceName := "azurerm_policy_set_definition.test" - - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_set_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicySetDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicySetDefinition_builtIn(ri), + Config: testAzureRMPolicySetDefinition_builtIn(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicySetDefinitionExists(resourceName), + testCheckAzureRMPolicySetDefinitionExists(data.ResourceName), ), }, - { - Config: testAzureRMPolicySetDefinition_requiresImport(ri), - ExpectError: acceptance.RequiresImportError("azurerm_policy_set_definition"), - }, + data.RequiresImportErrorStep(testAzureRMPolicySetDefinition_requiresImport), }, }) } func TestAccAzureRMPolicySetDefinition_custom(t *testing.T) { - resourceName := "azurerm_policy_set_definition.test" - - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_set_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicySetDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicySetDefinition_custom(ri), + Config: testAzureRMPolicySetDefinition_custom(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicySetDefinitionExists(resourceName), + testCheckAzureRMPolicySetDefinitionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPolicySetDefinition_ManagementGroup(t *testing.T) { - resourceName := "azurerm_policy_set_definition.test" - - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_policy_set_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMPolicySetDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPolicySetDefinition_ManagementGroup(ri), + Config: testAzureRMPolicySetDefinition_ManagementGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPolicySetDefinitionExists(resourceName), + testCheckAzureRMPolicySetDefinitionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAzureRMPolicySetDefinition_builtIn(ri int) string { +func testAzureRMPolicySetDefinition_builtIn(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_policy_set_definition" "test" { name = "acctestpolset-%d" @@ -153,12 +125,12 @@ PARAMETERS ] POLICY_DEFINITIONS } -`, ri, ri) +`, data.RandomInteger, data.RandomInteger) } -func testAzureRMPolicySetDefinition_requiresImport(ri int) string { +func testAzureRMPolicySetDefinition_requiresImport(data acceptance.TestData) string { + template := testAzureRMPolicySetDefinition_builtIn(data) return fmt.Sprintf(` - %s resource "azurerm_policy_set_definition" "import" { @@ -167,10 +139,10 @@ resource "azurerm_policy_set_definition" "import" { display_name = "${azurerm_policy_set_definition.test.display_name}" parameters = "${azurerm_policy_set_definition.test.parameters}" } -`, testAzureRMPolicySetDefinition_builtIn(ri)) +`, template) } -func testAzureRMPolicySetDefinition_custom(ri int) string { +func testAzureRMPolicySetDefinition_custom(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_policy_definition" "test" { name = "acctestpol-%d" @@ -237,10 +209,10 @@ PARAMETERS ] POLICY_DEFINITIONS } -`, ri, ri, ri, ri) +`, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAzureRMPolicySetDefinition_ManagementGroup(ri int) string { +func testAzureRMPolicySetDefinition_ManagementGroup(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_management_group" "test" { display_name = "acctestmg-%d" @@ -278,7 +250,7 @@ PARAMETERS ] POLICY_DEFINITIONS } -`, ri, ri, ri) +`, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMPolicySetDefinitionExists(resourceName string) resource.TestCheckFunc { From aeb331036a310d56a20ab3a128c11114027ca68a Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 17:58:54 +0100 Subject: [PATCH 124/203] notificationhub: fixing the tests --- ..._source_notification_hub_namespace_test.go | 21 +- .../data_source_notification_hub_test.go | 21 +- ...otification_hub_authorization_rule_test.go | 194 +++++++----------- ...rce_arm_notification_hub_namespace_test.go | 66 +++--- .../resource_arm_notification_hub_test.go | 47 ++--- 5 files changed, 136 insertions(+), 213 deletions(-) rename azurerm/internal/services/notificationhub/{ => tests}/data_source_notification_hub_namespace_test.go (54%) rename azurerm/internal/services/notificationhub/{ => tests}/data_source_notification_hub_test.go (57%) rename azurerm/internal/services/notificationhub/{ => tests}/resource_arm_notification_hub_authorization_rule_test.go (64%) rename azurerm/internal/services/notificationhub/{ => tests}/resource_arm_notification_hub_namespace_test.go (75%) rename azurerm/internal/services/notificationhub/{ => tests}/resource_arm_notification_hub_test.go (74%) diff --git a/azurerm/internal/services/notificationhub/data_source_notification_hub_namespace_test.go b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go similarity index 54% rename from azurerm/internal/services/notificationhub/data_source_notification_hub_namespace_test.go rename to azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go index 3909e5c57174..2c210fb3bc63 100644 --- a/azurerm/internal/services/notificationhub/data_source_notification_hub_namespace_test.go +++ b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_namespace_test.go @@ -1,38 +1,33 @@ -package notificationhub +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMNotificationHubNamespace_free(t *testing.T) { - dataSourceName := "data.azurerm_notification_hub_namespace.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMNotificationHubNamespaceFree(rInt, location) - + data := acceptance.BuildTestData(t, "data.azurerm_notification_hub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMNotificationHubNamespaceFree(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "namespace_type", "NotificationHub"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.name", "Free"), + resource.TestCheckResourceAttr(data.ResourceName, "namespace_type", "NotificationHub"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Free"), ), }, }, }) } -func testAccDataSourceAzureRMNotificationHubNamespaceFree(rInt int, location string) string { - r := testAccAzureRMNotificationHubNamespace_free(rInt, location) +func testAccDataSourceAzureRMNotificationHubNamespaceFree(data acceptance.TestData) string { + template := testAccAzureRMNotificationHubNamespace_free(data) return fmt.Sprintf(` %s @@ -40,5 +35,5 @@ data "azurerm_notification_hub_namespace" "test" { name = "${azurerm_notification_hub_namespace.test.name}" resource_group_name = "${azurerm_notification_hub_namespace.test.resource_group_name}" } -`, r) +`, template) } diff --git a/azurerm/internal/services/notificationhub/data_source_notification_hub_test.go b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go similarity index 57% rename from azurerm/internal/services/notificationhub/data_source_notification_hub_test.go rename to azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go index c4600438757e..a50725388c6e 100644 --- a/azurerm/internal/services/notificationhub/data_source_notification_hub_test.go +++ b/azurerm/internal/services/notificationhub/tests/data_source_notification_hub_test.go @@ -1,38 +1,33 @@ -package notificationhub +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMNotificationHub_basic(t *testing.T) { - dataSourceName := "data.azurerm_notification_hub.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMNotificationHubBasic(rInt, location) - + data := acceptance.BuildTestData(t, "data.azurerm_notification_hub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMNotificationHubBasic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "apns_credential.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "gcm_credential.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "apns_credential.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "gcm_credential.#", "0"), ), }, }, }) } -func testAccDataSourceAzureRMNotificationHubBasic(rInt int, location string) string { - r := testAccAzureRMNotificationHub_basic(rInt, location) +func testAccDataSourceAzureRMNotificationHubBasic(data acceptance.TestData) string { + template := testAccAzureRMNotificationHub_basic(data) return fmt.Sprintf(` %s @@ -41,5 +36,5 @@ data "azurerm_notification_hub" "test" { namespace_name = "${azurerm_notification_hub_namespace.test.name}" resource_group_name = "${azurerm_notification_hub_namespace.test.resource_group_name}" } -`, r) +`, template) } diff --git a/azurerm/internal/services/notificationhub/resource_arm_notification_hub_authorization_rule_test.go b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_authorization_rule_test.go similarity index 64% rename from azurerm/internal/services/notificationhub/resource_arm_notification_hub_authorization_rule_test.go rename to azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_authorization_rule_test.go index 81a4cfb7fdbf..3babcaa184cf 100644 --- a/azurerm/internal/services/notificationhub/resource_arm_notification_hub_authorization_rule_test.go +++ b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_authorization_rule_test.go @@ -1,4 +1,4 @@ -package notificationhub +package tests import ( "fmt" @@ -7,37 +7,30 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMNotificationHubAuthorizationRule_listen(t *testing.T) { - resourceName := "azurerm_notification_hub_authorization_rule.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNotificationHubAuthorizationRule_listen(ri, acceptance.Location()), + Config: testAzureRMNotificationHubAuthorizationRule_listen(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMNotificationHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -48,117 +41,93 @@ func TestAccAzureRMNotificationHubAuthorizationRule_requiresImport(t *testing.T) return } - resourceName := "azurerm_notification_hub_authorization_rule.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNotificationHubAuthorizationRule_listen(ri, acceptance.Location()), + Config: testAzureRMNotificationHubAuthorizationRule_listen(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMNotificationHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, - { - Config: testAzureRMNotificationHubAuthorizationRule_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_notification_hub_authorization_rule"), - }, + data.RequiresImportErrorStep(testAzureRMNotificationHubAuthorizationRule_requiresImport), }, }) } func TestAccAzureRMNotificationHubAuthorizationRule_manage(t *testing.T) { - resourceName := "azurerm_notification_hub_authorization_rule.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNotificationHubAuthorizationRule_manage(ri, location), + Config: testAzureRMNotificationHubAuthorizationRule_manage(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "manage", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "true"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMNotificationHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNotificationHubAuthorizationRule_send(t *testing.T) { - resourceName := "azurerm_notification_hub_authorization_rule.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNotificationHubAuthorizationRule_send(ri, location), + Config: testAzureRMNotificationHubAuthorizationRule_send(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), - resource.TestCheckResourceAttr(resourceName, "send", "true"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMNotificationHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNotificationHubAuthorizationRule_multi(t *testing.T) { - resourceOneName := "azurerm_notification_hub_authorization_rule.test1" + data := acceptance.BuildTestData(t, "azurerm_notification_hub_authorization_rule", "test1") resourceTwoName := "azurerm_notification_hub_authorization_rule.test2" resourceThreeName := "azurerm_notification_hub_authorization_rule.test3" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNotificationHubAuthorizationRule_multi(ri, location), + Config: testAzureRMNotificationHubAuthorizationRule_multi(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceOneName), - resource.TestCheckResourceAttr(resourceOneName, "manage", "false"), - resource.TestCheckResourceAttr(resourceOneName, "send", "true"), - resource.TestCheckResourceAttr(resourceOneName, "listen", "true"), - resource.TestCheckResourceAttrSet(resourceOneName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceOneName, "secondary_access_key"), + testCheckAzureRMNotificationHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceTwoName), resource.TestCheckResourceAttr(resourceTwoName, "manage", "false"), resource.TestCheckResourceAttr(resourceTwoName, "send", "true"), @@ -173,11 +142,7 @@ func TestAccAzureRMNotificationHubAuthorizationRule_multi(t *testing.T) { resource.TestCheckResourceAttrSet(resourceThreeName, "secondary_access_key"), ), }, - { - ResourceName: resourceOneName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { ResourceName: resourceTwoName, ImportState: true, @@ -193,36 +158,32 @@ func TestAccAzureRMNotificationHubAuthorizationRule_multi(t *testing.T) { } func TestAccAzureRMNotificationHubAuthorizationRule_updated(t *testing.T) { - resourceName := "azurerm_notification_hub_authorization_rule.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNotificationHubAuthorizationRule_listen(ri, location), + Config: testAzureRMNotificationHubAuthorizationRule_listen(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMNotificationHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, { - Config: testAzureRMNotificationHubAuthorizationRule_manage(ri, location), + Config: testAzureRMNotificationHubAuthorizationRule_manage(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "manage", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "true"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMNotificationHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, }, @@ -284,8 +245,8 @@ func testCheckAzureRMNotificationHubAuthorizationRuleDestroy(s *terraform.State) return nil } -func testAzureRMNotificationHubAuthorizationRule_listen(ri int, location string) string { - template := testAzureRMNotificationHubAuthorizationRule_template(ri, location) +func testAzureRMNotificationHubAuthorizationRule_listen(data acceptance.TestData) string { + template := testAzureRMNotificationHubAuthorizationRule_template(data) return fmt.Sprintf(` %s @@ -296,10 +257,11 @@ resource "azurerm_notification_hub_authorization_rule" "test" { resource_group_name = "${azurerm_resource_group.test.name}" listen = true } -`, template, ri) +`, template, data.RandomInteger) } -func testAzureRMNotificationHubAuthorizationRule_requiresImport(ri int, location string) string { +func testAzureRMNotificationHubAuthorizationRule_requiresImport(data acceptance.TestData) string { + template := testAzureRMNotificationHubAuthorizationRule_listen(data) return fmt.Sprintf(` %s @@ -310,11 +272,11 @@ resource "azurerm_notification_hub_authorization_rule" "import" { resource_group_name = "${azurerm_notification_hub_authorization_rule.test.resource_group_name}" listen = "${azurerm_notification_hub_authorization_rule.test.listen}" } -`, testAzureRMNotificationHubAuthorizationRule_listen(ri, location)) +`, template) } -func testAzureRMNotificationHubAuthorizationRule_send(ri int, location string) string { - template := testAzureRMNotificationHubAuthorizationRule_template(ri, location) +func testAzureRMNotificationHubAuthorizationRule_send(data acceptance.TestData) string { + template := testAzureRMNotificationHubAuthorizationRule_template(data) return fmt.Sprintf(` %s @@ -326,11 +288,11 @@ resource "azurerm_notification_hub_authorization_rule" "test" { send = true listen = true } -`, template, ri) +`, template, data.RandomInteger) } -func testAzureRMNotificationHubAuthorizationRule_multi(ri int, location string) string { - template := testAzureRMNotificationHubAuthorizationRule_template(ri, location) +func testAzureRMNotificationHubAuthorizationRule_multi(data acceptance.TestData) string { + template := testAzureRMNotificationHubAuthorizationRule_template(data) return fmt.Sprintf(` %s @@ -361,11 +323,11 @@ resource "azurerm_notification_hub_authorization_rule" "test3" { listen = true } -`, template, ri, ri, ri) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAzureRMNotificationHubAuthorizationRule_manage(ri int, location string) string { - template := testAzureRMNotificationHubAuthorizationRule_template(ri, location) +func testAzureRMNotificationHubAuthorizationRule_manage(data acceptance.TestData) string { + template := testAzureRMNotificationHubAuthorizationRule_template(data) return fmt.Sprintf(` %s @@ -378,10 +340,10 @@ resource "azurerm_notification_hub_authorization_rule" "test" { send = true listen = true } -`, template, ri) +`, template, data.RandomInteger) } -func testAzureRMNotificationHubAuthorizationRule_template(ri int, location string) string { +func testAzureRMNotificationHubAuthorizationRule_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -405,5 +367,5 @@ resource "azurerm_notification_hub" "test" { resource_group_name = "${azurerm_resource_group.test.name}" location = "${azurerm_resource_group.test.location}" } -`, ri, location, ri, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace_test.go b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go similarity index 75% rename from azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace_test.go rename to azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go index bd14c6f402c1..3418d02a7812 100644 --- a/azurerm/internal/services/notificationhub/resource_arm_notification_hub_namespace_test.go +++ b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_namespace_test.go @@ -1,4 +1,4 @@ -package notificationhub +package tests import ( "fmt" @@ -8,72 +8,58 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMNotificationHubNamespace_free(t *testing.T) { - resourceName := "azurerm_notification_hub_namespace.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNotificationHubNamespace_free(ri, acceptance.Location()), + Config: testAccAzureRMNotificationHubNamespace_free(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubNamespaceExists(resourceName), + testCheckAzureRMNotificationHubNamespaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } // Remove in 2.0 func TestAccAzureRMNotificationHubNamespace_freeClassic(t *testing.T) { - resourceName := "azurerm_notification_hub_namespace.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNotificationHubNamespace_freeClassic(ri, acceptance.Location()), + Config: testAccAzureRMNotificationHubNamespace_freeClassic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubNamespaceExists(resourceName), + testCheckAzureRMNotificationHubNamespaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } // Remove in 2.0 func TestAccAzureRMNotificationHubNamespace_freeNotDefined(t *testing.T) { - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNotificationHubNamespace_freeNotDefined(ri, acceptance.Location()), + Config: testAccAzureRMNotificationHubNamespace_freeNotDefined(data), ExpectError: regexp.MustCompile("either 'sku_name' or 'sku' must be defined in the configuration file"), }, }, @@ -86,24 +72,19 @@ func TestAccAzureRMNotificationHubNamespace_requiresImport(t *testing.T) { return } - resourceName := "azurerm_notification_hub_namespace.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNotificationHubNamespace_free(ri, acceptance.Location()), + Config: testAccAzureRMNotificationHubNamespace_free(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubNamespaceExists(resourceName), + testCheckAzureRMNotificationHubNamespaceExists(data.ResourceName), ), }, - { - Config: testAccAzureRMNotificationHubNamespace_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_notification_hub_namespace"), - }, + data.RequiresImportErrorStep(testAccAzureRMNotificationHubNamespace_requiresImport), }, }) } @@ -159,7 +140,7 @@ func testCheckAzureRMNotificationHubNamespaceDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNotificationHubNamespace_free(ri int, location string) string { +func testAccAzureRMNotificationHubNamespace_free(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -174,10 +155,10 @@ resource "azurerm_notification_hub_namespace" "test" { sku_name = "Free" } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMNotificationHubNamespace_freeClassic(ri int, location string) string { +func testAccAzureRMNotificationHubNamespace_freeClassic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -194,10 +175,10 @@ resource "azurerm_notification_hub_namespace" "test" { name = "Free" } } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMNotificationHubNamespace_freeNotDefined(ri int, location string) string { +func testAccAzureRMNotificationHubNamespace_freeNotDefined(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -210,10 +191,11 @@ resource "azurerm_notification_hub_namespace" "test" { location = "${azurerm_resource_group.test.location}" namespace_type = "NotificationHub" } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMNotificationHubNamespace_requiresImport(ri int, location string) string { +func testAccAzureRMNotificationHubNamespace_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNotificationHubNamespace_free(data) return fmt.Sprintf(` %s @@ -225,5 +207,5 @@ resource "azurerm_notification_hub_namespace" "import" { sku_name = "Free" } -`, testAccAzureRMNotificationHubNamespace_free(ri, location)) +`, template) } diff --git a/azurerm/internal/services/notificationhub/resource_arm_notification_hub_test.go b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go similarity index 74% rename from azurerm/internal/services/notificationhub/resource_arm_notification_hub_test.go rename to azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go index 5f2a35abb6d7..2a124b8e160a 100644 --- a/azurerm/internal/services/notificationhub/resource_arm_notification_hub_test.go +++ b/azurerm/internal/services/notificationhub/tests/resource_arm_notification_hub_test.go @@ -1,4 +1,4 @@ -package notificationhub +package tests import ( "fmt" @@ -7,34 +7,27 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMNotificationHub_basic(t *testing.T) { - resourceName := "azurerm_notification_hub.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNotificationHub_basic(ri, acceptance.Location()), + Config: testAccAzureRMNotificationHub_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "apns_credential.#", "0"), - resource.TestCheckResourceAttr(resourceName, "gcm_credential.#", "0"), + testCheckAzureRMNotificationHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "apns_credential.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "gcm_credential.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,26 +38,21 @@ func TestAccAzureRMNotificationHub_requiresImport(t *testing.T) { return } - resourceName := "azurerm_notification_hub.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_notification_hub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNotificationHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNotificationHub_basic(ri, acceptance.Location()), + Config: testAccAzureRMNotificationHub_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNotificationHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "apns_credential.#", "0"), - resource.TestCheckResourceAttr(resourceName, "gcm_credential.#", "0"), + testCheckAzureRMNotificationHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "apns_credential.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "gcm_credential.#", "0"), ), }, - { - Config: testAccAzureRMNotificationHub_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_notification_hub"), - }, + data.RequiresImportErrorStep(testAccAzureRMNotificationHub_requiresImport), }, }) } @@ -123,7 +111,7 @@ func testCheckAzureRMNotificationHubDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNotificationHub_basic(ri int, location string) string { +func testAccAzureRMNotificationHub_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRGpol-%d" @@ -147,10 +135,11 @@ resource "azurerm_notification_hub" "test" { resource_group_name = "${azurerm_resource_group.test.name}" location = "${azurerm_resource_group.test.location}" } -`, ri, location, ri, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNotificationHub_requiresImport(ri int, location string) string { +func testAccAzureRMNotificationHub_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNotificationHub_basic(data) return fmt.Sprintf(` %s @@ -160,5 +149,5 @@ resource "azurerm_notification_hub" "import" { resource_group_name = "${azurerm_notification_hub.test.resource_group_name}" location = "${azurerm_notification_hub.test.location}" } -`, testAccAzureRMNotificationHub_basic(ri, location)) +`, template) } From c6155789b9cad9602dc73c475161082c2f6912ec Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 08:21:32 -0800 Subject: [PATCH 125/203] netapp: switching to the new test structure --- azurerm/internal/provider/services.go | 2 + .../data_source_netapp_account_test.go | 17 +- .../data_source_netapp_pool_test.go | 23 +-- .../data_source_netapp_volume_test.go | 21 +- .../resource_arm_netapp_account_test.go | 82 +++----- .../resource_arm_netapp_pool_test.go | 88 +++----- .../resource_arm_netapp_volume_test.go | 190 +++++++----------- 7 files changed, 159 insertions(+), 264 deletions(-) rename azurerm/internal/services/netapp/{ => tests}/data_source_netapp_account_test.go (55%) rename azurerm/internal/services/netapp/{ => tests}/data_source_netapp_pool_test.go (50%) rename azurerm/internal/services/netapp/{ => tests}/data_source_netapp_volume_test.go (54%) rename azurerm/internal/services/netapp/{ => tests}/resource_arm_netapp_account_test.go (72%) rename azurerm/internal/services/netapp/{ => tests}/resource_arm_netapp_pool_test.go (69%) rename azurerm/internal/services/netapp/{ => tests}/resource_arm_netapp_volume_test.go (67%) diff --git a/azurerm/internal/provider/services.go b/azurerm/internal/provider/services.go index f6993db64d69..70d8913b5c2f 100644 --- a/azurerm/internal/provider/services.go +++ b/azurerm/internal/provider/services.go @@ -40,6 +40,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/msi" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mssql" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mysql" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/notificationhub" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/policy" @@ -103,6 +104,7 @@ func SupportedServices() []common.ServiceRegistration { msi.Registration{}, mssql.Registration{}, mysql.Registration{}, + netapp.Registration{}, network.Registration{}, notificationhub.Registration{}, policy.Registration{}, diff --git a/azurerm/internal/services/netapp/data_source_netapp_account_test.go b/azurerm/internal/services/netapp/tests/data_source_netapp_account_test.go similarity index 55% rename from azurerm/internal/services/netapp/data_source_netapp_account_test.go rename to azurerm/internal/services/netapp/tests/data_source_netapp_account_test.go index 39b144a4dd55..e0267b233cda 100644 --- a/azurerm/internal/services/netapp/data_source_netapp_account_test.go +++ b/azurerm/internal/services/netapp/tests/data_source_netapp_account_test.go @@ -1,36 +1,33 @@ -package netapp +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func testAccDataSourceAzureRMNetAppAccount_basic(t *testing.T) { - dataSourceName := "data.azurerm_netapp_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_netapp_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceNetAppAccount_basicConfig(ri, location), + Config: testAccDataSourceNetAppAccount_basicConfig(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), ), }, }, }) } -func testAccDataSourceNetAppAccount_basicConfig(rInt int, location string) string { - config := testAccAzureRMNetAppAccount_basicConfig(rInt, location) +func testAccDataSourceNetAppAccount_basicConfig(data acceptance.TestData) string { + config := testAccAzureRMNetAppAccount_basicConfig(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/netapp/data_source_netapp_pool_test.go b/azurerm/internal/services/netapp/tests/data_source_netapp_pool_test.go similarity index 50% rename from azurerm/internal/services/netapp/data_source_netapp_pool_test.go rename to azurerm/internal/services/netapp/tests/data_source_netapp_pool_test.go index 6f0b842d82b4..074ff09041f4 100644 --- a/azurerm/internal/services/netapp/data_source_netapp_pool_test.go +++ b/azurerm/internal/services/netapp/tests/data_source_netapp_pool_test.go @@ -1,39 +1,36 @@ -package netapp +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMNetAppPool_basic(t *testing.T) { - dataSourceName := "data.azurerm_netapp_pool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_netapp_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceNetAppPool_basic(ri, location), + Config: testAccDataSourceNetAppPool_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "account_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "service_level"), - resource.TestCheckResourceAttrSet(dataSourceName, "size_in_tb"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "account_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "service_level"), + resource.TestCheckResourceAttrSet(data.ResourceName, "size_in_tb"), ), }, }, }) } -func testAccDataSourceNetAppPool_basic(rInt int, location string) string { - config := testAccAzureRMNetAppPool_basic(rInt, location) +func testAccDataSourceNetAppPool_basic(data acceptance.TestData) string { + config := testAccAzureRMNetAppPool_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/netapp/data_source_netapp_volume_test.go b/azurerm/internal/services/netapp/tests/data_source_netapp_volume_test.go similarity index 54% rename from azurerm/internal/services/netapp/data_source_netapp_volume_test.go rename to azurerm/internal/services/netapp/tests/data_source_netapp_volume_test.go index 508e7cc7bfc6..2b8d6e59f58e 100644 --- a/azurerm/internal/services/netapp/data_source_netapp_volume_test.go +++ b/azurerm/internal/services/netapp/tests/data_source_netapp_volume_test.go @@ -1,38 +1,35 @@ -package netapp +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMNetAppVolume_basic(t *testing.T) { - dataSourceName := "data.azurerm_netapp_volume.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_netapp_volume", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceNetAppVolume_basic(ri, location), + Config: testAccDataSourceNetAppVolume_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "volume_path"), - resource.TestCheckResourceAttrSet(dataSourceName, "service_level"), - resource.TestCheckResourceAttrSet(dataSourceName, "subnet_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "storage_quota_in_gb"), + resource.TestCheckResourceAttrSet(data.ResourceName, "volume_path"), + resource.TestCheckResourceAttrSet(data.ResourceName, "service_level"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_quota_in_gb"), ), }, }, }) } -func testAccDataSourceNetAppVolume_basic(rInt int, location string) string { - config := testAccAzureRMNetAppVolume_basic(rInt, location) +func testAccDataSourceNetAppVolume_basic(data acceptance.TestData) string { + config := testAccAzureRMNetAppVolume_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/netapp/resource_arm_netapp_account_test.go b/azurerm/internal/services/netapp/tests/resource_arm_netapp_account_test.go similarity index 72% rename from azurerm/internal/services/netapp/resource_arm_netapp_account_test.go rename to azurerm/internal/services/netapp/tests/resource_arm_netapp_account_test.go index 0fb077bf8162..eba360b31b5d 100644 --- a/azurerm/internal/services/netapp/resource_arm_netapp_account_test.go +++ b/azurerm/internal/services/netapp/tests/resource_arm_netapp_account_test.go @@ -1,4 +1,4 @@ -package netapp +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -41,9 +40,7 @@ func TestAccAzureRMNetAppAccount(t *testing.T) { } func testAccAzureRMNetAppAccount_basic(t *testing.T) { - resourceName := "azurerm_netapp_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_netapp_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,16 +48,12 @@ func testAccAzureRMNetAppAccount_basic(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppAccount_basicConfig(ri, location), + Config: testAccAzureRMNetAppAccount_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppAccountExists(resourceName), + testCheckAzureRMNetAppAccountExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -71,8 +64,7 @@ func testAccAzureRMNetAppAccount_requiresImport(t *testing.T) { return } - resourceName := "azurerm_netapp_account.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_netapp_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,13 +72,13 @@ func testAccAzureRMNetAppAccount_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppAccount_basicConfig(ri, acceptance.Location()), + Config: testAccAzureRMNetAppAccount_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppAccountExists(resourceName), + testCheckAzureRMNetAppAccountExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetAppAccount_requiresImportConfig(ri, acceptance.Location()), + Config: testAccAzureRMNetAppAccount_requiresImportConfig(data), ExpectError: acceptance.RequiresImportError("azurerm_netapp_account"), }, }, @@ -94,9 +86,7 @@ func testAccAzureRMNetAppAccount_requiresImport(t *testing.T) { } func testAccAzureRMNetAppAccount_complete(t *testing.T) { - resourceName := "azurerm_netapp_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_netapp_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,28 +94,19 @@ func testAccAzureRMNetAppAccount_complete(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppAccount_completeConfig(ri, location), + Config: testAccAzureRMNetAppAccount_completeConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "active_directory.#", "1"), + testCheckAzureRMNetAppAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "active_directory.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "active_directory", - }, - }, + data.ImportStep("active_directory"), }, }) } func testAccAzureRMNetAppAccount_update(t *testing.T) { - resourceName := "azurerm_netapp_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_netapp_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -133,27 +114,20 @@ func testAccAzureRMNetAppAccount_update(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppAccount_basicConfig(ri, location), + Config: testAccAzureRMNetAppAccount_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "active_directory.#", "0"), + testCheckAzureRMNetAppAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "active_directory.#", "0"), ), }, { - Config: testAccAzureRMNetAppAccount_completeConfig(ri, location), + Config: testAccAzureRMNetAppAccount_completeConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "active_directory.#", "1"), + testCheckAzureRMNetAppAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "active_directory.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "active_directory", - }, - }, + data.ImportStep("active_directory"), }, }) } @@ -206,7 +180,7 @@ func testCheckAzureRMNetAppAccountDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNetAppAccount_basicConfig(rInt int, location string) string { +func testAccAzureRMNetAppAccount_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" @@ -218,10 +192,10 @@ resource "azurerm_netapp_account" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMNetAppAccount_requiresImportConfig(rInt int, location string) string { +func testAccAzureRMNetAppAccount_requiresImportConfig(data acceptance.TestData) string { return fmt.Sprintf(` %s resource "azurerm_netapp_account" "import" { @@ -229,10 +203,10 @@ resource "azurerm_netapp_account" "import" { location = "${azurerm_netapp_account.test.location}" resource_group_name = "${azurerm_netapp_account.test.name}" } -`, testAccAzureRMNetAppAccount_basicConfig(rInt, location)) +`, testAccAzureRMNetAppAccount_basicConfig(data)) } -func testAccAzureRMNetAppAccount_completeConfig(rInt int, location string) string { +func testAccAzureRMNetAppAccount_completeConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" @@ -253,5 +227,5 @@ resource "azurerm_netapp_account" "test" { organizational_unit = "OU=FirstLevel" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/netapp/resource_arm_netapp_pool_test.go b/azurerm/internal/services/netapp/tests/resource_arm_netapp_pool_test.go similarity index 69% rename from azurerm/internal/services/netapp/resource_arm_netapp_pool_test.go rename to azurerm/internal/services/netapp/tests/resource_arm_netapp_pool_test.go index 09cb17a3c409..e4fcd527ac99 100644 --- a/azurerm/internal/services/netapp/resource_arm_netapp_pool_test.go +++ b/azurerm/internal/services/netapp/tests/resource_arm_netapp_pool_test.go @@ -1,4 +1,4 @@ -package netapp +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMNetAppPool_basic(t *testing.T) { - resourceName := "azurerm_netapp_pool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_netapp_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +21,12 @@ func TestAccAzureRMNetAppPool_basic(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppPool_basic(ri, location), + Config: testAccAzureRMNetAppPool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppPoolExists(resourceName), + testCheckAzureRMNetAppPoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,8 +37,7 @@ func TestAccAzureRMNetAppPool_requiresImport(t *testing.T) { return } - resourceName := "azurerm_netapp_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_netapp_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,13 +45,13 @@ func TestAccAzureRMNetAppPool_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppPool_basic(ri, acceptance.Location()), + Config: testAccAzureRMNetAppPool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppPoolExists(resourceName), + testCheckAzureRMNetAppPoolExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetAppPool_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMNetAppPool_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_netapp_pool"), }, }, @@ -67,9 +59,7 @@ func TestAccAzureRMNetAppPool_requiresImport(t *testing.T) { } func TestAccAzureRMNetAppPool_complete(t *testing.T) { - resourceName := "azurerm_netapp_pool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_netapp_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -77,26 +67,20 @@ func TestAccAzureRMNetAppPool_complete(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppPool_complete(ri, location), + Config: testAccAzureRMNetAppPool_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "service_level", "Standard"), - resource.TestCheckResourceAttr(resourceName, "size_in_tb", "15"), + testCheckAzureRMNetAppPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "size_in_tb", "15"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNetAppPool_update(t *testing.T) { - resourceName := "azurerm_netapp_pool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_netapp_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,31 +88,23 @@ func TestAccAzureRMNetAppPool_update(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppPoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppPool_basic(ri, location), + Config: testAccAzureRMNetAppPool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "service_level", "Premium"), - resource.TestCheckResourceAttr(resourceName, "size_in_tb", "4"), + testCheckAzureRMNetAppPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "size_in_tb", "4"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMNetAppPool_complete(ri, location), + Config: testAccAzureRMNetAppPool_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "service_level", "Standard"), - resource.TestCheckResourceAttr(resourceName, "size_in_tb", "15"), + testCheckAzureRMNetAppPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "size_in_tb", "15"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -183,7 +159,7 @@ func testCheckAzureRMNetAppPoolDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNetAppPool_basic(rInt int, location string) string { +func testAccAzureRMNetAppPool_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" @@ -204,10 +180,10 @@ resource "azurerm_netapp_pool" "test" { service_level = "Premium" size_in_tb = 4 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetAppPool_requiresImport(rInt int, location string) string { +func testAccAzureRMNetAppPool_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s resource "azurerm_netapp_pool" "import" { @@ -216,10 +192,10 @@ resource "azurerm_netapp_pool" "import" { resource_group_name = "${azurerm_netapp_pool.test.name}" } } -`, testAccAzureRMNetAppPool_basic(rInt, location)) +`, testAccAzureRMNetAppPool_basic(data)) } -func testAccAzureRMNetAppPool_complete(rInt int, location string) string { +func testAccAzureRMNetAppPool_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" @@ -240,5 +216,5 @@ resource "azurerm_netapp_pool" "test" { service_level = "Standard" size_in_tb = 15 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/netapp/resource_arm_netapp_volume_test.go b/azurerm/internal/services/netapp/tests/resource_arm_netapp_volume_test.go similarity index 67% rename from azurerm/internal/services/netapp/resource_arm_netapp_volume_test.go rename to azurerm/internal/services/netapp/tests/resource_arm_netapp_volume_test.go index 27fc71336ef9..42ff431c3697 100644 --- a/azurerm/internal/services/netapp/resource_arm_netapp_volume_test.go +++ b/azurerm/internal/services/netapp/tests/resource_arm_netapp_volume_test.go @@ -1,4 +1,4 @@ -package netapp +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,7 @@ import ( ) func TestAccAzureRMNetAppVolume_basic(t *testing.T) { - resourceName := "azurerm_netapp_volume.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,16 +22,12 @@ func TestAccAzureRMNetAppVolume_basic(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppVolumeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppVolume_basic(ri, location), + Config: testAccAzureRMNetAppVolume_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppVolumeExists(resourceName), + testCheckAzureRMNetAppVolumeExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,8 +38,7 @@ func TestAccAzureRMNetAppVolume_requiresImport(t *testing.T) { return } - resourceName := "azurerm_netapp_volume.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,13 +46,13 @@ func TestAccAzureRMNetAppVolume_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppVolumeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppVolume_basic(ri, acceptance.Location()), + Config: testAccAzureRMNetAppVolume_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppVolumeExists(resourceName), + testCheckAzureRMNetAppVolumeExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetAppVolume_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMNetAppVolume_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_netapp_volume"), }, }, @@ -68,9 +60,7 @@ func TestAccAzureRMNetAppVolume_requiresImport(t *testing.T) { } func TestAccAzureRMNetAppVolume_complete(t *testing.T) { - resourceName := "azurerm_netapp_volume.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,27 +68,21 @@ func TestAccAzureRMNetAppVolume_complete(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppVolumeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppVolume_complete(ri, location), + Config: testAccAzureRMNetAppVolume_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppVolumeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "service_level", "Premium"), - resource.TestCheckResourceAttr(resourceName, "storage_quota_in_gb", "101"), - resource.TestCheckResourceAttr(resourceName, "export_policy_rule.#", "2"), + testCheckAzureRMNetAppVolumeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "service_level", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_quota_in_gb", "101"), + resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNetAppVolume_update(t *testing.T) { - resourceName := "azurerm_netapp_volume.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -106,57 +90,43 @@ func TestAccAzureRMNetAppVolume_update(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppVolumeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppVolume_basic(ri, location), + Config: testAccAzureRMNetAppVolume_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppVolumeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_quota_in_gb", "100"), - resource.TestCheckResourceAttr(resourceName, "export_policy_rule.#", "0"), + testCheckAzureRMNetAppVolumeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_quota_in_gb", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "0"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMNetAppVolume_complete(ri, location), + Config: testAccAzureRMNetAppVolume_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppVolumeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_quota_in_gb", "101"), - resource.TestCheckResourceAttr(resourceName, "export_policy_rule.#", "2"), + testCheckAzureRMNetAppVolumeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_quota_in_gb", "101"), + resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "2"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMNetAppVolume_basic(ri, location), + Config: testAccAzureRMNetAppVolume_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppVolumeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_quota_in_gb", "100"), - resource.TestCheckResourceAttr(resourceName, "export_policy_rule.#", "0"), + testCheckAzureRMNetAppVolumeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_quota_in_gb", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNetAppVolume_updateSubnet(t *testing.T) { - resourceName := "azurerm_netapp_volume.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resourceGroupName := fmt.Sprintf("acctestRG-netapp-%d", ri) - oldVNetName := fmt.Sprintf("acctest-VirtualNetwork-%d", ri) - oldSubnetName := fmt.Sprintf("acctest-Subnet-%d", ri) - newVNetName := fmt.Sprintf("acctest-updated-VirtualNetwork-%d", ri) - newSubnetName := fmt.Sprintf("acctest-updated-Subnet-%d", ri) + data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test") + resourceGroupName := fmt.Sprintf("acctestRG-netapp-%d", data.RandomInteger) + oldVNetName := fmt.Sprintf("acctest-VirtualNetwork-%d", data.RandomInteger) + oldSubnetName := fmt.Sprintf("acctest-Subnet-%d", data.RandomInteger) + newVNetName := fmt.Sprintf("acctest-updated-VirtualNetwork-%d", data.RandomInteger) + newSubnetName := fmt.Sprintf("acctest-updated-Subnet-%d", data.RandomInteger) uriTemplate := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s" subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") @@ -169,37 +139,27 @@ func TestAccAzureRMNetAppVolume_updateSubnet(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppVolumeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppVolume_basic(ri, location), + Config: testAccAzureRMNetAppVolume_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppVolumeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subnet_id", oldSubnetId), + testCheckAzureRMNetAppVolumeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subnet_id", oldSubnetId), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMNetAppVolume_updateSubnet(ri, location), + Config: testAccAzureRMNetAppVolume_updateSubnet(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppVolumeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subnet_id", newSubnetId), + testCheckAzureRMNetAppVolumeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subnet_id", newSubnetId), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNetAppVolume_updateExportPolicyRule(t *testing.T) { - resourceName := "azurerm_netapp_volume.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_netapp_volume", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -207,29 +167,21 @@ func TestAccAzureRMNetAppVolume_updateExportPolicyRule(t *testing.T) { CheckDestroy: testCheckAzureRMNetAppVolumeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetAppVolume_complete(ri, location), + Config: testAccAzureRMNetAppVolume_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppVolumeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "export_policy_rule.#", "2"), + testCheckAzureRMNetAppVolumeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "2"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMNetAppVolume_updateExportPolicyRule(ri, location), + Config: testAccAzureRMNetAppVolume_updateExportPolicyRule(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetAppVolumeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "export_policy_rule.#", "1"), + testCheckAzureRMNetAppVolumeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "export_policy_rule.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -286,8 +238,8 @@ func testCheckAzureRMNetAppVolumeDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNetAppVolume_basic(rInt int, location string) string { - template := testAccAzureRMNetAppVolume_template(rInt, location) +func testAccAzureRMNetAppVolume_basic(data acceptance.TestData) string { + template := testAccAzureRMNetAppVolume_template(data) return fmt.Sprintf(` %s @@ -302,10 +254,10 @@ resource "azurerm_netapp_volume" "test" { subnet_id = "${azurerm_subnet.test.id}" storage_quota_in_gb = 100 } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetAppVolume_requiresImport(rInt int, location string) string { +func testAccAzureRMNetAppVolume_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -314,11 +266,11 @@ resource "azurerm_netapp_volume" "import" { location = "${azurerm_netapp_volume.test.location}" resource_group_name = "${azurerm_netapp_volume.test.name}" } -`, testAccAzureRMNetAppVolume_basic(rInt, location)) +`, testAccAzureRMNetAppVolume_basic(data)) } -func testAccAzureRMNetAppVolume_complete(rInt int, location string) string { - template := testAccAzureRMNetAppVolume_template(rInt, location) +func testAccAzureRMNetAppVolume_complete(data acceptance.TestData) string { + template := testAccAzureRMNetAppVolume_template(data) return fmt.Sprintf(` %s @@ -353,11 +305,11 @@ resource "azurerm_netapp_volume" "test" { unix_read_write = false } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetAppVolume_updateSubnet(rInt int, location string) string { - template := testAccAzureRMNetAppVolume_template(rInt, location) +func testAccAzureRMNetAppVolume_updateSubnet(data acceptance.TestData) string { + template := testAccAzureRMNetAppVolume_template(data) return fmt.Sprintf(` %s @@ -395,11 +347,11 @@ resource "azurerm_netapp_volume" "test" { subnet_id = "${azurerm_subnet.updated.id}" storage_quota_in_gb = 100 } -`, template, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetAppVolume_updateExportPolicyRule(rInt int, location string) string { - template := testAccAzureRMNetAppVolume_template(rInt, location) +func testAccAzureRMNetAppVolume_updateExportPolicyRule(data acceptance.TestData) string { + template := testAccAzureRMNetAppVolume_template(data) return fmt.Sprintf(` %s @@ -424,10 +376,10 @@ resource "azurerm_netapp_volume" "test" { unix_read_write = true } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetAppVolume_template(rInt int, location string) string { +func testAccAzureRMNetAppVolume_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-netapp-%d" @@ -471,5 +423,5 @@ resource "azurerm_netapp_pool" "test" { service_level = "Premium" size_in_tb = 4 } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } From 81f8a924b486b14a6dee8e83bb6d0eddd200b3c2 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 08:31:52 -0800 Subject: [PATCH 126/203] kusto: switching to the new test structure --- .../internal/services/kusto/registration.go | 6 +- .../resource_arm_kusto_cluster_test.go | 76 ++++++++----------- .../resource_arm_kusto_database_test.go | 70 +++++++---------- ...arm_kusto_eventhub_data_connection_test.go | 22 ++---- 4 files changed, 73 insertions(+), 101 deletions(-) rename azurerm/internal/services/kusto/{ => tests}/resource_arm_kusto_cluster_test.go (67%) rename azurerm/internal/services/kusto/{ => tests}/resource_arm_kusto_database_test.go (77%) rename azurerm/internal/services/kusto/{ => tests}/resource_arm_kusto_eventhub_data_connection_test.go (88%) diff --git a/azurerm/internal/services/kusto/registration.go b/azurerm/internal/services/kusto/registration.go index 9db2a2ced35f..805981e53a7a 100644 --- a/azurerm/internal/services/kusto/registration.go +++ b/azurerm/internal/services/kusto/registration.go @@ -18,5 +18,9 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { - return map[string]*schema.Resource{} + return map[string]*schema.Resource{ + "azurerm_kusto_cluster": resourceArmKustoCluster(), + "azurerm_kusto_database": resourceArmKustoDatabase(), + "azurerm_kusto_eventhub_data_connection": resourceArmKustoEventHubDataConnection(), + } } diff --git a/azurerm/internal/services/kusto/resource_arm_kusto_cluster_test.go b/azurerm/internal/services/kusto/tests/resource_arm_kusto_cluster_test.go similarity index 67% rename from azurerm/internal/services/kusto/resource_arm_kusto_cluster_test.go rename to azurerm/internal/services/kusto/tests/resource_arm_kusto_cluster_test.go index baf04dc18538..3e9dfa646047 100644 --- a/azurerm/internal/services/kusto/resource_arm_kusto_cluster_test.go +++ b/azurerm/internal/services/kusto/tests/resource_arm_kusto_cluster_test.go @@ -1,22 +1,18 @@ -package kusto +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMKustoCluster_basic(t *testing.T) { - resourceName := "azurerm_kusto_cluster.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(6) + data := acceptance.BuildTestData(t, "azurerm_kusto_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,26 +20,20 @@ func TestAccAzureRMKustoCluster_basic(t *testing.T) { CheckDestroy: testCheckAzureRMKustoClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKustoCluster_basic(ri, rs, acceptance.Location()), + Config: testAccAzureRMKustoCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoClusterExists(resourceName), + testCheckAzureRMKustoClusterExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKustoCluster_withTags(t *testing.T) { - resourceName := "azurerm_kusto_cluster.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(6) - preConfig := testAccAzureRMKustoCluster_withTags(ri, rs, acceptance.Location()) - postConfig := testAccAzureRMKustoCluster_withTagsUpdate(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_kusto_cluster", "test") + preConfig := testAccAzureRMKustoCluster_withTags(data) + postConfig := testAccAzureRMKustoCluster_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,18 +43,18 @@ func TestAccAzureRMKustoCluster_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.label", "test"), + testCheckAzureRMKustoClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.label", "test"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.label", "test1"), - resource.TestCheckResourceAttr(resourceName, "tags.ENV", "prod"), + testCheckAzureRMKustoClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.label", "test1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "prod"), ), }, }, @@ -72,11 +62,9 @@ func TestAccAzureRMKustoCluster_withTags(t *testing.T) { } func TestAccAzureRMKustoCluster_sku(t *testing.T) { - resourceName := "azurerm_kusto_cluster.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(6) - preConfig := testAccAzureRMKustoCluster_basic(ri, rs, acceptance.Location()) - postConfig := testAccAzureRMKustoCluster_skuUpdate(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_kusto_cluster", "test") + preConfig := testAccAzureRMKustoCluster_basic(data) + postConfig := testAccAzureRMKustoCluster_skuUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,24 +74,24 @@ func TestAccAzureRMKustoCluster_sku(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Dev(No SLA)_Standard_D11_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), + testCheckAzureRMKustoClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Dev(No SLA)_Standard_D11_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_D11_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "2"), + testCheckAzureRMKustoClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_D11_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "2"), ), }, }, }) } -func testAccAzureRMKustoCluster_basic(rInt int, rs string, location string) string { +func testAccAzureRMKustoCluster_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -120,10 +108,10 @@ resource "azurerm_kusto_cluster" "test" { capacity = 1 } } -`, rInt, location, rs) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMKustoCluster_withTags(rInt int, rs string, location string) string { +func testAccAzureRMKustoCluster_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -144,10 +132,10 @@ resource "azurerm_kusto_cluster" "test" { label = "test" } } -`, rInt, location, rs) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMKustoCluster_withTagsUpdate(rInt int, rs string, location string) string { +func testAccAzureRMKustoCluster_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -169,10 +157,10 @@ resource "azurerm_kusto_cluster" "test" { ENV = "prod" } } -`, rInt, location, rs) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMKustoCluster_skuUpdate(rInt int, rs string, location string) string { +func testAccAzureRMKustoCluster_skuUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -189,7 +177,7 @@ resource "azurerm_kusto_cluster" "test" { capacity = 2 } } -`, rInt, location, rs) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } func testCheckAzureRMKustoClusterDestroy(s *terraform.State) error { diff --git a/azurerm/internal/services/kusto/resource_arm_kusto_database_test.go b/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_test.go similarity index 77% rename from azurerm/internal/services/kusto/resource_arm_kusto_database_test.go rename to azurerm/internal/services/kusto/tests/resource_arm_kusto_database_test.go index b37d5d608212..8956f8199bc9 100644 --- a/azurerm/internal/services/kusto/resource_arm_kusto_database_test.go +++ b/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_test.go @@ -1,22 +1,18 @@ -package kusto +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMKustoDatabase_basic(t *testing.T) { - resourceName := "azurerm_kusto_database.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(6) + data := acceptance.BuildTestData(t, "azurerm_kusto_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,26 +20,20 @@ func TestAccAzureRMKustoDatabase_basic(t *testing.T) { CheckDestroy: testCheckAzureRMKustoDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKustoDatabase_basic(ri, rs, acceptance.Location()), + Config: testAccAzureRMKustoDatabase_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoDatabaseExists(resourceName), + testCheckAzureRMKustoDatabaseExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKustoDatabase_softDeletePeriod(t *testing.T) { - resourceName := "azurerm_kusto_database.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(6) - preConfig := testAccAzureRMKustoDatabase_softDeletePeriod(ri, rs, acceptance.Location()) - postConfig := testAccAzureRMKustoDatabase_softDeletePeriodUpdate(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_kusto_database", "test") + preConfig := testAccAzureRMKustoDatabase_softDeletePeriod(data) + postConfig := testAccAzureRMKustoDatabase_softDeletePeriodUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,15 +43,15 @@ func TestAccAzureRMKustoDatabase_softDeletePeriod(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "soft_delete_period", "P7D"), + testCheckAzureRMKustoDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_period", "P7D"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "soft_delete_period", "P31D"), + testCheckAzureRMKustoDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "soft_delete_period", "P31D"), ), }, }, @@ -69,11 +59,9 @@ func TestAccAzureRMKustoDatabase_softDeletePeriod(t *testing.T) { } func TestAccAzureRMKustoDatabase_hotCachePeriod(t *testing.T) { - resourceName := "azurerm_kusto_database.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(6) - preConfig := testAccAzureRMKustoDatabase_hotCachePeriod(ri, rs, acceptance.Location()) - postConfig := testAccAzureRMKustoDatabase_hotCachePeriodUpdate(ri, rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_kusto_database", "test") + preConfig := testAccAzureRMKustoDatabase_hotCachePeriod(data) + postConfig := testAccAzureRMKustoDatabase_hotCachePeriodUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -83,22 +71,22 @@ func TestAccAzureRMKustoDatabase_hotCachePeriod(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "hot_cache_period", "P7D"), + testCheckAzureRMKustoDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "hot_cache_period", "P7D"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "hot_cache_period", "P14DT12H"), + testCheckAzureRMKustoDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "hot_cache_period", "P14DT12H"), ), }, }, }) } -func testAccAzureRMKustoDatabase_basic(rInt int, rs string, location string) string { +func testAccAzureRMKustoDatabase_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -122,10 +110,10 @@ resource "azurerm_kusto_database" "test" { location = azurerm_resource_group.rg.location cluster_name = azurerm_kusto_cluster.cluster.name } -`, rInt, location, rs, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMKustoDatabase_softDeletePeriod(rInt int, rs string, location string) string { +func testAccAzureRMKustoDatabase_softDeletePeriod(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -151,10 +139,10 @@ resource "azurerm_kusto_database" "test" { soft_delete_period = "P7D" } -`, rInt, location, rs, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMKustoDatabase_softDeletePeriodUpdate(rInt int, rs string, location string) string { +func testAccAzureRMKustoDatabase_softDeletePeriodUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -180,10 +168,10 @@ resource "azurerm_kusto_database" "test" { soft_delete_period = "P31D" } -`, rInt, location, rs, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMKustoDatabase_hotCachePeriod(rInt int, rs string, location string) string { +func testAccAzureRMKustoDatabase_hotCachePeriod(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -209,10 +197,10 @@ resource "azurerm_kusto_database" "test" { hot_cache_period = "P7D" } -`, rInt, location, rs, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMKustoDatabase_hotCachePeriodUpdate(rInt int, rs string, location string) string { +func testAccAzureRMKustoDatabase_hotCachePeriodUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -238,7 +226,7 @@ resource "azurerm_kusto_database" "test" { hot_cache_period = "P14DT12H" } -`, rInt, location, rs, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } func testCheckAzureRMKustoDatabaseDestroy(s *terraform.State) error { diff --git a/azurerm/internal/services/kusto/resource_arm_kusto_eventhub_data_connection_test.go b/azurerm/internal/services/kusto/tests/resource_arm_kusto_eventhub_data_connection_test.go similarity index 88% rename from azurerm/internal/services/kusto/resource_arm_kusto_eventhub_data_connection_test.go rename to azurerm/internal/services/kusto/tests/resource_arm_kusto_eventhub_data_connection_test.go index ba0841e93f50..748b76055cd5 100644 --- a/azurerm/internal/services/kusto/resource_arm_kusto_eventhub_data_connection_test.go +++ b/azurerm/internal/services/kusto/tests/resource_arm_kusto_eventhub_data_connection_test.go @@ -1,22 +1,18 @@ -package kusto +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMKustoEventHubDataConnection_basic(t *testing.T) { - resourceName := "azurerm_kusto_eventhub_data_connection.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(6) + data := acceptance.BuildTestData(t, "azurerm_kusto_eventhub_data_connection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,21 +20,17 @@ func TestAccAzureRMKustoEventHubDataConnection_basic(t *testing.T) { CheckDestroy: testCheckAzureRMKustoEventHubDataConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKustoEventHubDataConnection_basic(ri, rs, acceptance.Location()), + Config: testAccAzureRMKustoEventHubDataConnection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKustoEventHubDataConnectionExists(resourceName), + testCheckAzureRMKustoEventHubDataConnectionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMKustoEventHubDataConnection_basic(rInt int, rs string, location string) string { +func testAccAzureRMKustoEventHubDataConnection_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -95,7 +87,7 @@ resource "azurerm_kusto_eventhub_data_connection" "test" { eventhub_id = "${azurerm_eventhub.test.id}" consumer_group = "${azurerm_eventhub_consumer_group.test.name}" } -`, rInt, location, rs, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMKustoEventHubDataConnectionDestroy(s *terraform.State) error { From 27464150b64f6edd8d798cf888361fe75ad4a210 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 18:12:04 +0100 Subject: [PATCH 127/203] servicebus: fixing up a file that was missed --- .../resource_arm_servicebus_namespace_test.go | 29 +- .../resource_arm_servicebus_queue_test.go | 281 +++++++----------- 2 files changed, 111 insertions(+), 199 deletions(-) rename azurerm/internal/services/servicebus/{ => tests}/resource_arm_servicebus_queue_test.go (65%) diff --git a/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_test.go index 7edaf7cd1874..cd9321579df3 100644 --- a/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_test.go @@ -15,15 +15,13 @@ import ( func TestAccAzureRMServiceBusNamespace_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") - config := testAccAzureRMServiceBusNamespace_basic(data) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMServiceBusNamespace_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), ), @@ -57,15 +55,13 @@ func TestAccAzureRMServiceBusNamespace_requiresImport(t *testing.T) { func TestAccAzureRMServiceBusNamespace_readDefaultKeys(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") - config := testAccAzureRMServiceBusNamespace_basic(data) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMServiceBusNamespace_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), resource.TestMatchResourceAttr( @@ -84,7 +80,6 @@ func TestAccAzureRMServiceBusNamespace_readDefaultKeys(t *testing.T) { func TestAccAzureRMServiceBusNamespace_NonStandardCasing(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") - config := testAccAzureRMServiceBusNamespaceNonStandardCasing(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -92,13 +87,13 @@ func TestAccAzureRMServiceBusNamespace_NonStandardCasing(t *testing.T) { CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMServiceBusNamespaceNonStandardCasing(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), ), }, { - Config: config, + Config: testAccAzureRMServiceBusNamespaceNonStandardCasing(data), PlanOnly: true, ExpectNonEmptyPlan: false, }, @@ -109,15 +104,13 @@ func TestAccAzureRMServiceBusNamespace_NonStandardCasing(t *testing.T) { func TestAccAzureRMServiceBusNamespace_premium(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") - config := testAccAzureRMServiceBusNamespace_premium(data) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMServiceBusNamespace_premium(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), ), @@ -129,15 +122,13 @@ func TestAccAzureRMServiceBusNamespace_premium(t *testing.T) { func TestAccAzureRMServiceBusNamespace_basicCapacity(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") - config := testAccAzureRMServiceBusNamespace_basicCapacity(data) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMServiceBusNamespace_basicCapacity(data), ExpectError: regexp.MustCompile("Service Bus SKU \"Basic\" only supports `capacity` of 0"), }, }, @@ -146,15 +137,13 @@ func TestAccAzureRMServiceBusNamespace_basicCapacity(t *testing.T) { func TestAccAzureRMServiceBusNamespace_premiumCapacity(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") - config := testAccAzureRMServiceBusNamespace_premiumCapacity(data) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMServiceBusNamespace_premiumCapacity(data), ExpectError: regexp.MustCompile("Service Bus SKU \"Premium\" only supports `capacity` of 1, 2, 4 or 8"), }, }, @@ -163,15 +152,13 @@ func TestAccAzureRMServiceBusNamespace_premiumCapacity(t *testing.T) { func TestAccAzureRMServiceBusNamespace_zoneRedundant(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_servicebus_namespace", "test") - config := testAccAzureRMServiceBusNamespace_zoneRedundant(data) - resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusNamespaceDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMServiceBusNamespace_zoneRedundant(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMServiceBusNamespaceExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "zone_redundant", "true"), diff --git a/azurerm/internal/services/servicebus/resource_arm_servicebus_queue_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_queue_test.go similarity index 65% rename from azurerm/internal/services/servicebus/resource_arm_servicebus_queue_test.go rename to azurerm/internal/services/servicebus/tests/resource_arm_servicebus_queue_test.go index 7ad254b3e716..86e79cbda0d6 100644 --- a/azurerm/internal/services/servicebus/resource_arm_servicebus_queue_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_queue_test.go @@ -1,4 +1,4 @@ -package servicebus +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,27 +14,21 @@ import ( ) func TestAccAzureRMServiceBusQueue_basic(t *testing.T) { - resourceName := "azurerm_servicebus_queue.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusQueue_basic(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_express", "false"), - resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "false"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_express", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_partitioning", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,90 +37,72 @@ func TestAccAzureRMServiceBusQueue_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_servicebus_queue.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusQueue_basic(ri, acceptance.Location()), + Config: testAccAzureRMServiceBusQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_express", "false"), - resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "false"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_express", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_partitioning", "false"), ), }, - { - Config: testAccAzureRMServiceBusQueue_requiresImport(ri, acceptance.Location()), - ExpectError: acceptance.RequiresImportError("azurerm_service_fabric_cluster"), - }, + data.RequiresImportErrorStep(testAccAzureRMServiceBusQueue_requiresImport), }, }) } func TestAccAzureRMServiceBusQueue_update(t *testing.T) { - resourceName := "azurerm_servicebus_queue.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusQueue_basic(ri, location) - postConfig := testAccAzureRMServiceBusQueue_update(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMServiceBusQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_express", "false"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_express", "false"), ), }, { - Config: postConfig, + Config: testAccAzureRMServiceBusQueue_update(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "enable_express", "true"), - resource.TestCheckResourceAttr(resourceName, "max_size_in_megabytes", "2048"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_express", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "max_size_in_megabytes", "2048"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusQueue_enablePartitioningStandard(t *testing.T) { - resourceName := "azurerm_servicebus_queue.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusQueue_basic(ri, location) - postConfig := testAccAzureRMServiceBusQueue_enablePartitioningStandard(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMServiceBusQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "false"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_partitioning", "false"), ), }, { - Config: postConfig, + Config: testAccAzureRMServiceBusQueue_enablePartitioningStandard(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_partitioning", "true"), // Ensure size is read back in it's original value and not the x16 value returned by Azure - resource.TestCheckResourceAttr(resourceName, "max_size_in_megabytes", "5120"), + resource.TestCheckResourceAttr(data.ResourceName, "max_size_in_megabytes", "5120"), ), }, }, @@ -135,137 +110,104 @@ func TestAccAzureRMServiceBusQueue_enablePartitioningStandard(t *testing.T) { } func TestAccAzureRMServiceBusQueue_defaultEnablePartitioningPremium(t *testing.T) { - resourceName := "azurerm_servicebus_queue.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusQueue_Premium(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMServiceBusQueue_Premium(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_partitioning", "false"), - resource.TestCheckResourceAttr(resourceName, "enable_express", "false"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_partitioning", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_express", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusQueue_enableDuplicateDetection(t *testing.T) { - resourceName := "azurerm_servicebus_queue.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMServiceBusQueue_basic(ri, location) - postConfig := testAccAzureRMServiceBusQueue_enableDuplicateDetection(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMServiceBusQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "requires_duplicate_detection", "false"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "requires_duplicate_detection", "false"), ), }, { - Config: postConfig, + Config: testAccAzureRMServiceBusQueue_enableDuplicateDetection(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "requires_duplicate_detection", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "requires_duplicate_detection", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusQueue_enableRequiresSession(t *testing.T) { - resourceName := "azurerm_servicebus_queue.test" - location := acceptance.Location() - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusQueue_basic(ri, location), + Config: testAccAzureRMServiceBusQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "requires_session", "false"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "requires_session", "false"), ), }, { - Config: testAccAzureRMServiceBusQueue_enableRequiresSession(ri, location), + Config: testAccAzureRMServiceBusQueue_enableRequiresSession(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "requires_session", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "requires_session", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusQueue_enableDeadLetteringOnMessageExpiration(t *testing.T) { - resourceName := "azurerm_servicebus_queue.test" - location := acceptance.Location() - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusQueue_basic(ri, location), + Config: testAccAzureRMServiceBusQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "dead_lettering_on_message_expiration", "false"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "dead_lettering_on_message_expiration", "false"), ), }, { - Config: testAccAzureRMServiceBusQueue_enableDeadLetteringOnMessageExpiration(ri, location), + Config: testAccAzureRMServiceBusQueue_enableDeadLetteringOnMessageExpiration(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "dead_lettering_on_message_expiration", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "dead_lettering_on_message_expiration", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusQueue_lockDuration(t *testing.T) { - resourceName := "azurerm_servicebus_queue.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - config := testAccAzureRMServiceBusQueue_lockDuration(ri, location) - updatedConfig := testAccAzureRMServiceBusQueue_lockDurationUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") + config := testAccAzureRMServiceBusQueue_lockDuration(data) + updatedConfig := testAccAzureRMServiceBusQueue_lockDurationUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -275,83 +217,65 @@ func TestAccAzureRMServiceBusQueue_lockDuration(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "lock_duration", "PT40S"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "lock_duration", "PT40S"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "lock_duration", "PT2M"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "lock_duration", "PT2M"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusQueue_isoTimeSpanAttributes(t *testing.T) { - resourceName := "azurerm_servicebus_queue.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMServiceBusQueue_isoTimeSpanAttributes(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMServiceBusQueue_isoTimeSpanAttributes(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_delete_on_idle", "PT10M"), - resource.TestCheckResourceAttr(resourceName, "default_message_ttl", "PT30M"), - resource.TestCheckResourceAttr(resourceName, "requires_duplicate_detection", "true"), - resource.TestCheckResourceAttr(resourceName, "duplicate_detection_history_time_window", "PT15M"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_delete_on_idle", "PT10M"), + resource.TestCheckResourceAttr(data.ResourceName, "default_message_ttl", "PT30M"), + resource.TestCheckResourceAttr(data.ResourceName, "requires_duplicate_detection", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "duplicate_detection_history_time_window", "PT15M"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMServiceBusQueue_maxDeliveryCount(t *testing.T) { - resourceName := "azurerm_servicebus_queue.test" - location := acceptance.Location() - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMServiceBusQueue_basic(ri, location), + Config: testAccAzureRMServiceBusQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMServiceBusQueueExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "max_delivery_count", "10"), + testCheckAzureRMServiceBusQueueExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "max_delivery_count", "10"), ), }, { - Config: testAccAzureRMServiceBusQueue_maxDeliveryCount(ri, location), + Config: testAccAzureRMServiceBusQueue_maxDeliveryCount(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "max_delivery_count", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "max_delivery_count", "20"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -416,7 +340,7 @@ func testCheckAzureRMServiceBusQueueExists(resourceName string) resource.TestChe } } -func testAccAzureRMServiceBusQueue_basic(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -435,10 +359,11 @@ resource "azurerm_servicebus_queue" "test" { resource_group_name = "${azurerm_resource_group.test.name}" namespace_name = "${azurerm_servicebus_namespace.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusQueue_requiresImport(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMServiceBusQueue_basic(data) return fmt.Sprintf(` %s @@ -447,10 +372,10 @@ resource "azurerm_servicebus_queue" "import" { resource_group_name = "${azurerm_servicebus_queue.test.resource_group_name}" namespace_name = "${azurerm_servicebus_queue.test.namespace_name}" } -`, testAccAzureRMServiceBusQueue_basic(rInt, location)) +`, template) } -func testAccAzureRMServiceBusQueue_Premium(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_Premium(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -472,10 +397,10 @@ resource "azurerm_servicebus_queue" "test" { enable_partitioning = false enable_express = false } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusQueue_update(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -496,10 +421,10 @@ resource "azurerm_servicebus_queue" "test" { enable_express = true max_size_in_megabytes = 2048 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusQueue_enablePartitioningStandard(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_enablePartitioningStandard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -520,10 +445,10 @@ resource "azurerm_servicebus_queue" "test" { enable_partitioning = true max_size_in_megabytes = 5120 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusQueue_enableDuplicateDetection(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_enableDuplicateDetection(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -543,10 +468,10 @@ resource "azurerm_servicebus_queue" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" requires_duplicate_detection = true } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusQueue_enableRequiresSession(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_enableRequiresSession(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -567,10 +492,10 @@ resource "azurerm_servicebus_queue" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" requires_session = true } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusQueue_enableDeadLetteringOnMessageExpiration(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_enableDeadLetteringOnMessageExpiration(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -591,10 +516,10 @@ resource "azurerm_servicebus_queue" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" dead_lettering_on_message_expiration = true } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusQueue_lockDuration(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_lockDuration(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -614,10 +539,10 @@ resource "azurerm_servicebus_queue" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" lock_duration = "PT40S" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusQueue_lockDurationUpdated(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_lockDurationUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -637,10 +562,10 @@ resource "azurerm_servicebus_queue" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" lock_duration = "PT2M" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusQueue_isoTimeSpanAttributes(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_isoTimeSpanAttributes(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -663,10 +588,10 @@ resource "azurerm_servicebus_queue" "test" { requires_duplicate_detection = true duplicate_detection_history_time_window = "PT15M" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMServiceBusQueue_maxDeliveryCount(rInt int, location string) string { +func testAccAzureRMServiceBusQueue_maxDeliveryCount(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -686,5 +611,5 @@ resource "azurerm_servicebus_queue" "test" { namespace_name = "${azurerm_servicebus_namespace.test.name}" max_delivery_count = 20 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } From 11602375b6ad2c65248e66319c2ddae22f4cc9c3 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Sat, 21 Dec 2019 09:07:44 -0800 Subject: [PATCH 128/203] applicationinsights --- ...arm_application_insights_analytics_item.go | 8 +- .../data_source_application_insights_test.go | 25 ++- ...pplication_insights_analytics_item_test.go | 99 +++++------ ...e_arm_application_insights_api_key_test.go | 112 +++++-------- .../resource_arm_application_insights_test.go | 154 +++++++----------- ..._arm_application_insights_webtests_test.go | 89 ++++------ 6 files changed, 183 insertions(+), 304 deletions(-) rename azurerm/internal/services/applicationinsights/{ => tests}/data_source_application_insights_test.go (56%) rename azurerm/internal/services/applicationinsights/{ => tests}/resource_arm_application_insights_analytics_item_test.go (73%) rename azurerm/internal/services/applicationinsights/{ => tests}/resource_arm_application_insights_api_key_test.go (61%) rename azurerm/internal/services/applicationinsights/{ => tests}/resource_arm_application_insights_test.go (61%) rename azurerm/internal/services/applicationinsights/{ => tests}/resource_arm_application_insights_webtests_test.go (72%) diff --git a/azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item.go index e1c0a17e7002..4522036afd20 100644 --- a/azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item.go @@ -118,7 +118,7 @@ func resourceArmApplicationInsightsAnalyticsItemCreateUpdate(d *schema.ResourceD id := d.Id() itemID := "" if id != "" { - _, _, _, itemID, err = resourcesArmApplicationInsightsAnalyticsItemParseID(id) + _, _, _, itemID, err = ResourcesArmApplicationInsightsAnalyticsItemParseID(id) if err != nil { return fmt.Errorf("Error parsing Application Insights Analytics Item ID %s: %s", id, err) } @@ -169,7 +169,7 @@ func resourceArmApplicationInsightsAnalyticsItemRead(d *schema.ResourceData, met defer cancel() id := d.Id() - resourceGroupName, appInsightsName, itemScopePath, itemID, err := resourcesArmApplicationInsightsAnalyticsItemParseID(id) + resourceGroupName, appInsightsName, itemScopePath, itemID, err := ResourcesArmApplicationInsightsAnalyticsItemParseID(id) if err != nil { return fmt.Errorf("Error parsing Application Insights Analytics Item ID %s: %s", id, err) } @@ -203,7 +203,7 @@ func resourceArmApplicationInsightsAnalyticsItemDelete(d *schema.ResourceData, m defer cancel() id := d.Id() - resourceGroupName, appInsightsName, itemScopePath, itemID, err := resourcesArmApplicationInsightsAnalyticsItemParseID(id) + resourceGroupName, appInsightsName, itemScopePath, itemID, err := ResourcesArmApplicationInsightsAnalyticsItemParseID(id) if err != nil { return fmt.Errorf("Error parsing Application Insights Analytics Item ID %s: %s", id, err) } @@ -216,7 +216,7 @@ func resourceArmApplicationInsightsAnalyticsItemDelete(d *schema.ResourceData, m return nil } -func resourcesArmApplicationInsightsAnalyticsItemParseID(id string) (string, string, insights.ItemScopePath, string, error) { +func ResourcesArmApplicationInsightsAnalyticsItemParseID(id string) (string, string, insights.ItemScopePath, string, error) { resourceID, err := azure.ParseAzureResourceID(id) if err != nil { return "", "", "", "", fmt.Errorf("Error parsing resource ID: %s", err) diff --git a/azurerm/internal/services/applicationinsights/data_source_application_insights_test.go b/azurerm/internal/services/applicationinsights/tests/data_source_application_insights_test.go similarity index 56% rename from azurerm/internal/services/applicationinsights/data_source_application_insights_test.go rename to azurerm/internal/services/applicationinsights/tests/data_source_application_insights_test.go index 0385682ae869..c189f74ff801 100644 --- a/azurerm/internal/services/applicationinsights/data_source_application_insights_test.go +++ b/azurerm/internal/services/applicationinsights/tests/data_source_application_insights_test.go @@ -1,40 +1,37 @@ -package applicationinsights +package tests import ( "fmt" "testing" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccDataSourceApplicationInsights_basic(t *testing.T) { - dataSourceName := "data.azurerm_application_insights.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_application_insights", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccResourceApplicationInsights_complete(ri, location), + Config: testAccResourceApplicationInsights_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "instrumentation_key"), - resource.TestCheckResourceAttrSet(dataSourceName, "app_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttr(dataSourceName, "application_type", "other"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.foo", "bar"), + resource.TestCheckResourceAttrSet(data.ResourceName, "instrumentation_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "app_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttr(data.ResourceName, "application_type", "other"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.foo", "bar"), ), }, }, }) } -func testAccResourceApplicationInsights_complete(rInt int, location string) string { +func testAccResourceApplicationInsights_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -56,5 +53,5 @@ data "azurerm_application_insights" "test" { resource_group_name = "${azurerm_resource_group.test.name}" name = "${azurerm_application_insights.test.name}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go similarity index 73% rename from azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item_test.go rename to azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go index f8ad114f2b3c..5836c3be158e 100644 --- a/azurerm/internal/services/applicationinsights/resource_arm_application_insights_analytics_item_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go @@ -1,20 +1,19 @@ -package applicationinsights +package tests import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/applicationinsights" "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/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMApplicationInsightsAnalyticsItem_basic(t *testing.T) { - resourceName := "azurerm_application_insights_analytics_item.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsightsAnalyticsItem_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_application_insights_analytics_item", "test") + config := testAccAzureRMApplicationInsightsAnalyticsItem_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,27 +23,22 @@ func TestAccAzureRMApplicationInsightsAnalyticsItem_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsAnalyticsItemExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "testquery"), - resource.TestCheckResourceAttr(resourceName, "scope", "shared"), - resource.TestCheckResourceAttr(resourceName, "type", "query"), - resource.TestCheckResourceAttr(resourceName, "content", "requests #test"), + testCheckAzureRMApplicationInsightsAnalyticsItemExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "testquery"), + resource.TestCheckResourceAttr(data.ResourceName, "scope", "shared"), + resource.TestCheckResourceAttr(data.ResourceName, "type", "query"), + resource.TestCheckResourceAttr(data.ResourceName, "content", "requests #test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationInsightsAnalyticsItem_update(t *testing.T) { - resourceName := "azurerm_application_insights_analytics_item.test" - ri := tf.AccRandTimeInt() - config1 := testAccAzureRMApplicationInsightsAnalyticsItem_basic(ri, acceptance.Location()) - config2 := testAccAzureRMApplicationInsightsAnalyticsItem_basic2(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_application_insights_analytics_item", "test") + config1 := testAccAzureRMApplicationInsightsAnalyticsItem_basic(data) + config2 := testAccAzureRMApplicationInsightsAnalyticsItem_basic2(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,43 +48,34 @@ func TestAccAzureRMApplicationInsightsAnalyticsItem_update(t *testing.T) { { Config: config1, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsAnalyticsItemExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "testquery"), - resource.TestCheckResourceAttr(resourceName, "scope", "shared"), - resource.TestCheckResourceAttr(resourceName, "type", "query"), - resource.TestCheckResourceAttr(resourceName, "content", "requests #test"), + testCheckAzureRMApplicationInsightsAnalyticsItemExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "testquery"), + resource.TestCheckResourceAttr(data.ResourceName, "scope", "shared"), + resource.TestCheckResourceAttr(data.ResourceName, "type", "query"), + resource.TestCheckResourceAttr(data.ResourceName, "content", "requests #test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: config2, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsAnalyticsItemExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "testquery"), - resource.TestCheckResourceAttr(resourceName, "scope", "shared"), - resource.TestCheckResourceAttr(resourceName, "type", "query"), - resource.TestCheckResourceAttr(resourceName, "content", "requests #updated"), + testCheckAzureRMApplicationInsightsAnalyticsItemExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "testquery"), + resource.TestCheckResourceAttr(data.ResourceName, "scope", "shared"), + resource.TestCheckResourceAttr(data.ResourceName, "type", "query"), + resource.TestCheckResourceAttr(data.ResourceName, "content", "requests #updated"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationInsightsAnalyticsItem_multiple(t *testing.T) { - resourceName1 := "azurerm_application_insights_analytics_item.test1" + data := acceptance.BuildTestData(t, "azurerm_application_insights_analytics_item", "test") resourceName2 := "azurerm_application_insights_analytics_item.test2" resourceName3 := "azurerm_application_insights_analytics_item.test3" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsightsAnalyticsItem_multiple(ri, acceptance.Location()) + config := testAccAzureRMApplicationInsightsAnalyticsItem_multiple(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -100,13 +85,13 @@ func TestAccAzureRMApplicationInsightsAnalyticsItem_multiple(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsAnalyticsItemExists(resourceName1), + testCheckAzureRMApplicationInsightsAnalyticsItemExists(data.ResourceName), testCheckAzureRMApplicationInsightsAnalyticsItemExists(resourceName2), testCheckAzureRMApplicationInsightsAnalyticsItemExists(resourceName3), - resource.TestCheckResourceAttr(resourceName1, "name", "testquery1"), - resource.TestCheckResourceAttr(resourceName1, "scope", "shared"), - resource.TestCheckResourceAttr(resourceName1, "type", "query"), - resource.TestCheckResourceAttr(resourceName1, "content", "requests #test1"), + resource.TestCheckResourceAttr(data.ResourceName, "name", "testquery1"), + resource.TestCheckResourceAttr(data.ResourceName, "scope", "shared"), + resource.TestCheckResourceAttr(data.ResourceName, "type", "query"), + resource.TestCheckResourceAttr(data.ResourceName, "content", "requests #test1"), resource.TestCheckResourceAttr(resourceName2, "name", "testquery2"), resource.TestCheckResourceAttr(resourceName2, "scope", "user"), resource.TestCheckResourceAttr(resourceName2, "type", "query"), @@ -118,11 +103,7 @@ func TestAccAzureRMApplicationInsightsAnalyticsItem_multiple(t *testing.T) { resource.TestCheckResourceAttr(resourceName3, "function_alias", "myfunction"), ), }, - { - ResourceName: resourceName1, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { ResourceName: resourceName2, ImportState: true, @@ -181,7 +162,7 @@ func testCheckAzureRMApplicationInsightsAnalyticsItemExists(resourceName string) func testCheckAzureRMApplicationInsightsAnalyticsItemExistsInternal(rs *terraform.ResourceState) (bool, error) { id := rs.Primary.Attributes["id"] - resGroup, appInsightsName, itemScopePath, itemID, err := resourcesArmApplicationInsightsAnalyticsItemParseID(id) + resGroup, appInsightsName, itemScopePath, itemID, err := applicationinsights.ResourcesArmApplicationInsightsAnalyticsItemParseID(id) if err != nil { return false, fmt.Errorf("Failed to parse ID (id: %s): %+v", id, err) } @@ -201,7 +182,7 @@ func testCheckAzureRMApplicationInsightsAnalyticsItemExistsInternal(rs *terrafor return true, nil } -func testAccAzureRMApplicationInsightsAnalyticsItem_basic(rInt int, location string) string { +func testAccAzureRMApplicationInsightsAnalyticsItem_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -222,10 +203,10 @@ resource "azurerm_application_insights_analytics_item" "test" { scope = "shared" type = "query" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApplicationInsightsAnalyticsItem_basic2(rInt int, location string) string { +func testAccAzureRMApplicationInsightsAnalyticsItem_basic2(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -246,10 +227,10 @@ resource "azurerm_application_insights_analytics_item" "test" { scope = "shared" type = "query" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApplicationInsightsAnalyticsItem_multiple(rInt int, location string) string { +func testAccAzureRMApplicationInsightsAnalyticsItem_multiple(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -287,5 +268,5 @@ resource "azurerm_application_insights_analytics_item" "test3" { type = "function" function_alias = "myfunction" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/applicationinsights/resource_arm_application_insights_api_key_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go similarity index 61% rename from azurerm/internal/services/applicationinsights/resource_arm_application_insights_api_key_test.go rename to azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go index cf7a4f4eea24..7843baee0456 100644 --- a/azurerm/internal/services/applicationinsights/resource_arm_application_insights_api_key_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go @@ -1,4 +1,4 @@ -package applicationinsights +package tests import ( "fmt" @@ -9,15 +9,14 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMApplicationInsightsAPIKey_no_permission(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsightsAPIKey_basic(ri, acceptance.Location(), "[]", "[]") + data := acceptance.BuildTestData(t, "azurerm_application_insights_api_key", "test") + config := testAccAzureRMApplicationInsightsAPIKey_basic(data, "[]", "[]") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -37,10 +36,7 @@ func TestAccAzureRMApplicationInsightsAPIKey_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_application_insights_api_key.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_application_insights_api_key", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -48,25 +44,24 @@ func TestAccAzureRMApplicationInsightsAPIKey_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationInsightsAPIKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationInsightsAPIKey_basic(ri, acceptance.Location(), "[]", `["annotations"]`), + Config: testAccAzureRMApplicationInsightsAPIKey_basic(data, "[]", `["annotations"]`), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsAPIKeyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "read_permissions.#", "0"), - resource.TestCheckResourceAttr(resourceName, "write_permissions.#", "1"), + testCheckAzureRMApplicationInsightsAPIKeyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "read_permissions.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "write_permissions.#", "1"), ), }, { - Config: testAccAzureRMApplicationInsightsAPIKey_requiresImport(ri, location, "[]", `["annotations"]`), - ExpectError: acceptance.RequiresImportError("azurerm_application_insights_api_key"), + Config: testAccAzureRMApplicationInsights_requiresImport(data, "web"), + ExpectError: acceptance.RequiresImportError("azurerm_application_insights"), }, }, }) } func TestAccAzureRMApplicationInsightsAPIKey_read_telemetry_permissions(t *testing.T) { - resourceName := "azurerm_application_insights_api_key.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsightsAPIKey_basic(ri, acceptance.Location(), `["aggregate", "api", "draft", "extendqueries", "search"]`, "[]") + data := acceptance.BuildTestData(t, "azurerm_application_insights_api_key", "test") + config := testAccAzureRMApplicationInsightsAPIKey_basic(data, `["aggregate", "api", "draft", "extendqueries", "search"]`, "[]") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -76,27 +71,19 @@ func TestAccAzureRMApplicationInsightsAPIKey_read_telemetry_permissions(t *testi { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsAPIKeyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "read_permissions.#", "5"), - resource.TestCheckResourceAttr(resourceName, "write_permissions.#", "0"), + testCheckAzureRMApplicationInsightsAPIKeyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "read_permissions.#", "5"), + resource.TestCheckResourceAttr(data.ResourceName, "write_permissions.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "api_key", // not returned from API, sensitive - }, - }, + data.ImportStep("api_key"), }, }) } func TestAccAzureRMApplicationInsightsAPIKey_write_annotations_permission(t *testing.T) { - resourceName := "azurerm_application_insights_api_key.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsightsAPIKey_basic(ri, acceptance.Location(), "[]", `["annotations"]`) + data := acceptance.BuildTestData(t, "azurerm_application_insights_api_key", "test") + config := testAccAzureRMApplicationInsightsAPIKey_basic(data, "[]", `["annotations"]`) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -106,27 +93,19 @@ func TestAccAzureRMApplicationInsightsAPIKey_write_annotations_permission(t *tes { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsAPIKeyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "read_permissions.#", "0"), - resource.TestCheckResourceAttr(resourceName, "write_permissions.#", "1"), + testCheckAzureRMApplicationInsightsAPIKeyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "read_permissions.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "write_permissions.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "api_key", // not returned from API, sensitive - }, - }, + data.ImportStep("api_key"), }, }) } func TestAccAzureRMApplicationInsightsAPIKey_authenticate_permission(t *testing.T) { - resourceName := "azurerm_application_insights_api_key.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsightsAPIKey_basic(ri, acceptance.Location(), `["agentconfig"]`, "[]") + data := acceptance.BuildTestData(t, "azurerm_application_insights_api_key", "test") + config := testAccAzureRMApplicationInsightsAPIKey_basic(data, `["agentconfig"]`, "[]") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -136,27 +115,19 @@ func TestAccAzureRMApplicationInsightsAPIKey_authenticate_permission(t *testing. { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsAPIKeyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "read_permissions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "write_permissions.#", "0"), + testCheckAzureRMApplicationInsightsAPIKeyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "read_permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "write_permissions.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "api_key", // not returned from API, sensitive - }, - }, + data.ImportStep("api_key"), }, }) } func TestAccAzureRMApplicationInsightsAPIKey_full_permissions(t *testing.T) { - resourceName := "azurerm_application_insights_api_key.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsightsAPIKey_basic(ri, acceptance.Location(), `["agentconfig", "aggregate", "api", "draft", "extendqueries", "search"]`, `["annotations"]`) + data := acceptance.BuildTestData(t, "azurerm_application_insights_api_key", "test") + config := testAccAzureRMApplicationInsightsAPIKey_basic(data, `["agentconfig", "aggregate", "api", "draft", "extendqueries", "search"]`, `["annotations"]`) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -166,19 +137,12 @@ func TestAccAzureRMApplicationInsightsAPIKey_full_permissions(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsAPIKeyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "read_permissions.#", "6"), - resource.TestCheckResourceAttr(resourceName, "write_permissions.#", "1"), + testCheckAzureRMApplicationInsightsAPIKeyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "read_permissions.#", "6"), + resource.TestCheckResourceAttr(data.ResourceName, "write_permissions.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "api_key", // not returned from API, sensitive - }, - }, + data.ImportStep("api_key"), }, }) } @@ -246,7 +210,7 @@ func testCheckAzureRMApplicationInsightsAPIKeyExists(resourceName string) resour } } -func testAccAzureRMApplicationInsightsAPIKey_basic(rInt int, location, readPerms, writePerms string) string { +func testAccAzureRMApplicationInsightsAPIKey_basic(data acceptance.TestData, readPerms, writePerms string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -266,11 +230,11 @@ resource "azurerm_application_insights_api_key" "test" { read_permissions = %s write_permissions = %s } -`, rInt, location, rInt, rInt, readPerms, writePerms) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, readPerms, writePerms) } -func testAccAzureRMApplicationInsightsAPIKey_requiresImport(rInt int, location, readPerms, writePerms string) string { - template := testAccAzureRMApplicationInsightsAPIKey_basic(rInt, location, readPerms, writePerms) +func testAccAzureRMApplicationInsightsAPIKey_requiresImport(data acceptance.TestData, readPerms, writePerms string) string { + template := testAccAzureRMApplicationInsightsAPIKey_basic(data, readPerms, writePerms) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/applicationinsights/resource_arm_application_insights_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go similarity index 61% rename from azurerm/internal/services/applicationinsights/resource_arm_application_insights_test.go rename to azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go index 927dccea1fe9..44e084b8e61c 100644 --- a/azurerm/internal/services/applicationinsights/resource_arm_application_insights_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go @@ -1,4 +1,4 @@ -package applicationinsights +package tests import ( "fmt" @@ -7,16 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMApplicationInsights_basicWeb(t *testing.T) { - resourceName := "azurerm_application_insights.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsights_basic(ri, acceptance.Location(), "web") + data := acceptance.BuildTestData(t, "azurerm_application_insights", "test") + config := testAccAzureRMApplicationInsights_basic(data, "web") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,15 +24,11 @@ func TestAccAzureRMApplicationInsights_basicWeb(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "application_type", "web"), + testCheckAzureRMApplicationInsightsExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "application_type", "web"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,10 +38,7 @@ func TestAccAzureRMApplicationInsights_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_application_insights.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_application_insights", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,14 +46,14 @@ func TestAccAzureRMApplicationInsights_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationInsightsDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationInsights_basic(ri, location, "web"), + Config: testAccAzureRMApplicationInsights_basic(data, "web"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "application_type", "web"), + testCheckAzureRMApplicationInsightsExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "application_type", "web"), ), }, { - Config: testAccAzureRMApplicationInsights_requiresImport(ri, location, "web"), + Config: testAccAzureRMApplicationInsights_requiresImport(data, "web"), ExpectError: acceptance.RequiresImportError("azurerm_application_insights"), }, }, @@ -70,9 +61,8 @@ func TestAccAzureRMApplicationInsights_requiresImport(t *testing.T) { } func TestAccAzureRMApplicationInsights_basicJava(t *testing.T) { - resourceName := "azurerm_application_insights.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsights_basic(ri, acceptance.Location(), "java") + data := acceptance.BuildTestData(t, "azurerm_application_insights", "test") + config := testAccAzureRMApplicationInsights_basic(data, "java") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,23 +72,18 @@ func TestAccAzureRMApplicationInsights_basicJava(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "application_type", "java"), + testCheckAzureRMApplicationInsightsExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "application_type", "java"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationInsights_basicMobileCenter(t *testing.T) { - resourceName := "azurerm_application_insights.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsights_basic(ri, acceptance.Location(), "MobileCenter") + data := acceptance.BuildTestData(t, "azurerm_application_insights", "test") + config := testAccAzureRMApplicationInsights_basic(data, "MobileCenter") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -108,23 +93,18 @@ func TestAccAzureRMApplicationInsights_basicMobileCenter(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "application_type", "MobileCenter"), + testCheckAzureRMApplicationInsightsExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "application_type", "MobileCenter"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationInsights_basicOther(t *testing.T) { - resourceName := "azurerm_application_insights.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsights_basic(ri, acceptance.Location(), "other") + data := acceptance.BuildTestData(t, "azurerm_application_insights", "test") + config := testAccAzureRMApplicationInsights_basic(data, "other") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -134,23 +114,18 @@ func TestAccAzureRMApplicationInsights_basicOther(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "application_type", "other"), + testCheckAzureRMApplicationInsightsExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "application_type", "other"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationInsights_basicPhone(t *testing.T) { - resourceName := "azurerm_application_insights.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsights_basic(ri, acceptance.Location(), "phone") + data := acceptance.BuildTestData(t, "azurerm_application_insights", "test") + config := testAccAzureRMApplicationInsights_basic(data, "phone") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -160,23 +135,18 @@ func TestAccAzureRMApplicationInsights_basicPhone(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "application_type", "phone"), + testCheckAzureRMApplicationInsightsExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "application_type", "phone"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationInsights_basicStore(t *testing.T) { - resourceName := "azurerm_application_insights.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsights_basic(ri, acceptance.Location(), "store") + data := acceptance.BuildTestData(t, "azurerm_application_insights", "test") + config := testAccAzureRMApplicationInsights_basic(data, "store") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -186,23 +156,18 @@ func TestAccAzureRMApplicationInsights_basicStore(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "application_type", "store"), + testCheckAzureRMApplicationInsightsExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "application_type", "store"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationInsights_basiciOS(t *testing.T) { - resourceName := "azurerm_application_insights.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsights_basic(ri, acceptance.Location(), "ios") + data := acceptance.BuildTestData(t, "azurerm_application_insights", "test") + config := testAccAzureRMApplicationInsights_basic(data, "ios") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -212,15 +177,11 @@ func TestAccAzureRMApplicationInsights_basiciOS(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "application_type", "ios"), + testCheckAzureRMApplicationInsightsExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "application_type", "ios"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -282,9 +243,8 @@ func testCheckAzureRMApplicationInsightsExists(resourceName string) resource.Tes } func TestAccAzureRMApplicationInsights_complete(t *testing.T) { - resourceName := "azurerm_application_insights.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsights_complete(ri, acceptance.Location(), "web") + data := acceptance.BuildTestData(t, "azurerm_application_insights", "test") + config := testAccAzureRMApplicationInsights_complete(data, "web") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -294,23 +254,19 @@ func TestAccAzureRMApplicationInsights_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "application_type", "web"), - resource.TestCheckResourceAttr(resourceName, "sampling_percentage", "50"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), + testCheckAzureRMApplicationInsightsExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "application_type", "web"), + resource.TestCheckResourceAttr(data.ResourceName, "sampling_percentage", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } -func testAccAzureRMApplicationInsights_basic(rInt int, location string, applicationType string) string { +func testAccAzureRMApplicationInsights_basic(data acceptance.TestData, applicationType string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -323,11 +279,11 @@ resource "azurerm_application_insights" "test" { resource_group_name = "${azurerm_resource_group.test.name}" application_type = "%s" } -`, rInt, location, rInt, applicationType) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType) } -func testAccAzureRMApplicationInsights_requiresImport(rInt int, location string, applicationType string) string { - template := testAccAzureRMApplicationInsights_basic(rInt, location, applicationType) +func testAccAzureRMApplicationInsights_requiresImport(data acceptance.TestData, applicationType string) string { + template := testAccAzureRMApplicationInsights_basic(data, applicationType) return fmt.Sprintf(` %s @@ -340,7 +296,7 @@ resource "azurerm_application_insights" "import" { `, template) } -func testAccAzureRMApplicationInsights_complete(rInt int, location string, applicationType string) string { +func testAccAzureRMApplicationInsights_complete(data acceptance.TestData, applicationType string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -358,5 +314,5 @@ resource "azurerm_application_insights" "test" { Hello = "World" } } -`, rInt, location, rInt, applicationType) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType) } diff --git a/azurerm/internal/services/applicationinsights/resource_arm_application_insights_webtests_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_webtests_test.go similarity index 72% rename from azurerm/internal/services/applicationinsights/resource_arm_application_insights_webtests_test.go rename to azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_webtests_test.go index e340fab13a41..8dab22ae606b 100644 --- a/azurerm/internal/services/applicationinsights/resource_arm_application_insights_webtests_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_webtests_test.go @@ -1,4 +1,4 @@ -package applicationinsights +package tests import ( "fmt" @@ -7,16 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMApplicationInsightsWebTests_basic(t *testing.T) { - resourceName := "azurerm_application_insights_web_test.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMApplicationInsightsWebTests_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_application_insights_web_test", "test") + config := testAccAzureRMApplicationInsightsWebTests_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,21 +24,16 @@ func TestAccAzureRMApplicationInsightsWebTests_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsWebTestExists(resourceName), + testCheckAzureRMApplicationInsightsWebTestExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationInsightsWebTests_complete(t *testing.T) { - resourceName := "azurerm_application_insights_web_test.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_insights_web_test", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -48,24 +41,18 @@ func TestAccAzureRMApplicationInsightsWebTests_complete(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationInsightsWebTestsDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationInsightsWebTests_complete(ri, acceptance.Location()), + Config: testAccAzureRMApplicationInsightsWebTests_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsWebTestExists(resourceName), + testCheckAzureRMApplicationInsightsWebTestExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationInsightsWebTests_update(t *testing.T) { - resourceName := "azurerm_application_insights_web_test.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_application_insights_web_test", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -73,30 +60,30 @@ func TestAccAzureRMApplicationInsightsWebTests_update(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationInsightsWebTestsDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationInsightsWebTests_basic(ri, location), + Config: testAccAzureRMApplicationInsightsWebTests_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsWebTestExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "geo_locations.#", "1"), - resource.TestCheckResourceAttr(resourceName, "frequency", "300"), - resource.TestCheckResourceAttr(resourceName, "timeout", "30"), + testCheckAzureRMApplicationInsightsWebTestExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "geo_locations.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "300"), + resource.TestCheckResourceAttr(data.ResourceName, "timeout", "30"), ), }, { - Config: testAccAzureRMApplicationInsightsWebTests_complete(ri, location), + Config: testAccAzureRMApplicationInsightsWebTests_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsWebTestExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "geo_locations.#", "2"), - resource.TestCheckResourceAttr(resourceName, "frequency", "900"), - resource.TestCheckResourceAttr(resourceName, "timeout", "120"), + testCheckAzureRMApplicationInsightsWebTestExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "geo_locations.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "900"), + resource.TestCheckResourceAttr(data.ResourceName, "timeout", "120"), ), }, { - Config: testAccAzureRMApplicationInsightsWebTests_basic(ri, location), + Config: testAccAzureRMApplicationInsightsWebTests_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsWebTestExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "geo_locations.#", "1"), - resource.TestCheckResourceAttr(resourceName, "frequency", "300"), - resource.TestCheckResourceAttr(resourceName, "timeout", "30"), + testCheckAzureRMApplicationInsightsWebTestExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "geo_locations.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "frequency", "300"), + resource.TestCheckResourceAttr(data.ResourceName, "timeout", "30"), ), }, }, @@ -108,11 +95,8 @@ func TestAccAzureRMApplicationInsightsWebTests_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_application_insights_web_test.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMApplicationInsightsWebTests_basic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_application_insights_web_test", "test") + config := testAccAzureRMApplicationInsightsWebTests_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -122,13 +106,10 @@ func TestAccAzureRMApplicationInsightsWebTests_requiresImport(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationInsightsWebTestExists(resourceName), + testCheckAzureRMApplicationInsightsWebTestExists(data.ResourceName), ), }, - { - Config: testAccAzureRMApplicationInsightsWebTests_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_application_insights_web_test"), - }, + data.RequiresImportErrorStep(testAccAzureRMApplicationInsightsWebTests_requiresImport), }, }) } @@ -185,7 +166,7 @@ func testCheckAzureRMApplicationInsightsWebTestExists(resourceName string) resou } } -func testAccAzureRMApplicationInsightsWebTests_basic(rInt int, location string) string { +func testAccAzureRMApplicationInsightsWebTests_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -215,10 +196,10 @@ resource "azurerm_application_insights_web_test" "test" { XML } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationInsightsWebTests_complete(rInt int, location string) string { +func testAccAzureRMApplicationInsightsWebTests_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -251,11 +232,11 @@ resource "azurerm_application_insights_web_test" "test" { XML } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationInsightsWebTests_requiresImport(rInt int, location string) string { - template := testAccAzureRMApplicationInsightsWebTests_basic(rInt, location) +func testAccAzureRMApplicationInsightsWebTests_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApplicationInsightsWebTests_basic(data) return fmt.Sprintf(` %s From 226da6304a6bd8452cf1ea44120bcd30ea13640d Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 09:03:05 -0800 Subject: [PATCH 129/203] keyvault: switching to the new test structure --- .../batch/data_source_batch_account_test.go | 2 +- .../batch/data_source_batch_pool_test.go | 2 +- .../batch/resource_arm_batch_account_test.go | 4 +- .../resource_arm_batch_certificate_test.go | 7 +- .../batch/resource_arm_batch_pool_test.go | 22 +- .../keyvault/data_source_key_vault.go | 2 +- .../keyvault/data_source_key_vault_test.go | 161 ------------ .../keyvault/resource_arm_key_vault.go | 6 +- .../resource_arm_key_vault_access_policy.go | 4 +- .../resource_arm_key_vault_migration.go | 2 +- ...ata_source_key_vault_access_policy_test.go | 58 ++--- .../data_source_key_vault_key_test.go | 20 +- .../data_source_key_vault_secret_test.go | 33 +-- .../tests/data_source_key_vault_test.go | 152 +++++++++++ ...source_arm_key_vault_access_policy_test.go | 140 +++++----- ...resource_arm_key_vault_certificate_test.go | 171 ++++++------- .../resource_arm_key_vault_key_test.go | 177 +++++-------- .../resource_arm_key_vault_migration_test.go | 5 +- .../resource_arm_key_vault_secret_test.go | 114 ++++----- .../resource_arm_key_vault_test.go | 241 +++++++----------- .../network/data_source_public_ips_test.go | 4 +- 21 files changed, 573 insertions(+), 754 deletions(-) delete mode 100644 azurerm/internal/services/keyvault/data_source_key_vault_test.go rename azurerm/internal/services/keyvault/{ => tests}/data_source_key_vault_access_policy_test.go (57%) rename azurerm/internal/services/keyvault/{ => tests}/data_source_key_vault_key_test.go (51%) rename azurerm/internal/services/keyvault/{ => tests}/data_source_key_vault_secret_test.go (51%) create mode 100644 azurerm/internal/services/keyvault/tests/data_source_key_vault_test.go rename azurerm/internal/services/keyvault/{ => tests}/resource_arm_key_vault_access_policy_test.go (66%) rename azurerm/internal/services/keyvault/{ => tests}/resource_arm_key_vault_certificate_test.go (78%) rename azurerm/internal/services/keyvault/{ => tests}/resource_arm_key_vault_key_test.go (77%) rename azurerm/internal/services/keyvault/{ => tests}/resource_arm_key_vault_migration_test.go (98%) rename azurerm/internal/services/keyvault/{ => tests}/resource_arm_key_vault_secret_test.go (77%) rename azurerm/internal/services/keyvault/{ => tests}/resource_arm_key_vault_test.go (75%) diff --git a/azurerm/internal/services/batch/data_source_batch_account_test.go b/azurerm/internal/services/batch/data_source_batch_account_test.go index 7048fa582f75..594811e87cf4 100644 --- a/azurerm/internal/services/batch/data_source_batch_account_test.go +++ b/azurerm/internal/services/batch/data_source_batch_account_test.go @@ -140,7 +140,7 @@ data "azurerm_batch_account" "test" { name = "${azurerm_batch_account.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testAccDataSourceAzureBatchAccount_userSubscription(rInt int, rString string, location string, tenantID string, subscriptionID string) string { diff --git a/azurerm/internal/services/batch/data_source_batch_pool_test.go b/azurerm/internal/services/batch/data_source_batch_pool_test.go index 417950997faf..cf6b4941e507 100644 --- a/azurerm/internal/services/batch/data_source_batch_pool_test.go +++ b/azurerm/internal/services/batch/data_source_batch_pool_test.go @@ -162,5 +162,5 @@ data "azurerm_batch_pool" "test" { account_name = "${azurerm_batch_pool.test.account_name}" resource_group_name = "${azurerm_batch_pool.test.resource_group_name}" } -`, rInt, location, rString, rString, rString) +`, rInt, location, rString, data.RandomString, data.RandomString) } diff --git a/azurerm/internal/services/batch/resource_arm_batch_account_test.go b/azurerm/internal/services/batch/resource_arm_batch_account_test.go index 3aa1b96873ff..5872a11c2d75 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_account_test.go +++ b/azurerm/internal/services/batch/resource_arm_batch_account_test.go @@ -268,7 +268,7 @@ resource "azurerm_batch_account" "test" { env = "test" } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testAccAzureRMBatchAccount_completeUpdated(rInt int, rString string, location string) string { @@ -298,7 +298,7 @@ resource "azurerm_batch_account" "test" { version = "2" } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testAccAzureRMBatchAccount_userSubscription(rInt int, batchAccountSuffix string, location string, tenantID string) string { diff --git a/azurerm/internal/services/batch/resource_arm_batch_certificate_test.go b/azurerm/internal/services/batch/resource_arm_batch_certificate_test.go index 2124c6a1dcee..e5fad946ca93 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_certificate_test.go +++ b/azurerm/internal/services/batch/resource_arm_batch_certificate_test.go @@ -96,12 +96,7 @@ func TestAccAzureRMBatchCertificate_Cer(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "thumbprint_algorithm", "sha1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"certificate"}, - }, + data.ImportStep("certificate"), }, }) } diff --git a/azurerm/internal/services/batch/resource_arm_batch_pool_test.go b/azurerm/internal/services/batch/resource_arm_batch_pool_test.go index 15bb90a9ae3e..208e5ae1e959 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_pool_test.go +++ b/azurerm/internal/services/batch/resource_arm_batch_pool_test.go @@ -506,7 +506,7 @@ resource "azurerm_batch_pool" "test" { version = "latest" } } -`, rInt, location, rString, rString, rString) +`, rInt, location, rString, data.RandomString, data.RandomString) } func testaccAzureRMBatchPool_autoScale_complete(rInt int, rString string, location string) string { @@ -564,7 +564,7 @@ EOF version = "latest" } } -`, rInt, location, rString, rString, rString) +`, rInt, location, rString, data.RandomString, data.RandomString) } func testaccAzureRMBatchPool_basic(rInt int, rString string, location string) string { @@ -598,7 +598,7 @@ resource "azurerm_batch_pool" "test" { version = "latest" } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testaccAzureRMBatchPool_requiresImport(rInt int, rString string, location string) string { @@ -680,7 +680,7 @@ resource "azurerm_batch_pool" "test" { } } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testaccAzureRMBatchPoolValidateResourceFileWithoutSource(rInt int, rString string, location string) string { @@ -738,7 +738,7 @@ resource "azurerm_batch_pool" "test" { } } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testaccAzureRMBatchPoolValidateResourceFileWithMultipleSources(rInt int, rString string, location string) string { @@ -796,7 +796,7 @@ resource "azurerm_batch_pool" "test" { } } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testaccAzureRMBatchPoolValidateResourceFileBlobPrefixWithoutAutoStorageContainerName(rInt int, rString string, location string) string { @@ -854,7 +854,7 @@ resource "azurerm_batch_pool" "test" { } } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testaccAzureRMBatchPoolValidateResourceFileHttpURLWithoutFilePath(rInt int, rString string, location string) string { @@ -911,7 +911,7 @@ resource "azurerm_batch_pool" "test" { } } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testaccAzureRMBatchPoolCertificates(rInt int, rString string, location string) string { @@ -976,7 +976,7 @@ resource "azurerm_batch_pool" "test" { visibility = ["StartTask", "RemoteUser"] } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testaccAzureRMBatchPoolContainerConfiguration(rInt int, rString string, location string) string { @@ -1028,7 +1028,7 @@ resource "azurerm_batch_pool" "test" { ] } } -`, rInt, location, rString, rString, rString) +`, rInt, location, rString, data.RandomString, data.RandomString) } func testaccAzureRMBatchPoolCustomImageConfiguration(rInt int, rString string, location string) string { @@ -1177,5 +1177,5 @@ resource "azurerm_batch_pool" "test" { id = "${azurerm_image.test.id}" } } -`, rInt, location, rInt, rInt, rInt, rInt, rString, rInt, rInt, rInt, rString, rString) +`, rInt, location, rInt, rInt, rInt, rInt, rString, rInt, rInt, rInt, data.RandomString, data.RandomString) } diff --git a/azurerm/internal/services/keyvault/data_source_key_vault.go b/azurerm/internal/services/keyvault/data_source_key_vault.go index 2e18d242effa..ef5bf1b85f54 100644 --- a/azurerm/internal/services/keyvault/data_source_key_vault.go +++ b/azurerm/internal/services/keyvault/data_source_key_vault.go @@ -27,7 +27,7 @@ func dataSourceArmKeyVault() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateKeyVaultName, + ValidateFunc: ValidateKeyVaultName, }, "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), diff --git a/azurerm/internal/services/keyvault/data_source_key_vault_test.go b/azurerm/internal/services/keyvault/data_source_key_vault_test.go deleted file mode 100644 index cc8d96d77f76..000000000000 --- a/azurerm/internal/services/keyvault/data_source_key_vault_test.go +++ /dev/null @@ -1,161 +0,0 @@ -package keyvault - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMKeyVault_basic(t *testing.T) { - dataSourceName := "data.azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMKeyVault_basic(ri, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKeyVaultDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "tenant_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "sku_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "access_policy.0.tenant_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "access_policy.0.object_id"), - resource.TestCheckResourceAttr(dataSourceName, "access_policy.0.key_permissions.0", "create"), - resource.TestCheckResourceAttr(dataSourceName, "access_policy.0.secret_permissions.0", "set"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMKeyVault_basicClassic(t *testing.T) { - dataSourceName := "data.azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMKeyVault_basic(ri, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKeyVaultDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "tenant_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "sku.0.name"), - resource.TestCheckResourceAttrSet(dataSourceName, "access_policy.0.tenant_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "access_policy.0.object_id"), - resource.TestCheckResourceAttr(dataSourceName, "access_policy.0.key_permissions.0", "create"), - resource.TestCheckResourceAttr(dataSourceName, "access_policy.0.secret_permissions.0", "set"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMKeyVault_complete(t *testing.T) { - dataSourceName := "data.azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMKeyVault_complete(ri, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKeyVaultDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "tenant_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "sku.0.name"), - resource.TestCheckResourceAttrSet(dataSourceName, "access_policy.0.tenant_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "access_policy.0.object_id"), - resource.TestCheckResourceAttr(dataSourceName, "access_policy.0.key_permissions.0", "get"), - resource.TestCheckResourceAttr(dataSourceName, "access_policy.0.secret_permissions.0", "get"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "Production"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMKeyVault_networkAcls(t *testing.T) { - dataSourceName := "data.azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMKeyVault_networkAcls(ri, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKeyVaultDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "tenant_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "sku.0.name"), - resource.TestCheckResourceAttrSet(dataSourceName, "access_policy.0.tenant_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "access_policy.0.object_id"), - resource.TestCheckResourceAttr(dataSourceName, "access_policy.0.key_permissions.0", "create"), - resource.TestCheckResourceAttr(dataSourceName, "access_policy.0.secret_permissions.0", "set"), - resource.TestCheckResourceAttr(dataSourceName, "network_acls.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "network_acls.0.default_action", "Allow"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKeyVault_basic(rInt int, location string) string { - r := testAccAzureRMKeyVault_basic(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_key_vault" "test" { - name = "${azurerm_key_vault.test.name}" - resource_group_name = "${azurerm_key_vault.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKeyVault_complete(rInt int, location string) string { - r := testAccAzureRMKeyVault_complete(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_key_vault" "test" { - name = "${azurerm_key_vault.test.name}" - resource_group_name = "${azurerm_key_vault.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKeyVault_networkAcls(rInt int, location string) string { - r := testAccAzureRMKeyVault_networkAclsUpdated(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_key_vault" "test" { - name = "${azurerm_key_vault.test.name}" - resource_group_name = "${azurerm_key_vault.test.resource_group_name}" -} -`, r) -} diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault.go b/azurerm/internal/services/keyvault/resource_arm_key_vault.go index 0e071d1fd02d..d2b8d3055d17 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault.go @@ -44,7 +44,7 @@ func resourceArmKeyVault() *schema.Resource { State: schema.ImportStatePassthrough, }, - MigrateState: resourceAzureRMKeyVaultMigrateState, + MigrateState: ResourceAzureRMKeyVaultMigrateState, SchemaVersion: 1, Timeouts: &schema.ResourceTimeout{ @@ -59,7 +59,7 @@ func resourceArmKeyVault() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateKeyVaultName, + ValidateFunc: ValidateKeyVaultName, }, "location": azure.SchemaLocation(), @@ -516,7 +516,7 @@ func flattenKeyVaultNetworkAcls(input *keyvault.NetworkRuleSet) []interface{} { return []interface{}{output} } -func validateKeyVaultName(v interface{}, k string) (warnings []string, errors []error) { +func ValidateKeyVaultName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if matched := regexp.MustCompile(`^[a-zA-Z0-9-]{3,24}$`).Match([]byte(value)); !matched { errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes and must be between 3-24 chars", k)) diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go index 71a76c7ed360..22e059ab6a71 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy.go @@ -311,7 +311,7 @@ func resourceArmKeyVaultAccessPolicyRead(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error making Read request on Azure KeyVault %q (Resource Group %q): %+v", vaultName, resGroup, err) } - policy, err := findKeyVaultAccessPolicy(resp.Properties.AccessPolicies, objectId, applicationId) + policy, err := FindKeyVaultAccessPolicy(resp.Properties.AccessPolicies, objectId, applicationId) if err != nil { return fmt.Errorf("Error locating Access Policy (Object ID %q / Application ID %q) in Key Vault %q (Resource Group %q)", objectId, applicationId, vaultName, resGroup) } @@ -360,7 +360,7 @@ func resourceArmKeyVaultAccessPolicyRead(d *schema.ResourceData, meta interface{ return nil } -func findKeyVaultAccessPolicy(policies *[]keyvault.AccessPolicyEntry, objectId string, applicationId string) (*keyvault.AccessPolicyEntry, error) { +func FindKeyVaultAccessPolicy(policies *[]keyvault.AccessPolicyEntry, objectId string, applicationId string) (*keyvault.AccessPolicyEntry, error) { if policies == nil { return nil, nil } diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go b/azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go index f3dff4890ebe..5e5930a0d2a4 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault_migration.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func resourceAzureRMKeyVaultMigrateState(v int, is *terraform.InstanceState, _ interface{}) (*terraform.InstanceState, error) { +func ResourceAzureRMKeyVaultMigrateState(v int, is *terraform.InstanceState, _ interface{}) (*terraform.InstanceState, error) { switch v { case 0: log.Println("[INFO] Found AzureRM Key Vault State v0; migrating to v1") diff --git a/azurerm/internal/services/keyvault/data_source_key_vault_access_policy_test.go b/azurerm/internal/services/keyvault/tests/data_source_key_vault_access_policy_test.go similarity index 57% rename from azurerm/internal/services/keyvault/data_source_key_vault_access_policy_test.go rename to azurerm/internal/services/keyvault/tests/data_source_key_vault_access_policy_test.go index b5fc0c8d3b40..6e55a259b7a6 100644 --- a/azurerm/internal/services/keyvault/data_source_key_vault_access_policy_test.go +++ b/azurerm/internal/services/keyvault/tests/data_source_key_vault_access_policy_test.go @@ -1,4 +1,4 @@ -package keyvault +package tests import ( "fmt" @@ -9,7 +9,7 @@ import ( ) func TestAccDataSourceAzureRMKeyVaultAccessPolicy_key(t *testing.T) { - dataSourceName := "data.azurerm_key_vault_access_policy.test" + data := acceptance.BuildTestData(t, "data.azurerm_key_vault_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -17,9 +17,9 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_key(t *testing.T) { { Config: testAccDataSourceKeyVaultAccessPolicy("Key Management"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "key_permissions.#", "9"), - resource.TestCheckNoResourceAttr(dataSourceName, "secret_permissions"), - resource.TestCheckNoResourceAttr(dataSourceName, "certificate_permissions"), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.#", "9"), + resource.TestCheckNoResourceAttr(data.ResourceName, "secret_permissions"), + resource.TestCheckNoResourceAttr(data.ResourceName, "certificate_permissions"), ), }, }, @@ -27,7 +27,7 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_key(t *testing.T) { } func TestAccDataSourceAzureRMKeyVaultAccessPolicy_secret(t *testing.T) { - dataSourceName := "data.azurerm_key_vault_access_policy.test" + data := acceptance.BuildTestData(t, "data.azurerm_key_vault_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -35,9 +35,9 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_secret(t *testing.T) { { Config: testAccDataSourceKeyVaultAccessPolicy("Secret Management"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckNoResourceAttr(dataSourceName, "key_permissions"), - resource.TestCheckResourceAttr(dataSourceName, "secret_permissions.#", "7"), - resource.TestCheckNoResourceAttr(dataSourceName, "certificate_permissions"), + resource.TestCheckNoResourceAttr(data.ResourceName, "key_permissions"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.#", "7"), + resource.TestCheckNoResourceAttr(data.ResourceName, "certificate_permissions"), ), }, }, @@ -45,7 +45,7 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_secret(t *testing.T) { } func TestAccDataSourceAzureRMKeyVaultAccessPolicy_certificate(t *testing.T) { - dataSourceName := "data.azurerm_key_vault_access_policy.test" + data := acceptance.BuildTestData(t, "data.azurerm_key_vault_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -53,9 +53,9 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_certificate(t *testing.T) { { Config: testAccDataSourceKeyVaultAccessPolicy("Certificate Management"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckNoResourceAttr(dataSourceName, "key_permissions"), - resource.TestCheckNoResourceAttr(dataSourceName, "secret_permissions"), - resource.TestCheckResourceAttr(dataSourceName, "certificate_permissions.#", "12"), + resource.TestCheckNoResourceAttr(data.ResourceName, "key_permissions"), + resource.TestCheckNoResourceAttr(data.ResourceName, "secret_permissions"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_permissions.#", "12"), ), }, }, @@ -63,7 +63,7 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_certificate(t *testing.T) { } func TestAccDataSourceAzureRMKeyVaultAccessPolicy_keySecret(t *testing.T) { - dataSourceName := "data.azurerm_key_vault_access_policy.test" + data := acceptance.BuildTestData(t, "data.azurerm_key_vault_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -71,9 +71,9 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_keySecret(t *testing.T) { { Config: testAccDataSourceKeyVaultAccessPolicy("Key & Secret Management"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "key_permissions.#", "9"), - resource.TestCheckResourceAttr(dataSourceName, "secret_permissions.#", "7"), - resource.TestCheckNoResourceAttr(dataSourceName, "certificate_permissions"), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.#", "9"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.#", "7"), + resource.TestCheckNoResourceAttr(data.ResourceName, "certificate_permissions"), ), }, }, @@ -81,7 +81,7 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_keySecret(t *testing.T) { } func TestAccDataSourceAzureRMKeyVaultAccessPolicy_keyCertificate(t *testing.T) { - dataSourceName := "data.azurerm_key_vault_access_policy.test" + data := acceptance.BuildTestData(t, "data.azurerm_key_vault_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -89,9 +89,9 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_keyCertificate(t *testing.T) { { Config: testAccDataSourceKeyVaultAccessPolicy("Key & Certificate Management"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "key_permissions.#", "9"), - resource.TestCheckNoResourceAttr(dataSourceName, "secret_permissions"), - resource.TestCheckResourceAttr(dataSourceName, "certificate_permissions.#", "12"), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.#", "9"), + resource.TestCheckNoResourceAttr(data.ResourceName, "secret_permissions"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_permissions.#", "12"), ), }, }, @@ -99,7 +99,7 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_keyCertificate(t *testing.T) { } func TestAccDataSourceAzureRMKeyVaultAccessPolicy_secretCertificate(t *testing.T) { - dataSourceName := "data.azurerm_key_vault_access_policy.test" + data := acceptance.BuildTestData(t, "data.azurerm_key_vault_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -107,9 +107,9 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_secretCertificate(t *testing.T { Config: testAccDataSourceKeyVaultAccessPolicy("Secret & Certificate Management"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckNoResourceAttr(dataSourceName, "key_permissions"), - resource.TestCheckResourceAttr(dataSourceName, "secret_permissions.#", "7"), - resource.TestCheckResourceAttr(dataSourceName, "certificate_permissions.#", "12"), + resource.TestCheckNoResourceAttr(data.ResourceName, "key_permissions"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.#", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_permissions.#", "12"), ), }, }, @@ -117,7 +117,7 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_secretCertificate(t *testing.T } func TestAccDataSourceAzureRMKeyVaultAccessPolicy_keySecretCertificate(t *testing.T) { - dataSourceName := "data.azurerm_key_vault_access_policy.test" + data := acceptance.BuildTestData(t, "data.azurerm_key_vault_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -125,9 +125,9 @@ func TestAccDataSourceAzureRMKeyVaultAccessPolicy_keySecretCertificate(t *testin { Config: testAccDataSourceKeyVaultAccessPolicy("Key, Secret, & Certificate Management"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "key_permissions.#", "9"), - resource.TestCheckResourceAttr(dataSourceName, "secret_permissions.#", "7"), - resource.TestCheckResourceAttr(dataSourceName, "certificate_permissions.#", "12"), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.#", "9"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.#", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_permissions.#", "12"), ), }, }, diff --git a/azurerm/internal/services/keyvault/data_source_key_vault_key_test.go b/azurerm/internal/services/keyvault/tests/data_source_key_vault_key_test.go similarity index 51% rename from azurerm/internal/services/keyvault/data_source_key_vault_key_test.go rename to azurerm/internal/services/keyvault/tests/data_source_key_vault_key_test.go index c2cc5cf74272..0221cc88cac5 100644 --- a/azurerm/internal/services/keyvault/data_source_key_vault_key_test.go +++ b/azurerm/internal/services/keyvault/tests/data_source_key_vault_key_test.go @@ -1,38 +1,34 @@ -package keyvault +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMKeyVaultKey_complete(t *testing.T) { - dataSourceName := "data.azurerm_key_vault_key.test" - - rString := acctest.RandString(8) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_key_vault_key", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceKeyVaultKey_complete(rString, location), + Config: testAccDataSourceKeyVaultKey_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "key_type", "RSA"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.hello", "world"), + resource.TestCheckResourceAttr(data.ResourceName, "key_type", "RSA"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.hello", "world"), ), }, }, }) } -func testAccDataSourceKeyVaultKey_complete(rString string, location string) string { - t := testAccAzureRMKeyVaultKey_complete(rString, location) +func testAccDataSourceKeyVaultKey_complete(data acceptance.TestData) string { + t := testAccAzureRMKeyVaultKey_complete(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/keyvault/data_source_key_vault_secret_test.go b/azurerm/internal/services/keyvault/tests/data_source_key_vault_secret_test.go similarity index 51% rename from azurerm/internal/services/keyvault/data_source_key_vault_secret_test.go rename to azurerm/internal/services/keyvault/tests/data_source_key_vault_secret_test.go index cf83fbdb8ff2..618a81d2fd9f 100644 --- a/azurerm/internal/services/keyvault/data_source_key_vault_secret_test.go +++ b/azurerm/internal/services/keyvault/tests/data_source_key_vault_secret_test.go @@ -1,20 +1,17 @@ -package keyvault +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMKeyVaultSecret_basic(t *testing.T) { - dataSourceName := "data.azurerm_key_vault_secret.test" + data := acceptance.BuildTestData(t, "data.azurerm_key_vault_secret", "test") - rString := acctest.RandString(8) - location := acceptance.Location() - config := testAccDataSourceKeyVaultSecret_basic(rString, location) + config := testAccDataSourceKeyVaultSecret_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,8 +20,8 @@ func TestAccDataSourceAzureRMKeyVaultSecret_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "value", "rick-and-morty"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "value", "rick-and-morty"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -32,11 +29,9 @@ func TestAccDataSourceAzureRMKeyVaultSecret_basic(t *testing.T) { } func TestAccDataSourceAzureRMKeyVaultSecret_complete(t *testing.T) { - dataSourceName := "data.azurerm_key_vault_secret.test" + data := acceptance.BuildTestData(t, "data.azurerm_key_vault_secret", "test") - rString := acctest.RandString(8) - location := acceptance.Location() - config := testAccDataSourceKeyVaultSecret_complete(rString, location) + config := testAccDataSourceKeyVaultSecret_complete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -45,17 +40,17 @@ func TestAccDataSourceAzureRMKeyVaultSecret_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "value", ""), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.hello", "world"), + resource.TestCheckResourceAttr(data.ResourceName, "value", ""), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.hello", "world"), ), }, }, }) } -func testAccDataSourceKeyVaultSecret_basic(rString string, location string) string { - r := testAccAzureRMKeyVaultSecret_basic(rString, location) +func testAccDataSourceKeyVaultSecret_basic(data acceptance.TestData) string { + r := testAccAzureRMKeyVaultSecret_basic(data) return fmt.Sprintf(` %s @@ -66,8 +61,8 @@ data "azurerm_key_vault_secret" "test" { `, r) } -func testAccDataSourceKeyVaultSecret_complete(rString string, location string) string { - r := testAccAzureRMKeyVaultSecret_complete(rString, location) +func testAccDataSourceKeyVaultSecret_complete(data acceptance.TestData) string { + r := testAccAzureRMKeyVaultSecret_complete(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/keyvault/tests/data_source_key_vault_test.go b/azurerm/internal/services/keyvault/tests/data_source_key_vault_test.go new file mode 100644 index 000000000000..d73910a860bb --- /dev/null +++ b/azurerm/internal/services/keyvault/tests/data_source_key_vault_test.go @@ -0,0 +1,152 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMKeyVault_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_key_vault", "test") + config := testAccDataSourceAzureRMKeyVault_basic(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "sku_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.object_id"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "create"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "set"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMKeyVault_basicClassic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_key_vault", "test") + config := testAccDataSourceAzureRMKeyVault_basic(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "sku.0.name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.object_id"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "create"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "set"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMKeyVault_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_key_vault", "test") + config := testAccDataSourceAzureRMKeyVault_complete(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "sku.0.name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.object_id"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMKeyVault_networkAcls(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_key_vault", "test") + config := testAccDataSourceAzureRMKeyVault_networkAcls(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKeyVaultDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "sku.0.name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.tenant_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.object_id"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "create"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "set"), + resource.TestCheckResourceAttr(data.ResourceName, "network_acls.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "network_acls.0.default_action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKeyVault_basic(data acceptance.TestData) string { + r := testAccAzureRMKeyVault_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_key_vault" "test" { + name = "${azurerm_key_vault.test.name}" + resource_group_name = "${azurerm_key_vault.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKeyVault_complete(data acceptance.TestData) string { + r := testAccAzureRMKeyVault_complete(data) + return fmt.Sprintf(` +%s + +data "azurerm_key_vault" "test" { + name = "${azurerm_key_vault.test.name}" + resource_group_name = "${azurerm_key_vault.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKeyVault_networkAcls(data acceptance.TestData) string { + r := testAccAzureRMKeyVault_networkAclsUpdated(data) + return fmt.Sprintf(` +%s + +data "azurerm_key_vault" "test" { + name = "${azurerm_key_vault.test.name}" + resource_group_name = "${azurerm_key_vault.test.resource_group_name}" +} +`, r) +} diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go similarity index 66% rename from azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy_test.go rename to azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go index 9ce37e81176e..69f831a58b63 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_access_policy_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go @@ -1,24 +1,23 @@ -package keyvault +package tests import ( "fmt" "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "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/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault` "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMKeyVaultAccessPolicy_basic(t *testing.T) { - resourceName := "azurerm_key_vault_access_policy.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultAccessPolicy_basic(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_access_policy", "test") + config := testAccAzureRMKeyVaultAccessPolicy_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -28,25 +27,20 @@ func TestAccAzureRMKeyVaultAccessPolicy_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultAccessPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "key_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName, "secret_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName, "secret_permissions.1", "set"), + testCheckAzureRMKeyVaultAccessPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.1", "set"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKeyVaultAccessPolicy_basicClassic(t *testing.T) { - resourceName := "azurerm_key_vault_access_policy.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultAccessPolicy_basicClassic(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_access_policy", "test") + config := testAccAzureRMKeyVaultAccessPolicy_basicClassic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,17 +50,13 @@ func TestAccAzureRMKeyVaultAccessPolicy_basicClassic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultAccessPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "key_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName, "secret_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName, "secret_permissions.1", "set"), + testCheckAzureRMKeyVaultAccessPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.1", "set"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -77,9 +67,7 @@ func TestAccAzureRMKeyVaultAccessPolicy_requiresImport(t *testing.T) { return } - resourceName := "azurerm_key_vault_access_policy.test" - rs := acctest.RandString(6) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_key_vault_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,16 +75,16 @@ func TestAccAzureRMKeyVaultAccessPolicy_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKeyVaultAccessPolicy_basic(rs, location), + Config: testAccAzureRMKeyVaultAccessPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultAccessPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "key_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName, "secret_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName, "secret_permissions.1", "set"), + testCheckAzureRMKeyVaultAccessPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.1", "set"), ), }, { - Config: testAccAzureRMKeyVaultAccessPolicy_requiresImport(rs, location), + Config: testAccAzureRMKeyVaultAccessPolicy_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_key_vault_access_policy"), }, }, @@ -104,10 +92,8 @@ func TestAccAzureRMKeyVaultAccessPolicy_requiresImport(t *testing.T) { } func TestAccAzureRMKeyVaultAccessPolicy_multiple(t *testing.T) { - resourceName1 := "azurerm_key_vault_access_policy.test_with_application_id" + data := acceptance.BuildTestData(t, "azurerm_key_vault_access_policy", "test_with_application_id") resourceName2 := "azurerm_key_vault_access_policy.test_no_application_id" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultAccessPolicy_multiple(rs, acceptance.Location()) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -115,15 +101,15 @@ func TestAccAzureRMKeyVaultAccessPolicy_multiple(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMKeyVaultAccessPolicy_multiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultAccessPolicyExists(resourceName1), - resource.TestCheckResourceAttr(resourceName1, "key_permissions.0", "create"), - resource.TestCheckResourceAttr(resourceName1, "key_permissions.1", "get"), - resource.TestCheckResourceAttr(resourceName1, "secret_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName1, "secret_permissions.1", "delete"), - resource.TestCheckResourceAttr(resourceName1, "certificate_permissions.0", "create"), - resource.TestCheckResourceAttr(resourceName1, "certificate_permissions.1", "delete"), + testCheckAzureRMKeyVaultAccessPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.0", "create"), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.1", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.1", "delete"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_permissions.0", "create"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_permissions.1", "delete"), testCheckAzureRMKeyVaultAccessPolicyExists(resourceName2), resource.TestCheckResourceAttr(resourceName2, "key_permissions.0", "list"), @@ -134,11 +120,7 @@ func TestAccAzureRMKeyVaultAccessPolicy_multiple(t *testing.T) { resource.TestCheckResourceAttr(resourceName2, "certificate_permissions.1", "delete"), ), }, - { - ResourceName: resourceName1, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { ResourceName: resourceName2, ImportState: true, @@ -149,10 +131,9 @@ func TestAccAzureRMKeyVaultAccessPolicy_multiple(t *testing.T) { } func TestAccAzureRMKeyVaultAccessPolicy_update(t *testing.T) { - rs := acctest.RandString(6) - resourceName := "azurerm_key_vault_access_policy.test" - preConfig := testAccAzureRMKeyVaultAccessPolicy_basic(rs, acceptance.Location()) - postConfig := testAccAzureRMKeyVaultAccessPolicy_update(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_access_policy", "test") + preConfig := testAccAzureRMKeyVaultAccessPolicy_basic(data) + postConfig := testAccAzureRMKeyVaultAccessPolicy_update(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -162,18 +143,18 @@ func TestAccAzureRMKeyVaultAccessPolicy_update(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultAccessPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "key_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName, "secret_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName, "secret_permissions.1", "set"), + testCheckAzureRMKeyVaultAccessPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "secret_permissions.1", "set"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultAccessPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "key_permissions.0", "list"), - resource.TestCheckResourceAttr(resourceName, "key_permissions.1", "encrypt"), + testCheckAzureRMKeyVaultAccessPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.0", "list"), + resource.TestCheckResourceAttr(data.ResourceName, "key_permissions.1", "encrypt"), ), }, }, @@ -181,8 +162,7 @@ func TestAccAzureRMKeyVaultAccessPolicy_update(t *testing.T) { } func TestAccAzureRMKeyVaultAccessPolicy_nonExistentVault(t *testing.T) { - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultAccessPolicy_nonExistentVault(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -190,7 +170,7 @@ func TestAccAzureRMKeyVaultAccessPolicy_nonExistentVault(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMKeyVaultAccessPolicy_nonExistentVault(data), ExpectNonEmptyPlan: true, ExpectError: regexp.MustCompile(`Error retrieving Key Vault`), }, @@ -229,7 +209,7 @@ func testCheckAzureRMKeyVaultAccessPolicyExists(resourceName string) resource.Te return fmt.Errorf("Bad: Get on keyVaultClient: %+v", err) } - policy, err := findKeyVaultAccessPolicy(resp.Properties.AccessPolicies, objectId, applicationId) + policy, err := keyvault.FindKeyVaultAccessPolicy(resp.Properties.AccessPolicies, objectId, applicationId) if err != nil { return fmt.Errorf("Error finding Key Vault Access Policy %q : %+v", vaultName, err) } @@ -241,8 +221,8 @@ func testCheckAzureRMKeyVaultAccessPolicyExists(resourceName string) resource.Te } } -func testAccAzureRMKeyVaultAccessPolicy_basic(rString string, location string) string { - template := testAccAzureRMKeyVaultAccessPolicy_template(rString, location) +func testAccAzureRMKeyVaultAccessPolicy_basic(data acceptance.TestData) string { + template := testAccAzureRMKeyVaultAccessPolicy_template(data) return fmt.Sprintf(` %s @@ -264,8 +244,8 @@ resource "azurerm_key_vault_access_policy" "test" { `, template) } -func testAccAzureRMKeyVaultAccessPolicy_basicClassic(rString string, location string) string { - template := testAccAzureRMKeyVaultAccessPolicy_template(rString, location) +func testAccAzureRMKeyVaultAccessPolicy_basicClassic(data acceptance.TestData) string { + template := testAccAzureRMKeyVaultAccessPolicy_template(data) return fmt.Sprintf(` %s @@ -288,8 +268,8 @@ resource "azurerm_key_vault_access_policy" "test" { `, template) } -func testAccAzureRMKeyVaultAccessPolicy_requiresImport(rString string, location string) string { - template := testAccAzureRMKeyVaultAccessPolicy_basic(rString, location) +func testAccAzureRMKeyVaultAccessPolicy_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMKeyVaultAccessPolicy_basic(data) return fmt.Sprintf(` %s @@ -310,8 +290,8 @@ resource "azurerm_key_vault_access_policy" "import" { `, template) } -func testAccAzureRMKeyVaultAccessPolicy_multiple(rString string, location string) string { - template := testAccAzureRMKeyVaultAccessPolicy_template(rString, location) +func testAccAzureRMKeyVaultAccessPolicy_multiple(data acceptance.TestData) string { + template := testAccAzureRMKeyVaultAccessPolicy_template(data) return fmt.Sprintf(` %s @@ -379,8 +359,8 @@ resource "azurerm_key_vault_access_policy" "test_no_application_id" { `, template) } -func testAccAzureRMKeyVaultAccessPolicy_update(rString string, location string) string { - template := testAccAzureRMKeyVaultAccessPolicy_template(rString, location) +func testAccAzureRMKeyVaultAccessPolicy_update(data acceptance.TestData) string { + template := testAccAzureRMKeyVaultAccessPolicy_template(data) return fmt.Sprintf(` %s @@ -401,7 +381,7 @@ resource "azurerm_key_vault_access_policy" "test" { `, template) } -func testAccAzureRMKeyVaultAccessPolicy_template(rString string, location string) string { +func testAccAzureRMKeyVaultAccessPolicy_template(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -422,10 +402,10 @@ resource "azurerm_key_vault" "test" { environment = "Production" } } -`, rString, location, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString) } -func testAccAzureRMKeyVaultAccessPolicy_nonExistentVault(rString string, location string) string { +func testAccAzureRMKeyVaultAccessPolicy_nonExistentVault(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -462,5 +442,5 @@ resource "azurerm_key_vault_access_policy" "test" { "get", ] } -`, rString, location, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_certificate_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_certificate_test.go similarity index 78% rename from azurerm/internal/services/keyvault/resource_arm_key_vault_certificate_test.go rename to azurerm/internal/services/keyvault/tests/resource_arm_key_vault_certificate_test.go index 8284def0639d..27043f51fd45 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_certificate_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_certificate_test.go @@ -1,4 +1,4 @@ -package keyvault +package tests import ( "fmt" @@ -10,16 +10,14 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMKeyVaultCertificate_basicImportPFX(t *testing.T) { - resourceName := "azurerm_key_vault_certificate.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultCertificate_basicImportPFX(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") + config := testAccAzureRMKeyVaultCertificate_basicImportPFX(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,24 +27,18 @@ func TestAccAzureRMKeyVaultCertificate_basicImportPFX(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultCertificateExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "certificate_data"), + testCheckAzureRMKeyVaultCertificateExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "certificate_data"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"certificate"}, - }, + data.ImportStep("certificate"), }, }) } func TestAccAzureRMKeyVaultCertificate_basicImportPFXClassic(t *testing.T) { - resourceName := "azurerm_key_vault_certificate.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultCertificate_basicImportPFXClassic(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") + config := testAccAzureRMKeyVaultCertificate_basicImportPFXClassic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,16 +48,11 @@ func TestAccAzureRMKeyVaultCertificate_basicImportPFXClassic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultCertificateExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "certificate_data"), + testCheckAzureRMKeyVaultCertificateExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "certificate_data"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"certificate"}, - }, + data.ImportStep("certificate"), }, }) } @@ -76,9 +63,7 @@ func TestAccAzureRMKeyVaultCertificate_requiresImport(t *testing.T) { return } - resourceName := "azurerm_key_vault_certificate.test" - rs := acctest.RandString(6) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,14 +71,14 @@ func TestAccAzureRMKeyVaultCertificate_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKeyVaultCertificate_basicImportPFX(rs, location), + Config: testAccAzureRMKeyVaultCertificate_basicImportPFX(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultCertificateExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "certificate_data"), + testCheckAzureRMKeyVaultCertificateExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "certificate_data"), ), }, { - Config: testAccAzureRMKeyVaultCertificate_requiresImport(rs, location), + Config: testAccAzureRMKeyVaultCertificate_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_key_vault_certificate"), }, }, @@ -101,9 +86,8 @@ func TestAccAzureRMKeyVaultCertificate_requiresImport(t *testing.T) { } func TestAccAzureRMKeyVaultCertificate_disappears(t *testing.T) { - resourceName := "azurerm_key_vault_certificate.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultCertificate_basicGenerate(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") + config := testAccAzureRMKeyVaultCertificate_basicGenerate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,8 +97,8 @@ func TestAccAzureRMKeyVaultCertificate_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultCertificateExists(resourceName), - testCheckAzureRMKeyVaultCertificateDisappears(resourceName), + testCheckAzureRMKeyVaultCertificateExists(data.ResourceName), + testCheckAzureRMKeyVaultCertificateDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -123,8 +107,8 @@ func TestAccAzureRMKeyVaultCertificate_disappears(t *testing.T) { } func TestAccAzureRMKeyVaultCertificate_disappearsWhenParentKeyVaultDeleted(t *testing.T) { - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultCertificate_basicGenerate(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") + config := testAccAzureRMKeyVaultCertificate_basicGenerate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -144,9 +128,8 @@ func TestAccAzureRMKeyVaultCertificate_disappearsWhenParentKeyVaultDeleted(t *te } func TestAccAzureRMKeyVaultCertificate_basicGenerate(t *testing.T) { - resourceName := "azurerm_key_vault_certificate.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultCertificate_basicGenerate(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") + config := testAccAzureRMKeyVaultCertificate_basicGenerate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -156,24 +139,19 @@ func TestAccAzureRMKeyVaultCertificate_basicGenerate(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultCertificateExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "secret_id"), - resource.TestCheckResourceAttrSet(resourceName, "certificate_data"), + testCheckAzureRMKeyVaultCertificateExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "secret_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "certificate_data"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKeyVaultCertificate_basicGenerateSans(t *testing.T) { - resourceName := "azurerm_key_vault_certificate.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultCertificate_basicGenerateSans(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") + config := testAccAzureRMKeyVaultCertificate_basicGenerateSans(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -183,11 +161,11 @@ func TestAccAzureRMKeyVaultCertificate_basicGenerateSans(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultCertificateExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "certificate_data"), - resource.TestCheckResourceAttr(resourceName, "certificate_policy.0.x509_certificate_properties.0.subject_alternative_names.0.emails.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate_policy.0.x509_certificate_properties.0.subject_alternative_names.0.dns_names.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate_policy.0.x509_certificate_properties.0.subject_alternative_names.0.upns.#", "1"), + testCheckAzureRMKeyVaultCertificateExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "certificate_data"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_policy.0.x509_certificate_properties.0.subject_alternative_names.0.emails.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_policy.0.x509_certificate_properties.0.subject_alternative_names.0.dns_names.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_policy.0.x509_certificate_properties.0.subject_alternative_names.0.upns.#", "1"), ), }, }, @@ -195,9 +173,8 @@ func TestAccAzureRMKeyVaultCertificate_basicGenerateSans(t *testing.T) { } func TestAccAzureRMKeyVaultCertificate_basicGenerateTags(t *testing.T) { - resourceName := "azurerm_key_vault_certificate.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultCertificate_basicGenerateTags(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") + config := testAccAzureRMKeyVaultCertificate_basicGenerateTags(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -207,25 +184,20 @@ func TestAccAzureRMKeyVaultCertificate_basicGenerateTags(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultCertificateExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "certificate_data"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.hello", "world"), + testCheckAzureRMKeyVaultCertificateExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "certificate_data"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.hello", "world"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKeyVaultCertificate_basicExtendedKeyUsage(t *testing.T) { - resourceName := "azurerm_key_vault_certificate.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultCertificate_basicExtendedKeyUsage(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") + config := testAccAzureRMKeyVaultCertificate_basicExtendedKeyUsage(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -235,12 +207,12 @@ func TestAccAzureRMKeyVaultCertificate_basicExtendedKeyUsage(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultCertificateExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "certificate_data"), - resource.TestCheckResourceAttr(resourceName, "certificate_policy.0.x509_certificate_properties.0.extended_key_usage.#", "3"), - resource.TestCheckResourceAttr(resourceName, "certificate_policy.0.x509_certificate_properties.0.extended_key_usage.0", "1.3.6.1.5.5.7.3.1"), - resource.TestCheckResourceAttr(resourceName, "certificate_policy.0.x509_certificate_properties.0.extended_key_usage.1", "1.3.6.1.5.5.7.3.2"), - resource.TestCheckResourceAttr(resourceName, "certificate_policy.0.x509_certificate_properties.0.extended_key_usage.2", "1.3.6.1.4.1.311.21.10"), + testCheckAzureRMKeyVaultCertificateExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "certificate_data"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_policy.0.x509_certificate_properties.0.extended_key_usage.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_policy.0.x509_certificate_properties.0.extended_key_usage.0", "1.3.6.1.5.5.7.3.1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_policy.0.x509_certificate_properties.0.extended_key_usage.1", "1.3.6.1.5.5.7.3.2"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_policy.0.x509_certificate_properties.0.extended_key_usage.2", "1.3.6.1.4.1.311.21.10"), ), }, }, @@ -248,9 +220,8 @@ func TestAccAzureRMKeyVaultCertificate_basicExtendedKeyUsage(t *testing.T) { } func TestAccAzureRMKeyVaultCertificate_emptyExtendedKeyUsage(t *testing.T) { - resourceName := "azurerm_key_vault_certificate.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultCertificate_emptyExtendedKeyUsage(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_certificate", "test") + config := testAccAzureRMKeyVaultCertificate_emptyExtendedKeyUsage(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -260,9 +231,9 @@ func TestAccAzureRMKeyVaultCertificate_emptyExtendedKeyUsage(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultCertificateExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "certificate_data"), - resource.TestCheckResourceAttr(resourceName, "certificate_policy.0.x509_certificate_properties.0.extended_key_usage.#", "0"), + testCheckAzureRMKeyVaultCertificateExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "certificate_data"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate_policy.0.x509_certificate_properties.0.extended_key_usage.#", "0"), ), }, }, @@ -379,7 +350,7 @@ func testCheckAzureRMKeyVaultCertificateDisappears(resourceName string) resource } } -func testAccAzureRMKeyVaultCertificate_basicImportPFX(rString string, location string) string { +func testAccAzureRMKeyVaultCertificate_basicImportPFX(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -442,10 +413,10 @@ resource "azurerm_key_vault_certificate" "test" { } } } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultCertificate_basicImportPFXClassic(rString string, location string) string { +func testAccAzureRMKeyVaultCertificate_basicImportPFXClassic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -512,11 +483,11 @@ resource "azurerm_key_vault_certificate" "test" { } } } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultCertificate_requiresImport(rString string, location string) string { - template := testAccAzureRMKeyVaultCertificate_basicImportPFX(rString, location) +func testAccAzureRMKeyVaultCertificate_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMKeyVaultCertificate_basicImportPFX(data) return fmt.Sprintf(` %s @@ -549,7 +520,7 @@ resource "azurerm_key_vault_certificate" "import" { `, template) } -func testAccAzureRMKeyVaultCertificate_basicGenerate(rString string, location string) string { +func testAccAzureRMKeyVaultCertificate_basicGenerate(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -636,10 +607,10 @@ resource "azurerm_key_vault_certificate" "test" { } } } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultCertificate_basicGenerateSans(rString string, location string) string { +func testAccAzureRMKeyVaultCertificate_basicGenerateSans(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -733,10 +704,10 @@ resource "azurerm_key_vault_certificate" "test" { } } } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultCertificate_basicGenerateTags(rString string, location string) string { +func testAccAzureRMKeyVaultCertificate_basicGenerateTags(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -823,10 +794,10 @@ resource "azurerm_key_vault_certificate" "test" { "hello" = "world" } } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultCertificate_basicExtendedKeyUsage(rString string, location string) string { +func testAccAzureRMKeyVaultCertificate_basicExtendedKeyUsage(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -919,10 +890,10 @@ resource "azurerm_key_vault_certificate" "test" { } } } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultCertificate_emptyExtendedKeyUsage(rString string, location string) string { +func testAccAzureRMKeyVaultCertificate_emptyExtendedKeyUsage(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -1011,5 +982,5 @@ resource "azurerm_key_vault_certificate" "test" { } } } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_key_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_key_test.go similarity index 77% rename from azurerm/internal/services/keyvault/resource_arm_key_vault_key_test.go rename to azurerm/internal/services/keyvault/tests/resource_arm_key_vault_key_test.go index afed4a81fb7f..cf5f2b45e3d4 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_key_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_key_test.go @@ -1,4 +1,4 @@ -package keyvault +package tests import ( "fmt" @@ -10,16 +10,14 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMKeyVaultKey_basicEC(t *testing.T) { - resourceName := "azurerm_key_vault_key.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultKey_basicEC(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") + config := testAccAzureRMKeyVaultKey_basicEC(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,23 +27,17 @@ func TestAccAzureRMKeyVaultKey_basicEC(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"key_size"}, - }, + data.ImportStep("key_size"), }, }) } func TestAccAzureRMKeyVaultKey_basicECClassic(t *testing.T) { - resourceName := "azurerm_key_vault_key.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultKey_basicECClassic(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") + config := testAccAzureRMKeyVaultKey_basicECClassic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,15 +47,10 @@ func TestAccAzureRMKeyVaultKey_basicECClassic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"key_size"}, - }, + data.ImportStep("key_size"), }, }) } @@ -74,9 +61,7 @@ func TestAccAzureRMKeyVaultKey_requiresImport(t *testing.T) { return } - resourceName := "azurerm_key_vault_key.test" - rs := acctest.RandString(6) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,13 +69,13 @@ func TestAccAzureRMKeyVaultKey_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultKeyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKeyVaultKey_basicEC(rs, location), + Config: testAccAzureRMKeyVaultKey_basicEC(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), ), }, { - Config: testAccAzureRMKeyVaultKey_requiresImport(rs, location), + Config: testAccAzureRMKeyVaultKey_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_key_vault_key"), }, }, @@ -98,9 +83,8 @@ func TestAccAzureRMKeyVaultKey_requiresImport(t *testing.T) { } func TestAccAzureRMKeyVaultKey_basicECHSM(t *testing.T) { - resourceName := "azurerm_key_vault_key.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultKey_basicECHSM(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") + config := testAccAzureRMKeyVaultKey_basicECHSM(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -110,7 +94,7 @@ func TestAccAzureRMKeyVaultKey_basicECHSM(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), ), }, }, @@ -118,9 +102,8 @@ func TestAccAzureRMKeyVaultKey_basicECHSM(t *testing.T) { } func TestAccAzureRMKeyVaultKey_curveEC(t *testing.T) { - resourceName := "azurerm_key_vault_key.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultKey_curveEC(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") + config := testAccAzureRMKeyVaultKey_curveEC(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -130,22 +113,17 @@ func TestAccAzureRMKeyVaultKey_curveEC(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKeyVaultKey_basicRSA(t *testing.T) { - resourceName := "azurerm_key_vault_key.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultKey_basicRSA(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") + config := testAccAzureRMKeyVaultKey_basicRSA(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -155,23 +133,17 @@ func TestAccAzureRMKeyVaultKey_basicRSA(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"key_size"}, - }, + data.ImportStep("key_size"), }, }) } func TestAccAzureRMKeyVaultKey_basicRSAHSM(t *testing.T) { - resourceName := "azurerm_key_vault_key.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultKey_basicRSAHSM(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") + config := testAccAzureRMKeyVaultKey_basicRSAHSM(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -181,23 +153,17 @@ func TestAccAzureRMKeyVaultKey_basicRSAHSM(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"key_size"}, - }, + data.ImportStep("key_size"), }, }) } func TestAccAzureRMKeyVaultKey_complete(t *testing.T) { - resourceName := "azurerm_key_vault_key.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultKey_complete(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") + config := testAccAzureRMKeyVaultKey_complete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -207,26 +173,20 @@ func TestAccAzureRMKeyVaultKey_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.hello", "world"), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.hello", "world"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"key_size"}, - }, + data.ImportStep("key_size"), }, }) } func TestAccAzureRMKeyVaultKey_update(t *testing.T) { - resourceName := "azurerm_key_vault_key.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultKey_basicRSA(rs, acceptance.Location()) - updatedConfig := testAccAzureRMKeyVaultKey_basicUpdated(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") + config := testAccAzureRMKeyVaultKey_basicRSA(data) + updatedConfig := testAccAzureRMKeyVaultKey_basicUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -236,17 +196,17 @@ func TestAccAzureRMKeyVaultKey_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "key_opts.#", "6"), - resource.TestCheckResourceAttr(resourceName, "key_opts.0", "decrypt"), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "key_opts.#", "6"), + resource.TestCheckResourceAttr(data.ResourceName, "key_opts.0", "decrypt"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "key_opts.#", "5"), - resource.TestCheckResourceAttr(resourceName, "key_opts.0", "encrypt"), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "key_opts.#", "5"), + resource.TestCheckResourceAttr(data.ResourceName, "key_opts.0", "encrypt"), ), }, }, @@ -254,9 +214,7 @@ func TestAccAzureRMKeyVaultKey_update(t *testing.T) { } func TestAccAzureRMKeyVaultKey_disappears(t *testing.T) { - resourceName := "azurerm_key_vault_key.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultKey_basicEC(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -264,10 +222,10 @@ func TestAccAzureRMKeyVaultKey_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultKeyDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMKeyVaultKey_basicEC(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultKeyExists(resourceName), - testCheckAzureRMKeyVaultKeyDisappears(resourceName), + testCheckAzureRMKeyVaultKeyExists(data.ResourceName), + testCheckAzureRMKeyVaultKeyDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -276,8 +234,7 @@ func TestAccAzureRMKeyVaultKey_disappears(t *testing.T) { } func TestAccAzureRMKeyVaultKey_disappearsWhenParentKeyVaultDeleted(t *testing.T) { - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultKey_basicEC(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_key", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -285,7 +242,7 @@ func TestAccAzureRMKeyVaultKey_disappearsWhenParentKeyVaultDeleted(t *testing.T) CheckDestroy: testCheckAzureRMKeyVaultKeyDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMKeyVaultKey_basicEC(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKeyVaultKeyExists("azurerm_key_vault_key.test"), testCheckAzureRMKeyVaultDisappears("azurerm_key_vault.test"), @@ -406,7 +363,7 @@ func testCheckAzureRMKeyVaultKeyDisappears(resourceName string) resource.TestChe } } -func testAccAzureRMKeyVaultKey_basicEC(rString string, location string) string { +func testAccAzureRMKeyVaultKey_basicEC(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -456,10 +413,10 @@ resource "azurerm_key_vault_key" "test" { "verify", ] } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultKey_basicECClassic(rString string, location string) string { +func testAccAzureRMKeyVaultKey_basicECClassic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -509,11 +466,11 @@ resource "azurerm_key_vault_key" "test" { "verify", ] } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultKey_requiresImport(rString string, location string) string { - template := testAccAzureRMKeyVaultKey_basicEC(rString, location) +func testAccAzureRMKeyVaultKey_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMKeyVaultKey_basicEC(data) return fmt.Sprintf(` %s @@ -531,7 +488,7 @@ resource "azurerm_key_vault_key" "import" { `, template) } -func testAccAzureRMKeyVaultKey_basicRSA(rString string, location string) string { +func testAccAzureRMKeyVaultKey_basicRSA(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -586,10 +543,10 @@ resource "azurerm_key_vault_key" "test" { "wrapKey", ] } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultKey_basicRSAHSM(rString string, location string) string { +func testAccAzureRMKeyVaultKey_basicRSAHSM(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -643,10 +600,10 @@ resource "azurerm_key_vault_key" "test" { "wrapKey", ] } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultKey_complete(rString string, location string) string { +func testAccAzureRMKeyVaultKey_complete(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -704,10 +661,10 @@ resource "azurerm_key_vault_key" "test" { "hello" = "world" } } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultKey_basicUpdated(rString string, location string) string { +func testAccAzureRMKeyVaultKey_basicUpdated(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -761,10 +718,10 @@ resource "azurerm_key_vault_key" "test" { "wrapKey", ] } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultKey_curveEC(rString string, location string) string { +func testAccAzureRMKeyVaultKey_curveEC(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -816,10 +773,10 @@ resource "azurerm_key_vault_key" "test" { "verify", ] } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultKey_basicECHSM(rString string, location string) string { +func testAccAzureRMKeyVaultKey_basicECHSM(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -871,5 +828,5 @@ resource "azurerm_key_vault_key" "test" { "verify", ] } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_migration_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_migration_test.go similarity index 98% rename from azurerm/internal/services/keyvault/resource_arm_key_vault_migration_test.go rename to azurerm/internal/services/keyvault/tests/resource_arm_key_vault_migration_test.go index e3eed458484f..39d845b89ad1 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_migration_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_migration_test.go @@ -1,10 +1,11 @@ -package keyvault +package tests import ( "reflect" "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault` ) func TestAzureRMKeyVaultMigrateState(t *testing.T) { @@ -365,7 +366,7 @@ func TestAzureRMKeyVaultMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.Attributes, } - is, err := resourceAzureRMKeyVaultMigrateState(tc.StateVersion, is, tc.Meta) + is, err := keyvault.ResourceAzureRMKeyVaultMigrateState(tc.StateVersion, is, tc.Meta) if err != nil { t.Fatalf("bad: %q, err: %+v", tn, err) diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_secret_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_secret_test.go similarity index 77% rename from azurerm/internal/services/keyvault/resource_arm_key_vault_secret_test.go rename to azurerm/internal/services/keyvault/tests/resource_arm_key_vault_secret_test.go index 1e6c11423266..fe0ffade324d 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_secret_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_secret_test.go @@ -1,4 +1,4 @@ -package keyvault +package tests import ( "fmt" @@ -10,16 +10,14 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMKeyVaultSecret_basic(t *testing.T) { - resourceName := "azurerm_key_vault_secret.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultSecret_basic(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_secret", "test") + config := testAccAzureRMKeyVaultSecret_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,23 +27,18 @@ func TestAccAzureRMKeyVaultSecret_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultSecretExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "rick-and-morty"), + testCheckAzureRMKeyVaultSecretExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "rick-and-morty"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKeyVaultSecret_basicClassic(t *testing.T) { - resourceName := "azurerm_key_vault_secret.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultSecret_basicClasic(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_secret", "test") + config := testAccAzureRMKeyVaultSecret_basicClasic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,15 +48,11 @@ func TestAccAzureRMKeyVaultSecret_basicClassic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultSecretExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "rick-and-morty"), + testCheckAzureRMKeyVaultSecretExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "rick-and-morty"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -74,9 +63,7 @@ func TestAccAzureRMKeyVaultSecret_requiresImport(t *testing.T) { return } - resourceName := "azurerm_key_vault_secret.test" - rs := acctest.RandString(6) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_key_vault_secret", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,14 +71,14 @@ func TestAccAzureRMKeyVaultSecret_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultSecretDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKeyVaultSecret_basic(rs, location), + Config: testAccAzureRMKeyVaultSecret_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultSecretExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "rick-and-morty"), + testCheckAzureRMKeyVaultSecretExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "rick-and-morty"), ), }, { - Config: testAccAzureRMKeyVaultSecret_requiresImport(rs, location), + Config: testAccAzureRMKeyVaultSecret_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_key_vault_secret"), }, }, @@ -99,9 +86,8 @@ func TestAccAzureRMKeyVaultSecret_requiresImport(t *testing.T) { } func TestAccAzureRMKeyVaultSecret_disappears(t *testing.T) { - resourceName := "azurerm_key_vault_secret.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultSecret_basic(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_secret", "test") + config := testAccAzureRMKeyVaultSecret_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,8 +97,8 @@ func TestAccAzureRMKeyVaultSecret_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultSecretExists(resourceName), - testCheckAzureRMKeyVaultSecretDisappears(resourceName), + testCheckAzureRMKeyVaultSecretExists(data.ResourceName), + testCheckAzureRMKeyVaultSecretDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -121,8 +107,8 @@ func TestAccAzureRMKeyVaultSecret_disappears(t *testing.T) { } func TestAccAzureRMKeyVaultSecret_disappearsWhenParentKeyVaultDeleted(t *testing.T) { - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultSecret_basic(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_secret", "test") + config := testAccAzureRMKeyVaultSecret_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -142,9 +128,8 @@ func TestAccAzureRMKeyVaultSecret_disappearsWhenParentKeyVaultDeleted(t *testing } func TestAccAzureRMKeyVaultSecret_complete(t *testing.T) { - resourceName := "azurerm_key_vault_secret.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultSecret_complete(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_secret", "test") + config := testAccAzureRMKeyVaultSecret_complete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -154,27 +139,22 @@ func TestAccAzureRMKeyVaultSecret_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultSecretExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "not_before_date", "2019-01-01T01:02:03Z"), - resource.TestCheckResourceAttr(resourceName, "expiration_date", "2020-01-01T01:02:03Z"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.hello", "world"), + testCheckAzureRMKeyVaultSecretExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "not_before_date", "2019-01-01T01:02:03Z"), + resource.TestCheckResourceAttr(data.ResourceName, "expiration_date", "2020-01-01T01:02:03Z"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.hello", "world"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKeyVaultSecret_update(t *testing.T) { - resourceName := "azurerm_key_vault_secret.test" - rs := acctest.RandString(6) - config := testAccAzureRMKeyVaultSecret_basic(rs, acceptance.Location()) - updatedConfig := testAccAzureRMKeyVaultSecret_basicUpdated(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault_secret", "test") + config := testAccAzureRMKeyVaultSecret_basic(data) + updatedConfig := testAccAzureRMKeyVaultSecret_basicUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -184,15 +164,15 @@ func TestAccAzureRMKeyVaultSecret_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultSecretExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "rick-and-morty"), + testCheckAzureRMKeyVaultSecretExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "rick-and-morty"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultSecretExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "szechuan"), + testCheckAzureRMKeyVaultSecretExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "szechuan"), ), }, }, @@ -308,7 +288,7 @@ func testCheckAzureRMKeyVaultSecretDisappears(resourceName string) resource.Test } } -func testAccAzureRMKeyVaultSecret_basic(rString string, location string) string { +func testAccAzureRMKeyVaultSecret_basic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -350,10 +330,10 @@ resource "azurerm_key_vault_secret" "test" { value = "rick-and-morty" key_vault_id = "${azurerm_key_vault.test.id}" } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultSecret_basicClasic(rString string, location string) string { +func testAccAzureRMKeyVaultSecret_basicClasic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -395,11 +375,11 @@ resource "azurerm_key_vault_secret" "test" { value = "rick-and-morty" vault_uri = "${azurerm_key_vault.test.vault_uri}" } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultSecret_requiresImport(rString string, location string) string { - template := testAccAzureRMKeyVaultSecret_basic(rString, location) +func testAccAzureRMKeyVaultSecret_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMKeyVaultSecret_basic(data) return fmt.Sprintf(` %s @@ -411,7 +391,7 @@ resource "azurerm_key_vault_secret" "import" { `, template) } -func testAccAzureRMKeyVaultSecret_complete(rString string, location string) string { +func testAccAzureRMKeyVaultSecret_complete(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -460,10 +440,10 @@ resource "azurerm_key_vault_secret" "test" { "hello" = "world" } } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMKeyVaultSecret_basicUpdated(rString string, location string) string { +func testAccAzureRMKeyVaultSecret_basicUpdated(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -505,5 +485,5 @@ resource "azurerm_key_vault_secret" "test" { value = "szechuan" vault_uri = "${azurerm_key_vault.test.vault_uri}" } -`, rString, location, rString, rString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go similarity index 75% rename from azurerm/internal/services/keyvault/resource_arm_key_vault_test.go rename to azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go index 9b807eb77a21..37ff79b1efa5 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go @@ -1,4 +1,4 @@ -package keyvault +package tests import ( "fmt" @@ -6,13 +6,12 @@ import ( "testing" "github.com/hashicorp/go-azure-helpers/response" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault` "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -64,10 +63,9 @@ func TestAccAzureRMKeyVault_name(t *testing.T) { } for _, tc := range cases { - _, errors := validateKeyVaultName(tc.Input, "") + _, errors := keyvault.ValidateKeyVaultName(tc.Input, "") hasError := len(errors) > 0 - if tc.ExpectError && !hasError { t.Fatalf("Expected the Key Vault Name to trigger a validation error for '%s'", tc.Input) } @@ -75,9 +73,8 @@ func TestAccAzureRMKeyVault_name(t *testing.T) { } func TestAccAzureRMKeyVault_basic(t *testing.T) { - resourceName := "azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMKeyVault_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + config := testAccAzureRMKeyVault_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,23 +84,19 @@ func TestAccAzureRMKeyVault_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku_name", "premium"), + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "premium"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } // Remove in 2.0 func TestAccAzureRMKeyVault_basicNotDefined(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMKeyVault_basicNotDefined(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + config := testAccAzureRMKeyVault_basicNotDefined(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -120,9 +113,8 @@ func TestAccAzureRMKeyVault_basicNotDefined(t *testing.T) { // Remove in 2.0 func TestAccAzureRMKeyVault_basicClassic(t *testing.T) { - resourceName := "azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMKeyVault_basicClassic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + config := testAccAzureRMKeyVault_basicClassic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -132,15 +124,11 @@ func TestAccAzureRMKeyVault_basicClassic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "premium"), + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "premium"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -151,9 +139,7 @@ func TestAccAzureRMKeyVault_requiresImport(t *testing.T) { return } - resourceName := "azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -161,13 +147,13 @@ func TestAccAzureRMKeyVault_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKeyVault_basic(ri, location), + Config: testAccAzureRMKeyVault_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), + testCheckAzureRMKeyVaultExists(data.ResourceName), ), }, { - Config: testAccAzureRMKeyVault_requiresImport(ri, location), + Config: testAccAzureRMKeyVault_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_key_vault"), }, }, @@ -175,9 +161,7 @@ func TestAccAzureRMKeyVault_requiresImport(t *testing.T) { } func TestAccAzureRMKeyVault_networkAcls(t *testing.T) { - resourceName := "azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -185,35 +169,25 @@ func TestAccAzureRMKeyVault_networkAcls(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKeyVault_networkAcls(ri, location), + Config: testAccAzureRMKeyVault_networkAcls(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), + testCheckAzureRMKeyVaultExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMKeyVault_networkAclsUpdated(ri, location), + Config: testAccAzureRMKeyVault_networkAclsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), + testCheckAzureRMKeyVaultExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKeyVault_networkAclsAllowed(t *testing.T) { - resourceName := "azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -221,25 +195,18 @@ func TestAccAzureRMKeyVault_networkAclsAllowed(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKeyVault_networkAclsAllowed(ri, location), + Config: testAccAzureRMKeyVault_networkAclsAllowed(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), + testCheckAzureRMKeyVaultExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKeyVault_accessPolicyUpperLimit(t *testing.T) { - resourceName := "azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(10) - config := testAccAzureRMKeyVault_accessPolicyUpperLimit(ri, acceptance.Location(), rs) + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -247,10 +214,10 @@ func TestAccAzureRMKeyVault_accessPolicyUpperLimit(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMKeyVault_accessPolicyUpperLimit(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), - testCheckAzureRMKeyVaultDisappears(resourceName), + testCheckAzureRMKeyVaultExists(data.ResourceName), + testCheckAzureRMKeyVaultDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -259,9 +226,7 @@ func TestAccAzureRMKeyVault_accessPolicyUpperLimit(t *testing.T) { } func TestAccAzureRMKeyVault_disappears(t *testing.T) { - resourceName := "azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMKeyVault_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -269,10 +234,10 @@ func TestAccAzureRMKeyVault_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMKeyVault_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), - testCheckAzureRMKeyVaultDisappears(resourceName), + testCheckAzureRMKeyVaultExists(data.ResourceName), + testCheckAzureRMKeyVaultDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -281,9 +246,7 @@ func TestAccAzureRMKeyVault_disappears(t *testing.T) { } func TestAccAzureRMKeyVault_complete(t *testing.T) { - resourceName := "azurerm_key_vault.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMKeyVault_complete(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -291,28 +254,23 @@ func TestAccAzureRMKeyVault_complete(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMKeyVault_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "access_policy.0.application_id"), + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "access_policy.0.application_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMKeyVault_update(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_key_vault.test" - preConfig := testAccAzureRMKeyVault_basic(ri, acceptance.Location()) - postConfig := testAccAzureRMKeyVault_update(ri, acceptance.Location()) - noAccessPolicyConfig := testAccAzureRMKeyVault_noAccessPolicyBlocks(ri, acceptance.Location()) - forceZeroAccessPolicyConfig := testAccAzureRMKeyVault_accessPolicyExplicitZero(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") + preConfig := testAccAzureRMKeyVault_basic(data) + postConfig := testAccAzureRMKeyVault_update(data) + noAccessPolicyConfig := testAccAzureRMKeyVault_noAccessPolicyBlocks(data) + forceZeroAccessPolicyConfig := testAccAzureRMKeyVault_accessPolicyExplicitZero(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -322,21 +280,21 @@ func TestAccAzureRMKeyVault_update(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "access_policy.0.key_permissions.0", "create"), - resource.TestCheckResourceAttr(resourceName, "access_policy.0.secret_permissions.0", "set"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "create"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "set"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "access_policy.0.key_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName, "access_policy.0.secret_permissions.0", "get"), - resource.TestCheckResourceAttr(resourceName, "enabled_for_deployment", "true"), - resource.TestCheckResourceAttr(resourceName, "enabled_for_disk_encryption", "true"), - resource.TestCheckResourceAttr(resourceName, "enabled_for_template_deployment", "true"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Staging"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.key_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.secret_permissions.0", "get"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled_for_deployment", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled_for_disk_encryption", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled_for_template_deployment", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Staging"), ), }, { @@ -345,7 +303,7 @@ func TestAccAzureRMKeyVault_update(t *testing.T) { // There are no access_policy blocks in this configuration // at all, which means to ignore any existing policies and // so the one created in previous steps is still present. - resource.TestCheckResourceAttr(resourceName, "access_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.#", "1"), ), }, { @@ -353,7 +311,7 @@ func TestAccAzureRMKeyVault_update(t *testing.T) { Check: resource.ComposeTestCheckFunc( // This config explicitly sets access_policy = [], which // means to delete any existing policies. - resource.TestCheckResourceAttr(resourceName, "access_policy.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.#", "0"), ), }, }, @@ -361,8 +319,7 @@ func TestAccAzureRMKeyVault_update(t *testing.T) { } func TestAccAzureRMKeyVault_justCert(t *testing.T) { - resourceName := "azurerm_key_vault.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_key_vault", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -370,17 +327,13 @@ func TestAccAzureRMKeyVault_justCert(t *testing.T) { CheckDestroy: testCheckAzureRMKeyVaultDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKeyVault_justCert(ri, acceptance.Location()), + Config: testAccAzureRMKeyVault_justCert(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKeyVaultExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "access_policy.0.certificate_permissions.0", "get"), + testCheckAzureRMKeyVaultExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "access_policy.0.certificate_permissions.0", "get"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -471,7 +424,7 @@ func testCheckAzureRMKeyVaultDisappears(resourceName string) resource.TestCheckF } } -func testAccAzureRMKeyVault_basic(rInt int, location string) string { +func testAccAzureRMKeyVault_basic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -501,10 +454,10 @@ resource "azurerm_key_vault" "test" { ] } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMKeyVault_basicNotDefined(rInt int, location string) string { +func testAccAzureRMKeyVault_basicNotDefined(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -532,10 +485,10 @@ resource "azurerm_key_vault" "test" { ] } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMKeyVault_basicClassic(rInt int, location string) string { +func testAccAzureRMKeyVault_basicClassic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -567,11 +520,11 @@ resource "azurerm_key_vault" "test" { ] } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMKeyVault_requiresImport(rInt int, location string) string { - template := testAccAzureRMKeyVault_basic(rInt, location) +func testAccAzureRMKeyVault_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMKeyVault_basic(data) return fmt.Sprintf(` %s @@ -599,7 +552,7 @@ resource "azurerm_key_vault" "import" { `, template) } -func testAccAzureRMKeyVault_networkAclsTemplate(rInt int, location string) string { +func testAccAzureRMKeyVault_networkAclsTemplate(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -630,11 +583,11 @@ resource "azurerm_subnet" "test_b" { address_prefix = "10.0.4.0/24" service_endpoints = ["Microsoft.KeyVault"] } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMKeyVault_networkAcls(rInt int, location string) string { - template := testAccAzureRMKeyVault_networkAclsTemplate(rInt, location) +func testAccAzureRMKeyVault_networkAcls(data acceptance.TestData) string { + template := testAccAzureRMKeyVault_networkAclsTemplate(data) return fmt.Sprintf(` %s @@ -665,11 +618,11 @@ resource "azurerm_key_vault" "test" { virtual_network_subnet_ids = ["${azurerm_subnet.test_a.id}", "${azurerm_subnet.test_b.id}"] } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMKeyVault_networkAclsUpdated(rInt int, location string) string { - template := testAccAzureRMKeyVault_networkAclsTemplate(rInt, location) +func testAccAzureRMKeyVault_networkAclsUpdated(data acceptance.TestData) string { + template := testAccAzureRMKeyVault_networkAclsTemplate(data) return fmt.Sprintf(` %s @@ -701,11 +654,11 @@ resource "azurerm_key_vault" "test" { virtual_network_subnet_ids = ["${azurerm_subnet.test_a.id}"] } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMKeyVault_networkAclsAllowed(rInt int, location string) string { - template := testAccAzureRMKeyVault_networkAclsTemplate(rInt, location) +func testAccAzureRMKeyVault_networkAclsAllowed(data acceptance.TestData) string { + template := testAccAzureRMKeyVault_networkAclsTemplate(data) return fmt.Sprintf(` %s @@ -735,10 +688,10 @@ resource "azurerm_key_vault" "test" { bypass = "AzureServices" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMKeyVault_update(rInt int, location string) string { +func testAccAzureRMKeyVault_update(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -776,10 +729,10 @@ resource "azurerm_key_vault" "test" { environment = "Staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMKeyVault_noAccessPolicyBlocks(rInt int, location string) string { +func testAccAzureRMKeyVault_noAccessPolicyBlocks(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -806,10 +759,10 @@ resource "azurerm_key_vault" "test" { environment = "Staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMKeyVault_accessPolicyExplicitZero(rInt int, location string) string { +func testAccAzureRMKeyVault_accessPolicyExplicitZero(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -838,10 +791,10 @@ resource "azurerm_key_vault" "test" { environment = "Staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMKeyVault_complete(rInt int, location string) string { +func testAccAzureRMKeyVault_complete(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -880,10 +833,10 @@ resource "azurerm_key_vault" "test" { environment = "Production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMKeyVault_justCert(rInt int, location string) string { +func testAccAzureRMKeyVault_justCert(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -909,15 +862,15 @@ resource "azurerm_key_vault" "test" { ] } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMKeyVault_accessPolicyUpperLimit(rInt int, location string, rs string) string { +func testAccAzureRMKeyVault_accessPolicyUpperLimit(data acceptance.TestData) string { var storageAccountConfigs string var accessPoliciesConfigs string for i := 1; i <= 20; i++ { - storageAccountConfigs += testAccAzureRMKeyVault_generateStorageAccountConfigs(i, rs) + storageAccountConfigs += testAccAzureRMKeyVault_generateStorageAccountConfigs(i, data.RandomString) accessPoliciesConfigs += testAccAzureRMKeyVault_generateAccessPolicyConfigs(i) } @@ -941,7 +894,7 @@ resource "azurerm_key_vault" "test" { %s -`, rInt, location, rInt, accessPoliciesConfigs, storageAccountConfigs) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, accessPoliciesConfigs, storageAccountConfigs) } func testAccAzureRMKeyVault_generateStorageAccountConfigs(accountNum int, rs string) string { diff --git a/azurerm/internal/services/network/data_source_public_ips_test.go b/azurerm/internal/services/network/data_source_public_ips_test.go index 0d6eedc9e418..5086edaed360 100644 --- a/azurerm/internal/services/network/data_source_public_ips_test.go +++ b/azurerm/internal/services/network/data_source_public_ips_test.go @@ -186,7 +186,7 @@ resource "azurerm_public_ip" "test2" { environment = "test" } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testAccDataSourceAzureRMPublicIPs_prefixDataSource(rInt int, rString string, location string) string { @@ -233,7 +233,7 @@ resource "azurerm_public_ip" "static" { environment = "test" } } -`, rInt, location, rString, rString) +`, rInt, location, data.RandomString, data.RandomString) } func testAccDataSourceAzureRMPublicIPs_allocationTypeDataSources(rInt int, rString string, location string) string { From 534bf7de870ddff2430744733336a0499e6dd04a Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 09:04:37 -0800 Subject: [PATCH 130/203] move keyvault testdata into tests package --- .../keyvault/{ => tests}/testdata/keyvaultcert.pfx | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename azurerm/internal/services/keyvault/{ => tests}/testdata/keyvaultcert.pfx (100%) diff --git a/azurerm/internal/services/keyvault/testdata/keyvaultcert.pfx b/azurerm/internal/services/keyvault/tests/testdata/keyvaultcert.pfx similarity index 100% rename from azurerm/internal/services/keyvault/testdata/keyvaultcert.pfx rename to azurerm/internal/services/keyvault/tests/testdata/keyvaultcert.pfx From 1952ab5ab26578f843c01672c758b4fcbd08e488 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 18:30:07 +0100 Subject: [PATCH 131/203] compute: fixing the remnants --- .../data_source_shared_image_test.go | 29 ++--- .../resource_arm_shared_image_test.go | 72 ++++------- .../resource_arm_shared_image_version_test.go | 8 +- ...urce_arm_virtual_machine_scale_set_test.go | 2 +- .../services/compute/validation_test.go | 117 ++++++++++++++++++ ...irtual_machine_scale_set_extension_test.go | 69 ----------- .../compute/virtual_machine_scale_set_test.go | 58 --------- 7 files changed, 160 insertions(+), 195 deletions(-) rename azurerm/internal/services/compute/{ => tests}/data_source_shared_image_test.go (62%) rename azurerm/internal/services/compute/{ => tests}/resource_arm_shared_image_test.go (73%) delete mode 100644 azurerm/internal/services/compute/virtual_machine_scale_set_extension_test.go delete mode 100644 azurerm/internal/services/compute/virtual_machine_scale_set_test.go diff --git a/azurerm/internal/services/compute/data_source_shared_image_test.go b/azurerm/internal/services/compute/tests/data_source_shared_image_test.go similarity index 62% rename from azurerm/internal/services/compute/data_source_shared_image_test.go rename to azurerm/internal/services/compute/tests/data_source_shared_image_test.go index 86959c898e16..8dd2b7dd3f01 100644 --- a/azurerm/internal/services/compute/data_source_shared_image_test.go +++ b/azurerm/internal/services/compute/tests/data_source_shared_image_test.go @@ -1,28 +1,24 @@ -package compute +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMSharedImage_basic(t *testing.T) { - dataSourceName := "data.azurerm_shared_image.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "data.azurerm_shared_image", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMSharedImageDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceSharedImage_basic(rInt, location), + Config: testAccDataSourceSharedImage_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -30,27 +26,24 @@ func TestAccDataSourceAzureRMSharedImage_basic(t *testing.T) { } func TestAccDataSourceAzureRMSharedImage_complete(t *testing.T) { - dataSourceName := "data.azurerm_shared_image.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "data.azurerm_shared_image", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMSharedImageDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceSharedImage_complete(rInt, location), + Config: testAccDataSourceSharedImage_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, }) } -func testAccDataSourceSharedImage_basic(rInt int, location string) string { - template := testAccAzureRMSharedImage_basic(rInt, location) +func testAccDataSourceSharedImage_basic(data acceptance.TestData) string { + template := testAccAzureRMSharedImage_basic(data) return fmt.Sprintf(` %s @@ -62,8 +55,8 @@ data "azurerm_shared_image" "test" { `, template) } -func testAccDataSourceSharedImage_complete(rInt int, location string) string { - template := testAccAzureRMSharedImage_complete(rInt, location) +func testAccDataSourceSharedImage_complete(data acceptance.TestData) string { + template := testAccAzureRMSharedImage_complete(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/compute/resource_arm_shared_image_test.go b/azurerm/internal/services/compute/tests/resource_arm_shared_image_test.go similarity index 73% rename from azurerm/internal/services/compute/resource_arm_shared_image_test.go rename to azurerm/internal/services/compute/tests/resource_arm_shared_image_test.go index de560adfebf8..a1a718d21bd7 100644 --- a/azurerm/internal/services/compute/resource_arm_shared_image_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_shared_image_test.go @@ -1,4 +1,4 @@ -package compute +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,26 +14,20 @@ import ( ) func TestAccAzureRMSharedImage_basic(t *testing.T) { - resourceName := "azurerm_shared_image.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_shared_image", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMSharedImageDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSharedImage_basic(ri, acceptance.Location()), + Config: testAccAzureRMSharedImage_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", ""), + testCheckAzureRMSharedImageExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,55 +37,43 @@ func TestAccAzureRMSharedImage_requiresImport(t *testing.T) { return } - resourceName := "azurerm_shared_image.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_shared_image", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMSharedImageDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSharedImage_basic(ri, location), + Config: testAccAzureRMSharedImage_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", ""), + testCheckAzureRMSharedImageExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), ), }, - { - Config: testAccAzureRMSharedImage_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_shared_image"), - }, + data.RequiresImportErrorStep(testAccAzureRMSharedImage_requiresImport), }, }) } func TestAccAzureRMSharedImage_complete(t *testing.T) { - resourceName := "azurerm_shared_image.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_shared_image", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMSharedImageDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSharedImage_complete(ri, acceptance.Location()), + Config: testAccAzureRMSharedImage_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSharedImageExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "os_type", "Linux"), - resource.TestCheckResourceAttr(resourceName, "description", "Wubba lubba dub dub"), - resource.TestCheckResourceAttr(resourceName, "eula", "Do you agree there's infinite Rick's and Infinite Morty's?"), - resource.TestCheckResourceAttr(resourceName, "privacy_statement_uri", "https://council.of.ricks/privacy-statement"), - resource.TestCheckResourceAttr(resourceName, "release_note_uri", "https://council.of.ricks/changelog.md"), + testCheckAzureRMSharedImageExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "os_type", "Linux"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "Wubba lubba dub dub"), + resource.TestCheckResourceAttr(data.ResourceName, "eula", "Do you agree there's infinite Rick's and Infinite Morty's?"), + resource.TestCheckResourceAttr(data.ResourceName, "privacy_statement_uri", "https://council.of.ricks/privacy-statement"), + resource.TestCheckResourceAttr(data.ResourceName, "release_note_uri", "https://council.of.ricks/changelog.md"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -157,7 +138,7 @@ func testCheckAzureRMSharedImageExists(resourceName string) resource.TestCheckFu } } -func testAccAzureRMSharedImage_basic(rInt int, location string) string { +func testAccAzureRMSharedImage_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -183,10 +164,11 @@ resource "azurerm_shared_image" "test" { sku = "AccTesSku%d" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSharedImage_requiresImport(rInt int, location string) string { +func testAccAzureRMSharedImage_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMSharedImage_basic(data) return fmt.Sprintf(` %s @@ -203,10 +185,10 @@ resource "azurerm_shared_image" "import" { sku = "AccTesSku%d" } } -`, testAccAzureRMSharedImage_basic(rInt, location), rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSharedImage_complete(rInt int, location string) string { +func testAccAzureRMSharedImage_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -236,5 +218,5 @@ resource "azurerm_shared_image" "test" { sku = "AccTesSku%d" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go b/azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go index 52ebb5644cfe..7a40f9fa086c 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_shared_image_version_test.go @@ -33,7 +33,7 @@ func TestAccAzureRMSharedImageVersion_basic(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, acceptance.Location()), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { @@ -78,7 +78,7 @@ func TestAccAzureRMSharedImageVersion_storageAccountTypeLrs(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, acceptance.Location()), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { @@ -114,7 +114,7 @@ func TestAccAzureRMSharedImageVersion_storageAccountTypeZrs(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, acceptance.Location()), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { @@ -154,7 +154,7 @@ func TestAccAzureRMSharedImageVersion_requiresImport(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, acceptance.Location()), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { diff --git a/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_test.go index 233d30de7733..aaf2d2cc14d2 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_test.go @@ -607,7 +607,7 @@ func TestAccAzureRMVirtualMachineScaleSet_customImage(t *testing.T) { Destroy: false, Check: resource.ComposeTestCheckFunc( testCheckAzureVMExists("azurerm_virtual_machine.testsource", true), - testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, acceptance.Location()), + testGeneralizeVMImage(resourceGroup, "testsource", userName, password, hostName, sshPort, data.Locations.Primary), ), }, { diff --git a/azurerm/internal/services/compute/validation_test.go b/azurerm/internal/services/compute/validation_test.go index d57e97578d15..fc9a45d4c9fe 100644 --- a/azurerm/internal/services/compute/validation_test.go +++ b/azurerm/internal/services/compute/validation_test.go @@ -137,3 +137,120 @@ func TestValidateWindowsName(t *testing.T) { } } } + +func TestParseVirtualMachineScaleSetExtensionID(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *VirtualMachineScaleSetExtensionResourceID + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Virtual Machine Scale Set Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo", + Expected: nil, + }, + { + Name: "No Virtual Machine Scale Set Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/", + Expected: nil, + }, + { + Name: "No Extensions Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/machine1", + Expected: nil, + }, + { + Name: "No Extensions Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/machine1/extensions/", + Expected: nil, + }, + { + Name: "Completed", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/machine1/extensions/extension1", + Expected: &VirtualMachineScaleSetExtensionResourceID{ + Name: "extension1", + VirtualMachineName: "machine1", + ResourceGroup: "foo", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := ParseVirtualMachineScaleSetExtensionID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} + +func TestParseVirtualMachineScaleSetID(t *testing.T) { + testData := []struct { + Name string + Input string + Expected *VirtualMachineScaleSetResourceID + }{ + { + Name: "Empty", + Input: "", + Expected: nil, + }, + { + Name: "No Virtual Machine Scale Set Segment", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo", + Expected: nil, + }, + { + Name: "No Virtual Machine Scale Set Value", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/", + Expected: nil, + }, + { + Name: "Completed", + Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/example", + Expected: &VirtualMachineScaleSetResourceID{ + Name: "example", + ResourceGroup: "foo", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Name) + + actual, err := ParseVirtualMachineScaleSetID(v.Input) + if err != nil { + if v.Expected == nil { + continue + } + + t.Fatalf("Expected a value but got an error: %s", err) + } + + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + + if actual.ResourceGroup != v.Expected.ResourceGroup { + t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) + } + } +} diff --git a/azurerm/internal/services/compute/virtual_machine_scale_set_extension_test.go b/azurerm/internal/services/compute/virtual_machine_scale_set_extension_test.go deleted file mode 100644 index f95c01c24930..000000000000 --- a/azurerm/internal/services/compute/virtual_machine_scale_set_extension_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package compute - -import ( - "testing" -) - -func TestParseVirtualMachineScaleSetExtensionID(t *testing.T) { - testData := []struct { - Name string - Input string - Expected *VirtualMachineScaleSetExtensionResourceID - }{ - { - Name: "Empty", - Input: "", - Expected: nil, - }, - { - Name: "No Virtual Machine Scale Set Segment", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo", - Expected: nil, - }, - { - Name: "No Virtual Machine Scale Set Value", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/", - Expected: nil, - }, - { - Name: "No Extensions Segment", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/machine1", - Expected: nil, - }, - { - Name: "No Extensions Value", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/machine1/extensions/", - Expected: nil, - }, - { - Name: "Completed", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/machine1/extensions/extension1", - Expected: &VirtualMachineScaleSetExtensionResourceID{ - Name: "extension1", - VirtualMachineName: "machine1", - ResourceGroup: "foo", - }, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Name) - - actual, err := ParseVirtualMachineScaleSetExtensionID(v.Input) - if err != nil { - if v.Expected == nil { - continue - } - - t.Fatalf("Expected a value but got an error: %s", err) - } - - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) - } - - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) - } - } -} diff --git a/azurerm/internal/services/compute/virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/virtual_machine_scale_set_test.go deleted file mode 100644 index 7d761904b9a9..000000000000 --- a/azurerm/internal/services/compute/virtual_machine_scale_set_test.go +++ /dev/null @@ -1,58 +0,0 @@ -package compute - -import ( - "testing" -) - -func TestParseVirtualMachineScaleSetID(t *testing.T) { - testData := []struct { - Name string - Input string - Expected *VirtualMachineScaleSetResourceID - }{ - { - Name: "Empty", - Input: "", - Expected: nil, - }, - { - Name: "No Virtual Machine Scale Set Segment", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo", - Expected: nil, - }, - { - Name: "No Virtual Machine Scale Set Value", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/", - Expected: nil, - }, - { - Name: "Completed", - Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/virtualMachineScaleSets/example", - Expected: &VirtualMachineScaleSetResourceID{ - Name: "example", - ResourceGroup: "foo", - }, - }, - } - - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Name) - - actual, err := ParseVirtualMachineScaleSetID(v.Input) - if err != nil { - if v.Expected == nil { - continue - } - - t.Fatalf("Expected a value but got an error: %s", err) - } - - if actual.Name != v.Expected.Name { - t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) - } - - if actual.ResourceGroup != v.Expected.ResourceGroup { - t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) - } - } -} From 58abad0f8a91c25e118d62159a459c3b23cb975b Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 09:18:32 -0800 Subject: [PATCH 132/203] iothub: switching to the new test structure --- .../resource_arm_iot_dps_certificate_test.go | 70 +++------ .../{ => tests}/resource_arm_iot_dps_test.go | 92 +++++------- ...resource_arm_iothub_consumer_group_test.go | 55 +++---- ...esource_arm_iothub_dps_certificate_test.go | 70 +++------ ...rm_iothub_dps_shared_access_policy_test.go | 36 +++-- .../resource_arm_iothub_dps_test.go | 100 +++++-------- ...ource_arm_iothub_endpoint_eventhub_test.go | 34 ++--- ...m_iothub_endpoint_servicebus_queue_test.go | 34 ++--- ...m_iothub_endpoint_servicebus_topic_test.go | 34 ++--- ..._iothub_endpoint_storage_container_test.go | 42 +++--- ...resource_arm_iothub_fallback_route_test.go | 65 +++----- .../resource_arm_iothub_route_test.go | 65 +++----- ...ce_arm_iothub_shared_access_policy_test.go | 52 +++---- .../{ => tests}/resource_arm_iothub_test.go | 140 +++++++----------- .../testdata/application_gateway_test.cer | 0 .../testdata/batch_certificate.cer | 0 16 files changed, 325 insertions(+), 564 deletions(-) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iot_dps_certificate_test.go (75%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iot_dps_test.go (74%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_consumer_group_test.go (73%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_dps_certificate_test.go (75%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_dps_shared_access_policy_test.go (88%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_dps_test.go (71%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_endpoint_eventhub_test.go (86%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_endpoint_servicebus_queue_test.go (87%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_endpoint_servicebus_topic_test.go (87%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_endpoint_storage_container_test.go (84%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_fallback_route_test.go (81%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_route_test.go (83%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_shared_access_policy_test.go (79%) rename azurerm/internal/services/iothub/{ => tests}/resource_arm_iothub_test.go (74%) rename azurerm/internal/services/iothub/{ => tests}/testdata/application_gateway_test.cer (100%) rename azurerm/internal/services/iothub/{ => tests}/testdata/batch_certificate.cer (100%) diff --git a/azurerm/internal/services/iothub/resource_arm_iot_dps_certificate_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iot_dps_certificate_test.go similarity index 75% rename from azurerm/internal/services/iothub/resource_arm_iot_dps_certificate_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iot_dps_certificate_test.go index b1597915ec69..73cac8855a4a 100644 --- a/azurerm/internal/services/iothub/resource_arm_iot_dps_certificate_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iot_dps_certificate_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMIotDPSCertificate_basic(t *testing.T) { - resourceName := "azurerm_iot_dps_certificate.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iot_dps_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,19 +21,12 @@ func TestAccAzureRMIotDPSCertificate_basic(t *testing.T) { CheckDestroy: testCheckAzureRMIotDPSCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotDPSCertificate_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotDPSCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSCertificateExists(resourceName), + testCheckAzureRMIotDPSCertificateExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "certificate_content", - }, - }, + data.ImportStep("certificate_content"), }, }) } @@ -46,9 +37,7 @@ func TestAccAzureRMIotDPSCertificate_requiresImport(t *testing.T) { return } - resourceName := "azurerm_iot_dps_certificate.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iot_dps_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +45,13 @@ func TestAccAzureRMIotDPSCertificate_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMIotDPSCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotDPSCertificate_basic(rInt, location), + Config: testAccAzureRMIotDPSCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSCertificateExists(resourceName), + testCheckAzureRMIotDPSCertificateExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotDPSCertificate_requiresImport(rInt, location), + Config: testAccAzureRMIotDPSCertificate_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iotdps"), }, }, @@ -70,8 +59,7 @@ func TestAccAzureRMIotDPSCertificate_requiresImport(t *testing.T) { } func TestAccAzureRMIotDPSCertificate_update(t *testing.T) { - resourceName := "azurerm_iot_dps_certificate.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iot_dps_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,33 +67,19 @@ func TestAccAzureRMIotDPSCertificate_update(t *testing.T) { CheckDestroy: testCheckAzureRMIotDPSCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotDPSCertificate_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotDPSCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSCertificateExists(resourceName), + testCheckAzureRMIotDPSCertificateExists(data.ResourceName), ), }, + data.ImportStep("certificate_content"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "certificate_content", - }, - }, - { - Config: testAccAzureRMIotDPSCertificate_update(rInt, acceptance.Location()), + Config: testAccAzureRMIotDPSCertificate_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSCertificateExists(resourceName), + testCheckAzureRMIotDPSCertificateExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "certificate_content", - }, - }, + data.ImportStep("certificate_content"), }, }) } @@ -166,7 +140,7 @@ func testCheckAzureRMIotDPSCertificateExists(resourceName string) resource.TestC } } -func testAccAzureRMIotDPSCertificate_basic(rInt int, location string) string { +func testAccAzureRMIotDPSCertificate_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -192,11 +166,11 @@ resource "azurerm_iot_dps_certificate" "test" { certificate_content = "${filebase64("testdata/batch_certificate.cer")}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMIotDPSCertificate_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotDPS_basic(rInt, location) +func testAccAzureRMIotDPSCertificate_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotDPS_basic(data) return fmt.Sprintf(` %s @@ -210,7 +184,7 @@ resource "azurerm_iot_dps_certificate" "test" { `, template) } -func testAccAzureRMIotDPSCertificate_update(rInt int, location string) string { +func testAccAzureRMIotDPSCertificate_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -240,5 +214,5 @@ resource "azurerm_iot_dps_certificate" "test" { certificate_content = "${filebase64("testdata/application_gateway_test.cer")}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/iothub/resource_arm_iot_dps_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iot_dps_test.go similarity index 74% rename from azurerm/internal/services/iothub/resource_arm_iot_dps_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iot_dps_test.go index 2ddd83b1a558..bc2888bdf1c6 100644 --- a/azurerm/internal/services/iothub/resource_arm_iot_dps_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iot_dps_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMIotDPS_basic(t *testing.T) { - resourceName := "azurerm_iot_dps.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iot_dps", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,16 +21,12 @@ func TestAccAzureRMIotDPS_basic(t *testing.T) { CheckDestroy: testCheckAzureRMIotDPSDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotDPS_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotDPS_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(resourceName), + testCheckAzureRMIotDPSExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,9 +37,7 @@ func TestAccAzureRMIotDPS_requiresImport(t *testing.T) { return } - resourceName := "azurerm_iot_dps.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iot_dps", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,13 +45,13 @@ func TestAccAzureRMIotDPS_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMIotDPSDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotDPS_basic(rInt, location), + Config: testAccAzureRMIotDPS_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(resourceName), + testCheckAzureRMIotDPSExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotDPS_requiresImport(rInt, location), + Config: testAccAzureRMIotDPS_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iotdps"), }, }, @@ -67,8 +59,7 @@ func TestAccAzureRMIotDPS_requiresImport(t *testing.T) { } func TestAccAzureRMIotDPS_update(t *testing.T) { - resourceName := "azurerm_iot_dps.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iot_dps", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -76,34 +67,25 @@ func TestAccAzureRMIotDPS_update(t *testing.T) { CheckDestroy: testCheckAzureRMIotDPSDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotDPS_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotDPS_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(resourceName), + testCheckAzureRMIotDPSExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMIotDPS_update(rInt, acceptance.Location()), + Config: testAccAzureRMIotDPS_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(resourceName), + testCheckAzureRMIotDPSExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMIotDPS_linkedHubs(t *testing.T) { - resourceName := "azurerm_iot_dps.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iot_dps", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,27 +93,19 @@ func TestAccAzureRMIotDPS_linkedHubs(t *testing.T) { CheckDestroy: testCheckAzureRMIotDPSDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotDPS_linkedHubs(rInt, acceptance.Location()), + Config: testAccAzureRMIotDPS_linkedHubs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(resourceName), + testCheckAzureRMIotDPSExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMIotDPS_linkedHubsUpdated(rInt, acceptance.Location()), + Config: testAccAzureRMIotDPS_linkedHubsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotDPSExists(resourceName), + testCheckAzureRMIotDPSExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -189,7 +163,7 @@ func testCheckAzureRMIotDPSExists(resourceName string) resource.TestCheckFunc { } } -func testAccAzureRMIotDPS_basic(rInt int, location string) string { +func testAccAzureRMIotDPS_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -207,11 +181,11 @@ resource "azurerm_iot_dps" "test" { capacity = "1" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotDPS_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotDPS_basic(rInt, location) +func testAccAzureRMIotDPS_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotDPS_basic(data) return fmt.Sprintf(` %s @@ -229,7 +203,7 @@ resource "azurerm_iot_dps" "import" { `, template) } -func testAccAzureRMIotDPS_update(rInt int, location string) string { +func testAccAzureRMIotDPS_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -251,10 +225,10 @@ resource "azurerm_iot_dps" "test" { purpose = "testing" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotDPS_linkedHubs(rInt int, location string) string { +func testAccAzureRMIotDPS_linkedHubs(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -284,10 +258,10 @@ resource "azurerm_iot_dps" "test" { location = "${azurerm_resource_group.test.location}" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotDPS_linkedHubsUpdated(rInt int, location string) string { +func testAccAzureRMIotDPS_linkedHubsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -311,5 +285,5 @@ resource "azurerm_iot_dps" "test" { allocation_weight = 150 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_consumer_group_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_consumer_group_test.go similarity index 73% rename from azurerm/internal/services/iothub/resource_arm_iothub_consumer_group_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_consumer_group_test.go index 79cd21ffb9d1..a7786b69f5bf 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_consumer_group_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_consumer_group_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMIotHubConsumerGroup_events(t *testing.T) { - resourceName := "azurerm_iothub_consumer_group.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_consumer_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,17 +21,13 @@ func TestAccAzureRMIotHubConsumerGroup_events(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubConsumerGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubConsumerGroup_basic(rInt, location, "events"), + Config: testAccAzureRMIotHubConsumerGroup_basic(data, "events"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubConsumerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "eventhub_endpoint_name", "events"), + testCheckAzureRMIotHubConsumerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub_endpoint_name", "events"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,9 +38,7 @@ func TestAccAzureRMIotHubConsumerGroup_requiresImport(t *testing.T) { return } - resourceName := "azurerm_iothub_consumer_group.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_consumer_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,14 +46,14 @@ func TestAccAzureRMIotHubConsumerGroup_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubConsumerGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubConsumerGroup_basic(rInt, location, "events"), + Config: testAccAzureRMIotHubConsumerGroup_basic(data, "events"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubConsumerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "eventhub_endpoint_name", "events"), + testCheckAzureRMIotHubConsumerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub_endpoint_name", "events"), ), }, { - Config: testAccAzureRMIotHubConsumerGroup_requiresImport(rInt, location, "events"), + Config: testAccAzureRMIotHubConsumerGroup_requiresImport(data, "events"), ExpectError: acceptance.RequiresImportError("azurerm_iothub_consumer_group"), }, }, @@ -70,9 +61,7 @@ func TestAccAzureRMIotHubConsumerGroup_requiresImport(t *testing.T) { } func TestAccAzureRMIotHubConsumerGroup_operationsMonitoringEvents(t *testing.T) { - resourceName := "azurerm_iothub_consumer_group.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_consumer_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,16 +69,12 @@ func TestAccAzureRMIotHubConsumerGroup_operationsMonitoringEvents(t *testing.T) CheckDestroy: testCheckAzureRMIotHubConsumerGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubConsumerGroup_basic(rInt, location, "operationsMonitoringEvents"), + Config: testAccAzureRMIotHubConsumerGroup_basic(data, "operationsMonitoringEvents"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubConsumerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "eventhub_endpoint_name", "operationsMonitoringEvents"), + testCheckAzureRMIotHubConsumerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub_endpoint_name", "operationsMonitoringEvents"), ), - }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + }, data.ImportStep(), }, }) } @@ -149,7 +134,7 @@ func testCheckAzureRMIotHubConsumerGroupExists(resourceName string) resource.Tes } } -func testAccAzureRMIotHubConsumerGroup_basic(rInt int, location, eventName string) string { +func testAccAzureRMIotHubConsumerGroup_basic(data acceptance.TestData, eventName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -178,11 +163,11 @@ resource "azurerm_iothub_consumer_group" "test" { eventhub_endpoint_name = "%s" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, eventName) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, eventName) } -func testAccAzureRMIotHubConsumerGroup_requiresImport(rInt int, location, eventName string) string { - template := testAccAzureRMIotHubConsumerGroup_basic(rInt, location, eventName) +func testAccAzureRMIotHubConsumerGroup_requiresImport(data acceptance.TestData, eventName string) string { + template := testAccAzureRMIotHubConsumerGroup_basic(data, eventName) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_dps_certificate_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_certificate_test.go similarity index 75% rename from azurerm/internal/services/iothub/resource_arm_iothub_dps_certificate_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_certificate_test.go index 8951948e5be2..8582938e4ab8 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_dps_certificate_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_certificate_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMIotHubDPSCertificate_basic(t *testing.T) { - resourceName := "azurerm_iothub_dps_certificate.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,19 +21,12 @@ func TestAccAzureRMIotHubDPSCertificate_basic(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDPSCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDPSCertificate_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDPSCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDPSCertificateExists(resourceName), + testCheckAzureRMIotHubDPSCertificateExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "certificate_content", - }, - }, + data.ImportStep("certificate_content"), }, }) } @@ -46,9 +37,7 @@ func TestAccAzureRMIotHubDPSCertificate_requiresImport(t *testing.T) { return } - resourceName := "azurerm_iothub_dps_certificate.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +45,13 @@ func TestAccAzureRMIotHubDPSCertificate_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDPSCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDPSCertificate_basic(rInt, location), + Config: testAccAzureRMIotHubDPSCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDPSCertificateExists(resourceName), + testCheckAzureRMIotHubDPSCertificateExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotHubDPSCertificate_requiresImport(rInt, location), + Config: testAccAzureRMIotHubDPSCertificate_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iothubdps"), }, }, @@ -70,8 +59,7 @@ func TestAccAzureRMIotHubDPSCertificate_requiresImport(t *testing.T) { } func TestAccAzureRMIotHubDPSCertificate_update(t *testing.T) { - resourceName := "azurerm_iothub_dps_certificate.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,33 +67,19 @@ func TestAccAzureRMIotHubDPSCertificate_update(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDPSCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDPSCertificate_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDPSCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDPSCertificateExists(resourceName), + testCheckAzureRMIotHubDPSCertificateExists(data.ResourceName), ), }, + data.ImportStep("certificate_content"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "certificate_content", - }, - }, - { - Config: testAccAzureRMIotHubDPSCertificate_update(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDPSCertificate_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDPSCertificateExists(resourceName), + testCheckAzureRMIotHubDPSCertificateExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "certificate_content", - }, - }, + data.ImportStep("certificate_content"), }, }) } @@ -166,7 +140,7 @@ func testCheckAzureRMIotHubDPSCertificateExists(resourceName string) resource.Te } } -func testAccAzureRMIotHubDPSCertificate_basic(rInt int, location string) string { +func testAccAzureRMIotHubDPSCertificate_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -192,11 +166,11 @@ resource "azurerm_iothub_dps_certificate" "test" { certificate_content = "${filebase64("testdata/batch_certificate.cer")}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMIotHubDPSCertificate_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotHubDPS_basic(rInt, location) +func testAccAzureRMIotHubDPSCertificate_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotHubDPS_basic(data) return fmt.Sprintf(` %s @@ -210,7 +184,7 @@ resource "azurerm_iothub_dps_certificate" "test" { `, template) } -func testAccAzureRMIotHubDPSCertificate_update(rInt int, location string) string { +func testAccAzureRMIotHubDPSCertificate_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -240,5 +214,5 @@ resource "azurerm_iothub_dps_certificate" "test" { certificate_content = "${filebase64("testdata/application_gateway_test.cer")}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go similarity index 88% rename from azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go index a1717bdf8cb5..43d3ef00c83f 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMIotHubDpsSharedAccessPolicy_basic(t *testing.T) { - resourceName := "azurerm_iothub_dps_shared_access_policy.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps_shared_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,7 +22,7 @@ func TestAccAzureRMIotHubDpsSharedAccessPolicy_basic(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDpsSharedAccessPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDpsSharedAccessPolicy_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDpsSharedAccessPolicy_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMIotHubDpsSharedAccessPolicyExists(resourceName), resource.TestCheckResourceAttr(resourceName, "name", "acctest"), @@ -44,7 +42,7 @@ func TestAccAzureRMIotHubDpsSharedAccessPolicy_basic(t *testing.T) { } func TestAccAzureRMIotHubDpsSharedAccessPolicy_writeWithoutRead(t *testing.T) { - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps_shared_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,7 +50,7 @@ func TestAccAzureRMIotHubDpsSharedAccessPolicy_writeWithoutRead(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDpsSharedAccessPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDpsSharedAccessPolicy_writeWithoutRead(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDpsSharedAccessPolicy_writeWithoutRead(data), ExpectError: regexp.MustCompile("If `registration_write` is set to true, `registration_read` must also be set to true"), }, }, @@ -60,7 +58,7 @@ func TestAccAzureRMIotHubDpsSharedAccessPolicy_writeWithoutRead(t *testing.T) { } func TestAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentReadWithoutRegistration(t *testing.T) { - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps_shared_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -68,7 +66,7 @@ func TestAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentReadWithoutRegistration CheckDestroy: testCheckAzureRMIotHubDpsSharedAccessPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentReadWithoutRegistration(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentReadWithoutRegistration(data), ExpectError: regexp.MustCompile("If `enrollment_read` is set to true, `registration_read` must also be set to true"), }, }, @@ -76,7 +74,7 @@ func TestAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentReadWithoutRegistration } func TestAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentWriteWithoutOthers(t *testing.T) { - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps_shared_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,14 +82,14 @@ func TestAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentWriteWithoutOthers(t *t CheckDestroy: testCheckAzureRMIotHubDpsSharedAccessPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentWriteWithoutOthers(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentWriteWithoutOthers(data), ExpectError: regexp.MustCompile("If `enrollment_write` is set to true, `enrollment_read`, `registration_read`, and `registration_write` must also be set to true"), }, }, }) } -func testAccAzureRMIotHubDpsSharedAccessPolicy_basic(rInt int, location string) string { +func testAccAzureRMIotHubDpsSharedAccessPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -114,10 +112,10 @@ resource "azurerm_iothub_dps_shared_access_policy" "test" { name = "acctest" service_config = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHubDpsSharedAccessPolicy_writeWithoutRead(rInt int, location string) string { +func testAccAzureRMIotHubDpsSharedAccessPolicy_writeWithoutRead(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -140,10 +138,10 @@ resource "azurerm_iothub_dps_shared_access_policy" "test" { name = "acctest" registration_write = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentReadWithoutRegistration(rInt int, location string) string { +func testAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentReadWithoutRegistration(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -166,10 +164,10 @@ resource "azurerm_iothub_dps_shared_access_policy" "test" { name = "acctest" enrollment_read = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentWriteWithoutOthers(rInt int, location string) string { +func testAccAzureRMIotHubDpsSharedAccessPolicy_enrollmentWriteWithoutOthers(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -192,7 +190,7 @@ resource "azurerm_iothub_dps_shared_access_policy" "test" { name = "acctest" enrollment_write = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testCheckAzureRMIotHubDpsSharedAccessPolicyExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_dps_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_test.go similarity index 71% rename from azurerm/internal/services/iothub/resource_arm_iothub_dps_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_test.go index e73987f44e1e..0f9bc4bed310 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_dps_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMIotHubDPS_basic(t *testing.T) { - resourceName := "azurerm_iothub_dps.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,20 +21,16 @@ func TestAccAzureRMIotHubDPS_basic(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDPSDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDPS_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDPS_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDPSExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "allocation_policy"), - resource.TestCheckResourceAttrSet(resourceName, "device_provisioning_host_name"), - resource.TestCheckResourceAttrSet(resourceName, "id_scope"), - resource.TestCheckResourceAttrSet(resourceName, "service_operations_host_name"), + testCheckAzureRMIotHubDPSExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "allocation_policy"), + resource.TestCheckResourceAttrSet(data.ResourceName, "device_provisioning_host_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "id_scope"), + resource.TestCheckResourceAttrSet(data.ResourceName, "service_operations_host_name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,9 +41,7 @@ func TestAccAzureRMIotHubDPS_requiresImport(t *testing.T) { return } - resourceName := "azurerm_iothub_dps.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,13 +49,13 @@ func TestAccAzureRMIotHubDPS_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMIotDPSDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDPS_basic(rInt, location), + Config: testAccAzureRMIotHubDPS_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDPSExists(resourceName), + testCheckAzureRMIotHubDPSExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotHubDPS_requiresImport(rInt, location), + Config: testAccAzureRMIotHubDPS_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iothubdps"), }, }, @@ -71,8 +63,7 @@ func TestAccAzureRMIotHubDPS_requiresImport(t *testing.T) { } func TestAccAzureRMIotHubDPS_update(t *testing.T) { - resourceName := "azurerm_iothub_dps.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,34 +71,25 @@ func TestAccAzureRMIotHubDPS_update(t *testing.T) { CheckDestroy: testCheckAzureRMIotDPSDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDPS_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDPS_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDPSExists(resourceName), + testCheckAzureRMIotHubDPSExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMIotHubDPS_update(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDPS_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDPSExists(resourceName), + testCheckAzureRMIotHubDPSExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMIotHubDPS_linkedHubs(t *testing.T) { - resourceName := "azurerm_iothub_dps.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_dps", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -115,27 +97,19 @@ func TestAccAzureRMIotHubDPS_linkedHubs(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDPSDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubDPS_linkedHubs(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDPS_linkedHubs(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDPSExists(resourceName), + testCheckAzureRMIotHubDPSExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMIotHubDPS_linkedHubsUpdated(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubDPS_linkedHubsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDPSExists(resourceName), + testCheckAzureRMIotHubDPSExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -193,7 +167,7 @@ func testCheckAzureRMIotHubDPSExists(resourceName string) resource.TestCheckFunc } } -func testAccAzureRMIotHubDPS_basic(rInt int, location string) string { +func testAccAzureRMIotHubDPS_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -211,11 +185,11 @@ resource "azurerm_iothub_dps" "test" { capacity = "1" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHubDPS_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotHubDPS_basic(rInt, location) +func testAccAzureRMIotHubDPS_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotHubDPS_basic(data) return fmt.Sprintf(` %s @@ -233,7 +207,7 @@ resource "azurerm_iothub_dps" "import" { `, template) } -func testAccAzureRMIotHubDPS_update(rInt int, location string) string { +func testAccAzureRMIotHubDPS_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -255,10 +229,10 @@ resource "azurerm_iothub_dps" "test" { purpose = "testing" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHubDPS_linkedHubs(rInt int, location string) string { +func testAccAzureRMIotHubDPS_linkedHubs(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -288,10 +262,10 @@ resource "azurerm_iothub_dps" "test" { location = "${azurerm_resource_group.test.location}" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHubDPS_linkedHubsUpdated(rInt int, location string) string { +func testAccAzureRMIotHubDPS_linkedHubsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -315,5 +289,5 @@ resource "azurerm_iothub_dps" "test" { allocation_weight = 150 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_eventhub_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_eventhub_test.go similarity index 86% rename from azurerm/internal/services/iothub/resource_arm_iothub_endpoint_eventhub_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_eventhub_test.go index 414533270b55..1a224f65b5f0 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_eventhub_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_eventhub_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +15,7 @@ import ( ) func TestAccAzureRMIotHubEndpointEventHub_basic(t *testing.T) { - resourceName := "azurerm_iothub_endpoint_eventhub.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_endpoint_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,16 +23,12 @@ func TestAccAzureRMIotHubEndpointEventHub_basic(t *testing.T) { CheckDestroy: testAccAzureRMIotHubEndpointStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubEndpointEventHub_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubEndpointEventHub_basic(data), Check: resource.ComposeTestCheckFunc( - testAccAzureRMIotHubEndpointEventHubExists(resourceName), + testAccAzureRMIotHubEndpointEventHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,9 +38,7 @@ func TestAccAzureRMIotHubEndpointEventHub_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_iothub_endpoint_eventhub.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_endpoint_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,20 +46,20 @@ func TestAccAzureRMIotHubEndpointEventHub_requiresImport(t *testing.T) { CheckDestroy: testAccAzureRMIotHubEndpointEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubEndpointEventHub_basic(rInt, location), + Config: testAccAzureRMIotHubEndpointEventHub_basic(data), Check: resource.ComposeTestCheckFunc( - testAccAzureRMIotHubEndpointEventHubExists(resourceName), + testAccAzureRMIotHubEndpointEventHubExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotHubEndpointEventHub_requiresImport(rInt, location), + Config: testAccAzureRMIotHubEndpointEventHub_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iothub_endpoint_eventhub"), }, }, }) } -func testAccAzureRMIotHubEndpointEventHub_basic(rInt int, location string) string { +func testAccAzureRMIotHubEndpointEventHub_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" @@ -123,11 +115,11 @@ resource "azurerm_iothub_endpoint_eventhub" "test" { connection_string = "${azurerm_eventhub_authorization_rule.test.primary_connection_string}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMIotHubEndpointEventHub_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotHubEndpointEventHub_basic(rInt, location) +func testAccAzureRMIotHubEndpointEventHub_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotHubEndpointEventHub_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_queue_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_queue_test.go similarity index 87% rename from azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_queue_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_queue_test.go index 3e79f0e6a742..7fc007eceb7d 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_queue_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_queue_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +15,7 @@ import ( ) func TestAccAzureRMIotHubEndpointServiceBusQueue_basic(t *testing.T) { - resourceName := "azurerm_iothub_endpoint_servicebus_queue.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_endpoint_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,16 +23,12 @@ func TestAccAzureRMIotHubEndpointServiceBusQueue_basic(t *testing.T) { CheckDestroy: testAccAzureRMIotHubEndpointStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubEndpointServiceBusQueue_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubEndpointServiceBusQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testAccAzureRMIotHubEndpointServiceBusQueueExists(resourceName), + testAccAzureRMIotHubEndpointServiceBusQueueExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,9 +38,7 @@ func TestAccAzureRMIotHubEndpointServiceBusQueue_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_iothub_endpoint_servicebus_queue.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_endpoint_servicebus_queue", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,20 +46,20 @@ func TestAccAzureRMIotHubEndpointServiceBusQueue_requiresImport(t *testing.T) { CheckDestroy: testAccAzureRMIotHubEndpointServiceBusQueueDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubEndpointServiceBusQueue_basic(rInt, location), + Config: testAccAzureRMIotHubEndpointServiceBusQueue_basic(data), Check: resource.ComposeTestCheckFunc( - testAccAzureRMIotHubEndpointServiceBusQueueExists(resourceName), + testAccAzureRMIotHubEndpointServiceBusQueueExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotHubEndpointServiceBusQueue_requiresImport(rInt, location), + Config: testAccAzureRMIotHubEndpointServiceBusQueue_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iothub_endpoint_servicebus_queue"), }, }, }) } -func testAccAzureRMIotHubEndpointServiceBusQueue_basic(rInt int, location string) string { +func testAccAzureRMIotHubEndpointServiceBusQueue_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" @@ -124,11 +116,11 @@ resource "azurerm_iothub_endpoint_servicebus_queue" "test" { connection_string = "${azurerm_servicebus_queue_authorization_rule.test.primary_connection_string}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMIotHubEndpointServiceBusQueue_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotHubEndpointServiceBusQueue_basic(rInt, location) +func testAccAzureRMIotHubEndpointServiceBusQueue_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotHubEndpointServiceBusQueue_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_topic_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_topic_test.go similarity index 87% rename from azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_topic_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_topic_test.go index 0f663c7bc9dc..6a2e7ee20c66 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_servicebus_topic_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_servicebus_topic_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +15,7 @@ import ( ) func TestAccAzureRMIotHubEndpointServiceBusTopic_basic(t *testing.T) { - resourceName := "azurerm_iothub_endpoint_servicebus_topic.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_endpoint_servicebus_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,16 +23,12 @@ func TestAccAzureRMIotHubEndpointServiceBusTopic_basic(t *testing.T) { CheckDestroy: testAccAzureRMIotHubEndpointStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubEndpointServiceBusTopic_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubEndpointServiceBusTopic_basic(data), Check: resource.ComposeTestCheckFunc( - testAccAzureRMIotHubEndpointServiceBusTopicExists(resourceName), + testAccAzureRMIotHubEndpointServiceBusTopicExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,9 +39,7 @@ func TestAccAzureRMIotHubEndpointServiceBusTopic_requiresImport(t *testing.T) { return } - resourceName := "azurerm_iothub_endpoint_servicebus_topic.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_endpoint_servicebus_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,20 +47,20 @@ func TestAccAzureRMIotHubEndpointServiceBusTopic_requiresImport(t *testing.T) { CheckDestroy: testAccAzureRMIotHubEndpointServiceBusTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubEndpointServiceBusTopic_basic(rInt, location), + Config: testAccAzureRMIotHubEndpointServiceBusTopic_basic(data), Check: resource.ComposeTestCheckFunc( - testAccAzureRMIotHubEndpointServiceBusTopicExists(resourceName), + testAccAzureRMIotHubEndpointServiceBusTopicExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotHubEndpointServiceBusTopic_requiresImport(rInt, location), + Config: testAccAzureRMIotHubEndpointServiceBusTopic_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iothub_endpoint_servicebus_topic"), }, }, }) } -func testAccAzureRMIotHubEndpointServiceBusTopic_basic(rInt int, location string) string { +func testAccAzureRMIotHubEndpointServiceBusTopic_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" @@ -122,11 +114,11 @@ resource "azurerm_iothub_endpoint_servicebus_topic" "test" { connection_string = "${azurerm_servicebus_topic_authorization_rule.test.primary_connection_string}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMIotHubEndpointServiceBusTopic_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotHubEndpointServiceBusTopic_basic(rInt, location) +func testAccAzureRMIotHubEndpointServiceBusTopic_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotHubEndpointServiceBusTopic_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_storage_container_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_storage_container_test.go similarity index 84% rename from azurerm/internal/services/iothub/resource_arm_iothub_endpoint_storage_container_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_storage_container_test.go index 58f55cdff048..33142368da1c 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_endpoint_storage_container_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_endpoint_storage_container_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +15,7 @@ import ( ) func TestAccAzureRMIotHubEndpointStorageContainer_basic(t *testing.T) { - resourceName := "azurerm_iothub_endpoint_storage_container.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_endpoint_storage_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,20 +23,16 @@ func TestAccAzureRMIotHubEndpointStorageContainer_basic(t *testing.T) { CheckDestroy: testAccAzureRMIotHubEndpointStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubEndpointStorageContainer_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubEndpointStorageContainer_basic(data), Check: resource.ComposeTestCheckFunc( - testAccAzureRMIotHubEndpointStorageContainerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "file_name_format", "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}"), - resource.TestCheckResourceAttr(resourceName, "batch_frequency_in_seconds", "60"), - resource.TestCheckResourceAttr(resourceName, "max_chunk_size_in_bytes", "10485760"), - resource.TestCheckResourceAttr(resourceName, "encoding", "JSON"), + testAccAzureRMIotHubEndpointStorageContainerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "file_name_format", "{iothub}/{partition}_{YYYY}_{MM}_{DD}_{HH}_{mm}"), + resource.TestCheckResourceAttr(data.ResourceName, "batch_frequency_in_seconds", "60"), + resource.TestCheckResourceAttr(data.ResourceName, "max_chunk_size_in_bytes", "10485760"), + resource.TestCheckResourceAttr(data.ResourceName, "encoding", "JSON"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -48,9 +42,7 @@ func TestAccAzureRMIotHubEndpointStorageContainer_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_iothub_endpoint_storage_container.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_endpoint_storage_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -58,20 +50,20 @@ func TestAccAzureRMIotHubEndpointStorageContainer_requiresImport(t *testing.T) { CheckDestroy: testAccAzureRMIotHubEndpointStorageContainerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubEndpointStorageContainer_basic(rInt, location), + Config: testAccAzureRMIotHubEndpointStorageContainer_basic(data), Check: resource.ComposeTestCheckFunc( - testAccAzureRMIotHubEndpointStorageContainerExists(resourceName), + testAccAzureRMIotHubEndpointStorageContainerExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotHubEndpointStorageContainer_requiresImport(rInt, location), + Config: testAccAzureRMIotHubEndpointStorageContainer_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iothub_endpoint_storage_container"), }, }, }) } -func testAccAzureRMIotHubEndpointStorageContainer_basic(rInt int, location string) string { +func testAccAzureRMIotHubEndpointStorageContainer_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" @@ -122,11 +114,11 @@ resource "azurerm_iothub_endpoint_storage_container" "test" { max_chunk_size_in_bytes = 10485760 encoding = "JSON" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMIotHubEndpointStorageContainer_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotHubEndpointStorageContainer_basic(rInt, location) +func testAccAzureRMIotHubEndpointStorageContainer_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotHubEndpointStorageContainer_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_fallback_route_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_fallback_route_test.go similarity index 81% rename from azurerm/internal/services/iothub/resource_arm_iothub_fallback_route_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_fallback_route_test.go index aabc4a76f707..cc3ab08e408d 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_fallback_route_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_fallback_route_test.go @@ -1,14 +1,12 @@ -package iothub +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,9 +14,7 @@ import ( ) func TestAccAzureRMIotHubFallbackRoute_basic(t *testing.T) { - resourceName := "azurerm_iothub_fallback_route.test" - rInt := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_iothub_fallback_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,16 +22,12 @@ func TestAccAzureRMIotHubFallbackRoute_basic(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubFallbackRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubFallbackRoute_basic(rInt, rs, acceptance.Location()), + Config: testAccAzureRMIotHubFallbackRoute_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubFallbackRouteExists(resourceName), + testCheckAzureRMIotHubFallbackRouteExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,10 +38,7 @@ func TestAccAzureRMIotHubFallbackRoute_requiresImport(t *testing.T) { return } - resourceName := "azurerm_iothub_fallback_route.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_iothub_fallback_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,13 +46,13 @@ func TestAccAzureRMIotHubFallbackRoute_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubFallbackRoute_basic(rInt, rs, location), + Config: testAccAzureRMIotHubFallbackRoute_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubFallbackRouteExists(resourceName), + testCheckAzureRMIotHubFallbackRouteExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotHubFallbackRoute_requiresImport(rInt, location), + Config: testAccAzureRMIotHubFallbackRoute_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iothub_fallback_route"), }, }, @@ -71,9 +60,7 @@ func TestAccAzureRMIotHubFallbackRoute_requiresImport(t *testing.T) { } func TestAccAzureRMIotHubFallbackRoute_update(t *testing.T) { - resourceName := "azurerm_iothub_fallback_route.test" - rInt := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_iothub_fallback_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,27 +68,19 @@ func TestAccAzureRMIotHubFallbackRoute_update(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubFallbackRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubFallbackRoute_basic(rInt, rs, acceptance.Location()), + Config: testAccAzureRMIotHubFallbackRoute_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubFallbackRouteExists(resourceName), + testCheckAzureRMIotHubFallbackRouteExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMIotHubFallbackRoute_update(rInt, rs, acceptance.Location()), + Config: testAccAzureRMIotHubFallbackRoute_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubFallbackRouteExists(resourceName), + testCheckAzureRMIotHubFallbackRouteExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -170,8 +149,8 @@ func testCheckAzureRMIotHubFallbackRouteExists(resourceName string) resource.Tes } } -func testAccAzureRMIotHubFallbackRoute_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotHub_basic(rInt, location) +func testAccAzureRMIotHubFallbackRoute_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotHub_basic(data) return fmt.Sprintf(` %s @@ -187,7 +166,7 @@ resource "azurerm_iothub_fallback_route" "import" { `, template) } -func testAccAzureRMIotHubFallbackRoute_basic(rInt int, rStr string, location string) string { +func testAccAzureRMIotHubFallbackRoute_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" @@ -246,10 +225,10 @@ resource "azurerm_iothub_fallback_route" "test" { endpoint_names = ["${azurerm_iothub_endpoint_storage_container.test.name}"] enabled = true } -`, rInt, location, rStr) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMIotHubFallbackRoute_update(rInt int, rStr string, location string) string { +func testAccAzureRMIotHubFallbackRoute_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" @@ -308,5 +287,5 @@ resource "azurerm_iothub_fallback_route" "test" { endpoint_names = ["${azurerm_iothub_endpoint_storage_container.test.name}"] enabled = false } -`, rInt, location, rStr) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_route_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_route_test.go similarity index 83% rename from azurerm/internal/services/iothub/resource_arm_iothub_route_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_route_test.go index ca388827912d..def2cdc517a2 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_route_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_route_test.go @@ -1,15 +1,13 @@ -package iothub +package tests import ( "fmt" "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -17,9 +15,7 @@ import ( ) func TestAccAzureRMIotHubRoute_basic(t *testing.T) { - resourceName := "azurerm_iothub_route.test" - rInt := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_iothub_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,16 +23,12 @@ func TestAccAzureRMIotHubRoute_basic(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubRoute_basic(rInt, rs, acceptance.Location()), + Config: testAccAzureRMIotHubRoute_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubRouteExists(resourceName), + testCheckAzureRMIotHubRouteExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,10 +39,7 @@ func TestAccAzureRMIotHubRoute_requiresImport(t *testing.T) { return } - resourceName := "azurerm_iothub_route.test" - rInt := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -58,13 +47,13 @@ func TestAccAzureRMIotHubRoute_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubRoute_basic(rInt, rs, location), + Config: testAccAzureRMIotHubRoute_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubRouteExists(resourceName), + testCheckAzureRMIotHubRouteExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotHubRoute_requiresImport(rInt, rs, location), + Config: testAccAzureRMIotHubRoute_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iothub_route"), }, }, @@ -72,9 +61,7 @@ func TestAccAzureRMIotHubRoute_requiresImport(t *testing.T) { } func TestAccAzureRMIotHubRoute_update(t *testing.T) { - resourceName := "azurerm_iothub_route.test" - rInt := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_iothub_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,27 +69,19 @@ func TestAccAzureRMIotHubRoute_update(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubRoute_basic(rInt, rs, acceptance.Location()), + Config: testAccAzureRMIotHubRoute_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubRouteExists(resourceName), + testCheckAzureRMIotHubRouteExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMIotHubRoute_update(rInt, rs, acceptance.Location()), + Config: testAccAzureRMIotHubRoute_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubRouteExists(resourceName), + testCheckAzureRMIotHubRouteExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -192,8 +171,8 @@ func testCheckAzureRMIotHubRouteExists(resourceName string) resource.TestCheckFu } } -func testAccAzureRMIotHubRoute_requiresImport(rInt int, rStr string, location string) string { - template := testAccAzureRMIotHubRoute_basic(rInt, rStr, location) +func testAccAzureRMIotHubRoute_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotHubRoute_basic(data) return fmt.Sprintf(` %s @@ -210,7 +189,7 @@ resource "azurerm_iothub_route" "import" { `, template) } -func testAccAzureRMIotHubRoute_basic(rInt int, rStr string, location string) string { +func testAccAzureRMIotHubRoute_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" @@ -272,10 +251,10 @@ resource "azurerm_iothub_route" "test" { enabled = true } -`, rInt, location, rStr) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMIotHubRoute_update(rInt int, rStr string, location string) string { +func testAccAzureRMIotHubRoute_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-iothub-%[1]d" @@ -337,5 +316,5 @@ resource "azurerm_iothub_route" "test" { enabled = false } -`, rInt, location, rStr) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_shared_access_policy_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_shared_access_policy_test.go similarity index 79% rename from azurerm/internal/services/iothub/resource_arm_iothub_shared_access_policy_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_shared_access_policy_test.go index 0c974e9e3ab0..16815a10fe74 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_shared_access_policy_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_shared_access_policy_test.go @@ -1,4 +1,4 @@ -package iothub +package tests import ( "fmt" @@ -9,7 +9,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -17,8 +16,7 @@ import ( ) func TestAccAzureRMIotHubSharedAccessPolicy_basic(t *testing.T) { - resourceName := "azurerm_iothub_shared_access_policy.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_shared_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,27 +24,23 @@ func TestAccAzureRMIotHubSharedAccessPolicy_basic(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubSharedAccessPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubSharedAccessPolicy_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubSharedAccessPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubSharedAccessPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "registry_read", "true"), - resource.TestCheckResourceAttr(resourceName, "registry_write", "true"), - resource.TestCheckResourceAttr(resourceName, "service_connect", "false"), - resource.TestCheckResourceAttr(resourceName, "device_connect", "false"), - resource.TestCheckResourceAttr(resourceName, "name", "acctest"), + testCheckAzureRMIotHubSharedAccessPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "registry_read", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "registry_write", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "service_connect", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "device_connect", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctest"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMIotHubSharedAccessPolicy_writeWithoutRead(t *testing.T) { - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub_shared_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,7 +48,7 @@ func TestAccAzureRMIotHubSharedAccessPolicy_writeWithoutRead(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubSharedAccessPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubSharedAccessPolicy_writeWithoutRead(rInt, acceptance.Location()), + Config: testAccAzureRMIotHubSharedAccessPolicy_writeWithoutRead(data), ExpectError: regexp.MustCompile("If `registry_write` is set to true, `registry_read` must also be set to true"), }, }, @@ -67,9 +61,7 @@ func TestAccAzureRMIotHubSharedAccessPolicy_requiresImport(t *testing.T) { return } - resourceName := "azurerm_iothub_shared_access_policy.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub_shared_access_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -77,20 +69,20 @@ func TestAccAzureRMIotHubSharedAccessPolicy_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubSharedAccessPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHubSharedAccessPolicy_basic(rInt, location), + Config: testAccAzureRMIotHubSharedAccessPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubSharedAccessPolicyExists(resourceName), + testCheckAzureRMIotHubSharedAccessPolicyExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotHubSharedAccessPolicy_requiresImport(rInt, location), + Config: testAccAzureRMIotHubSharedAccessPolicy_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iothub_shared_access_policy"), }, }, }) } -func testAccAzureRMIotHubSharedAccessPolicy_basic(rInt int, location string) string { +func testAccAzureRMIotHubSharedAccessPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -121,11 +113,11 @@ resource "azurerm_iothub_shared_access_policy" "test" { registry_read = true registry_write = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHubSharedAccessPolicy_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotHubSharedAccessPolicy_basic(rInt, location) +func testAccAzureRMIotHubSharedAccessPolicy_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotHubSharedAccessPolicy_basic(data) return fmt.Sprintf(` %s @@ -140,7 +132,7 @@ resource "azurerm_iothub_shared_access_policy" "import" { `, template) } -func testAccAzureRMIotHubSharedAccessPolicy_writeWithoutRead(rInt int, location string) string { +func testAccAzureRMIotHubSharedAccessPolicy_writeWithoutRead(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -170,7 +162,7 @@ resource "azurerm_iothub_shared_access_policy" "test" { registry_write = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testCheckAzureRMIotHubSharedAccessPolicyExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go similarity index 74% rename from azurerm/internal/services/iothub/resource_arm_iothub_test.go rename to azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go index c113071e6794..6c165d6c14ef 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_test.go @@ -1,22 +1,19 @@ -package iothub +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMIotHub_basic(t *testing.T) { - resourceName := "azurerm_iothub.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,23 +21,18 @@ func TestAccAzureRMIotHub_basic(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHub_basic(rInt, acceptance.Location()), + Config: testAccAzureRMIotHub_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(resourceName), + testCheckAzureRMIotHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMIotHub_ipFilterRules(t *testing.T) { - resourceName := "azurerm_iothub.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -48,16 +40,12 @@ func TestAccAzureRMIotHub_ipFilterRules(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHub_ipFilterRules(rInt, acceptance.Location()), + Config: testAccAzureRMIotHub_ipFilterRules(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(resourceName), + testCheckAzureRMIotHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -68,9 +56,7 @@ func TestAccAzureRMIotHub_requiresImport(t *testing.T) { return } - resourceName := "azurerm_iothub.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,13 +64,13 @@ func TestAccAzureRMIotHub_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHub_basic(rInt, location), + Config: testAccAzureRMIotHub_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(resourceName), + testCheckAzureRMIotHubExists(data.ResourceName), ), }, { - Config: testAccAzureRMIotHub_requiresImport(rInt, location), + Config: testAccAzureRMIotHub_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_iothub"), }, }, @@ -92,8 +78,7 @@ func TestAccAzureRMIotHub_requiresImport(t *testing.T) { } func TestAccAzureRMIotHub_standard(t *testing.T) { - resourceName := "azurerm_iothub.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -101,24 +86,18 @@ func TestAccAzureRMIotHub_standard(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHub_standard(rInt, acceptance.Location()), + Config: testAccAzureRMIotHub_standard(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(resourceName), + testCheckAzureRMIotHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMIotHub_customRoutes(t *testing.T) { - resourceName := "azurerm_iothub.test" - rInt := tf.AccRandTimeInt() - rStr := acctest.RandString(5) + data := acceptance.BuildTestData(t, "azurerm_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -126,28 +105,22 @@ func TestAccAzureRMIotHub_customRoutes(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHub_customRoutes(rInt, rStr, acceptance.Location()), + Config: testAccAzureRMIotHub_customRoutes(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "endpoint.#", "2"), - resource.TestCheckResourceAttr(resourceName, "endpoint.0.type", "AzureIotHub.StorageContainer"), - resource.TestCheckResourceAttr(resourceName, "endpoint.1.type", "AzureIotHub.EventHub"), - resource.TestCheckResourceAttr(resourceName, "route.#", "2"), + testCheckAzureRMIotHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint.0.type", "AzureIotHub.StorageContainer"), + resource.TestCheckResourceAttr(data.ResourceName, "endpoint.1.type", "AzureIotHub.EventHub"), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMIotHub_fileUpload(t *testing.T) { - resourceName := "azurerm_iothub.test" - rInt := tf.AccRandTimeInt() - rStr := acctest.RandString(5) + data := acceptance.BuildTestData(t, "azurerm_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -155,25 +128,20 @@ func TestAccAzureRMIotHub_fileUpload(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHub_fileUpload(rInt, rStr, acceptance.Location()), + Config: testAccAzureRMIotHub_fileUpload(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "file_upload.#", "1"), - resource.TestCheckResourceAttr(resourceName, "file_upload.0.lock_duration", "PT5M"), + testCheckAzureRMIotHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "file_upload.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "file_upload.0.lock_duration", "PT5M"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMIotHub_fallbackRoute(t *testing.T) { - resourceName := "azurerm_iothub.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_iothub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -181,19 +149,15 @@ func TestAccAzureRMIotHub_fallbackRoute(t *testing.T) { CheckDestroy: testCheckAzureRMIotHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMIotHub_fallbackRoute(rInt, acceptance.Location()), + Config: testAccAzureRMIotHub_fallbackRoute(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "fallback_route.0.source", "DeviceMessages"), - resource.TestCheckResourceAttr(resourceName, "fallback_route.0.endpoint_names.#", "1"), - resource.TestCheckResourceAttr(resourceName, "fallback_route.0.enabled", "true"), + testCheckAzureRMIotHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "fallback_route.0.source", "DeviceMessages"), + resource.TestCheckResourceAttr(data.ResourceName, "fallback_route.0.endpoint_names.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fallback_route.0.enabled", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -251,7 +215,7 @@ func testCheckAzureRMIotHubExists(resourceName string) resource.TestCheckFunc { } } -func testAccAzureRMIotHub_basic(rInt int, location string) string { +func testAccAzureRMIotHub_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -273,11 +237,11 @@ resource "azurerm_iothub" "test" { purpose = "testing" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHub_requiresImport(rInt int, location string) string { - template := testAccAzureRMIotHub_basic(rInt, location) +func testAccAzureRMIotHub_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMIotHub_basic(data) return fmt.Sprintf(` %s @@ -299,7 +263,7 @@ resource "azurerm_iothub" "import" { `, template) } -func testAccAzureRMIotHub_standard(rInt int, location string) string { +func testAccAzureRMIotHub_standard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -321,10 +285,10 @@ resource "azurerm_iothub" "test" { purpose = "testing" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHub_ipFilterRules(rInt int, location string) string { +func testAccAzureRMIotHub_ipFilterRules(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -352,10 +316,10 @@ resource "azurerm_iothub" "test" { purpose = "testing" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHub_customRoutes(rInt int, rStr string, location string) string { +func testAccAzureRMIotHub_customRoutes(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -448,10 +412,10 @@ resource "azurerm_iothub" "test" { purpose = "testing" } } -`, rInt, location, rStr, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMIotHub_fallbackRoute(rInt int, location string) string { +func testAccAzureRMIotHub_fallbackRoute(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -479,10 +443,10 @@ resource "azurerm_iothub" "test" { purpose = "testing" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMIotHub_fileUpload(rInt int, rStr string, location string) string { +func testAccAzureRMIotHub_fileUpload(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -525,5 +489,5 @@ resource "azurerm_iothub" "test" { lock_duration = "PT5M" } } -`, rInt, location, rStr, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/iothub/testdata/application_gateway_test.cer b/azurerm/internal/services/iothub/tests/testdata/application_gateway_test.cer similarity index 100% rename from azurerm/internal/services/iothub/testdata/application_gateway_test.cer rename to azurerm/internal/services/iothub/tests/testdata/application_gateway_test.cer diff --git a/azurerm/internal/services/iothub/testdata/batch_certificate.cer b/azurerm/internal/services/iothub/tests/testdata/batch_certificate.cer similarity index 100% rename from azurerm/internal/services/iothub/testdata/batch_certificate.cer rename to azurerm/internal/services/iothub/tests/testdata/batch_certificate.cer From bcbafb81f74fb2f13f78917cbe43662c4c838d1b Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Sat, 21 Dec 2019 09:24:23 -0800 Subject: [PATCH 133/203] tests: authorization --- ...ata_source_builtin_role_definition_test.go | 111 --------- .../data_source_role_definition_test.go | 214 ------------------ ...ata_source_builtin_role_definition_test.go | 112 +++++++++ .../data_source_client_config_test.go | 16 +- .../tests/data_source_role_definition_test.go | 210 +++++++++++++++++ .../resource_arm_role_assignment_test.go | 67 +++--- .../resource_arm_role_definition_test.go | 129 +++++------ 7 files changed, 414 insertions(+), 445 deletions(-) delete mode 100644 azurerm/internal/services/authorization/data_source_builtin_role_definition_test.go delete mode 100644 azurerm/internal/services/authorization/data_source_role_definition_test.go create mode 100644 azurerm/internal/services/authorization/tests/data_source_builtin_role_definition_test.go rename azurerm/internal/services/authorization/{ => tests}/data_source_client_config_test.go (66%) create mode 100644 azurerm/internal/services/authorization/tests/data_source_role_definition_test.go rename azurerm/internal/services/authorization/{ => tests}/resource_arm_role_assignment_test.go (89%) rename azurerm/internal/services/authorization/{ => tests}/resource_arm_role_definition_test.go (66%) diff --git a/azurerm/internal/services/authorization/data_source_builtin_role_definition_test.go b/azurerm/internal/services/authorization/data_source_builtin_role_definition_test.go deleted file mode 100644 index f9cde6d89bfe..000000000000 --- a/azurerm/internal/services/authorization/data_source_builtin_role_definition_test.go +++ /dev/null @@ -1,111 +0,0 @@ -package authorization - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMBuiltInRoleDefinition_contributor(t *testing.T) { - dataSourceName := "data.azurerm_builtin_role_definition.test" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceBuiltInRoleDefinition("Contributor"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"), - resource.TestCheckResourceAttrSet(dataSourceName, "description"), - resource.TestCheckResourceAttrSet(dataSourceName, "type"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "5"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/Delete"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.1", "Microsoft.Authorization/*/Write"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.2", "Microsoft.Authorization/elevateAccess/Action"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.3", "Microsoft.Blueprint/blueprintAssignments/write"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.4", "Microsoft.Blueprint/blueprintAssignments/delete"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMBuiltInRoleDefinition_owner(t *testing.T) { - dataSourceName := "data.azurerm_builtin_role_definition.test" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceBuiltInRoleDefinition("Owner"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"), - resource.TestCheckResourceAttrSet(dataSourceName, "description"), - resource.TestCheckResourceAttrSet(dataSourceName, "type"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMBuiltInRoleDefinition_reader(t *testing.T) { - dataSourceName := "data.azurerm_builtin_role_definition.test" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceBuiltInRoleDefinition("Reader"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7"), - resource.TestCheckResourceAttrSet(dataSourceName, "description"), - resource.TestCheckResourceAttrSet(dataSourceName, "type"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*/read"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMBuiltInRoleDefinition_virtualMachineContributor(t *testing.T) { - dataSourceName := "data.azurerm_builtin_role_definition.test" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceBuiltInRoleDefinition("VirtualMachineContributor"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"), - resource.TestCheckResourceAttrSet(dataSourceName, "description"), - resource.TestCheckResourceAttrSet(dataSourceName, "type"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "38"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "Microsoft.Authorization/*/read"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.15", "Microsoft.Network/networkSecurityGroups/join/action"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "0"), - ), - }, - }, - }) -} - -func testAccDataSourceBuiltInRoleDefinition(name string) string { - return fmt.Sprintf(` -data "azurerm_builtin_role_definition" "test" { - name = "%s" -} -`, name) -} diff --git a/azurerm/internal/services/authorization/data_source_role_definition_test.go b/azurerm/internal/services/authorization/data_source_role_definition_test.go deleted file mode 100644 index 60a6374694c2..000000000000 --- a/azurerm/internal/services/authorization/data_source_role_definition_test.go +++ /dev/null @@ -1,214 +0,0 @@ -package authorization - -import ( - "fmt" - "testing" - - "github.com/google/uuid" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMRoleDefinition_basic(t *testing.T) { - dataSourceName := "data.azurerm_role_definition.test" - - id := uuid.New().String() - ri := tf.AccRandTimeInt() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceRoleDefinition_basic(id, ri), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "description"), - resource.TestCheckResourceAttrSet(dataSourceName, "type"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "3"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/Delete"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.1", "Microsoft.Authorization/*/Write"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.2", "Microsoft.Authorization/elevateAccess/Action"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMRoleDefinition_basicByName(t *testing.T) { - dataSourceName := "data.azurerm_role_definition.test" - - id := uuid.New().String() - ri := tf.AccRandTimeInt() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceRoleDefinition_byName(id, ri), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "description"), - resource.TestCheckResourceAttrSet(dataSourceName, "type"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "3"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/Delete"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.1", "Microsoft.Authorization/*/Write"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.2", "Microsoft.Authorization/elevateAccess/Action"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMRoleDefinition_builtIn_contributor(t *testing.T) { - dataSourceName := "data.azurerm_role_definition.test" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMRoleDefinition_builtIn("Contributor"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"), - resource.TestCheckResourceAttrSet(dataSourceName, "description"), - resource.TestCheckResourceAttrSet(dataSourceName, "type"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "5"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/Delete"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.1", "Microsoft.Authorization/*/Write"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.2", "Microsoft.Authorization/elevateAccess/Action"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.3", "Microsoft.Blueprint/blueprintAssignments/write"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.4", "Microsoft.Blueprint/blueprintAssignments/delete"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMRoleDefinition_builtIn_owner(t *testing.T) { - dataSourceName := "data.azurerm_role_definition.test" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMRoleDefinition_builtIn("Owner"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"), - resource.TestCheckResourceAttrSet(dataSourceName, "description"), - resource.TestCheckResourceAttrSet(dataSourceName, "type"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMRoleDefinition_builtIn_reader(t *testing.T) { - dataSourceName := "data.azurerm_role_definition.test" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMRoleDefinition_builtIn("Reader"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7"), - resource.TestCheckResourceAttrSet(dataSourceName, "description"), - resource.TestCheckResourceAttrSet(dataSourceName, "type"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "*/read"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMRoleDefinition_builtIn_virtualMachineContributor(t *testing.T) { - dataSourceName := "data.azurerm_role_definition.test" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMRoleDefinition_builtIn("VirtualMachineContributor"), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"), - resource.TestCheckResourceAttrSet(dataSourceName, "description"), - resource.TestCheckResourceAttrSet(dataSourceName, "type"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.#", "38"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.0", "Microsoft.Authorization/*/read"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.actions.15", "Microsoft.Network/networkSecurityGroups/join/action"), - resource.TestCheckResourceAttr(dataSourceName, "permissions.0.not_actions.#", "0"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMRoleDefinition_builtIn(name string) string { - return fmt.Sprintf(` -data "azurerm_role_definition" "test" { - name = "%s" -} -`, name) -} - -func testAccDataSourceRoleDefinition_basic(id string, rInt int) string { - return fmt.Sprintf(` -data "azurerm_subscription" "primary" {} - -resource "azurerm_role_definition" "test" { - role_definition_id = "%s" - name = "acctestrd-%d" - scope = "${data.azurerm_subscription.primary.id}" - description = "Created by the Data Source Role Definition Acceptance Test" - - permissions { - actions = ["*"] - - not_actions = [ - "Microsoft.Authorization/*/Delete", - "Microsoft.Authorization/*/Write", - "Microsoft.Authorization/elevateAccess/Action", - ] - } - - assignable_scopes = [ - "${data.azurerm_subscription.primary.id}", - ] -} - -data "azurerm_role_definition" "test" { - role_definition_id = "${azurerm_role_definition.test.role_definition_id}" - scope = "${data.azurerm_subscription.primary.id}" -} -`, id, rInt) -} - -func testAccDataSourceRoleDefinition_byName(id string, rInt int) string { - return fmt.Sprintf(` -%s - -data "azurerm_role_definition" "byName" { - name = "${azurerm_role_definition.test.name}" - scope = "${data.azurerm_subscription.primary.id}" -} -`, testAccDataSourceRoleDefinition_basic(id, rInt)) -} diff --git a/azurerm/internal/services/authorization/tests/data_source_builtin_role_definition_test.go b/azurerm/internal/services/authorization/tests/data_source_builtin_role_definition_test.go new file mode 100644 index 000000000000..805b443e014c --- /dev/null +++ b/azurerm/internal/services/authorization/tests/data_source_builtin_role_definition_test.go @@ -0,0 +1,112 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMBuiltInRoleDefinition_contributor(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_builtin_role_definition", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceBuiltInRoleDefinition("Contributor"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"), + resource.TestCheckResourceAttrSet(data.ResourceName, "description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "5"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/Delete"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.1", "Microsoft.Authorization/*/Write"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.2", "Microsoft.Authorization/elevateAccess/Action"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.3", "Microsoft.Blueprint/blueprintAssignments/write"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.4", "Microsoft.Blueprint/blueprintAssignments/delete"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMBuiltInRoleDefinition_owner(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_builtin_role_definition", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceBuiltInRoleDefinition("Owner"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"), + resource.TestCheckResourceAttrSet(data.ResourceName, "description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMBuiltInRoleDefinition_reader(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_builtin_role_definition", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceBuiltInRoleDefinition("Reader"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7"), + resource.TestCheckResourceAttrSet(data.ResourceName, "description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*/read"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMBuiltInRoleDefinition_virtualMachineContributor(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_builtin_role_definition", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceBuiltInRoleDefinition("VirtualMachineContributor"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"), + resource.TestCheckResourceAttrSet(data.ResourceName, "description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "38"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "Microsoft.Authorization/*/read"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.15", "Microsoft.Network/networkSecurityGroups/join/action"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), + ), + }, + }, + }) +} + +func testAccDataSourceBuiltInRoleDefinition(name string) string { + return fmt.Sprintf(` +data "azurerm_builtin_role_definition" "test" { + name = "%s" +} +`, name) +} diff --git a/azurerm/internal/services/authorization/data_source_client_config_test.go b/azurerm/internal/services/authorization/tests/data_source_client_config_test.go similarity index 66% rename from azurerm/internal/services/authorization/data_source_client_config_test.go rename to azurerm/internal/services/authorization/tests/data_source_client_config_test.go index 829b18c31e04..681c9d69458b 100644 --- a/azurerm/internal/services/authorization/data_source_client_config_test.go +++ b/azurerm/internal/services/authorization/tests/data_source_client_config_test.go @@ -1,4 +1,4 @@ -package authorization +package tests import ( "os" @@ -11,7 +11,7 @@ import ( ) func TestAccDataSourceAzureRMClientConfig_basic(t *testing.T) { - dataSourceName := "data.azurerm_client_config.current" + data := acceptance.BuildTestData(t, "data.azurerm_client_config", "test") clientId := os.Getenv("ARM_CLIENT_ID") tenantId := os.Getenv("ARM_TENANT_ID") subscriptionId := os.Getenv("ARM_SUBSCRIPTION_ID") @@ -23,12 +23,12 @@ func TestAccDataSourceAzureRMClientConfig_basic(t *testing.T) { { Config: testAccCheckArmClientConfig_basic, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "client_id", clientId), - resource.TestCheckResourceAttr(dataSourceName, "tenant_id", tenantId), - resource.TestCheckResourceAttr(dataSourceName, "subscription_id", subscriptionId), - testAzureRMClientConfigGUIDAttr(dataSourceName, "object_id"), - testAzureRMClientConfigGUIDAttr(dataSourceName, "service_principal_application_id"), - testAzureRMClientConfigGUIDAttr(dataSourceName, "service_principal_object_id"), + resource.TestCheckResourceAttr(data.ResourceName, "client_id", clientId), + resource.TestCheckResourceAttr(data.ResourceName, "tenant_id", tenantId), + resource.TestCheckResourceAttr(data.ResourceName, "subscription_id", subscriptionId), + testAzureRMClientConfigGUIDAttr(data.ResourceName, "object_id"), + testAzureRMClientConfigGUIDAttr(data.ResourceName, "service_principal_application_id"), + testAzureRMClientConfigGUIDAttr(data.ResourceName, "service_principal_object_id"), ), }, }, diff --git a/azurerm/internal/services/authorization/tests/data_source_role_definition_test.go b/azurerm/internal/services/authorization/tests/data_source_role_definition_test.go new file mode 100644 index 000000000000..f1bb395f5f28 --- /dev/null +++ b/azurerm/internal/services/authorization/tests/data_source_role_definition_test.go @@ -0,0 +1,210 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMRoleDefinition_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_role_definition", "test") + id := uuid.New().String() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceRoleDefinition_basic(id, data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/Delete"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.1", "Microsoft.Authorization/*/Write"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.2", "Microsoft.Authorization/elevateAccess/Action"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMRoleDefinition_basicByName(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_role_definition", "test") + + id := uuid.New().String() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceRoleDefinition_byName(id, data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/Delete"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.1", "Microsoft.Authorization/*/Write"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.2", "Microsoft.Authorization/elevateAccess/Action"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMRoleDefinition_builtIn_contributor(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_role_definition", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMRoleDefinition_builtIn("Contributor"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"), + resource.TestCheckResourceAttrSet(data.ResourceName, "description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "5"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/Delete"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.1", "Microsoft.Authorization/*/Write"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.2", "Microsoft.Authorization/elevateAccess/Action"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.3", "Microsoft.Blueprint/blueprintAssignments/write"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.4", "Microsoft.Blueprint/blueprintAssignments/delete"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMRoleDefinition_builtIn_owner(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_role_definition", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMRoleDefinition_builtIn("Owner"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"), + resource.TestCheckResourceAttrSet(data.ResourceName, "description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMRoleDefinition_builtIn_reader(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_role_definition", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMRoleDefinition_builtIn("Reader"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/acdd72a7-3385-48ef-bd42-f606fba81ae7"), + resource.TestCheckResourceAttrSet(data.ResourceName, "description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*/read"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMRoleDefinition_builtIn_virtualMachineContributor(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_role_definition", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMRoleDefinition_builtIn("VirtualMachineContributor"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "id", "/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"), + resource.TestCheckResourceAttrSet(data.ResourceName, "description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "type"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "38"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "Microsoft.Authorization/*/read"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.15", "Microsoft.Network/networkSecurityGroups/join/action"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMRoleDefinition_builtIn(name string) string { + return fmt.Sprintf(` +data "azurerm_role_definition" "test" { + name = "%s" +} +`, name) +} + +func testAccDataSourceRoleDefinition_basic(id string, data acceptance.TestData) string { + return fmt.Sprintf(` +data "azurerm_subscription" "primary" {} + +resource "azurerm_role_definition" "test" { + role_definition_id = "%s" + name = "acctestrd-%d" + scope = "${data.azurerm_subscription.primary.id}" + description = "Created by the Data Source Role Definition Acceptance Test" + + permissions { + actions = ["*"] + + not_actions = [ + "Microsoft.Authorization/*/Delete", + "Microsoft.Authorization/*/Write", + "Microsoft.Authorization/elevateAccess/Action", + ] + } + + assignable_scopes = [ + "${data.azurerm_subscription.primary.id}", + ] +} + +data "azurerm_role_definition" "test" { + role_definition_id = "${azurerm_role_definition.test.role_definition_id}" + scope = "${data.azurerm_subscription.primary.id}" +} +`, id, data.RandomInteger) +} + +func testAccDataSourceRoleDefinition_byName(id string, data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_role_definition" "byName" { + name = "${azurerm_role_definition.test.name}" + scope = "${data.azurerm_subscription.primary.id}" +} +`, testAccDataSourceRoleDefinition_basic(id, data)) +} diff --git a/azurerm/internal/services/authorization/resource_arm_role_assignment_test.go b/azurerm/internal/services/authorization/tests/resource_arm_role_assignment_test.go similarity index 89% rename from azurerm/internal/services/authorization/resource_arm_role_assignment_test.go rename to azurerm/internal/services/authorization/tests/resource_arm_role_assignment_test.go index a4441775df82..fb15da813ee9 100644 --- a/azurerm/internal/services/authorization/resource_arm_role_assignment_test.go +++ b/azurerm/internal/services/authorization/tests/resource_arm_role_assignment_test.go @@ -1,4 +1,4 @@ -package authorization +package tests import ( "fmt" @@ -50,7 +50,7 @@ func TestAccAzureRMRoleAssignment(t *testing.T) { } func testAccAzureRMRoleAssignment_emptyName(t *testing.T) { - resourceName := "azurerm_role_assignment.test" + data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -60,12 +60,12 @@ func testAccAzureRMRoleAssignment_emptyName(t *testing.T) { { Config: testAccAzureRMRoleAssignment_emptyNameConfig(), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleAssignmentExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), + testCheckAzureRMRoleAssignmentExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -77,7 +77,7 @@ func testAccAzureRMRoleAssignment_emptyName(t *testing.T) { } func testAccAzureRMRoleAssignment_roleName(t *testing.T) { - resourceName := "azurerm_role_assignment.test" + data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test") id := uuid.New().String() resource.Test(t, resource.TestCase{ @@ -88,13 +88,13 @@ func testAccAzureRMRoleAssignment_roleName(t *testing.T) { { Config: testAccAzureRMRoleAssignment_roleNameConfig(id), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleAssignmentExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "role_definition_id"), - resource.TestCheckResourceAttr(resourceName, "role_definition_name", "Log Analytics Reader"), + testCheckAzureRMRoleAssignmentExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "role_definition_id"), + resource.TestCheckResourceAttr(data.ResourceName, "role_definition_name", "Log Analytics Reader"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -110,8 +110,7 @@ func testAccAzureRMRoleAssignment_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_role_assignment.test" + data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test") id := uuid.New().String() resource.ParallelTest(t, resource.TestCase{ @@ -122,9 +121,9 @@ func testAccAzureRMRoleAssignment_requiresImport(t *testing.T) { { Config: testAccAzureRMRoleAssignment_roleNameConfig(id), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleAssignmentExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "role_definition_id"), - resource.TestCheckResourceAttr(resourceName, "role_definition_name", "Log Analytics Reader"), + testCheckAzureRMRoleAssignmentExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "role_definition_id"), + resource.TestCheckResourceAttr(data.ResourceName, "role_definition_name", "Log Analytics Reader"), ), }, { @@ -137,7 +136,7 @@ func testAccAzureRMRoleAssignment_requiresImport(t *testing.T) { func testAccAzureRMRoleAssignment_dataActions(t *testing.T) { id := uuid.New().String() - resourceName := "azurerm_role_assignment.test" + data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -147,24 +146,17 @@ func testAccAzureRMRoleAssignment_dataActions(t *testing.T) { { Config: testAccAzureRMRoleAssignment_dataActionsConfig(id), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleAssignmentExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "role_definition_id"), + testCheckAzureRMRoleAssignmentExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "role_definition_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "skip_service_principal_aad_check", - }, - }, + data.ImportStep("skip_service_principal_aad_check"), }, }) } func testAccAzureRMRoleAssignment_builtin(t *testing.T) { - resourceName := "azurerm_role_assignment.test" + data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test") id := uuid.New().String() resource.Test(t, resource.TestCase{ @@ -175,23 +167,16 @@ func testAccAzureRMRoleAssignment_builtin(t *testing.T) { { Config: testAccAzureRMRoleAssignment_builtinConfig(id), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleAssignmentExists(resourceName), + testCheckAzureRMRoleAssignmentExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "skip_service_principal_aad_check", - }, - }, + data.ImportStep("skip_service_principal_aad_check"), }, }) } func testAccAzureRMRoleAssignment_custom(t *testing.T) { - resourceName := "azurerm_role_assignment.test" + data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test") roleDefinitionId := uuid.New().String() roleAssignmentId := uuid.New().String() rInt := tf.AccRandTimeInt() @@ -204,11 +189,11 @@ func testAccAzureRMRoleAssignment_custom(t *testing.T) { { Config: testAccAzureRMRoleAssignment_customConfig(roleDefinitionId, roleAssignmentId, rInt), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleAssignmentExists(resourceName), + testCheckAzureRMRoleAssignmentExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{ @@ -220,7 +205,7 @@ func testAccAzureRMRoleAssignment_custom(t *testing.T) { } func testAccAzureRMActiveDirectoryServicePrincipal_servicePrincipal(t *testing.T) { - resourceName := "azurerm_role_assignment.test" + data := acceptance.BuildTestData(t, "azurerm_role_assignment", "test") ri := tf.AccRandTimeInt() id := uuid.New().String() @@ -233,7 +218,7 @@ func testAccAzureRMActiveDirectoryServicePrincipal_servicePrincipal(t *testing.T Config: testAccAzureRMRoleAssignment_servicePrincipal(ri, id), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRoleAssignmentExists("azurerm_role_assignment.test"), - resource.TestCheckResourceAttr(resourceName, "principal_type", "ServicePrincipal"), + resource.TestCheckResourceAttr(data.ResourceName, "principal_type", "ServicePrincipal"), ), }, }, diff --git a/azurerm/internal/services/authorization/resource_arm_role_definition_test.go b/azurerm/internal/services/authorization/tests/resource_arm_role_definition_test.go similarity index 66% rename from azurerm/internal/services/authorization/resource_arm_role_definition_test.go rename to azurerm/internal/services/authorization/tests/resource_arm_role_definition_test.go index c8457544ca8c..e434e9328a79 100644 --- a/azurerm/internal/services/authorization/resource_arm_role_definition_test.go +++ b/azurerm/internal/services/authorization/tests/resource_arm_role_definition_test.go @@ -1,4 +1,4 @@ -package authorization +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +14,7 @@ import ( ) func TestAccAzureRMRoleDefinition_basic(t *testing.T) { - resourceName := "azurerm_role_definition.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_role_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,13 +22,13 @@ func TestAccAzureRMRoleDefinition_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRoleDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRoleDefinition_basic(uuid.New().String(), ri), + Config: testAccAzureRMRoleDefinition_basic(uuid.New().String(), data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleDefinitionExists(resourceName), + testCheckAzureRMRoleDefinitionExists(data.ResourceName), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"role_definition_id", "scope"}, @@ -44,10 +42,8 @@ func TestAccAzureRMRoleDefinition_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_role_definition.test" + data := acceptance.BuildTestData(t, "azurerm_role_definition", "test") id := uuid.New().String() - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,13 +51,13 @@ func TestAccAzureRMRoleDefinition_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMRoleDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRoleDefinition_basic(id, ri), + Config: testAccAzureRMRoleDefinition_basic(id, data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleDefinitionExists(resourceName), + testCheckAzureRMRoleDefinitionExists(data.ResourceName), ), }, { - Config: testAccAzureRMRoleDefinition_requiresImport(id, ri), + Config: testAccAzureRMRoleDefinition_requiresImport(id, data), ExpectError: acceptance.RequiresImportError("azurerm_role_definition"), }, }, @@ -69,8 +65,7 @@ func TestAccAzureRMRoleDefinition_requiresImport(t *testing.T) { } func TestAccAzureRMRoleDefinition_complete(t *testing.T) { - resourceName := "azurerm_role_definition.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_role_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,25 +73,19 @@ func TestAccAzureRMRoleDefinition_complete(t *testing.T) { CheckDestroy: testCheckAzureRMRoleDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRoleDefinition_complete(uuid.New().String(), ri), + Config: testAccAzureRMRoleDefinition_complete(uuid.New().String(), data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleDefinitionExists(resourceName), + testCheckAzureRMRoleDefinitionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"role_definition_id", "scope"}, - }, + data.ImportStep("role_definition_id", "scope"), }, }) } func TestAccAzureRMRoleDefinition_update(t *testing.T) { - resourceName := "azurerm_role_definition.test" + data := acceptance.BuildTestData(t, "azurerm_role_definition", "test") id := uuid.New().String() - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,24 +93,24 @@ func TestAccAzureRMRoleDefinition_update(t *testing.T) { CheckDestroy: testCheckAzureRMRoleDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRoleDefinition_basic(id, ri), + Config: testAccAzureRMRoleDefinition_basic(id, data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleDefinitionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.not_actions.#", "0"), + testCheckAzureRMRoleDefinitionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), ), }, { - Config: testAccAzureRMRoleDefinition_updated(id, ri), + Config: testAccAzureRMRoleDefinition_updated(id, data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleDefinitionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.not_actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/read"), + testCheckAzureRMRoleDefinitionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/read"), ), }, }, @@ -129,8 +118,7 @@ func TestAccAzureRMRoleDefinition_update(t *testing.T) { } func TestAccAzureRMRoleDefinition_updateEmptyId(t *testing.T) { - resourceName := "azurerm_role_definition.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_role_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -138,24 +126,24 @@ func TestAccAzureRMRoleDefinition_updateEmptyId(t *testing.T) { CheckDestroy: testCheckAzureRMRoleDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRoleDefinition_emptyId(ri), + Config: testAccAzureRMRoleDefinition_emptyId(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleDefinitionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.not_actions.#", "0"), + testCheckAzureRMRoleDefinitionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "0"), ), }, { - Config: testAccAzureRMRoleDefinition_updateEmptyId(ri), + Config: testAccAzureRMRoleDefinition_updateEmptyId(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleDefinitionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "permissions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.actions.0", "*"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.not_actions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/read"), + testCheckAzureRMRoleDefinitionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.actions.0", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "permissions.0.not_actions.0", "Microsoft.Authorization/*/read"), ), }, }, @@ -163,8 +151,7 @@ func TestAccAzureRMRoleDefinition_updateEmptyId(t *testing.T) { } func TestAccAzureRMRoleDefinition_emptyName(t *testing.T) { - resourceName := "azurerm_role_definition.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_role_definition", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -172,11 +159,11 @@ func TestAccAzureRMRoleDefinition_emptyName(t *testing.T) { CheckDestroy: testCheckAzureRMRoleDefinitionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRoleDefinition_emptyId(ri), + Config: testAccAzureRMRoleDefinition_emptyId(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRoleDefinitionExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "id"), - resource.TestCheckResourceAttrSet(resourceName, "name"), + testCheckAzureRMRoleDefinitionExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), ), }, }, @@ -233,7 +220,7 @@ func testCheckAzureRMRoleDefinitionDestroy(s *terraform.State) error { return nil } -func testAccAzureRMRoleDefinition_basic(id string, rInt int) string { +func testAccAzureRMRoleDefinition_basic(id string, data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_subscription" "primary" {} @@ -251,10 +238,10 @@ resource "azurerm_role_definition" "test" { "${data.azurerm_subscription.primary.id}", ] } -`, id, rInt) +`, id, data.RandomInteger) } -func testAccAzureRMRoleDefinition_requiresImport(id string, rInt int) string { +func testAccAzureRMRoleDefinition_requiresImport(id string, data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -272,10 +259,10 @@ resource "azurerm_role_definition" "import" { "${data.azurerm_subscription.primary.id}", ] } -`, testAccAzureRMRoleDefinition_basic(id, rInt)) +`, testAccAzureRMRoleDefinition_basic(id, data)) } -func testAccAzureRMRoleDefinition_complete(id string, rInt int) string { +func testAccAzureRMRoleDefinition_complete(id string, data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_subscription" "primary" {} @@ -296,10 +283,10 @@ resource "azurerm_role_definition" "test" { "${data.azurerm_subscription.primary.id}", ] } -`, id, rInt) +`, id, data.RandomInteger) } -func testAccAzureRMRoleDefinition_updated(id string, rInt int) string { +func testAccAzureRMRoleDefinition_updated(id string, data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_subscription" "primary" {} @@ -318,10 +305,10 @@ resource "azurerm_role_definition" "test" { "${data.azurerm_subscription.primary.id}", ] } -`, id, rInt) +`, id, data.RandomInteger) } -func testAccAzureRMRoleDefinition_emptyId(rInt int) string { +func testAccAzureRMRoleDefinition_emptyId(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_subscription" "primary" {} @@ -338,10 +325,10 @@ resource "azurerm_role_definition" "test" { "${data.azurerm_subscription.primary.id}", ] } -`, rInt) +`, data.RandomInteger) } -func testAccAzureRMRoleDefinition_updateEmptyId(rInt int) string { +func testAccAzureRMRoleDefinition_updateEmptyId(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_subscription" "primary" {} @@ -358,5 +345,5 @@ resource "azurerm_role_definition" "test" { "${data.azurerm_subscription.primary.id}", ] } -`, rInt) +`, data.RandomInteger) } From fb0542bfcf561232cef2838f9d7d8f1ce75b4167 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 19:18:07 +0100 Subject: [PATCH 134/203] healthcare: fixing the tests --- .../data_source_healthcare_service_test.go | 49 -------------- .../data_source_healthcare_service_test.go | 44 +++++++++++++ .../resource_arm_healthcare_service_test.go | 65 +++++++------------ 3 files changed, 69 insertions(+), 89 deletions(-) delete mode 100644 azurerm/internal/services/healthcare/data_source_healthcare_service_test.go create mode 100644 azurerm/internal/services/healthcare/tests/data_source_healthcare_service_test.go rename azurerm/internal/services/healthcare/{ => tests}/resource_arm_healthcare_service_test.go (78%) diff --git a/azurerm/internal/services/healthcare/data_source_healthcare_service_test.go b/azurerm/internal/services/healthcare/data_source_healthcare_service_test.go deleted file mode 100644 index b1270b4baad7..000000000000 --- a/azurerm/internal/services/healthcare/data_source_healthcare_service_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package healthcare - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccAzureRMDataSourceHealthCareService_basic(t *testing.T) { - dataSourceName := "data.azurerm_healthcare_service.test" - ri := tf.AccRandTimeInt() / 10 - // currently only supported in "ukwest", "northcentralus", "westus2". - location := "westus2" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHealthCareServiceDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMDataSourceHealthcareService_basic(ri, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "kind"), - resource.TestCheckResourceAttrSet(dataSourceName, "cosmosdb_throughput"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "2"), - ), - }, - }, - }) -} - -func testAccAzureRMDataSourceHealthcareService_basic(rInt int, location string) string { - resource := testAccAzureRMHealthCareService_basic(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_healthcare_service" "test" { - name = "${azurerm_healthcare_service.test.name}" - resource_group_name = "${azurerm_healthcare_service.test.resource_group_name}" - location = "${azurerm_resource_group.test.location}" -} -`, resource) -} diff --git a/azurerm/internal/services/healthcare/tests/data_source_healthcare_service_test.go b/azurerm/internal/services/healthcare/tests/data_source_healthcare_service_test.go new file mode 100644 index 000000000000..180f45f720d2 --- /dev/null +++ b/azurerm/internal/services/healthcare/tests/data_source_healthcare_service_test.go @@ -0,0 +1,44 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccAzureRMDataSourceHealthCareService_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_healthcare_service", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMHealthCareServiceDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataSourceHealthcareService_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kind"), + resource.TestCheckResourceAttrSet(data.ResourceName, "cosmosdb_throughput"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + ), + }, + }, + }) +} + +func testAccAzureRMDataSourceHealthcareService_basic(data acceptance.TestData) string { + resource := testAccAzureRMHealthCareService_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_healthcare_service" "test" { + name = "${azurerm_healthcare_service.test.name}" + resource_group_name = "${azurerm_healthcare_service.test.resource_group_name}" + location = "${azurerm_resource_group.test.location}" +} +`, resource) +} diff --git a/azurerm/internal/services/healthcare/resource_arm_healthcare_service_test.go b/azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go similarity index 78% rename from azurerm/internal/services/healthcare/resource_arm_healthcare_service_test.go rename to azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go index 664c1e9b7819..d0cf65dc5e64 100644 --- a/azurerm/internal/services/healthcare/resource_arm_healthcare_service_test.go +++ b/azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go @@ -1,4 +1,4 @@ -package healthcare +package tests import ( "fmt" @@ -7,33 +7,25 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMHealthCareService_basic(t *testing.T) { - ri := tf.AccRandTimeInt() / 10 - // currently only supported in "ukwest", "northcentralus", "westus2". - location := "westus2" - + data := acceptance.BuildTestData(t, "azurerm_healthcare_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMHealthCareServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMHealthCareService_basic(ri, location), + Config: testAccAzureRMHealthCareService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHealthCareServiceExists("azurerm_healthcare_service.test"), + testCheckAzureRMHealthCareServiceExists(data.ResourceName), ), }, - { - ResourceName: "azurerm_healthcare_service.test", - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,50 +36,37 @@ func TestAccAzureRMHealthCareService_requiresImport(t *testing.T) { return } - ri := tf.AccRandTimeInt() / 10 - // currently only supported in "ukwest", "northcentralus", "westus2". - location := "westus2" - + data := acceptance.BuildTestData(t, "azurerm_healthcare_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMHealthCareServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMHealthCareService_basic(ri, location), + Config: testAccAzureRMHealthCareService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHealthCareServiceExists("azurerm_healthcare_service.test"), + testCheckAzureRMHealthCareServiceExists(data.ResourceName), ), }, - { - Config: testAccAzureRMHealthCareService_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_healthcare_service"), - }, + data.RequiresImportErrorStep(testAccAzureRMHealthCareService_requiresImport), }, }) } func TestAccAzureRMHealthCareService_complete(t *testing.T) { - ri := tf.AccRandTimeInt() / 10 - // currently only supported in "ukwest", "northcentralus", "westus2". - location := "westus2" - + data := acceptance.BuildTestData(t, "azurerm_healthcare_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMHealthCareServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMHealthCareService_complete(ri, location), + Config: testAccAzureRMHealthCareService_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHealthCareServiceExists("azurerm_healthcare_service.test"), + testCheckAzureRMHealthCareServiceExists(data.ResourceName), ), }, - { - ResourceName: "azurerm_healthcare_service.test", - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -146,7 +125,10 @@ func testCheckAzureRMHealthCareServiceDestroy(s *terraform.State) error { return nil } -func testAccAzureRMHealthCareService_basic(rInt int, location string) string { +func testAccAzureRMHealthCareService_basic(data acceptance.TestData) string { + // currently only supported in "ukwest", "northcentralus", "westus2". + location := "westus2" + return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -164,11 +146,11 @@ resource "azurerm_healthcare_service" "test" { "${data.azurerm_client_config.current.service_principal_object_id}", ] } -`, rInt, location, rInt) +`, data.RandomInteger, location, data.RandomInteger) } -func testAccAzureRMHealthCareService_requiresImport(rInt int, location string) string { - template := testAccAzureRMHealthCareService_basic(rInt, location) +func testAccAzureRMHealthCareService_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMHealthCareService_basic(data) return fmt.Sprintf(` %s @@ -184,7 +166,10 @@ resource "azurerm_healthcare_service" "import" { `, template) } -func testAccAzureRMHealthCareService_complete(rInt int, location string) string { +func testAccAzureRMHealthCareService_complete(data acceptance.TestData) string { + // currently only supported in "ukwest", "northcentralus", "westus2". + location := "westus2" + return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -221,5 +206,5 @@ resource "azurerm_healthcare_service" "test" { allow_credentials = true } } -`, rInt, location, rInt) +`, data.RandomInteger, location, data.RandomInteger) } From 6f5097d01b6d646c9dabb061e7f4401eee844ee1 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Sat, 21 Dec 2019 10:15:25 -0800 Subject: [PATCH 135/203] tests: automation --- .../automation/automation_variable.go | 6 +- .../{ => tests}/automation_variable_test.go | 5 +- .../data_source_automation_account_test.go | 13 +- ...ta_source_automation_variable_bool_test.go | 10 +- ...ource_automation_variable_datetime_test.go | 10 +- ...ata_source_automation_variable_int_test.go | 10 +- ..._source_automation_variable_string_test.go | 10 +- .../resource_arm_automation_account_test.go | 97 ++++------ ...esource_arm_automation_certificate_test.go | 94 ++++------ ...resource_arm_automation_credential_test.go | 63 +++---- ...e_arm_automation_dsc_configuration_test.go | 2 +- ...m_automation_dsc_nodeconfiguration_test.go | 42 ++--- ...source_arm_automation_job_schedule_test.go | 65 +++---- .../resource_arm_automation_module_test.go | 60 ++---- .../resource_arm_automation_runbook_test.go | 83 +++----- .../resource_arm_automation_schedule_test.go | 177 ++++++------------ ...ource_arm_automation_variable_bool_test.go | 69 +++---- ...e_arm_automation_variable_datetime_test.go | 69 +++---- ...source_arm_automation_variable_int_test.go | 69 +++---- ...rce_arm_automation_variable_string_test.go | 69 +++---- .../testdata/automation_certificate_test.pfx | Bin .../automation_certificate_test.thumb | 0 .../automation_certificate_testdata.sh | 0 ...source_arm_key_vault_access_policy_test.go | 2 +- .../resource_arm_key_vault_migration_test.go | 2 +- .../tests/resource_arm_key_vault_test.go | 2 +- 26 files changed, 385 insertions(+), 644 deletions(-) rename azurerm/internal/services/automation/{ => tests}/automation_variable_test.go (95%) rename azurerm/internal/services/automation/{ => tests}/data_source_automation_account_test.go (75%) rename azurerm/internal/services/automation/{ => tests}/data_source_automation_variable_bool_test.go (78%) rename azurerm/internal/services/automation/{ => tests}/data_source_automation_variable_datetime_test.go (77%) rename azurerm/internal/services/automation/{ => tests}/data_source_automation_variable_int_test.go (79%) rename azurerm/internal/services/automation/{ => tests}/data_source_automation_variable_string_test.go (77%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_account_test.go (69%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_certificate_test.go (69%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_credential_test.go (74%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_dsc_configuration_test.go (99%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_dsc_nodeconfiguration_test.go (81%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_job_schedule_test.go (81%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_module_test.go (77%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_runbook_test.go (75%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_schedule_test.go (73%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_variable_bool_test.go (59%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_variable_datetime_test.go (58%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_variable_int_test.go (59%) rename azurerm/internal/services/automation/{ => tests}/resource_arm_automation_variable_string_test.go (58%) rename azurerm/internal/services/automation/{ => tests}/testdata/automation_certificate_test.pfx (100%) rename azurerm/internal/services/automation/{ => tests}/testdata/automation_certificate_test.thumb (100%) rename azurerm/internal/services/automation/{ => tests}/testdata/automation_certificate_testdata.sh (100%) diff --git a/azurerm/internal/services/automation/automation_variable.go b/azurerm/internal/services/automation/automation_variable.go index 3f71144455a7..220ba47c3db8 100644 --- a/azurerm/internal/services/automation/automation_variable.go +++ b/azurerm/internal/services/automation/automation_variable.go @@ -19,7 +19,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func parseAzureAutomationVariableValue(resource string, input *string) (interface{}, error) { +func ParseAzureAutomationVariableValue(resource string, input *string) (interface{}, error) { if input == nil { if resource != "azurerm_automation_variable_null" { return nil, fmt.Errorf("Expected value \"nil\" to be %q, actual type is \"azurerm_automation_variable_null\"", resource) @@ -224,7 +224,7 @@ func resourceAutomationVariableRead(d *schema.ResourceData, meta interface{}, va d.Set("description", properties.Description) d.Set("encrypted", properties.IsEncrypted) if !d.Get("encrypted").(bool) { - value, err := parseAzureAutomationVariableValue(fmt.Sprintf("azurerm_automation_variable_%s", varTypeLower), properties.Value) + value, err := ParseAzureAutomationVariableValue(fmt.Sprintf("azurerm_automation_variable_%s", varTypeLower), properties.Value) if err != nil { return err } @@ -269,7 +269,7 @@ func dataSourceAutomationVariableRead(d *schema.ResourceData, meta interface{}, d.Set("description", properties.Description) d.Set("encrypted", properties.IsEncrypted) if !d.Get("encrypted").(bool) { - value, err := parseAzureAutomationVariableValue(fmt.Sprintf("azurerm_automation_variable_%s", varTypeLower), properties.Value) + value, err := ParseAzureAutomationVariableValue(fmt.Sprintf("azurerm_automation_variable_%s", varTypeLower), properties.Value) if err != nil { return err } diff --git a/azurerm/internal/services/automation/automation_variable_test.go b/azurerm/internal/services/automation/tests/automation_variable_test.go similarity index 95% rename from azurerm/internal/services/automation/automation_variable_test.go rename to azurerm/internal/services/automation/tests/automation_variable_test.go index de4a146e22af..3e4eae607d73 100644 --- a/azurerm/internal/services/automation/automation_variable_test.go +++ b/azurerm/internal/services/automation/tests/automation_variable_test.go @@ -1,7 +1,8 @@ -package automation +package tests import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/automation" "strings" "testing" "time" @@ -66,7 +67,7 @@ func TestParseAzureRmAutomationVariableValue(t *testing.T) { if tc.IsNil { value = nil } - actual, err := parseAzureAutomationVariableValue(tc.Resource, value) + actual, err := automation.ParseAzureAutomationVariableValue(tc.Resource, value) if tc.HasError && err == nil { t.Fatalf("Expect parseAzureAutomationVariableValue to return error for resource %q and value %s", tc.Resource, tc.Value) } diff --git a/azurerm/internal/services/automation/data_source_automation_account_test.go b/azurerm/internal/services/automation/tests/data_source_automation_account_test.go similarity index 75% rename from azurerm/internal/services/automation/data_source_automation_account_test.go rename to azurerm/internal/services/automation/tests/data_source_automation_account_test.go index 38ecc22c7a1f..7d9654a337b3 100644 --- a/azurerm/internal/services/automation/data_source_automation_account_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_account_test.go @@ -1,28 +1,25 @@ -package automation +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAutomationAccount(t *testing.T) { - dataSourceName := "data.azurerm_automation_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resourceGroupName := fmt.Sprintf("acctestRG-%d", ri) + data := acceptance.BuildTestData(t, "data.azurerm_automation_account", "test") + resourceGroupName := fmt.Sprintf("acctestRG-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAutomationAccount_complete(resourceGroupName, location, ri), + Config: testAccDataSourceAutomationAccount_complete(resourceGroupName, data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "resource_group_name", resourceGroupName), + resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName), ), }, }, diff --git a/azurerm/internal/services/automation/data_source_automation_variable_bool_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go similarity index 78% rename from azurerm/internal/services/automation/data_source_automation_variable_bool_test.go rename to azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go index 50d786fc2cca..21129d5bfb9d 100644 --- a/azurerm/internal/services/automation/data_source_automation_variable_bool_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -10,18 +10,16 @@ import ( ) func TestAccDataSourceAzureRMAutomationVariableBool_basic(t *testing.T) { - dataSourceName := "data.azurerm_automation_variable_bool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_automation_variable_bool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAutomationVariableBool_basic(ri, location), + Config: testAccDataSourceAutomationVariableBool_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "value", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "value", "false"), ), }, }, diff --git a/azurerm/internal/services/automation/data_source_automation_variable_datetime_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go similarity index 77% rename from azurerm/internal/services/automation/data_source_automation_variable_datetime_test.go rename to azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go index f2aa15df1109..983c71a39d1a 100644 --- a/azurerm/internal/services/automation/data_source_automation_variable_datetime_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -10,18 +10,16 @@ import ( ) func TestAccDataSourceAzureRMAutomationVariableDateTime_basic(t *testing.T) { - dataSourceName := "data.azurerm_automation_variable_datetime.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_automation_variable_datetime", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAutomationVariableDateTime_basic(ri, location), + Config: testAccDataSourceAutomationVariableDateTime_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "value", "2019-04-24T21:40:54.074Z"), + resource.TestCheckResourceAttr(data.ResourceName, "value", "2019-04-24T21:40:54.074Z"), ), }, }, diff --git a/azurerm/internal/services/automation/data_source_automation_variable_int_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go similarity index 79% rename from azurerm/internal/services/automation/data_source_automation_variable_int_test.go rename to azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go index 137ca7de9ea2..20abed0d6197 100644 --- a/azurerm/internal/services/automation/data_source_automation_variable_int_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -10,18 +10,16 @@ import ( ) func TestAccDataSourceAzureRMAutomationVariableInt_basic(t *testing.T) { - dataSourceName := "data.azurerm_automation_variable_int.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_automation_variable_int", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAutomationVariableInt_basic(ri, location), + Config: testAccDataSourceAutomationVariableInt_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "value", "1234"), + resource.TestCheckResourceAttr(data.ResourceName, "value", "1234"), ), }, }, diff --git a/azurerm/internal/services/automation/data_source_automation_variable_string_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go similarity index 77% rename from azurerm/internal/services/automation/data_source_automation_variable_string_test.go rename to azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go index 967ca94bc477..fd3df40904ea 100644 --- a/azurerm/internal/services/automation/data_source_automation_variable_string_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -10,18 +10,16 @@ import ( ) func TestAccDataSourceAzureRMAutomationVariableString_basic(t *testing.T) { - dataSourceName := "data.azurerm_automation_variable_string.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_automation_variable_string", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAutomationVariableString_basic(ri, location), + Config: testAccDataSourceAutomationVariableString_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "value", "Hello, Terraform Basic Test."), + resource.TestCheckResourceAttr(data.ResourceName, "value", "Hello, Terraform Basic Test."), ), }, }, diff --git a/azurerm/internal/services/automation/resource_arm_automation_account_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_account_test.go similarity index 69% rename from azurerm/internal/services/automation/resource_arm_automation_account_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_account_test.go index 65d7df7d8e37..cf27c7a958d1 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_account_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_account_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +14,7 @@ import ( ) func TestAccAzureRMAutomationAccount_basic(t *testing.T) { - resourceName := "azurerm_automation_account.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,28 +22,23 @@ func TestAccAzureRMAutomationAccount_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationAccount_basic(ri, acceptance.Location()), + Config: testAccAzureRMAutomationAccount_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku_name", "Basic"), - resource.TestCheckResourceAttrSet(resourceName, "dsc_server_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "dsc_primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "dsc_secondary_access_key"), + testCheckAzureRMAutomationAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "Basic"), + resource.TestCheckResourceAttrSet(data.ResourceName, "dsc_server_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "dsc_primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "dsc_secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } // Remove in 2.0 func TestAccAzureRMAutomationAccount_basicClassic(t *testing.T) { - resourceName := "azurerm_automation_account.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,27 +46,23 @@ func TestAccAzureRMAutomationAccount_basicClassic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationAccount_basicClassic(ri, acceptance.Location()), + Config: testAccAzureRMAutomationAccount_basicClassic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Basic"), - resource.TestCheckResourceAttrSet(resourceName, "dsc_server_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "dsc_primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "dsc_secondary_access_key"), + testCheckAzureRMAutomationAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Basic"), + resource.TestCheckResourceAttrSet(data.ResourceName, "dsc_server_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "dsc_primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "dsc_secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } // Remove in 2.0 func TestAccAzureRMAutomationAccount_basicNotDefined(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,7 +70,7 @@ func TestAccAzureRMAutomationAccount_basicNotDefined(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationAccount_basicNotDefined(ri, acceptance.Location()), + Config: testAccAzureRMAutomationAccount_basicNotDefined(data), ExpectError: regexp.MustCompile("either 'sku_name' or 'sku' must be defined in the configuration file"), }, }, @@ -93,10 +82,7 @@ func TestAccAzureRMAutomationAccount_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_automation_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,13 +90,13 @@ func TestAccAzureRMAutomationAccount_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationAccount_basic(ri, location), + Config: testAccAzureRMAutomationAccount_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationAccountExists(resourceName), + testCheckAzureRMAutomationAccountExists(data.ResourceName), ), }, { - Config: testAccAzureRMAutomationAccount_requiresImport(ri, location), + Config: testAccAzureRMAutomationAccount_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_automation_account"), }, }, @@ -118,8 +104,7 @@ func TestAccAzureRMAutomationAccount_requiresImport(t *testing.T) { } func TestAccAzureRMAutomationAccount_complete(t *testing.T) { - resourceName := "azurerm_automation_account.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -127,18 +112,14 @@ func TestAccAzureRMAutomationAccount_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationAccount_complete(ri, acceptance.Location()), + Config: testAccAzureRMAutomationAccount_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku_name", "Basic"), - resource.TestCheckResourceAttr(resourceName, "tags.hello", "world"), + testCheckAzureRMAutomationAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "Basic"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.hello", "world"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -202,7 +183,7 @@ func testCheckAzureRMAutomationAccountExists(resourceName string) resource.TestC } } -func testAccAzureRMAutomationAccount_basic(rInt int, location string) string { +func testAccAzureRMAutomationAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -216,11 +197,11 @@ resource "azurerm_automation_account" "test" { sku_name = "Basic" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } // Remove in 2.0 -func testAccAzureRMAutomationAccount_basicClassic(rInt int, location string) string { +func testAccAzureRMAutomationAccount_basicClassic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -236,11 +217,11 @@ resource "azurerm_automation_account" "test" { name = "Basic" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } // Remove in 2.0 -func testAccAzureRMAutomationAccount_basicNotDefined(rInt int, location string) string { +func testAccAzureRMAutomationAccount_basicNotDefined(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -252,11 +233,11 @@ resource "azurerm_automation_account" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAutomationAccount_requiresImport(rInt int, location string) string { - template := testAccAzureRMAutomationAccount_basic(rInt, location) +func testAccAzureRMAutomationAccount_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAutomationAccount_basic(data) return fmt.Sprintf(` %s @@ -270,7 +251,7 @@ resource "azurerm_automation_account" "import" { `, template) } -func testAccAzureRMAutomationAccount_complete(rInt int, location string) string { +func testAccAzureRMAutomationAccount_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -288,5 +269,5 @@ resource "azurerm_automation_account" "test" { "hello" = "world" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/automation/resource_arm_automation_certificate_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_certificate_test.go similarity index 69% rename from azurerm/internal/services/automation/resource_arm_automation_certificate_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_certificate_test.go index 9796c4c7a952..7c4b4b3d5df1 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_certificate_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_certificate_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "encoding/base64" @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -23,8 +22,7 @@ var testCertRaw, _ = ioutil.ReadFile(filepath.Join("testdata", "automation_certi var testCertBase64 = base64.StdEncoding.EncodeToString(testCertRaw) func TestAccAzureRMAutomationCertificate_basic(t *testing.T) { - resourceName := "azurerm_automation_certificate.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -32,17 +30,12 @@ func TestAccAzureRMAutomationCertificate_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationCertificate_basic(ri, acceptance.Location()), + Config: testAccAzureRMAutomationCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationCertificateExists(resourceName), + testCheckAzureRMAutomationCertificateExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"base64"}, - }, + data.ImportStep("base64"), }, }) } @@ -52,10 +45,7 @@ func TestAccAzureRMAutomationCertificate_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_automation_certificate.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_certificate", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -63,22 +53,18 @@ func TestAccAzureRMAutomationCertificate_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationCertificate_basic(ri, location), + Config: testAccAzureRMAutomationCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationCertificateExists(resourceName), + testCheckAzureRMAutomationCertificateExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAutomationCertificate_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_automation_certificate"), - }, + data.RequiresImportErrorStep(testAccAzureRMAutomationCertificate_requiresImport), }, }) } func TestAccAzureRMAutomationCertificate_complete(t *testing.T) { - resourceName := "azurerm_automation_certificate.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_certificate", "test") testCertThumbprint := strings.TrimSpace(string(testCertThumbprintRaw)) resource.ParallelTest(t, resource.TestCase{ @@ -87,26 +73,20 @@ func TestAccAzureRMAutomationCertificate_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationCertificate_complete(ri, acceptance.Location()), + Config: testAccAzureRMAutomationCertificate_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationCertificateExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "base64", testCertBase64), - resource.TestCheckResourceAttr(resourceName, "thumbprint", testCertThumbprint), + testCheckAzureRMAutomationCertificateExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "base64", testCertBase64), + resource.TestCheckResourceAttr(data.ResourceName, "thumbprint", testCertThumbprint), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"base64"}, - }, + data.ImportStep("base64"), }, }) } func TestAccAzureRMAutomationCertificate_update(t *testing.T) { - resourceName := "azurerm_automation_certificate.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_certificate", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,31 +94,21 @@ func TestAccAzureRMAutomationCertificate_update(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationCertificateDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationCertificate_basic(ri, acceptance.Location()), + Config: testAccAzureRMAutomationCertificate_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationCertificateExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", ""), + testCheckAzureRMAutomationCertificateExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", ""), ), }, + data.ImportStep("base64"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"base64"}, - }, - { - Config: testAccAzureRMAutomationCertificate_update(ri, acceptance.Location()), + Config: testAccAzureRMAutomationCertificate_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationCertificateExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This is a test certificate for terraform acceptance test"), + testCheckAzureRMAutomationCertificateExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This is a test certificate for terraform acceptance test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"base64"}, - }, + data.ImportStep("base64"), }, }) } @@ -201,7 +171,7 @@ func testCheckAzureRMAutomationCertificateExists(resourceName string) resource.T } } -func testAccAzureRMAutomationCertificate_basic(rInt int, location string) string { +func testAccAzureRMAutomationCertificate_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -221,11 +191,11 @@ resource "azurerm_automation_certificate" "test" { automation_account_name = azurerm_automation_account.test.name base64 = "%s" } -`, rInt, location, rInt, rInt, testCertBase64) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, testCertBase64) } -func testAccAzureRMAutomationCertificate_requiresImport(rInt int, location string) string { - template := testAccAzureRMAutomationCertificate_basic(rInt, location) +func testAccAzureRMAutomationCertificate_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAutomationCertificate_basic(data) return fmt.Sprintf(` %s @@ -239,7 +209,7 @@ resource "azurerm_automation_certificate" "import" { `, template) } -func testAccAzureRMAutomationCertificate_complete(rInt int, location string) string { +func testAccAzureRMAutomationCertificate_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -260,10 +230,10 @@ resource "azurerm_automation_certificate" "test" { base64 = "%s" description = "This is a test certificate for terraform acceptance test" } -`, rInt, location, rInt, rInt, testCertBase64) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, testCertBase64) } -func testAccAzureRMAutomationCertificate_update(rInt int, location string) string { +func testAccAzureRMAutomationCertificate_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -284,5 +254,5 @@ resource "azurerm_automation_certificate" "test" { base64 = "%s" description = "This is a test certificate for terraform acceptance test" } -`, rInt, location, rInt, rInt, testCertBase64) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, testCertBase64) } diff --git a/azurerm/internal/services/automation/resource_arm_automation_credential_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_credential_test.go similarity index 74% rename from azurerm/internal/services/automation/resource_arm_automation_credential_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_credential_test.go index 0ac1307f800b..1952bf0dde56 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_credential_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_credential_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMAutomationCredential_basic(t *testing.T) { - resourceName := "azurerm_automation_credential.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_credential", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,18 +21,13 @@ func TestAccAzureRMAutomationCredential_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationCredentialDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationCredential_basic(ri, acceptance.Location()), + Config: testAccAzureRMAutomationCredential_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationCredentialExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "username", "test_user"), + testCheckAzureRMAutomationCredentialExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "username", "test_user"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"password"}, - }, + data.ImportStep("password"), }, }) } @@ -44,10 +37,7 @@ func TestAccAzureRMAutomationCredential_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_automation_credential.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_credential", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,22 +45,18 @@ func TestAccAzureRMAutomationCredential_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationCredentialDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationCredential_basic(ri, location), + Config: testAccAzureRMAutomationCredential_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationCredentialExists(resourceName), + testCheckAzureRMAutomationCredentialExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAutomationCredential_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_automation_credential"), - }, + data.RequiresImportErrorStep(testAccAzureRMAutomationCredential_requiresImport), }, }) } func TestAccAzureRMAutomationCredential_complete(t *testing.T) { - resourceName := "azurerm_automation_credential.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_credential", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,19 +64,14 @@ func TestAccAzureRMAutomationCredential_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationCredentialDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationCredential_complete(ri, acceptance.Location()), + Config: testAccAzureRMAutomationCredential_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationCredentialExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "username", "test_user"), - resource.TestCheckResourceAttr(resourceName, "description", "This is a test credential for terraform acceptance test"), + testCheckAzureRMAutomationCredentialExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "username", "test_user"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This is a test credential for terraform acceptance test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"password"}, - }, + data.ImportStep("password"), }, }) } @@ -161,7 +142,7 @@ func testCheckAzureRMAutomationCredentialExists(resourceName string) resource.Te } } -func testAccAzureRMAutomationCredential_basic(rInt int, location string) string { +func testAccAzureRMAutomationCredential_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -185,11 +166,11 @@ resource "azurerm_automation_credential" "test" { username = "test_user" password = "test_pwd" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAutomationCredential_requiresImport(rInt int, location string) string { - template := testAccAzureRMAutomationCredential_basic(rInt, location) +func testAccAzureRMAutomationCredential_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAutomationCredential_basic(data) return fmt.Sprintf(` %s @@ -203,7 +184,7 @@ resource "azurerm_automation_credential" "import" { `, template) } -func testAccAzureRMAutomationCredential_complete(rInt int, location string) string { +func testAccAzureRMAutomationCredential_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -228,5 +209,5 @@ resource "azurerm_automation_credential" "test" { password = "test_pwd" description = "This is a test credential for terraform acceptance test" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/automation/resource_arm_automation_dsc_configuration_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go similarity index 99% rename from azurerm/internal/services/automation/resource_arm_automation_dsc_configuration_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go index 372173bb7fa5..589c2701117f 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_dsc_configuration_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" diff --git a/azurerm/internal/services/automation/resource_arm_automation_dsc_nodeconfiguration_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_nodeconfiguration_test.go similarity index 81% rename from azurerm/internal/services/automation/resource_arm_automation_dsc_nodeconfiguration_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_dsc_nodeconfiguration_test.go index 6e87fe0949ff..c2fa8e736bbf 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_dsc_nodeconfiguration_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_nodeconfiguration_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMAutomationDscNodeConfiguration_basic(t *testing.T) { - resourceName := "azurerm_automation_dsc_nodeconfiguration.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_dsc_nodeconfiguration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,19 +21,13 @@ func TestAccAzureRMAutomationDscNodeConfiguration_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationDscNodeConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationDscNodeConfiguration_basic(ri, acceptance.Location()), + Config: testAccAzureRMAutomationDscNodeConfiguration_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationDscNodeConfigurationExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "configuration_name", "acctest"), + testCheckAzureRMAutomationDscNodeConfigurationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "configuration_name", "acctest"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - // Cannot check content_embedded at this time as it is not exposed via REST API / Azure SDK - ImportStateVerifyIgnore: []string{"content_embedded"}, - }, + data.ImportStep("content_embedded"), }, }) } @@ -45,10 +37,7 @@ func TestAccAzureRMAutomationDscNodeConfiguration_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_automation_dsc_nodeconfiguration.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_dsc_nodeconfiguration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,15 +45,12 @@ func TestAccAzureRMAutomationDscNodeConfiguration_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationDscNodeConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationDscNodeConfiguration_basic(ri, location), + Config: testAccAzureRMAutomationDscNodeConfiguration_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationDscNodeConfigurationExists(resourceName), + testCheckAzureRMAutomationDscNodeConfigurationExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAutomationDscNodeConfiguration_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_automation_dsc_nodeconfiguration"), - }, + data.RequiresImportErrorStep(testAccAzureRMAutomationDscNodeConfiguration_requiresImport), }, }) } @@ -135,7 +121,7 @@ func testCheckAzureRMAutomationDscNodeConfigurationExists(resourceName string) r } } -func testAccAzureRMAutomationDscNodeConfiguration_basic(rInt int, location string) string { +func testAccAzureRMAutomationDscNodeConfiguration_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -190,11 +176,11 @@ instance of OMI_ConfigurationDocument }; mofcontent } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAutomationDscNodeConfiguration_requiresImport(rInt int, location string) string { - template := testAccAzureRMAutomationDscNodeConfiguration_basic(rInt, location) +func testAccAzureRMAutomationDscNodeConfiguration_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAutomationDscNodeConfiguration_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/automation/resource_arm_automation_job_schedule_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_job_schedule_test.go similarity index 81% rename from azurerm/internal/services/automation/resource_arm_automation_job_schedule_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_job_schedule_test.go index d90d2eef3a27..b80e23057658 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_job_schedule_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_job_schedule_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" uuid "github.com/satori/go.uuid" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +15,7 @@ import ( ) func TestAccAzureRMAutomationJobSchedule_basic(t *testing.T) { - resourceName := "azurerm_automation_job_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_job_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,11 +23,11 @@ func TestAccAzureRMAutomationJobSchedule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationJobScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationJobSchedule_basic(ri, acceptance.Location()), - Check: checkAccAzureRMAutomationJobSchedule_basic(resourceName), + Config: testAccAzureRMAutomationJobSchedule_basic(data), + Check: checkAccAzureRMAutomationJobSchedule_basic(data.ResourceName), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -38,8 +36,7 @@ func TestAccAzureRMAutomationJobSchedule_basic(t *testing.T) { } func TestAccAzureRMAutomationJobSchedule_complete(t *testing.T) { - resourceName := "azurerm_automation_job_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_job_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -47,11 +44,11 @@ func TestAccAzureRMAutomationJobSchedule_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationJobScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationJobSchedule_complete(ri, acceptance.Location()), - Check: checkAccAzureRMAutomationJobSchedule_complete(resourceName), + Config: testAccAzureRMAutomationJobSchedule_complete(data), + Check: checkAccAzureRMAutomationJobSchedule_complete(data.ResourceName), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -60,8 +57,7 @@ func TestAccAzureRMAutomationJobSchedule_complete(t *testing.T) { } func TestAccAzureRMAutomationJobSchedule_update(t *testing.T) { - resourceName := "azurerm_automation_job_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_job_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -69,19 +65,19 @@ func TestAccAzureRMAutomationJobSchedule_update(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationJobScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationJobSchedule_basic(ri, acceptance.Location()), - Check: checkAccAzureRMAutomationJobSchedule_basic(resourceName), + Config: testAccAzureRMAutomationJobSchedule_basic(data), + Check: checkAccAzureRMAutomationJobSchedule_basic(data.ResourceName), }, { - Config: testAccAzureRMAutomationJobSchedule_complete(ri, acceptance.Location()), - Check: checkAccAzureRMAutomationJobSchedule_complete(resourceName), + Config: testAccAzureRMAutomationJobSchedule_complete(data), + Check: checkAccAzureRMAutomationJobSchedule_complete(data.ResourceName), }, { - Config: testAccAzureRMAutomationJobSchedule_basic(ri, acceptance.Location()), - Check: checkAccAzureRMAutomationJobSchedule_basic(resourceName), + Config: testAccAzureRMAutomationJobSchedule_basic(data), + Check: checkAccAzureRMAutomationJobSchedule_basic(data.ResourceName), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, }, @@ -94,10 +90,7 @@ func TestAccAzureRMAutomationJobSchedule_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_automation_job_schedule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_job_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -105,11 +98,11 @@ func TestAccAzureRMAutomationJobSchedule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationJobScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationJobSchedule_basic(ri, location), - Check: checkAccAzureRMAutomationJobSchedule_basic(resourceName), + Config: testAccAzureRMAutomationJobSchedule_basic(data), + Check: checkAccAzureRMAutomationJobSchedule_basic(data.ResourceName), }, { - Config: testAccAzureRMAutomationJobSchedule_requiresImport(ri, location), + Config: testAccAzureRMAutomationJobSchedule_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_automation_job_schedule"), }, }, @@ -191,7 +184,7 @@ func testCheckAzureRMAutomationJobScheduleExists(resourceName string) resource.T } } -func testAccAzureRMAutomationJobSchedulePrerequisites(rInt int, location string) string { +func testAccAzureRMAutomationJobSchedulePrerequisites(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -245,11 +238,11 @@ resource "azurerm_automation_schedule" "test" { automation_account_name = "${azurerm_automation_account.test.name}" frequency = "OneTime" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAutomationJobSchedule_basic(rInt int, location string) string { - template := testAccAzureRMAutomationJobSchedulePrerequisites(rInt, location) +func testAccAzureRMAutomationJobSchedule_basic(data acceptance.TestData) string { + template := testAccAzureRMAutomationJobSchedulePrerequisites(data) return fmt.Sprintf(` %s @@ -273,8 +266,8 @@ func checkAccAzureRMAutomationJobSchedule_basic(resourceName string) resource.Te ) } -func testAccAzureRMAutomationJobSchedule_complete(rInt int, location string) string { - template := testAccAzureRMAutomationJobSchedulePrerequisites(rInt, location) +func testAccAzureRMAutomationJobSchedule_complete(data acceptance.TestData) string { + template := testAccAzureRMAutomationJobSchedulePrerequisites(data) return fmt.Sprintf(` %s @@ -312,8 +305,8 @@ func checkAccAzureRMAutomationJobSchedule_complete(resourceName string) resource ) } -func testAccAzureRMAutomationJobSchedule_requiresImport(rInt int, location string) string { - template := testAccAzureRMAutomationJobSchedule_basic(rInt, location) +func testAccAzureRMAutomationJobSchedule_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAutomationJobSchedule_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/automation/resource_arm_automation_module_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_module_test.go similarity index 77% rename from azurerm/internal/services/automation/resource_arm_automation_module_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_module_test.go index b1f51c7f15b5..af057d5e4806 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_module_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_module_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMAutomationModule_basic(t *testing.T) { - resourceName := "azurerm_automation_module.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_module", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,18 +21,12 @@ func TestAccAzureRMAutomationModule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationModuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationModule_basic(ri, acceptance.Location()), + Config: testAccAzureRMAutomationModule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationModuleExists(resourceName), + testCheckAzureRMAutomationModuleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - // Module link is not returned by api in Get operation - ImportStateVerifyIgnore: []string{"module_link"}, - }, + data.ImportStep("module_link"), }, }) } @@ -44,10 +36,7 @@ func TestAccAzureRMAutomationModule_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_automation_module.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_module", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,23 +44,18 @@ func TestAccAzureRMAutomationModule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationModuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationModule_basic(ri, location), + Config: testAccAzureRMAutomationModule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationModuleExists(resourceName), + testCheckAzureRMAutomationModuleExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAutomationModule_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_automation_module"), - }, + data.RequiresImportErrorStep(testAccAzureRMAutomationModule_requiresImport), }, }) } func TestAccAzureRMAutomationModule_multipleModules(t *testing.T) { - resourceName := "azurerm_automation_module.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_module", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,18 +63,12 @@ func TestAccAzureRMAutomationModule_multipleModules(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationModuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationModule_multipleModules(ri, location), + Config: testAccAzureRMAutomationModule_multipleModules(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationModuleExists(resourceName), + testCheckAzureRMAutomationModuleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - // Module link is not returned by api in Get operation - ImportStateVerifyIgnore: []string{"module_link"}, - }, + data.ImportStep("module_link"), }, }) } @@ -161,7 +139,7 @@ func testCheckAzureRMAutomationModuleExists(resourceName string) resource.TestCh } } -func testAccAzureRMAutomationModule_basic(rInt int, location string) string { +func testAccAzureRMAutomationModule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -187,10 +165,10 @@ resource "azurerm_automation_module" "test" { uri = "https://devopsgallerystorage.blob.core.windows.net/packages/xactivedirectory.2.19.0.nupkg" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAutomationModule_multipleModules(rInt int, location string) string { +func testAccAzureRMAutomationModule_multipleModules(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -228,11 +206,11 @@ resource "azurerm_automation_module" "second" { depends_on = ["azurerm_automation_module.test"] } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAutomationModule_requiresImport(rInt int, location string) string { - template := testAccAzureRMAutomationModule_basic(rInt, location) +func testAccAzureRMAutomationModule_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAutomationModule_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/automation/resource_arm_automation_runbook_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_runbook_test.go similarity index 75% rename from azurerm/internal/services/automation/resource_arm_automation_runbook_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_runbook_test.go index 9b76f4b26390..4d3611883eba 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_runbook_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_runbook_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMAutomationRunbook_PSWorkflow(t *testing.T) { - resourceName := "azurerm_automation_runbook.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_runbook", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,18 +21,13 @@ func TestAccAzureRMAutomationRunbook_PSWorkflow(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationRunbookDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationRunbook_PSWorkflow(ri, acceptance.Location()), + Config: testAccAzureRMAutomationRunbook_PSWorkflow(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationRunbookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "runbook_type", "PowerShellWorkflow"), + testCheckAzureRMAutomationRunbookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "runbook_type", "PowerShellWorkflow"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"publish_content_link"}, - }, + data.ImportStep("publish_content_link"), }, }) } @@ -44,10 +37,7 @@ func TestAccAzureRMAutomationRunbook_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_automation_runbook.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_runbook", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,22 +45,18 @@ func TestAccAzureRMAutomationRunbook_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationRunbookDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationRunbook_PSWorkflow(ri, location), + Config: testAccAzureRMAutomationRunbook_PSWorkflow(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationRunbookExists(resourceName), + testCheckAzureRMAutomationRunbookExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAutomationRunbook_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_automation_runbook"), - }, + data.RequiresImportErrorStep(testAccAzureRMAutomationRunbook_requiresImport), }, }) } func TestAccAzureRMAutomationRunbook_PSWorkflowWithHash(t *testing.T) { - resourceName := "azurerm_automation_runbook.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_runbook", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,25 +64,19 @@ func TestAccAzureRMAutomationRunbook_PSWorkflowWithHash(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationRunbookDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationRunbook_PSWorkflowWithHash(ri, acceptance.Location()), + Config: testAccAzureRMAutomationRunbook_PSWorkflowWithHash(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationRunbookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "runbook_type", "PowerShellWorkflow"), + testCheckAzureRMAutomationRunbookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "runbook_type", "PowerShellWorkflow"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"publish_content_link"}, - }, + data.ImportStep("publish_content_link"), }, }) } func TestAccAzureRMAutomationRunbook_PSWithContent(t *testing.T) { - resourceName := "azurerm_automation_runbook.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_runbook", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,19 +84,14 @@ func TestAccAzureRMAutomationRunbook_PSWithContent(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationRunbookDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationRunbook_PSWithContent(ri, acceptance.Location()), + Config: testAccAzureRMAutomationRunbook_PSWithContent(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationRunbookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "runbook_type", "PowerShell"), - resource.TestCheckResourceAttr(resourceName, "content", "# Some test content\n# for Terraform acceptance test\n"), + testCheckAzureRMAutomationRunbookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "runbook_type", "PowerShell"), + resource.TestCheckResourceAttr(data.ResourceName, "content", "# Some test content\n# for Terraform acceptance test\n"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"publish_content_link"}, - }, + data.ImportStep("publish_content_link"), }, }) } @@ -187,7 +162,7 @@ func testCheckAzureRMAutomationRunbookExists(resourceName string) resource.TestC } } -func testAccAzureRMAutomationRunbook_PSWorkflow(rInt int, location string) string { +func testAccAzureRMAutomationRunbook_PSWorkflow(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -219,11 +194,11 @@ resource "azurerm_automation_runbook" "test" { uri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/c4935ffb69246a6058eb24f54640f53f69d3ac9f/101-automation-runbook-getvms/Runbooks/Get-AzureVMTutorial.ps1" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAutomationRunbook_requiresImport(rInt int, location string) string { - template := testAccAzureRMAutomationRunbook_PSWorkflow(rInt, location) +func testAccAzureRMAutomationRunbook_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAutomationRunbook_PSWorkflow(data) return fmt.Sprintf(` %s @@ -245,7 +220,7 @@ resource "azurerm_automation_runbook" "import" { `, template) } -func testAccAzureRMAutomationRunbook_PSWorkflowWithHash(rInt int, location string) string { +func testAccAzureRMAutomationRunbook_PSWorkflowWithHash(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -283,10 +258,10 @@ resource "azurerm_automation_runbook" "test" { } } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAutomationRunbook_PSWithContent(rInt int, location string) string { +func testAccAzureRMAutomationRunbook_PSWithContent(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -323,5 +298,5 @@ resource "azurerm_automation_runbook" "test" { # for Terraform acceptance test CONTENT } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/automation/resource_arm_automation_schedule_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_schedule_test.go similarity index 73% rename from azurerm/internal/services/automation/resource_arm_automation_schedule_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_schedule_test.go index facfe47b2156..f8c627f24797 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_schedule_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_schedule_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +15,7 @@ import ( ) func TestAccAzureRMAutomationSchedule_oneTime_basic(t *testing.T) { - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,14 +23,10 @@ func TestAccAzureRMAutomationSchedule_oneTime_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_oneTime_basic(ri, acceptance.Location()), - Check: checkAccAzureRMAutomationSchedule_oneTime_basic(resourceName), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMAutomationSchedule_oneTime_basic(data), + Check: checkAccAzureRMAutomationSchedule_oneTime_basic(data.ResourceName), }, + data.ImportStep(), }, }) } @@ -41,10 +35,7 @@ func TestAccAzureRMAutomationSchedule_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,20 +43,16 @@ func TestAccAzureRMAutomationSchedule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_oneTime_basic(ri, location), - Check: checkAccAzureRMAutomationSchedule_oneTime_basic(resourceName), - }, - { - Config: testAccAzureRMAutomationSchedule_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_automation_schedule"), + Config: testAccAzureRMAutomationSchedule_oneTime_basic(data), + Check: checkAccAzureRMAutomationSchedule_oneTime_basic(data.ResourceName), }, + data.RequiresImportErrorStep(testAccAzureRMAutomationSchedule_requiresImport), }, }) } func TestAccAzureRMAutomationSchedule_oneTime_complete(t *testing.T) { - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") //the API returns the time in the timezone we pass in //it also seems to strip seconds, hijack the RFC3339 format to have 0s there @@ -78,21 +65,16 @@ func TestAccAzureRMAutomationSchedule_oneTime_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_oneTime_complete(ri, acceptance.Location(), startTime), - Check: checkAccAzureRMAutomationSchedule_oneTime_complete(resourceName, startTime), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMAutomationSchedule_oneTime_complete(data, startTime), + Check: checkAccAzureRMAutomationSchedule_oneTime_complete(data.ResourceName, startTime), }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationSchedule_oneTime_update(t *testing.T) { - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") //the API returns the time in the timezone we pass in //it also seems to strip seconds, hijack the RFC3339 format to have 0s there @@ -105,20 +87,19 @@ func TestAccAzureRMAutomationSchedule_oneTime_update(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_oneTime_basic(ri, acceptance.Location()), - Check: checkAccAzureRMAutomationSchedule_oneTime_basic(resourceName), + Config: testAccAzureRMAutomationSchedule_oneTime_basic(data), + Check: checkAccAzureRMAutomationSchedule_oneTime_basic(data.ResourceName), }, { - Config: testAccAzureRMAutomationSchedule_oneTime_complete(ri, acceptance.Location(), startTime), - Check: checkAccAzureRMAutomationSchedule_oneTime_complete(resourceName, startTime), + Config: testAccAzureRMAutomationSchedule_oneTime_complete(data, startTime), + Check: checkAccAzureRMAutomationSchedule_oneTime_complete(data.ResourceName, startTime), }, }, }) } func TestAccAzureRMAutomationSchedule_hourly(t *testing.T) { - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -126,21 +107,16 @@ func TestAccAzureRMAutomationSchedule_hourly(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_recurring_basic(ri, acceptance.Location(), "Hour", 7), - Check: checkAccAzureRMAutomationSchedule_recurring_basic(resourceName, "Hour", 7), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMAutomationSchedule_recurring_basic(data, "Hour", 7), + Check: checkAccAzureRMAutomationSchedule_recurring_basic(data.ResourceName, "Hour", 7), }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationSchedule_daily(t *testing.T) { - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -148,21 +124,16 @@ func TestAccAzureRMAutomationSchedule_daily(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_recurring_basic(ri, acceptance.Location(), "Day", 7), - Check: checkAccAzureRMAutomationSchedule_recurring_basic(resourceName, "Day", 7), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMAutomationSchedule_recurring_basic(data, "Day", 7), + Check: checkAccAzureRMAutomationSchedule_recurring_basic(data.ResourceName, "Day", 7), }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationSchedule_weekly(t *testing.T) { - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -170,21 +141,16 @@ func TestAccAzureRMAutomationSchedule_weekly(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_recurring_basic(ri, acceptance.Location(), "Week", 7), - Check: checkAccAzureRMAutomationSchedule_recurring_basic(resourceName, "Week", 7), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMAutomationSchedule_recurring_basic(data, "Week", 7), + Check: checkAccAzureRMAutomationSchedule_recurring_basic(data.ResourceName, "Week", 7), }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationSchedule_monthly(t *testing.T) { - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -192,21 +158,16 @@ func TestAccAzureRMAutomationSchedule_monthly(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_recurring_basic(ri, acceptance.Location(), "Month", 7), - Check: checkAccAzureRMAutomationSchedule_recurring_basic(resourceName, "Month", 7), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMAutomationSchedule_recurring_basic(data, "Month", 7), + Check: checkAccAzureRMAutomationSchedule_recurring_basic(data.ResourceName, "Month", 7), }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationSchedule_weekly_advanced(t *testing.T) { - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -214,21 +175,16 @@ func TestAccAzureRMAutomationSchedule_weekly_advanced(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_recurring_advanced_week(ri, acceptance.Location(), "Monday"), - Check: checkAccAzureRMAutomationSchedule_recurring_advanced_week(resourceName), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMAutomationSchedule_recurring_advanced_week(data, "Monday"), + Check: checkAccAzureRMAutomationSchedule_recurring_advanced_week(data.ResourceName), }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationSchedule_monthly_advanced_by_day(t *testing.T) { - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -236,21 +192,16 @@ func TestAccAzureRMAutomationSchedule_monthly_advanced_by_day(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_recurring_advanced_month(ri, acceptance.Location(), 2), - Check: checkAccAzureRMAutomationSchedule_recurring_advanced_month(resourceName), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMAutomationSchedule_recurring_advanced_month(data, 2), + Check: checkAccAzureRMAutomationSchedule_recurring_advanced_month(data.ResourceName), }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationSchedule_monthly_advanced_by_week_day(t *testing.T) { - resourceName := "azurerm_automation_schedule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_automation_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -258,14 +209,10 @@ func TestAccAzureRMAutomationSchedule_monthly_advanced_by_week_day(t *testing.T) CheckDestroy: testCheckAzureRMAutomationScheduleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationSchedule_recurring_advanced_month_week_day(ri, acceptance.Location(), "Monday", 2), - Check: checkAccAzureRMAutomationSchedule_recurring_advanced_month_week_day(resourceName, "Monday", 2), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMAutomationSchedule_recurring_advanced_month_week_day(data, "Monday", 2), + Check: checkAccAzureRMAutomationSchedule_recurring_advanced_month_week_day(data.ResourceName, "Monday", 2), }, + data.ImportStep(), }, }) } @@ -335,7 +282,7 @@ func testCheckAzureRMAutomationScheduleExists(resourceName string) resource.Test } } -func testAccAzureRMAutomationSchedule_prerequisites(rInt int, location string) string { +func testAccAzureRMAutomationSchedule_prerequisites(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -351,10 +298,10 @@ resource "azurerm_automation_account" "test" { name = "Basic" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAutomationSchedule_oneTime_basic(rInt int, location string) string { +func testAccAzureRMAutomationSchedule_oneTime_basic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -364,11 +311,11 @@ resource "azurerm_automation_schedule" "test" { automation_account_name = "${azurerm_automation_account.test.name}" frequency = "OneTime" } -`, testAccAzureRMAutomationSchedule_prerequisites(rInt, location), rInt) +`, testAccAzureRMAutomationSchedule_prerequisites(data), data.RandomInteger) } -func testAccAzureRMAutomationSchedule_requiresImport(rInt int, location string) string { - template := testAccAzureRMAutomationSchedule_oneTime_basic(rInt, location) +func testAccAzureRMAutomationSchedule_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAutomationSchedule_oneTime_basic(data) return fmt.Sprintf(` %s @@ -393,7 +340,7 @@ func checkAccAzureRMAutomationSchedule_oneTime_basic(resourceName string) resour ) } -func testAccAzureRMAutomationSchedule_oneTime_complete(rInt int, location, startTime string) string { +func testAccAzureRMAutomationSchedule_oneTime_complete(data acceptance.TestData, startTime string) string { return fmt.Sprintf(` %s @@ -406,7 +353,7 @@ resource "azurerm_automation_schedule" "test" { timezone = "Central Europe Standard Time" description = "This is an automation schedule" } -`, testAccAzureRMAutomationSchedule_prerequisites(rInt, location), rInt, startTime) +`, testAccAzureRMAutomationSchedule_prerequisites(data), data.RandomInteger, startTime) } func checkAccAzureRMAutomationSchedule_oneTime_complete(resourceName, startTime string) resource.TestCheckFunc { @@ -422,7 +369,7 @@ func checkAccAzureRMAutomationSchedule_oneTime_complete(resourceName, startTime ) } -func testAccAzureRMAutomationSchedule_recurring_basic(rInt int, location, frequency string, interval int) string { +func testAccAzureRMAutomationSchedule_recurring_basic(data acceptance.TestData, frequency string, interval int) string { return fmt.Sprintf(` %s @@ -433,7 +380,7 @@ resource "azurerm_automation_schedule" "test" { frequency = "%s" interval = "%d" } -`, testAccAzureRMAutomationSchedule_prerequisites(rInt, location), rInt, frequency, interval) +`, testAccAzureRMAutomationSchedule_prerequisites(data), data.RandomInteger, frequency, interval) } func checkAccAzureRMAutomationSchedule_recurring_basic(resourceName string, frequency string, interval int) resource.TestCheckFunc { @@ -449,7 +396,7 @@ func checkAccAzureRMAutomationSchedule_recurring_basic(resourceName string, freq ) } -func testAccAzureRMAutomationSchedule_recurring_advanced_week(rInt int, location string, weekDay string) string { +func testAccAzureRMAutomationSchedule_recurring_advanced_week(data acceptance.TestData, weekDay string) string { return fmt.Sprintf(` %s @@ -461,7 +408,7 @@ resource "azurerm_automation_schedule" "test" { interval = "1" week_days = ["%s"] } -`, testAccAzureRMAutomationSchedule_prerequisites(rInt, location), rInt, weekDay) +`, testAccAzureRMAutomationSchedule_prerequisites(data), data.RandomInteger, weekDay) } func checkAccAzureRMAutomationSchedule_recurring_advanced_week(resourceName string) resource.TestCheckFunc { @@ -478,7 +425,7 @@ func checkAccAzureRMAutomationSchedule_recurring_advanced_week(resourceName stri ) } -func testAccAzureRMAutomationSchedule_recurring_advanced_month(rInt int, location string, monthDay int) string { +func testAccAzureRMAutomationSchedule_recurring_advanced_month(data acceptance.TestData, monthDay int) string { return fmt.Sprintf(` %s @@ -490,7 +437,7 @@ resource "azurerm_automation_schedule" "test" { interval = "1" month_days = [%d] } -`, testAccAzureRMAutomationSchedule_prerequisites(rInt, location), rInt, monthDay) +`, testAccAzureRMAutomationSchedule_prerequisites(data), data.RandomInteger, monthDay) } func checkAccAzureRMAutomationSchedule_recurring_advanced_month(resourceName string) resource.TestCheckFunc { @@ -507,7 +454,7 @@ func checkAccAzureRMAutomationSchedule_recurring_advanced_month(resourceName str ) } -func testAccAzureRMAutomationSchedule_recurring_advanced_month_week_day(rInt int, location string, weekDay string, weekDayOccurrence int) string { +func testAccAzureRMAutomationSchedule_recurring_advanced_month_week_day(data acceptance.TestData, weekDay string, weekDayOccurrence int) string { return fmt.Sprintf(` %s @@ -523,7 +470,7 @@ resource "azurerm_automation_schedule" "test" { occurrence = "%d" } } -`, testAccAzureRMAutomationSchedule_prerequisites(rInt, location), rInt, weekDay, weekDayOccurrence) +`, testAccAzureRMAutomationSchedule_prerequisites(data), data.RandomInteger, weekDay, weekDayOccurrence) } func checkAccAzureRMAutomationSchedule_recurring_advanced_month_week_day(resourceName string, monthWeekDay string, monthWeekOccurrence int) resource.TestCheckFunc { diff --git a/azurerm/internal/services/automation/resource_arm_automation_variable_bool_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_variable_bool_test.go similarity index 59% rename from azurerm/internal/services/automation/resource_arm_automation_variable_bool_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_variable_bool_test.go index 59e634dc6abc..def9fe78d6f0 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_variable_bool_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_variable_bool_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -6,14 +6,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMAutomationVariableBool_basic(t *testing.T) { - resourceName := "azurerm_automation_variable_bool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_bool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,25 +18,19 @@ func TestAccAzureRMAutomationVariableBool_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableBoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableBool_basic(ri, location), + Config: testAccAzureRMAutomationVariableBool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableBoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "false"), + testCheckAzureRMAutomationVariableBoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationVariableBool_complete(t *testing.T) { - resourceName := "azurerm_automation_variable_bool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_bool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -47,26 +38,20 @@ func TestAccAzureRMAutomationVariableBool_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableBoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableBool_complete(ri, location), + Config: testAccAzureRMAutomationVariableBool_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableBoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), - resource.TestCheckResourceAttr(resourceName, "value", "true"), + testCheckAzureRMAutomationVariableBoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(data.ResourceName, "value", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationVariableBool_basicCompleteUpdate(t *testing.T) { - resourceName := "azurerm_automation_variable_bool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_bool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,25 +59,25 @@ func TestAccAzureRMAutomationVariableBool_basicCompleteUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableBoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableBool_basic(ri, location), + Config: testAccAzureRMAutomationVariableBool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableBoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "false"), + testCheckAzureRMAutomationVariableBoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "false"), ), }, { - Config: testAccAzureRMAutomationVariableBool_complete(ri, location), + Config: testAccAzureRMAutomationVariableBool_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableBoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), - resource.TestCheckResourceAttr(resourceName, "value", "true"), + testCheckAzureRMAutomationVariableBoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(data.ResourceName, "value", "true"), ), }, { - Config: testAccAzureRMAutomationVariableBool_basic(ri, location), + Config: testAccAzureRMAutomationVariableBool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableBoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "false"), + testCheckAzureRMAutomationVariableBoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "false"), ), }, }, @@ -107,7 +92,7 @@ func testCheckAzureRMAutomationVariableBoolDestroy(s *terraform.State) error { return testCheckAzureRMAutomationVariableDestroy(s, "Bool") } -func testAccAzureRMAutomationVariableBool_basic(rInt int, location string) string { +func testAccAzureRMAutomationVariableBool_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -130,10 +115,10 @@ resource "azurerm_automation_variable_bool" "test" { automation_account_name = "${azurerm_automation_account.test.name}" value = false } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAutomationVariableBool_complete(rInt int, location string) string { +func testAccAzureRMAutomationVariableBool_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -157,5 +142,5 @@ resource "azurerm_automation_variable_bool" "test" { description = "This variable is created by Terraform acceptance test." value = true } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/automation/resource_arm_automation_variable_datetime_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_variable_datetime_test.go similarity index 58% rename from azurerm/internal/services/automation/resource_arm_automation_variable_datetime_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_variable_datetime_test.go index 879afa665c5f..efb0613a105c 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_variable_datetime_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_variable_datetime_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -6,14 +6,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMAutomationVariableDateTime_basic(t *testing.T) { - resourceName := "azurerm_automation_variable_datetime.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_datetime", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,25 +18,19 @@ func TestAccAzureRMAutomationVariableDateTime_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableDateTimeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableDateTime_basic(ri, location), + Config: testAccAzureRMAutomationVariableDateTime_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableDateTimeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "2019-04-24T21:40:54.074Z"), + testCheckAzureRMAutomationVariableDateTimeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "2019-04-24T21:40:54.074Z"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationVariableDateTime_complete(t *testing.T) { - resourceName := "azurerm_automation_variable_datetime.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_datetime", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -47,26 +38,20 @@ func TestAccAzureRMAutomationVariableDateTime_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableDateTimeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableDateTime_complete(ri, location), + Config: testAccAzureRMAutomationVariableDateTime_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableDateTimeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), - resource.TestCheckResourceAttr(resourceName, "value", "2019-04-20T08:40:04.02Z"), + testCheckAzureRMAutomationVariableDateTimeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(data.ResourceName, "value", "2019-04-20T08:40:04.02Z"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationVariableDateTime_basicCompleteUpdate(t *testing.T) { - resourceName := "azurerm_automation_variable_datetime.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_datetime", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,25 +59,25 @@ func TestAccAzureRMAutomationVariableDateTime_basicCompleteUpdate(t *testing.T) CheckDestroy: testCheckAzureRMAutomationVariableDateTimeDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableDateTime_basic(ri, location), + Config: testAccAzureRMAutomationVariableDateTime_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableDateTimeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "2019-04-24T21:40:54.074Z"), + testCheckAzureRMAutomationVariableDateTimeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "2019-04-24T21:40:54.074Z"), ), }, { - Config: testAccAzureRMAutomationVariableDateTime_complete(ri, location), + Config: testAccAzureRMAutomationVariableDateTime_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableDateTimeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), - resource.TestCheckResourceAttr(resourceName, "value", "2019-04-20T08:40:04.02Z"), + testCheckAzureRMAutomationVariableDateTimeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(data.ResourceName, "value", "2019-04-20T08:40:04.02Z"), ), }, { - Config: testAccAzureRMAutomationVariableDateTime_basic(ri, location), + Config: testAccAzureRMAutomationVariableDateTime_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableDateTimeExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "2019-04-24T21:40:54.074Z"), + testCheckAzureRMAutomationVariableDateTimeExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "2019-04-24T21:40:54.074Z"), ), }, }, @@ -107,7 +92,7 @@ func testCheckAzureRMAutomationVariableDateTimeDestroy(s *terraform.State) error return testCheckAzureRMAutomationVariableDestroy(s, "Datetime") } -func testAccAzureRMAutomationVariableDateTime_basic(rInt int, location string) string { +func testAccAzureRMAutomationVariableDateTime_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -130,10 +115,10 @@ resource "azurerm_automation_variable_datetime" "test" { automation_account_name = "${azurerm_automation_account.test.name}" value = "2019-04-24T21:40:54.074Z" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAutomationVariableDateTime_complete(rInt int, location string) string { +func testAccAzureRMAutomationVariableDateTime_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -157,5 +142,5 @@ resource "azurerm_automation_variable_datetime" "test" { description = "This variable is created by Terraform acceptance test." value = "2019-04-20T08:40:04.02Z" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/automation/resource_arm_automation_variable_int_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_variable_int_test.go similarity index 59% rename from azurerm/internal/services/automation/resource_arm_automation_variable_int_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_variable_int_test.go index 90878dd6b1ce..ab4a6b89f343 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_variable_int_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_variable_int_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -6,14 +6,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMAutomationVariableInt_basic(t *testing.T) { - resourceName := "azurerm_automation_variable_int.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_int", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,25 +18,19 @@ func TestAccAzureRMAutomationVariableInt_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableIntDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableInt_basic(ri, location), + Config: testAccAzureRMAutomationVariableInt_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableIntExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "1234"), + testCheckAzureRMAutomationVariableIntExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "1234"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationVariableInt_complete(t *testing.T) { - resourceName := "azurerm_automation_variable_int.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_int", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -47,26 +38,20 @@ func TestAccAzureRMAutomationVariableInt_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableIntDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableInt_complete(ri, location), + Config: testAccAzureRMAutomationVariableInt_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableIntExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), - resource.TestCheckResourceAttr(resourceName, "value", "12345"), + testCheckAzureRMAutomationVariableIntExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(data.ResourceName, "value", "12345"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationVariableInt_basicCompleteUpdate(t *testing.T) { - resourceName := "azurerm_automation_variable_int.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_int", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,25 +59,25 @@ func TestAccAzureRMAutomationVariableInt_basicCompleteUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableIntDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableInt_basic(ri, location), + Config: testAccAzureRMAutomationVariableInt_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableIntExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "1234"), + testCheckAzureRMAutomationVariableIntExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "1234"), ), }, { - Config: testAccAzureRMAutomationVariableInt_complete(ri, location), + Config: testAccAzureRMAutomationVariableInt_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableIntExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), - resource.TestCheckResourceAttr(resourceName, "value", "12345"), + testCheckAzureRMAutomationVariableIntExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(data.ResourceName, "value", "12345"), ), }, { - Config: testAccAzureRMAutomationVariableInt_basic(ri, location), + Config: testAccAzureRMAutomationVariableInt_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableIntExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "1234"), + testCheckAzureRMAutomationVariableIntExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "1234"), ), }, }, @@ -107,7 +92,7 @@ func testCheckAzureRMAutomationVariableIntDestroy(s *terraform.State) error { return testCheckAzureRMAutomationVariableDestroy(s, "Int") } -func testAccAzureRMAutomationVariableInt_basic(rInt int, location string) string { +func testAccAzureRMAutomationVariableInt_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -130,10 +115,10 @@ resource "azurerm_automation_variable_int" "test" { automation_account_name = "${azurerm_automation_account.test.name}" value = 1234 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAutomationVariableInt_complete(rInt int, location string) string { +func testAccAzureRMAutomationVariableInt_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -157,5 +142,5 @@ resource "azurerm_automation_variable_int" "test" { description = "This variable is created by Terraform acceptance test." value = 12345 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/automation/resource_arm_automation_variable_string_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_variable_string_test.go similarity index 58% rename from azurerm/internal/services/automation/resource_arm_automation_variable_string_test.go rename to azurerm/internal/services/automation/tests/resource_arm_automation_variable_string_test.go index 3d5d88814b63..6dbddc3747da 100644 --- a/azurerm/internal/services/automation/resource_arm_automation_variable_string_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_variable_string_test.go @@ -1,4 +1,4 @@ -package automation +package tests import ( "fmt" @@ -6,14 +6,11 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMAutomationVariableString_basic(t *testing.T) { - resourceName := "azurerm_automation_variable_string.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_string", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,25 +18,19 @@ func TestAccAzureRMAutomationVariableString_basic(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableStringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableString_basic(ri, location), + Config: testAccAzureRMAutomationVariableString_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableStringExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Basic Test."), + testCheckAzureRMAutomationVariableStringExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "Hello, Terraform Basic Test."), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationVariableString_complete(t *testing.T) { - resourceName := "azurerm_automation_variable_string.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_string", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -47,26 +38,20 @@ func TestAccAzureRMAutomationVariableString_complete(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableStringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableString_complete(ri, location), + Config: testAccAzureRMAutomationVariableString_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableStringExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), - resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Complete Test."), + testCheckAzureRMAutomationVariableStringExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(data.ResourceName, "value", "Hello, Terraform Complete Test."), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMAutomationVariableString_basicCompleteUpdate(t *testing.T) { - resourceName := "azurerm_automation_variable_string.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_automation_variable_string", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,25 +59,25 @@ func TestAccAzureRMAutomationVariableString_basicCompleteUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMAutomationVariableStringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationVariableString_basic(ri, location), + Config: testAccAzureRMAutomationVariableString_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableStringExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Basic Test."), + testCheckAzureRMAutomationVariableStringExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "Hello, Terraform Basic Test."), ), }, { - Config: testAccAzureRMAutomationVariableString_complete(ri, location), + Config: testAccAzureRMAutomationVariableString_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableStringExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "description", "This variable is created by Terraform acceptance test."), - resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Complete Test."), + testCheckAzureRMAutomationVariableStringExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "description", "This variable is created by Terraform acceptance test."), + resource.TestCheckResourceAttr(data.ResourceName, "value", "Hello, Terraform Complete Test."), ), }, { - Config: testAccAzureRMAutomationVariableString_basic(ri, location), + Config: testAccAzureRMAutomationVariableString_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationVariableStringExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "value", "Hello, Terraform Basic Test."), + testCheckAzureRMAutomationVariableStringExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "value", "Hello, Terraform Basic Test."), ), }, }, @@ -107,7 +92,7 @@ func testCheckAzureRMAutomationVariableStringDestroy(s *terraform.State) error { return testCheckAzureRMAutomationVariableDestroy(s, "String") } -func testAccAzureRMAutomationVariableString_basic(rInt int, location string) string { +func testAccAzureRMAutomationVariableString_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -130,10 +115,10 @@ resource "azurerm_automation_variable_string" "test" { automation_account_name = "${azurerm_automation_account.test.name}" value = "Hello, Terraform Basic Test." } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMAutomationVariableString_complete(rInt int, location string) string { +func testAccAzureRMAutomationVariableString_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -157,5 +142,5 @@ resource "azurerm_automation_variable_string" "test" { description = "This variable is created by Terraform acceptance test." value = "Hello, Terraform Complete Test." } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/automation/testdata/automation_certificate_test.pfx b/azurerm/internal/services/automation/tests/testdata/automation_certificate_test.pfx similarity index 100% rename from azurerm/internal/services/automation/testdata/automation_certificate_test.pfx rename to azurerm/internal/services/automation/tests/testdata/automation_certificate_test.pfx diff --git a/azurerm/internal/services/automation/testdata/automation_certificate_test.thumb b/azurerm/internal/services/automation/tests/testdata/automation_certificate_test.thumb similarity index 100% rename from azurerm/internal/services/automation/testdata/automation_certificate_test.thumb rename to azurerm/internal/services/automation/tests/testdata/automation_certificate_test.thumb diff --git a/azurerm/internal/services/automation/testdata/automation_certificate_testdata.sh b/azurerm/internal/services/automation/tests/testdata/automation_certificate_testdata.sh similarity index 100% rename from azurerm/internal/services/automation/testdata/automation_certificate_testdata.sh rename to azurerm/internal/services/automation/tests/testdata/automation_certificate_testdata.sh diff --git a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go index 69f831a58b63..473e3f224466 100644 --- a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_access_policy_test.go @@ -11,7 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) diff --git a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_migration_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_migration_test.go index 39d845b89ad1..97a6998d2bf2 100644 --- a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_migration_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_migration_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault" ) func TestAzureRMKeyVaultMigrateState(t *testing.T) { diff --git a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go index 37ff79b1efa5..1fc99cc8d0ff 100644 --- a/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go +++ b/azurerm/internal/services/keyvault/tests/resource_arm_key_vault_test.go @@ -11,7 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) From e37031d89eca8ad1871da271c8af4f700cd195b5 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 20:06:46 +0100 Subject: [PATCH 136/203] hdinsight: porting over to the new test helper --- azurerm/internal/acceptance/data.go | 8 +- azurerm/internal/acceptance/steps.go | 2 +- .../data_source_hdinsight_cluster_test.go | 300 ---------- .../{ => tests}/common_hdinsight_test.go | 2 +- .../data_source_hdinsight_cluster_test.go | 266 +++++++++ ...ource_arm_hdinsight_hadoop_cluster_test.go | 518 +++++++----------- ...source_arm_hdinsight_hbase_cluster_test.go | 325 ++++------- ...dinsight_interactive_query_cluster_test.go | 325 ++++------- ...source_arm_hdinsight_kafka_cluster_test.go | 322 ++++------- ..._arm_hdinsight_ml_services_cluster_test.go | 316 +++++------ ...urce_arm_hdinsight_rserver_cluster_test.go | 316 +++++------ ...source_arm_hdinsight_spark_cluster_test.go | 325 ++++------- ...source_arm_hdinsight_storm_cluster_test.go | 279 ++++------ 13 files changed, 1298 insertions(+), 2006 deletions(-) delete mode 100644 azurerm/internal/services/hdinsight/data_source_hdinsight_cluster_test.go rename azurerm/internal/services/hdinsight/{ => tests}/common_hdinsight_test.go (99%) create mode 100644 azurerm/internal/services/hdinsight/tests/data_source_hdinsight_cluster_test.go rename azurerm/internal/services/hdinsight/{ => tests}/resource_arm_hdinsight_hadoop_cluster_test.go (58%) rename azurerm/internal/services/hdinsight/{ => tests}/resource_arm_hdinsight_hbase_cluster_test.go (61%) rename azurerm/internal/services/hdinsight/{ => tests}/resource_arm_hdinsight_interactive_query_cluster_test.go (66%) rename azurerm/internal/services/hdinsight/{ => tests}/resource_arm_hdinsight_kafka_cluster_test.go (63%) rename azurerm/internal/services/hdinsight/{ => tests}/resource_arm_hdinsight_ml_services_cluster_test.go (59%) rename azurerm/internal/services/hdinsight/{ => tests}/resource_arm_hdinsight_rserver_cluster_test.go (59%) rename azurerm/internal/services/hdinsight/{ => tests}/resource_arm_hdinsight_spark_cluster_test.go (61%) rename azurerm/internal/services/hdinsight/{ => tests}/resource_arm_hdinsight_storm_cluster_test.go (60%) diff --git a/azurerm/internal/acceptance/data.go b/azurerm/internal/acceptance/data.go index 82535c9307ef..c0b9df10df51 100644 --- a/azurerm/internal/acceptance/data.go +++ b/azurerm/internal/acceptance/data.go @@ -29,6 +29,9 @@ type TestData struct { // e.g. `azurerm_resource_group.test` ResourceName string + // ResourceType is the Terraform Resource Type - `azurerm_resource_group` + ResourceType string + // Environment is a struct containing Details about the Azure Environment // that we're running against Environment azure.Environment @@ -36,9 +39,6 @@ type TestData struct { // EnvironmentName is the name of the Azure Environment where we're running EnvironmentName string - // resourceType is the Terraform Resource Type - `azurerm_resource_group` - resourceType string - // resourceLabel is the local used for the resource - generally "test"" resourceLabel string } @@ -65,7 +65,7 @@ func BuildTestData(t *testing.T, resourceType string, resourceLabel string) Test Environment: *env, EnvironmentName: EnvironmentName(), - resourceType: resourceType, + ResourceType: resourceType, resourceLabel: resourceLabel, } diff --git a/azurerm/internal/acceptance/steps.go b/azurerm/internal/acceptance/steps.go index 38aae55d0a49..e6621f46b1f2 100644 --- a/azurerm/internal/acceptance/steps.go +++ b/azurerm/internal/acceptance/steps.go @@ -53,6 +53,6 @@ func (td TestData) RequiresImportErrorStep(configBuilder func(data TestData) str config := configBuilder(td) return resource.TestStep{ Config: config, - ExpectError: RequiresImportError(td.resourceType), + ExpectError: RequiresImportError(td.ResourceType), } } diff --git a/azurerm/internal/services/hdinsight/data_source_hdinsight_cluster_test.go b/azurerm/internal/services/hdinsight/data_source_hdinsight_cluster_test.go deleted file mode 100644 index 1bf50986cd25..000000000000 --- a/azurerm/internal/services/hdinsight/data_source_hdinsight_cluster_test.go +++ /dev/null @@ -1,300 +0,0 @@ -package hdinsight - -import ( - "fmt" - "strings" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMHDInsightCluster_hadoop(t *testing.T) { - dataSourceName := "data.azurerm_hdinsight_cluster.test" - rInt := tf.AccRandTimeInt() - rString := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceHDInsightCluster_hadoop(rInt, rString, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "hadoop"), - resource.TestCheckResourceAttr(dataSourceName, "tier", "standard"), - resource.TestCheckResourceAttr(dataSourceName, "edge_ssh_endpoint", ""), - resource.TestCheckResourceAttrSet(dataSourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(dataSourceName, "ssh_endpoint"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMHDInsightCluster_hbase(t *testing.T) { - dataSourceName := "data.azurerm_hdinsight_cluster.test" - rInt := tf.AccRandTimeInt() - rString := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceHDInsightCluster_hbase(rInt, rString, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "hbase"), - resource.TestCheckResourceAttr(dataSourceName, "tier", "standard"), - resource.TestCheckResourceAttr(dataSourceName, "edge_ssh_endpoint", ""), - resource.TestCheckResourceAttrSet(dataSourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(dataSourceName, "ssh_endpoint"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMHDInsightCluster_interactiveQuery(t *testing.T) { - dataSourceName := "data.azurerm_hdinsight_cluster.test" - rInt := tf.AccRandTimeInt() - rString := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceHDInsightCluster_interactiveQuery(rInt, rString, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "interactivehive"), - resource.TestCheckResourceAttr(dataSourceName, "tier", "standard"), - resource.TestCheckResourceAttr(dataSourceName, "edge_ssh_endpoint", ""), - resource.TestCheckResourceAttrSet(dataSourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(dataSourceName, "ssh_endpoint"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMHDInsightCluster_kafka(t *testing.T) { - dataSourceName := "data.azurerm_hdinsight_cluster.test" - rInt := tf.AccRandTimeInt() - rString := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceHDInsightCluster_kafka(rInt, rString, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "kafka"), - resource.TestCheckResourceAttr(dataSourceName, "tier", "standard"), - resource.TestCheckResourceAttr(dataSourceName, "edge_ssh_endpoint", ""), - resource.TestCheckResourceAttrSet(dataSourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(dataSourceName, "ssh_endpoint"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMHDInsightCluster_mlServices(t *testing.T) { - dataSourceName := "data.azurerm_hdinsight_cluster.test" - rInt := tf.AccRandTimeInt() - rString := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceHDInsightCluster_mlServices(rInt, rString, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "mlservices"), - resource.TestCheckResourceAttr(dataSourceName, "tier", "standard"), - resource.TestCheckResourceAttrSet(dataSourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(dataSourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(dataSourceName, "ssh_endpoint"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMHDInsightCluster_rserver(t *testing.T) { - dataSourceName := "data.azurerm_hdinsight_cluster.test" - rInt := tf.AccRandTimeInt() - rString := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceHDInsightCluster_rserver(rInt, rString, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "rserver"), - resource.TestCheckResourceAttr(dataSourceName, "tier", "standard"), - resource.TestCheckResourceAttrSet(dataSourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(dataSourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(dataSourceName, "ssh_endpoint"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMHDInsightCluster_spark(t *testing.T) { - dataSourceName := "data.azurerm_hdinsight_cluster.test" - rInt := tf.AccRandTimeInt() - rString := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceHDInsightCluster_spark(rInt, rString, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "spark"), - resource.TestCheckResourceAttr(dataSourceName, "tier", "standard"), - resource.TestCheckResourceAttr(dataSourceName, "edge_ssh_endpoint", ""), - resource.TestCheckResourceAttrSet(dataSourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(dataSourceName, "ssh_endpoint"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMHDInsightCluster_storm(t *testing.T) { - dataSourceName := "data.azurerm_hdinsight_cluster.test" - rInt := tf.AccRandTimeInt() - rString := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceHDInsightCluster_storm(rInt, rString, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "kind", "storm"), - resource.TestCheckResourceAttr(dataSourceName, "tier", "standard"), - resource.TestCheckResourceAttr(dataSourceName, "edge_ssh_endpoint", ""), - resource.TestCheckResourceAttrSet(dataSourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(dataSourceName, "ssh_endpoint"), - ), - }, - }, - }) -} - -func testAccDataSourceHDInsightCluster_hadoop(rInt int, rString, location string) string { - template := testAccAzureRMHDInsightHadoopCluster_basic(rInt, rString, location) - return fmt.Sprintf(` -%s - -data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_hadoop_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_hadoop_cluster.test.resource_group_name}" -} -`, template) -} - -func testAccDataSourceHDInsightCluster_hbase(rInt int, rString, location string) string { - template := testAccAzureRMHDInsightHBaseCluster_basic(rInt, rString, location) - return fmt.Sprintf(` -%s - -data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_hbase_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_hbase_cluster.test.resource_group_name}" -} -`, template) -} - -func testAccDataSourceHDInsightCluster_interactiveQuery(rInt int, rString, location string) string { - template := testAccAzureRMHDInsightInteractiveQueryCluster_basic(rInt, rString, location) - return fmt.Sprintf(` -%s - -data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_interactive_query_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_interactive_query_cluster.test.resource_group_name}" -} -`, template) -} - -func testAccDataSourceHDInsightCluster_kafka(rInt int, rString, location string) string { - template := testAccAzureRMHDInsightKafkaCluster_basic(rInt, rString, location) - return fmt.Sprintf(` -%s - -data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_kafka_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_kafka_cluster.test.resource_group_name}" -} -`, template) -} - -func testAccDataSourceHDInsightCluster_mlServices(rInt int, rString, location string) string { - template := testAccAzureRMHDInsightMLServicesCluster_basic(rInt, rString, location) - return fmt.Sprintf(` -%s - -data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_ml_services_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_ml_services_cluster.test.resource_group_name}" -} -`, template) -} - -func testAccDataSourceHDInsightCluster_rserver(rInt int, rString, location string) string { - template := testAccAzureRMHDInsightRServerCluster_basic(rInt, rString, location) - return fmt.Sprintf(` -%s - -data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_rserver_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_rserver_cluster.test.resource_group_name}" -} -`, template) -} - -func testAccDataSourceHDInsightCluster_spark(rInt int, rString, location string) string { - template := testAccAzureRMHDInsightSparkCluster_basic(rInt, rString, location) - return fmt.Sprintf(` -%s - -data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_spark_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_spark_cluster.test.resource_group_name}" -} -`, template) -} - -func testAccDataSourceHDInsightCluster_storm(rInt int, rString, location string) string { - template := testAccAzureRMHDInsightStormCluster_basic(rInt, rString, location) - return fmt.Sprintf(` -%s - -data "azurerm_hdinsight_cluster" "test" { - name = "${azurerm_hdinsight_storm_cluster.test.name}" - resource_group_name = "${azurerm_hdinsight_storm_cluster.test.resource_group_name}" -} -`, template) -} diff --git a/azurerm/internal/services/hdinsight/common_hdinsight_test.go b/azurerm/internal/services/hdinsight/tests/common_hdinsight_test.go similarity index 99% rename from azurerm/internal/services/hdinsight/common_hdinsight_test.go rename to azurerm/internal/services/hdinsight/tests/common_hdinsight_test.go index 78160267018c..3b0c9881c16d 100644 --- a/azurerm/internal/services/hdinsight/common_hdinsight_test.go +++ b/azurerm/internal/services/hdinsight/tests/common_hdinsight_test.go @@ -1,4 +1,4 @@ -package hdinsight +package tests import ( "fmt" diff --git a/azurerm/internal/services/hdinsight/tests/data_source_hdinsight_cluster_test.go b/azurerm/internal/services/hdinsight/tests/data_source_hdinsight_cluster_test.go new file mode 100644 index 000000000000..48070e77d440 --- /dev/null +++ b/azurerm/internal/services/hdinsight/tests/data_source_hdinsight_cluster_test.go @@ -0,0 +1,266 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMHDInsightCluster_hadoop(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_hdinsight_cluster", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceHDInsightCluster_hadoop(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "kind", "hadoop"), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "standard"), + resource.TestCheckResourceAttr(data.ResourceName, "edge_ssh_endpoint", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMHDInsightCluster_hbase(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_hdinsight_cluster", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceHDInsightCluster_hbase(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "kind", "hbase"), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "standard"), + resource.TestCheckResourceAttr(data.ResourceName, "edge_ssh_endpoint", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMHDInsightCluster_interactiveQuery(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_hdinsight_cluster", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceHDInsightCluster_interactiveQuery(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "kind", "interactivehive"), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "standard"), + resource.TestCheckResourceAttr(data.ResourceName, "edge_ssh_endpoint", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMHDInsightCluster_kafka(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_hdinsight_cluster", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceHDInsightCluster_kafka(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "kind", "kafka"), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "standard"), + resource.TestCheckResourceAttr(data.ResourceName, "edge_ssh_endpoint", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMHDInsightCluster_mlServices(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_hdinsight_cluster", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceHDInsightCluster_mlServices(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "kind", "mlservices"), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "standard"), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMHDInsightCluster_rserver(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_hdinsight_cluster", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceHDInsightCluster_rserver(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "kind", "rserver"), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "standard"), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMHDInsightCluster_spark(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_hdinsight_cluster", "test") + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceHDInsightCluster_spark(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "kind", "spark"), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "standard"), + resource.TestCheckResourceAttr(data.ResourceName, "edge_ssh_endpoint", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMHDInsightCluster_storm(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_hdinsight_cluster", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceHDInsightCluster_storm(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "kind", "storm"), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "standard"), + resource.TestCheckResourceAttr(data.ResourceName, "edge_ssh_endpoint", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), + ), + }, + }, + }) +} + +func testAccDataSourceHDInsightCluster_hadoop(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHadoopCluster_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_hdinsight_cluster" "test" { + name = "${azurerm_hdinsight_hadoop_cluster.test.name}" + resource_group_name = "${azurerm_hdinsight_hadoop_cluster.test.resource_group_name}" +} +`, template) +} + +func testAccDataSourceHDInsightCluster_hbase(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHBaseCluster_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_hdinsight_cluster" "test" { + name = "${azurerm_hdinsight_hbase_cluster.test.name}" + resource_group_name = "${azurerm_hdinsight_hbase_cluster.test.resource_group_name}" +} +`, template) +} + +func testAccDataSourceHDInsightCluster_interactiveQuery(data acceptance.TestData) string { + template := testAccAzureRMHDInsightInteractiveQueryCluster_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_hdinsight_cluster" "test" { + name = "${azurerm_hdinsight_interactive_query_cluster.test.name}" + resource_group_name = "${azurerm_hdinsight_interactive_query_cluster.test.resource_group_name}" +} +`, template) +} + +func testAccDataSourceHDInsightCluster_kafka(data acceptance.TestData) string { + template := testAccAzureRMHDInsightKafkaCluster_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_hdinsight_cluster" "test" { + name = "${azurerm_hdinsight_kafka_cluster.test.name}" + resource_group_name = "${azurerm_hdinsight_kafka_cluster.test.resource_group_name}" +} +`, template) +} + +func testAccDataSourceHDInsightCluster_mlServices(data acceptance.TestData) string { + template := testAccAzureRMHDInsightMLServicesCluster_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_hdinsight_cluster" "test" { + name = "${azurerm_hdinsight_ml_services_cluster.test.name}" + resource_group_name = "${azurerm_hdinsight_ml_services_cluster.test.resource_group_name}" +} +`, template) +} + +func testAccDataSourceHDInsightCluster_rserver(data acceptance.TestData) string { + template := testAccAzureRMHDInsightRServerCluster_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_hdinsight_cluster" "test" { + name = "${azurerm_hdinsight_rserver_cluster.test.name}" + resource_group_name = "${azurerm_hdinsight_rserver_cluster.test.resource_group_name}" +} +`, template) +} + +func testAccDataSourceHDInsightCluster_spark(data acceptance.TestData) string { + template := testAccAzureRMHDInsightSparkCluster_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_hdinsight_cluster" "test" { + name = "${azurerm_hdinsight_spark_cluster.test.name}" + resource_group_name = "${azurerm_hdinsight_spark_cluster.test.resource_group_name}" +} +`, template) +} + +func testAccDataSourceHDInsightCluster_storm(data acceptance.TestData) string { + template := testAccAzureRMHDInsightStormCluster_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_hdinsight_cluster" "test" { + name = "${azurerm_hdinsight_storm_cluster.test.name}" + resource_group_name = "${azurerm_hdinsight_storm_cluster.test.resource_group_name}" +} +`, template) +} diff --git a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hadoop_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hadoop_cluster_test.go similarity index 58% rename from azurerm/internal/services/hdinsight/resource_arm_hdinsight_hadoop_cluster_test.go rename to azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hadoop_cluster_test.go index ac4b233cd901..a659d564c1c4 100644 --- a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hadoop_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hadoop_cluster_test.go @@ -1,50 +1,36 @@ -package hdinsight +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMHDInsightHadoopCluster_basic(t *testing.T) { - resourceName := "azurerm_hdinsight_hadoop_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hadoop_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHadoopCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightHadoopCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } @@ -55,402 +41,286 @@ func TestAccAzureRMHDInsightHadoopCluster_requiresImport(t *testing.T) { return } - resourceName := "azurerm_hdinsight_hadoop_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hadoop_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHadoopCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightHadoopCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - Config: testAccAzureRMHDInsightHadoopCluster_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_hdinsight_hadoop_cluster"), - }, + data.RequiresImportErrorStep(testAccAzureRMHDInsightHadoopCluster_requiresImport), }, }) } func TestAccAzureRMHDInsightHadoopCluster_update(t *testing.T) { - resourceName := "azurerm_hdinsight_hadoop_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hadoop_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHadoopCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightHadoopCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, - { - Config: testAccAzureRMHDInsightHadoopCluster_updated(ri, rs, location), + Config: testAccAzureRMHDInsightHadoopCluster_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightHadoopCluster_sshKeys(t *testing.T) { - resourceName := "azurerm_hdinsight_hadoop_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hadoop_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHadoopCluster_sshKeys(ri, rs, location), + Config: testAccAzureRMHDInsightHadoopCluster_sshKeys(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "storage_account", - "roles.0.head_node.0.ssh_keys", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.ssh_keys", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.ssh_keys", - "roles.0.zookeeper_node.0.vm_size", - }, - }, + data.ImportStep("storage_account", + "roles.0.head_node.0.ssh_keys", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.ssh_keys", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.ssh_keys", + "roles.0.zookeeper_node.0.vm_size"), }, }) } func TestAccAzureRMHDInsightHadoopCluster_virtualNetwork(t *testing.T) { - resourceName := "azurerm_hdinsight_hadoop_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hadoop_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHadoopCluster_virtualNetwork(ri, rs, location), + Config: testAccAzureRMHDInsightHadoopCluster_virtualNetwork(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightHadoopCluster_complete(t *testing.T) { - resourceName := "azurerm_hdinsight_hadoop_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hadoop_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHadoopCluster_complete(ri, rs, location), + Config: testAccAzureRMHDInsightHadoopCluster_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(t *testing.T) { - resourceName := "azurerm_hdinsight_hadoop_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hadoop_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(ri, rs, location, 2, "Standard_D3_V2"), + Config: testAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(data, 2, "Standard_D3_V2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightHadoopCluster_addEdgeNodeBasic(t *testing.T) { - resourceName := "azurerm_hdinsight_hadoop_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hadoop_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHadoopCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightHadoopCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, - { - Config: testAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(ri, rs, location, 1, "Standard_D3_V2"), + Config: testAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(data, 1, "Standard_D3_V2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, - { - Config: testAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(ri, rs, location, 3, "Standard_D4_V2"), + Config: testAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(data, 3, "Standard_D4_V2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightHadoopCluster_gen2storage(t *testing.T) { - resourceName := "azurerm_hdinsight_hadoop_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hadoop_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHadoopCluster_gen2storage(ri, rs, location), + Config: testAccAzureRMHDInsightHadoopCluster_gen2storage(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightHadoopCluster_gen2AndBlobStorage(t *testing.T) { - resourceName := "azurerm_hdinsight_hadoop_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hadoop_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hadoop_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHadoopCluster_gen2AndBlobStorage(ri, rs, location), + Config: testAccAzureRMHDInsightHadoopCluster_gen2AndBlobStorage(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } -func testAccAzureRMHDInsightHadoopCluster_basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHadoopCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHadoopCluster_basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHadoopCluster_template(data) return fmt.Sprintf(` %s @@ -498,11 +368,11 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightHadoopCluster_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHadoopCluster_basic(rInt, rString, location) +func testAccAzureRMHDInsightHadoopCluster_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHadoopCluster_basic(data) return fmt.Sprintf(` %s @@ -520,8 +390,8 @@ resource "azurerm_hdinsight_hadoop_cluster" "import" { `, template) } -func testAccAzureRMHDInsightHadoopCluster_sshKeys(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHadoopCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHadoopCluster_sshKeys(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHadoopCluster_template(data) return fmt.Sprintf(` %s @@ -573,11 +443,11 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightHadoopCluster_updated(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHadoopCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHadoopCluster_updated(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHadoopCluster_template(data) return fmt.Sprintf(` %s @@ -629,11 +499,11 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightHadoopCluster_virtualNetwork(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHadoopCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHadoopCluster_virtualNetwork(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHadoopCluster_template(data) return fmt.Sprintf(` %s @@ -701,11 +571,11 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightHadoopCluster_complete(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHadoopCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHadoopCluster_complete(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHadoopCluster_template(data) return fmt.Sprintf(` %s @@ -777,11 +647,11 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { Hello = "World" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(rInt int, rString string, location string, numEdgeNodes int, instanceType string) string { - template := testAccAzureRMHDInsightHadoopCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(data acceptance.TestData, numEdgeNodes int, instanceType string) string { + template := testAccAzureRMHDInsightHadoopCluster_template(data) return fmt.Sprintf(` %s @@ -838,11 +708,11 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } } } -`, template, rInt, numEdgeNodes, instanceType) +`, template, data.RandomInteger, numEdgeNodes, instanceType) } -func testAccAzureRMHDInsightHadoopCluster_gen2storage(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHadoopCluster_gen2template(rInt, rString, location) +func testAccAzureRMHDInsightHadoopCluster_gen2storage(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHadoopCluster_gen2template(data) return fmt.Sprintf(` %s resource "azurerm_hdinsight_hadoop_cluster" "test" { @@ -886,11 +756,11 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightHadoopCluster_gen2AndBlobStorage(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHadoopCluster_gen2template(rInt, rString, location) +func testAccAzureRMHDInsightHadoopCluster_gen2AndBlobStorage(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHadoopCluster_gen2template(data) return fmt.Sprintf(` %s @@ -954,10 +824,10 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" { } } } -`, template, rString, rInt) +`, template, data.RandomString, data.RandomInteger) } -func testAccAzureRMHDInsightHadoopCluster_template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightHadoopCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -978,10 +848,10 @@ resource "azurerm_storage_container" "test" { container_access_type = "private" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMHDInsightHadoopCluster_gen2template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightHadoopCluster_gen2template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1019,5 +889,5 @@ resource "azurerm_role_assignment" "test" { principal_id = "${azurerm_user_assigned_identity.test.principal_id}" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hbase_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hbase_cluster_test.go similarity index 61% rename from azurerm/internal/services/hdinsight/resource_arm_hdinsight_hbase_cluster_test.go rename to azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hbase_cluster_test.go index d7f7b42cf93c..d7e4fb404ff0 100644 --- a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_hbase_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_hbase_cluster_test.go @@ -1,87 +1,62 @@ -package hdinsight +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMHDInsightHBaseCluster_basic(t *testing.T) { - resourceName := "azurerm_hdinsight_hbase_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hbase_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hbase_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHBaseCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightHBaseCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightHBaseCluster_gen2basic(t *testing.T) { - resourceName := "azurerm_hdinsight_hbase_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hbase_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hbase_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHBaseCluster_gen2basic(ri, rs, location), + Config: testAccAzureRMHDInsightHBaseCluster_gen2basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } @@ -92,204 +67,146 @@ func TestAccAzureRMHDInsightHBaseCluster_requiresImport(t *testing.T) { return } - resourceName := "azurerm_hdinsight_hbase_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hbase_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hbase_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHBaseCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightHBaseCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - Config: testAccAzureRMHDInsightHBaseCluster_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_hdinsight_hbase_cluster"), - }, + data.RequiresImportErrorStep(testAccAzureRMHDInsightHBaseCluster_requiresImport), }, }) } func TestAccAzureRMHDInsightHBaseCluster_update(t *testing.T) { - resourceName := "azurerm_hdinsight_hbase_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hbase_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hbase_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHBaseCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightHBaseCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, - { - Config: testAccAzureRMHDInsightHBaseCluster_updated(ri, rs, location), + Config: testAccAzureRMHDInsightHBaseCluster_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightHBaseCluster_sshKeys(t *testing.T) { - resourceName := "azurerm_hdinsight_hbase_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hbase_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hbase_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHBaseCluster_sshKeys(ri, rs, location), + Config: testAccAzureRMHDInsightHBaseCluster_sshKeys(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "storage_account", - "roles.0.head_node.0.ssh_keys", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.ssh_keys", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.ssh_keys", - "roles.0.zookeeper_node.0.vm_size", - }, - }, + data.ImportStep("storage_account", + "roles.0.head_node.0.ssh_keys", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.ssh_keys", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.ssh_keys", + "roles.0.zookeeper_node.0.vm_size"), }, }) } func TestAccAzureRMHDInsightHBaseCluster_virtualNetwork(t *testing.T) { - resourceName := "azurerm_hdinsight_hbase_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hbase_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hbase_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHBaseCluster_virtualNetwork(ri, rs, location), + Config: testAccAzureRMHDInsightHBaseCluster_virtualNetwork(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightHBaseCluster_complete(t *testing.T) { - resourceName := "azurerm_hdinsight_hbase_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_hbase_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_hbase_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightHBaseCluster_complete(ri, rs, location), + Config: testAccAzureRMHDInsightHBaseCluster_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } -func testAccAzureRMHDInsightHBaseCluster_basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHBaseCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHBaseCluster_basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHBaseCluster_template(data) return fmt.Sprintf(` %s @@ -337,11 +254,11 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightHBaseCluster_gen2basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHBaseCluster_gen2template(rInt, rString, location) +func testAccAzureRMHDInsightHBaseCluster_gen2basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHBaseCluster_gen2template(data) return fmt.Sprintf(` %s @@ -390,11 +307,11 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightHBaseCluster_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHBaseCluster_basic(rInt, rString, location) +func testAccAzureRMHDInsightHBaseCluster_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHBaseCluster_basic(data) return fmt.Sprintf(` %s @@ -412,8 +329,8 @@ resource "azurerm_hdinsight_hbase_cluster" "import" { `, template) } -func testAccAzureRMHDInsightHBaseCluster_sshKeys(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHBaseCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHBaseCluster_sshKeys(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHBaseCluster_template(data) return fmt.Sprintf(` %s @@ -465,11 +382,11 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightHBaseCluster_updated(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHBaseCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHBaseCluster_updated(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHBaseCluster_template(data) return fmt.Sprintf(` %s @@ -521,11 +438,11 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightHBaseCluster_virtualNetwork(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHBaseCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHBaseCluster_virtualNetwork(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHBaseCluster_template(data) return fmt.Sprintf(` %s @@ -593,11 +510,11 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightHBaseCluster_complete(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightHBaseCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightHBaseCluster_complete(data acceptance.TestData) string { + template := testAccAzureRMHDInsightHBaseCluster_template(data) return fmt.Sprintf(` %s @@ -669,10 +586,10 @@ resource "azurerm_hdinsight_hbase_cluster" "test" { Hello = "World" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightHBaseCluster_template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightHBaseCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -693,10 +610,10 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMHDInsightHBaseCluster_gen2template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightHBaseCluster_gen2template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -734,5 +651,5 @@ resource "azurerm_role_assignment" "test" { role_definition_name = "Storage Blob Data Owner" principal_id = "${azurerm_user_assigned_identity.test.principal_id}" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_interactive_query_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_interactive_query_cluster_test.go similarity index 66% rename from azurerm/internal/services/hdinsight/resource_arm_hdinsight_interactive_query_cluster_test.go rename to azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_interactive_query_cluster_test.go index dc76dd69c6a9..80adb0a0e264 100644 --- a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_interactive_query_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_interactive_query_cluster_test.go @@ -1,87 +1,62 @@ -package hdinsight +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMHDInsightInteractiveQueryCluster_basic(t *testing.T) { - resourceName := "azurerm_hdinsight_interactive_query_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_interactive_query_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_interactive_query_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightInteractiveQueryCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightInteractiveQueryCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightInteractiveQueryCluster_gen2basic(t *testing.T) { - resourceName := "azurerm_hdinsight_interactive_query_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_interactive_query_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_interactive_query_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightInteractiveQueryCluster_gen2basic(ri, rs, location), + Config: testAccAzureRMHDInsightInteractiveQueryCluster_gen2basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } @@ -92,204 +67,146 @@ func TestAccAzureRMHDInsightInteractiveQueryCluster_requiresImport(t *testing.T) return } - resourceName := "azurerm_hdinsight_interactive_query_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_interactive_query_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_interactive_query_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightInteractiveQueryCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightInteractiveQueryCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - Config: testAccAzureRMHDInsightInteractiveQueryCluster_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_hdinsight_interactive_query_cluster"), - }, + data.RequiresImportErrorStep(testAccAzureRMHDInsightInteractiveQueryCluster_requiresImport), }, }) } func TestAccAzureRMHDInsightInteractiveQueryCluster_update(t *testing.T) { - resourceName := "azurerm_hdinsight_interactive_query_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_interactive_query_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_interactive_query_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightInteractiveQueryCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightInteractiveQueryCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, - { - Config: testAccAzureRMHDInsightInteractiveQueryCluster_updated(ri, rs, location), + Config: testAccAzureRMHDInsightInteractiveQueryCluster_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightInteractiveQueryCluster_sshKeys(t *testing.T) { - resourceName := "azurerm_hdinsight_interactive_query_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_interactive_query_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_interactive_query_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightInteractiveQueryCluster_sshKeys(ri, rs, location), + Config: testAccAzureRMHDInsightInteractiveQueryCluster_sshKeys(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "storage_account", - "roles.0.head_node.0.ssh_keys", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.ssh_keys", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.ssh_keys", - "roles.0.zookeeper_node.0.vm_size", - }, - }, + data.ImportStep("storage_account", + "roles.0.head_node.0.ssh_keys", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.ssh_keys", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.ssh_keys", + "roles.0.zookeeper_node.0.vm_size"), }, }) } func TestAccAzureRMHDInsightInteractiveQueryCluster_virtualNetwork(t *testing.T) { - resourceName := "azurerm_hdinsight_interactive_query_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_interactive_query_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_interactive_query_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightInteractiveQueryCluster_virtualNetwork(ri, rs, location), + Config: testAccAzureRMHDInsightInteractiveQueryCluster_virtualNetwork(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightInteractiveQueryCluster_complete(t *testing.T) { - resourceName := "azurerm_hdinsight_interactive_query_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_interactive_query_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_interactive_query_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightInteractiveQueryCluster_complete(ri, rs, location), + Config: testAccAzureRMHDInsightInteractiveQueryCluster_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } -func testAccAzureRMHDInsightInteractiveQueryCluster_basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightInteractiveQueryCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightInteractiveQueryCluster_basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightInteractiveQueryCluster_template(data) return fmt.Sprintf(` %s @@ -337,11 +254,11 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightInteractiveQueryCluster_gen2basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightInteractiveQueryCluster_gen2template(rInt, rString, location) +func testAccAzureRMHDInsightInteractiveQueryCluster_gen2basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightInteractiveQueryCluster_gen2template(data) return fmt.Sprintf(` %s @@ -392,11 +309,11 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightInteractiveQueryCluster_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightInteractiveQueryCluster_basic(rInt, rString, location) +func testAccAzureRMHDInsightInteractiveQueryCluster_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMHDInsightInteractiveQueryCluster_basic(data) return fmt.Sprintf(` %s @@ -414,8 +331,8 @@ resource "azurerm_hdinsight_interactive_query_cluster" "import" { `, template) } -func testAccAzureRMHDInsightInteractiveQueryCluster_sshKeys(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightInteractiveQueryCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightInteractiveQueryCluster_sshKeys(data acceptance.TestData) string { + template := testAccAzureRMHDInsightInteractiveQueryCluster_template(data) return fmt.Sprintf(` %s @@ -467,11 +384,11 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightInteractiveQueryCluster_updated(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightInteractiveQueryCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightInteractiveQueryCluster_updated(data acceptance.TestData) string { + template := testAccAzureRMHDInsightInteractiveQueryCluster_template(data) return fmt.Sprintf(` %s @@ -523,11 +440,11 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightInteractiveQueryCluster_virtualNetwork(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightInteractiveQueryCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightInteractiveQueryCluster_virtualNetwork(data acceptance.TestData) string { + template := testAccAzureRMHDInsightInteractiveQueryCluster_template(data) return fmt.Sprintf(` %s @@ -595,11 +512,11 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightInteractiveQueryCluster_complete(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightInteractiveQueryCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightInteractiveQueryCluster_complete(data acceptance.TestData) string { + template := testAccAzureRMHDInsightInteractiveQueryCluster_template(data) return fmt.Sprintf(` %s @@ -671,10 +588,10 @@ resource "azurerm_hdinsight_interactive_query_cluster" "test" { Hello = "World" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightInteractiveQueryCluster_template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightInteractiveQueryCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -695,10 +612,10 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMHDInsightInteractiveQueryCluster_gen2template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightInteractiveQueryCluster_gen2template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -734,5 +651,5 @@ resource "azurerm_role_assignment" "test" { role_definition_name = "Storage Blob Data Owner" principal_id = "${azurerm_user_assigned_identity.test.principal_id}" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_kafka_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_kafka_cluster_test.go similarity index 63% rename from azurerm/internal/services/hdinsight/resource_arm_hdinsight_kafka_cluster_test.go rename to azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_kafka_cluster_test.go index 0d4f87738b73..be933e1545c9 100644 --- a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_kafka_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_kafka_cluster_test.go @@ -1,87 +1,62 @@ -package hdinsight +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMHDInsightKafkaCluster_basic(t *testing.T) { - resourceName := "azurerm_hdinsight_kafka_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_kafka_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_kafka_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightKafkaCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightKafkaCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightKafkaCluster_gen2storage(t *testing.T) { - resourceName := "azurerm_hdinsight_kafka_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_kafka_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_kafka_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightKafkaCluster_gen2storage(ri, rs, location), + Config: testAccAzureRMHDInsightKafkaCluster_gen2storage(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } @@ -92,26 +67,22 @@ func TestAccAzureRMHDInsightKafkaCluster_requiresImport(t *testing.T) { return } - resourceName := "azurerm_hdinsight_kafka_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_kafka_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_kafka_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightKafkaCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightKafkaCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, { - Config: testAccAzureRMHDInsightKafkaCluster_requiresImport(ri, rs, location), + Config: testAccAzureRMHDInsightKafkaCluster_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_hdinsight_kafka_cluster"), }, }, @@ -119,177 +90,126 @@ func TestAccAzureRMHDInsightKafkaCluster_requiresImport(t *testing.T) { } func TestAccAzureRMHDInsightKafkaCluster_update(t *testing.T) { - resourceName := "azurerm_hdinsight_kafka_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_kafka_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_kafka_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightKafkaCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightKafkaCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, - { - Config: testAccAzureRMHDInsightKafkaCluster_updated(ri, rs, location), + Config: testAccAzureRMHDInsightKafkaCluster_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightKafkaCluster_sshKeys(t *testing.T) { - resourceName := "azurerm_hdinsight_kafka_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_kafka_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_kafka_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightKafkaCluster_sshKeys(ri, rs, location), + Config: testAccAzureRMHDInsightKafkaCluster_sshKeys(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "storage_account", - "roles.0.head_node.0.ssh_keys", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.ssh_keys", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.ssh_keys", - "roles.0.zookeeper_node.0.vm_size", - }, - }, + data.ImportStep("storage_account", + "roles.0.head_node.0.ssh_keys", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.ssh_keys", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.ssh_keys", + "roles.0.zookeeper_node.0.vm_size"), }, }) } func TestAccAzureRMHDInsightKafkaCluster_virtualNetwork(t *testing.T) { - resourceName := "azurerm_hdinsight_kafka_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_kafka_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_kafka_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightKafkaCluster_virtualNetwork(ri, rs, location), + Config: testAccAzureRMHDInsightKafkaCluster_virtualNetwork(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightKafkaCluster_complete(t *testing.T) { - resourceName := "azurerm_hdinsight_kafka_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_kafka_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_kafka_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightKafkaCluster_complete(ri, rs, location), + Config: testAccAzureRMHDInsightKafkaCluster_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } -func testAccAzureRMHDInsightKafkaCluster_basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightKafkaCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightKafkaCluster_basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightKafkaCluster_template(data) return fmt.Sprintf(` %s @@ -338,11 +258,11 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightKafkaCluster_gen2storage(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightKafkaCluster_gen2template(rInt, rString, location) +func testAccAzureRMHDInsightKafkaCluster_gen2storage(data acceptance.TestData) string { + template := testAccAzureRMHDInsightKafkaCluster_gen2template(data) return fmt.Sprintf(` %s @@ -394,11 +314,11 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightKafkaCluster_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightKafkaCluster_basic(rInt, rString, location) +func testAccAzureRMHDInsightKafkaCluster_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMHDInsightKafkaCluster_basic(data) return fmt.Sprintf(` %s @@ -416,8 +336,8 @@ resource "azurerm_hdinsight_kafka_cluster" "import" { `, template) } -func testAccAzureRMHDInsightKafkaCluster_sshKeys(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightKafkaCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightKafkaCluster_sshKeys(data acceptance.TestData) string { + template := testAccAzureRMHDInsightKafkaCluster_template(data) return fmt.Sprintf(` %s @@ -470,11 +390,11 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightKafkaCluster_updated(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightKafkaCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightKafkaCluster_updated(data acceptance.TestData) string { + template := testAccAzureRMHDInsightKafkaCluster_template(data) return fmt.Sprintf(` %s @@ -527,11 +447,11 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightKafkaCluster_virtualNetwork(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightKafkaCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightKafkaCluster_virtualNetwork(data acceptance.TestData) string { + template := testAccAzureRMHDInsightKafkaCluster_template(data) return fmt.Sprintf(` %s @@ -600,11 +520,11 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightKafkaCluster_complete(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightKafkaCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightKafkaCluster_complete(data acceptance.TestData) string { + template := testAccAzureRMHDInsightKafkaCluster_template(data) return fmt.Sprintf(` %s @@ -677,10 +597,10 @@ resource "azurerm_hdinsight_kafka_cluster" "test" { Hello = "World" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightKafkaCluster_template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightKafkaCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -701,10 +621,10 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMHDInsightKafkaCluster_gen2template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightKafkaCluster_gen2template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -740,5 +660,5 @@ resource "azurerm_role_assignment" "test" { role_definition_name = "Storage Blob Data Owner" principal_id = "${azurerm_user_assigned_identity.test.principal_id}" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_ml_services_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_ml_services_cluster_test.go similarity index 59% rename from azurerm/internal/services/hdinsight/resource_arm_hdinsight_ml_services_cluster_test.go rename to azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_ml_services_cluster_test.go index 437b0f584943..983ff39f5a4a 100644 --- a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_ml_services_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_ml_services_cluster_test.go @@ -1,53 +1,39 @@ -package hdinsight +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMHDInsightMLServicesCluster_basic(t *testing.T) { - resourceName := "azurerm_hdinsight_ml_services_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_ml_services_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_ml_services_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightMLServicesCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightMLServicesCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), }, }) } @@ -58,220 +44,162 @@ func TestAccAzureRMHDInsightMLServicesCluster_requiresImport(t *testing.T) { return } - resourceName := "azurerm_hdinsight_ml_services_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_ml_services_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_ml_services_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightMLServicesCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightMLServicesCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - Config: testAccAzureRMHDInsightMLServicesCluster_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_hdinsight_ml_services_cluster"), - }, + data.RequiresImportErrorStep(testAccAzureRMHDInsightMLServicesCluster_requiresImport), }, }) } func TestAccAzureRMHDInsightMLServicesCluster_update(t *testing.T) { - resourceName := "azurerm_hdinsight_ml_services_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_ml_services_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_ml_services_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightMLServicesCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightMLServicesCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, - { - Config: testAccAzureRMHDInsightMLServicesCluster_updated(ri, rs, location), + Config: testAccAzureRMHDInsightMLServicesCluster_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightMLServicesCluster_sshKeys(t *testing.T) { - resourceName := "azurerm_hdinsight_ml_services_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_ml_services_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_ml_services_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightMLServicesCluster_sshKeys(ri, rs, location), + Config: testAccAzureRMHDInsightMLServicesCluster_sshKeys(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "storage_account", - "roles.0.head_node.0.ssh_keys", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.ssh_keys", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.ssh_keys", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.ssh_keys", - "roles.0.edge_node.0.vm_size", - }, - }, + data.ImportStep("storage_account", + "roles.0.head_node.0.ssh_keys", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.ssh_keys", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.ssh_keys", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.ssh_keys", + "roles.0.edge_node.0.vm_size"), }, }) } func TestAccAzureRMHDInsightMLServicesCluster_virtualNetwork(t *testing.T) { - resourceName := "azurerm_hdinsight_ml_services_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_ml_services_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_ml_services_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightMLServicesCluster_virtualNetwork(ri, rs, location), + Config: testAccAzureRMHDInsightMLServicesCluster_virtualNetwork(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightMLServicesCluster_complete(t *testing.T) { - resourceName := "azurerm_hdinsight_ml_services_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_ml_services_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_ml_services_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightMLServicesCluster_complete(ri, rs, location), + Config: testAccAzureRMHDInsightMLServicesCluster_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), }, }) } -func testAccAzureRMHDInsightMLServicesCluster_basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightMLServicesCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightMLServicesCluster_basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightMLServicesCluster_template(data) return fmt.Sprintf(` %s @@ -322,11 +250,11 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightMLServicesCluster_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightMLServicesCluster_basic(rInt, rString, location) +func testAccAzureRMHDInsightMLServicesCluster_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMHDInsightMLServicesCluster_basic(data) return fmt.Sprintf(` %s @@ -343,8 +271,8 @@ resource "azurerm_hdinsight_ml_services_cluster" "import" { `, template) } -func testAccAzureRMHDInsightMLServicesCluster_sshKeys(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightMLServicesCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightMLServicesCluster_sshKeys(data acceptance.TestData) string { + template := testAccAzureRMHDInsightMLServicesCluster_template(data) return fmt.Sprintf(` %s @@ -399,11 +327,11 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightMLServicesCluster_updated(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightMLServicesCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightMLServicesCluster_updated(data acceptance.TestData) string { + template := testAccAzureRMHDInsightMLServicesCluster_template(data) return fmt.Sprintf(` %s @@ -458,11 +386,11 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightMLServicesCluster_virtualNetwork(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightMLServicesCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightMLServicesCluster_virtualNetwork(data acceptance.TestData) string { + template := testAccAzureRMHDInsightMLServicesCluster_template(data) return fmt.Sprintf(` %s @@ -535,11 +463,11 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightMLServicesCluster_complete(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightMLServicesCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightMLServicesCluster_complete(data acceptance.TestData) string { + template := testAccAzureRMHDInsightMLServicesCluster_template(data) return fmt.Sprintf(` %s @@ -616,10 +544,10 @@ resource "azurerm_hdinsight_ml_services_cluster" "test" { Hello = "World" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightMLServicesCluster_template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightMLServicesCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -640,5 +568,5 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_rserver_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_rserver_cluster_test.go similarity index 59% rename from azurerm/internal/services/hdinsight/resource_arm_hdinsight_rserver_cluster_test.go rename to azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_rserver_cluster_test.go index 00ebcc3c103f..5d4818cb076e 100644 --- a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_rserver_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_rserver_cluster_test.go @@ -1,53 +1,39 @@ -package hdinsight +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMHDInsightRServerCluster_basic(t *testing.T) { - resourceName := "azurerm_hdinsight_rserver_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_rserver_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_rserver_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightRServerCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightRServerCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), }, }) } @@ -58,220 +44,162 @@ func TestAccAzureRMHDInsightRServerCluster_requiresImport(t *testing.T) { return } - resourceName := "azurerm_hdinsight_rserver_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_rserver_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_rserver_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightRServerCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightRServerCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - Config: testAccAzureRMHDInsightRServerCluster_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_hdinsight_rserver_cluster"), - }, + data.RequiresImportErrorStep(testAccAzureRMHDInsightRServerCluster_requiresImport), }, }) } func TestAccAzureRMHDInsightRServerCluster_update(t *testing.T) { - resourceName := "azurerm_hdinsight_rserver_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_rserver_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_rserver_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightRServerCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightRServerCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, - { - Config: testAccAzureRMHDInsightRServerCluster_updated(ri, rs, location), + Config: testAccAzureRMHDInsightRServerCluster_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightRServerCluster_sshKeys(t *testing.T) { - resourceName := "azurerm_hdinsight_rserver_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_rserver_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_rserver_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightRServerCluster_sshKeys(ri, rs, location), + Config: testAccAzureRMHDInsightRServerCluster_sshKeys(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "storage_account", - "roles.0.head_node.0.ssh_keys", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.ssh_keys", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.ssh_keys", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.ssh_keys", - "roles.0.edge_node.0.vm_size", - }, - }, + data.ImportStep("storage_account", + "roles.0.head_node.0.ssh_keys", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.ssh_keys", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.ssh_keys", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.ssh_keys", + "roles.0.edge_node.0.vm_size"), }, }) } func TestAccAzureRMHDInsightRServerCluster_virtualNetwork(t *testing.T) { - resourceName := "azurerm_hdinsight_rserver_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_rserver_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_rserver_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightRServerCluster_virtualNetwork(ri, rs, location), + Config: testAccAzureRMHDInsightRServerCluster_virtualNetwork(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightRServerCluster_complete(t *testing.T) { - resourceName := "azurerm_hdinsight_rserver_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_rserver_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_rserver_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightRServerCluster_complete(ri, rs, location), + Config: testAccAzureRMHDInsightRServerCluster_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "edge_ssh_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "edge_ssh_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "roles.0.edge_node.0.password", - "roles.0.edge_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "roles.0.edge_node.0.password", + "roles.0.edge_node.0.vm_size", + "storage_account"), }, }) } -func testAccAzureRMHDInsightRServerCluster_basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightRServerCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightRServerCluster_basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightRServerCluster_template(data) return fmt.Sprintf(` %s @@ -322,11 +250,11 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightRServerCluster_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightRServerCluster_basic(rInt, rString, location) +func testAccAzureRMHDInsightRServerCluster_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMHDInsightRServerCluster_basic(data) return fmt.Sprintf(` %s @@ -343,8 +271,8 @@ resource "azurerm_hdinsight_rserver_cluster" "import" { `, template) } -func testAccAzureRMHDInsightRServerCluster_sshKeys(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightRServerCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightRServerCluster_sshKeys(data acceptance.TestData) string { + template := testAccAzureRMHDInsightRServerCluster_template(data) return fmt.Sprintf(` %s @@ -399,11 +327,11 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightRServerCluster_updated(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightRServerCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightRServerCluster_updated(data acceptance.TestData) string { + template := testAccAzureRMHDInsightRServerCluster_template(data) return fmt.Sprintf(` %s @@ -458,11 +386,11 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightRServerCluster_virtualNetwork(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightRServerCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightRServerCluster_virtualNetwork(data acceptance.TestData) string { + template := testAccAzureRMHDInsightRServerCluster_template(data) return fmt.Sprintf(` %s @@ -535,11 +463,11 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightRServerCluster_complete(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightRServerCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightRServerCluster_complete(data acceptance.TestData) string { + template := testAccAzureRMHDInsightRServerCluster_template(data) return fmt.Sprintf(` %s @@ -616,10 +544,10 @@ resource "azurerm_hdinsight_rserver_cluster" "test" { Hello = "World" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightRServerCluster_template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightRServerCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -640,5 +568,5 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_spark_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_spark_cluster_test.go similarity index 61% rename from azurerm/internal/services/hdinsight/resource_arm_hdinsight_spark_cluster_test.go rename to azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_spark_cluster_test.go index a31cc5281a70..0e16380f7599 100644 --- a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_spark_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_spark_cluster_test.go @@ -1,87 +1,62 @@ -package hdinsight +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMHDInsightSparkCluster_basic(t *testing.T) { - resourceName := "azurerm_hdinsight_spark_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_spark_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_spark_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightSparkCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightSparkCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightSparkCluster_gen2basic(t *testing.T) { - resourceName := "azurerm_hdinsight_spark_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_spark_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_spark_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightSparkCluster_gen2basic(ri, rs, location), + Config: testAccAzureRMHDInsightSparkCluster_gen2basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } @@ -92,204 +67,146 @@ func TestAccAzureRMHDInsightSparkCluster_requiresImport(t *testing.T) { return } - resourceName := "azurerm_hdinsight_spark_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_spark_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_spark_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightSparkCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightSparkCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - Config: testAccAzureRMHDInsightSparkCluster_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_hdinsight_spark_cluster"), - }, + data.RequiresImportErrorStep(testAccAzureRMHDInsightSparkCluster_requiresImport), }, }) } func TestAccAzureRMHDInsightSparkCluster_update(t *testing.T) { - resourceName := "azurerm_hdinsight_spark_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_spark_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_spark_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightSparkCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightSparkCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, - { - Config: testAccAzureRMHDInsightSparkCluster_updated(ri, rs, location), + Config: testAccAzureRMHDInsightSparkCluster_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightSparkCluster_sshKeys(t *testing.T) { - resourceName := "azurerm_hdinsight_spark_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_spark_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_spark_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightSparkCluster_sshKeys(ri, rs, location), + Config: testAccAzureRMHDInsightSparkCluster_sshKeys(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "storage_account", - "roles.0.head_node.0.ssh_keys", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.ssh_keys", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.ssh_keys", - "roles.0.zookeeper_node.0.vm_size", - }, - }, + data.ImportStep("storage_account", + "roles.0.head_node.0.ssh_keys", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.ssh_keys", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.ssh_keys", + "roles.0.zookeeper_node.0.vm_size"), }, }) } func TestAccAzureRMHDInsightSparkCluster_virtualNetwork(t *testing.T) { - resourceName := "azurerm_hdinsight_spark_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_spark_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_spark_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightSparkCluster_virtualNetwork(ri, rs, location), + Config: testAccAzureRMHDInsightSparkCluster_virtualNetwork(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightSparkCluster_complete(t *testing.T) { - resourceName := "azurerm_hdinsight_spark_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_spark_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_spark_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightSparkCluster_complete(ri, rs, location), + Config: testAccAzureRMHDInsightSparkCluster_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } -func testAccAzureRMHDInsightSparkCluster_basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightSparkCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightSparkCluster_basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightSparkCluster_template(data) return fmt.Sprintf(` %s @@ -337,11 +254,11 @@ resource "azurerm_hdinsight_spark_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightSparkCluster_gen2basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightSparkCluster_gen2template(rInt, rString, location) +func testAccAzureRMHDInsightSparkCluster_gen2basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightSparkCluster_gen2template(data) return fmt.Sprintf(` %s @@ -392,11 +309,11 @@ resource "azurerm_hdinsight_spark_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightSparkCluster_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightSparkCluster_basic(rInt, rString, location) +func testAccAzureRMHDInsightSparkCluster_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMHDInsightSparkCluster_basic(data) return fmt.Sprintf(` %s @@ -414,8 +331,8 @@ resource "azurerm_hdinsight_spark_cluster" "import" { `, template) } -func testAccAzureRMHDInsightSparkCluster_sshKeys(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightSparkCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightSparkCluster_sshKeys(data acceptance.TestData) string { + template := testAccAzureRMHDInsightSparkCluster_template(data) return fmt.Sprintf(` %s @@ -467,11 +384,11 @@ resource "azurerm_hdinsight_spark_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightSparkCluster_updated(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightSparkCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightSparkCluster_updated(data acceptance.TestData) string { + template := testAccAzureRMHDInsightSparkCluster_template(data) return fmt.Sprintf(` %s @@ -523,11 +440,11 @@ resource "azurerm_hdinsight_spark_cluster" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightSparkCluster_virtualNetwork(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightSparkCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightSparkCluster_virtualNetwork(data acceptance.TestData) string { + template := testAccAzureRMHDInsightSparkCluster_template(data) return fmt.Sprintf(` %s @@ -595,11 +512,11 @@ resource "azurerm_hdinsight_spark_cluster" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightSparkCluster_complete(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightSparkCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightSparkCluster_complete(data acceptance.TestData) string { + template := testAccAzureRMHDInsightSparkCluster_template(data) return fmt.Sprintf(` %s @@ -671,10 +588,10 @@ resource "azurerm_hdinsight_spark_cluster" "test" { Hello = "World" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightSparkCluster_template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightSparkCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -695,10 +612,10 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMHDInsightSparkCluster_gen2template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightSparkCluster_gen2template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -734,5 +651,5 @@ resource "azurerm_role_assignment" "test" { role_definition_name = "Storage Blob Data Owner" principal_id = "${azurerm_user_assigned_identity.test.principal_id}" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_storm_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go similarity index 60% rename from azurerm/internal/services/hdinsight/resource_arm_hdinsight_storm_cluster_test.go rename to azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go index dce011bd476d..43cb140c1013 100644 --- a/azurerm/internal/services/hdinsight/resource_arm_hdinsight_storm_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go @@ -1,50 +1,36 @@ -package hdinsight +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMHDInsightStormCluster_basic(t *testing.T) { - resourceName := "azurerm_hdinsight_storm_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_storm_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_storm_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightStormCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightStormCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } @@ -55,204 +41,147 @@ func TestAccAzureRMHDInsightStormCluster_requiresImport(t *testing.T) { return } - resourceName := "azurerm_hdinsight_storm_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_storm_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_storm_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightStormCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightStormCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - Config: testAccAzureRMHDInsightStormCluster_requiresImport(ri, rs, location), - ExpectError: acceptance.RequiresImportError("azurerm_hdinsight_storm_cluster"), - }, + data.RequiresImportErrorStep(testAccAzureRMHDInsightStormCluster_requiresImport), }, }) } func TestAccAzureRMHDInsightStormCluster_update(t *testing.T) { - resourceName := "azurerm_hdinsight_storm_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_storm_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_storm_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightStormCluster_basic(ri, rs, location), + Config: testAccAzureRMHDInsightStormCluster_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, - { - Config: testAccAzureRMHDInsightStormCluster_updated(ri, rs, location), + Config: testAccAzureRMHDInsightStormCluster_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep( + "roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightStormCluster_sshKeys(t *testing.T) { - resourceName := "azurerm_hdinsight_storm_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_storm_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_storm_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightStormCluster_sshKeys(ri, rs, location), + Config: testAccAzureRMHDInsightStormCluster_sshKeys(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "storage_account", - "roles.0.head_node.0.ssh_keys", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.ssh_keys", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.ssh_keys", - "roles.0.zookeeper_node.0.vm_size", - }, - }, + data.ImportStep("storage_account", + "roles.0.head_node.0.ssh_keys", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.ssh_keys", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.ssh_keys", + "roles.0.zookeeper_node.0.vm_size"), }, }) } func TestAccAzureRMHDInsightStormCluster_virtualNetwork(t *testing.T) { - resourceName := "azurerm_hdinsight_storm_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_storm_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_storm_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightStormCluster_virtualNetwork(ri, rs, location), + Config: testAccAzureRMHDInsightStormCluster_virtualNetwork(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } func TestAccAzureRMHDInsightStormCluster_complete(t *testing.T) { - resourceName := "azurerm_hdinsight_storm_cluster.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_hdinsight_storm_cluster", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMHDInsightClusterDestroy("azurerm_hdinsight_storm_cluster"), + CheckDestroy: testCheckAzureRMHDInsightClusterDestroy(data.ResourceType), Steps: []resource.TestStep{ { - Config: testAccAzureRMHDInsightStormCluster_complete(ri, rs, location), + Config: testAccAzureRMHDInsightStormCluster_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMHDInsightClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "https_endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "ssh_endpoint"), + testCheckAzureRMHDInsightClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "https_endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ssh_endpoint"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "roles.0.head_node.0.password", - "roles.0.head_node.0.vm_size", - "roles.0.worker_node.0.password", - "roles.0.worker_node.0.vm_size", - "roles.0.zookeeper_node.0.password", - "roles.0.zookeeper_node.0.vm_size", - "storage_account", - }, - }, + data.ImportStep("roles.0.head_node.0.password", + "roles.0.head_node.0.vm_size", + "roles.0.worker_node.0.password", + "roles.0.worker_node.0.vm_size", + "roles.0.zookeeper_node.0.password", + "roles.0.zookeeper_node.0.vm_size", + "storage_account"), }, }) } -func testAccAzureRMHDInsightStormCluster_basic(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightStormCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightStormCluster_basic(data acceptance.TestData) string { + template := testAccAzureRMHDInsightStormCluster_template(data) return fmt.Sprintf(` %s @@ -300,11 +229,11 @@ resource "azurerm_hdinsight_storm_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightStormCluster_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightStormCluster_basic(rInt, rString, location) +func testAccAzureRMHDInsightStormCluster_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMHDInsightStormCluster_basic(data) return fmt.Sprintf(` %s @@ -322,8 +251,8 @@ resource "azurerm_hdinsight_storm_cluster" "import" { `, template) } -func testAccAzureRMHDInsightStormCluster_sshKeys(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightStormCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightStormCluster_sshKeys(data acceptance.TestData) string { + template := testAccAzureRMHDInsightStormCluster_template(data) return fmt.Sprintf(` %s @@ -375,11 +304,11 @@ resource "azurerm_hdinsight_storm_cluster" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightStormCluster_updated(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightStormCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightStormCluster_updated(data acceptance.TestData) string { + template := testAccAzureRMHDInsightStormCluster_template(data) return fmt.Sprintf(` %s @@ -431,11 +360,11 @@ resource "azurerm_hdinsight_storm_cluster" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMHDInsightStormCluster_virtualNetwork(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightStormCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightStormCluster_virtualNetwork(data acceptance.TestData) string { + template := testAccAzureRMHDInsightStormCluster_template(data) return fmt.Sprintf(` %s @@ -503,11 +432,11 @@ resource "azurerm_hdinsight_storm_cluster" "test" { } } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightStormCluster_complete(rInt int, rString string, location string) string { - template := testAccAzureRMHDInsightStormCluster_template(rInt, rString, location) +func testAccAzureRMHDInsightStormCluster_complete(data acceptance.TestData) string { + template := testAccAzureRMHDInsightStormCluster_template(data) return fmt.Sprintf(` %s @@ -579,10 +508,10 @@ resource "azurerm_hdinsight_storm_cluster" "test" { Hello = "World" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMHDInsightStormCluster_template(rInt int, rString string, location string) string { +func testAccAzureRMHDInsightStormCluster_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -603,5 +532,5 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 7a7ac3a2479d90fe995ddd7a02d2dabce71f861d Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Sat, 21 Dec 2019 10:53:30 -0800 Subject: [PATCH 137/203] tests: batch --- .../batch/data_source_batch_account.go | 2 +- .../batch/data_source_batch_certificate.go | 2 +- .../data_source_batch_certificate_test.go | 69 --- .../services/batch/data_source_batch_pool.go | 2 +- .../batch/data_source_batch_pool_test.go | 166 -------- .../batch/resource_arm_batch_account.go | 4 +- .../batch/resource_arm_batch_application.go | 2 +- .../batch/resource_arm_batch_certificate.go | 2 +- .../services/batch/resource_arm_batch_pool.go | 2 +- .../data_source_batch_account_test.go | 61 ++- .../data_source_batch_certificate_test.go | 64 +++ .../tests/data_source_batch_pool_test.go | 160 +++++++ .../resource_arm_batch_account_test.go | 91 ++-- .../resource_arm_batch_application_test.go | 41 +- .../resource_arm_batch_certificate_test.go | 73 ++-- .../resource_arm_batch_pool_test.go | 400 ++++++++---------- 16 files changed, 523 insertions(+), 618 deletions(-) delete mode 100644 azurerm/internal/services/batch/data_source_batch_certificate_test.go delete mode 100644 azurerm/internal/services/batch/data_source_batch_pool_test.go rename azurerm/internal/services/batch/{ => tests}/data_source_batch_account_test.go (64%) create mode 100644 azurerm/internal/services/batch/tests/data_source_batch_certificate_test.go create mode 100644 azurerm/internal/services/batch/tests/data_source_batch_pool_test.go rename azurerm/internal/services/batch/{ => tests}/resource_arm_batch_account_test.go (73%) rename azurerm/internal/services/batch/{ => tests}/resource_arm_batch_application_test.go (74%) rename azurerm/internal/services/batch/{ => tests}/resource_arm_batch_certificate_test.go (74%) rename azurerm/internal/services/batch/{ => tests}/resource_arm_batch_pool_test.go (62%) diff --git a/azurerm/internal/services/batch/data_source_batch_account.go b/azurerm/internal/services/batch/data_source_batch_account.go index 016e9f193087..92ea0fc319e7 100644 --- a/azurerm/internal/services/batch/data_source_batch_account.go +++ b/azurerm/internal/services/batch/data_source_batch_account.go @@ -26,7 +26,7 @@ func dataSourceArmBatchAccount() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureRMBatchAccountName, + ValidateFunc: ValidateAzureRMBatchAccountName, }, "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), "location": azure.SchemaLocationForDataSource(), diff --git a/azurerm/internal/services/batch/data_source_batch_certificate.go b/azurerm/internal/services/batch/data_source_batch_certificate.go index 0bda0eb71435..9957d8f37e7d 100644 --- a/azurerm/internal/services/batch/data_source_batch_certificate.go +++ b/azurerm/internal/services/batch/data_source_batch_certificate.go @@ -30,7 +30,7 @@ func dataSourceArmBatchCertificate() *schema.Resource { "account_name": { Type: schema.TypeString, Required: true, - ValidateFunc: validateAzureRMBatchAccountName, + ValidateFunc: ValidateAzureRMBatchAccountName, }, "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), diff --git a/azurerm/internal/services/batch/data_source_batch_certificate_test.go b/azurerm/internal/services/batch/data_source_batch_certificate_test.go deleted file mode 100644 index ca4f00f1dee8..000000000000 --- a/azurerm/internal/services/batch/data_source_batch_certificate_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package batch - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMBatchCertificate_basic(t *testing.T) { - dataSourceName := "data.azurerm_batch_certificate.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - config := testAccDataSourceAzureRMBatchCertificate_basic(ri, rs, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", "sha1-42c107874fd0e4a9583292a2f1098e8fe4b2edda"), - resource.TestCheckResourceAttr(dataSourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(dataSourceName, "format", "Pfx"), - resource.TestCheckResourceAttr(dataSourceName, "public_data", "MIIFqzCCA5OgAwIBAgIJAMs4jwMPq7T1MA0GCSqGSIb3DQEBCwUAMGwxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApTb21lLVN0YXRlMRgwFgYDVQQKDA9UZXJyYWZvcm0gVGVzdHMxDjAMBgNVBAsMBUF6dXJlMR4wHAYDVQQDDBVUZXJyYWZvcm0gQXBwIEdhdGV3YXkwHhcNMTYxMTAxMTcxOTEyWhcNMjYxMDMwMTcxOTEyWjBsMQswCQYDVQQGEwJVUzETMBEGA1UECAwKU29tZS1TdGF0ZTEYMBYGA1UECgwPVGVycmFmb3JtIFRlc3RzMQ4wDAYDVQQLDAVBenVyZTEeMBwGA1UEAwwVVGVycmFmb3JtIEFwcCBHYXRld2F5MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA49HW2pYIlW/mlaadLA1AsXiV48xVhXAvGVk3DEl1ffjp5bN8rap5WV1D83uMg1Ii7CJM8yNHkRkvN8n5WXFng4R5V1jPxGOTAj+xLybvEASi++GZelWdpOuMk8/nAoKPMbQ5NyKFy5WzlOduMldR7Awt2pwdId3akqm1i9ITG9Js+4P4nYXM8vfJCajILqi4YfhEoCNvS1EUgvlpSFE7pfNhc2W+zsfUWxWmB2SpWwX9MgQ1D4OmdKp+Eo+b6vzst3XArKMHMadPTUAk8H+ZgAnlX9yO+3vQ6z86vma/WgrG2LH6GCGXBjmKlhxVCPMLA5LeRUwEGc/Q7X/ClitGWY9umPN1XVj5e5Di1K2M082Y14mgbTTRTpv/nx7Xlph+MHnVhEWvaGMpqCHuM1W1y7wIS1IREYQ2q+K54xxZSPKYJMSnmj6A0hR/LBV0rL1uVhedEpdviduuO76qCyZrGG4HwBlW4hnIaahLzgqlvlmbDUQonAVPDgi3brVdXJgLv2zi7/ZHFW3IHgDylUVIdig0ccbzxKymlkGQ0RsLBjWOyxak2J8bN5JNVyxSwX43NZqxJ8yOv5xjB+rVMri9SX3Dl5NbFzOjynov601Pmwvb7zYnyttG2Hl5EKrkahjijGRjGy3EWEiBiArLkdTKCDHBlHxykTEvY6ZH5B9waP0CAwEAAaNQME4wHQYDVR0OBBYEFD2/Hq3IivZ5RMOKrPsM7ijIFHmMMB8GA1UdIwQYMBaAFD2/Hq3IivZ5RMOKrPsM7ijIFHmMMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBAKxHWO/Q4labjnCVxYi+kaMRCPJUdHj7lga8yi8EGHaL+CbwynkaiyTfPvtmcqiuaZM9BaXsuNMRcHMtXM0EHBsjViwAHk6SrqLXd/opFvMI2QbG93koFUCpczrpyO9GvnRN4iOIYbSPXAdGOB6bkpMbm/XajORoDrua+/ET/X/1FP0GZBTmEFwojuCfOI/VuJXj0OW8XzkLmsXiLpOiakjU1obBup/1lz9DtOEBsiB9Ury+f5gZ+FnZuqhgQxeDxlZ69P6YYAfkzhcfbf7HO+nMKhppAj1BFeR4SBb+F/fLchCGO5yohwkxWz3i2q9gTDhBgo31416viyCKFWSVW3Vn7jbsjZ+Q9MK1jVSOSxC7qoQkRoNy9SKpqylunXZb+K6F3HfBkDQvn3OwsxYiSOcX9JaWpQAInNIZVg+WrJ1PXm8PFIaVPJfMgP3GOdm9vRAMjOM5Bc9iqGr2spimFd5h0GmgLvh35B3jHHWF4i3NupJQ6hUvHQZtYZOxfwxnY0/LVBTyLTVlniFA7dGSI+5Uexm+Pjh7IMGI532jTONlfNm9Bz/jdf1o0FlOclzG6Eif22gml3GM3xCUVlaElylYNAjO2lfvZuRVo5GKdMwtV9acNl0OwSx+0zbMYY2Ni3jQCI4kOL5Csctryf0rHXTlCCvnzBYVDPKmFJPna61T"), - resource.TestCheckResourceAttr(dataSourceName, "thumbprint", "42c107874fd0e4a9583292a2f1098e8fe4b2edda"), - resource.TestCheckResourceAttr(dataSourceName, "thumbprint_algorithm", "sha1"), // api now always returns this as lowercase - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMBatchCertificate_basic(rInt int, rString string, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "testaccbatch%d" - location = "%s" -} - -resource "azurerm_batch_account" "test" { - name = "testaccbatch%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - pool_allocation_mode = "BatchService" -} - -resource "azurerm_batch_certificate" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - account_name = "${azurerm_batch_account.test.name}" - certificate = "${filebase64("testdata/batch_certificate.pfx")}" - format = "Pfx" - password = "terraform" - thumbprint = "42c107874fd0e4a9583292a2f1098e8fe4b2edda" - thumbprint_algorithm = "SHA1" -} - -data "azurerm_batch_certificate" "test" { - name = "${azurerm_batch_certificate.test.name}" - account_name = "${azurerm_batch_account.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, rInt, location, rString) -} diff --git a/azurerm/internal/services/batch/data_source_batch_pool.go b/azurerm/internal/services/batch/data_source_batch_pool.go index 11a64c51ddff..24c7d09a0b62 100644 --- a/azurerm/internal/services/batch/data_source_batch_pool.go +++ b/azurerm/internal/services/batch/data_source_batch_pool.go @@ -31,7 +31,7 @@ func dataSourceArmBatchPool() *schema.Resource { "account_name": { Type: schema.TypeString, Required: true, - ValidateFunc: validateAzureRMBatchAccountName, + ValidateFunc: ValidateAzureRMBatchAccountName, }, "display_name": { Type: schema.TypeString, diff --git a/azurerm/internal/services/batch/data_source_batch_pool_test.go b/azurerm/internal/services/batch/data_source_batch_pool_test.go deleted file mode 100644 index cf6b4941e507..000000000000 --- a/azurerm/internal/services/batch/data_source_batch_pool_test.go +++ /dev/null @@ -1,166 +0,0 @@ -package batch - -import ( - "fmt" - "testing" - - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" -) - -func TestAccDataSourceAzureRMBatchPool_complete(t *testing.T) { - dataSourceName := "data.azurerm_batch_pool.test" - ri := tf.AccRandTimeInt() - - rs := acctest.RandString(4) - location := acceptance.Location() - config := testAccDataSourceAzureRMBatchPool_complete(ri, rs, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("testaccpool%s", rs)), - resource.TestCheckResourceAttr(dataSourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(dataSourceName, "vm_size", "STANDARD_A1"), - resource.TestCheckResourceAttr(dataSourceName, "storage_image_reference.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "storage_image_reference.0.publisher", "microsoft-azure-batch"), - resource.TestCheckResourceAttr(dataSourceName, "storage_image_reference.0.sku", "16-04-lts"), - resource.TestCheckResourceAttr(dataSourceName, "storage_image_reference.0.offer", "ubuntu-server-container"), - resource.TestCheckResourceAttr(dataSourceName, "fixed_scale.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "fixed_scale.0.target_dedicated_nodes", "2"), - resource.TestCheckResourceAttr(dataSourceName, "fixed_scale.0.resize_timeout", "PT15M"), - resource.TestCheckResourceAttr(dataSourceName, "fixed_scale.0.target_low_priority_nodes", "0"), - resource.TestCheckResourceAttr(dataSourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(dataSourceName, "max_tasks_per_node", "2"), - resource.TestCheckResourceAttr(dataSourceName, "start_task.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "start_task.0.max_task_retry_count", "1"), - resource.TestCheckResourceAttr(dataSourceName, "start_task.0.environment.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "start_task.0.environment.env", "TEST"), - resource.TestCheckResourceAttr(dataSourceName, "start_task.0.user_identity.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "start_task.0.user_identity.0.auto_user.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "start_task.0.user_identity.0.auto_user.0.scope", "Task"), - resource.TestCheckResourceAttr(dataSourceName, "start_task.0.user_identity.0.auto_user.0.elevation_level", "NonAdmin"), - resource.TestCheckResourceAttr(dataSourceName, "certificate.#", "1"), - resource.TestCheckResourceAttrSet(dataSourceName, "certificate.0.id"), - resource.TestCheckResourceAttr(dataSourceName, "certificate.0.store_location", "CurrentUser"), - resource.TestCheckResourceAttr(dataSourceName, "certificate.0.store_name", ""), - resource.TestCheckResourceAttr(dataSourceName, "certificate.0.visibility.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "certificate.0.visibility.3294600504", "StartTask"), - resource.TestCheckResourceAttr(dataSourceName, "certificate.0.visibility.4077195354", "RemoteUser"), - resource.TestCheckResourceAttr(dataSourceName, "container_configuration.0.type", "DockerCompatible"), - resource.TestCheckResourceAttr(dataSourceName, "container_configuration.0.container_registries.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "container_configuration.0.container_registries.0.registry_server", "myContainerRegistry.azurecr.io"), - resource.TestCheckResourceAttr(dataSourceName, "container_configuration.0.container_registries.0.user_name", "myUserName"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMBatchPool_complete(rInt int, rString string, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "testaccRG-%d-batch" - location = "%s" -} - -resource "azurerm_storage_account" "test" { - name = "testaccsa%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - account_tier = "Standard" - account_replication_type = "LRS" -} - -resource "azurerm_batch_account" "test" { - name = "testaccbatch%s" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - pool_allocation_mode = "BatchService" - storage_account_id = "${azurerm_storage_account.test.id}" - - tags = { - env = "test" - } -} - -resource "azurerm_batch_certificate" "test" { - resource_group_name = "${azurerm_resource_group.test.name}" - account_name = "${azurerm_batch_account.test.name}" - certificate = "${filebase64("testdata/batch_certificate.pfx")}" - format = "Pfx" - password = "terraform" - thumbprint = "42c107874fd0e4a9583292a2f1098e8fe4b2edda" - thumbprint_algorithm = "SHA1" -} - -resource "azurerm_batch_pool" "test" { - name = "testaccpool%s" - resource_group_name = "${azurerm_resource_group.test.name}" - account_name = "${azurerm_batch_account.test.name}" - display_name = "Test Acc Pool" - vm_size = "Standard_A1" - node_agent_sku_id = "batch.node.ubuntu 16.04" - max_tasks_per_node = 2 - - fixed_scale { - target_dedicated_nodes = 2 - resize_timeout = "PT15M" - } - - storage_image_reference { - publisher = "microsoft-azure-batch" - offer = "ubuntu-server-container" - sku = "16-04-lts" - version = "latest" - } - - certificate { - id = "${azurerm_batch_certificate.test.id}" - store_location = "CurrentUser" - visibility = ["StartTask", "RemoteUser"] - } - - container_configuration { - type = "DockerCompatible" - container_registries = [ - { - registry_server = "myContainerRegistry.azurecr.io" - user_name = "myUserName" - password = "myPassword" - }, - ] - } - - start_task { - command_line = "echo 'Hello World from $env'" - max_task_retry_count = 1 - wait_for_success = true - - environment = { - env = "TEST" - } - - user_identity { - auto_user { - elevation_level = "NonAdmin" - scope = "Task" - } - } - } -} - -data "azurerm_batch_pool" "test" { - name = "${azurerm_batch_pool.test.name}" - account_name = "${azurerm_batch_pool.test.account_name}" - resource_group_name = "${azurerm_batch_pool.test.resource_group_name}" -} -`, rInt, location, rString, data.RandomString, data.RandomString) -} diff --git a/azurerm/internal/services/batch/resource_arm_batch_account.go b/azurerm/internal/services/batch/resource_arm_batch_account.go index 46f437a3c8b9..477a599ca048 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_account.go +++ b/azurerm/internal/services/batch/resource_arm_batch_account.go @@ -42,7 +42,7 @@ func resourceArmBatchAccount() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureRMBatchAccountName, + ValidateFunc: ValidateAzureRMBatchAccountName, }, // TODO: make this case sensitive once this API bug has been fixed: @@ -303,7 +303,7 @@ func resourceArmBatchAccountDelete(d *schema.ResourceData, meta interface{}) err return nil } -func validateAzureRMBatchAccountName(v interface{}, k string) (warnings []string, errors []error) { +func ValidateAzureRMBatchAccountName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^[a-z0-9]+$`).MatchString(value) { errors = append(errors, fmt.Errorf("lowercase letters and numbers only are allowed in %q: %q", k, value)) diff --git a/azurerm/internal/services/batch/resource_arm_batch_application.go b/azurerm/internal/services/batch/resource_arm_batch_application.go index 5b29b32e927a..b2b7412d2307 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_application.go +++ b/azurerm/internal/services/batch/resource_arm_batch_application.go @@ -48,7 +48,7 @@ func resourceArmBatchApplication() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureRMBatchAccountName, + ValidateFunc: ValidateAzureRMBatchAccountName, }, "allow_updates": { diff --git a/azurerm/internal/services/batch/resource_arm_batch_certificate.go b/azurerm/internal/services/batch/resource_arm_batch_certificate.go index 43629793dafe..4de220e39dd4 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_certificate.go +++ b/azurerm/internal/services/batch/resource_arm_batch_certificate.go @@ -45,7 +45,7 @@ func resourceArmBatchCertificate() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureRMBatchAccountName, + ValidateFunc: ValidateAzureRMBatchAccountName, }, // TODO: make this case sensitive once this API bug has been fixed: diff --git a/azurerm/internal/services/batch/resource_arm_batch_pool.go b/azurerm/internal/services/batch/resource_arm_batch_pool.go index 45e4d40213c9..bdc9b356c500 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_pool.go +++ b/azurerm/internal/services/batch/resource_arm_batch_pool.go @@ -55,7 +55,7 @@ func resourceArmBatchPool() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureRMBatchAccountName, + ValidateFunc: ValidateAzureRMBatchAccountName, }, "display_name": { Type: schema.TypeString, diff --git a/azurerm/internal/services/batch/data_source_batch_account_test.go b/azurerm/internal/services/batch/tests/data_source_batch_account_test.go similarity index 64% rename from azurerm/internal/services/batch/data_source_batch_account_test.go rename to azurerm/internal/services/batch/tests/data_source_batch_account_test.go index 594811e87cf4..002d6dc7e817 100644 --- a/azurerm/internal/services/batch/data_source_batch_account_test.go +++ b/azurerm/internal/services/batch/tests/data_source_batch_account_test.go @@ -1,23 +1,18 @@ -package batch +package tests import ( "fmt" "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMBatchAccount_basic(t *testing.T) { - dataSourceName := "data.azurerm_batch_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - config := testAccDataSourceAzureRMBatchAccount_basic(ri, rs, location) + data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test") + config := testAccDataSourceAzureRMBatchAccount_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,9 +21,9 @@ func TestAccDataSourceAzureRMBatchAccount_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(dataSourceName, "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr(dataSourceName, "pool_allocation_mode", "BatchService"), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "BatchService"), ), }, }, @@ -36,11 +31,8 @@ func TestAccDataSourceAzureRMBatchAccount_basic(t *testing.T) { } func TestAccDataSourceAzureRMBatchAccount_complete(t *testing.T) { - dataSourceName := "data.azurerm_batch_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - config := testAccDataSourceAzureRMBatchAccount_complete(ri, rs, location) + data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test") + config := testAccDataSourceAzureRMBatchAccount_complete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -49,11 +41,11 @@ func TestAccDataSourceAzureRMBatchAccount_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(dataSourceName, "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr(dataSourceName, "pool_allocation_mode", "BatchService"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.env", "test"), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "BatchService"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, }, @@ -61,15 +53,12 @@ func TestAccDataSourceAzureRMBatchAccount_complete(t *testing.T) { } func TestAccDataSourceAzureRMBatchAccount_userSubscription(t *testing.T) { - dataSourceName := "data.azurerm_batch_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test") tenantID := os.Getenv("ARM_TENANT_ID") subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") - config := testAccDataSourceAzureBatchAccount_userSubscription(ri, rs, location, tenantID, subscriptionID) + config := testAccDataSourceAzureBatchAccount_userSubscription(data, tenantID, subscriptionID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,17 +67,17 @@ func TestAccDataSourceAzureRMBatchAccount_userSubscription(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(dataSourceName, "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr(dataSourceName, "pool_allocation_mode", "UserSubscription"), - resource.TestCheckResourceAttr(dataSourceName, "key_vault_reference.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "UserSubscription"), + resource.TestCheckResourceAttr(data.ResourceName, "key_vault_reference.#", "1"), ), }, }, }) } -func testAccDataSourceAzureRMBatchAccount_basic(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMBatchAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccRG-%d-batch" @@ -106,10 +95,10 @@ data "azurerm_batch_account" "test" { name = "${azurerm_batch_account.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccDataSourceAzureRMBatchAccount_complete(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMBatchAccount_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccRG-%d-batch" @@ -140,10 +129,10 @@ data "azurerm_batch_account" "test" { name = "${azurerm_batch_account.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccDataSourceAzureBatchAccount_userSubscription(rInt int, rString string, location string, tenantID string, subscriptionID string) string { +func testAccDataSourceAzureBatchAccount_userSubscription(data acceptance.TestData, tenantID string, subscriptionID string) string { return fmt.Sprintf(` data "azurerm_azuread_service_principal" "test" { display_name = "Microsoft Azure Batch" @@ -204,5 +193,5 @@ data "azurerm_batch_account" "test" { name = "${azurerm_batch_account.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rString, tenantID, tenantID, subscriptionID, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, tenantID, tenantID, subscriptionID, data.RandomString) } diff --git a/azurerm/internal/services/batch/tests/data_source_batch_certificate_test.go b/azurerm/internal/services/batch/tests/data_source_batch_certificate_test.go new file mode 100644 index 000000000000..460b8ed455e9 --- /dev/null +++ b/azurerm/internal/services/batch/tests/data_source_batch_certificate_test.go @@ -0,0 +1,64 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMBatchCertificate_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_batch_certificate", "test") + config := testAccDataSourceAzureRMBatchCertificate_basic(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "name", "sha1-42c107874fd0e4a9583292a2f1098e8fe4b2edda"), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "format", "Pfx"), + resource.TestCheckResourceAttr(data.ResourceName, "public_data", "MIIFqzCCA5OgAwIBAgIJAMs4jwMPq7T1MA0GCSqGSIb3DQEBCwUAMGwxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApTb21lLVN0YXRlMRgwFgYDVQQKDA9UZXJyYWZvcm0gVGVzdHMxDjAMBgNVBAsMBUF6dXJlMR4wHAYDVQQDDBVUZXJyYWZvcm0gQXBwIEdhdGV3YXkwHhcNMTYxMTAxMTcxOTEyWhcNMjYxMDMwMTcxOTEyWjBsMQswCQYDVQQGEwJVUzETMBEGA1UECAwKU29tZS1TdGF0ZTEYMBYGA1UECgwPVGVycmFmb3JtIFRlc3RzMQ4wDAYDVQQLDAVBenVyZTEeMBwGA1UEAwwVVGVycmFmb3JtIEFwcCBHYXRld2F5MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA49HW2pYIlW/mlaadLA1AsXiV48xVhXAvGVk3DEl1ffjp5bN8rap5WV1D83uMg1Ii7CJM8yNHkRkvN8n5WXFng4R5V1jPxGOTAj+xLybvEASi++GZelWdpOuMk8/nAoKPMbQ5NyKFy5WzlOduMldR7Awt2pwdId3akqm1i9ITG9Js+4P4nYXM8vfJCajILqi4YfhEoCNvS1EUgvlpSFE7pfNhc2W+zsfUWxWmB2SpWwX9MgQ1D4OmdKp+Eo+b6vzst3XArKMHMadPTUAk8H+ZgAnlX9yO+3vQ6z86vma/WgrG2LH6GCGXBjmKlhxVCPMLA5LeRUwEGc/Q7X/ClitGWY9umPN1XVj5e5Di1K2M082Y14mgbTTRTpv/nx7Xlph+MHnVhEWvaGMpqCHuM1W1y7wIS1IREYQ2q+K54xxZSPKYJMSnmj6A0hR/LBV0rL1uVhedEpdviduuO76qCyZrGG4HwBlW4hnIaahLzgqlvlmbDUQonAVPDgi3brVdXJgLv2zi7/ZHFW3IHgDylUVIdig0ccbzxKymlkGQ0RsLBjWOyxak2J8bN5JNVyxSwX43NZqxJ8yOv5xjB+rVMri9SX3Dl5NbFzOjynov601Pmwvb7zYnyttG2Hl5EKrkahjijGRjGy3EWEiBiArLkdTKCDHBlHxykTEvY6ZH5B9waP0CAwEAAaNQME4wHQYDVR0OBBYEFD2/Hq3IivZ5RMOKrPsM7ijIFHmMMB8GA1UdIwQYMBaAFD2/Hq3IivZ5RMOKrPsM7ijIFHmMMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggIBAKxHWO/Q4labjnCVxYi+kaMRCPJUdHj7lga8yi8EGHaL+CbwynkaiyTfPvtmcqiuaZM9BaXsuNMRcHMtXM0EHBsjViwAHk6SrqLXd/opFvMI2QbG93koFUCpczrpyO9GvnRN4iOIYbSPXAdGOB6bkpMbm/XajORoDrua+/ET/X/1FP0GZBTmEFwojuCfOI/VuJXj0OW8XzkLmsXiLpOiakjU1obBup/1lz9DtOEBsiB9Ury+f5gZ+FnZuqhgQxeDxlZ69P6YYAfkzhcfbf7HO+nMKhppAj1BFeR4SBb+F/fLchCGO5yohwkxWz3i2q9gTDhBgo31416viyCKFWSVW3Vn7jbsjZ+Q9MK1jVSOSxC7qoQkRoNy9SKpqylunXZb+K6F3HfBkDQvn3OwsxYiSOcX9JaWpQAInNIZVg+WrJ1PXm8PFIaVPJfMgP3GOdm9vRAMjOM5Bc9iqGr2spimFd5h0GmgLvh35B3jHHWF4i3NupJQ6hUvHQZtYZOxfwxnY0/LVBTyLTVlniFA7dGSI+5Uexm+Pjh7IMGI532jTONlfNm9Bz/jdf1o0FlOclzG6Eif22gml3GM3xCUVlaElylYNAjO2lfvZuRVo5GKdMwtV9acNl0OwSx+0zbMYY2Ni3jQCI4kOL5Csctryf0rHXTlCCvnzBYVDPKmFJPna61T"), + resource.TestCheckResourceAttr(data.ResourceName, "thumbprint", "42c107874fd0e4a9583292a2f1098e8fe4b2edda"), + resource.TestCheckResourceAttr(data.ResourceName, "thumbprint_algorithm", "sha1"), // api now always returns this as lowercase + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMBatchCertificate_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "testaccbatch%d" + location = "%s" +} + +resource "azurerm_batch_account" "test" { + name = "testaccbatch%s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + pool_allocation_mode = "BatchService" +} + +resource "azurerm_batch_certificate" "test" { + resource_group_name = "${azurerm_resource_group.test.name}" + account_name = "${azurerm_batch_account.test.name}" + certificate = "${filebase64("testdata/batch_certificate.pfx")}" + format = "Pfx" + password = "terraform" + thumbprint = "42c107874fd0e4a9583292a2f1098e8fe4b2edda" + thumbprint_algorithm = "SHA1" +} + +data "azurerm_batch_certificate" "test" { + name = "${azurerm_batch_certificate.test.name}" + account_name = "${azurerm_batch_account.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} diff --git a/azurerm/internal/services/batch/tests/data_source_batch_pool_test.go b/azurerm/internal/services/batch/tests/data_source_batch_pool_test.go new file mode 100644 index 000000000000..919245180fe9 --- /dev/null +++ b/azurerm/internal/services/batch/tests/data_source_batch_pool_test.go @@ -0,0 +1,160 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" +) + +func TestAccDataSourceAzureRMBatchPool_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_batch_pool", "test") + config := testAccDataSourceAzureRMBatchPool_complete(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testaccpool%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.publisher", "microsoft-azure-batch"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.sku", "16-04-lts"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.offer", "ubuntu-server-container"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_dedicated_nodes", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.resize_timeout", "PT15M"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_low_priority_nodes", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), + resource.TestCheckResourceAttr(data.ResourceName, "max_tasks_per_node", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.max_task_retry_count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.environment.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.environment.env", "TEST"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.user_identity.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.user_identity.0.auto_user.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.user_identity.0.auto_user.0.scope", "Task"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.user_identity.0.auto_user.0.elevation_level", "NonAdmin"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "certificate.0.id"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.store_location", "CurrentUser"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.store_name", ""), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.visibility.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.visibility.3294600504", "StartTask"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.visibility.4077195354", "RemoteUser"), + resource.TestCheckResourceAttr(data.ResourceName, "container_configuration.0.type", "DockerCompatible"), + resource.TestCheckResourceAttr(data.ResourceName, "container_configuration.0.container_registries.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container_configuration.0.container_registries.0.registry_server", "myContainerRegistry.azurecr.io"), + resource.TestCheckResourceAttr(data.ResourceName, "container_configuration.0.container_registries.0.user_name", "myUserName"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMBatchPool_complete(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "testaccRG-%d-batch" + location = "%s" +} + +resource "azurerm_storage_account" "test" { + name = "testaccsa%s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_batch_account" "test" { + name = "testaccbatch%s" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + pool_allocation_mode = "BatchService" + storage_account_id = "${azurerm_storage_account.test.id}" + + tags = { + env = "test" + } +} + +resource "azurerm_batch_certificate" "test" { + resource_group_name = "${azurerm_resource_group.test.name}" + account_name = "${azurerm_batch_account.test.name}" + certificate = "${filebase64("testdata/batch_certificate.pfx")}" + format = "Pfx" + password = "terraform" + thumbprint = "42c107874fd0e4a9583292a2f1098e8fe4b2edda" + thumbprint_algorithm = "SHA1" +} + +resource "azurerm_batch_pool" "test" { + name = "testaccpool%s" + resource_group_name = "${azurerm_resource_group.test.name}" + account_name = "${azurerm_batch_account.test.name}" + display_name = "Test Acc Pool" + vm_size = "Standard_A1" + node_agent_sku_id = "batch.node.ubuntu 16.04" + max_tasks_per_node = 2 + + fixed_scale { + target_dedicated_nodes = 2 + resize_timeout = "PT15M" + } + + storage_image_reference { + publisher = "microsoft-azure-batch" + offer = "ubuntu-server-container" + sku = "16-04-lts" + version = "latest" + } + + certificate { + id = "${azurerm_batch_certificate.test.id}" + store_location = "CurrentUser" + visibility = ["StartTask", "RemoteUser"] + } + + container_configuration { + type = "DockerCompatible" + container_registries = [ + { + registry_server = "myContainerRegistry.azurecr.io" + user_name = "myUserName" + password = "myPassword" + }, + ] + } + + start_task { + command_line = "echo 'Hello World from $env'" + max_task_retry_count = 1 + wait_for_success = true + + environment = { + env = "TEST" + } + + user_identity { + auto_user { + elevation_level = "NonAdmin" + scope = "Task" + } + } + } +} + +data "azurerm_batch_pool" "test" { + name = "${azurerm_batch_pool.test.name}" + account_name = "${azurerm_batch_pool.test.account_name}" + resource_group_name = "${azurerm_batch_pool.test.resource_group_name}" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString) +} diff --git a/azurerm/internal/services/batch/resource_arm_batch_account_test.go b/azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go similarity index 73% rename from azurerm/internal/services/batch/resource_arm_batch_account_test.go rename to azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go index 5872a11c2d75..810a449b738c 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_account_test.go +++ b/azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go @@ -1,15 +1,14 @@ -package batch +package tests import ( "fmt" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/batch" "net/http" "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -30,7 +29,7 @@ func TestValidateBatchAccountName(t *testing.T) { } for _, test := range testCases { - _, es := validateAzureRMBatchAccountName(test.input, "name") + _, es := batch.ValidateAzureRMBatchAccountName(test.input, "name") if test.shouldError && len(es) == 0 { t.Fatalf("Expected validating name %q to fail", test.input) @@ -43,12 +42,9 @@ func TestValidateBatchAccountName(t *testing.T) { } func TestAccAzureRMBatchAccount_basic(t *testing.T) { - resourceName := "azurerm_batch_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test") - config := testAccAzureRMBatchAccount_basic(ri, rs, location) + config := testAccAzureRMBatchAccount_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -58,8 +54,8 @@ func TestAccAzureRMBatchAccount_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "pool_allocation_mode", "BatchService"), + testCheckAzureRMBatchAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "BatchService"), ), }, }, @@ -71,12 +67,7 @@ func TestAccAzureRMBatchAccount_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_batch_account.test" - ri := tf.AccRandTimeInt() - - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,13 +75,13 @@ func TestAccAzureRMBatchAccount_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMBatchAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBatchAccount_basic(ri, rs, location), + Config: testAccAzureRMBatchAccount_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchAccountExists(resourceName), + testCheckAzureRMBatchAccountExists(data.ResourceName), ), }, { - Config: testAccAzureRMBatchAccount_requiresImport(ri, rs, location), + Config: testAccAzureRMBatchAccount_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_batch_account"), }, }, @@ -98,13 +89,10 @@ func TestAccAzureRMBatchAccount_requiresImport(t *testing.T) { } func TestAccAzureRMBatchAccount_complete(t *testing.T) { - resourceName := "azurerm_batch_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test") - config := testAccAzureRMBatchAccount_complete(ri, rs, location) - configUpdate := testAccAzureRMBatchAccount_completeUpdated(ri, rs, location) + config := testAccAzureRMBatchAccount_complete(data) + configUpdate := testAccAzureRMBatchAccount_completeUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,20 +102,20 @@ func TestAccAzureRMBatchAccount_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "pool_allocation_mode", "BatchService"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMBatchAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "BatchService"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, { Config: configUpdate, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "pool_allocation_mode", "BatchService"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), - resource.TestCheckResourceAttr(resourceName, "tags.version", "2"), + testCheckAzureRMBatchAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "BatchService"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.version", "2"), ), }, }, @@ -135,14 +123,9 @@ func TestAccAzureRMBatchAccount_complete(t *testing.T) { } func TestAccAzureRMBatchAccount_userSubscription(t *testing.T) { - resourceName := "azurerm_batch_account.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "data.azurerm_batch_account", "test") tenantID := os.Getenv("ARM_TENANT_ID") - - config := testAccAzureRMBatchAccount_userSubscription(ri, rs, location, tenantID) + config := testAccAzureRMBatchAccount_userSubscription(data, tenantID) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -152,8 +135,8 @@ func TestAccAzureRMBatchAccount_userSubscription(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "pool_allocation_mode", "UserSubscription"), + testCheckAzureRMBatchAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "pool_allocation_mode", "UserSubscription"), ), }, }, @@ -213,7 +196,7 @@ func testCheckAzureRMBatchAccountDestroy(s *terraform.State) error { return nil } -func testAccAzureRMBatchAccount_basic(rInt int, batchAccountSuffix string, location string) string { +func testAccAzureRMBatchAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccRG-%d-batchaccount" @@ -226,11 +209,11 @@ resource "azurerm_batch_account" "test" { location = "${azurerm_resource_group.test.location}" pool_allocation_mode = "BatchService" } -`, rInt, location, batchAccountSuffix) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMBatchAccount_requiresImport(rInt int, batchAccountSuffix string, location string) string { - template := testAccAzureRMBatchAccount_basic(rInt, batchAccountSuffix, location) +func testAccAzureRMBatchAccount_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMBatchAccount_basic(data) return fmt.Sprintf(` %s resource "azurerm_batch_account" "import" { @@ -242,7 +225,7 @@ resource "azurerm_batch_account" "import" { `, template) } -func testAccAzureRMBatchAccount_complete(rInt int, rString string, location string) string { +func testAccAzureRMBatchAccount_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccRG-%d-batchaccount" @@ -268,10 +251,10 @@ resource "azurerm_batch_account" "test" { env = "test" } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMBatchAccount_completeUpdated(rInt int, rString string, location string) string { +func testAccAzureRMBatchAccount_completeUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccRG-%d-batchaccount" @@ -298,10 +281,10 @@ resource "azurerm_batch_account" "test" { version = "2" } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccAzureRMBatchAccount_userSubscription(rInt int, batchAccountSuffix string, location string, tenantID string) string { +func testAccAzureRMBatchAccount_userSubscription(data acceptance.TestData, tenantID string) string { return fmt.Sprintf(` data "azuread_service_principal" "test" { display_name = "Microsoft Azure Batch" @@ -351,5 +334,5 @@ resource "azurerm_batch_account" "test" { url = "${azurerm_key_vault.test.vault_uri}" } } -`, rInt, location, batchAccountSuffix, tenantID, tenantID, batchAccountSuffix) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, tenantID, tenantID, data.RandomString) } diff --git a/azurerm/internal/services/batch/resource_arm_batch_application_test.go b/azurerm/internal/services/batch/tests/resource_arm_batch_application_test.go similarity index 74% rename from azurerm/internal/services/batch/resource_arm_batch_application_test.go rename to azurerm/internal/services/batch/tests/resource_arm_batch_application_test.go index e845d74cfaf8..d1248c502a56 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_application_test.go +++ b/azurerm/internal/services/batch/tests/resource_arm_batch_application_test.go @@ -1,24 +1,18 @@ -package batch +package tests import ( "fmt" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMBatchApplication_basic(t *testing.T) { - resourceName := "azurerm_batch_application.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_batch_application", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,26 +20,19 @@ func TestAccAzureRMBatchApplication_basic(t *testing.T) { CheckDestroy: testCheckAzureRMBatchApplicationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBatchApplication_template(ri, rs, location, ""), + Config: testAccAzureRMBatchApplication_template(data, ""), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchApplicationExists(resourceName), + testCheckAzureRMBatchApplicationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMBatchApplication_update(t *testing.T) { - resourceName := "azurerm_batch_application.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() - displayName := fmt.Sprintf("TestAccDisplayName-%d", ri) + data := acceptance.BuildTestData(t, "azurerm_batch_application", "test") + displayName := fmt.Sprintf("TestAccDisplayName-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,16 +40,16 @@ func TestAccAzureRMBatchApplication_update(t *testing.T) { CheckDestroy: testCheckAzureRMBatchApplicationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBatchApplication_template(ri, rs, location, ""), + Config: testAccAzureRMBatchApplication_template(data, ""), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchApplicationExists(resourceName), + testCheckAzureRMBatchApplicationExists(data.ResourceName), ), }, { - Config: testAccAzureRMBatchApplication_template(ri, rs, location, fmt.Sprintf(`display_name = "%s"`, displayName)), + Config: testAccAzureRMBatchApplication_template(data, fmt.Sprintf(`display_name = "%s"`, displayName)), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchApplicationExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "display_name", displayName), + testCheckAzureRMBatchApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "display_name", displayName), ), }, }, @@ -119,7 +106,7 @@ func testCheckAzureRMBatchApplicationDestroy(s *terraform.State) error { return nil } -func testAccAzureRMBatchApplication_template(rInt int, rString string, location string, displayName string) string { +func testAccAzureRMBatchApplication_template(data acceptance.TestData, displayName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -148,5 +135,5 @@ resource "azurerm_batch_application" "test" { account_name = "${azurerm_batch_account.test.name}" %s } -`, rInt, location, rString, rString, rInt, displayName) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, displayName) } diff --git a/azurerm/internal/services/batch/resource_arm_batch_certificate_test.go b/azurerm/internal/services/batch/tests/resource_arm_batch_certificate_test.go similarity index 74% rename from azurerm/internal/services/batch/resource_arm_batch_certificate_test.go rename to azurerm/internal/services/batch/tests/resource_arm_batch_certificate_test.go index e5fad946ca93..ba35c12051f4 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_certificate_test.go +++ b/azurerm/internal/services/batch/tests/resource_arm_batch_certificate_test.go @@ -1,4 +1,4 @@ -package batch +package tests import ( "fmt" @@ -6,25 +6,18 @@ import ( "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMBatchCertificate_Pfx(t *testing.T) { - resourceName := "azurerm_batch_certificate.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_batch_certificate", "test") subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") - certificateID := fmt.Sprintf("/subscriptions/%s/resourceGroups/testaccbatch%d/providers/Microsoft.Batch/batchAccounts/testaccbatch%s/certificates/sha1-42c107874fd0e4a9583292a2f1098e8fe4b2edda", subscriptionID, ri, rs) - - config := testAccAzureRMBatchCertificatePfx(ri, rs, location) + certificateID := fmt.Sprintf("/subscriptions/%s/resourceGroups/testaccbatch%d/providers/Microsoft.Batch/batchAccounts/testaccbatch%s/certificates/sha1-42c107874fd0e4a9583292a2f1098e8fe4b2edda", subscriptionID, data.RandomInteger, data.RandomString) + config := testAccAzureRMBatchCertificatePfx(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -34,14 +27,14 @@ func TestAccAzureRMBatchCertificate_Pfx(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "id", certificateID), - resource.TestCheckResourceAttr(resourceName, "format", "Pfx"), - resource.TestCheckResourceAttr(resourceName, "thumbprint", "42c107874fd0e4a9583292a2f1098e8fe4b2edda"), - resource.TestCheckResourceAttr(resourceName, "thumbprint_algorithm", "sha1"), + resource.TestCheckResourceAttr(data.ResourceName, "id", certificateID), + resource.TestCheckResourceAttr(data.ResourceName, "format", "Pfx"), + resource.TestCheckResourceAttr(data.ResourceName, "thumbprint", "42c107874fd0e4a9583292a2f1098e8fe4b2edda"), + resource.TestCheckResourceAttr(data.ResourceName, "thumbprint_algorithm", "sha1"), ), }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"certificate", "password"}, @@ -51,11 +44,8 @@ func TestAccAzureRMBatchCertificate_Pfx(t *testing.T) { } func TestAccAzureRMBatchCertificate_PfxWithoutPassword(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - - config := testAccAzureRMBatchCertificatePfxWithoutPassword(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_batch_certificate", "test") + config := testAccAzureRMBatchCertificatePfxWithoutPassword(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -71,15 +61,11 @@ func TestAccAzureRMBatchCertificate_PfxWithoutPassword(t *testing.T) { } func TestAccAzureRMBatchCertificate_Cer(t *testing.T) { - resourceName := "azurerm_batch_certificate.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_batch_certificate", "test") subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") - certificateID := fmt.Sprintf("/subscriptions/%s/resourceGroups/testaccbatch%d/providers/Microsoft.Batch/batchAccounts/testaccbatch%s/certificates/sha1-312d31a79fa0cef49c00f769afc2b73e9f4edf34", subscriptionID, ri, rs) + certificateID := fmt.Sprintf("/subscriptions/%s/resourceGroups/testaccbatch%d/providers/Microsoft.Batch/batchAccounts/testaccbatch%s/certificates/sha1-312d31a79fa0cef49c00f769afc2b73e9f4edf34", subscriptionID, data.RandomInteger, data.RandomString) - config := testAccAzureRMBatchCertificateCer(ri, rs, location) + config := testAccAzureRMBatchCertificateCer(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -90,10 +76,10 @@ func TestAccAzureRMBatchCertificate_Cer(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "id", certificateID), - resource.TestCheckResourceAttr(resourceName, "format", "Cer"), - resource.TestCheckResourceAttr(resourceName, "thumbprint", "312d31a79fa0cef49c00f769afc2b73e9f4edf34"), - resource.TestCheckResourceAttr(resourceName, "thumbprint_algorithm", "sha1"), + resource.TestCheckResourceAttr(data.ResourceName, "id", certificateID), + resource.TestCheckResourceAttr(data.ResourceName, "format", "Cer"), + resource.TestCheckResourceAttr(data.ResourceName, "thumbprint", "312d31a79fa0cef49c00f769afc2b73e9f4edf34"), + resource.TestCheckResourceAttr(data.ResourceName, "thumbprint_algorithm", "sha1"), ), }, data.ImportStep("certificate"), @@ -102,11 +88,8 @@ func TestAccAzureRMBatchCertificate_Cer(t *testing.T) { } func TestAccAzureRMBatchCertificate_CerWithPassword(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() - - config := testAccAzureRMBatchCertificateCerWithPassword(ri, rs, location) + data := acceptance.BuildTestData(t, "azurerm_batch_certificate", "test") + config := testAccAzureRMBatchCertificateCerWithPassword(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -121,7 +104,7 @@ func TestAccAzureRMBatchCertificate_CerWithPassword(t *testing.T) { }) } -func testAccAzureRMBatchCertificatePfx(rInt int, batchAccountSuffix string, location string) string { +func testAccAzureRMBatchCertificatePfx(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccbatch%d" @@ -144,10 +127,10 @@ resource "azurerm_batch_certificate" "test" { thumbprint = "42c107874fd0e4a9583292a2f1098e8fe4b2edda" thumbprint_algorithm = "SHA1" } -`, rInt, location, batchAccountSuffix) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMBatchCertificatePfxWithoutPassword(rInt int, batchAccountSuffix string, location string) string { +func testAccAzureRMBatchCertificatePfxWithoutPassword(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccbatch%d" @@ -169,9 +152,9 @@ resource "azurerm_batch_certificate" "test" { thumbprint = "42c107874fd0e4a9583292a2f1098e8fe4b2edda" thumbprint_algorithm = "SHA1" } -`, rInt, location, batchAccountSuffix) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMBatchCertificateCer(rInt int, batchAccountSuffix string, location string) string { +func testAccAzureRMBatchCertificateCer(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccbatch%d" @@ -193,9 +176,9 @@ resource "azurerm_batch_certificate" "test" { thumbprint = "312d31a79fa0cef49c00f769afc2b73e9f4edf34" thumbprint_algorithm = "SHA1" } -`, rInt, location, batchAccountSuffix) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccAzureRMBatchCertificateCerWithPassword(rInt int, batchAccountSuffix string, location string) string { +func testAccAzureRMBatchCertificateCerWithPassword(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccbatch%d" @@ -218,7 +201,7 @@ resource "azurerm_batch_certificate" "test" { thumbprint = "312d31a79fa0cef49c00f769afc2b73e9f4edf34" thumbprint_algorithm = "SHA1" } -`, rInt, location, batchAccountSuffix) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } func testCheckAzureRMBatchCertificateDestroy(s *terraform.State) error { diff --git a/azurerm/internal/services/batch/resource_arm_batch_pool_test.go b/azurerm/internal/services/batch/tests/resource_arm_batch_pool_test.go similarity index 62% rename from azurerm/internal/services/batch/resource_arm_batch_pool_test.go rename to azurerm/internal/services/batch/tests/resource_arm_batch_pool_test.go index 208e5ae1e959..cf3efecce0de 100644 --- a/azurerm/internal/services/batch/resource_arm_batch_pool_test.go +++ b/azurerm/internal/services/batch/tests/resource_arm_batch_pool_test.go @@ -1,4 +1,4 @@ -package batch +package tests import ( "fmt" @@ -7,21 +7,16 @@ import ( "regexp" "testing" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "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/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMBatchPool_basic(t *testing.T) { - resourceName := "azurerm_batch_pool.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,19 +24,19 @@ func TestAccAzureRMBatchPool_basic(t *testing.T) { CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPool_basic(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vm_size", "STANDARD_A1"), - resource.TestCheckResourceAttr(resourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(resourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.offer", "UbuntuServer"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.#", "1"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.target_dedicated_nodes", "1"), - resource.TestCheckResourceAttr(resourceName, "start_task.#", "0"), + testCheckAzureRMBatchPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.offer", "UbuntuServer"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_dedicated_nodes", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.#", "0"), ), }, }, @@ -53,10 +48,7 @@ func TestAccAzureRMBatchPool_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - - resourceName := "azurerm_batch_pool.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -64,23 +56,23 @@ func TestAccAzureRMBatchPool_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPool_basic(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPool_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vm_size", "STANDARD_A1"), - resource.TestCheckResourceAttr(resourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(resourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.offer", "UbuntuServer"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.#", "1"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.target_dedicated_nodes", "1"), - resource.TestCheckResourceAttr(resourceName, "start_task.#", "0"), + testCheckAzureRMBatchPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.offer", "UbuntuServer"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_dedicated_nodes", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.#", "0"), ), }, { - Config: testaccAzureRMBatchPool_requiresImport(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPool_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_batch_account"), }, }, @@ -88,9 +80,7 @@ func TestAccAzureRMBatchPool_requiresImport(t *testing.T) { } func TestAccAzureRMBatchPool_fixedScale_complete(t *testing.T) { - resourceName := "azurerm_batch_pool.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -98,23 +88,23 @@ func TestAccAzureRMBatchPool_fixedScale_complete(t *testing.T) { CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPool_fixedScale_complete(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPool_fixedScale_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vm_size", "STANDARD_A1"), - resource.TestCheckResourceAttr(resourceName, "max_tasks_per_node", "2"), - resource.TestCheckResourceAttr(resourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(resourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.offer", "UbuntuServer"), - resource.TestCheckResourceAttr(resourceName, "auto_scale.#", "0"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.#", "1"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.target_dedicated_nodes", "2"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.resize_timeout", "PT15M"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.target_low_priority_nodes", "0"), - resource.TestCheckResourceAttr(resourceName, "start_task.#", "0"), + testCheckAzureRMBatchPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), + resource.TestCheckResourceAttr(data.ResourceName, "max_tasks_per_node", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.offer", "UbuntuServer"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_scale.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_dedicated_nodes", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.resize_timeout", "PT15M"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_low_priority_nodes", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.#", "0"), ), }, }, @@ -122,9 +112,7 @@ func TestAccAzureRMBatchPool_fixedScale_complete(t *testing.T) { } func TestAccAzureRMBatchPool_autoScale_complete(t *testing.T) { - resourceName := "azurerm_batch_pool.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -132,20 +120,20 @@ func TestAccAzureRMBatchPool_autoScale_complete(t *testing.T) { CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPool_autoScale_complete(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPool_autoScale_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vm_size", "STANDARD_A1"), - resource.TestCheckResourceAttr(resourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(resourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.offer", "UbuntuServer"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.#", "0"), - resource.TestCheckResourceAttr(resourceName, "auto_scale.#", "1"), - resource.TestCheckResourceAttr(resourceName, "auto_scale.0.evaluation_interval", "PT15M"), - resource.TestCheckResourceAttr(resourceName, "start_task.#", "0"), + testCheckAzureRMBatchPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.offer", "UbuntuServer"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_scale.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_scale.0.evaluation_interval", "PT15M"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.#", "0"), ), }, }, @@ -153,9 +141,7 @@ func TestAccAzureRMBatchPool_autoScale_complete(t *testing.T) { } func TestAccAzureRMBatchPool_completeUpdated(t *testing.T) { - resourceName := "azurerm_batch_pool.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -163,39 +149,39 @@ func TestAccAzureRMBatchPool_completeUpdated(t *testing.T) { CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPool_fixedScale_complete(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPool_fixedScale_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vm_size", "STANDARD_A1"), - resource.TestCheckResourceAttr(resourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(resourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.offer", "UbuntuServer"), - resource.TestCheckResourceAttr(resourceName, "auto_scale.#", "0"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.#", "1"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.target_dedicated_nodes", "2"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.resize_timeout", "PT15M"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.target_low_priority_nodes", "0"), - resource.TestCheckResourceAttr(resourceName, "start_task.#", "0"), + testCheckAzureRMBatchPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.offer", "UbuntuServer"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_scale.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_dedicated_nodes", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.resize_timeout", "PT15M"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_low_priority_nodes", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.#", "0"), ), }, { - Config: testaccAzureRMBatchPool_autoScale_complete(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPool_autoScale_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vm_size", "STANDARD_A1"), - resource.TestCheckResourceAttr(resourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(resourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.offer", "UbuntuServer"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.#", "0"), - resource.TestCheckResourceAttr(resourceName, "auto_scale.#", "1"), - resource.TestCheckResourceAttr(resourceName, "auto_scale.0.evaluation_interval", "PT15M"), - resource.TestCheckResourceAttr(resourceName, "start_task.#", "0"), + testCheckAzureRMBatchPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.offer", "UbuntuServer"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_scale.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_scale.0.evaluation_interval", "PT15M"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.#", "0"), ), }, }, @@ -203,9 +189,7 @@ func TestAccAzureRMBatchPool_completeUpdated(t *testing.T) { } func TestAccAzureRMBatchPoolStartTask_basic(t *testing.T) { - resourceName := "azurerm_batch_pool.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -213,30 +197,30 @@ func TestAccAzureRMBatchPoolStartTask_basic(t *testing.T) { CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPoolStartTask_basic(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPoolStartTask_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vm_size", "STANDARD_A1"), - resource.TestCheckResourceAttr(resourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(resourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), - resource.TestCheckResourceAttr(resourceName, "storage_image_reference.0.offer", "UbuntuServer"), - resource.TestCheckResourceAttr(resourceName, "auto_scale.#", "0"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.#", "1"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.target_dedicated_nodes", "1"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.resize_timeout", "PT15M"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.target_low_priority_nodes", "0"), - resource.TestCheckResourceAttr(resourceName, "start_task.#", "1"), - resource.TestCheckResourceAttr(resourceName, "start_task.0.max_task_retry_count", "1"), - resource.TestCheckResourceAttr(resourceName, "start_task.0.environment.%", "2"), - resource.TestCheckResourceAttr(resourceName, "start_task.0.environment.env", "TEST"), - resource.TestCheckResourceAttr(resourceName, "start_task.0.environment.bu", "Research&Dev"), - resource.TestCheckResourceAttr(resourceName, "start_task.0.user_identity.#", "1"), - resource.TestCheckResourceAttr(resourceName, "start_task.0.user_identity.0.auto_user.#", "1"), - resource.TestCheckResourceAttr(resourceName, "start_task.0.user_identity.0.auto_user.0.scope", "Task"), - resource.TestCheckResourceAttr(resourceName, "start_task.0.user_identity.0.auto_user.0.elevation_level", "NonAdmin"), + testCheckAzureRMBatchPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.offer", "UbuntuServer"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_scale.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_dedicated_nodes", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.resize_timeout", "PT15M"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_low_priority_nodes", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.max_task_retry_count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.environment.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.environment.env", "TEST"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.environment.bu", "Research&Dev"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.user_identity.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.user_identity.0.auto_user.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.user_identity.0.auto_user.0.scope", "Task"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.0.user_identity.0.auto_user.0.elevation_level", "NonAdmin"), ), }, }, @@ -244,13 +228,11 @@ func TestAccAzureRMBatchPoolStartTask_basic(t *testing.T) { } func TestAccAzureRMBatchPool_certificates(t *testing.T) { - resourceName := "azurerm_batch_pool.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") - certificate0ID := fmt.Sprintf("/subscriptions/%s/resourceGroups/testaccbatch%d/providers/Microsoft.Batch/batchAccounts/testaccbatch%s/certificates/sha1-312d31a79fa0cef49c00f769afc2b73e9f4edf34", subscriptionID, ri, rs) - certificate1ID := fmt.Sprintf("/subscriptions/%s/resourceGroups/testaccbatch%d/providers/Microsoft.Batch/batchAccounts/testaccbatch%s/certificates/sha1-42c107874fd0e4a9583292a2f1098e8fe4b2edda", subscriptionID, ri, rs) + certificate0ID := fmt.Sprintf("/subscriptions/%s/resourceGroups/testaccbatch%d/providers/Microsoft.Batch/batchAccounts/testaccbatch%s/certificates/sha1-312d31a79fa0cef49c00f769afc2b73e9f4edf34", subscriptionID, data.RandomInteger, data.RandomString) + certificate1ID := fmt.Sprintf("/subscriptions/%s/resourceGroups/testaccbatch%d/providers/Microsoft.Batch/batchAccounts/testaccbatch%s/certificates/sha1-42c107874fd0e4a9583292a2f1098e8fe4b2edda", subscriptionID, data.RandomInteger, data.RandomString) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -258,24 +240,24 @@ func TestAccAzureRMBatchPool_certificates(t *testing.T) { CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPoolCertificates(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPoolCertificates(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vm_size", "STANDARD_A1"), - resource.TestCheckResourceAttr(resourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(resourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(resourceName, "certificate.#", "2"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.id", certificate0ID), - resource.TestCheckResourceAttr(resourceName, "certificate.0.store_location", "CurrentUser"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.store_name", ""), - resource.TestCheckResourceAttr(resourceName, "certificate.0.visibility.#", "1"), - resource.TestCheckResourceAttr(resourceName, "certificate.0.visibility.3294600504", "StartTask"), - resource.TestCheckResourceAttr(resourceName, "certificate.1.id", certificate1ID), - resource.TestCheckResourceAttr(resourceName, "certificate.1.store_location", "CurrentUser"), - resource.TestCheckResourceAttr(resourceName, "certificate.1.store_name", ""), - resource.TestCheckResourceAttr(resourceName, "certificate.1.visibility.#", "2"), - resource.TestCheckResourceAttr(resourceName, "certificate.1.visibility.3294600504", "StartTask"), - resource.TestCheckResourceAttr(resourceName, "certificate.1.visibility.4077195354", "RemoteUser"), + testCheckAzureRMBatchPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), + resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.id", certificate0ID), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.store_location", "CurrentUser"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.store_name", ""), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.visibility.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.0.visibility.3294600504", "StartTask"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.1.id", certificate1ID), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.1.store_location", "CurrentUser"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.1.store_name", ""), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.1.visibility.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.1.visibility.3294600504", "StartTask"), + resource.TestCheckResourceAttr(data.ResourceName, "certificate.1.visibility.4077195354", "RemoteUser"), ), }, }, @@ -283,8 +265,7 @@ func TestAccAzureRMBatchPool_certificates(t *testing.T) { } func TestAccAzureRMBatchPool_validateResourceFileWithoutSource(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -292,7 +273,7 @@ func TestAccAzureRMBatchPool_validateResourceFileWithoutSource(t *testing.T) { CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPoolValidateResourceFileWithoutSource(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPoolValidateResourceFileWithoutSource(data), ExpectError: regexp.MustCompile("Exactly one of auto_storage_container_name, storage_container_url and http_url must be specified"), }, }, @@ -300,9 +281,7 @@ func TestAccAzureRMBatchPool_validateResourceFileWithoutSource(t *testing.T) { } func TestAccAzureRMBatchPool_container(t *testing.T) { - resourceName := "azurerm_batch_pool.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -310,14 +289,14 @@ func TestAccAzureRMBatchPool_container(t *testing.T) { CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPoolContainerConfiguration(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPoolContainerConfiguration(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "container_configuration.0.type", "DockerCompatible"), - resource.TestCheckResourceAttr(resourceName, "container_configuration.0.container_registries.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container_configuration.0.container_registries.0.registry_server", "myContainerRegistry.azurecr.io"), - resource.TestCheckResourceAttr(resourceName, "container_configuration.0.container_registries.0.user_name", "myUserName"), - resource.TestCheckResourceAttr(resourceName, "container_configuration.0.container_registries.0.password", "myPassword"), + testCheckAzureRMBatchPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "container_configuration.0.type", "DockerCompatible"), + resource.TestCheckResourceAttr(data.ResourceName, "container_configuration.0.container_registries.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container_configuration.0.container_registries.0.registry_server", "myContainerRegistry.azurecr.io"), + resource.TestCheckResourceAttr(data.ResourceName, "container_configuration.0.container_registries.0.user_name", "myUserName"), + resource.TestCheckResourceAttr(data.ResourceName, "container_configuration.0.container_registries.0.password", "myPassword"), ), }, }, @@ -325,8 +304,7 @@ func TestAccAzureRMBatchPool_container(t *testing.T) { } func TestAccAzureRMBatchPool_validateResourceFileWithMultipleSources(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -334,7 +312,7 @@ func TestAccAzureRMBatchPool_validateResourceFileWithMultipleSources(t *testing. CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPoolValidateResourceFileWithMultipleSources(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPoolValidateResourceFileWithMultipleSources(data), ExpectError: regexp.MustCompile("Exactly one of auto_storage_container_name, storage_container_url and http_url must be specified"), }, }, @@ -342,8 +320,7 @@ func TestAccAzureRMBatchPool_validateResourceFileWithMultipleSources(t *testing. } func TestAccAzureRMBatchPool_validateResourceFileBlobPrefixWithoutAutoStorageContainerUrl(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -351,7 +328,7 @@ func TestAccAzureRMBatchPool_validateResourceFileBlobPrefixWithoutAutoStorageCon CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPoolValidateResourceFileBlobPrefixWithoutAutoStorageContainerName(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPoolValidateResourceFileBlobPrefixWithoutAutoStorageContainerName(data), ExpectError: regexp.MustCompile("auto_storage_container_name or storage_container_url must be specified when using blob_prefix"), }, }, @@ -359,8 +336,7 @@ func TestAccAzureRMBatchPool_validateResourceFileBlobPrefixWithoutAutoStorageCon } func TestAccAzureRMBatchPool_validateResourceFileHttpURLWithoutFilePath(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -368,7 +344,7 @@ func TestAccAzureRMBatchPool_validateResourceFileHttpURLWithoutFilePath(t *testi CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPoolValidateResourceFileHttpURLWithoutFilePath(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPoolValidateResourceFileHttpURLWithoutFilePath(data), ExpectError: regexp.MustCompile("file_path must be specified when using http_url"), }, }, @@ -376,9 +352,7 @@ func TestAccAzureRMBatchPool_validateResourceFileHttpURLWithoutFilePath(t *testi } func TestAccAzureRMBatchPool_customImage(t *testing.T) { - resourceName := "azurerm_batch_pool.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_batch_pool", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -386,19 +360,19 @@ func TestAccAzureRMBatchPool_customImage(t *testing.T) { CheckDestroy: testCheckAzureRMBatchPoolDestroy, Steps: []resource.TestStep{ { - Config: testaccAzureRMBatchPoolCustomImageConfiguration(ri, rs, acceptance.Location()), + Config: testaccAzureRMBatchPoolCustomImageConfiguration(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBatchPoolExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vm_size", "STANDARD_A1"), - resource.TestCheckResourceAttr(resourceName, "max_tasks_per_node", "2"), - resource.TestCheckResourceAttr(resourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(resourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), - resource.TestCheckResourceAttr(resourceName, "auto_scale.#", "0"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.#", "1"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.target_dedicated_nodes", "2"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.resize_timeout", "PT15M"), - resource.TestCheckResourceAttr(resourceName, "fixed_scale.0.target_low_priority_nodes", "0"), - resource.TestCheckResourceAttr(resourceName, "start_task.#", "0"), + testCheckAzureRMBatchPoolExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), + resource.TestCheckResourceAttr(data.ResourceName, "max_tasks_per_node", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), + resource.TestCheckResourceAttr(data.ResourceName, "auto_scale.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_dedicated_nodes", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.resize_timeout", "PT15M"), + resource.TestCheckResourceAttr(data.ResourceName, "fixed_scale.0.target_low_priority_nodes", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "start_task.#", "0"), ), }, }, @@ -459,7 +433,7 @@ func testCheckAzureRMBatchPoolDestroy(s *terraform.State) error { return nil } -func testaccAzureRMBatchPool_fixedScale_complete(rInt int, rString string, location string) string { +func testaccAzureRMBatchPool_fixedScale_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccRG-%d-batchpool" @@ -506,10 +480,10 @@ resource "azurerm_batch_pool" "test" { version = "latest" } } -`, rInt, location, rString, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString) } -func testaccAzureRMBatchPool_autoScale_complete(rInt int, rString string, location string) string { +func testaccAzureRMBatchPool_autoScale_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccRG-%d-batchpool" @@ -564,10 +538,10 @@ EOF version = "latest" } } -`, rInt, location, rString, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString) } -func testaccAzureRMBatchPool_basic(rInt int, rString string, location string) string { +func testaccAzureRMBatchPool_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccRG-%d-batchpool" @@ -598,10 +572,10 @@ resource "azurerm_batch_pool" "test" { version = "latest" } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testaccAzureRMBatchPool_requiresImport(rInt int, rString string, location string) string { +func testaccAzureRMBatchPool_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -623,10 +597,10 @@ resource "azurerm_batch_pool" "import" { version = "latest" } } -`, testaccAzureRMBatchPool_basic(rInt, rString, location)) +`, testaccAzureRMBatchPool_basic(data)) } -func testaccAzureRMBatchPoolStartTask_basic(rInt int, rString string, location string) string { +func testaccAzureRMBatchPoolStartTask_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccRG-%d-batchpool" @@ -680,10 +654,10 @@ resource "azurerm_batch_pool" "test" { } } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testaccAzureRMBatchPoolValidateResourceFileWithoutSource(rInt int, rString string, location string) string { +func testaccAzureRMBatchPoolValidateResourceFileWithoutSource(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccbatch%d" @@ -738,10 +712,10 @@ resource "azurerm_batch_pool" "test" { } } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testaccAzureRMBatchPoolValidateResourceFileWithMultipleSources(rInt int, rString string, location string) string { +func testaccAzureRMBatchPoolValidateResourceFileWithMultipleSources(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccbatch%d" @@ -796,10 +770,10 @@ resource "azurerm_batch_pool" "test" { } } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testaccAzureRMBatchPoolValidateResourceFileBlobPrefixWithoutAutoStorageContainerName(rInt int, rString string, location string) string { +func testaccAzureRMBatchPoolValidateResourceFileBlobPrefixWithoutAutoStorageContainerName(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccbatch%d" @@ -854,10 +828,10 @@ resource "azurerm_batch_pool" "test" { } } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testaccAzureRMBatchPoolValidateResourceFileHttpURLWithoutFilePath(rInt int, rString string, location string) string { +func testaccAzureRMBatchPoolValidateResourceFileHttpURLWithoutFilePath(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccbatch%d" @@ -911,10 +885,10 @@ resource "azurerm_batch_pool" "test" { } } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testaccAzureRMBatchPoolCertificates(rInt int, rString string, location string) string { +func testaccAzureRMBatchPoolCertificates(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccbatch%d" @@ -976,10 +950,10 @@ resource "azurerm_batch_pool" "test" { visibility = ["StartTask", "RemoteUser"] } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testaccAzureRMBatchPoolContainerConfiguration(rInt int, rString string, location string) string { +func testaccAzureRMBatchPoolContainerConfiguration(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccbatch%d" @@ -1028,10 +1002,10 @@ resource "azurerm_batch_pool" "test" { ] } } -`, rInt, location, rString, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomString) } -func testaccAzureRMBatchPoolCustomImageConfiguration(rInt int, rString string, location string) string { +func testaccAzureRMBatchPoolCustomImageConfiguration(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "testaccRG-%d-batchpool" @@ -1177,5 +1151,5 @@ resource "azurerm_batch_pool" "test" { id = "${azurerm_image.test.id}" } } -`, rInt, location, rInt, rInt, rInt, rInt, rString, rInt, rInt, rInt, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomString) } From 3d9264ea8399488f432ae80f75f97e06a285cd7e Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 20:07:39 +0100 Subject: [PATCH 138/203] hdinsight: fixing the type --- .../tests/resource_arm_hdinsight_storm_cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go index 43cb140c1013..1e80c779ac03 100644 --- a/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go +++ b/azurerm/internal/services/hdinsight/tests/resource_arm_hdinsight_storm_cluster_test.go @@ -532,5 +532,5 @@ resource "azurerm_storage_container" "test" { storage_account_name = "${azurerm_storage_account.test.name}" container_access_type = "private" } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } From 931ecf1258a940623ed0ddc63b55f4f2a78be90d Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 11:10:07 -0800 Subject: [PATCH 139/203] network: switching to the new test structure --- .../data_source_express_route_circuit_test.go | 48 - .../services/network/data_source_firewall.go | 2 +- ...ource_loadbalancer_backend_address_pool.go | 2 +- ..._link_service_endpoint_connections_test.go | 47 - .../data_source_private_link_service_test.go | 51 - .../network/data_source_route_table_test.go | 121 -- .../internal/services/network/loadbalancer.go | 22 +- .../services/network/resource_arm_firewall.go | 4 +- ...rm_firewall_application_rule_collection.go | 4 +- ...source_arm_firewall_nat_rule_collection.go | 4 +- ...ce_arm_firewall_network_rule_collection.go | 4 +- ...e_arm_loadbalancer_backend_address_pool.go | 6 +- .../resource_arm_loadbalancer_nat_pool.go | 8 +- .../resource_arm_loadbalancer_nat_rule.go | 8 +- ...resource_arm_loadbalancer_outbound_rule.go | 8 +- .../resource_arm_loadbalancer_probe.go | 6 +- .../network/resource_arm_loadbalancer_rule.go | 12 +- ...ource_arm_network_watcher_flow_log_test.go | 539 --------- ...rm_web_application_firewall_policy_test.go | 281 ----- ..._source_application_security_group_test.go | 39 +- .../data_source_express_route_circuit_test.go | 45 + .../{ => tests}/data_source_firewall_test.go | 17 +- ..._loadbalancer_backend_address_pool_test.go | 17 +- .../data_source_loadbalancer_test.go | 15 +- .../data_source_nat_gateway_test.go | 30 +- ...ource_network_ddos_protection_plan_test.go | 17 +- .../data_source_network_interface_test.go | 28 +- ...data_source_network_security_group_test.go | 71 +- .../data_source_network_watcher_test.go | 27 +- ...source_private_endpoint_connection_test.go | 15 +- ...e_private_link_endpoint_connection_test.go | 15 +- ..._link_service_endpoint_connections_test.go | 44 + .../data_source_private_link_service_test.go | 48 + .../data_source_public_ip_prefix_test.go | 32 +- .../{ => tests}/data_source_public_ip_test.go | 63 +- .../data_source_public_ips_test.go | 67 +- .../tests/data_source_route_table_test.go | 114 ++ .../{ => tests}/data_source_subnet_test.go | 93 +- .../data_source_virtual_hub_test.go | 17 +- .../data_source_virtual_machine_test.go | 16 +- ...virtual_network_gateway_connection_test.go | 76 +- ...ata_source_virtual_network_gateway_test.go | 12 +- .../data_source_virtual_network_test.go | 49 +- .../network_security_group_test.go | 10 +- .../point_to_site_vpn_gateway_test.go | 10 +- .../{ => tests}/private_link_endpoint_test.go | 6 +- .../resource_arm_application_gateway_test.go | 1060 +++++++---------- ...rce_arm_application_security_group_test.go | 63 +- .../resource_arm_bastion_host_test.go | 52 +- .../resource_arm_connection_monitor_test.go | 254 ++-- .../resource_arm_ddos_protection_plan_test.go | 83 +- ...xpress_route_circuit_authorization_test.go | 52 +- ..._arm_express_route_circuit_peering_test.go | 94 +- ...resource_arm_express_route_circuit_test.go | 127 +- ...rewall_application_rule_collection_test.go | 386 +++--- ...e_arm_firewall_nat_rule_collection_test.go | 218 ++-- ...m_firewall_network_rule_collection_test.go | 250 ++-- .../{ => tests}/resource_arm_firewall_test.go | 173 ++- ..._loadbalancer_backend_address_pool_test.go | 57 +- ...resource_arm_loadbalancer_nat_pool_test.go | 79 +- ...resource_arm_loadbalancer_nat_rule_test.go | 109 +- ...rce_arm_loadbalancer_outbound_rule_test.go | 96 +- .../resource_arm_loadbalancer_probe_test.go | 101 +- .../resource_arm_loadbalancer_rule_test.go | 88 +- .../resource_arm_loadbalancer_test.go | 159 +-- ...resource_arm_local_network_gateway_test.go | 182 ++- .../resource_arm_nat_gateway_test.go | 82 +- ...rce_arm_network_connection_monitor_test.go | 254 ++-- ...e_arm_network_ddos_protection_plan_test.go | 83 +- ...ce_application_gateway_association_test.go | 38 +- ...ication_security_group_association_test.go | 38 +- ...e_backend_address_pool_association_test.go | 38 +- ...ork_interface_nat_rule_association_test.go | 38 +- .../resource_arm_network_interface_test.go | 277 ++--- ...esource_arm_network_packet_capture_test.go | 109 +- .../resource_arm_network_profile_test.go | 83 +- ...esource_arm_network_security_group_test.go | 184 ++- ...resource_arm_network_security_rule_test.go | 91 +- ...ource_arm_network_watcher_flow_log_test.go | 495 ++++++++ .../resource_arm_network_watcher_test.go | 71 +- .../resource_arm_packet_capture_test.go | 109 +- ...urce_arm_point_to_site_vpn_gateway_test.go | 91 +- .../resource_arm_private_endpoint_test.go | 71 +- ...resource_arm_private_link_endpoint_test.go | 59 +- .../resource_arm_private_link_service_test.go | 319 ++--- .../resource_arm_public_ip_prefix_test.go | 84 +- .../resource_arm_public_ip_test.go | 376 +++--- .../resource_arm_route_table_test.go | 228 ++-- .../{ => tests}/resource_arm_route_test.go | 79 +- ...arm_subnet_nat_gateway_association_test.go | 52 +- ...network_security_group_association_test.go | 47 +- ...arm_subnet_route_table_association_test.go | 47 +- .../{ => tests}/resource_arm_subnet_test.go | 182 ++- .../resource_arm_virtual_hub_test.go | 126 +- ...virtual_network_gateway_connection_test.go | 107 +- ...source_arm_virtual_network_gateway_test.go | 177 ++- ...source_arm_virtual_network_peering_test.go | 73 +- .../resource_arm_virtual_network_test.go | 147 +-- .../resource_arm_virtual_wan_test.go | 51 +- .../resource_arm_vpn_gateway_test.go | 137 +-- ...ource_arm_vpn_server_configuration_test.go | 157 +-- ...rm_web_application_firewall_policy_test.go | 262 ++++ .../testdata/app_service_certificate.pfx | Bin .../testdata/application_gateway_test.cer | 0 .../testdata/application_gateway_test.pfx | Bin .../testdata/application_gateway_test_2.crt | 0 .../testdata/application_gateway_test_2.pfx | Bin 107 files changed, 4607 insertions(+), 6108 deletions(-) delete mode 100644 azurerm/internal/services/network/data_source_express_route_circuit_test.go delete mode 100644 azurerm/internal/services/network/data_source_private_link_service_endpoint_connections_test.go delete mode 100644 azurerm/internal/services/network/data_source_private_link_service_test.go delete mode 100644 azurerm/internal/services/network/data_source_route_table_test.go delete mode 100644 azurerm/internal/services/network/resource_arm_network_watcher_flow_log_test.go delete mode 100644 azurerm/internal/services/network/resource_arm_web_application_firewall_policy_test.go rename azurerm/internal/services/network/{ => tests}/data_source_application_security_group_test.go (58%) create mode 100644 azurerm/internal/services/network/tests/data_source_express_route_circuit_test.go rename azurerm/internal/services/network/{ => tests}/data_source_firewall_test.go (77%) rename azurerm/internal/services/network/{ => tests}/data_source_loadbalancer_backend_address_pool_test.go (69%) rename azurerm/internal/services/network/{ => tests}/data_source_loadbalancer_test.go (60%) rename azurerm/internal/services/network/{ => tests}/data_source_nat_gateway_test.go (58%) rename azurerm/internal/services/network/{ => tests}/data_source_network_ddos_protection_plan_test.go (66%) rename azurerm/internal/services/network/{ => tests}/data_source_network_interface_test.go (79%) rename azurerm/internal/services/network/{ => tests}/data_source_network_security_group_test.go (57%) rename azurerm/internal/services/network/{ => tests}/data_source_network_watcher_test.go (55%) rename azurerm/internal/services/network/{ => tests}/data_source_private_endpoint_connection_test.go (60%) rename azurerm/internal/services/network/{ => tests}/data_source_private_link_endpoint_connection_test.go (60%) create mode 100644 azurerm/internal/services/network/tests/data_source_private_link_service_endpoint_connections_test.go create mode 100644 azurerm/internal/services/network/tests/data_source_private_link_service_test.go rename azurerm/internal/services/network/{ => tests}/data_source_public_ip_prefix_test.go (51%) rename azurerm/internal/services/network/{ => tests}/data_source_public_ip_test.go (50%) rename azurerm/internal/services/network/{ => tests}/data_source_public_ips_test.go (75%) create mode 100644 azurerm/internal/services/network/tests/data_source_route_table_test.go rename azurerm/internal/services/network/{ => tests}/data_source_subnet_test.go (63%) rename azurerm/internal/services/network/{ => tests}/data_source_virtual_hub_test.go (55%) rename azurerm/internal/services/network/{ => tests}/data_source_virtual_machine_test.go (87%) rename azurerm/internal/services/network/{ => tests}/data_source_virtual_network_gateway_connection_test.go (81%) rename azurerm/internal/services/network/{ => tests}/data_source_virtual_network_gateway_test.go (85%) rename azurerm/internal/services/network/{ => tests}/data_source_virtual_network_test.go (69%) rename azurerm/internal/services/network/{ => tests}/network_security_group_test.go (81%) rename azurerm/internal/services/network/{ => tests}/point_to_site_vpn_gateway_test.go (81%) rename azurerm/internal/services/network/{ => tests}/private_link_endpoint_test.go (90%) rename azurerm/internal/services/network/{ => tests}/resource_arm_application_gateway_test.go (79%) rename azurerm/internal/services/network/{ => tests}/resource_arm_application_security_group_test.go (72%) rename azurerm/internal/services/network/{ => tests}/resource_arm_bastion_host_test.go (79%) rename azurerm/internal/services/network/{ => tests}/resource_arm_connection_monitor_test.go (66%) rename azurerm/internal/services/network/{ => tests}/resource_arm_ddos_protection_plan_test.go (73%) rename azurerm/internal/services/network/{ => tests}/resource_arm_express_route_circuit_authorization_test.go (84%) rename azurerm/internal/services/network/{ => tests}/resource_arm_express_route_circuit_peering_test.go (76%) rename azurerm/internal/services/network/{ => tests}/resource_arm_express_route_circuit_test.go (76%) rename azurerm/internal/services/network/{ => tests}/resource_arm_firewall_application_rule_collection_test.go (60%) rename azurerm/internal/services/network/{ => tests}/resource_arm_firewall_nat_rule_collection_test.go (72%) rename azurerm/internal/services/network/{ => tests}/resource_arm_firewall_network_rule_collection_test.go (65%) rename azurerm/internal/services/network/{ => tests}/resource_arm_firewall_test.go (75%) rename azurerm/internal/services/network/{ => tests}/resource_arm_loadbalancer_backend_address_pool_test.go (80%) rename azurerm/internal/services/network/{ => tests}/resource_arm_loadbalancer_nat_pool_test.go (81%) rename azurerm/internal/services/network/{ => tests}/resource_arm_loadbalancer_nat_rule_test.go (78%) rename azurerm/internal/services/network/{ => tests}/resource_arm_loadbalancer_outbound_rule_test.go (80%) rename azurerm/internal/services/network/{ => tests}/resource_arm_loadbalancer_probe_test.go (80%) rename azurerm/internal/services/network/{ => tests}/resource_arm_loadbalancer_rule_test.go (84%) rename azurerm/internal/services/network/{ => tests}/resource_arm_loadbalancer_test.go (73%) rename azurerm/internal/services/network/{ => tests}/resource_arm_local_network_gateway_test.go (63%) rename azurerm/internal/services/network/{ => tests}/resource_arm_nat_gateway_test.go (64%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_connection_monitor_test.go (70%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_ddos_protection_plan_test.go (79%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_interface_application_gateway_association_test.go (90%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_interface_application_security_group_association_test.go (90%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_interface_backend_address_pool_association_test.go (91%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_interface_nat_rule_association_test.go (90%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_interface_test.go (80%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_packet_capture_test.go (79%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_profile_test.go (78%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_security_group_test.go (73%) rename azurerm/internal/services/network/{ => tests}/resource_arm_network_security_rule_test.go (84%) create mode 100644 azurerm/internal/services/network/tests/resource_arm_network_watcher_flow_log_test.go rename azurerm/internal/services/network/{ => tests}/resource_arm_network_watcher_test.go (83%) rename azurerm/internal/services/network/{ => tests}/resource_arm_packet_capture_test.go (78%) rename azurerm/internal/services/network/{ => tests}/resource_arm_point_to_site_vpn_gateway_test.go (78%) rename azurerm/internal/services/network/{ => tests}/resource_arm_private_endpoint_test.go (75%) rename azurerm/internal/services/network/{ => tests}/resource_arm_private_link_endpoint_test.go (54%) rename azurerm/internal/services/network/{ => tests}/resource_arm_private_link_service_test.go (68%) rename azurerm/internal/services/network/{ => tests}/resource_arm_public_ip_prefix_test.go (72%) rename azurerm/internal/services/network/{ => tests}/resource_arm_public_ip_test.go (64%) rename azurerm/internal/services/network/{ => tests}/resource_arm_route_table_test.go (68%) rename azurerm/internal/services/network/{ => tests}/resource_arm_route_test.go (78%) rename azurerm/internal/services/network/{ => tests}/resource_arm_subnet_nat_gateway_association_test.go (82%) rename azurerm/internal/services/network/{ => tests}/resource_arm_subnet_network_security_group_association_test.go (89%) rename azurerm/internal/services/network/{ => tests}/resource_arm_subnet_route_table_association_test.go (85%) rename azurerm/internal/services/network/{ => tests}/resource_arm_subnet_test.go (81%) rename azurerm/internal/services/network/{ => tests}/resource_arm_virtual_hub_test.go (67%) rename azurerm/internal/services/network/{ => tests}/resource_arm_virtual_network_gateway_connection_test.go (84%) rename azurerm/internal/services/network/{ => tests}/resource_arm_virtual_network_gateway_test.go (79%) rename azurerm/internal/services/network/{ => tests}/resource_arm_virtual_network_peering_test.go (81%) rename azurerm/internal/services/network/{ => tests}/resource_arm_virtual_network_test.go (72%) rename azurerm/internal/services/network/{ => tests}/resource_arm_virtual_wan_test.go (77%) rename azurerm/internal/services/network/{ => tests}/resource_arm_vpn_gateway_test.go (66%) rename azurerm/internal/services/network/{ => tests}/resource_arm_vpn_server_configuration_test.go (81%) create mode 100644 azurerm/internal/services/network/tests/resource_arm_web_application_firewall_policy_test.go rename azurerm/internal/services/network/{ => tests}/testdata/app_service_certificate.pfx (100%) rename azurerm/internal/services/network/{ => tests}/testdata/application_gateway_test.cer (100%) rename azurerm/internal/services/network/{ => tests}/testdata/application_gateway_test.pfx (100%) rename azurerm/internal/services/network/{ => tests}/testdata/application_gateway_test_2.crt (100%) rename azurerm/internal/services/network/{ => tests}/testdata/application_gateway_test_2.pfx (100%) diff --git a/azurerm/internal/services/network/data_source_express_route_circuit_test.go b/azurerm/internal/services/network/data_source_express_route_circuit_test.go deleted file mode 100644 index b6bf471735f1..000000000000 --- a/azurerm/internal/services/network/data_source_express_route_circuit_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package network - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func testAccDataSourceAzureRMExpressRoute_basicMetered(t *testing.T) { - dataSourceName := "data.azurerm_express_route_circuit.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMExpressRoute_basic(ri, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "service_provider_properties.0.service_provider_name", "Equinix"), - resource.TestCheckResourceAttr(dataSourceName, "service_provider_properties.0.peering_location", "Silicon Valley"), - resource.TestCheckResourceAttr(dataSourceName, "service_provider_properties.0.bandwidth_in_mbps", "50"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.tier", "Standard"), - resource.TestCheckResourceAttr(dataSourceName, "sku.0.family", "MeteredData"), - resource.TestCheckResourceAttr(dataSourceName, "service_provider_provisioning_state", "NotProvisioned"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMExpressRoute_basic(rInt int, location string) string { - config := testAccAzureRMExpressRouteCircuit_basicMeteredConfig(rInt, location) - - return fmt.Sprintf(` -%s - -data "azurerm_express_route_circuit" test { - resource_group_name = "${azurerm_resource_group.test.name}" - name = "${azurerm_express_route_circuit.test.name}" -} -`, config) -} diff --git a/azurerm/internal/services/network/data_source_firewall.go b/azurerm/internal/services/network/data_source_firewall.go index 63a8308d9ad0..c2c6ed68a001 100644 --- a/azurerm/internal/services/network/data_source_firewall.go +++ b/azurerm/internal/services/network/data_source_firewall.go @@ -26,7 +26,7 @@ func dataSourceArmFirewall() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureFirewallName, + ValidateFunc: ValidateAzureFirewallName, }, "location": azure.SchemaLocationForDataSource(), diff --git a/azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool.go b/azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool.go index 5ecde9b35100..2d9d741c1d59 100644 --- a/azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool.go +++ b/azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool.go @@ -58,7 +58,7 @@ func dataSourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, met return fmt.Errorf("Unable to retrieve Backend Address Pool %q since Load Balancer %q was not found", name, loadBalancerID) } - bap, _, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, name) + bap, _, exists := FindLoadBalancerBackEndAddressPoolByName(loadBalancer, name) if !exists { return fmt.Errorf("Backend Address Pool %q was not found in Load Balancer %q", name, loadBalancerID) } diff --git a/azurerm/internal/services/network/data_source_private_link_service_endpoint_connections_test.go b/azurerm/internal/services/network/data_source_private_link_service_endpoint_connections_test.go deleted file mode 100644 index f36fbeca12d7..000000000000 --- a/azurerm/internal/services/network/data_source_private_link_service_endpoint_connections_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package network - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourcePrivateLinkServiceEndpointConnections_complete(t *testing.T) { - dataSourceName := "data.azurerm_private_link_service_endpoint_connections.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourcePrivateLinkServiceEndpointConnections_complete(ri, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "private_endpoint_connections.0.action_required", "None"), - resource.TestCheckResourceAttr(dataSourceName, "private_endpoint_connections.0.description", "Approved"), - resource.TestCheckResourceAttr(dataSourceName, "private_endpoint_connections.0.status", "Approved"), - resource.TestCheckResourceAttrSet(dataSourceName, "private_endpoint_connections.0.connection_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "private_endpoint_connections.0.connection_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "private_endpoint_connections.0.private_endpoint_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "private_endpoint_connections.0.private_endpoint_name"), - ), - }, - }, - }) -} - -func testAccDataSourcePrivateLinkServiceEndpointConnections_complete(rInt int, location string) string { - return fmt.Sprintf(` -%s - -data "azurerm_private_link_service_endpoint_connections" "test" { - service_id = azurerm_private_link_service.test.id - resource_group_name = azurerm_resource_group.test.name - depends_on = [azurerm_private_link_endpoint.test,] -} -`, testAccAzureRMPrivateEndpoint_basic(rInt, location)) -} diff --git a/azurerm/internal/services/network/data_source_private_link_service_test.go b/azurerm/internal/services/network/data_source_private_link_service_test.go deleted file mode 100644 index 912cfdbcdaca..000000000000 --- a/azurerm/internal/services/network/data_source_private_link_service_test.go +++ /dev/null @@ -1,51 +0,0 @@ -package network - -import ( - "fmt" - "os" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMPrivateLinkService_complete(t *testing.T) { - dataSourceName := "data.azurerm_private_link_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - subscriptionId := os.Getenv("ARM_SUBSCRIPTION_ID") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - Steps: []resource.TestStep{ - { - Config: testAccDataSourcePrivateLinkService_complete(ri, location), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.0.private_ip_address", "10.5.1.40"), - resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.0.private_ip_address_version", "IPv4"), - resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.1.private_ip_address", "10.5.1.41"), - resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.1.private_ip_address_version", "IPv4"), - resource.TestCheckResourceAttr(dataSourceName, "auto_approval_subscription_ids.0", subscriptionId), - resource.TestCheckResourceAttr(dataSourceName, "visibility_subscription_ids.0", subscriptionId), - resource.TestCheckResourceAttr(dataSourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), - resource.TestCheckResourceAttrSet(dataSourceName, "load_balancer_frontend_ip_configuration_ids.0"), - ), - }, - }, - }) -} - -func testAccDataSourcePrivateLinkService_complete(rInt int, location string) string { - config := testAccAzureRMPrivateLinkService_complete(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_private_link_service" "test" { - name = azurerm_private_link_service.test.name - resource_group_name = azurerm_private_link_service.test.resource_group_name -} -`, config) -} diff --git a/azurerm/internal/services/network/data_source_route_table_test.go b/azurerm/internal/services/network/data_source_route_table_test.go deleted file mode 100644 index 564ee5708f96..000000000000 --- a/azurerm/internal/services/network/data_source_route_table_test.go +++ /dev/null @@ -1,121 +0,0 @@ -package network - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMRouteTable_basic(t *testing.T) { - dataSourceName := "data.azurerm_route_table.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMRouteTable_basic(ri, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "route.#", "0"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMRouteTable_singleRoute(t *testing.T) { - dataSourceName := "data.azurerm_route_table.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMRouteTable_singleRoute(ri, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "route.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "route.0.name", "route1"), - resource.TestCheckResourceAttr(dataSourceName, "route.0.address_prefix", "10.1.0.0/16"), - resource.TestCheckResourceAttr(dataSourceName, "route.0.next_hop_type", "VnetLocal"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMRouteTable_multipleRoutes(t *testing.T) { - dataSourceName := "data.azurerm_route_table.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMRouteTable_multipleRoutes(ri, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMRouteTableDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "route.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "route.0.name", "route1"), - resource.TestCheckResourceAttr(dataSourceName, "route.0.address_prefix", "10.1.0.0/16"), - resource.TestCheckResourceAttr(dataSourceName, "route.0.next_hop_type", "VnetLocal"), - resource.TestCheckResourceAttr(dataSourceName, "route.1.name", "route2"), - resource.TestCheckResourceAttr(dataSourceName, "route.1.address_prefix", "10.2.0.0/16"), - resource.TestCheckResourceAttr(dataSourceName, "route.1.next_hop_type", "VnetLocal"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMRouteTable_basic(rInt int, location string) string { - r := testAccAzureRMRouteTable_basic(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_route_table" "test" { - name = "${azurerm_route_table.test.name}" - resource_group_name = "${azurerm_route_table.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMRouteTable_singleRoute(rInt int, location string) string { - r := testAccAzureRMRouteTable_singleRoute(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_route_table" "test" { - name = "${azurerm_route_table.test.name}" - resource_group_name = "${azurerm_route_table.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMRouteTable_multipleRoutes(rInt int, location string) string { - r := testAccAzureRMRouteTable_multipleRoutes(rInt, location) - return fmt.Sprintf(` -%s - -data "azurerm_route_table" "test" { - name = "${azurerm_route_table.test.name}" - resource_group_name = "${azurerm_route_table.test.resource_group_name}" -} -`, r) -} diff --git a/azurerm/internal/services/network/loadbalancer.go b/azurerm/internal/services/network/loadbalancer.go index 2f351f09624b..dff2f8279885 100644 --- a/azurerm/internal/services/network/loadbalancer.go +++ b/azurerm/internal/services/network/loadbalancer.go @@ -47,7 +47,7 @@ func retrieveLoadBalancerById(d *schema.ResourceData, loadBalancerId string, met return &resp, true, nil } -func findLoadBalancerBackEndAddressPoolByName(lb *network.LoadBalancer, name string) (*network.BackendAddressPool, int, bool) { +func FindLoadBalancerBackEndAddressPoolByName(lb *network.LoadBalancer, name string) (*network.BackendAddressPool, int, bool) { if lb == nil || lb.LoadBalancerPropertiesFormat == nil || lb.LoadBalancerPropertiesFormat.BackendAddressPools == nil { return nil, -1, false } @@ -61,7 +61,7 @@ func findLoadBalancerBackEndAddressPoolByName(lb *network.LoadBalancer, name str return nil, -1, false } -func findLoadBalancerFrontEndIpConfigurationByName(lb *network.LoadBalancer, name string) (*network.FrontendIPConfiguration, bool) { +func FindLoadBalancerFrontEndIpConfigurationByName(lb *network.LoadBalancer, name string) (*network.FrontendIPConfiguration, bool) { if lb == nil || lb.LoadBalancerPropertiesFormat == nil || lb.LoadBalancerPropertiesFormat.FrontendIPConfigurations == nil { return nil, false } @@ -75,7 +75,7 @@ func findLoadBalancerFrontEndIpConfigurationByName(lb *network.LoadBalancer, nam return nil, false } -func findLoadBalancerRuleByName(lb *network.LoadBalancer, name string) (*network.LoadBalancingRule, int, bool) { +func FindLoadBalancerRuleByName(lb *network.LoadBalancer, name string) (*network.LoadBalancingRule, int, bool) { if lb == nil || lb.LoadBalancerPropertiesFormat == nil || lb.LoadBalancerPropertiesFormat.LoadBalancingRules == nil { return nil, -1, false } @@ -89,7 +89,7 @@ func findLoadBalancerRuleByName(lb *network.LoadBalancer, name string) (*network return nil, -1, false } -func findLoadBalancerOutboundRuleByName(lb *network.LoadBalancer, name string) (*network.OutboundRule, int, bool) { +func FindLoadBalancerOutboundRuleByName(lb *network.LoadBalancer, name string) (*network.OutboundRule, int, bool) { if lb == nil || lb.LoadBalancerPropertiesFormat == nil || lb.LoadBalancerPropertiesFormat.OutboundRules == nil { return nil, -1, false } @@ -103,7 +103,7 @@ func findLoadBalancerOutboundRuleByName(lb *network.LoadBalancer, name string) ( return nil, -1, false } -func findLoadBalancerNatRuleByName(lb *network.LoadBalancer, name string) (*network.InboundNatRule, int, bool) { +func FindLoadBalancerNatRuleByName(lb *network.LoadBalancer, name string) (*network.InboundNatRule, int, bool) { if lb == nil || lb.LoadBalancerPropertiesFormat == nil || lb.LoadBalancerPropertiesFormat.InboundNatRules == nil { return nil, -1, false } @@ -117,7 +117,7 @@ func findLoadBalancerNatRuleByName(lb *network.LoadBalancer, name string) (*netw return nil, -1, false } -func findLoadBalancerNatPoolByName(lb *network.LoadBalancer, name string) (*network.InboundNatPool, int, bool) { +func FindLoadBalancerNatPoolByName(lb *network.LoadBalancer, name string) (*network.InboundNatPool, int, bool) { if lb == nil || lb.LoadBalancerPropertiesFormat == nil || lb.LoadBalancerPropertiesFormat.InboundNatPools == nil { return nil, -1, false } @@ -131,7 +131,7 @@ func findLoadBalancerNatPoolByName(lb *network.LoadBalancer, name string) (*netw return nil, -1, false } -func findLoadBalancerProbeByName(lb *network.LoadBalancer, name string) (*network.Probe, int, bool) { +func FindLoadBalancerProbeByName(lb *network.LoadBalancer, name string) (*network.Probe, int, bool) { if lb == nil || lb.LoadBalancerPropertiesFormat == nil || lb.LoadBalancerPropertiesFormat.Probes == nil { return nil, -1, false } @@ -145,14 +145,6 @@ func findLoadBalancerProbeByName(lb *network.LoadBalancer, name string) (*networ return nil, -1, false } -func validateLoadBalancerPrivateIpAddressAllocation(v interface{}, _ string) (warnings []string, errors []error) { - value := strings.ToLower(v.(string)) - if value != "static" && value != "dynamic" { - errors = append(errors, fmt.Errorf("LoadBalancer Allocations can only be Static or Dynamic")) - } - return warnings, errors -} - // sets the loadbalancer_id in the ResourceData from the sub resources full id func loadBalancerSubResourceStateImporter(d *schema.ResourceData, _ interface{}) ([]*schema.ResourceData, error) { r, err := regexp.Compile(`.+\/loadBalancers\/.+?\/`) diff --git a/azurerm/internal/services/network/resource_arm_firewall.go b/azurerm/internal/services/network/resource_arm_firewall.go index 1a705c476ab9..f3bf12bac2d8 100644 --- a/azurerm/internal/services/network/resource_arm_firewall.go +++ b/azurerm/internal/services/network/resource_arm_firewall.go @@ -43,7 +43,7 @@ func resourceArmFirewall() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureFirewallName, + ValidateFunc: ValidateAzureFirewallName, }, "location": azure.SchemaLocation(), @@ -394,7 +394,7 @@ func flattenArmFirewallIPConfigurations(input *[]network.AzureFirewallIPConfigur return result } -func validateAzureFirewallName(v interface{}, k string) (warnings []string, errors []error) { +func ValidateAzureFirewallName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) // From the Portal: diff --git a/azurerm/internal/services/network/resource_arm_firewall_application_rule_collection.go b/azurerm/internal/services/network/resource_arm_firewall_application_rule_collection.go index ed9828c04d07..49c76b45e362 100644 --- a/azurerm/internal/services/network/resource_arm_firewall_application_rule_collection.go +++ b/azurerm/internal/services/network/resource_arm_firewall_application_rule_collection.go @@ -41,14 +41,14 @@ func resourceArmFirewallApplicationRuleCollection() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureFirewallName, + ValidateFunc: ValidateAzureFirewallName, }, "azure_firewall_name": { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureFirewallName, + ValidateFunc: ValidateAzureFirewallName, }, "resource_group_name": azure.SchemaResourceGroupName(), diff --git a/azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection.go b/azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection.go index c66b583adc05..7cd36ee957a2 100644 --- a/azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection.go +++ b/azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection.go @@ -41,14 +41,14 @@ func resourceArmFirewallNatRuleCollection() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureFirewallName, + ValidateFunc: ValidateAzureFirewallName, }, "azure_firewall_name": { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureFirewallName, + ValidateFunc: ValidateAzureFirewallName, }, "resource_group_name": azure.SchemaResourceGroupName(), diff --git a/azurerm/internal/services/network/resource_arm_firewall_network_rule_collection.go b/azurerm/internal/services/network/resource_arm_firewall_network_rule_collection.go index 94152cbba0a9..89f0209e638d 100644 --- a/azurerm/internal/services/network/resource_arm_firewall_network_rule_collection.go +++ b/azurerm/internal/services/network/resource_arm_firewall_network_rule_collection.go @@ -41,14 +41,14 @@ func resourceArmFirewallNetworkRuleCollection() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureFirewallName, + ValidateFunc: ValidateAzureFirewallName, }, "azure_firewall_name": { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureFirewallName, + ValidateFunc: ValidateAzureFirewallName, }, "resource_group_name": azure.SchemaResourceGroupName(), diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool.go b/azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool.go index d5d078b0f5ee..67772c22fe4e 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool.go @@ -96,7 +96,7 @@ func resourceArmLoadBalancerBackendAddressPoolCreate(d *schema.ResourceData, met } backendAddressPools := append(*loadBalancer.LoadBalancerPropertiesFormat.BackendAddressPools, expandAzureRmLoadBalancerBackendAddressPools(d)) - existingPool, existingPoolIndex, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, name) + existingPool, existingPoolIndex, exists := FindLoadBalancerBackEndAddressPoolByName(loadBalancer, name) if exists { if name == *existingPool.Name { if features.ShouldResourcesBeImported() && d.IsNewResource() { @@ -164,7 +164,7 @@ func resourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, meta return nil } - config, _, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, name) + config, _, exists := FindLoadBalancerBackEndAddressPoolByName(loadBalancer, name) if !exists { d.SetId("") log.Printf("[INFO] Load Balancer Backend Address Pool %q not found. Removing from state", name) @@ -215,7 +215,7 @@ func resourceArmLoadBalancerBackendAddressPoolDelete(d *schema.ResourceData, met return nil } - _, index, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, d.Get("name").(string)) + _, index, exists := FindLoadBalancerBackEndAddressPoolByName(loadBalancer, d.Get("name").(string)) if !exists { return nil } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool.go b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool.go index 5ad3b2e3c00b..52c862e53a12 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool.go @@ -127,7 +127,7 @@ func resourceArmLoadBalancerNatPoolCreateUpdate(d *schema.ResourceData, meta int natPools := append(*loadBalancer.LoadBalancerPropertiesFormat.InboundNatPools, *newNatPool) - existingNatPool, existingNatPoolIndex, exists := findLoadBalancerNatPoolByName(loadBalancer, name) + existingNatPool, existingNatPoolIndex, exists := FindLoadBalancerNatPoolByName(loadBalancer, name) if exists { if name == *existingNatPool.Name { if features.ShouldResourcesBeImported() && d.IsNewResource() { @@ -195,7 +195,7 @@ func resourceArmLoadBalancerNatPoolRead(d *schema.ResourceData, meta interface{} return nil } - config, _, exists := findLoadBalancerNatPoolByName(loadBalancer, name) + config, _, exists := FindLoadBalancerNatPoolByName(loadBalancer, name) if !exists { d.SetId("") log.Printf("[INFO] Load Balancer Nat Pool %q not found. Removing from state", name) @@ -243,7 +243,7 @@ func resourceArmLoadBalancerNatPoolDelete(d *schema.ResourceData, meta interface return nil } - _, index, exists := findLoadBalancerNatPoolByName(loadBalancer, d.Get("name").(string)) + _, index, exists := FindLoadBalancerNatPoolByName(loadBalancer, d.Get("name").(string)) if !exists { return nil } @@ -286,7 +286,7 @@ func expandAzureRmLoadBalancerNatPool(d *schema.ResourceData, lb *network.LoadBa } if v := d.Get("frontend_ip_configuration_name").(string); v != "" { - rule, exists := findLoadBalancerFrontEndIpConfigurationByName(lb, v) + rule, exists := FindLoadBalancerFrontEndIpConfigurationByName(lb, v) if !exists { return nil, fmt.Errorf("[ERROR] Cannot find FrontEnd IP Configuration with the name %s", v) } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule.go b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule.go index 4b9436e81351..2387edd00298 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule.go @@ -133,7 +133,7 @@ func resourceArmLoadBalancerNatRuleCreateUpdate(d *schema.ResourceData, meta int natRules := append(*loadBalancer.LoadBalancerPropertiesFormat.InboundNatRules, *newNatRule) - existingNatRule, existingNatRuleIndex, exists := findLoadBalancerNatRuleByName(loadBalancer, name) + existingNatRule, existingNatRuleIndex, exists := FindLoadBalancerNatRuleByName(loadBalancer, name) if exists { if name == *existingNatRule.Name { if features.ShouldResourcesBeImported() && d.IsNewResource() { @@ -202,7 +202,7 @@ func resourceArmLoadBalancerNatRuleRead(d *schema.ResourceData, meta interface{} return nil } - config, _, exists := findLoadBalancerNatRuleByName(loadBalancer, name) + config, _, exists := FindLoadBalancerNatRuleByName(loadBalancer, name) if !exists { d.SetId("") log.Printf("[INFO] Load Balancer Nat Rule %q not found. Removing from state", name) @@ -254,7 +254,7 @@ func resourceArmLoadBalancerNatRuleDelete(d *schema.ResourceData, meta interface return nil } - _, index, exists := findLoadBalancerNatRuleByName(loadBalancer, d.Get("name").(string)) + _, index, exists := FindLoadBalancerNatRuleByName(loadBalancer, d.Get("name").(string)) if !exists { return nil } @@ -300,7 +300,7 @@ func expandAzureRmLoadBalancerNatRule(d *schema.ResourceData, lb *network.LoadBa } if v := d.Get("frontend_ip_configuration_name").(string); v != "" { - rule, exists := findLoadBalancerFrontEndIpConfigurationByName(lb, v) + rule, exists := FindLoadBalancerFrontEndIpConfigurationByName(lb, v) if !exists { return nil, fmt.Errorf("[ERROR] Cannot find FrontEnd IP Configuration with the name %s", v) } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule.go b/azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule.go index df514bc7effc..0daf82300611 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule.go @@ -140,7 +140,7 @@ func resourceArmLoadBalancerOutboundRuleCreateUpdate(d *schema.ResourceData, met outboundRules = *loadBalancer.LoadBalancerPropertiesFormat.OutboundRules } - existingOutboundRule, existingOutboundRuleIndex, exists := findLoadBalancerOutboundRuleByName(loadBalancer, name) + existingOutboundRule, existingOutboundRuleIndex, exists := FindLoadBalancerOutboundRuleByName(loadBalancer, name) if exists { if name == *existingOutboundRule.Name { if features.ShouldResourcesBeImported() && d.IsNewResource() { @@ -211,7 +211,7 @@ func resourceArmLoadBalancerOutboundRuleRead(d *schema.ResourceData, meta interf return nil } - config, _, exists := findLoadBalancerOutboundRuleByName(loadBalancer, name) + config, _, exists := FindLoadBalancerOutboundRuleByName(loadBalancer, name) if !exists { d.SetId("") log.Printf("[INFO] Load Balancer Outbound Rule %q not found. Removing from state", name) @@ -279,7 +279,7 @@ func resourceArmLoadBalancerOutboundRuleDelete(d *schema.ResourceData, meta inte return nil } - _, index, exists := findLoadBalancerOutboundRuleByName(loadBalancer, d.Get("name").(string)) + _, index, exists := FindLoadBalancerOutboundRuleByName(loadBalancer, d.Get("name").(string)) if !exists { return nil } @@ -323,7 +323,7 @@ func expandAzureRmLoadBalancerOutboundRule(d *schema.ResourceData, lb *network.L for _, raw := range feConfigs { v := raw.(map[string]interface{}) - rule, exists := findLoadBalancerFrontEndIpConfigurationByName(lb, v["name"].(string)) + rule, exists := FindLoadBalancerFrontEndIpConfigurationByName(lb, v["name"].(string)) if !exists { return nil, fmt.Errorf("[ERROR] Cannot find FrontEnd IP Configuration with the name %s", v["name"]) } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_probe.go b/azurerm/internal/services/network/resource_arm_loadbalancer_probe.go index 0cac7cd3a7c1..fc8f43864f1b 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_probe.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_probe.go @@ -127,7 +127,7 @@ func resourceArmLoadBalancerProbeCreateUpdate(d *schema.ResourceData, meta inter newProbe := expandAzureRmLoadBalancerProbe(d) probes := append(*loadBalancer.LoadBalancerPropertiesFormat.Probes, *newProbe) - existingProbe, existingProbeIndex, exists := findLoadBalancerProbeByName(loadBalancer, name) + existingProbe, existingProbeIndex, exists := FindLoadBalancerProbeByName(loadBalancer, name) if exists { if name == *existingProbe.Name { if features.ShouldResourcesBeImported() && d.IsNewResource() { @@ -195,7 +195,7 @@ func resourceArmLoadBalancerProbeRead(d *schema.ResourceData, meta interface{}) return nil } - config, _, exists := findLoadBalancerProbeByName(loadBalancer, name) + config, _, exists := FindLoadBalancerProbeByName(loadBalancer, name) if !exists { d.SetId("") log.Printf("[INFO] Load Balancer Probe %q not found. Removing from state", name) @@ -246,7 +246,7 @@ func resourceArmLoadBalancerProbeDelete(d *schema.ResourceData, meta interface{} return nil } - _, index, exists := findLoadBalancerProbeByName(loadBalancer, d.Get("name").(string)) + _, index, exists := FindLoadBalancerProbeByName(loadBalancer, d.Get("name").(string)) if !exists { return nil } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_rule.go b/azurerm/internal/services/network/resource_arm_loadbalancer_rule.go index a980504662fe..0a46bb89965b 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_rule.go +++ b/azurerm/internal/services/network/resource_arm_loadbalancer_rule.go @@ -43,7 +43,7 @@ func resourceArmLoadBalancerRule() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmLoadBalancerRuleName, + ValidateFunc: ValidateArmLoadBalancerRuleName, }, "location": azure.SchemaLocationDeprecated(), @@ -158,7 +158,7 @@ func resourceArmLoadBalancerRuleCreateUpdate(d *schema.ResourceData, meta interf lbRules := append(*loadBalancer.LoadBalancerPropertiesFormat.LoadBalancingRules, *newLbRule) - existingRule, existingRuleIndex, exists := findLoadBalancerRuleByName(loadBalancer, name) + existingRule, existingRuleIndex, exists := FindLoadBalancerRuleByName(loadBalancer, name) if exists { if name == *existingRule.Name { if features.ShouldResourcesBeImported() && d.IsNewResource() { @@ -226,7 +226,7 @@ func resourceArmLoadBalancerRuleRead(d *schema.ResourceData, meta interface{}) e return nil } - config, _, exists := findLoadBalancerRuleByName(loadBalancer, name) + config, _, exists := FindLoadBalancerRuleByName(loadBalancer, name) if !exists { d.SetId("") log.Printf("[INFO] Load Balancer Rule %q not found. Removing from state", name) @@ -294,7 +294,7 @@ func resourceArmLoadBalancerRuleDelete(d *schema.ResourceData, meta interface{}) return nil } - _, index, exists := findLoadBalancerRuleByName(loadBalancer, d.Get("name").(string)) + _, index, exists := FindLoadBalancerRuleByName(loadBalancer, d.Get("name").(string)) if !exists { return nil } @@ -346,7 +346,7 @@ func expandAzureRmLoadBalancerRule(d *schema.ResourceData, lb *network.LoadBalan } if v := d.Get("frontend_ip_configuration_name").(string); v != "" { - rule, exists := findLoadBalancerFrontEndIpConfigurationByName(lb, v) + rule, exists := FindLoadBalancerFrontEndIpConfigurationByName(lb, v) if !exists { return nil, fmt.Errorf("[ERROR] Cannot find FrontEnd IP Configuration with the name %s", v) } @@ -374,7 +374,7 @@ func expandAzureRmLoadBalancerRule(d *schema.ResourceData, lb *network.LoadBalan }, nil } -func validateArmLoadBalancerRuleName(v interface{}, k string) (warnings []string, errors []error) { +func ValidateArmLoadBalancerRuleName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^[a-zA-Z_0-9.-]+$`).MatchString(value) { errors = append(errors, fmt.Errorf( diff --git a/azurerm/internal/services/network/resource_arm_network_watcher_flow_log_test.go b/azurerm/internal/services/network/resource_arm_network_watcher_flow_log_test.go deleted file mode 100644 index 343e6c0ad7b6..000000000000 --- a/azurerm/internal/services/network/resource_arm_network_watcher_flow_log_test.go +++ /dev/null @@ -1,539 +0,0 @@ -package network - -import ( - "fmt" - "testing" - - "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" -) - -func testAccAzureRMNetworkWatcherFlowLog_basic(t *testing.T) { - resourceName := "azurerm_network_watcher_flow_log.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMNetworkWatcherFlowLog_basicConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.days", "0"), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccAzureRMNetworkWatcherFlowLog_disabled(t *testing.T) { - resourceName := "azurerm_network_watcher_flow_log.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMNetworkWatcherFlowLog_disabledConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "retention_policy.0.enabled"), - resource.TestCheckResourceAttrSet(resourceName, "retention_policy.0.days"), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), - ), - }, - // disabled flow logs don't import all values - }, - }) -} - -func testAccAzureRMNetworkWatcherFlowLog_reenabled(t *testing.T) { - resourceName := "azurerm_network_watcher_flow_log.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMNetworkWatcherFlowLog_disabledConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "retention_policy.0.enabled"), - resource.TestCheckResourceAttrSet(resourceName, "retention_policy.0.days"), - resource.TestCheckResourceAttr(resourceName, "enabled", "false"), - ), - }, - { - Config: testAccAzureRMNetworkWatcherFlowLog_basicConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.days", "0"), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccAzureRMNetworkWatcherFlowLog_retentionPolicy(t *testing.T) { - resourceName := "azurerm_network_watcher_flow_log.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMNetworkWatcherFlowLog_basicConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.days", "0"), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.days", "7"), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccAzureRMNetworkWatcherFlowLog_updateStorageAccount(t *testing.T) { - resourceName := "azurerm_network_watcher_flow_log.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.days", "7"), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfigUpdateStorageAccount(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.days", "7"), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testAccAzureRMNetworkWatcherFlowLog_trafficAnalytics(t *testing.T) { - resourceName := "azurerm_network_watcher_flow_log.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMNetworkWatcherFlowLog_basicConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.days", "0"), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsDisabledConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.days", "7"), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - ), - }, - { - Config: testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsEnabledConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.days", "7"), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "traffic_analytics.#", "1"), - resource.TestCheckResourceAttr(resourceName, "traffic_analytics.0.enabled", "true"), - resource.TestCheckResourceAttrSet(resourceName, "traffic_analytics.0.workspace_id"), - resource.TestCheckResourceAttrSet(resourceName, "traffic_analytics.0.workspace_region"), - resource.TestCheckResourceAttrSet(resourceName, "traffic_analytics.0.workspace_resource_id"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - // flow log must be disabled before destroy - { - Config: testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsDisabledConfig(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherFlowLogExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_watcher_name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "storage_account_id"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "retention_policy.0.days", "7"), - resource.TestCheckResourceAttr(resourceName, "enabled", "true"), - ), - }, - }, - }) -} - -func testCheckAzureRMNetworkWatcherFlowLogExists(name string) resource.TestCheckFunc { - return func(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.WatcherClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[name] - if !ok { - return fmt.Errorf("Not found: %s", name) - } - - id, err := ParseNetworkWatcherFlowLogID(rs.Primary.Attributes["id"]) - if err != nil { - return err - } - - statusParameters := network.FlowLogStatusParameters{ - TargetResourceID: &id.NetworkSecurityGroupID, - } - future, err := client.GetFlowLogStatus(ctx, id.ResourceGroup, id.NetworkWatcherName, statusParameters) - if err != nil { - return fmt.Errorf("Error retrieving Flow Log Configuration for target %q (Network Watcher %q / Resource Group %q): %+v", id.NetworkSecurityGroupID, id.NetworkWatcherName, id.ResourceGroup, err) - } - - if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("Error waiting for retrieval of Flow Log Configuration for target %q (Network Watcher %q / Resource Group %q): %+v", id.NetworkSecurityGroupID, id.NetworkWatcherName, id.ResourceGroup, err) - } - - if _, err := future.Result(*client); err != nil { - return fmt.Errorf("Error retrieving of Flow Log Configuration for target %q (Network Watcher %q / Resource Group %q): %+v", id.NetworkSecurityGroupID, id.NetworkWatcherName, id.ResourceGroup, err) - } - - return nil - } -} - -func testAccAzureRMNetworkWatcherFlowLog_prerequisites(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-watcher-%d" - location = "%s" -} - -resource "azurerm_network_security_group" "test" { - name = "acctestNSG%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_network_watcher" "test" { - name = "acctest-NW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" -} - -resource "azurerm_storage_account" "test" { - name = "acctestsa%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - account_tier = "Standard" - account_kind = "StorageV2" - account_replication_type = "LRS" - enable_https_traffic_only = true -} -`, rInt, location, rInt, rInt, rInt%1000000) -} - -func testAccAzureRMNetworkWatcherFlowLog_basicConfig(rInt int, location string) string { - return fmt.Sprintf(` -%s - -resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.test.id}" - enabled = true - - retention_policy { - enabled = false - days = 0 - } -} -`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(rInt, location)) -} - -func testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfig(rInt int, location string) string { - return fmt.Sprintf(` -%s - -resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.test.id}" - enabled = true - - retention_policy { - enabled = true - days = 7 - } -} -`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(rInt, location)) -} - -func testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfigUpdateStorageAccount(rInt int, location string) string { - return fmt.Sprintf(` -%s - -resource "azurerm_storage_account" "testb" { - name = "acctestsab%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - account_tier = "Standard" - account_kind = "StorageV2" - account_replication_type = "LRS" - enable_https_traffic_only = true -} - -resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.testb.id}" - enabled = true - - retention_policy { - enabled = true - days = 7 - } -} -`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(rInt, location), rInt%1000000+1) -} - -func testAccAzureRMNetworkWatcherFlowLog_disabledConfig(rInt int, location string) string { - return fmt.Sprintf(` -%s - -resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.test.id}" - enabled = false - - retention_policy { - enabled = true - days = 7 - } -} -`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(rInt, location)) -} - -func testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsEnabledConfig(rInt int, location string) string { - return fmt.Sprintf(` -%s - -resource "azurerm_log_analytics_workspace" "test" { - name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "PerGB2018" -} - -resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.test.id}" - enabled = true - - retention_policy { - enabled = true - days = 7 - } - - traffic_analytics { - enabled = true - workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}" - workspace_region = "${azurerm_log_analytics_workspace.test.location}" - workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" - } -} -`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(rInt, location), rInt) -} - -func testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsDisabledConfig(rInt int, location string) string { - return fmt.Sprintf(` -%s - -resource "azurerm_log_analytics_workspace" "test" { - name = "acctestLAW-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - sku = "PerGB2018" -} - -resource "azurerm_network_watcher_flow_log" "test" { - network_watcher_name = "${azurerm_network_watcher.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" - - network_security_group_id = "${azurerm_network_security_group.test.id}" - storage_account_id = "${azurerm_storage_account.test.id}" - enabled = true - - retention_policy { - enabled = true - days = 7 - } - - traffic_analytics { - enabled = false - workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}" - workspace_region = "${azurerm_log_analytics_workspace.test.location}" - workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" - } -} -`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(rInt, location), rInt) -} diff --git a/azurerm/internal/services/network/resource_arm_web_application_firewall_policy_test.go b/azurerm/internal/services/network/resource_arm_web_application_firewall_policy_test.go deleted file mode 100644 index d87ea3e9b6ce..000000000000 --- a/azurerm/internal/services/network/resource_arm_web_application_firewall_policy_test.go +++ /dev/null @@ -1,281 +0,0 @@ -package network - -import ( - "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/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" -) - -func TestAccAzureRMWebApplicationFirewallPolicy_basic(t *testing.T) { - resourceName := "azurerm_web_application_firewall_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMWebApplicationFirewallPolicyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMWebApplicationFirewallPolicy_basic(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWebApplicationFirewallPolicyExists(resourceName), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMWebApplicationFirewallPolicy_complete(t *testing.T) { - resourceName := "azurerm_web_application_firewall_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMWebApplicationFirewallPolicyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMWebApplicationFirewallPolicy_complete(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWebApplicationFirewallPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "custom_rules.#", "2"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.name", "Rule1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.priority", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.rule_type", "MatchRule"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.match_variables.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.match_variables.0.variable_name", "RemoteAddr"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.operator", "IPMatch"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.negation_condition", "false"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.match_values.#", "2"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.match_values.0", "192.168.1.0/24"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.match_values.1", "10.0.0.0/24"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.action", "Block"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.name", "Rule2"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.priority", "2"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.rule_type", "MatchRule"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.#", "2"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.match_variables.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.match_variables.0.variable_name", "RemoteAddr"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.operator", "IPMatch"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.negation_condition", "false"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.match_values.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.match_values.0", "192.168.1.0/24"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.match_variables.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.match_variables.0.variable_name", "RequestHeaders"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.match_variables.0.selector", "UserAgent"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.operator", "Contains"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.negation_condition", "false"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.match_values.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.match_values.0", "Windows"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.action", "Block"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMWebApplicationFirewallPolicy_update(t *testing.T) { - resourceName := "azurerm_web_application_firewall_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMWebApplicationFirewallPolicyDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMWebApplicationFirewallPolicy_basic(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWebApplicationFirewallPolicyExists(resourceName), - ), - }, - { - Config: testAccAzureRMWebApplicationFirewallPolicy_complete(ri, location), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMWebApplicationFirewallPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "custom_rules.#", "2"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.name", "Rule1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.priority", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.rule_type", "MatchRule"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.match_variables.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.match_variables.0.variable_name", "RemoteAddr"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.operator", "IPMatch"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.negation_condition", "false"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.match_values.#", "2"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.match_values.0", "192.168.1.0/24"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.match_conditions.0.match_values.1", "10.0.0.0/24"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.0.action", "Block"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.name", "Rule2"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.priority", "2"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.rule_type", "MatchRule"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.#", "2"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.match_variables.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.match_variables.0.variable_name", "RemoteAddr"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.operator", "IPMatch"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.negation_condition", "false"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.match_values.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.0.match_values.0", "192.168.1.0/24"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.match_variables.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.match_variables.0.variable_name", "RequestHeaders"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.match_variables.0.selector", "UserAgent"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.operator", "Contains"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.negation_condition", "false"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.match_values.#", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.match_conditions.1.match_values.0", "Windows"), - resource.TestCheckResourceAttr(resourceName, "custom_rules.1.action", "Block"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testCheckAzureRMWebApplicationFirewallPolicyExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Web Application Firewall Policy not found: %s", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.WebApplicationFirewallPoliciesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - if resp, err := client.Get(ctx, resourceGroup, name); err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Web Application Firewall Policy %q (Resource Group %q) does not exist", name, resourceGroup) - } - return fmt.Errorf("Bad: Get on network.WebApplicationFirewallPoliciesClient: %+v", err) - } - - return nil - } -} - -func testCheckAzureRMWebApplicationFirewallPolicyDestroy(s *terraform.State) error { - client := acceptance.AzureProvider.Meta().(*clients.Client).Network.WebApplicationFirewallPoliciesClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_web_application_firewall_policy" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - if resp, err := client.Get(ctx, resourceGroup, name); err != nil { - if !utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Bad: Get on network.WebApplicationFirewallPoliciesClient: %+v", err) - } - } - - return nil - } - - return nil -} - -func testAccAzureRMWebApplicationFirewallPolicy_basic(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_web_application_firewall_policy" "test" { - name = "acctestwafpolicy-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" -} -`, rInt, location, rInt) -} - -func testAccAzureRMWebApplicationFirewallPolicy_complete(rInt int, location string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_web_application_firewall_policy" "test" { - name = "acctestwafpolicy-%d" - resource_group_name = "${azurerm_resource_group.test.name}" - location = "${azurerm_resource_group.test.location}" - - custom_rules { - name = "Rule1" - priority = 1 - rule_type = "MatchRule" - - match_conditions { - match_variables { - variable_name = "RemoteAddr" - } - - operator = "IPMatch" - negation_condition = false - match_values = ["192.168.1.0/24", "10.0.0.0/24"] - } - - action = "Block" - } - - custom_rules { - name = "Rule2" - priority = 2 - rule_type = "MatchRule" - - match_conditions { - match_variables { - variable_name = "RemoteAddr" - } - - operator = "IPMatch" - negation_condition = false - match_values = ["192.168.1.0/24"] - } - - match_conditions { - match_variables { - variable_name = "RequestHeaders" - selector = "UserAgent" - } - - operator = "Contains" - negation_condition = false - match_values = ["Windows"] - } - - action = "Block" - } -} -`, rInt, location, rInt) -} diff --git a/azurerm/internal/services/network/data_source_application_security_group_test.go b/azurerm/internal/services/network/tests/data_source_application_security_group_test.go similarity index 58% rename from azurerm/internal/services/network/data_source_application_security_group_test.go rename to azurerm/internal/services/network/tests/data_source_application_security_group_test.go index 20b9a646be49..4ab4b31459be 100644 --- a/azurerm/internal/services/network/data_source_application_security_group_test.go +++ b/azurerm/internal/services/network/tests/data_source_application_security_group_test.go @@ -1,28 +1,26 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMApplicationSecurityGroup_basic(t *testing.T) { - dataSourceName := "data.azurerm_application_security_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_application_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceApplicationSecurityGroup_basic(ri, acceptance.Location()), + Config: testAccDataSourceApplicationSecurityGroup_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -30,27 +28,26 @@ func TestAccDataSourceAzureRMApplicationSecurityGroup_basic(t *testing.T) { } func TestAccDataSourceAzureRMApplicationSecurityGroup_complete(t *testing.T) { - dataSourceName := "data.azurerm_application_security_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_application_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceApplicationSecurityGroup_complete(ri, acceptance.Location()), + Config: testAccDataSourceApplicationSecurityGroup_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.Hello", "World"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), ), }, }, }) } -func testAccDataSourceApplicationSecurityGroup_basic(rInt int, location string) string { +func testAccDataSourceApplicationSecurityGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -67,10 +64,10 @@ data "azurerm_application_security_group" "test" { name = "${azurerm_application_security_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceApplicationSecurityGroup_complete(rInt int, location string) string { +func testAccDataSourceApplicationSecurityGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -91,5 +88,5 @@ data "azurerm_application_security_group" "test" { name = "${azurerm_application_security_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/data_source_express_route_circuit_test.go b/azurerm/internal/services/network/tests/data_source_express_route_circuit_test.go new file mode 100644 index 000000000000..e0e824f3caab --- /dev/null +++ b/azurerm/internal/services/network/tests/data_source_express_route_circuit_test.go @@ -0,0 +1,45 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func testAccDataSourceAzureRMExpressRoute_basicMetered(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_express_route_circuit", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMExpressRoute_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "service_provider_properties.0.service_provider_name", "Equinix"), + resource.TestCheckResourceAttr(data.ResourceName, "service_provider_properties.0.peering_location", "Silicon Valley"), + resource.TestCheckResourceAttr(data.ResourceName, "service_provider_properties.0.bandwidth_in_mbps", "50"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "MeteredData"), + resource.TestCheckResourceAttr(data.ResourceName, "service_provider_provisioning_state", "NotProvisioned"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMExpressRoute_basic(data acceptance.TestData) string { + config := testAccAzureRMExpressRouteCircuit_basicMeteredConfig(data) + + return fmt.Sprintf(` +%s + +data "azurerm_express_route_circuit" test { + resource_group_name = "${azurerm_resource_group.test.name}" + name = "${azurerm_express_route_circuit.test.name}" +} +`, config) +} diff --git a/azurerm/internal/services/network/data_source_firewall_test.go b/azurerm/internal/services/network/tests/data_source_firewall_test.go similarity index 77% rename from azurerm/internal/services/network/data_source_firewall_test.go rename to azurerm/internal/services/network/tests/data_source_firewall_test.go index 067f6b9098e6..8b6fa76c17a6 100644 --- a/azurerm/internal/services/network/data_source_firewall_test.go +++ b/azurerm/internal/services/network/tests/data_source_firewall_test.go @@ -1,18 +1,15 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMFirewall_basic(t *testing.T) { - dataSourceName := "data.azurerm_firewall.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_firewall", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,17 +17,17 @@ func TestAccDataSourceAzureRMFirewall_basic(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceFirewall_basic(rInt, location), + Config: testAccDataSourceFirewall_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "ip_configuration.0.name", "configuration"), - resource.TestCheckResourceAttrSet(dataSourceName, "ip_configuration.0.private_ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "configuration"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), ), }, }, }) } -func testAccDataSourceFirewall_basic(rInt int, location string) string { +func testAccDataSourceFirewall_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -75,5 +72,5 @@ data "azurerm_firewall" "test" { name = "${azurerm_firewall.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool_test.go b/azurerm/internal/services/network/tests/data_source_loadbalancer_backend_address_pool_test.go similarity index 69% rename from azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool_test.go rename to azurerm/internal/services/network/tests/data_source_loadbalancer_backend_address_pool_test.go index a5a8836cc2cc..e9331c97908f 100644 --- a/azurerm/internal/services/network/data_source_loadbalancer_backend_address_pool_test.go +++ b/azurerm/internal/services/network/tests/data_source_loadbalancer_backend_address_pool_test.go @@ -1,20 +1,17 @@ -package network +package tests import ( "fmt" "testing" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccAzureRMDataSourceLoadBalancerBackEndAddressPool_basic(t *testing.T) { - dataSourceName := "data.azurerm_lb_backend_address_pool.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - addressPoolName := fmt.Sprintf("%d-address-pool", ri) + data := acceptance.BuildTestData(t, "data.azurerm_lb_backend_address_pool", "test") + addressPoolName := fmt.Sprintf("%d-address-pool", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,17 +19,17 @@ func TestAccAzureRMDataSourceLoadBalancerBackEndAddressPool_basic(t *testing.T) CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataSourceLoadBalancerBackEndAddressPool_basic(ri, location, addressPoolName), + Config: testAccAzureRMDataSourceLoadBalancerBackEndAddressPool_basic(data, addressPoolName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), ), }, }, }) } -func testAccAzureRMDataSourceLoadBalancerBackEndAddressPool_basic(rInt int, location, name string) string { - resource := testAccAzureRMLoadBalancerBackEndAddressPool_basic(rInt, name, location) +func testAccAzureRMDataSourceLoadBalancerBackEndAddressPool_basic(data acceptance.TestData, name string) string { + resource := testAccAzureRMLoadBalancerBackEndAddressPool_basic(data, name) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/data_source_loadbalancer_test.go b/azurerm/internal/services/network/tests/data_source_loadbalancer_test.go similarity index 60% rename from azurerm/internal/services/network/data_source_loadbalancer_test.go rename to azurerm/internal/services/network/tests/data_source_loadbalancer_test.go index c363ea711879..50b056d5adad 100644 --- a/azurerm/internal/services/network/data_source_loadbalancer_test.go +++ b/azurerm/internal/services/network/tests/data_source_loadbalancer_test.go @@ -1,19 +1,16 @@ -package network +package tests import ( "fmt" "testing" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) func TestAccAzureRMDataSourceLoadBalancer_basic(t *testing.T) { - dataSourceName := "data.azurerm_lb.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_lb", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -21,17 +18,17 @@ func TestAccAzureRMDataSourceLoadBalancer_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataSourceLoadBalancer_basic(ri, location), + Config: testAccAzureRMDataSourceLoadBalancer_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, }, }) } -func testAccAzureRMDataSourceLoadBalancer_basic(rInt int, location string) string { - resource := testAccAzureRMLoadBalancer_basic(rInt, location) +func testAccAzureRMDataSourceLoadBalancer_basic(data acceptance.TestData) string { + resource := testAccAzureRMLoadBalancer_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/data_source_nat_gateway_test.go b/azurerm/internal/services/network/tests/data_source_nat_gateway_test.go similarity index 58% rename from azurerm/internal/services/network/data_source_nat_gateway_test.go rename to azurerm/internal/services/network/tests/data_source_nat_gateway_test.go index f856984e0788..efc71a286938 100644 --- a/azurerm/internal/services/network/data_source_nat_gateway_test.go +++ b/azurerm/internal/services/network/tests/data_source_nat_gateway_test.go @@ -1,25 +1,23 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMNatGateway_basic(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_nat_gateway", "test") // Using alt location because the resource currently in private preview and is only available in eastus2. - location := acceptance.AltLocation() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceNatGateway_basic(ri, location), + Config: testAccDataSourceNatGateway_basic(data), Check: resource.ComposeTestCheckFunc(), }, }, @@ -27,30 +25,28 @@ func TestAccDataSourceAzureRMNatGateway_basic(t *testing.T) { } func TestAccDataSourceAzureRMNatGateway_complete(t *testing.T) { - dataSourceName := "data.azurerm_nat_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_nat_gateway", "test") // Using alt location because the resource currently in private preview and is only available in eastus2. - location := acceptance.AltLocation() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceNatGateway_complete(ri, location), + Config: testAccDataSourceNatGateway_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "public_ip_address_ids.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "public_ip_prefix_ids.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "sku_name", "Standard"), - resource.TestCheckResourceAttr(dataSourceName, "idle_timeout_in_minutes", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "public_ip_address_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "public_ip_prefix_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "idle_timeout_in_minutes", "10"), ), }, }, }) } -func testAccDataSourceNatGateway_basic(rInt int, location string) string { - config := testAccAzureRMNatGateway_basic(rInt, location) +func testAccDataSourceNatGateway_basic(data acceptance.TestData) string { + config := testAccAzureRMNatGateway_basic(data) return fmt.Sprintf(` %s @@ -61,8 +57,8 @@ data "azurerm_nat_gateway" "test" { `, config) } -func testAccDataSourceNatGateway_complete(rInt int, location string) string { - config := testAccAzureRMNatGateway_complete(rInt, location) +func testAccDataSourceNatGateway_complete(data acceptance.TestData) string { + config := testAccAzureRMNatGateway_complete(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/data_source_network_ddos_protection_plan_test.go b/azurerm/internal/services/network/tests/data_source_network_ddos_protection_plan_test.go similarity index 66% rename from azurerm/internal/services/network/data_source_network_ddos_protection_plan_test.go rename to azurerm/internal/services/network/tests/data_source_network_ddos_protection_plan_test.go index 90f696e1f5c0..e4680a4e9792 100644 --- a/azurerm/internal/services/network/data_source_network_ddos_protection_plan_test.go +++ b/azurerm/internal/services/network/tests/data_source_network_ddos_protection_plan_test.go @@ -1,18 +1,15 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func testAccAzureRMNetworkDDoSProtectionPlanDataSource_basic(t *testing.T) { - dsn := "azurerm_network_ddos_protection_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_ddos_protection_plan", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,17 +17,17 @@ func testAccAzureRMNetworkDDoSProtectionPlanDataSource_basic(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkDDoSProtectionPlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkDDoSProtectionPlanDataSource_basicConfig(ri, location), + Config: testAccAzureRMNetworkDDoSProtectionPlanDataSource_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkDDoSProtectionPlanExists(dsn), - resource.TestCheckResourceAttrSet(dsn, "virtual_network_ids.#"), + testCheckAzureRMNetworkDDoSProtectionPlanExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_ids.#"), ), }, }, }) } -func testAccAzureRMNetworkDDoSProtectionPlanDataSource_basicConfig(rInt int, location string) string { +func testAccAzureRMNetworkDDoSProtectionPlanDataSource_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -38,5 +35,5 @@ data "azurerm_network_ddos_protection_plan" "test" { name = "${azurerm_network_ddos_protection_plan.test.name}" resource_group_name = "${azurerm_network_ddos_protection_plan.test.resource_group_name}" } -`, testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(rInt, location)) +`, testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(data)) } diff --git a/azurerm/internal/services/network/data_source_network_interface_test.go b/azurerm/internal/services/network/tests/data_source_network_interface_test.go similarity index 79% rename from azurerm/internal/services/network/data_source_network_interface_test.go rename to azurerm/internal/services/network/tests/data_source_network_interface_test.go index 2e59d846ab99..e4c0bd02235e 100644 --- a/azurerm/internal/services/network/data_source_network_interface_test.go +++ b/azurerm/internal/services/network/tests/data_source_network_interface_test.go @@ -1,41 +1,39 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceArmVirtualNetworkInterface_basic(t *testing.T) { - dataSourceName := "data.azurerm_network_interface.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_network_interface", "test") - name := fmt.Sprintf("acctest-nic-%d", ri) + name := fmt.Sprintf("acctest-nic-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceArmVirtualNetworkInterface_basic(ri, acceptance.Location()), + Config: testAccDataSourceArmVirtualNetworkInterface_basic(data), }, { - Config: testAccDataSourceArmVirtualNetworkInterface_withDataSource(ri, acceptance.Location()), + Config: testAccDataSourceArmVirtualNetworkInterface_withDataSource(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", name), - resource.TestCheckResourceAttrSet(dataSourceName, "id"), - resource.TestCheckResourceAttr(dataSourceName, "private_ip_address", "10.0.1.4"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_security_group_id"), + resource.TestCheckResourceAttr(data.ResourceName, "name", name), + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + resource.TestCheckResourceAttr(data.ResourceName, "private_ip_address", "10.0.1.4"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), ), }, }, }) } -func testAccDataSourceArmVirtualNetworkInterface_basic(rInt int, location string) string { +func testAccDataSourceArmVirtualNetworkInterface_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-%d-rg" @@ -78,10 +76,10 @@ resource "azurerm_network_interface" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccDataSourceArmVirtualNetworkInterface_withDataSource(rInt int, location string) string { +func testAccDataSourceArmVirtualNetworkInterface_withDataSource(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-%d-rg" @@ -129,5 +127,5 @@ data "azurerm_network_interface" "test" { name = "acctest-nic-%d" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/data_source_network_security_group_test.go b/azurerm/internal/services/network/tests/data_source_network_security_group_test.go similarity index 57% rename from azurerm/internal/services/network/data_source_network_security_group_test.go rename to azurerm/internal/services/network/tests/data_source_network_security_group_test.go index 0bdb82319294..514a79a54508 100644 --- a/azurerm/internal/services/network/data_source_network_security_group_test.go +++ b/azurerm/internal/services/network/tests/data_source_network_security_group_test.go @@ -1,19 +1,16 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMNetworkSecurityGroup_basic(t *testing.T) { - dataSourceName := "data.azurerm_network_security_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMNetworkSecurityGroupBasic(ri, location) + data := acceptance.BuildTestData(t, "data.azurerm_network_security_group", "test") + config := testAccDataSourceAzureRMNetworkSecurityGroupBasic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,9 +20,9 @@ func TestAccDataSourceAzureRMNetworkSecurityGroup_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -33,10 +30,8 @@ func TestAccDataSourceAzureRMNetworkSecurityGroup_basic(t *testing.T) { } func TestAccDataSourceAzureRMNetworkSecurityGroup_rules(t *testing.T) { - dataSourceName := "data.azurerm_network_security_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMNetworkSecurityGroupWithRules(ri, location) + data := acceptance.BuildTestData(t, "data.azurerm_network_security_group", "test") + config := testAccDataSourceAzureRMNetworkSecurityGroupWithRules(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -46,18 +41,18 @@ func TestAccDataSourceAzureRMNetworkSecurityGroup_rules(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.0.name", "test123"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.0.priority", "100"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.0.direction", "Inbound"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.0.access", "Allow"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.0.protocol", "Tcp"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.0.source_port_range", "*"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.0.destination_port_range", "*"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.0.source_address_prefix", "*"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.0.destination_address_prefix", "*"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.0.name", "test123"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.0.priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.0.direction", "Inbound"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.0.access", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.0.protocol", "Tcp"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.0.source_port_range", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.0.destination_port_range", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.0.source_address_prefix", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.0.destination_address_prefix", "*"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -65,10 +60,8 @@ func TestAccDataSourceAzureRMNetworkSecurityGroup_rules(t *testing.T) { } func TestAccDataSourceAzureRMNetworkSecurityGroup_tags(t *testing.T) { - dataSourceName := "data.azurerm_network_security_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMNetworkSecurityGroupTags(ri, location) + data := acceptance.BuildTestData(t, "data.azurerm_network_security_group", "test") + config := testAccDataSourceAzureRMNetworkSecurityGroupTags(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,17 +71,17 @@ func TestAccDataSourceAzureRMNetworkSecurityGroup_tags(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttr(dataSourceName, "security_rule.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "staging"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, }, }) } -func testAccDataSourceAzureRMNetworkSecurityGroupBasic(rInt int, location string) string { +func testAccDataSourceAzureRMNetworkSecurityGroupBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -105,10 +98,10 @@ data "azurerm_network_security_group" "test" { name = "${azurerm_network_security_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceAzureRMNetworkSecurityGroupWithRules(rInt int, location string) string { +func testAccDataSourceAzureRMNetworkSecurityGroupWithRules(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -137,10 +130,10 @@ data "azurerm_network_security_group" "test" { name = "${azurerm_network_security_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceAzureRMNetworkSecurityGroupTags(rInt int, location string) string { +func testAccDataSourceAzureRMNetworkSecurityGroupTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -161,5 +154,5 @@ data "azurerm_network_security_group" "test" { name = "${azurerm_network_security_group.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/data_source_network_watcher_test.go b/azurerm/internal/services/network/tests/data_source_network_watcher_test.go similarity index 55% rename from azurerm/internal/services/network/data_source_network_watcher_test.go rename to azurerm/internal/services/network/tests/data_source_network_watcher_test.go index 524278f1af3d..5677cb7f271f 100644 --- a/azurerm/internal/services/network/data_source_network_watcher_test.go +++ b/azurerm/internal/services/network/tests/data_source_network_watcher_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,37 +6,34 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func testAccDataSourceAzureRMNetworkWatcher_basic(t *testing.T) { - dataSourceName := "data.azurerm_network_watcher.test" + data := acceptance.BuildTestData(t, "data.azurerm_network_watcher", "test") - ri := tf.AccRandTimeInt() - name := fmt.Sprintf("acctestnw-%d", ri) - location := acceptance.Location() + name := fmt.Sprintf("acctestnw-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMNetworkWatcher_basicConfig(ri, location), + Config: testAccDataSourceAzureRMNetworkWatcher_basicConfig(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "id"), - resource.TestCheckResourceAttr(dataSourceName, "name", name), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttr(dataSourceName, "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.env", "test"), + resource.TestCheckResourceAttrSet(data.ResourceName, "id"), + resource.TestCheckResourceAttr(data.ResourceName, "name", name), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, }, }) } -func testAccDataSourceAzureRMNetworkWatcher_basicConfig(rInt int, location string) string { +func testAccDataSourceAzureRMNetworkWatcher_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -57,5 +54,5 @@ data "azurerm_network_watcher" "test" { name = "${azurerm_network_watcher.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/data_source_private_endpoint_connection_test.go b/azurerm/internal/services/network/tests/data_source_private_endpoint_connection_test.go similarity index 60% rename from azurerm/internal/services/network/data_source_private_endpoint_connection_test.go rename to azurerm/internal/services/network/tests/data_source_private_endpoint_connection_test.go index 585e9c0147cf..e342e6ff6a26 100644 --- a/azurerm/internal/services/network/data_source_private_endpoint_connection_test.go +++ b/azurerm/internal/services/network/tests/data_source_private_endpoint_connection_test.go @@ -1,34 +1,31 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMPrivateEndpointConnection_complete(t *testing.T) { - dataSourceName := "data.azurerm_private_endpoint_connection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_private_endpoint_connection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourcePrivateEndpointConnection_complete(ri, location), + Config: testAccDataSourcePrivateEndpointConnection_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "private_service_connection.0.status", "Approved"), + resource.TestCheckResourceAttr(data.ResourceName, "private_service_connection.0.status", "Approved"), ), }, }, }) } -func testAccDataSourcePrivateEndpointConnection_complete(rInt int, location string) string { +func testAccDataSourcePrivateEndpointConnection_complete(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -36,5 +33,5 @@ data "azurerm_private_endpoint_connection" "test" { name = azurerm_private_endpoint.test.name resource_group_name = azurerm_resource_group.test.name } -`, testAccAzureRMPrivateEndpoint_basic(rInt, location)) +`, testAccAzureRMPrivateEndpoint_basic(data)) } diff --git a/azurerm/internal/services/network/data_source_private_link_endpoint_connection_test.go b/azurerm/internal/services/network/tests/data_source_private_link_endpoint_connection_test.go similarity index 60% rename from azurerm/internal/services/network/data_source_private_link_endpoint_connection_test.go rename to azurerm/internal/services/network/tests/data_source_private_link_endpoint_connection_test.go index b6f3a6bc84cb..ede0b0744a08 100644 --- a/azurerm/internal/services/network/data_source_private_link_endpoint_connection_test.go +++ b/azurerm/internal/services/network/tests/data_source_private_link_endpoint_connection_test.go @@ -1,34 +1,31 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMPrivateLinkEndpointConnection_complete(t *testing.T) { - dataSourceName := "data.azurerm_private_link_endpoint_connection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_private_link_endpoint_connection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourcePrivateLinkEndpointConnection_complete(ri, location), + Config: testAccDataSourcePrivateLinkEndpointConnection_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "private_service_connection.0.status", "Approved"), + resource.TestCheckResourceAttr(data.ResourceName, "private_service_connection.0.status", "Approved"), ), }, }, }) } -func testAccDataSourcePrivateLinkEndpointConnection_complete(rInt int, location string) string { +func testAccDataSourcePrivateLinkEndpointConnection_complete(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -36,5 +33,5 @@ data "azurerm_private_link_endpoint_connection" "test" { name = azurerm_private_link_endpoint.test.name resource_group_name = azurerm_resource_group.test.name } -`, testAccAzureRMPrivateLinkEndpoint_basic(rInt, location)) +`, testAccAzureRMPrivateLinkEndpoint_basic(data)) } diff --git a/azurerm/internal/services/network/tests/data_source_private_link_service_endpoint_connections_test.go b/azurerm/internal/services/network/tests/data_source_private_link_service_endpoint_connections_test.go new file mode 100644 index 000000000000..6de98ca1f889 --- /dev/null +++ b/azurerm/internal/services/network/tests/data_source_private_link_service_endpoint_connections_test.go @@ -0,0 +1,44 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourcePrivateLinkServiceEndpointConnections_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_private_link_service_endpoint_connections", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourcePrivateLinkServiceEndpointConnections_complete(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "private_endpoint_connections.0.action_required", "None"), + resource.TestCheckResourceAttr(data.ResourceName, "private_endpoint_connections.0.description", "Approved"), + resource.TestCheckResourceAttr(data.ResourceName, "private_endpoint_connections.0.status", "Approved"), + resource.TestCheckResourceAttrSet(data.ResourceName, "private_endpoint_connections.0.connection_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "private_endpoint_connections.0.connection_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "private_endpoint_connections.0.private_endpoint_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "private_endpoint_connections.0.private_endpoint_name"), + ), + }, + }, + }) +} + +func testAccDataSourcePrivateLinkServiceEndpointConnections_complete(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_private_link_service_endpoint_connections" "test" { + service_id = azurerm_private_link_service.test.id + resource_group_name = azurerm_resource_group.test.name + depends_on = [azurerm_private_link_endpoint.test,] +} +`, testAccAzureRMPrivateEndpoint_basic(data)) +} diff --git a/azurerm/internal/services/network/tests/data_source_private_link_service_test.go b/azurerm/internal/services/network/tests/data_source_private_link_service_test.go new file mode 100644 index 000000000000..108a0e79602a --- /dev/null +++ b/azurerm/internal/services/network/tests/data_source_private_link_service_test.go @@ -0,0 +1,48 @@ +package tests + +import ( + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMPrivateLinkService_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_private_link_service", "test") + subscriptionId := os.Getenv("ARM_SUBSCRIPTION_ID") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourcePrivateLinkService_complete(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.0.private_ip_address", "10.5.1.40"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.0.private_ip_address_version", "IPv4"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.1.private_ip_address", "10.5.1.41"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.1.private_ip_address_version", "IPv4"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_approval_subscription_ids.0", subscriptionId), + resource.TestCheckResourceAttr(data.ResourceName, "visibility_subscription_ids.0", subscriptionId), + resource.TestCheckResourceAttr(data.ResourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "load_balancer_frontend_ip_configuration_ids.0"), + ), + }, + }, + }) +} + +func testAccDataSourcePrivateLinkService_complete(data acceptance.TestData) string { + config := testAccAzureRMPrivateLinkService_complete(data) + return fmt.Sprintf(` +%s + +data "azurerm_private_link_service" "test" { + name = azurerm_private_link_service.test.name + resource_group_name = azurerm_private_link_service.test.resource_group_name +} +`, config) +} diff --git a/azurerm/internal/services/network/data_source_public_ip_prefix_test.go b/azurerm/internal/services/network/tests/data_source_public_ip_prefix_test.go similarity index 51% rename from azurerm/internal/services/network/data_source_public_ip_prefix_test.go rename to azurerm/internal/services/network/tests/data_source_public_ip_prefix_test.go index aec8d2629438..ca697c199dca 100644 --- a/azurerm/internal/services/network/data_source_public_ip_prefix_test.go +++ b/azurerm/internal/services/network/tests/data_source_public_ip_prefix_test.go @@ -1,42 +1,40 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMPublicIPPrefix_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - name := fmt.Sprintf("acctestpublicipprefix-%d", ri) - resourceGroupName := fmt.Sprintf("acctestRG-%d", ri) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_public_ip_prefix", "test") + name := fmt.Sprintf("acctestpublicipprefix-%d", data.RandomInteger) + resourceGroupName := fmt.Sprintf("acctestRG-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMPublicIPPrefixBasic(name, resourceGroupName, location), + Config: testAccDataSourceAzureRMPublicIPPrefixBasic(name, resourceGroupName, data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("data.azurerm_public_ip_prefix.test", "name", name), - resource.TestCheckResourceAttr("data.azurerm_public_ip_prefix.test", "resource_group_name", resourceGroupName), - resource.TestCheckResourceAttr("data.azurerm_public_ip_prefix.test", "location", location), - resource.TestCheckResourceAttr("data.azurerm_public_ip_prefix.test", "sku", "Standard"), - resource.TestCheckResourceAttr("data.azurerm_public_ip_prefix.test", "prefix_length", "31"), - resource.TestCheckResourceAttrSet("data.azurerm_public_ip_prefix.test", "ip_prefix"), - resource.TestCheckResourceAttr("data.azurerm_public_ip_prefix.test", "tags.%", "1"), - resource.TestCheckResourceAttr("data.azurerm_public_ip_prefix.test", "tags.env", "test"), + resource.TestCheckResourceAttr(data.ResourceName, "name", name), + resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName), + resource.TestCheckResourceAttr(data.ResourceName, "location", data.Locations.Primary), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "prefix_length", "31"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_prefix"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, }, }) } -func testAccDataSourceAzureRMPublicIPPrefixBasic(name string, resourceGroupName string, location string) string { +func testAccDataSourceAzureRMPublicIPPrefixBasic(name string, resourceGroupName string, data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "%s" @@ -63,5 +61,5 @@ data "azurerm_public_ip_prefix" "test" { name = azurerm_public_ip_prefix.test.name resource_group_name = azurerm_resource_group.test.name } -`, resourceGroupName, location, name) +`, resourceGroupName, data.Locations.Primary, name) } diff --git a/azurerm/internal/services/network/data_source_public_ip_test.go b/azurerm/internal/services/network/tests/data_source_public_ip_test.go similarity index 50% rename from azurerm/internal/services/network/data_source_public_ip_test.go rename to azurerm/internal/services/network/tests/data_source_public_ip_test.go index f1c5fe235bfc..58fb3ac2bb95 100644 --- a/azurerm/internal/services/network/data_source_public_ip_test.go +++ b/azurerm/internal/services/network/tests/data_source_public_ip_test.go @@ -1,20 +1,18 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMPublicIP_static(t *testing.T) { - dataSourceName := "data.azurerm_public_ip.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_public_ip", "test") - name := fmt.Sprintf("acctestpublicip-%d", ri) - resourceGroupName := fmt.Sprintf("acctestRG-%d", ri) + name := fmt.Sprintf("acctestpublicip-%d", data.RandomInteger) + resourceGroupName := fmt.Sprintf("acctestRG-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,17 +20,17 @@ func TestAccDataSourceAzureRMPublicIP_static(t *testing.T) { CheckDestroy: testCheckAzureRMPublicIpDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMPublicIP_static(name, resourceGroupName, ri, acceptance.Location()), + Config: testAccDataSourceAzureRMPublicIP_static(name, resourceGroupName, data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", name), - resource.TestCheckResourceAttr(dataSourceName, "resource_group_name", resourceGroupName), - resource.TestCheckResourceAttr(dataSourceName, "domain_name_label", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(dataSourceName, "idle_timeout_in_minutes", "30"), - resource.TestCheckResourceAttrSet(dataSourceName, "fqdn"), - resource.TestCheckResourceAttrSet(dataSourceName, "ip_address"), - resource.TestCheckResourceAttr(dataSourceName, "ip_version", "IPv4"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "test"), + resource.TestCheckResourceAttr(data.ResourceName, "name", name), + resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName), + resource.TestCheckResourceAttr(data.ResourceName, "domain_name_label", fmt.Sprintf("acctest-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "idle_timeout_in_minutes", "30"), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv4"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "test"), ), }, }, @@ -40,11 +38,10 @@ func TestAccDataSourceAzureRMPublicIP_static(t *testing.T) { } func TestAccDataSourceAzureRMPublicIP_dynamic(t *testing.T) { - dataSourceName := "data.azurerm_public_ip.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_public_ip", "test") - name := fmt.Sprintf("acctestpublicip-%d", ri) - resourceGroupName := fmt.Sprintf("acctestRG-%d", ri) + name := fmt.Sprintf("acctestpublicip-%d", data.RandomInteger) + resourceGroupName := fmt.Sprintf("acctestRG-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,23 +49,23 @@ func TestAccDataSourceAzureRMPublicIP_dynamic(t *testing.T) { CheckDestroy: testCheckAzureRMPublicIpDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMPublicIP_dynamic(ri, acceptance.Location(), "Ipv4"), + Config: testAccDataSourceAzureRMPublicIP_dynamic(data, "Ipv4"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", name), - resource.TestCheckResourceAttr(dataSourceName, "resource_group_name", resourceGroupName), - resource.TestCheckResourceAttr(dataSourceName, "domain_name_label", ""), - resource.TestCheckResourceAttr(dataSourceName, "fqdn", ""), - resource.TestCheckResourceAttr(dataSourceName, "ip_address", ""), - resource.TestCheckResourceAttr(dataSourceName, "ip_version", "IPv4"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.environment", "test"), + resource.TestCheckResourceAttr(data.ResourceName, "name", name), + resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName), + resource.TestCheckResourceAttr(data.ResourceName, "domain_name_label", ""), + resource.TestCheckResourceAttr(data.ResourceName, "fqdn", ""), + resource.TestCheckResourceAttr(data.ResourceName, "ip_address", ""), + resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv4"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "test"), ), }, }, }) } -func testAccDataSourceAzureRMPublicIP_static(name string, resourceGroupName string, rInt int, location string) string { +func testAccDataSourceAzureRMPublicIP_static(name string, resourceGroupName string, data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "%s" @@ -92,10 +89,10 @@ data "azurerm_public_ip" "test" { name = "${azurerm_public_ip.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, resourceGroupName, location, name, rInt) +`, resourceGroupName, data.Locations.Primary, name, data.RandomInteger) } -func testAccDataSourceAzureRMPublicIP_dynamic(rInt int, location string, ipVersion string) string { +func testAccDataSourceAzureRMPublicIP_dynamic(data acceptance.TestData, ipVersion string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -119,5 +116,5 @@ data "azurerm_public_ip" "test" { name = "${azurerm_public_ip.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, ipVersion) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, ipVersion) } diff --git a/azurerm/internal/services/network/data_source_public_ips_test.go b/azurerm/internal/services/network/tests/data_source_public_ips_test.go similarity index 75% rename from azurerm/internal/services/network/data_source_public_ips_test.go rename to azurerm/internal/services/network/tests/data_source_public_ips_test.go index 5086edaed360..59005ccffc6d 100644 --- a/azurerm/internal/services/network/data_source_public_ips_test.go +++ b/azurerm/internal/services/network/tests/data_source_public_ips_test.go @@ -1,23 +1,18 @@ -package network +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMPublicIPs_namePrefix(t *testing.T) { - dataSourceName := "data.azurerm_public_ips.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_public_ips", "test") - resourceConfig := testAccDataSourceAzureRMPublicIPs_prefix(ri, rs, location) - dataSourceConfig := testAccDataSourceAzureRMPublicIPs_prefixDataSource(ri, rs, location) + resourceConfig := testAccDataSourceAzureRMPublicIPs_prefix(data) + dataSourceConfig := testAccDataSourceAzureRMPublicIPs_prefixDataSource(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -31,8 +26,8 @@ func TestAccDataSourceAzureRMPublicIPs_namePrefix(t *testing.T) { { Config: dataSourceConfig, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "public_ips.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpipa%s-0", rs)), + resource.TestCheckResourceAttr(data.ResourceName, "public_ips.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "public_ips.0.name", fmt.Sprintf("acctestpipa%s-0", data.RandomString)), ), }, }, @@ -40,14 +35,13 @@ func TestAccDataSourceAzureRMPublicIPs_namePrefix(t *testing.T) { } func TestAccDataSourceAzureRMPublicIPs_assigned(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_public_ips", "test") + attachedDataSourceName := "data.azurerm_public_ips.attached" unattachedDataSourceName := "data.azurerm_public_ips.unattached" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() - resourceConfig := testAccDataSourceAzureRMPublicIPs_attached(ri, rs, location) - dataSourceConfig := testAccDataSourceAzureRMPublicIPs_attachedDataSource(ri, rs, location) + resourceConfig := testAccDataSourceAzureRMPublicIPs_attached(data) + dataSourceConfig := testAccDataSourceAzureRMPublicIPs_attachedDataSource(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -62,9 +56,9 @@ func TestAccDataSourceAzureRMPublicIPs_assigned(t *testing.T) { Config: dataSourceConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(attachedDataSourceName, "public_ips.#", "3"), - resource.TestCheckResourceAttr(attachedDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpip%s-0", rs)), + resource.TestCheckResourceAttr(attachedDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpip%s-0", data.RandomString)), resource.TestCheckResourceAttr(unattachedDataSourceName, "public_ips.#", "4"), - resource.TestCheckResourceAttr(unattachedDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpip%s-3", rs)), + resource.TestCheckResourceAttr(unattachedDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpip%s-3", data.RandomString)), ), }, }, @@ -72,14 +66,13 @@ func TestAccDataSourceAzureRMPublicIPs_assigned(t *testing.T) { } func TestAccDataSourceAzureRMPublicIPs_allocationType(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_public_ips", "test") + staticDataSourceName := "data.azurerm_public_ips.static" dynamicDataSourceName := "data.azurerm_public_ips.dynamic" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() - resourceConfig := testAccDataSourceAzureRMPublicIPs_allocationType(ri, rs, location) - dataSourceConfig := testAccDataSourceAzureRMPublicIPs_allocationTypeDataSources(ri, rs, location) + resourceConfig := testAccDataSourceAzureRMPublicIPs_allocationType(data) + dataSourceConfig := testAccDataSourceAzureRMPublicIPs_allocationTypeDataSources(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -94,16 +87,16 @@ func TestAccDataSourceAzureRMPublicIPs_allocationType(t *testing.T) { Config: dataSourceConfig, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(staticDataSourceName, "public_ips.#", "3"), - resource.TestCheckResourceAttr(staticDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpips%s-0", rs)), + resource.TestCheckResourceAttr(staticDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpips%s-0", data.RandomString)), resource.TestCheckResourceAttr(dynamicDataSourceName, "public_ips.#", "4"), - resource.TestCheckResourceAttr(dynamicDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpipd%s-0", rs)), + resource.TestCheckResourceAttr(dynamicDataSourceName, "public_ips.0.name", fmt.Sprintf("acctestpipd%s-0", data.RandomString)), ), }, }, }) } -func testAccDataSourceAzureRMPublicIPs_attached(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMPublicIPs_attached(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -134,11 +127,11 @@ resource "azurerm_lb" "test" { public_ip_address_id = "${element(azurerm_public_ip.test.*.id, count.index)}" } } -`, rInt, location, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString) } -func testAccDataSourceAzureRMPublicIPs_attachedDataSource(rInt int, rString string, location string) string { - resources := testAccDataSourceAzureRMPublicIPs_attached(rInt, rString, location) +func testAccDataSourceAzureRMPublicIPs_attachedDataSource(data acceptance.TestData) string { + resources := testAccDataSourceAzureRMPublicIPs_attached(data) return fmt.Sprintf(` %s @@ -154,7 +147,7 @@ data "azurerm_public_ips" "attached" { `, resources) } -func testAccDataSourceAzureRMPublicIPs_prefix(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMPublicIPs_prefix(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -186,11 +179,11 @@ resource "azurerm_public_ip" "test2" { environment = "test" } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccDataSourceAzureRMPublicIPs_prefixDataSource(rInt int, rString string, location string) string { - prefixed := testAccDataSourceAzureRMPublicIPs_prefix(rInt, rString, location) +func testAccDataSourceAzureRMPublicIPs_prefixDataSource(data acceptance.TestData) string { + prefixed := testAccDataSourceAzureRMPublicIPs_prefix(data) return fmt.Sprintf(` %s @@ -201,7 +194,7 @@ data "azurerm_public_ips" "test" { `, prefixed) } -func testAccDataSourceAzureRMPublicIPs_allocationType(rInt int, rString string, location string) string { +func testAccDataSourceAzureRMPublicIPs_allocationType(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -233,11 +226,11 @@ resource "azurerm_public_ip" "static" { environment = "test" } } -`, rInt, location, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } -func testAccDataSourceAzureRMPublicIPs_allocationTypeDataSources(rInt int, rString string, location string) string { - allocationType := testAccDataSourceAzureRMPublicIPs_allocationType(rInt, rString, location) +func testAccDataSourceAzureRMPublicIPs_allocationTypeDataSources(data acceptance.TestData) string { + allocationType := testAccDataSourceAzureRMPublicIPs_allocationType(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/tests/data_source_route_table_test.go b/azurerm/internal/services/network/tests/data_source_route_table_test.go new file mode 100644 index 000000000000..ca7d84c6ba39 --- /dev/null +++ b/azurerm/internal/services/network/tests/data_source_route_table_test.go @@ -0,0 +1,114 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMRouteTable_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_route_table", "test") + config := testAccDataSourceAzureRMRouteTable_basic(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMRouteTableDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMRouteTableExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMRouteTable_singleRoute(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_route_table", "test") + config := testAccDataSourceAzureRMRouteTable_singleRoute(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMRouteTableDestroy, + Steps: []resource.TestStep{ + { + Config: config, + 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"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMRouteTable_multipleRoutes(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_route_table", "test") + config := testAccDataSourceAzureRMRouteTable_multipleRoutes(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMRouteTableDestroy, + Steps: []resource.TestStep{ + { + Config: config, + 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"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMRouteTable_basic(data acceptance.TestData) string { + r := testAccAzureRMRouteTable_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_route_table" "test" { + name = "${azurerm_route_table.test.name}" + resource_group_name = "${azurerm_route_table.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMRouteTable_singleRoute(data acceptance.TestData) string { + r := testAccAzureRMRouteTable_singleRoute(data) + return fmt.Sprintf(` +%s + +data "azurerm_route_table" "test" { + name = "${azurerm_route_table.test.name}" + resource_group_name = "${azurerm_route_table.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMRouteTable_multipleRoutes(data acceptance.TestData) string { + r := testAccAzureRMRouteTable_multipleRoutes(data) + return fmt.Sprintf(` +%s + +data "azurerm_route_table" "test" { + name = "${azurerm_route_table.test.name}" + resource_group_name = "${azurerm_route_table.test.resource_group_name}" +} +`, r) +} diff --git a/azurerm/internal/services/network/data_source_subnet_test.go b/azurerm/internal/services/network/tests/data_source_subnet_test.go similarity index 63% rename from azurerm/internal/services/network/data_source_subnet_test.go rename to azurerm/internal/services/network/tests/data_source_subnet_test.go index b0b245fc2654..89440f431cfa 100644 --- a/azurerm/internal/services/network/data_source_subnet_test.go +++ b/azurerm/internal/services/network/tests/data_source_subnet_test.go @@ -1,31 +1,29 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMSubnet_basic(t *testing.T) { - resourceName := "data.azurerm_subnet.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSubnet_basic(ri, acceptance.Location()), + Config: testAccDataSourceAzureRMSubnet_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(resourceName, "virtual_network_name"), - resource.TestCheckResourceAttrSet(resourceName, "address_prefix"), - resource.TestCheckResourceAttr(resourceName, "network_security_group_id", ""), - resource.TestCheckResourceAttr(resourceName, "route_table_id", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "address_prefix"), + resource.TestCheckResourceAttr(data.ResourceName, "network_security_group_id", ""), + resource.TestCheckResourceAttr(data.ResourceName, "route_table_id", ""), ), }, }, @@ -33,22 +31,21 @@ func TestAccDataSourceAzureRMSubnet_basic(t *testing.T) { } func TestAccDataSourceAzureRMSubnet_networkSecurityGroup(t *testing.T) { - dataSourceName := "data.azurerm_subnet.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSubnet_networkSecurityGroup(ri, acceptance.Location()), + Config: testAccDataSourceAzureRMSubnet_networkSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "virtual_network_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "address_prefix"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_security_group_id"), - resource.TestCheckResourceAttr(dataSourceName, "route_table_id", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "address_prefix"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttr(data.ResourceName, "route_table_id", ""), ), }, }, @@ -56,22 +53,21 @@ func TestAccDataSourceAzureRMSubnet_networkSecurityGroup(t *testing.T) { } func TestAccDataSourceAzureRMSubnet_routeTable(t *testing.T) { - dataSourceName := "data.azurerm_subnet.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSubnet_routeTable(ri, acceptance.Location()), + Config: testAccDataSourceAzureRMSubnet_routeTable(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "virtual_network_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "address_prefix"), - resource.TestCheckResourceAttr(dataSourceName, "network_security_group_id", ""), - resource.TestCheckResourceAttrSet(dataSourceName, "route_table_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "address_prefix"), + resource.TestCheckResourceAttr(data.ResourceName, "network_security_group_id", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "route_table_id"), ), }, }, @@ -79,32 +75,31 @@ func TestAccDataSourceAzureRMSubnet_routeTable(t *testing.T) { } func TestAccDataSourceAzureRMSubnet_serviceEndpoints(t *testing.T) { - dataSourceName := "data.azurerm_subnet.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMSubnet_serviceEndpoints(ri, acceptance.Location()), + Config: testAccDataSourceAzureRMSubnet_serviceEndpoints(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "virtual_network_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "address_prefix"), - resource.TestCheckResourceAttr(dataSourceName, "network_security_group_id", ""), - resource.TestCheckResourceAttr(dataSourceName, "route_table_id", ""), - resource.TestCheckResourceAttr(dataSourceName, "service_endpoints.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "service_endpoints.0", "Microsoft.Sql"), - resource.TestCheckResourceAttr(dataSourceName, "service_endpoints.1", "Microsoft.Storage"), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "address_prefix"), + resource.TestCheckResourceAttr(data.ResourceName, "network_security_group_id", ""), + resource.TestCheckResourceAttr(data.ResourceName, "route_table_id", ""), + resource.TestCheckResourceAttr(data.ResourceName, "service_endpoints.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "service_endpoints.0", "Microsoft.Sql"), + resource.TestCheckResourceAttr(data.ResourceName, "service_endpoints.1", "Microsoft.Storage"), ), }, }, }) } -func testAccDataSourceAzureRMSubnet_basic(rInt int, location string) string { +func testAccDataSourceAzureRMSubnet_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest%d-rg" @@ -130,10 +125,10 @@ data "azurerm_subnet" "test" { resource_group_name = "${azurerm_resource_group.test.name}" virtual_network_name = "${azurerm_virtual_network.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccDataSourceAzureRMSubnet_networkSecurityGroup(rInt int, location string) string { +func testAccDataSourceAzureRMSubnet_networkSecurityGroup(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest%d-rg" @@ -178,10 +173,10 @@ data "azurerm_subnet" "test" { resource_group_name = "${azurerm_resource_group.test.name}" virtual_network_name = "${azurerm_virtual_network.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccDataSourceAzureRMSubnet_routeTable(rInt int, location string) string { +func testAccDataSourceAzureRMSubnet_routeTable(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -221,10 +216,10 @@ data "azurerm_subnet" "test" { resource_group_name = "${azurerm_resource_group.test.name}" virtual_network_name = "${azurerm_virtual_network.test.name}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccDataSourceAzureRMSubnet_serviceEndpoints(rInt int, location string) string { +func testAccDataSourceAzureRMSubnet_serviceEndpoints(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -251,5 +246,5 @@ data "azurerm_subnet" "test" { resource_group_name = "${azurerm_resource_group.test.name}" virtual_network_name = "${azurerm_virtual_network.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/data_source_virtual_hub_test.go b/azurerm/internal/services/network/tests/data_source_virtual_hub_test.go similarity index 55% rename from azurerm/internal/services/network/data_source_virtual_hub_test.go rename to azurerm/internal/services/network/tests/data_source_virtual_hub_test.go index 5cccc5921623..571412082d60 100644 --- a/azurerm/internal/services/network/data_source_virtual_hub_test.go +++ b/azurerm/internal/services/network/tests/data_source_virtual_hub_test.go @@ -1,36 +1,33 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMVirtualHub_basic(t *testing.T) { - dataSourceName := "data.azurerm_virtual_hub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_virtual_hub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceVirtualHub_basic(ri, location), + Config: testAccDataSourceVirtualHub_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "address_prefix"), - resource.TestCheckResourceAttrSet(dataSourceName, "virtual_wan_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "address_prefix"), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_wan_id"), ), }, }, }) } -func testAccDataSourceVirtualHub_basic(rInt int, location string) string { - config := testAccAzureRMVirtualHub_basic(rInt, location) +func testAccDataSourceVirtualHub_basic(data acceptance.TestData) string { + config := testAccAzureRMVirtualHub_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/data_source_virtual_machine_test.go b/azurerm/internal/services/network/tests/data_source_virtual_machine_test.go similarity index 87% rename from azurerm/internal/services/network/data_source_virtual_machine_test.go rename to azurerm/internal/services/network/tests/data_source_virtual_machine_test.go index 4a8a3f6a3a03..5674d61aa020 100644 --- a/azurerm/internal/services/network/data_source_virtual_machine_test.go +++ b/azurerm/internal/services/network/tests/data_source_virtual_machine_test.go @@ -1,20 +1,18 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceVirtualMachine_basic(t *testing.T) { - dataSourceName := "data.azurerm_virtual_machine.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_virtual_machine", "test") - name := fmt.Sprintf("acctvm-%d", ri) - config := testAccDataSourceVirtualMachine_basic(ri, acceptance.Location()) + name := fmt.Sprintf("acctvm-%d", data.RandomInteger) + config := testAccDataSourceVirtualMachine_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,13 +20,13 @@ func TestAccDataSourceVirtualMachine_basic(t *testing.T) { Steps: []resource.TestStep{ { Config: config, - Check: resource.TestCheckResourceAttr(dataSourceName, "name", name), + Check: resource.TestCheckResourceAttr(data.ResourceName, "name", name), }, }, }) } -func testAccDataSourceVirtualMachine_basic(rInt int, location string) string { +func testAccDataSourceVirtualMachine_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -112,5 +110,5 @@ data "azurerm_virtual_machine" "test" { resource_group_name = "${azurerm_resource_group.test.name}" name = "${azurerm_virtual_machine.test.name}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/network/data_source_virtual_network_gateway_connection_test.go b/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_connection_test.go similarity index 81% rename from azurerm/internal/services/network/data_source_virtual_network_gateway_connection_test.go rename to azurerm/internal/services/network/tests/data_source_virtual_network_gateway_connection_test.go index 107eb0ef11e3..dcc40c038c7e 100644 --- a/azurerm/internal/services/network/data_source_virtual_network_gateway_connection_test.go +++ b/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_connection_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_sitetosite(t *testing.T) { - resourceName := "azurerm_virtual_network_gateway_connection.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test") sharedKey := "4-v3ry-53cr37-1p53c-5h4r3d-k3y" - config := testAccAzureRMDataSourceVirtualNetworkGatewayConnection_sitetosite(ri, acceptance.Location()) + config := testAccAzureRMDataSourceVirtualNetworkGatewayConnection_sitetosite(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,9 +23,9 @@ func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_sitetosite(t *testi { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayConnectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "shared_key", sharedKey), - resource.TestCheckResourceAttr(resourceName, "type", string(network.IPsec)), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "shared_key", sharedKey), + resource.TestCheckResourceAttr(data.ResourceName, "type", string(network.IPsec)), ), }, }, @@ -35,13 +33,10 @@ func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_sitetosite(t *testi } func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_vnettovnet(t *testing.T) { - firstResourceName := "azurerm_virtual_network_gateway_connection.test_1" - secondResourceName := "azurerm_virtual_network_gateway_connection.test_2" + data1 := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test_1") + data2 := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test_2") - ri := tf.AccRandTimeInt() - ri2 := tf.AccRandTimeInt() sharedKey := "4-v3ry-53cr37-1p53c-5h4r3d-k3y" - config := testAccAzureRMDataSourceVirtualNetworkGatewayConnection_vnettovnet(ri, ri2, sharedKey, acceptance.Location(), acceptance.AltLocation()) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -49,14 +44,14 @@ func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_vnettovnet(t *testi CheckDestroy: testCheckAzureRMVirtualNetworkGatewayConnectionDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataSourceVirtualNetworkGatewayConnection_vnettovnet(data1, data2.RandomInteger, sharedKey), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayConnectionExists(firstResourceName), - testCheckAzureRMVirtualNetworkGatewayConnectionExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "shared_key", sharedKey), - resource.TestCheckResourceAttr(secondResourceName, "shared_key", sharedKey), - resource.TestCheckResourceAttr(firstResourceName, "type", string(network.Vnet2Vnet)), - resource.TestCheckResourceAttr(secondResourceName, "type", string(network.Vnet2Vnet)), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data1.ResourceName), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data2.ResourceName), + resource.TestCheckResourceAttr(data1.ResourceName, "shared_key", sharedKey), + resource.TestCheckResourceAttr(data2.ResourceName, "shared_key", sharedKey), + resource.TestCheckResourceAttr(data1.ResourceName, "type", string(network.Vnet2Vnet)), + resource.TestCheckResourceAttr(data2.ResourceName, "type", string(network.Vnet2Vnet)), ), }, }, @@ -64,10 +59,9 @@ func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_vnettovnet(t *testi } func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_ipsecpolicy(t *testing.T) { - resourceName := "azurerm_virtual_network_gateway_connection.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test") sharedKey := "4-v3ry-53cr37-1p53c-5h4r3d-k3y" - config := testAccAzureRMDataSourceVirtualNetworkGatewayConnection_ipsecpolicy(ri, acceptance.Location()) + config := testAccAzureRMDataSourceVirtualNetworkGatewayConnection_ipsecpolicy(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -77,25 +71,25 @@ func TestAccAzureRMDataSourceVirtualNetworkGatewayConnection_ipsecpolicy(t *test { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayConnectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "shared_key", sharedKey), - resource.TestCheckResourceAttr(resourceName, "type", string(network.IPsec)), - resource.TestCheckResourceAttr(resourceName, "routing_weight", "20"), - resource.TestCheckResourceAttr(resourceName, "ipsec_policy.0.dh_group", string(network.DHGroup14)), - resource.TestCheckResourceAttr(resourceName, "ipsec_policy.0.ike_encryption", string(network.AES256)), - resource.TestCheckResourceAttr(resourceName, "ipsec_policy.0.ike_integrity", string(network.IkeIntegritySHA256)), - resource.TestCheckResourceAttr(resourceName, "ipsec_policy.0.ipsec_encryption", string(network.IpsecEncryptionAES256)), - resource.TestCheckResourceAttr(resourceName, "ipsec_policy.0.ipsec_integrity", string(network.IpsecIntegritySHA256)), - resource.TestCheckResourceAttr(resourceName, "ipsec_policy.0.pfs_group", string(network.PfsGroupPFS2048)), - resource.TestCheckResourceAttr(resourceName, "ipsec_policy.0.sa_datasize", "102400000"), - resource.TestCheckResourceAttr(resourceName, "ipsec_policy.0.sa_lifetime", "27000"), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "shared_key", sharedKey), + resource.TestCheckResourceAttr(data.ResourceName, "type", string(network.IPsec)), + resource.TestCheckResourceAttr(data.ResourceName, "routing_weight", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "ipsec_policy.0.dh_group", string(network.DHGroup14)), + resource.TestCheckResourceAttr(data.ResourceName, "ipsec_policy.0.ike_encryption", string(network.AES256)), + resource.TestCheckResourceAttr(data.ResourceName, "ipsec_policy.0.ike_integrity", string(network.IkeIntegritySHA256)), + resource.TestCheckResourceAttr(data.ResourceName, "ipsec_policy.0.ipsec_encryption", string(network.IpsecEncryptionAES256)), + resource.TestCheckResourceAttr(data.ResourceName, "ipsec_policy.0.ipsec_integrity", string(network.IpsecIntegritySHA256)), + resource.TestCheckResourceAttr(data.ResourceName, "ipsec_policy.0.pfs_group", string(network.PfsGroupPFS2048)), + resource.TestCheckResourceAttr(data.ResourceName, "ipsec_policy.0.sa_datasize", "102400000"), + resource.TestCheckResourceAttr(data.ResourceName, "ipsec_policy.0.sa_lifetime", "27000"), ), }, }, }) } -func testAccAzureRMDataSourceVirtualNetworkGatewayConnection_sitetosite(rInt int, location string) string { +func testAccAzureRMDataSourceVirtualNetworkGatewayConnection_sitetosite(data acceptance.TestData) string { return fmt.Sprintf(` variable "random" { default = "%d" @@ -165,10 +159,10 @@ data "azurerm_virtual_network_gateway_connection" "test" { name = "${azurerm_virtual_network_gateway_connection.test.name}" resource_group_name = "${azurerm_virtual_network_gateway_connection.test.resource_group_name}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMDataSourceVirtualNetworkGatewayConnection_vnettovnet(rInt, rInt2 int, sharedKey, location, altLocation string) string { +func testAccAzureRMDataSourceVirtualNetworkGatewayConnection_vnettovnet(data acceptance.TestData, rInt2 int, sharedKey string) string { return fmt.Sprintf(` variable "random1" { default = "%d" @@ -301,10 +295,10 @@ data "azurerm_virtual_network_gateway_connection" "test_2" { name = "${azurerm_virtual_network_gateway_connection.test_2.name}" resource_group_name = "${azurerm_virtual_network_gateway_connection.test_2.resource_group_name}" } -`, rInt, rInt2, sharedKey, location, altLocation) +`, data.RandomInteger, rInt2, sharedKey, data.Locations.Primary, data.Locations.Secondary) } -func testAccAzureRMDataSourceVirtualNetworkGatewayConnection_ipsecpolicy(rInt int, location string) string { +func testAccAzureRMDataSourceVirtualNetworkGatewayConnection_ipsecpolicy(data acceptance.TestData) string { return fmt.Sprintf(` variable "random" { default = "%d" @@ -388,5 +382,5 @@ data "azurerm_virtual_network_gateway_connection" "test" { name = "${azurerm_virtual_network_gateway_connection.test.name}" resource_group_name = "${azurerm_virtual_network_gateway_connection.test.resource_group_name}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/network/data_source_virtual_network_gateway_test.go b/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_test.go similarity index 85% rename from azurerm/internal/services/network/data_source_virtual_network_gateway_test.go rename to azurerm/internal/services/network/tests/data_source_virtual_network_gateway_test.go index f2809a54ad5f..7ecd9af8bbb8 100644 --- a/azurerm/internal/services/network/data_source_virtual_network_gateway_test.go +++ b/azurerm/internal/services/network/tests/data_source_virtual_network_gateway_test.go @@ -1,17 +1,15 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMDataSourceVirtualNetworkGateway_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataSourceVirtualNetworkGateway_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "data.azurerm_virtual_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -19,7 +17,7 @@ func TestAccAzureRMDataSourceVirtualNetworkGateway_basic(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataSourceVirtualNetworkGateway_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualNetworkGatewayExists("data.azurerm_virtual_network_gateway.test"), ), @@ -28,7 +26,7 @@ func TestAccAzureRMDataSourceVirtualNetworkGateway_basic(t *testing.T) { }) } -func testAccAzureRMDataSourceVirtualNetworkGateway_basic(rInt int, location string) string { +func testAccAzureRMDataSourceVirtualNetworkGateway_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -76,5 +74,5 @@ data "azurerm_virtual_network_gateway" "test" { name = "${azurerm_virtual_network_gateway.test.name}" resource_group_name = "${azurerm_virtual_network_gateway.test.resource_group_name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/data_source_virtual_network_test.go b/azurerm/internal/services/network/tests/data_source_virtual_network_test.go similarity index 69% rename from azurerm/internal/services/network/data_source_virtual_network_test.go rename to azurerm/internal/services/network/tests/data_source_virtual_network_test.go index 95bc6633ae4c..474914c84acf 100644 --- a/azurerm/internal/services/network/data_source_virtual_network_test.go +++ b/azurerm/internal/services/network/tests/data_source_virtual_network_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,17 +6,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceArmVirtualNetwork_basic(t *testing.T) { - dataSourceName := "data.azurerm_virtual_network.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_virtual_network", "test") - name := fmt.Sprintf("acctestvnet-%d", ri) - location := acceptance.Location() - config := testAccDataSourceArmVirtualNetwork_basic(ri, acceptance.Location()) + name := fmt.Sprintf("acctestvnet-%d", data.RandomInteger) + config := testAccDataSourceArmVirtualNetwork_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,11 +22,11 @@ func TestAccDataSourceArmVirtualNetwork_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", name), - resource.TestCheckResourceAttr(dataSourceName, "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr(dataSourceName, "dns_servers.0", "10.0.0.4"), - resource.TestCheckResourceAttr(dataSourceName, "address_spaces.0", "10.0.0.0/16"), - resource.TestCheckResourceAttr(dataSourceName, "subnets.0", "subnet1"), + resource.TestCheckResourceAttr(data.ResourceName, "name", name), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "dns_servers.0", "10.0.0.4"), + resource.TestCheckResourceAttr(data.ResourceName, "address_spaces.0", "10.0.0.0/16"), + resource.TestCheckResourceAttr(data.ResourceName, "subnets.0", "subnet1"), ), }, }, @@ -37,32 +34,30 @@ func TestAccDataSourceArmVirtualNetwork_basic(t *testing.T) { } func TestAccDataSourceArmVirtualNetwork_peering(t *testing.T) { - dataSourceName := "data.azurerm_virtual_network.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_virtual_network", "test") - virtualNetworkName := fmt.Sprintf("acctestvnet-1-%d", ri) - location := acceptance.Location() + virtualNetworkName := fmt.Sprintf("acctestvnet-1-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceArmVirtualNetwork_peering(ri, location), + Config: testAccDataSourceArmVirtualNetwork_peering(data), }, { - Config: testAccDataSourceArmVirtualNetwork_peeringWithDataSource(ri, location), + Config: testAccDataSourceArmVirtualNetwork_peeringWithDataSource(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", virtualNetworkName), - resource.TestCheckResourceAttr(dataSourceName, "address_spaces.0", "10.0.1.0/24"), - resource.TestCheckResourceAttr(dataSourceName, "vnet_peerings.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "name", virtualNetworkName), + resource.TestCheckResourceAttr(data.ResourceName, "address_spaces.0", "10.0.1.0/24"), + resource.TestCheckResourceAttr(data.ResourceName, "vnet_peerings.%", "1"), ), }, }, }) } -func testAccDataSourceArmVirtualNetwork_basic(rInt int, location string) string { +func testAccDataSourceArmVirtualNetwork_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest%d-rg" @@ -86,10 +81,10 @@ data "azurerm_virtual_network" "test" { resource_group_name = "${azurerm_resource_group.test.name}" name = "${azurerm_virtual_network.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceArmVirtualNetwork_peering(rInt int, location string) string { +func testAccDataSourceArmVirtualNetwork_peering(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest%d-rg" @@ -116,10 +111,10 @@ resource "azurerm_virtual_network_peering" "test1" { virtual_network_name = "${azurerm_virtual_network.test1.name}" remote_virtual_network_id = "${azurerm_virtual_network.test2.id}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccDataSourceArmVirtualNetwork_peeringWithDataSource(rInt int, location string) string { +func testAccDataSourceArmVirtualNetwork_peeringWithDataSource(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest%d-rg" @@ -151,5 +146,5 @@ data "azurerm_virtual_network" "test" { resource_group_name = "${azurerm_resource_group.test.name}" name = "${azurerm_virtual_network.test1.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/network_security_group_test.go b/azurerm/internal/services/network/tests/network_security_group_test.go similarity index 81% rename from azurerm/internal/services/network/network_security_group_test.go rename to azurerm/internal/services/network/tests/network_security_group_test.go index 4b98e753b55d..9b59b3fa5c4b 100644 --- a/azurerm/internal/services/network/network_security_group_test.go +++ b/azurerm/internal/services/network/tests/network_security_group_test.go @@ -1,14 +1,16 @@ -package network +package tests import ( "testing" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" ) func TestParseNetworkSecurityGroup(t *testing.T) { testData := []struct { Name string Input string - Expected *NetworkSecurityGroupResourceID + Expected *network.NetworkSecurityGroupResourceID }{ { Name: "Empty", @@ -28,7 +30,7 @@ func TestParseNetworkSecurityGroup(t *testing.T) { { Name: "Completed", Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/networkSecurityGroups/example", - Expected: &NetworkSecurityGroupResourceID{ + Expected: &network.NetworkSecurityGroupResourceID{ Name: "example", ResourceGroup: "foo", }, @@ -38,7 +40,7 @@ func TestParseNetworkSecurityGroup(t *testing.T) { for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Name) - actual, err := ParseNetworkSecurityGroupID(v.Input) + actual, err := network.ParseNetworkSecurityGroupID(v.Input) if err != nil { if v.Expected == nil { continue diff --git a/azurerm/internal/services/network/point_to_site_vpn_gateway_test.go b/azurerm/internal/services/network/tests/point_to_site_vpn_gateway_test.go similarity index 81% rename from azurerm/internal/services/network/point_to_site_vpn_gateway_test.go rename to azurerm/internal/services/network/tests/point_to_site_vpn_gateway_test.go index 803fed7bebcb..bc3e245e507e 100644 --- a/azurerm/internal/services/network/point_to_site_vpn_gateway_test.go +++ b/azurerm/internal/services/network/tests/point_to_site_vpn_gateway_test.go @@ -1,14 +1,16 @@ -package network +package tests import ( "testing" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" ) func TestParsePointToSiteVPNGateway(t *testing.T) { testData := []struct { Name string Input string - Expected *PointToSiteVPNGatewayResourceID + Expected *network.PointToSiteVPNGatewayResourceID }{ { Name: "Empty", @@ -28,7 +30,7 @@ func TestParsePointToSiteVPNGateway(t *testing.T) { { Name: "Completed", Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/p2sVpnGateways/example", - Expected: &PointToSiteVPNGatewayResourceID{ + Expected: &network.PointToSiteVPNGatewayResourceID{ Name: "example", ResourceGroup: "foo", }, @@ -38,7 +40,7 @@ func TestParsePointToSiteVPNGateway(t *testing.T) { for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Name) - actual, err := ParsePointToSiteVPNGatewayID(v.Input) + actual, err := network.ParsePointToSiteVPNGatewayID(v.Input) if err != nil { if v.Expected == nil { continue diff --git a/azurerm/internal/services/network/private_link_endpoint_test.go b/azurerm/internal/services/network/tests/private_link_endpoint_test.go similarity index 90% rename from azurerm/internal/services/network/private_link_endpoint_test.go rename to azurerm/internal/services/network/tests/private_link_endpoint_test.go index b7ccd7116939..abf2d642178a 100644 --- a/azurerm/internal/services/network/private_link_endpoint_test.go +++ b/azurerm/internal/services/network/tests/private_link_endpoint_test.go @@ -1,7 +1,9 @@ -package network +package tests import ( "testing" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" ) func TestValidatePrivateLinkSubResourceName(t *testing.T) { @@ -125,7 +127,7 @@ func TestValidatePrivateLinkSubResourceName(t *testing.T) { for _, v := range testData { t.Logf("[DEBUG] Testing %q", v.Name) - _, errors := ValidatePrivateLinkSubResourceName(v.Input, "private_link_endpoint_subresource") + _, errors := network.ValidatePrivateLinkSubResourceName(v.Input, "private_link_endpoint_subresource") isValid := len(errors) == 0 if v.Valid != isValid { t.Fatalf("Expected %t but got %t", v.Valid, isValid) diff --git a/azurerm/internal/services/network/resource_arm_application_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_application_gateway_test.go similarity index 79% rename from azurerm/internal/services/network/resource_arm_application_gateway_test.go rename to azurerm/internal/services/network/tests/resource_arm_application_gateway_test.go index f4678c029abb..a7dae45ad2d6 100644 --- a/azurerm/internal/services/network/resource_arm_application_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_application_gateway_test.go @@ -1,14 +1,12 @@ -package network +package tests import ( "fmt" "regexp" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,8 +14,7 @@ import ( ) func TestAccAzureRMApplicationGateway_basic(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,27 +22,22 @@ func TestAccAzureRMApplicationGateway_basic(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_basic(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_Small"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Standard"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "2"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.#", "0"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_Small"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_autoscaleConfiguration(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,39 +45,34 @@ func TestAccAzureRMApplicationGateway_autoscaleConfiguration(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_autoscaleConfiguration(ri, acceptance.Location(), 0, 10), + Config: testAccAzureRMApplicationGateway_autoscaleConfiguration(data, 0, 10), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Standard_v2"), - resource.TestCheckResourceAttr(resourceName, "autoscale_configuration.0.min_capacity", "0"), - resource.TestCheckResourceAttr(resourceName, "autoscale_configuration.0.max_capacity", "10"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.#", "0"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Standard_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "autoscale_configuration.0.min_capacity", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "autoscale_configuration.0.max_capacity", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.#", "0"), ), }, { - Config: testAccAzureRMApplicationGateway_autoscaleConfiguration(ri, acceptance.Location(), 4, 12), + Config: testAccAzureRMApplicationGateway_autoscaleConfiguration(data, 4, 12), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Standard_v2"), - resource.TestCheckResourceAttr(resourceName, "autoscale_configuration.0.min_capacity", "4"), - resource.TestCheckResourceAttr(resourceName, "autoscale_configuration.0.max_capacity", "12"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.#", "0"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Standard_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "autoscale_configuration.0.min_capacity", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "autoscale_configuration.0.max_capacity", "12"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_autoscaleConfigurationNoMaxCapacity(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -93,27 +80,22 @@ func TestAccAzureRMApplicationGateway_autoscaleConfigurationNoMaxCapacity(t *tes CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_autoscaleConfigurationNoMaxCapacity(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_autoscaleConfigurationNoMaxCapacity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Standard_v2"), - resource.TestCheckResourceAttr(resourceName, "autoscale_configuration.0.min_capacity", "2"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.#", "0"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Standard_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "autoscale_configuration.0.min_capacity", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_zones(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -121,28 +103,23 @@ func TestAccAzureRMApplicationGateway_zones(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_zones(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_zones(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Standard_v2"), - resource.TestCheckResourceAttr(resourceName, "zones.#", "2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "2"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.#", "0"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Standard_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_overridePath(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -150,24 +127,19 @@ func TestAccAzureRMApplicationGateway_overridePath(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_overridePath(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_overridePath(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "backend_http_settings.0.path", "/path1/"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backend_http_settings.0.path", "/path1/"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_http2(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -175,17 +147,13 @@ func TestAccAzureRMApplicationGateway_http2(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_http2(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_http2(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_http2", "true"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_http2", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -196,9 +164,7 @@ func TestAccAzureRMApplicationGateway_requiresImport(t *testing.T) { return } - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -206,13 +172,13 @@ func TestAccAzureRMApplicationGateway_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_basic(ri, location), + Config: testAccAzureRMApplicationGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), ), }, { - Config: testAccAzureRMApplicationGateway_requiresImport(ri, location), + Config: testAccAzureRMApplicationGateway_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_application_gateway"), }, }, @@ -220,9 +186,7 @@ func TestAccAzureRMApplicationGateway_requiresImport(t *testing.T) { } func TestAccAzureRMApplicationGateway_authCertificate(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -230,37 +194,29 @@ func TestAccAzureRMApplicationGateway_authCertificate(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_authCertificate(ri, location), + Config: testAccAzureRMApplicationGateway_authCertificate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "authentication_certificate.0.name"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "authentication_certificate.0.name"), ), }, + // since these are read from the existing state + data.ImportStep( + + "authentication_certificate.0.data", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // since these are read from the existing state - "authentication_certificate.0.data", - }, - }, - { - Config: testAccAzureRMApplicationGateway_authCertificateUpdated(ri, location), + Config: testAccAzureRMApplicationGateway_authCertificateUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "authentication_certificate.0.name"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "authentication_certificate.0.name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // since these are read from the existing state - "authentication_certificate.0.data", - }, - }, + // since these are read from the existing state + data.ImportStep( + + "authentication_certificate.0.data", + ), }, }) } @@ -269,9 +225,7 @@ func TestAccAzureRMApplicationGateway_authCertificate(t *testing.T) { func TestAccAzureRMApplicationGateway_trustedRootCertificate_keyvault(t *testing.T) { t.Skip() - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -279,25 +233,19 @@ func TestAccAzureRMApplicationGateway_trustedRootCertificate_keyvault(t *testing CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_trustedRootCertificate_keyvault(ri, location), + Config: testAccAzureRMApplicationGateway_trustedRootCertificate_keyvault(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "trusted_root_certificate.0.name"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "trusted_root_certificate.0.name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_trustedRootCertificate(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -305,44 +253,33 @@ func TestAccAzureRMApplicationGateway_trustedRootCertificate(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_trustedRootCertificate(ri, location), + Config: testAccAzureRMApplicationGateway_trustedRootCertificate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "trusted_root_certificate.0.name"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "trusted_root_certificate.0.name"), ), }, + // since these are read from the existing state + data.ImportStep( + "trusted_root_certificate.0.data", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // since these are read from the existing state - "trusted_root_certificate.0.data", - }, - }, - { - Config: testAccAzureRMApplicationGateway_trustedRootCertificateUpdated(ri, location), + Config: testAccAzureRMApplicationGateway_trustedRootCertificateUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "trusted_root_certificate.0.name"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "trusted_root_certificate.0.name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // since these are read from the existing state - "trusted_root_certificate.0.data", - }, - }, + // since these are read from the existing state + data.ImportStep( + "trusted_root_certificate.0.data", + ), }, }) } func TestAccAzureRMApplicationGateway_pathBasedRouting(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -350,23 +287,18 @@ func TestAccAzureRMApplicationGateway_pathBasedRouting(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_pathBasedRouting(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_pathBasedRouting(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_routingRedirect_httpListener(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -374,27 +306,23 @@ func TestAccAzureRMApplicationGateway_routingRedirect_httpListener(t *testing.T) CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_routingRedirect_httpListener(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_routingRedirect_httpListener(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "redirect_configuration.0.name"), - resource.TestCheckResourceAttr(resourceName, "redirect_configuration.0.redirect_type", "Temporary"), - resource.TestCheckResourceAttrSet(resourceName, "redirect_configuration.0.target_listener_name"), - resource.TestCheckResourceAttr(resourceName, "redirect_configuration.0.include_path", "true"), - resource.TestCheckResourceAttr(resourceName, "redirect_configuration.0.include_query_string", "false"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "redirect_configuration.0.name"), + resource.TestCheckResourceAttr(data.ResourceName, "redirect_configuration.0.redirect_type", "Temporary"), + resource.TestCheckResourceAttrSet(data.ResourceName, "redirect_configuration.0.target_listener_name"), + resource.TestCheckResourceAttr(data.ResourceName, "redirect_configuration.0.include_path", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "redirect_configuration.0.include_query_string", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_routingRedirect_httpListenerError(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -402,7 +330,7 @@ func TestAccAzureRMApplicationGateway_routingRedirect_httpListenerError(t *testi CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_routingRedirect_httpListenerError(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_routingRedirect_httpListenerError(data), ExpectError: regexp.MustCompile("Conflict between `backend_address_pool_name` and `redirect_configuration_name`"), }, }, @@ -410,8 +338,7 @@ func TestAccAzureRMApplicationGateway_routingRedirect_httpListenerError(t *testi } func TestAccAzureRMApplicationGateway_routingRedirect_pathBased(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -419,32 +346,27 @@ func TestAccAzureRMApplicationGateway_routingRedirect_pathBased(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_routingRedirect_pathBased(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_routingRedirect_pathBased(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "redirect_configuration.0.name"), - resource.TestCheckResourceAttr(resourceName, "redirect_configuration.0.redirect_type", "Found"), - resource.TestCheckResourceAttr(resourceName, "redirect_configuration.0.target_url", "http://www.example.com"), - resource.TestCheckResourceAttr(resourceName, "redirect_configuration.0.include_query_string", "true"), - resource.TestCheckResourceAttrSet(resourceName, "redirect_configuration.1.name"), - resource.TestCheckResourceAttr(resourceName, "redirect_configuration.1.redirect_type", "Permanent"), - resource.TestCheckResourceAttrSet(resourceName, "redirect_configuration.1.target_listener_name"), - resource.TestCheckResourceAttr(resourceName, "redirect_configuration.1.include_path", "false"), - resource.TestCheckResourceAttr(resourceName, "redirect_configuration.1.include_query_string", "false"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "redirect_configuration.0.name"), + resource.TestCheckResourceAttr(data.ResourceName, "redirect_configuration.0.redirect_type", "Found"), + resource.TestCheckResourceAttr(data.ResourceName, "redirect_configuration.0.target_url", "http://www.example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "redirect_configuration.0.include_query_string", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "redirect_configuration.1.name"), + resource.TestCheckResourceAttr(data.ResourceName, "redirect_configuration.1.redirect_type", "Permanent"), + resource.TestCheckResourceAttrSet(data.ResourceName, "redirect_configuration.1.target_listener_name"), + resource.TestCheckResourceAttr(data.ResourceName, "redirect_configuration.1.include_path", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "redirect_configuration.1.include_query_string", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_customErrorConfigurations(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -452,23 +374,18 @@ func TestAccAzureRMApplicationGateway_customErrorConfigurations(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_customErrorConfigurations(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_customErrorConfigurations(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_rewriteRuleSets_backend(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -476,24 +393,19 @@ func TestAccAzureRMApplicationGateway_rewriteRuleSets_backend(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_rewriteRuleSets_backend(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_rewriteRuleSets_backend(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "rewrite_rule_set.0.name"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "rewrite_rule_set.0.name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_rewriteRuleSets_redirect(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -501,24 +413,19 @@ func TestAccAzureRMApplicationGateway_rewriteRuleSets_redirect(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_rewriteRuleSets_redirect(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_rewriteRuleSets_redirect(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "rewrite_rule_set.0.name"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "rewrite_rule_set.0.name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_probes(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -526,23 +433,18 @@ func TestAccAzureRMApplicationGateway_probes(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_probes(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_probes(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_probesEmptyMatch(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -550,23 +452,18 @@ func TestAccAzureRMApplicationGateway_probesEmptyMatch(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_probesEmptyMatch(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_probesEmptyMatch(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_probesPickHostNameFromBackendHTTPSettings(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -574,24 +471,19 @@ func TestAccAzureRMApplicationGateway_probesPickHostNameFromBackendHTTPSettings( CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_probesPickHostNameFromBackendHTTPSettings(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_probesPickHostNameFromBackendHTTPSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "probe.0.pick_host_name_from_backend_http_settings", "true"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "probe.0.pick_host_name_from_backend_http_settings", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_backendHttpSettingsHostName(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") hostName := "example.com" resource.ParallelTest(t, resource.TestCase{ @@ -600,23 +492,19 @@ func TestAccAzureRMApplicationGateway_backendHttpSettingsHostName(t *testing.T) CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_backendHttpSettingsHostName(ri, acceptance.Location(), hostName, false), + Config: testAccAzureRMApplicationGateway_backendHttpSettingsHostName(data, hostName, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "backend_http_settings.0.host_name", hostName), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backend_http_settings.0.host_name", hostName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_backendHttpSettingsHostNameAndPick(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") hostName := "example.com" resource.ParallelTest(t, resource.TestCase{ @@ -625,7 +513,7 @@ func TestAccAzureRMApplicationGateway_backendHttpSettingsHostNameAndPick(t *test CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_backendHttpSettingsHostName(ri, acceptance.Location(), hostName, true), + Config: testAccAzureRMApplicationGateway_backendHttpSettingsHostName(data, hostName, true), ExpectError: regexp.MustCompile("Only one of `host_name` or `pick_host_name_from_backend_address` can be set"), }, }, @@ -633,8 +521,7 @@ func TestAccAzureRMApplicationGateway_backendHttpSettingsHostNameAndPick(t *test } func TestAccAzureRMApplicationGateway_settingsPickHostNameFromBackendAddress(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -642,24 +529,19 @@ func TestAccAzureRMApplicationGateway_settingsPickHostNameFromBackendAddress(t * CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_settingsPickHostNameFromBackendAddress(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_settingsPickHostNameFromBackendAddress(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "backend_http_settings.0.pick_host_name_from_backend_address", "true"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backend_http_settings.0.pick_host_name_from_backend_address", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_sslCertificate(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -667,44 +549,33 @@ func TestAccAzureRMApplicationGateway_sslCertificate(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_sslCertificate(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_sslCertificate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), ), }, + // since these are read from the existing state + data.ImportStep( + "ssl_certificate.0.data", + "ssl_certificate.0.password", + ), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // since these are read from the existing state - "ssl_certificate.0.data", - "ssl_certificate.0.password", - }, - }, - { - Config: testAccAzureRMApplicationGateway_sslCertificateUpdated(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_sslCertificateUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // since these are read from the existing state - "ssl_certificate.0.data", - "ssl_certificate.0.password", - }, - }, + // since these are read from the existing state + data.ImportStep( + "ssl_certificate.0.data", + "ssl_certificate.0.password", + ), }, }) } func TestAccAzureRMApplicationGateway_webApplicationFirewall(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -712,19 +583,19 @@ func TestAccAzureRMApplicationGateway_webApplicationFirewall(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_webApplicationFirewall(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_webApplicationFirewall(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "WAF_Medium"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "WAF"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.firewall_mode", "Detection"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.rule_set_type", "OWASP"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.rule_set_version", "3.0"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.file_upload_limit_mb", "100"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.request_body_check", "true"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.max_request_body_size_kb", "100"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "WAF_Medium"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "WAF"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.firewall_mode", "Detection"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.rule_set_type", "OWASP"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.rule_set_version", "3.0"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.file_upload_limit_mb", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.request_body_check", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.max_request_body_size_kb", "100"), ), }, }, @@ -732,8 +603,7 @@ func TestAccAzureRMApplicationGateway_webApplicationFirewall(t *testing.T) { } func TestAccAzureRMApplicationGateway_connectionDraining(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -741,41 +611,32 @@ func TestAccAzureRMApplicationGateway_connectionDraining(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_connectionDraining(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_connectionDraining(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "backend_http_settings.0.connection_draining.0.enabled", "true"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backend_http_settings.0.connection_draining.0.enabled", "true"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMApplicationGateway_basic(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "Standard_Small"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Standard"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "2"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.#", "0"), - resource.TestCheckNoResourceAttr(resourceName, "backend_http_settings.0.connection_draining.0.enabled"), - resource.TestCheckNoResourceAttr(resourceName, "backend_http_settings.0.connection_draining.0.drain_timeout_sec"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "Standard_Small"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.#", "0"), + resource.TestCheckNoResourceAttr(data.ResourceName, "backend_http_settings.0.connection_draining.0.enabled"), + resource.TestCheckNoResourceAttr(data.ResourceName, "backend_http_settings.0.connection_draining.0.drain_timeout_sec"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -783,48 +644,48 @@ func TestAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups( CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "WAF_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "WAF_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.firewall_mode", "Detection"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.rule_set_type", "OWASP"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.rule_set_version", "3.0"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.request_body_check", "true"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.max_request_body_size_kb", "128"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.file_upload_limit_mb", "100"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.0.rule_group_name", "REQUEST-921-PROTOCOL-ATTACK"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.0.rules.0", "921110"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.0.rules.1", "921151"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.0.rules.2", "921180"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.1.rule_group_name", "REQUEST-930-APPLICATION-ATTACK-LFI"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.1.rules.0", "930120"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.1.rules.1", "930130"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.2.rule_group_name", "REQUEST-942-APPLICATION-ATTACK-SQLI"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "WAF_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "WAF_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.firewall_mode", "Detection"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.rule_set_type", "OWASP"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.rule_set_version", "3.0"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.request_body_check", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.max_request_body_size_kb", "128"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.file_upload_limit_mb", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.0.rule_group_name", "REQUEST-921-PROTOCOL-ATTACK"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.0.rules.0", "921110"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.0.rules.1", "921151"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.0.rules.2", "921180"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.1.rule_group_name", "REQUEST-930-APPLICATION-ATTACK-LFI"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.1.rules.0", "930120"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.1.rules.1", "930130"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.2.rule_group_name", "REQUEST-942-APPLICATION-ATTACK-SQLI"), ), }, { - Config: testAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups_enabled_some_rules(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups_enabled_some_rules(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "WAF_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "WAF_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.firewall_mode", "Detection"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.rule_set_type", "OWASP"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.rule_set_version", "3.0"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.request_body_check", "true"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.max_request_body_size_kb", "128"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.file_upload_limit_mb", "100"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.0.rule_group_name", "REQUEST-921-PROTOCOL-ATTACK"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.0.rules.0", "921110"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.0.rules.1", "921151"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.0.rules.2", "921180"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.disabled_rule_group.1.rule_group_name", "REQUEST-942-APPLICATION-ATTACK-SQLI"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "WAF_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "WAF_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.firewall_mode", "Detection"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.rule_set_type", "OWASP"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.rule_set_version", "3.0"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.request_body_check", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.max_request_body_size_kb", "128"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.file_upload_limit_mb", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.0.rule_group_name", "REQUEST-921-PROTOCOL-ATTACK"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.0.rules.0", "921110"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.0.rules.1", "921151"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.0.rules.2", "921180"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.disabled_rule_group.1.rule_group_name", "REQUEST-942-APPLICATION-ATTACK-SQLI"), ), }, }, @@ -832,8 +693,7 @@ func TestAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups( } func TestAccAzureRMApplicationGateway_webApplicationFirewall_exclusions(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -841,53 +701,53 @@ func TestAccAzureRMApplicationGateway_webApplicationFirewall_exclusions(t *testi CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_webApplicationFirewall_exclusions_many(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_webApplicationFirewall_exclusions_many(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "WAF_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "WAF_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.firewall_mode", "Detection"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.rule_set_type", "OWASP"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.rule_set_version", "3.0"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.request_body_check", "true"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.max_request_body_size_kb", "128"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.file_upload_limit_mb", "100"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.0.match_variable", "RequestArgNames"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.0.selector_match_operator", "Equals"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.0.selector", "displayNameHtml"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.1.match_variable", "RequestCookieNames"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.1.selector_match_operator", "EndsWith"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.1.selector", "username"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.2.match_variable", "RequestHeaderNames"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.2.selector_match_operator", "StartsWith"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.2.selector", "ORIGIN"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.3.match_variable", "RequestHeaderNames"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.3.selector_match_operator", "Contains"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.3.selector", "ORIGIN"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.4.match_variable", "RequestHeaderNames"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.4.selector_match_operator", ""), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.4.selector", ""), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "WAF_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "WAF_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.firewall_mode", "Detection"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.rule_set_type", "OWASP"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.rule_set_version", "3.0"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.request_body_check", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.max_request_body_size_kb", "128"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.file_upload_limit_mb", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.0.match_variable", "RequestArgNames"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.0.selector_match_operator", "Equals"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.0.selector", "displayNameHtml"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.1.match_variable", "RequestCookieNames"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.1.selector_match_operator", "EndsWith"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.1.selector", "username"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.2.match_variable", "RequestHeaderNames"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.2.selector_match_operator", "StartsWith"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.2.selector", "ORIGIN"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.3.match_variable", "RequestHeaderNames"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.3.selector_match_operator", "Contains"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.3.selector", "ORIGIN"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.4.match_variable", "RequestHeaderNames"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.4.selector_match_operator", ""), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.4.selector", ""), ), }, { - Config: testAccAzureRMApplicationGateway_webApplicationFirewall_exclusions_one(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_webApplicationFirewall_exclusions_one(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.0.name", "WAF_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "WAF_v2"), - resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "1"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.firewall_mode", "Detection"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.rule_set_type", "OWASP"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.rule_set_version", "3.0"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.request_body_check", "true"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.max_request_body_size_kb", "128"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.file_upload_limit_mb", "100"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.0.match_variable", "RequestArgNames"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.0.selector_match_operator", "Equals"), - resource.TestCheckResourceAttr(resourceName, "waf_configuration.0.exclusion.0.selector", "displayNameHtml"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.name", "WAF_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "WAF_v2"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.capacity", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.firewall_mode", "Detection"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.rule_set_type", "OWASP"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.rule_set_version", "3.0"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.request_body_check", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.max_request_body_size_kb", "128"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.file_upload_limit_mb", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.0.match_variable", "RequestArgNames"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.0.selector_match_operator", "Equals"), + resource.TestCheckResourceAttr(data.ResourceName, "waf_configuration.0.exclusion.0.selector", "displayNameHtml"), ), }, }, @@ -895,8 +755,7 @@ func TestAccAzureRMApplicationGateway_webApplicationFirewall_exclusions(t *testi } func TestAccAzureRMApplicationGateway_sslPolicy_policyType_predefined(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -904,11 +763,11 @@ func TestAccAzureRMApplicationGateway_sslPolicy_policyType_predefined(t *testing CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_sslPolicy_policyType_predefined(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_sslPolicy_policyType_predefined(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ssl_policy.0.policy_type", "Predefined"), - resource.TestCheckResourceAttr(resourceName, "ssl_policy.0.policy_name", "AppGwSslPolicy20170401S"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_policy.0.policy_type", "Predefined"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_policy.0.policy_name", "AppGwSslPolicy20170401S"), ), }, }, @@ -916,8 +775,7 @@ func TestAccAzureRMApplicationGateway_sslPolicy_policyType_predefined(t *testing } func TestAccAzureRMApplicationGateway_sslPolicy_policyType_custom(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -925,14 +783,14 @@ func TestAccAzureRMApplicationGateway_sslPolicy_policyType_custom(t *testing.T) CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_sslPolicy_policyType_custom(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_sslPolicy_policyType_custom(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ssl_policy.0.policy_type", "Custom"), - resource.TestCheckResourceAttr(resourceName, "ssl_policy.0.min_protocol_version", "TLSv1_1"), - resource.TestCheckResourceAttr(resourceName, "ssl_policy.0.cipher_suites.0", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"), - resource.TestCheckResourceAttr(resourceName, "ssl_policy.0.cipher_suites.1", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"), - resource.TestCheckResourceAttr(resourceName, "ssl_policy.0.cipher_suites.2", "TLS_RSA_WITH_AES_128_GCM_SHA256"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_policy.0.policy_type", "Custom"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_policy.0.min_protocol_version", "TLSv1_1"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_policy.0.cipher_suites.0", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_policy.0.cipher_suites.1", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_policy.0.cipher_suites.2", "TLS_RSA_WITH_AES_128_GCM_SHA256"), ), }, }, @@ -940,8 +798,7 @@ func TestAccAzureRMApplicationGateway_sslPolicy_policyType_custom(t *testing.T) } func TestAccAzureRMApplicationGateway_sslPolicy_disabledProtocols(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -949,11 +806,11 @@ func TestAccAzureRMApplicationGateway_sslPolicy_disabledProtocols(t *testing.T) CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_sslPolicy_disabledProtocols(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_sslPolicy_disabledProtocols(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ssl_policy.0.disabled_protocols.0", "TLSv1_0"), - resource.TestCheckResourceAttr(resourceName, "ssl_policy.0.disabled_protocols.1", "TLSv1_1"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_policy.0.disabled_protocols.0", "TLSv1_0"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_policy.0.disabled_protocols.1", "TLSv1_1"), ), }, }, @@ -961,8 +818,7 @@ func TestAccAzureRMApplicationGateway_sslPolicy_disabledProtocols(t *testing.T) } func TestAccAzureRMApplicationGateway_disabledSslProtocols(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -970,11 +826,11 @@ func TestAccAzureRMApplicationGateway_disabledSslProtocols(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_disabledSslProtocols(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_disabledSslProtocols(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "disabled_ssl_protocols.0", "TLSv1_0"), - resource.TestCheckResourceAttr(resourceName, "disabled_ssl_protocols.1", "TLSv1_1"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "disabled_ssl_protocols.0", "TLSv1_0"), + resource.TestCheckResourceAttr(data.ResourceName, "disabled_ssl_protocols.1", "TLSv1_1"), ), }, }, @@ -982,8 +838,7 @@ func TestAccAzureRMApplicationGateway_disabledSslProtocols(t *testing.T) { } func TestAccAzureRMApplicationGateway_cookieAffinity(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -991,36 +846,27 @@ func TestAccAzureRMApplicationGateway_cookieAffinity(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_cookieAffinity(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_cookieAffinity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "backend_http_settings.0.affinity_cookie_name", "testCookieName"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backend_http_settings.0.affinity_cookie_name", "testCookieName"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMApplicationGateway_cookieAffinityUpdated(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_cookieAffinityUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "backend_http_settings.0.affinity_cookie_name", ""), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backend_http_settings.0.affinity_cookie_name", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_gatewayIP(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1028,35 +874,25 @@ func TestAccAzureRMApplicationGateway_gatewayIP(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_basic(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMApplicationGateway_gatewayIPUpdated(ri, acceptance.Location()), + Config: testAccAzureRMApplicationGateway_gatewayIPUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMApplicationGateway_UserAssignedIdentity(t *testing.T) { - resourceName := "azurerm_application_gateway.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(14) + data := acceptance.BuildTestData(t, "azurerm_application_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1064,11 +900,11 @@ func TestAccAzureRMApplicationGateway_UserAssignedIdentity(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationGateway_UserDefinedIdentity(ri, acceptance.Location(), rs), + Config: testAccAzureRMApplicationGateway_UserDefinedIdentity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), + testCheckAzureRMApplicationGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), ), }, }, @@ -1132,8 +968,8 @@ func testCheckAzureRMApplicationGatewayDestroy(s *terraform.State) error { return nil } -func testAccAzureRMApplicationGateway_basic(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_basic(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -1200,11 +1036,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_UserDefinedIdentity(rInt int, location string, rString string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_UserDefinedIdentity(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -1290,11 +1126,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rString, rInt, rInt) +`, template, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_zones(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_zones(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -1370,11 +1206,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_autoscaleConfiguration(rInt int, location string, minCapacity int, maxCapacity int) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_autoscaleConfiguration(data acceptance.TestData, minCapacity int, maxCapacity int) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -1453,11 +1289,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt, minCapacity, maxCapacity) +`, template, data.RandomInteger, data.RandomInteger, minCapacity, maxCapacity) } -func testAccAzureRMApplicationGateway_autoscaleConfigurationNoMaxCapacity(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_autoscaleConfigurationNoMaxCapacity(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -1535,11 +1371,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_overridePath(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_overridePath(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -1607,11 +1443,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_http2(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_http2(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -1679,11 +1515,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_requiresImport(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_basic(rInt, location) +func testAccAzureRMApplicationGateway_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_basic(data) return fmt.Sprintf(` %s @@ -1743,8 +1579,8 @@ resource "azurerm_application_gateway" "import" { `, template) } -func testAccAzureRMApplicationGateway_authCertificate(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_authCertificate(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -1821,11 +1657,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_trustedRootCertificate_keyvault(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_trustedRootCertificate_keyvault(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %[1]s @@ -1974,11 +1810,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_trustedRootCertificate(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_trustedRootCertificate(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %[1]s @@ -2062,11 +1898,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_authCertificateUpdated(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_authCertificateUpdated(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %[1]s @@ -2143,11 +1979,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_trustedRootCertificateUpdated(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_trustedRootCertificateUpdated(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %[1]s @@ -2232,11 +2068,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_pathBasedRouting(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_pathBasedRouting(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -2320,11 +2156,11 @@ resource "azurerm_application_gateway" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_routingRedirect_httpListener(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_routingRedirect_httpListener(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -2415,11 +2251,11 @@ resource "azurerm_application_gateway" "test" { include_query_string = false } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_routingRedirect_httpListenerError(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_routingRedirect_httpListenerError(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -2511,11 +2347,11 @@ resource "azurerm_application_gateway" "test" { include_query_string = false } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_routingRedirect_pathBased(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_routingRedirect_pathBased(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -2640,11 +2476,11 @@ resource "azurerm_application_gateway" "test" { include_query_string = false } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_probes(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_probes(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -2743,11 +2579,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_probesEmptyMatch(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_probesEmptyMatch(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -2849,11 +2685,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_probesPickHostNameFromBackendHTTPSettings(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_probesPickHostNameFromBackendHTTPSettings(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -2933,11 +2769,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_backendHttpSettingsHostName(rInt int, location string, hostName string, pick bool) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_backendHttpSettingsHostName(data acceptance.TestData, hostName string, pick bool) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -3006,11 +2842,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, hostName, pick) +`, template, data.RandomInteger, hostName, pick) } -func testAccAzureRMApplicationGateway_settingsPickHostNameFromBackendAddress(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_settingsPickHostNameFromBackendAddress(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -3078,11 +2914,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_sslCertificate(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_sslCertificate(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -3157,11 +2993,11 @@ resource "azurerm_application_gateway" "test" { password = "terraform" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_sslCertificateUpdated(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_sslCertificateUpdated(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -3236,11 +3072,11 @@ resource "azurerm_application_gateway" "test" { password = "hello-world" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_webApplicationFirewall(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_webApplicationFirewall(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -3321,11 +3157,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_connectionDraining(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_connectionDraining(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -3398,10 +3234,10 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -3500,11 +3336,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups_enabled_some_rules(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_webApplicationFirewall_disabledRuleGroups_enabled_some_rules(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -3598,11 +3434,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_webApplicationFirewall_exclusions_many(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_webApplicationFirewall_exclusions_many(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -3715,10 +3551,10 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_webApplicationFirewall_exclusions_one(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_webApplicationFirewall_exclusions_one(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -3809,11 +3645,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_sslPolicy_policyType_predefined(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_sslPolicy_policyType_predefined(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s # since these variables are re-used - a locals block makes this more maintainable @@ -3892,11 +3728,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_sslPolicy_policyType_custom(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_sslPolicy_policyType_custom(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s # since these variables are re-used - a locals block makes this more maintainable @@ -3976,11 +3812,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_sslPolicy_disabledProtocols(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_sslPolicy_disabledProtocols(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s # since these variables are re-used - a locals block makes this more maintainable @@ -4058,11 +3894,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_disabledSslProtocols(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_disabledSslProtocols(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s # since these variables are re-used - a locals block makes this more maintainable @@ -4138,10 +3974,10 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_template(rInt int, location string) string { +func testAccAzureRMApplicationGateway_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -4168,11 +4004,11 @@ resource "azurerm_public_ip" "test" { resource_group_name = "${azurerm_resource_group.test.name}" allocation_method = "Dynamic" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_customErrorConfigurations(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_customErrorConfigurations(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -4261,11 +4097,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_rewriteRuleSets_backend(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_rewriteRuleSets_backend(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -4362,11 +4198,11 @@ resource "azurerm_application_gateway" "test" { } } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_rewriteRuleSets_redirect(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_rewriteRuleSets_redirect(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -4485,11 +4321,11 @@ resource "azurerm_application_gateway" "test" { include_query_string = false } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMApplicationGateway_cookieAffinity(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_cookieAffinity(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -4557,11 +4393,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_cookieAffinityUpdated(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_cookieAffinityUpdated(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -4628,11 +4464,11 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMApplicationGateway_gatewayIPUpdated(rInt int, location string) string { - template := testAccAzureRMApplicationGateway_template(rInt, location) +func testAccAzureRMApplicationGateway_gatewayIPUpdated(data acceptance.TestData) string { + template := testAccAzureRMApplicationGateway_template(data) return fmt.Sprintf(` %s @@ -4706,5 +4542,5 @@ resource "azurerm_application_gateway" "test" { backend_http_settings_name = "${local.http_setting_name}" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_application_security_group_test.go b/azurerm/internal/services/network/tests/resource_arm_application_security_group_test.go similarity index 72% rename from azurerm/internal/services/network/resource_arm_application_security_group_test.go rename to azurerm/internal/services/network/tests/resource_arm_application_security_group_test.go index 82d1854de7ec..a35fe6467d30 100644 --- a/azurerm/internal/services/network/resource_arm_application_security_group_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_application_security_group_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,8 @@ import ( ) func TestAccAzureRMApplicationSecurityGroup_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_application_security_group.test" - config := testAccAzureRMApplicationSecurityGroup_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_application_security_group", "test") + config := testAccAzureRMApplicationSecurityGroup_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,8 +24,8 @@ func TestAccAzureRMApplicationSecurityGroup_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationSecurityGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMApplicationSecurityGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -40,9 +38,7 @@ func TestAccAzureRMApplicationSecurityGroup_requiresImport(t *testing.T) { return } - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resourceName := "azurerm_application_security_group.test" + data := acceptance.BuildTestData(t, "azurerm_application_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,13 +46,13 @@ func TestAccAzureRMApplicationSecurityGroup_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationSecurityGroup_basic(ri, location), + Config: testAccAzureRMApplicationSecurityGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationSecurityGroupExists(resourceName), + testCheckAzureRMApplicationSecurityGroupExists(data.ResourceName), ), }, { - Config: testAccAzureRMApplicationSecurityGroup_requiresImport(ri, location), + Config: testAccAzureRMApplicationSecurityGroup_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_app_service_custom_hostname_binding"), }, }, @@ -64,9 +60,8 @@ func TestAccAzureRMApplicationSecurityGroup_requiresImport(t *testing.T) { } func TestAccAzureRMApplicationSecurityGroup_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_application_security_group.test" - config := testAccAzureRMApplicationSecurityGroup_complete(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_application_security_group", "test") + config := testAccAzureRMApplicationSecurityGroup_complete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -76,9 +71,9 @@ func TestAccAzureRMApplicationSecurityGroup_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationSecurityGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), + testCheckAzureRMApplicationSecurityGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), ), }, }, @@ -86,9 +81,7 @@ func TestAccAzureRMApplicationSecurityGroup_complete(t *testing.T) { } func TestAccAzureRMApplicationSecurityGroup_update(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resourceName := "azurerm_application_security_group.test" + data := acceptance.BuildTestData(t, "azurerm_application_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -96,18 +89,18 @@ func TestAccAzureRMApplicationSecurityGroup_update(t *testing.T) { CheckDestroy: testCheckAzureRMApplicationSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMApplicationSecurityGroup_basic(ri, location), + Config: testAccAzureRMApplicationSecurityGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationSecurityGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMApplicationSecurityGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, { - Config: testAccAzureRMApplicationSecurityGroup_complete(ri, location), + Config: testAccAzureRMApplicationSecurityGroup_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMApplicationSecurityGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), + testCheckAzureRMApplicationSecurityGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), ), }, }, @@ -172,7 +165,7 @@ func testCheckAzureRMApplicationSecurityGroupExists(resourceName string) resourc } } -func testAccAzureRMApplicationSecurityGroup_basic(rInt int, location string) string { +func testAccAzureRMApplicationSecurityGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -184,11 +177,11 @@ resource "azurerm_application_security_group" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMApplicationSecurityGroup_requiresImport(rInt int, location string) string { - template := testAccAzureRMApplicationSecurityGroup_basic(rInt, location) +func testAccAzureRMApplicationSecurityGroup_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApplicationSecurityGroup_basic(data) return fmt.Sprintf(` %s @@ -200,7 +193,7 @@ resource "azurerm_application_security_group" "import" { `, template) } -func testAccAzureRMApplicationSecurityGroup_complete(rInt int, location string) string { +func testAccAzureRMApplicationSecurityGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -216,5 +209,5 @@ resource "azurerm_application_security_group" "test" { Hello = "World" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_bastion_host_test.go b/azurerm/internal/services/network/tests/resource_arm_bastion_host_test.go similarity index 79% rename from azurerm/internal/services/network/resource_arm_bastion_host_test.go rename to azurerm/internal/services/network/tests/resource_arm_bastion_host_test.go index 8485d6e70f9e..c1b85022a51a 100644 --- a/azurerm/internal/services/network/resource_arm_bastion_host_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_bastion_host_test.go @@ -1,13 +1,11 @@ -package network +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,11 +13,9 @@ import ( ) func TestAccAzureRMBastionHost_basic(t *testing.T) { - resourceName := "azurerm_bastion_host.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_bastion_host", "test") - config := testAccAzureRMBastionHost_basic(ri, rs, acceptance.Location()) + config := testAccAzureRMBastionHost_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,7 +25,7 @@ func TestAccAzureRMBastionHost_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBastionHostExists(resourceName), + testCheckAzureRMBastionHostExists(data.ResourceName), ), }, }, @@ -37,11 +33,9 @@ func TestAccAzureRMBastionHost_basic(t *testing.T) { } func TestAccAzureRMBastionHost_complete(t *testing.T) { - resourceName := "azurerm_bastion_host.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_bastion_host", "test") - config := testAccAzureRMBastionHost_complete(ri, rs, acceptance.Location()) + config := testAccAzureRMBastionHost_complete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -51,16 +45,12 @@ func TestAccAzureRMBastionHost_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBastionHostExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), + testCheckAzureRMBastionHostExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -71,9 +61,7 @@ func TestAccAzureRMBastionHost_requiresImport(t *testing.T) { return } - resourceName := "azurerm_bastion_host.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_bastion_host", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,20 +69,20 @@ func TestAccAzureRMBastionHost_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMBastionHostDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMBastionHost_basic(ri, rs, acceptance.Location()), + Config: testAccAzureRMBastionHost_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBastionHostExists(resourceName), + testCheckAzureRMBastionHostExists(data.ResourceName), ), }, { - Config: testAccAzureRMBastionHost_requiresImport(ri, rs, acceptance.Location()), + Config: testAccAzureRMBastionHost_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_bastion_host"), }, }, }) } -func testAccAzureRMBastionHost_basic(rInt int, rString string, location string) string { +func testAccAzureRMBastionHost_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-bastion-%d" @@ -134,10 +122,10 @@ resource "azurerm_bastion_host" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rString, rInt, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomString) } -func testAccAzureRMBastionHost_complete(rInt int, rString string, location string) string { +func testAccAzureRMBastionHost_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-bastion-%d" @@ -181,11 +169,11 @@ resource "azurerm_bastion_host" "test" { environment = "production" } } -`, rInt, location, rString, rInt, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomString) } -func testAccAzureRMBastionHost_requiresImport(rInt int, rString string, location string) string { - template := testAccAzureRMBastionHost_basic(rInt, rString, location) +func testAccAzureRMBastionHost_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMBastionHost_basic(data) return fmt.Sprintf(` %s resource "azurerm_bastion_host" "import" { diff --git a/azurerm/internal/services/network/resource_arm_connection_monitor_test.go b/azurerm/internal/services/network/tests/resource_arm_connection_monitor_test.go similarity index 66% rename from azurerm/internal/services/network/resource_arm_connection_monitor_test.go rename to azurerm/internal/services/network/tests/resource_arm_connection_monitor_test.go index 1b19af1fcdf3..920946361a78 100644 --- a/azurerm/internal/services/network/resource_arm_connection_monitor_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_connection_monitor_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -9,17 +9,13 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func testAccAzureRMConnectionMonitor_addressBasic(t *testing.T) { - resourceName := "azurerm_connection_monitor.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,20 +23,16 @@ func testAccAzureRMConnectionMonitor_addressBasic(t *testing.T) { CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMConnectionMonitor_basicAddressConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_basicAddressConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttr(resourceName, "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr(resourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "60"), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "60"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -51,10 +43,7 @@ func testAccAzureRMConnectionMonitor_requiresImport(t *testing.T) { return } - resourceName := "azurerm_connection_monitor.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -62,13 +51,13 @@ func testAccAzureRMConnectionMonitor_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMConnectionMonitor_basicAddressConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_basicAddressConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), ), }, { - Config: testAccAzureRMConnectionMonitor_requiresImportConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_requiresImportConfig(data), ExpectError: acceptance.RequiresImportError("azurerm_connection_monitor"), }, }, @@ -76,10 +65,8 @@ func testAccAzureRMConnectionMonitor_requiresImport(t *testing.T) { } func testAccAzureRMConnectionMonitor_addressComplete(t *testing.T) { - resourceName := "azurerm_connection_monitor.test" + data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - ri := tf.AccRandTimeInt() - location := acceptance.Location() autoStart := "false" resource.Test(t, resource.TestCase{ @@ -88,30 +75,24 @@ func testAccAzureRMConnectionMonitor_addressComplete(t *testing.T) { CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMConnectionMonitor_completeAddressConfig(ri, location, autoStart), + Config: testAccAzureRMConnectionMonitor_completeAddressConfig(data, autoStart), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_start", "false"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(resourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMConnectionMonitor_addressUpdate(t *testing.T) { - resourceName := "azurerm_connection_monitor.test" + data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - ri := tf.AccRandTimeInt() - location := acceptance.Location() autoStart := "true" resource.Test(t, resource.TestCase{ @@ -120,36 +101,29 @@ func testAccAzureRMConnectionMonitor_addressUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMConnectionMonitor_basicAddressConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_basicAddressConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), ), }, { - Config: testAccAzureRMConnectionMonitor_completeAddressConfig(ri, location, autoStart), + Config: testAccAzureRMConnectionMonitor_completeAddressConfig(data, autoStart), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(resourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMConnectionMonitor_vmBasic(t *testing.T) { - resourceName := "azurerm_connection_monitor.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -157,29 +131,23 @@ func testAccAzureRMConnectionMonitor_vmBasic(t *testing.T) { CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMConnectionMonitor_basicVmConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_basicVmConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttr(resourceName, "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr(resourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "60"), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "60"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMConnectionMonitor_vmComplete(t *testing.T) { - resourceName := "azurerm_connection_monitor.test" + data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") - ri := tf.AccRandTimeInt() - location := acceptance.Location() autoStart := "false" resource.Test(t, resource.TestCase{ @@ -188,30 +156,23 @@ func testAccAzureRMConnectionMonitor_vmComplete(t *testing.T) { CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMConnectionMonitor_completeVmConfig(ri, location, autoStart), + Config: testAccAzureRMConnectionMonitor_completeVmConfig(data, autoStart), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_start", "false"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(resourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMConnectionMonitor_vmUpdate(t *testing.T) { - resourceName := "azurerm_connection_monitor.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -219,36 +180,29 @@ func testAccAzureRMConnectionMonitor_vmUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMConnectionMonitor_basicVmConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_basicVmConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), ), }, { - Config: testAccAzureRMConnectionMonitor_completeVmConfig(ri, location, "true"), + Config: testAccAzureRMConnectionMonitor_completeVmConfig(data, "true"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(resourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMConnectionMonitor_destinationUpdate(t *testing.T) { - resourceName := "azurerm_connection_monitor.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -256,38 +210,33 @@ func testAccAzureRMConnectionMonitor_destinationUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMConnectionMonitor_basicAddressConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_basicAddressConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "destination.0.address"), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "destination.0.address"), ), }, { - Config: testAccAzureRMConnectionMonitor_basicVmConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_basicVmConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "destination.0.virtual_machine_id"), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "destination.0.virtual_machine_id"), ), }, { - Config: testAccAzureRMConnectionMonitor_basicAddressConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_basicAddressConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "destination.0.address"), + testCheckAzureRMConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "destination.0.address"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMConnectionMonitor_missingDestination(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -295,7 +244,7 @@ func testAccAzureRMConnectionMonitor_missingDestination(t *testing.T) { CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMConnectionMonitor_missingDestinationConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_missingDestinationConfig(data), ExpectError: regexp.MustCompile("Error: either `destination.virtual_machine_id` or `destination.address` must be specified"), }, }, @@ -303,8 +252,7 @@ func testAccAzureRMConnectionMonitor_missingDestination(t *testing.T) { } func testAccAzureRMConnectionMonitor_conflictingDestinations(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -312,7 +260,7 @@ func testAccAzureRMConnectionMonitor_conflictingDestinations(t *testing.T) { CheckDestroy: testCheckAzureRMConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMConnectionMonitor_conflictingDestinationsConfig(ri, location), + Config: testAccAzureRMConnectionMonitor_conflictingDestinationsConfig(data), ExpectError: regexp.MustCompile("conflicts with destination.0.address"), }, }, @@ -373,7 +321,7 @@ func testCheckAzureRMConnectionMonitorDestroy(s *terraform.State) error { return nil } -func testAccAzureRMConnectionMonitor_baseConfig(rInt int, location string) string { +func testAccAzureRMConnectionMonitor_baseConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -454,11 +402,11 @@ resource "azurerm_virtual_machine_extension" "src" { type_handler_version = "1.4" auto_upgrade_minor_version = true } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMConnectionMonitor_baseWithDestConfig(rInt int, location string) string { - config := testAccAzureRMConnectionMonitor_baseConfig(rInt, location) +func testAccAzureRMConnectionMonitor_baseWithDestConfig(data acceptance.TestData) string { + config := testAccAzureRMConnectionMonitor_baseConfig(data) return fmt.Sprintf(` %s @@ -505,11 +453,11 @@ resource "azurerm_virtual_machine" "dest" { disable_password_authentication = false } } -`, config, rInt, rInt, rInt, rInt) +`, config, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMConnectionMonitor_basicAddressConfig(rInt int, location string) string { - config := testAccAzureRMConnectionMonitor_baseConfig(rInt, location) +func testAccAzureRMConnectionMonitor_basicAddressConfig(data acceptance.TestData) string { + config := testAccAzureRMConnectionMonitor_baseConfig(data) return fmt.Sprintf(` %s @@ -530,11 +478,11 @@ resource "azurerm_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAccAzureRMConnectionMonitor_completeAddressConfig(rInt int, location, autoStart string) string { - config := testAccAzureRMConnectionMonitor_baseConfig(rInt, location) +func testAccAzureRMConnectionMonitor_completeAddressConfig(data acceptance.TestData, autoStart string) string { + config := testAccAzureRMConnectionMonitor_baseConfig(data) return fmt.Sprintf(` %s @@ -563,11 +511,11 @@ resource "azurerm_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt, autoStart) +`, config, data.RandomInteger, autoStart) } -func testAccAzureRMConnectionMonitor_basicVmConfig(rInt int, location string) string { - config := testAccAzureRMConnectionMonitor_baseWithDestConfig(rInt, location) +func testAccAzureRMConnectionMonitor_basicVmConfig(data acceptance.TestData) string { + config := testAccAzureRMConnectionMonitor_baseWithDestConfig(data) return fmt.Sprintf(` %s @@ -588,11 +536,11 @@ resource "azurerm_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAccAzureRMConnectionMonitor_completeVmConfig(rInt int, location, autoStart string) string { - config := testAccAzureRMConnectionMonitor_baseWithDestConfig(rInt, location) +func testAccAzureRMConnectionMonitor_completeVmConfig(data acceptance.TestData, autoStart string) string { + config := testAccAzureRMConnectionMonitor_baseWithDestConfig(data) return fmt.Sprintf(` %s @@ -621,11 +569,11 @@ resource "azurerm_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt, autoStart) +`, config, data.RandomInteger, autoStart) } -func testAccAzureRMConnectionMonitor_missingDestinationConfig(rInt int, location string) string { - config := testAccAzureRMConnectionMonitor_baseConfig(rInt, location) +func testAccAzureRMConnectionMonitor_missingDestinationConfig(data acceptance.TestData) string { + config := testAccAzureRMConnectionMonitor_baseConfig(data) return fmt.Sprintf(` %s @@ -645,11 +593,11 @@ resource "azurerm_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAccAzureRMConnectionMonitor_conflictingDestinationsConfig(rInt int, location string) string { - config := testAccAzureRMConnectionMonitor_baseConfig(rInt, location) +func testAccAzureRMConnectionMonitor_conflictingDestinationsConfig(data acceptance.TestData) string { + config := testAccAzureRMConnectionMonitor_baseConfig(data) return fmt.Sprintf(` %s @@ -671,11 +619,11 @@ resource "azurerm_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAccAzureRMConnectionMonitor_requiresImportConfig(rInt int, location string) string { - config := testAccAzureRMConnectionMonitor_basicAddressConfig(rInt, location) +func testAccAzureRMConnectionMonitor_requiresImportConfig(data acceptance.TestData) string { + config := testAccAzureRMConnectionMonitor_basicAddressConfig(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_ddos_protection_plan_test.go b/azurerm/internal/services/network/tests/resource_arm_ddos_protection_plan_test.go similarity index 73% rename from azurerm/internal/services/network/resource_arm_ddos_protection_plan_test.go rename to azurerm/internal/services/network/tests/resource_arm_ddos_protection_plan_test.go index dbc8fd26ffa8..5d6c03d2deb6 100644 --- a/azurerm/internal/services/network/resource_arm_ddos_protection_plan_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_ddos_protection_plan_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func testAccAzureRMDDoSProtectionPlan_basic(t *testing.T) { - resourceName := "azurerm_ddos_protection_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_ddos_protection_plan", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,17 +21,13 @@ func testAccAzureRMDDoSProtectionPlan_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDDoSProtectionPlan_basicConfig(ri, location), + Config: testAccAzureRMDDoSProtectionPlan_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDDoSProtectionPlanExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "virtual_network_ids.#"), + testCheckAzureRMDDoSProtectionPlanExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_ids.#"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,9 +38,7 @@ func testAccAzureRMDDoSProtectionPlan_requiresImport(t *testing.T) { return } - resourceName := "azurerm_ddos_protection_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_ddos_protection_plan", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,13 +46,13 @@ func testAccAzureRMDDoSProtectionPlan_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDDoSProtectionPlan_basicConfig(ri, location), + Config: testAccAzureRMDDoSProtectionPlan_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDDoSProtectionPlanExists(resourceName), + testCheckAzureRMDDoSProtectionPlanExists(data.ResourceName), ), }, { - Config: testAccAzureRMDDoSProtectionPlan_requiresImportConfig(ri, location), + Config: testAccAzureRMDDoSProtectionPlan_requiresImportConfig(data), ExpectError: acceptance.RequiresImportError("azurerm_ddos_protection_plan"), }, }, @@ -69,9 +60,7 @@ func testAccAzureRMDDoSProtectionPlan_requiresImport(t *testing.T) { } func testAccAzureRMDDoSProtectionPlan_withTags(t *testing.T) { - resourceName := "azurerm_ddos_protection_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_ddos_protection_plan", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,35 +68,29 @@ func testAccAzureRMDDoSProtectionPlan_withTags(t *testing.T) { CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDDoSProtectionPlan_withTagsConfig(ri, location), + Config: testAccAzureRMDDoSProtectionPlan_withTagsConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDDoSProtectionPlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMDDoSProtectionPlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { - Config: testAccAzureRMDDoSProtectionPlan_withUpdatedTagsConfig(ri, location), + Config: testAccAzureRMDDoSProtectionPlan_withUpdatedTagsConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDDoSProtectionPlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Staging"), + testCheckAzureRMDDoSProtectionPlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Staging"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMDDoSProtectionPlan_disappears(t *testing.T) { - resourceName := "azurerm_ddos_protection_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_ddos_protection_plan", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -115,10 +98,10 @@ func testAccAzureRMDDoSProtectionPlan_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMDDoSProtectionPlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDDoSProtectionPlan_basicConfig(ri, location), + Config: testAccAzureRMDDoSProtectionPlan_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDDoSProtectionPlanExists(resourceName), - testCheckAzureRMDDoSProtectionPlanDisappears(resourceName), + testCheckAzureRMDDoSProtectionPlanExists(data.ResourceName), + testCheckAzureRMDDoSProtectionPlanDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -211,7 +194,7 @@ func testCheckAzureRMDDoSProtectionPlanDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDDoSProtectionPlan_basicConfig(rInt int, location string) string { +func testAccAzureRMDDoSProtectionPlan_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -223,11 +206,11 @@ resource "azurerm_ddos_protection_plan" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDDoSProtectionPlan_requiresImportConfig(rInt int, location string) string { - basicConfig := testAccAzureRMDDoSProtectionPlan_basicConfig(rInt, location) +func testAccAzureRMDDoSProtectionPlan_requiresImportConfig(data acceptance.TestData) string { + basicConfig := testAccAzureRMDDoSProtectionPlan_basicConfig(data) return fmt.Sprintf(` %s @@ -239,7 +222,7 @@ resource "azurerm_ddos_protection_plan" "import" { `, basicConfig) } -func testAccAzureRMDDoSProtectionPlan_withTagsConfig(rInt int, location string) string { +func testAccAzureRMDDoSProtectionPlan_withTagsConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -256,10 +239,10 @@ resource "azurerm_ddos_protection_plan" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDDoSProtectionPlan_withUpdatedTagsConfig(rInt int, location string) string { +func testAccAzureRMDDoSProtectionPlan_withUpdatedTagsConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -275,5 +258,5 @@ resource "azurerm_ddos_protection_plan" "test" { environment = "Staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_express_route_circuit_authorization_test.go b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_authorization_test.go similarity index 84% rename from azurerm/internal/services/network/resource_arm_express_route_circuit_authorization_test.go rename to azurerm/internal/services/network/tests/resource_arm_express_route_circuit_authorization_test.go index 0d9842265d56..4e6a6e23326b 100644 --- a/azurerm/internal/services/network/resource_arm_express_route_circuit_authorization_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_authorization_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +14,7 @@ import ( ) func testAccAzureRMExpressRouteCircuitAuthorization_basic(t *testing.T) { - resourceName := "azurerm_express_route_circuit_authorization.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_authorization", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,17 +22,13 @@ func testAccAzureRMExpressRouteCircuitAuthorization_basic(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitAuthorizationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuitAuthorization_basicConfig(ri, acceptance.Location()), + Config: testAccAzureRMExpressRouteCircuitAuthorization_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitAuthorizationExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "authorization_key"), + testCheckAzureRMExpressRouteCircuitAuthorizationExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "authorization_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,10 +39,7 @@ func testAccAzureRMExpressRouteCircuitAuthorization_requiresImport(t *testing.T) return } - resourceName := "azurerm_express_route_circuit_authorization.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_authorization", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,14 +47,14 @@ func testAccAzureRMExpressRouteCircuitAuthorization_requiresImport(t *testing.T) CheckDestroy: testCheckAzureRMExpressRouteCircuitAuthorizationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuitAuthorization_basicConfig(ri, location), + Config: testAccAzureRMExpressRouteCircuitAuthorization_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitAuthorizationExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "authorization_key"), + testCheckAzureRMExpressRouteCircuitAuthorizationExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "authorization_key"), ), }, { - Config: testAccAzureRMExpressRouteCircuitAuthorization_requiresImportConfig(ri, location), + Config: testAccAzureRMExpressRouteCircuitAuthorization_requiresImportConfig(data), ExpectError: acceptance.RequiresImportError("azurerm_express_route_circuit_authorization"), }, }, @@ -71,9 +62,8 @@ func testAccAzureRMExpressRouteCircuitAuthorization_requiresImport(t *testing.T) } func testAccAzureRMExpressRouteCircuitAuthorization_multiple(t *testing.T) { - firstResourceName := "azurerm_express_route_circuit_authorization.test1" + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_authorization", "test1") secondResourceName := "azurerm_express_route_circuit_authorization.test2" - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,10 +71,10 @@ func testAccAzureRMExpressRouteCircuitAuthorization_multiple(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitAuthorizationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuitAuthorization_multipleConfig(ri, acceptance.Location()), + Config: testAccAzureRMExpressRouteCircuitAuthorization_multipleConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitAuthorizationExists(firstResourceName), - resource.TestCheckResourceAttrSet(firstResourceName, "authorization_key"), + testCheckAzureRMExpressRouteCircuitAuthorizationExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "authorization_key"), testCheckAzureRMExpressRouteCircuitAuthorizationExists(secondResourceName), resource.TestCheckResourceAttrSet(secondResourceName, "authorization_key"), ), @@ -150,7 +140,7 @@ func testCheckAzureRMExpressRouteCircuitAuthorizationDestroy(s *terraform.State) return nil } -func testAccAzureRMExpressRouteCircuitAuthorization_basicConfig(rInt int, location string) string { +func testAccAzureRMExpressRouteCircuitAuthorization_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -183,11 +173,11 @@ resource "azurerm_express_route_circuit_authorization" "test" { express_route_circuit_name = "${azurerm_express_route_circuit.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMExpressRouteCircuitAuthorization_requiresImportConfig(rInt int, location string) string { - template := testAccAzureRMExpressRouteCircuitAuthorization_basicConfig(rInt, location) +func testAccAzureRMExpressRouteCircuitAuthorization_requiresImportConfig(data acceptance.TestData) string { + template := testAccAzureRMExpressRouteCircuitAuthorization_basicConfig(data) return fmt.Sprintf(` %s @@ -199,7 +189,7 @@ resource "azurerm_express_route_circuit_authorization" "import" { `, template) } -func testAccAzureRMExpressRouteCircuitAuthorization_multipleConfig(rInt int, location string) string { +func testAccAzureRMExpressRouteCircuitAuthorization_multipleConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -238,5 +228,5 @@ resource "azurerm_express_route_circuit_authorization" "test2" { express_route_circuit_name = "${azurerm_express_route_circuit.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_express_route_circuit_peering_test.go b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go similarity index 76% rename from azurerm/internal/services/network/resource_arm_express_route_circuit_peering_test.go rename to azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go index e3ab9663f3c2..c09255fafbdd 100644 --- a/azurerm/internal/services/network/resource_arm_express_route_circuit_peering_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,7 @@ import ( ) func testAccAzureRMExpressRouteCircuitPeering_azurePrivatePeering(t *testing.T) { - resourceName := "azurerm_express_route_circuit_peering.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,19 +22,14 @@ func testAccAzureRMExpressRouteCircuitPeering_azurePrivatePeering(t *testing.T) CheckDestroy: testCheckAzureRMExpressRouteCircuitPeeringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuitPeering_privatePeering(ri, location), + Config: testAccAzureRMExpressRouteCircuitPeering_privatePeering(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitPeeringExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "peering_type", "AzurePrivatePeering"), - resource.TestCheckResourceAttr(resourceName, "microsoft_peering_config.#", "0"), + testCheckAzureRMExpressRouteCircuitPeeringExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "peering_type", "AzurePrivatePeering"), + resource.TestCheckResourceAttr(data.ResourceName, "microsoft_peering_config.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"shared_key"}, //is not returned by the API - }, + data.ImportStep("shared_key"), //is not returned by the API }, }) } @@ -48,10 +40,7 @@ func testAccAzureRMExpressRouteCircuitPeering_requiresImport(t *testing.T) { return } - resourceName := "azurerm_express_route_circuit_peering.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -59,13 +48,13 @@ func testAccAzureRMExpressRouteCircuitPeering_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitPeeringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuitPeering_privatePeering(ri, location), + Config: testAccAzureRMExpressRouteCircuitPeering_privatePeering(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitPeeringExists(resourceName), + testCheckAzureRMExpressRouteCircuitPeeringExists(data.ResourceName), ), }, { - Config: testAccAzureRMExpressRouteCircuitPeering_requiresImportConfig(ri, location), + Config: testAccAzureRMExpressRouteCircuitPeering_requiresImportConfig(data), ExpectError: acceptance.RequiresImportError("azurerm_express_route_circuit_peering"), }, }, @@ -73,9 +62,7 @@ func testAccAzureRMExpressRouteCircuitPeering_requiresImport(t *testing.T) { } func testAccAzureRMExpressRouteCircuitPeering_microsoftPeering(t *testing.T) { - resourceName := "azurerm_express_route_circuit_peering.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -83,26 +70,20 @@ func testAccAzureRMExpressRouteCircuitPeering_microsoftPeering(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitPeeringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuitPeering_msPeering(ri, location), + Config: testAccAzureRMExpressRouteCircuitPeering_msPeering(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitPeeringExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "peering_type", "MicrosoftPeering"), - resource.TestCheckResourceAttr(resourceName, "microsoft_peering_config.#", "1"), + testCheckAzureRMExpressRouteCircuitPeeringExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "peering_type", "MicrosoftPeering"), + resource.TestCheckResourceAttr(data.ResourceName, "microsoft_peering_config.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMExpressRouteCircuitPeering_azurePrivatePeeringWithCircuitUpdate(t *testing.T) { - resourceName := "azurerm_express_route_circuit_peering.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -110,27 +91,22 @@ func testAccAzureRMExpressRouteCircuitPeering_azurePrivatePeeringWithCircuitUpda CheckDestroy: testCheckAzureRMExpressRouteCircuitPeeringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuitPeering_privatePeering(ri, location), + Config: testAccAzureRMExpressRouteCircuitPeering_privatePeering(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitPeeringExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "peering_type", "AzurePrivatePeering"), - resource.TestCheckResourceAttr(resourceName, "microsoft_peering_config.#", "0"), + testCheckAzureRMExpressRouteCircuitPeeringExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "peering_type", "AzurePrivatePeering"), + resource.TestCheckResourceAttr(data.ResourceName, "microsoft_peering_config.#", "0"), ), }, { - Config: testAccAzureRMExpressRouteCircuitPeering_privatePeeringWithCircuitUpdate(ri, location), + Config: testAccAzureRMExpressRouteCircuitPeering_privatePeeringWithCircuitUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitPeeringExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "peering_type", "AzurePrivatePeering"), - resource.TestCheckResourceAttr(resourceName, "microsoft_peering_config.#", "0"), + testCheckAzureRMExpressRouteCircuitPeeringExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "peering_type", "AzurePrivatePeering"), + resource.TestCheckResourceAttr(data.ResourceName, "microsoft_peering_config.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"shared_key"}, //is not returned by the API - }, + data.ImportStep("shared_key"), //is not returned by the API }, }) } @@ -192,7 +168,7 @@ func testCheckAzureRMExpressRouteCircuitPeeringDestroy(s *terraform.State) error return nil } -func testAccAzureRMExpressRouteCircuitPeering_privatePeering(rInt int, location string) string { +func testAccAzureRMExpressRouteCircuitPeering_privatePeering(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -228,11 +204,11 @@ resource "azurerm_express_route_circuit_peering" "test" { secondary_peer_address_prefix = "192.168.2.0/30" vlan_id = 100 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMExpressRouteCircuitPeering_requiresImportConfig(rInt int, location string) string { - template := testAccAzureRMExpressRouteCircuitPeering_privatePeering(rInt, location) +func testAccAzureRMExpressRouteCircuitPeering_requiresImportConfig(data acceptance.TestData) string { + template := testAccAzureRMExpressRouteCircuitPeering_privatePeering(data) return fmt.Sprintf(` %s @@ -249,7 +225,7 @@ resource "azurerm_express_route_circuit_peering" "import" { `, template) } -func testAccAzureRMExpressRouteCircuitPeering_msPeering(rInt int, location string) string { +func testAccAzureRMExpressRouteCircuitPeering_msPeering(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -288,10 +264,10 @@ resource "azurerm_express_route_circuit_peering" "test" { advertised_public_prefixes = ["123.1.0.0/24"] } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMExpressRouteCircuitPeering_privatePeeringWithCircuitUpdate(rInt int, location string) string { +func testAccAzureRMExpressRouteCircuitPeering_privatePeeringWithCircuitUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -327,5 +303,5 @@ resource "azurerm_express_route_circuit_peering" "test" { secondary_peer_address_prefix = "192.168.2.0/30" vlan_id = 100 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_express_route_circuit_test.go b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_test.go similarity index 76% rename from azurerm/internal/services/network/resource_arm_express_route_circuit_test.go rename to azurerm/internal/services/network/tests/resource_arm_express_route_circuit_test.go index 5f9f2ac43dbd..82f6bab218bd 100644 --- a/azurerm/internal/services/network/resource_arm_express_route_circuit_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -59,9 +58,8 @@ func TestAccAzureRMExpressRouteCircuit(t *testing.T) { } func testAccAzureRMExpressRouteCircuit_basicMetered(t *testing.T) { - resourceName := "azurerm_express_route_circuit.test" + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit", "test") var erc network.ExpressRouteCircuit - ri := tf.AccRandTimeInt() resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -69,16 +67,12 @@ func testAccAzureRMExpressRouteCircuit_basicMetered(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuit_basicMeteredConfig(ri, acceptance.Location()), + Config: testAccAzureRMExpressRouteCircuit_basicMeteredConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitExists(resourceName, &erc), + testCheckAzureRMExpressRouteCircuitExists(data.ResourceName, &erc), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -89,11 +83,8 @@ func testAccAzureRMExpressRouteCircuit_requiresImport(t *testing.T) { return } - resourceName := "azurerm_express_route_circuit.test" + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit", "test") var erc network.ExpressRouteCircuit - ri := tf.AccRandTimeInt() - - location := acceptance.Location() resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -101,13 +92,13 @@ func testAccAzureRMExpressRouteCircuit_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuit_basicMeteredConfig(ri, location), + Config: testAccAzureRMExpressRouteCircuit_basicMeteredConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitExists(resourceName, &erc), + testCheckAzureRMExpressRouteCircuitExists(data.ResourceName, &erc), ), }, { - Config: testAccAzureRMExpressRouteCircuit_requiresImportConfig(ri, location), + Config: testAccAzureRMExpressRouteCircuit_requiresImportConfig(data), ExpectError: acceptance.RequiresImportError("azurerm_express_route_circuit"), }, }, @@ -115,9 +106,8 @@ func testAccAzureRMExpressRouteCircuit_requiresImport(t *testing.T) { } func testAccAzureRMExpressRouteCircuit_basicUnlimited(t *testing.T) { - resourceName := "azurerm_express_route_circuit.test" + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit", "test") var erc network.ExpressRouteCircuit - ri := tf.AccRandTimeInt() resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -125,24 +115,19 @@ func testAccAzureRMExpressRouteCircuit_basicUnlimited(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuit_basicUnlimitedConfig(ri, acceptance.Location()), + Config: testAccAzureRMExpressRouteCircuit_basicUnlimitedConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitExists(resourceName, &erc), + testCheckAzureRMExpressRouteCircuitExists(data.ResourceName, &erc), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMExpressRouteCircuit_update(t *testing.T) { - resourceName := "azurerm_express_route_circuit.test" + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit", "test") var erc network.ExpressRouteCircuit - ri := tf.AccRandTimeInt() resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -150,17 +135,17 @@ func testAccAzureRMExpressRouteCircuit_update(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuit_basicMeteredConfig(ri, acceptance.Location()), + Config: testAccAzureRMExpressRouteCircuit_basicMeteredConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitExists(resourceName, &erc), - resource.TestCheckResourceAttr(resourceName, "sku.0.family", "MeteredData"), + testCheckAzureRMExpressRouteCircuitExists(data.ResourceName, &erc), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "MeteredData"), ), }, { - Config: testAccAzureRMExpressRouteCircuit_basicUnlimitedConfig(ri, acceptance.Location()), + Config: testAccAzureRMExpressRouteCircuit_basicUnlimitedConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMExpressRouteCircuitExists(resourceName, &erc), - resource.TestCheckResourceAttr(resourceName, "sku.0.family", "UnlimitedData"), + testCheckAzureRMExpressRouteCircuitExists(data.ResourceName, &erc), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "UnlimitedData"), ), }, }, @@ -168,9 +153,8 @@ func testAccAzureRMExpressRouteCircuit_update(t *testing.T) { } func testAccAzureRMExpressRouteCircuit_tierUpdate(t *testing.T) { - resourceName := "azurerm_express_route_circuit.test" + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit", "test") var erc network.ExpressRouteCircuit - ri := tf.AccRandTimeInt() resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -178,17 +162,17 @@ func testAccAzureRMExpressRouteCircuit_tierUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuit_sku(ri, acceptance.Location(), "Standard", "MeteredData"), + Config: testAccAzureRMExpressRouteCircuit_sku(data, "Standard", "MeteredData"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMExpressRouteCircuitExists("azurerm_express_route_circuit.test", &erc), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Standard"), ), }, { - Config: testAccAzureRMExpressRouteCircuit_sku(ri, acceptance.Location(), "Premium", "MeteredData"), + Config: testAccAzureRMExpressRouteCircuit_sku(data, "Premium", "MeteredData"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMExpressRouteCircuitExists("azurerm_express_route_circuit.test", &erc), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Premium"), ), }, }, @@ -196,9 +180,8 @@ func testAccAzureRMExpressRouteCircuit_tierUpdate(t *testing.T) { } func testAccAzureRMExpressRouteCircuit_premiumMetered(t *testing.T) { - resourceName := "azurerm_express_route_circuit.test" + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit", "test") var erc network.ExpressRouteCircuit - ri := tf.AccRandTimeInt() resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -206,26 +189,21 @@ func testAccAzureRMExpressRouteCircuit_premiumMetered(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuit_sku(ri, acceptance.Location(), "Premium", "MeteredData"), + Config: testAccAzureRMExpressRouteCircuit_sku(data, "Premium", "MeteredData"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMExpressRouteCircuitExists("azurerm_express_route_circuit.test", &erc), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Premium"), - resource.TestCheckResourceAttr(resourceName, "sku.0.family", "MeteredData"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "MeteredData"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMExpressRouteCircuit_premiumUnlimited(t *testing.T) { - resourceName := "azurerm_express_route_circuit.test" + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit", "test") var erc network.ExpressRouteCircuit - ri := tf.AccRandTimeInt() resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -233,26 +211,21 @@ func testAccAzureRMExpressRouteCircuit_premiumUnlimited(t *testing.T) { CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuit_sku(ri, acceptance.Location(), "Premium", "UnlimitedData"), + Config: testAccAzureRMExpressRouteCircuit_sku(data, "Premium", "UnlimitedData"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMExpressRouteCircuitExists("azurerm_express_route_circuit.test", &erc), - resource.TestCheckResourceAttr(resourceName, "sku.0.tier", "Premium"), - resource.TestCheckResourceAttr(resourceName, "sku.0.family", "UnlimitedData"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.tier", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "sku.0.family", "UnlimitedData"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMExpressRouteCircuit_allowClassicOperationsUpdate(t *testing.T) { - resourceName := "azurerm_express_route_circuit.test" + data := acceptance.BuildTestData(t, "azurerm_express_route_circuit", "test") var erc network.ExpressRouteCircuit - ri := tf.AccRandTimeInt() resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -260,17 +233,17 @@ func testAccAzureRMExpressRouteCircuit_allowClassicOperationsUpdate(t *testing.T CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMExpressRouteCircuit_allowClassicOperations(ri, acceptance.Location(), "false"), + Config: testAccAzureRMExpressRouteCircuit_allowClassicOperations(data, "false"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMExpressRouteCircuitExists("azurerm_express_route_circuit.test", &erc), - resource.TestCheckResourceAttr(resourceName, "allow_classic_operations", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "allow_classic_operations", "false"), ), }, { - Config: testAccAzureRMExpressRouteCircuit_allowClassicOperations(ri, acceptance.Location(), "true"), + Config: testAccAzureRMExpressRouteCircuit_allowClassicOperations(data, "true"), Check: resource.ComposeTestCheckFunc( testCheckAzureRMExpressRouteCircuitExists("azurerm_express_route_circuit.test", &erc), - resource.TestCheckResourceAttr(resourceName, "allow_classic_operations", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "allow_classic_operations", "true"), ), }, }, @@ -334,7 +307,7 @@ func testCheckAzureRMExpressRouteCircuitDestroy(s *terraform.State) error { return nil } -func testAccAzureRMExpressRouteCircuit_basicMeteredConfig(rInt int, location string) string { +func testAccAzureRMExpressRouteCircuit_basicMeteredConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -361,11 +334,11 @@ resource "azurerm_express_route_circuit" "test" { Purpose = "AcceptanceTests" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMExpressRouteCircuit_requiresImportConfig(rInt int, location string) string { - template := testAccAzureRMExpressRouteCircuit_basicMeteredConfig(rInt, location) +func testAccAzureRMExpressRouteCircuit_requiresImportConfig(data acceptance.TestData) string { + template := testAccAzureRMExpressRouteCircuit_basicMeteredConfig(data) return fmt.Sprintf(` %s @@ -392,7 +365,7 @@ resource "azurerm_express_route_circuit" "import" { `, template) } -func testAccAzureRMExpressRouteCircuit_basicUnlimitedConfig(rInt int, location string) string { +func testAccAzureRMExpressRouteCircuit_basicUnlimitedConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -419,10 +392,10 @@ resource "azurerm_express_route_circuit" "test" { Purpose = "AcceptanceTests" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMExpressRouteCircuit_sku(rInt int, location string, tier string, family string) string { +func testAccAzureRMExpressRouteCircuit_sku(data acceptance.TestData, tier string, family string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -449,10 +422,10 @@ resource "azurerm_express_route_circuit" "test" { Purpose = "AcceptanceTests" } } -`, rInt, location, rInt, tier, family) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, tier, family) } -func testAccAzureRMExpressRouteCircuit_allowClassicOperations(rInt int, location string, allowClassicOperations string) string { +func testAccAzureRMExpressRouteCircuit_allowClassicOperations(data acceptance.TestData, allowClassicOperations string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -479,5 +452,5 @@ resource "azurerm_express_route_circuit" "test" { Purpose = "AcceptanceTests" } } -`, rInt, location, rInt, allowClassicOperations) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, allowClassicOperations) } diff --git a/azurerm/internal/services/network/resource_arm_firewall_application_rule_collection_test.go b/azurerm/internal/services/network/tests/resource_arm_firewall_application_rule_collection_test.go similarity index 60% rename from azurerm/internal/services/network/resource_arm_firewall_application_rule_collection_test.go rename to azurerm/internal/services/network/tests/resource_arm_firewall_application_rule_collection_test.go index 9c483e1689ac..2356d4f03918 100644 --- a/azurerm/internal/services/network/resource_arm_firewall_application_rule_collection_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_firewall_application_rule_collection_test.go @@ -1,10 +1,9 @@ -package network +package tests import ( "fmt" "testing" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,10 +14,7 @@ import ( ) func TestAccAzureRMFirewallApplicationRuleCollection_basic(t *testing.T) { - resourceName := "azurerm_firewall_application_rule_collection.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_application_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,26 +22,22 @@ func TestAccAzureRMFirewallApplicationRuleCollection_basic(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallApplicationRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.name", "rule1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.source_addresses.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.target_fqdns.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.0.port", "443"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.0.type", "Https"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.name", "rule1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.source_addresses.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.target_fqdns.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.0.port", "443"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.0.type", "Https"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -56,10 +48,7 @@ func TestAccAzureRMFirewallApplicationRuleCollection_requiresImport(t *testing.T return } - resourceName := "azurerm_firewall_application_rule_collection.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_application_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -67,13 +56,13 @@ func TestAccAzureRMFirewallApplicationRuleCollection_requiresImport(t *testing.T CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallApplicationRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), ), }, { - Config: testAccAzureRMFirewallApplicationRuleCollection_requiresImport(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_firewall_application_rule_collection"), }, }, @@ -81,10 +70,7 @@ func TestAccAzureRMFirewallApplicationRuleCollection_requiresImport(t *testing.T } func TestAccAzureRMFirewallApplicationRuleCollection_updatedName(t *testing.T) { - resourceName := "azurerm_firewall_application_rule_collection.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_application_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -92,25 +78,25 @@ func TestAccAzureRMFirewallApplicationRuleCollection_updatedName(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallApplicationRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.name", "rule1"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.name", "rule1"), ), }, { - Config: testAccAzureRMFirewallApplicationRuleCollection_updatedName(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_updatedName(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.name", "rule2"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.name", "rule2"), ), }, }, @@ -118,11 +104,9 @@ func TestAccAzureRMFirewallApplicationRuleCollection_updatedName(t *testing.T) { } func TestAccAzureRMFirewallApplicationRuleCollection_multipleRuleCollections(t *testing.T) { - firstRule := "azurerm_firewall_application_rule_collection.test" - secondRule := "azurerm_firewall_application_rule_collection.test_add" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_firewall_application_rule_collection", "test") - location := acceptance.Location() + secondRule := "azurerm_firewall_application_rule_collection.test_add" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -130,23 +114,23 @@ func TestAccAzureRMFirewallApplicationRuleCollection_multipleRuleCollections(t * CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallApplicationRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(firstRule), - resource.TestCheckResourceAttr(firstRule, "name", "acctestarc"), - resource.TestCheckResourceAttr(firstRule, "priority", "100"), - resource.TestCheckResourceAttr(firstRule, "action", "Allow"), - resource.TestCheckResourceAttr(firstRule, "rule.#", "1"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), ), }, { - Config: testAccAzureRMFirewallApplicationRuleCollection_multiple(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_multiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(firstRule), - resource.TestCheckResourceAttr(firstRule, "name", "acctestarc"), - resource.TestCheckResourceAttr(firstRule, "priority", "100"), - resource.TestCheckResourceAttr(firstRule, "action", "Allow"), - resource.TestCheckResourceAttr(firstRule, "rule.#", "1"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), testCheckAzureRMFirewallApplicationRuleCollectionExists(secondRule), resource.TestCheckResourceAttr(secondRule, "name", "acctestarc_add"), resource.TestCheckResourceAttr(secondRule, "priority", "200"), @@ -155,13 +139,13 @@ func TestAccAzureRMFirewallApplicationRuleCollection_multipleRuleCollections(t * ), }, { - Config: testAccAzureRMFirewallApplicationRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(firstRule), - resource.TestCheckResourceAttr(firstRule, "name", "acctestarc"), - resource.TestCheckResourceAttr(firstRule, "priority", "100"), - resource.TestCheckResourceAttr(firstRule, "action", "Allow"), - resource.TestCheckResourceAttr(firstRule, "rule.#", "1"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), testCheckAzureRMFirewallApplicationRuleCollectionDoesNotExist("azurerm_firewall.test", "acctestarc_add"), ), }, @@ -170,11 +154,8 @@ func TestAccAzureRMFirewallApplicationRuleCollection_multipleRuleCollections(t * } func TestAccAzureRMFirewallApplicationRuleCollection_update(t *testing.T) { - firstResourceName := "azurerm_firewall_application_rule_collection.test" + data := acceptance.BuildTestData(t, "azurerm_firewall_application_rule_collection", "test") secondResourceName := "azurerm_firewall_application_rule_collection.test_add" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -182,13 +163,13 @@ func TestAccAzureRMFirewallApplicationRuleCollection_update(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallApplicationRuleCollection_multiple(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_multiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(firstResourceName), - resource.TestCheckResourceAttr(firstResourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(firstResourceName, "priority", "100"), - resource.TestCheckResourceAttr(firstResourceName, "action", "Allow"), - resource.TestCheckResourceAttr(firstResourceName, "rule.#", "1"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), testCheckAzureRMFirewallApplicationRuleCollectionExists(secondResourceName), resource.TestCheckResourceAttr(secondResourceName, "name", "acctestarc_add"), resource.TestCheckResourceAttr(secondResourceName, "priority", "200"), @@ -197,13 +178,13 @@ func TestAccAzureRMFirewallApplicationRuleCollection_update(t *testing.T) { ), }, { - Config: testAccAzureRMFirewallApplicationRuleCollection_multipleUpdate(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_multipleUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(firstResourceName), - resource.TestCheckResourceAttr(firstResourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(firstResourceName, "priority", "300"), - resource.TestCheckResourceAttr(firstResourceName, "action", "Deny"), - resource.TestCheckResourceAttr(firstResourceName, "rule.#", "1"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "300"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Deny"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), testCheckAzureRMFirewallApplicationRuleCollectionExists(secondResourceName), resource.TestCheckResourceAttr(secondResourceName, "name", "acctestarc_add"), resource.TestCheckResourceAttr(secondResourceName, "priority", "400"), @@ -216,10 +197,7 @@ func TestAccAzureRMFirewallApplicationRuleCollection_update(t *testing.T) { } func TestAccAzureRMFirewallApplicationRuleCollection_disappears(t *testing.T) { - resourceName := "azurerm_firewall_application_rule_collection.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_application_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -227,14 +205,14 @@ func TestAccAzureRMFirewallApplicationRuleCollection_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallApplicationRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - testCheckAzureRMFirewallApplicationRuleCollectionDisappears(resourceName), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + testCheckAzureRMFirewallApplicationRuleCollectionDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -243,10 +221,7 @@ func TestAccAzureRMFirewallApplicationRuleCollection_disappears(t *testing.T) { } func TestAccAzureRMFirewallApplicationRuleCollection_multipleRules(t *testing.T) { - resourceName := "azurerm_firewall_application_rule_collection.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_application_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -254,33 +229,33 @@ func TestAccAzureRMFirewallApplicationRuleCollection_multipleRules(t *testing.T) CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallApplicationRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), ), }, { - Config: testAccAzureRMFirewallApplicationRuleCollection_multipleRules(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_multipleRules(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "2"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "2"), ), }, { - Config: testAccAzureRMFirewallApplicationRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), ), }, }, @@ -288,10 +263,7 @@ func TestAccAzureRMFirewallApplicationRuleCollection_multipleRules(t *testing.T) } func TestAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(t *testing.T) { - resourceName := "azurerm_firewall_application_rule_collection.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_application_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -299,34 +271,27 @@ func TestAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(t *testin CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.#", "2"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.0.port", "8000"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.0.type", "Http"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.1.port", "8001"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.1.type", "Https"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.0.port", "8000"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.0.type", "Http"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.1.port", "8001"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.1.type", "Https"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFirewallApplicationRuleCollection_updateProtocols(t *testing.T) { - resourceName := "azurerm_firewall_application_rule_collection.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_application_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -334,48 +299,48 @@ func TestAccAzureRMFirewallApplicationRuleCollection_updateProtocols(t *testing. CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.#", "2"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.0.port", "8000"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.0.type", "Http"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.1.port", "8001"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.1.type", "Https"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.0.port", "8000"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.0.type", "Http"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.1.port", "8001"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.1.type", "Https"), ), }, { - Config: testAccAzureRMFirewallApplicationRuleCollection_multipleProtocolsUpdate(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_multipleProtocolsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.#", "2"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.0.port", "9000"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.0.type", "Https"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.1.port", "9001"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.1.type", "Http"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.0.port", "9000"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.0.type", "Https"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.1.port", "9001"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.1.type", "Http"), ), }, { - Config: testAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.#", "2"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.0.port", "8000"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.0.type", "Http"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.1.port", "8001"), - resource.TestCheckResourceAttr(resourceName, "rule.0.protocol.1.type", "Https"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.0.port", "8000"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.0.type", "Http"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.1.port", "8001"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.protocol.1.type", "Https"), ), }, }, @@ -383,10 +348,7 @@ func TestAccAzureRMFirewallApplicationRuleCollection_updateProtocols(t *testing. } func TestAccAzureRMFirewallApplicationRuleCollection_updateFirewallTags(t *testing.T) { - resourceName := "azurerm_firewall_application_rule_collection.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_application_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -394,25 +356,25 @@ func TestAccAzureRMFirewallApplicationRuleCollection_updateFirewallTags(t *testi CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallApplicationRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.name", "rule1"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.name", "rule1"), ), }, { - Config: testAccAzureRMFirewallApplicationRuleCollection_updateFirewallTags(ri, location), + Config: testAccAzureRMFirewallApplicationRuleCollection_updateFirewallTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallApplicationRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestarc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.0.name", "rule1"), + testCheckAzureRMFirewallApplicationRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestarc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.0.name", "rule1"), ), }, }, @@ -523,8 +485,8 @@ func testCheckAzureRMFirewallApplicationRuleCollectionDisappears(resourceName st } } -func testAccAzureRMFirewallApplicationRuleCollection_basic(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallApplicationRuleCollection_basic(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -555,8 +517,8 @@ resource "azurerm_firewall_application_rule_collection" "test" { `, template) } -func testAccAzureRMFirewallApplicationRuleCollection_requiresImport(rInt int, location string) string { - template := testAccAzureRMFirewallApplicationRuleCollection_basic(rInt, location) +func testAccAzureRMFirewallApplicationRuleCollection_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMFirewallApplicationRuleCollection_basic(data) return fmt.Sprintf(` %s @@ -587,8 +549,8 @@ resource "azurerm_firewall_application_rule_collection" "import" { `, template) } -func testAccAzureRMFirewallApplicationRuleCollection_updatedName(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallApplicationRuleCollection_updatedName(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -619,8 +581,8 @@ resource "azurerm_firewall_application_rule_collection" "test" { `, template) } -func testAccAzureRMFirewallApplicationRuleCollection_multiple(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallApplicationRuleCollection_multiple(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -676,8 +638,8 @@ resource "azurerm_firewall_application_rule_collection" "test_add" { `, template) } -func testAccAzureRMFirewallApplicationRuleCollection_multipleUpdate(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallApplicationRuleCollection_multipleUpdate(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -733,8 +695,8 @@ resource "azurerm_firewall_application_rule_collection" "test_add" { `, template) } -func testAccAzureRMFirewallApplicationRuleCollection_multipleRules(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallApplicationRuleCollection_multipleRules(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -782,8 +744,8 @@ resource "azurerm_firewall_application_rule_collection" "test" { `, template) } -func testAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallApplicationRuleCollection_multipleProtocols(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -819,8 +781,8 @@ resource "azurerm_firewall_application_rule_collection" "test" { `, template) } -func testAccAzureRMFirewallApplicationRuleCollection_multipleProtocolsUpdate(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallApplicationRuleCollection_multipleProtocolsUpdate(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -856,8 +818,8 @@ resource "azurerm_firewall_application_rule_collection" "test" { `, template) } -func testAccAzureRMFirewallApplicationRuleCollection_updateFirewallTags(rInt int, location string) string { - template := testAccAzureRMFirewall_withTags(rInt, location) +func testAccAzureRMFirewallApplicationRuleCollection_updateFirewallTags(data acceptance.TestData) string { + template := testAccAzureRMFirewall_withTags(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection_test.go b/azurerm/internal/services/network/tests/resource_arm_firewall_nat_rule_collection_test.go similarity index 72% rename from azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection_test.go rename to azurerm/internal/services/network/tests/resource_arm_firewall_nat_rule_collection_test.go index d1783530aba6..0bb9735dd122 100644 --- a/azurerm/internal/services/network/resource_arm_firewall_nat_rule_collection_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_firewall_nat_rule_collection_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMFirewallNatRuleCollection_basic(t *testing.T) { - resourceName := "azurerm_firewall_nat_rule_collection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_nat_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +21,12 @@ func TestAccAzureRMFirewallNatRuleCollection_basic(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNatRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(resourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,10 +37,7 @@ func TestAccAzureRMFirewallNatRuleCollection_requiresImport(t *testing.T) { return } - resourceName := "azurerm_firewall_nat_rule_collection.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_nat_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,13 +45,13 @@ func TestAccAzureRMFirewallNatRuleCollection_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNatRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(resourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), ), }, { - Config: testAccAzureRMFirewallNatRuleCollection_requiresImport(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_firewall_nat_rule_collection"), }, }, @@ -69,9 +59,7 @@ func TestAccAzureRMFirewallNatRuleCollection_requiresImport(t *testing.T) { } func TestAccAzureRMFirewallNatRuleCollection_updatedName(t *testing.T) { - resourceName := "azurerm_firewall_nat_rule_collection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_nat_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,36 +67,26 @@ func TestAccAzureRMFirewallNatRuleCollection_updatedName(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNatRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(resourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMFirewallNatRuleCollection_updatedName(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_updatedName(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(resourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFirewallNatRuleCollection_multipleRuleCollections(t *testing.T) { - firstRule := "azurerm_firewall_nat_rule_collection.test" + data := acceptance.BuildTestData(t, "azurerm_firewall_nat_rule_collection", "test") secondRule := "azurerm_firewall_nat_rule_collection.test_add" - ri := tf.AccRandTimeInt() - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -116,49 +94,35 @@ func TestAccAzureRMFirewallNatRuleCollection_multipleRuleCollections(t *testing. CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNatRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(firstRule), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: firstRule, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMFirewallNatRuleCollection_multiple(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_multiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(firstRule), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), testCheckAzureRMFirewallNatRuleCollectionExists(secondRule), ), }, + data.ImportStep(), { - ResourceName: firstRule, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMFirewallNatRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(firstRule), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), testCheckAzureRMFirewallNatRuleCollectionDoesNotExist("azurerm_firewall.test", "acctestnrc_add"), ), }, - { - ResourceName: firstRule, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFirewallNatRuleCollection_update(t *testing.T) { - firstResourceName := "azurerm_firewall_nat_rule_collection.test" + data := acceptance.BuildTestData(t, "azurerm_firewall_nat_rule_collection", "test") secondResourceName := "azurerm_firewall_nat_rule_collection.test_add" - ri := tf.AccRandTimeInt() - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -166,37 +130,27 @@ func TestAccAzureRMFirewallNatRuleCollection_update(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNatRuleCollection_multiple(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_multiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(firstResourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), testCheckAzureRMFirewallNatRuleCollectionExists(secondResourceName), ), }, + data.ImportStep(), { - ResourceName: firstResourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMFirewallNatRuleCollection_multipleUpdate(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_multipleUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(firstResourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), testCheckAzureRMFirewallNatRuleCollectionExists(secondResourceName), ), }, - { - ResourceName: firstResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFirewallNatRuleCollection_disappears(t *testing.T) { - resourceName := "azurerm_firewall_nat_rule_collection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_nat_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -204,10 +158,10 @@ func TestAccAzureRMFirewallNatRuleCollection_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNatRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(resourceName), - testCheckAzureRMFirewallNatRuleCollectionDisappears(resourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), + testCheckAzureRMFirewallNatRuleCollectionDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -216,9 +170,7 @@ func TestAccAzureRMFirewallNatRuleCollection_disappears(t *testing.T) { } func TestAccAzureRMFirewallNatRuleCollection_multipleRules(t *testing.T) { - resourceName := "azurerm_firewall_nat_rule_collection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_nat_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -226,46 +178,32 @@ func TestAccAzureRMFirewallNatRuleCollection_multipleRules(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNatRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(resourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMFirewallNatRuleCollection_multipleRules(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_multipleRules(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(resourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMFirewallNatRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(resourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFirewallNatRuleCollection_updateFirewallTags(t *testing.T) { - resourceName := "azurerm_firewall_nat_rule_collection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_nat_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -273,27 +211,19 @@ func TestAccAzureRMFirewallNatRuleCollection_updateFirewallTags(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNatRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(resourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMFirewallNatRuleCollection_updateFirewallTags(ri, location), + Config: testAccAzureRMFirewallNatRuleCollection_updateFirewallTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNatRuleCollectionExists(resourceName), + testCheckAzureRMFirewallNatRuleCollectionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -403,8 +333,8 @@ func testCheckAzureRMFirewallNatRuleCollectionDisappears(resourceName string) re } } -func testAccAzureRMFirewallNatRuleCollection_basic(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallNatRuleCollection_basic(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -438,11 +368,11 @@ resource "azurerm_firewall_nat_rule_collection" "test" { translated_address = "8.8.8.8" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMFirewallNatRuleCollection_requiresImport(rInt int, location string) string { - template := testAccAzureRMFirewallNatRuleCollection_basic(rInt, location) +func testAccAzureRMFirewallNatRuleCollection_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMFirewallNatRuleCollection_basic(data) return fmt.Sprintf(` %s @@ -479,8 +409,8 @@ resource "azurerm_firewall_nat_rule_collection" "import" { `, template) } -func testAccAzureRMFirewallNatRuleCollection_updatedName(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallNatRuleCollection_updatedName(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -514,11 +444,11 @@ resource "azurerm_firewall_nat_rule_collection" "test" { translated_address = "8.8.8.8" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMFirewallNatRuleCollection_multiple(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallNatRuleCollection_multiple(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -583,11 +513,11 @@ resource "azurerm_firewall_nat_rule_collection" "test_add" { translated_address = "8.8.4.4" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFirewallNatRuleCollection_multipleUpdate(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallNatRuleCollection_multipleUpdate(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -652,11 +582,11 @@ resource "azurerm_firewall_nat_rule_collection" "test_add" { translated_address = "10.0.0.1" } } -`, template, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFirewallNatRuleCollection_multipleRules(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallNatRuleCollection_multipleRules(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -713,11 +643,11 @@ resource "azurerm_firewall_nat_rule_collection" "test" { translated_address = "192.168.0.1" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMFirewallNatRuleCollection_updateFirewallTags(rInt int, location string) string { - template := testAccAzureRMFirewall_withTags(rInt, location) +func testAccAzureRMFirewallNatRuleCollection_updateFirewallTags(data acceptance.TestData) string { + template := testAccAzureRMFirewall_withTags(data) return fmt.Sprintf(` %s @@ -751,5 +681,5 @@ resource "azurerm_firewall_nat_rule_collection" "test" { translated_address = "10.0.0.1" } } -`, template, rInt) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_firewall_network_rule_collection_test.go b/azurerm/internal/services/network/tests/resource_arm_firewall_network_rule_collection_test.go similarity index 65% rename from azurerm/internal/services/network/resource_arm_firewall_network_rule_collection_test.go rename to azurerm/internal/services/network/tests/resource_arm_firewall_network_rule_collection_test.go index d070995c97bd..7a17ff489656 100644 --- a/azurerm/internal/services/network/resource_arm_firewall_network_rule_collection_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_firewall_network_rule_collection_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMFirewallNetworkRuleCollection_basic(t *testing.T) { - resourceName := "azurerm_firewall_network_rule_collection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_network_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,20 +21,16 @@ func TestAccAzureRMFirewallNetworkRuleCollection_basic(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNetworkRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -48,10 +41,7 @@ func TestAccAzureRMFirewallNetworkRuleCollection_requiresImport(t *testing.T) { return } - resourceName := "azurerm_firewall_network_rule_collection.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_network_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -59,13 +49,13 @@ func TestAccAzureRMFirewallNetworkRuleCollection_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNetworkRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(resourceName), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), ), }, { - Config: testAccAzureRMFirewallNetworkRuleCollection_requiresImport(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_firewall_network_rule_collection"), }, }, @@ -73,9 +63,7 @@ func TestAccAzureRMFirewallNetworkRuleCollection_requiresImport(t *testing.T) { } func TestAccAzureRMFirewallNetworkRuleCollection_updatedName(t *testing.T) { - resourceName := "azurerm_firewall_network_rule_collection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_network_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -83,25 +71,25 @@ func TestAccAzureRMFirewallNetworkRuleCollection_updatedName(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNetworkRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.3765122797.name", "rule1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.3765122797.name", "rule1"), ), }, { - Config: testAccAzureRMFirewallNetworkRuleCollection_updatedName(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_updatedName(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - resource.TestCheckResourceAttr(resourceName, "rule.1700340761.name", "rule2"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.1700340761.name", "rule2"), ), }, }, @@ -109,10 +97,8 @@ func TestAccAzureRMFirewallNetworkRuleCollection_updatedName(t *testing.T) { } func TestAccAzureRMFirewallNetworkRuleCollection_multipleRuleCollections(t *testing.T) { - firstRule := "azurerm_firewall_network_rule_collection.test" + data := acceptance.BuildTestData(t, "azurerm_firewall_network_rule_collection", "test") secondRule := "azurerm_firewall_network_rule_collection.test_add" - ri := tf.AccRandTimeInt() - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -120,23 +106,23 @@ func TestAccAzureRMFirewallNetworkRuleCollection_multipleRuleCollections(t *test CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNetworkRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(firstRule), - resource.TestCheckResourceAttr(firstRule, "name", "acctestnrc"), - resource.TestCheckResourceAttr(firstRule, "priority", "100"), - resource.TestCheckResourceAttr(firstRule, "action", "Allow"), - resource.TestCheckResourceAttr(firstRule, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), ), }, { - Config: testAccAzureRMFirewallNetworkRuleCollection_multiple(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_multiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(firstRule), - resource.TestCheckResourceAttr(firstRule, "name", "acctestnrc"), - resource.TestCheckResourceAttr(firstRule, "priority", "100"), - resource.TestCheckResourceAttr(firstRule, "action", "Allow"), - resource.TestCheckResourceAttr(firstRule, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), testCheckAzureRMFirewallNetworkRuleCollectionExists(secondRule), resource.TestCheckResourceAttr(secondRule, "name", "acctestnrc_add"), resource.TestCheckResourceAttr(secondRule, "priority", "200"), @@ -145,13 +131,13 @@ func TestAccAzureRMFirewallNetworkRuleCollection_multipleRuleCollections(t *test ), }, { - Config: testAccAzureRMFirewallNetworkRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(firstRule), - resource.TestCheckResourceAttr(firstRule, "name", "acctestnrc"), - resource.TestCheckResourceAttr(firstRule, "priority", "100"), - resource.TestCheckResourceAttr(firstRule, "action", "Allow"), - resource.TestCheckResourceAttr(firstRule, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), testCheckAzureRMFirewallNetworkRuleCollectionDoesNotExist("azurerm_firewall.test", "acctestnrc_add"), ), }, @@ -160,10 +146,8 @@ func TestAccAzureRMFirewallNetworkRuleCollection_multipleRuleCollections(t *test } func TestAccAzureRMFirewallNetworkRuleCollection_update(t *testing.T) { - firstResourceName := "azurerm_firewall_network_rule_collection.test" + data := acceptance.BuildTestData(t, "azurerm_firewall_network_rule_collection", "test") secondResourceName := "azurerm_firewall_network_rule_collection.test_add" - ri := tf.AccRandTimeInt() - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -171,13 +155,13 @@ func TestAccAzureRMFirewallNetworkRuleCollection_update(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNetworkRuleCollection_multiple(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_multiple(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(firstResourceName), - resource.TestCheckResourceAttr(firstResourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(firstResourceName, "priority", "100"), - resource.TestCheckResourceAttr(firstResourceName, "action", "Allow"), - resource.TestCheckResourceAttr(firstResourceName, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), testCheckAzureRMFirewallNetworkRuleCollectionExists(secondResourceName), resource.TestCheckResourceAttr(secondResourceName, "name", "acctestnrc_add"), resource.TestCheckResourceAttr(secondResourceName, "priority", "200"), @@ -186,13 +170,13 @@ func TestAccAzureRMFirewallNetworkRuleCollection_update(t *testing.T) { ), }, { - Config: testAccAzureRMFirewallNetworkRuleCollection_multipleUpdate(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_multipleUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(firstResourceName), - resource.TestCheckResourceAttr(firstResourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(firstResourceName, "priority", "300"), - resource.TestCheckResourceAttr(firstResourceName, "action", "Deny"), - resource.TestCheckResourceAttr(firstResourceName, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "300"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Deny"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), testCheckAzureRMFirewallNetworkRuleCollectionExists(secondResourceName), resource.TestCheckResourceAttr(secondResourceName, "name", "acctestnrc_add"), resource.TestCheckResourceAttr(secondResourceName, "priority", "400"), @@ -205,9 +189,7 @@ func TestAccAzureRMFirewallNetworkRuleCollection_update(t *testing.T) { } func TestAccAzureRMFirewallNetworkRuleCollection_disappears(t *testing.T) { - resourceName := "azurerm_firewall_network_rule_collection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_network_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -215,14 +197,14 @@ func TestAccAzureRMFirewallNetworkRuleCollection_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNetworkRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), - testCheckAzureRMFirewallNetworkRuleCollectionDisappears(resourceName), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -231,9 +213,7 @@ func TestAccAzureRMFirewallNetworkRuleCollection_disappears(t *testing.T) { } func TestAccAzureRMFirewallNetworkRuleCollection_multipleRules(t *testing.T) { - resourceName := "azurerm_firewall_network_rule_collection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_network_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -241,33 +221,33 @@ func TestAccAzureRMFirewallNetworkRuleCollection_multipleRules(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNetworkRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), ), }, { - Config: testAccAzureRMFirewallNetworkRuleCollection_multipleRules(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_multipleRules(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "2"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "2"), ), }, { - Config: testAccAzureRMFirewallNetworkRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), ), }, }, @@ -275,9 +255,7 @@ func TestAccAzureRMFirewallNetworkRuleCollection_multipleRules(t *testing.T) { } func TestAccAzureRMFirewallNetworkRuleCollection_updateFirewallTags(t *testing.T) { - resourceName := "azurerm_firewall_network_rule_collection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall_network_rule_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -285,23 +263,23 @@ func TestAccAzureRMFirewallNetworkRuleCollection_updateFirewallTags(t *testing.T CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewallNetworkRuleCollection_basic(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), ), }, { - Config: testAccAzureRMFirewallNetworkRuleCollection_updateFirewallTags(ri, location), + Config: testAccAzureRMFirewallNetworkRuleCollection_updateFirewallTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallNetworkRuleCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctestnrc"), - resource.TestCheckResourceAttr(resourceName, "priority", "100"), - resource.TestCheckResourceAttr(resourceName, "action", "Allow"), - resource.TestCheckResourceAttr(resourceName, "rule.#", "1"), + testCheckAzureRMFirewallNetworkRuleCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctestnrc"), + resource.TestCheckResourceAttr(data.ResourceName, "priority", "100"), + resource.TestCheckResourceAttr(data.ResourceName, "action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "rule.#", "1"), ), }, }, @@ -413,8 +391,8 @@ func testCheckAzureRMFirewallNetworkRuleCollectionDisappears(resourceName string } } -func testAccAzureRMFirewallNetworkRuleCollection_basic(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallNetworkRuleCollection_basic(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -448,8 +426,8 @@ resource "azurerm_firewall_network_rule_collection" "test" { `, template) } -func testAccAzureRMFirewallNetworkRuleCollection_requiresImport(rInt int, location string) string { - template := testAccAzureRMFirewallNetworkRuleCollection_basic(rInt, location) +func testAccAzureRMFirewallNetworkRuleCollection_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMFirewallNetworkRuleCollection_basic(data) return fmt.Sprintf(` %s @@ -483,8 +461,8 @@ resource "azurerm_firewall_network_rule_collection" "import" { `, template) } -func testAccAzureRMFirewallNetworkRuleCollection_updatedName(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallNetworkRuleCollection_updatedName(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -518,8 +496,8 @@ resource "azurerm_firewall_network_rule_collection" "test" { `, template) } -func testAccAzureRMFirewallNetworkRuleCollection_multiple(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallNetworkRuleCollection_multiple(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -581,8 +559,8 @@ resource "azurerm_firewall_network_rule_collection" "test_add" { `, template) } -func testAccAzureRMFirewallNetworkRuleCollection_multipleUpdate(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallNetworkRuleCollection_multipleUpdate(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -644,8 +622,8 @@ resource "azurerm_firewall_network_rule_collection" "test_add" { `, template) } -func testAccAzureRMFirewallNetworkRuleCollection_multipleRules(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewallNetworkRuleCollection_multipleRules(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -699,8 +677,8 @@ resource "azurerm_firewall_network_rule_collection" "test" { `, template) } -func testAccAzureRMFirewallNetworkRuleCollection_updateFirewallTags(rInt int, location string) string { - template := testAccAzureRMFirewall_withTags(rInt, location) +func testAccAzureRMFirewallNetworkRuleCollection_updateFirewallTags(data acceptance.TestData) string { + template := testAccAzureRMFirewall_withTags(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_firewall_test.go b/azurerm/internal/services/network/tests/resource_arm_firewall_test.go similarity index 75% rename from azurerm/internal/services/network/resource_arm_firewall_test.go rename to azurerm/internal/services/network/tests/resource_arm_firewall_test.go index 71598089231f..b484277e1c76 100644 --- a/azurerm/internal/services/network/resource_arm_firewall_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_firewall_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,10 +7,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -26,7 +26,7 @@ func TestValidateFirewallName(t *testing.T) { strings.Repeat("w", 65), } for _, v := range validNames { - _, errors := validateAzureFirewallName(v, "name") + _, errors := network.ValidateAzureFirewallName(v, "name") if len(errors) != 0 { t.Fatalf("%q should be a valid Firewall Name: %q", v, errors) } @@ -43,7 +43,7 @@ func TestValidateFirewallName(t *testing.T) { "invalid!", } for _, v := range invalidNames { - _, errors := validateAzureFirewallName(v, "name") + _, errors := network.ValidateAzureFirewallName(v, "name") if len(errors) == 0 { t.Fatalf("%q should be an invalid Firewall Name", v) } @@ -51,9 +51,7 @@ func TestValidateFirewallName(t *testing.T) { } func TestAccAzureRMFirewall_basicOld(t *testing.T) { - resourceName := "azurerm_firewall.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -61,34 +59,28 @@ func TestAccAzureRMFirewall_basicOld(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewall_basicOld(ri, location), + Config: testAccAzureRMFirewall_basicOld(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.name", "configuration"), - resource.TestCheckResourceAttrSet(resourceName, "ip_configuration.0.private_ip_address"), + testCheckAzureRMFirewallExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "configuration"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), ), }, { - Config: testAccAzureRMFirewall_basic(ri, location), + Config: testAccAzureRMFirewall_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.name", "configuration"), - resource.TestCheckResourceAttrSet(resourceName, "ip_configuration.0.private_ip_address"), + testCheckAzureRMFirewallExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "configuration"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFirewall_basic(t *testing.T) { - resourceName := "azurerm_firewall.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -96,26 +88,20 @@ func TestAccAzureRMFirewall_basic(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewall_basic(ri, location), + Config: testAccAzureRMFirewall_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.name", "configuration"), - resource.TestCheckResourceAttrSet(resourceName, "ip_configuration.0.private_ip_address"), + testCheckAzureRMFirewallExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "configuration"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFirewall_withMultiplePublicIPs(t *testing.T) { - resourceName := "azurerm_firewall.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -123,20 +109,16 @@ func TestAccAzureRMFirewall_withMultiplePublicIPs(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewall_multiplePublicIps(ri, location), + Config: testAccAzureRMFirewall_multiplePublicIps(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.name", "configuration"), - resource.TestCheckResourceAttrSet(resourceName, "ip_configuration.0.private_ip_address"), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.1.name", "configuration_2"), - resource.TestCheckResourceAttrSet(resourceName, "ip_configuration.1.public_ip_address_id"), + testCheckAzureRMFirewallExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "configuration"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.name", "configuration_2"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.1.public_ip_address_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -147,10 +129,7 @@ func TestAccAzureRMFirewall_requiresImport(t *testing.T) { return } - resourceName := "azurerm_firewall.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -158,13 +137,13 @@ func TestAccAzureRMFirewall_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewall_basic(ri, location), + Config: testAccAzureRMFirewall_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(resourceName), + testCheckAzureRMFirewallExists(data.ResourceName), ), }, { - Config: testAccAzureRMFirewall_requiresImport(ri, location), + Config: testAccAzureRMFirewall_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_firewall"), }, }, @@ -172,9 +151,7 @@ func TestAccAzureRMFirewall_requiresImport(t *testing.T) { } func TestAccAzureRMFirewall_withTags(t *testing.T) { - resourceName := "azurerm_firewall.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -182,35 +159,29 @@ func TestAccAzureRMFirewall_withTags(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewall_withTags(ri, location), + Config: testAccAzureRMFirewall_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMFirewallExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { - Config: testAccAzureRMFirewall_withUpdatedTags(ri, location), + Config: testAccAzureRMFirewall_withUpdatedTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMFirewallExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFirewall_withZones(t *testing.T) { - resourceName := "azurerm_firewall.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall", "test") zones := []string{"1"} zonesUpdate := []string{"1", "3"} @@ -220,21 +191,21 @@ func TestAccAzureRMFirewall_withZones(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewall_withZones(rInt, location, zones), + Config: testAccAzureRMFirewall_withZones(data, zones), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "zones.#", "1"), - resource.TestCheckResourceAttr(resourceName, "zones.0", "1"), + testCheckAzureRMFirewallExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "zones.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.0", "1"), ), }, { - Config: testAccAzureRMFirewall_withZones(rInt, location, zonesUpdate), + Config: testAccAzureRMFirewall_withZones(data, zonesUpdate), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "zones.#", "2"), - resource.TestCheckResourceAttr(resourceName, "zones.0", "1"), - resource.TestCheckResourceAttr(resourceName, "zones.1", "3"), + testCheckAzureRMFirewallExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "zones.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.0", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.1", "3"), ), }, }, @@ -242,9 +213,7 @@ func TestAccAzureRMFirewall_withZones(t *testing.T) { } func TestAccAzureRMFirewall_disappears(t *testing.T) { - resourceName := "azurerm_firewall.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_firewall", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -252,10 +221,10 @@ func TestAccAzureRMFirewall_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMFirewallDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFirewall_basic(ri, location), + Config: testAccAzureRMFirewall_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFirewallExists(resourceName), - testCheckAzureRMFirewallDisappears(resourceName), + testCheckAzureRMFirewallExists(data.ResourceName), + testCheckAzureRMFirewallDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -347,7 +316,7 @@ func testCheckAzureRMFirewallDestroy(s *terraform.State) error { return nil } -func testAccAzureRMFirewall_basicOld(rInt int, location string) string { +func testAccAzureRMFirewall_basicOld(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -387,10 +356,10 @@ resource "azurerm_firewall" "test" { internal_public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFirewall_basic(rInt int, location string) string { +func testAccAzureRMFirewall_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -430,10 +399,10 @@ resource "azurerm_firewall" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFirewall_multiplePublicIps(rInt int, location string) string { +func testAccAzureRMFirewall_multiplePublicIps(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -486,11 +455,11 @@ resource "azurerm_firewall" "test" { public_ip_address_id = "${azurerm_public_ip.test_2.id}" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFirewall_requiresImport(rInt int, location string) string { - template := testAccAzureRMFirewall_basic(rInt, location) +func testAccAzureRMFirewall_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMFirewall_basic(data) return fmt.Sprintf(` %s @@ -508,7 +477,7 @@ resource "azurerm_firewall" "import" { `, template) } -func testAccAzureRMFirewall_withTags(rInt int, location string) string { +func testAccAzureRMFirewall_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -553,10 +522,10 @@ resource "azurerm_firewall" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFirewall_withUpdatedTags(rInt int, location string) string { +func testAccAzureRMFirewall_withUpdatedTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -600,10 +569,10 @@ resource "azurerm_firewall" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFirewall_withZones(rInt int, location string, zones []string) string { +func testAccAzureRMFirewall_withZones(data acceptance.TestData, zones []string) string { zoneString := strings.Join(zones, ",") return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -646,5 +615,5 @@ resource "azurerm_firewall" "test" { zones = [%s] } -`, rInt, location, rInt, rInt, rInt, zoneString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, zoneString) } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_backend_address_pool_test.go similarity index 80% rename from azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool_test.go rename to azurerm/internal/services/network/tests/resource_arm_loadbalancer_backend_address_pool_test.go index 73d0561cea26..a41442d0d214 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_backend_address_pool_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_backend_address_pool_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -9,21 +9,22 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + nw "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" ) func TestAccAzureRMLoadBalancerBackEndAddressPool_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_backend_address_pool", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - addressPoolName := fmt.Sprintf("%d-address-pool", ri) + addressPoolName := fmt.Sprintf("%d-address-pool", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") backendAddressPoolId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/backendAddressPools/%s", - subscriptionID, ri, ri, addressPoolName) + subscriptionID, data.RandomInteger, data.RandomInteger, addressPoolName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -31,7 +32,7 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerBackEndAddressPool_basic(ri, addressPoolName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerBackEndAddressPool_basic(data, addressPoolName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerBackEndAddressPoolExists(addressPoolName, &lb), @@ -55,15 +56,15 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_requiresImport(t *testing.T) { return } + data := acceptance.BuildTestData(t, "azurerm_lb_backend_address_pool", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - addressPoolName := fmt.Sprintf("%d-address-pool", ri) + addressPoolName := fmt.Sprintf("%d-address-pool", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") backendAddressPoolId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/backendAddressPools/%s", - subscriptionID, ri, ri, addressPoolName) - location := acceptance.Location() + subscriptionID, data.RandomInteger, data.RandomInteger, addressPoolName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -71,7 +72,7 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerBackEndAddressPool_basic(ri, addressPoolName, location), + Config: testAccAzureRMLoadBalancerBackEndAddressPool_basic(data, addressPoolName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerBackEndAddressPoolExists(addressPoolName, &lb), @@ -79,7 +80,7 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_requiresImport(t *testing.T) { ), }, { - Config: testAccAzureRMLoadBalancerBackEndAddressPool_requiresImport(ri, addressPoolName, location), + Config: testAccAzureRMLoadBalancerBackEndAddressPool_requiresImport(data, addressPoolName), ExpectError: acceptance.RequiresImportError("azurerm_lb_backend_address_pool"), }, }, @@ -87,9 +88,10 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_requiresImport(t *testing.T) { } func TestAccAzureRMLoadBalancerBackEndAddressPool_removal(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_backend_address_pool", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - addressPoolName := fmt.Sprintf("%d-address-pool", ri) + addressPoolName := fmt.Sprintf("%d-address-pool", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -97,7 +99,7 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_removal(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerBackEndAddressPool_removal(ri, acceptance.Location()), + Config: testAccAzureRMLoadBalancerBackEndAddressPool_removal(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerBackEndAddressPoolNotExists(addressPoolName, &lb), @@ -108,9 +110,10 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_removal(t *testing.T) { } func TestAccAzureRMLoadBalancerBackEndAddressPool_disappears(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_backend_address_pool", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - addressPoolName := fmt.Sprintf("%d-address-pool", ri) + addressPoolName := fmt.Sprintf("%d-address-pool", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -118,7 +121,7 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerBackEndAddressPool_basic(ri, addressPoolName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerBackEndAddressPool_basic(data, addressPoolName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerBackEndAddressPoolExists(addressPoolName, &lb), @@ -132,7 +135,7 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_disappears(t *testing.T) { func testCheckAzureRMLoadBalancerBackEndAddressPoolExists(addressPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - _, _, exists := findLoadBalancerBackEndAddressPoolByName(lb, addressPoolName) + _, _, exists := nw.FindLoadBalancerBackEndAddressPoolByName(lb, addressPoolName) if !exists { return fmt.Errorf("A BackEnd Address Pool with name %q cannot be found.", addressPoolName) } @@ -143,7 +146,7 @@ func testCheckAzureRMLoadBalancerBackEndAddressPoolExists(addressPoolName string func testCheckAzureRMLoadBalancerBackEndAddressPoolNotExists(addressPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - _, _, exists := findLoadBalancerBackEndAddressPoolByName(lb, addressPoolName) + _, _, exists := nw.FindLoadBalancerBackEndAddressPoolByName(lb, addressPoolName) if exists { return fmt.Errorf("A BackEnd Address Pool with name %q has been found.", addressPoolName) } @@ -157,7 +160,7 @@ func testCheckAzureRMLoadBalancerBackEndAddressPoolDisappears(addressPoolName st client := acceptance.AzureProvider.Meta().(*clients.Client).Network.LoadBalancersClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - _, i, exists := findLoadBalancerBackEndAddressPoolByName(lb, addressPoolName) + _, i, exists := nw.FindLoadBalancerBackEndAddressPoolByName(lb, addressPoolName) if !exists { return fmt.Errorf("A BackEnd Address Pool with name %q cannot be found.", addressPoolName) } @@ -185,7 +188,7 @@ func testCheckAzureRMLoadBalancerBackEndAddressPoolDisappears(addressPoolName st } } -func testAccAzureRMLoadBalancerBackEndAddressPool_basic(rInt int, addressPoolName string, location string) string { +func testAccAzureRMLoadBalancerBackEndAddressPool_basic(data acceptance.TestData, addressPoolName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -216,11 +219,11 @@ resource "azurerm_lb_backend_address_pool" "test" { loadbalancer_id = "${azurerm_lb.test.id}" name = "%s" } -`, rInt, location, rInt, rInt, rInt, addressPoolName) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, addressPoolName) } -func testAccAzureRMLoadBalancerBackEndAddressPool_requiresImport(rInt int, name string, location string) string { - template := testAccAzureRMLoadBalancerBackEndAddressPool_basic(rInt, name, location) +func testAccAzureRMLoadBalancerBackEndAddressPool_requiresImport(data acceptance.TestData, name string) string { + template := testAccAzureRMLoadBalancerBackEndAddressPool_basic(data, name) return fmt.Sprintf(` %s @@ -233,7 +236,7 @@ resource "azurerm_lb_backend_address_pool" "import" { `, template) } -func testAccAzureRMLoadBalancerBackEndAddressPool_removal(rInt int, location string) string { +func testAccAzureRMLoadBalancerBackEndAddressPool_removal(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -257,5 +260,5 @@ resource "azurerm_lb" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_pool_test.go similarity index 81% rename from azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool_test.go rename to azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_pool_test.go index a0b086903bb9..fc3cab1156c0 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_nat_pool_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_pool_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -9,21 +9,22 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + nw "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" ) func TestAccAzureRMLoadBalancerNatPool_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_pool", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natPoolName := fmt.Sprintf("NatPool-%d", ri) + natPoolName := fmt.Sprintf("NatPool-%d", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") natPoolId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/inboundNatPools/%s", - subscriptionID, ri, ri, natPoolName) + subscriptionID, data.RandomInteger, data.RandomInteger, natPoolName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -31,7 +32,7 @@ func TestAccAzureRMLoadBalancerNatPool_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatPool_basic(ri, natPoolName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatPool_basic(data, natPoolName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatPoolExists(natPoolName, &lb), @@ -56,15 +57,15 @@ func TestAccAzureRMLoadBalancerNatPool_requiresImport(t *testing.T) { return } + data := acceptance.BuildTestData(t, "azurerm_lb_nat_pool", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natPoolName := fmt.Sprintf("NatPool-%d", ri) - location := acceptance.Location() + natPoolName := fmt.Sprintf("NatPool-%d", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") natPoolId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/inboundNatPools/%s", - subscriptionID, ri, ri, natPoolName) + subscriptionID, data.RandomInteger, data.RandomInteger, natPoolName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -72,7 +73,7 @@ func TestAccAzureRMLoadBalancerNatPool_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatPool_basic(ri, natPoolName, location), + Config: testAccAzureRMLoadBalancerNatPool_basic(data, natPoolName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatPoolExists(natPoolName, &lb), @@ -81,7 +82,7 @@ func TestAccAzureRMLoadBalancerNatPool_requiresImport(t *testing.T) { ), }, { - Config: testAccAzureRMLoadBalancerNatPool_requiresImport(ri, natPoolName, location), + Config: testAccAzureRMLoadBalancerNatPool_requiresImport(data, natPoolName), ExpectError: acceptance.RequiresImportError("azurerm_lb_nat_pool"), }, }, @@ -89,9 +90,10 @@ func TestAccAzureRMLoadBalancerNatPool_requiresImport(t *testing.T) { } func TestAccAzureRMLoadBalancerNatPool_removal(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_pool", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natPoolName := fmt.Sprintf("NatPool-%d", ri) + natPoolName := fmt.Sprintf("NatPool-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -99,14 +101,14 @@ func TestAccAzureRMLoadBalancerNatPool_removal(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatPool_basic(ri, natPoolName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatPool_basic(data, natPoolName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatPoolExists(natPoolName, &lb), ), }, { - Config: testAccAzureRMLoadBalancerNatPool_removal(ri, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatPool_removal(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatPoolNotExists(natPoolName, &lb), @@ -117,10 +119,12 @@ func TestAccAzureRMLoadBalancerNatPool_removal(t *testing.T) { } func TestAccAzureRMLoadBalancerNatPool_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_pool", "test") + data2 := acceptance.BuildTestData(t, "azurerm_lb_nat_pool", "test2") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natPoolName := fmt.Sprintf("NatPool-%d", ri) - natPool2Name := fmt.Sprintf("NatPool-%d", tf.AccRandTimeInt()) + natPoolName := fmt.Sprintf("NatPool-%d", data.RandomInteger) + natPool2Name := fmt.Sprintf("NatPool-%d", data2.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -128,7 +132,7 @@ func TestAccAzureRMLoadBalancerNatPool_update(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatPool_multiplePools(ri, natPoolName, natPool2Name, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatPool_multiplePools(data, natPoolName, natPool2Name), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatPoolExists(natPoolName, &lb), @@ -137,7 +141,7 @@ func TestAccAzureRMLoadBalancerNatPool_update(t *testing.T) { ), }, { - Config: testAccAzureRMLoadBalancerNatPool_multiplePoolsUpdate(ri, natPoolName, natPool2Name, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatPool_multiplePoolsUpdate(data, natPoolName, natPool2Name), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatPoolExists(natPoolName, &lb), @@ -150,9 +154,10 @@ func TestAccAzureRMLoadBalancerNatPool_update(t *testing.T) { } func TestAccAzureRMLoadBalancerNatPool_disappears(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_pool", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natPoolName := fmt.Sprintf("NatPool-%d", ri) + natPoolName := fmt.Sprintf("NatPool-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -160,7 +165,7 @@ func TestAccAzureRMLoadBalancerNatPool_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatPool_basic(ri, natPoolName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatPool_basic(data, natPoolName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatPoolExists(natPoolName, &lb), @@ -174,7 +179,7 @@ func TestAccAzureRMLoadBalancerNatPool_disappears(t *testing.T) { func testCheckAzureRMLoadBalancerNatPoolExists(natPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - _, _, exists := findLoadBalancerNatPoolByName(lb, natPoolName) + _, _, exists := nw.FindLoadBalancerNatPoolByName(lb, natPoolName) if !exists { return fmt.Errorf("A NAT Pool with name %q cannot be found.", natPoolName) } @@ -185,7 +190,7 @@ func testCheckAzureRMLoadBalancerNatPoolExists(natPoolName string, lb *network.L func testCheckAzureRMLoadBalancerNatPoolNotExists(natPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - _, _, exists := findLoadBalancerNatPoolByName(lb, natPoolName) + _, _, exists := nw.FindLoadBalancerNatPoolByName(lb, natPoolName) if exists { return fmt.Errorf("A NAT Pool with name %q has been found.", natPoolName) } @@ -199,7 +204,7 @@ func testCheckAzureRMLoadBalancerNatPoolDisappears(natPoolName string, lb *netwo client := acceptance.AzureProvider.Meta().(*clients.Client).Network.LoadBalancersClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - _, i, exists := findLoadBalancerNatPoolByName(lb, natPoolName) + _, i, exists := nw.FindLoadBalancerNatPoolByName(lb, natPoolName) if !exists { return fmt.Errorf("A Nat Pool with name %q cannot be found.", natPoolName) } @@ -227,7 +232,7 @@ func testCheckAzureRMLoadBalancerNatPoolDisappears(natPoolName string, lb *netwo } } -func testAccAzureRMLoadBalancerNatPool_basic(rInt int, natPoolName string, location string) string { +func testAccAzureRMLoadBalancerNatPool_basic(data acceptance.TestData, natPoolName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -263,11 +268,11 @@ resource "azurerm_lb_nat_pool" "test" { backend_port = 3389 frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, natPoolName, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, natPoolName, data.RandomInteger) } -func testAccAzureRMLoadBalancerNatPool_requiresImport(rInt int, name string, location string) string { - template := testAccAzureRMLoadBalancerNatPool_basic(rInt, name, location) +func testAccAzureRMLoadBalancerNatPool_requiresImport(data acceptance.TestData, name string) string { + template := testAccAzureRMLoadBalancerNatPool_basic(data, name) return fmt.Sprintf(` %s @@ -285,7 +290,7 @@ resource "azurerm_lb_nat_pool" "import" { `, template) } -func testAccAzureRMLoadBalancerNatPool_removal(rInt int, location string) string { +func testAccAzureRMLoadBalancerNatPool_removal(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -309,10 +314,10 @@ resource "azurerm_lb" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLoadBalancerNatPool_multiplePools(rInt int, natPoolName, natPool2Name string, location string) string { +func testAccAzureRMLoadBalancerNatPool_multiplePools(data acceptance.TestData, natPoolName, natPool2Name string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -363,10 +368,10 @@ resource "azurerm_lb_nat_pool" "test2" { frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, natPoolName, rInt, natPool2Name, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, natPoolName, data.RandomInteger, natPool2Name, data.RandomInteger) } -func testAccAzureRMLoadBalancerNatPool_multiplePoolsUpdate(rInt int, natPoolName, natPool2Name string, location string) string { +func testAccAzureRMLoadBalancerNatPool_multiplePoolsUpdate(data acceptance.TestData, natPoolName, natPool2Name string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -414,5 +419,5 @@ resource "azurerm_lb_nat_pool" "test2" { backend_port = 3391 frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, natPoolName, rInt, natPool2Name, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, natPoolName, data.RandomInteger, natPool2Name, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_rule_test.go similarity index 78% rename from azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule_test.go rename to azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_rule_test.go index 8a69f699b9c4..80e1bdae6f13 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_nat_rule_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_nat_rule_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -9,21 +9,22 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + nw "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" ) func TestAccAzureRMLoadBalancerNatRule_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natRuleName := fmt.Sprintf("NatRule-%d", ri) + natRuleName := fmt.Sprintf("NatRule-%d", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") natRuleId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/inboundNatRules/%s", - subscriptionID, ri, ri, natRuleName) + subscriptionID, data.RandomInteger, data.RandomInteger, natRuleName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -31,7 +32,7 @@ func TestAccAzureRMLoadBalancerNatRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatRule_basic(ri, natRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatRule_basic(data, natRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb), @@ -56,15 +57,15 @@ func TestAccAzureRMLoadBalancerNatRule_requiresImport(t *testing.T) { return } + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natRuleName := fmt.Sprintf("NatRule-%d", ri) - location := acceptance.Location() + natRuleName := fmt.Sprintf("NatRule-%d", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") natRuleId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/inboundNatRules/%s", - subscriptionID, ri, ri, natRuleName) + subscriptionID, data.RandomInteger, data.RandomInteger, natRuleName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -72,7 +73,7 @@ func TestAccAzureRMLoadBalancerNatRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatRule_basic(ri, natRuleName, location), + Config: testAccAzureRMLoadBalancerNatRule_basic(data, natRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb), @@ -81,7 +82,7 @@ func TestAccAzureRMLoadBalancerNatRule_requiresImport(t *testing.T) { ), }, { - Config: testAccAzureRMLoadBalancerNatRule_requiresImport(ri, natRuleName, location), + Config: testAccAzureRMLoadBalancerNatRule_requiresImport(data, natRuleName), ExpectError: acceptance.RequiresImportError("azurerm_lb_nat_rule"), }, }, @@ -89,9 +90,9 @@ func TestAccAzureRMLoadBalancerNatRule_requiresImport(t *testing.T) { } func TestAccAzureRMLoadBalancerNatRule_removal(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natRuleName := fmt.Sprintf("NatRule-%d", ri) + natRuleName := fmt.Sprintf("NatRule-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -99,14 +100,14 @@ func TestAccAzureRMLoadBalancerNatRule_removal(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatRule_basic(ri, natRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatRule_basic(data, natRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb), ), }, { - Config: testAccAzureRMLoadBalancerNatRule_removal(ri, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatRule_removal(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleNotExists(natRuleName, &lb), @@ -117,10 +118,11 @@ func TestAccAzureRMLoadBalancerNatRule_removal(t *testing.T) { } func TestAccAzureRMLoadBalancerNatRule_update(t *testing.T) { + data1 := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + data2 := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test2") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natRuleName := fmt.Sprintf("NatRule-%d", ri) - natRule2Name := fmt.Sprintf("NatRule-%d", tf.AccRandTimeInt()) + natRuleName := fmt.Sprintf("NatRule-%d", data1.RandomInteger) + natRule2Name := fmt.Sprintf("NatRule-%d", data2.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -128,23 +130,23 @@ func TestAccAzureRMLoadBalancerNatRule_update(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatRule_multipleRules(ri, natRuleName, natRule2Name, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatRule_multipleRules(data1, natRuleName, natRule2Name), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRule2Name, &lb), - resource.TestCheckResourceAttr("azurerm_lb_nat_rule.test2", "frontend_port", "3390"), - resource.TestCheckResourceAttr("azurerm_lb_nat_rule.test2", "backend_port", "3390"), + resource.TestCheckResourceAttr(data2.ResourceName, "frontend_port", "3390"), + resource.TestCheckResourceAttr(data2.ResourceName, "backend_port", "3390"), ), }, { - Config: testAccAzureRMLoadBalancerNatRule_multipleRulesUpdate(ri, natRuleName, natRule2Name, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatRule_multipleRulesUpdate(data1, natRuleName, natRule2Name), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRule2Name, &lb), - resource.TestCheckResourceAttr("azurerm_lb_nat_rule.test2", "frontend_port", "3391"), - resource.TestCheckResourceAttr("azurerm_lb_nat_rule.test2", "backend_port", "3391"), + resource.TestCheckResourceAttr(data2.ResourceName, "frontend_port", "3391"), + resource.TestCheckResourceAttr(data2.ResourceName, "backend_port", "3391"), ), }, }, @@ -152,9 +154,10 @@ func TestAccAzureRMLoadBalancerNatRule_update(t *testing.T) { } func TestAccAzureRMLoadBalancerNatRule_disappears(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natRuleName := fmt.Sprintf("NatRule-%d", ri) + natRuleName := fmt.Sprintf("NatRule-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -162,7 +165,7 @@ func TestAccAzureRMLoadBalancerNatRule_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatRule_basic(ri, natRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerNatRule_basic(data, natRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb), @@ -175,10 +178,10 @@ func TestAccAzureRMLoadBalancerNatRule_disappears(t *testing.T) { } func TestAccAzureRMLoadBalancerNatRule_enableFloatingIP(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natRuleName := fmt.Sprintf("NatRule-%d", ri) - location := acceptance.Location() + natRuleName := fmt.Sprintf("NatRule-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -186,7 +189,7 @@ func TestAccAzureRMLoadBalancerNatRule_enableFloatingIP(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatRule_enableFloatingIP(ri, natRuleName, location), + Config: testAccAzureRMLoadBalancerNatRule_enableFloatingIP(data, natRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb), @@ -197,10 +200,10 @@ func TestAccAzureRMLoadBalancerNatRule_enableFloatingIP(t *testing.T) { } func TestAccAzureRMLoadBalancerNatRule_disableFloatingIP(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - natRuleName := fmt.Sprintf("NatRule-%d", ri) - location := acceptance.Location() + natRuleName := fmt.Sprintf("NatRule-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -208,21 +211,21 @@ func TestAccAzureRMLoadBalancerNatRule_disableFloatingIP(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerNatRule_basic(ri, natRuleName, location), + Config: testAccAzureRMLoadBalancerNatRule_basic(data, natRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb), ), }, { - Config: testAccAzureRMLoadBalancerNatRule_enableFloatingIP(ri, natRuleName, location), + Config: testAccAzureRMLoadBalancerNatRule_enableFloatingIP(data, natRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb), ), }, { - Config: testAccAzureRMLoadBalancerNatRule_basic(ri, natRuleName, location), + Config: testAccAzureRMLoadBalancerNatRule_basic(data, natRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb), @@ -234,7 +237,7 @@ func TestAccAzureRMLoadBalancerNatRule_disableFloatingIP(t *testing.T) { func testCheckAzureRMLoadBalancerNatRuleExists(natRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - _, _, exists := findLoadBalancerNatRuleByName(lb, natRuleName) + _, _, exists := nw.FindLoadBalancerNatRuleByName(lb, natRuleName) if !exists { return fmt.Errorf("A NAT Rule with name %q cannot be found.", natRuleName) } @@ -245,7 +248,7 @@ func testCheckAzureRMLoadBalancerNatRuleExists(natRuleName string, lb *network.L func testCheckAzureRMLoadBalancerNatRuleNotExists(natRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - _, _, exists := findLoadBalancerNatRuleByName(lb, natRuleName) + _, _, exists := nw.FindLoadBalancerNatRuleByName(lb, natRuleName) if exists { return fmt.Errorf("A NAT Rule with name %q has been found.", natRuleName) } @@ -259,7 +262,7 @@ func testCheckAzureRMLoadBalancerNatRuleDisappears(natRuleName string, lb *netwo client := acceptance.AzureProvider.Meta().(*clients.Client).Network.LoadBalancersClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - _, i, exists := findLoadBalancerNatRuleByName(lb, natRuleName) + _, i, exists := nw.FindLoadBalancerNatRuleByName(lb, natRuleName) if !exists { return fmt.Errorf("A Nat Rule with name %q cannot be found.", natRuleName) } @@ -287,7 +290,7 @@ func testCheckAzureRMLoadBalancerNatRuleDisappears(natRuleName string, lb *netwo } } -func testAccAzureRMLoadBalancerNatRule_basic(rInt int, natRuleName string, location string) string { +func testAccAzureRMLoadBalancerNatRule_basic(data acceptance.TestData, natRuleName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -322,11 +325,11 @@ resource "azurerm_lb_nat_rule" "test" { backend_port = 3389 frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, natRuleName, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, natRuleName, data.RandomInteger) } -func testAccAzureRMLoadBalancerNatRule_requiresImport(rInt int, name string, location string) string { - template := testAccAzureRMLoadBalancerNatRule_basic(rInt, name, location) +func testAccAzureRMLoadBalancerNatRule_requiresImport(data acceptance.TestData, name string) string { + template := testAccAzureRMLoadBalancerNatRule_basic(data, name) return fmt.Sprintf(` %s @@ -343,7 +346,7 @@ resource "azurerm_lb_nat_rule" "import" { `, template) } -func testAccAzureRMLoadBalancerNatRule_removal(rInt int, location string) string { +func testAccAzureRMLoadBalancerNatRule_removal(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -367,10 +370,10 @@ resource "azurerm_lb" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLoadBalancerNatRule_multipleRules(rInt int, natRuleName, natRule2Name string, location string) string { +func testAccAzureRMLoadBalancerNatRule_multipleRules(data acceptance.TestData, natRuleName, natRule2Name string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -416,10 +419,10 @@ resource "azurerm_lb_nat_rule" "test2" { backend_port = 3390 frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, natRuleName, rInt, natRule2Name, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, natRuleName, data.RandomInteger, natRule2Name, data.RandomInteger) } -func testAccAzureRMLoadBalancerNatRule_multipleRulesUpdate(rInt int, natRuleName, natRule2Name string, location string) string { +func testAccAzureRMLoadBalancerNatRule_multipleRulesUpdate(data acceptance.TestData, natRuleName, natRule2Name string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -465,10 +468,10 @@ resource "azurerm_lb_nat_rule" "test2" { backend_port = 3391 frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, natRuleName, rInt, natRule2Name, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, natRuleName, data.RandomInteger, natRule2Name, data.RandomInteger) } -func testAccAzureRMLoadBalancerNatRule_enableFloatingIP(rInt int, natRuleName string, location string) string { +func testAccAzureRMLoadBalancerNatRule_enableFloatingIP(data acceptance.TestData, natRuleName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -503,5 +506,5 @@ resource "azurerm_lb_nat_rule" "test" { backend_port = 3389 frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, natRuleName, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, natRuleName, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_outbound_rule_test.go similarity index 80% rename from azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule_test.go rename to azurerm/internal/services/network/tests/resource_arm_loadbalancer_outbound_rule_test.go index 768ab96706f4..6dcdd638eb50 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_outbound_rule_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_outbound_rule_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -9,21 +9,22 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + nw "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" ) func TestAccAzureRMLoadBalancerOutboundRule_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - outboundRuleName := fmt.Sprintf("OutboundRule-%d", ri) + outboundRuleName := fmt.Sprintf("OutboundRule-%d", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") outboundRuleId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/outboundRules/%s", - subscriptionID, ri, ri, outboundRuleName) + subscriptionID, data.RandomInteger, data.RandomInteger, outboundRuleName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -31,7 +32,7 @@ func TestAccAzureRMLoadBalancerOutboundRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerOutboundRule_basic(ri, outboundRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerOutboundRule_basic(data, outboundRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRuleName, &lb), @@ -56,15 +57,15 @@ func TestAccAzureRMLoadBalancerOutboundRule_requiresImport(t *testing.T) { return } + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - outboundRuleName := fmt.Sprintf("OutboundRule-%d", ri) - location := acceptance.Location() + outboundRuleName := fmt.Sprintf("OutboundRule-%d", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") outboundRuleId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/outboundRules/%s", - subscriptionID, ri, ri, outboundRuleName) + subscriptionID, data.RandomInteger, data.RandomInteger, outboundRuleName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -72,7 +73,7 @@ func TestAccAzureRMLoadBalancerOutboundRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerOutboundRule_basic(ri, outboundRuleName, location), + Config: testAccAzureRMLoadBalancerOutboundRule_basic(data, outboundRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRuleName, &lb), @@ -81,7 +82,7 @@ func TestAccAzureRMLoadBalancerOutboundRule_requiresImport(t *testing.T) { ), }, { - Config: testAccAzureRMLoadBalancerOutboundRule_requiresImport(ri, outboundRuleName, location), + Config: testAccAzureRMLoadBalancerOutboundRule_requiresImport(data, outboundRuleName), ExpectError: acceptance.RequiresImportError("azurerm_lb_outbound_rule"), }, }, @@ -89,9 +90,10 @@ func TestAccAzureRMLoadBalancerOutboundRule_requiresImport(t *testing.T) { } func TestAccAzureRMLoadBalancerOutboundRule_removal(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - outboundRuleName := fmt.Sprintf("OutboundRule-%d", ri) + outboundRuleName := fmt.Sprintf("OutboundRule-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -99,14 +101,14 @@ func TestAccAzureRMLoadBalancerOutboundRule_removal(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerOutboundRule_basic(ri, outboundRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerOutboundRule_basic(data, outboundRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRuleName, &lb), ), }, { - Config: testAccAzureRMLoadBalancerOutboundRule_removal(ri, acceptance.Location()), + Config: testAccAzureRMLoadBalancerOutboundRule_removal(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerOutboundRuleNotExists(outboundRuleName, &lb), @@ -117,10 +119,12 @@ func TestAccAzureRMLoadBalancerOutboundRule_removal(t *testing.T) { } func TestAccAzureRMLoadBalancerOutboundRule_update(t *testing.T) { + data1 := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + data2 := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test2") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - outboundRuleName := fmt.Sprintf("OutboundRule-%d", ri) - outboundRule2Name := fmt.Sprintf("OutboundRule-%d", tf.AccRandTimeInt()) + outboundRuleName := fmt.Sprintf("OutboundRule-%d", data1.RandomInteger) + outboundRule2Name := fmt.Sprintf("OutboundRule-%d", data2.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -128,21 +132,21 @@ func TestAccAzureRMLoadBalancerOutboundRule_update(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerOutboundRule_multipleRules(ri, outboundRuleName, outboundRule2Name, acceptance.Location()), + Config: testAccAzureRMLoadBalancerOutboundRule_multipleRules(data1, outboundRuleName, outboundRule2Name), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRuleName, &lb), testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRule2Name, &lb), - resource.TestCheckResourceAttr("azurerm_lb_outbound_rule.test2", "protocol", "Udp"), + resource.TestCheckResourceAttr(data2.ResourceName, "protocol", "Udp"), ), }, { - Config: testAccAzureRMLoadBalancerOutboundRule_multipleRulesUpdate(ri, outboundRuleName, outboundRule2Name, acceptance.Location()), + Config: testAccAzureRMLoadBalancerOutboundRule_multipleRulesUpdate(data1, outboundRuleName, outboundRule2Name), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRuleName, &lb), testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRule2Name, &lb), - resource.TestCheckResourceAttr("azurerm_lb_outbound_rule.test2", "protocol", "All"), + resource.TestCheckResourceAttr(data2.ResourceName, "protocol", "All"), ), }, }, @@ -150,14 +154,15 @@ func TestAccAzureRMLoadBalancerOutboundRule_update(t *testing.T) { } func TestAccAzureRMLoadBalancerOutboundRule_withPublicIPPrefix(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - outboundRuleName := fmt.Sprintf("OutboundRule-%d", ri) + outboundRuleName := fmt.Sprintf("OutboundRule-%d", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") outboundRuleId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/outboundRules/%s", - subscriptionID, ri, ri, outboundRuleName) + subscriptionID, data.RandomInteger, data.RandomInteger, outboundRuleName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -165,7 +170,7 @@ func TestAccAzureRMLoadBalancerOutboundRule_withPublicIPPrefix(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerOutboundRule_withPublicIPPrefix(ri, outboundRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerOutboundRule_withPublicIPPrefix(data, outboundRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRuleName, &lb), @@ -185,9 +190,10 @@ func TestAccAzureRMLoadBalancerOutboundRule_withPublicIPPrefix(t *testing.T) { } func TestAccAzureRMLoadBalancerOutboundRule_disappears(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_nat_rule", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - outboundRuleName := fmt.Sprintf("OutboundRule-%d", ri) + outboundRuleName := fmt.Sprintf("OutboundRule-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -195,7 +201,7 @@ func TestAccAzureRMLoadBalancerOutboundRule_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerOutboundRule_basic(ri, outboundRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerOutboundRule_basic(data, outboundRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRuleName, &lb), @@ -209,7 +215,7 @@ func TestAccAzureRMLoadBalancerOutboundRule_disappears(t *testing.T) { func testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - if _, _, exists := findLoadBalancerOutboundRuleByName(lb, outboundRuleName); !exists { + if _, _, exists := nw.FindLoadBalancerOutboundRuleByName(lb, outboundRuleName); !exists { return fmt.Errorf("A Load Balancer Outbound Rule with name %q cannot be found.", outboundRuleName) } @@ -219,7 +225,7 @@ func testCheckAzureRMLoadBalancerOutboundRuleExists(outboundRuleName string, lb func testCheckAzureRMLoadBalancerOutboundRuleNotExists(outboundRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - if _, _, exists := findLoadBalancerOutboundRuleByName(lb, outboundRuleName); exists { + if _, _, exists := nw.FindLoadBalancerOutboundRuleByName(lb, outboundRuleName); exists { return fmt.Errorf("A Load Balancer Outbound Rule with name %q has been found.", outboundRuleName) } @@ -232,7 +238,7 @@ func testCheckAzureRMLoadBalancerOutboundRuleDisappears(ruleName string, lb *net client := acceptance.AzureProvider.Meta().(*clients.Client).Network.LoadBalancersClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - _, i, exists := findLoadBalancerOutboundRuleByName(lb, ruleName) + _, i, exists := nw.FindLoadBalancerOutboundRuleByName(lb, ruleName) if !exists { return fmt.Errorf("A Outbound Rule with name %q cannot be found.", ruleName) } @@ -260,7 +266,7 @@ func testCheckAzureRMLoadBalancerOutboundRuleDisappears(ruleName string, lb *net } } -func testAccAzureRMLoadBalancerOutboundRule_basic(rInt int, outboundRuleName string, location string) string { +func testAccAzureRMLoadBalancerOutboundRule_basic(data acceptance.TestData, outboundRuleName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -304,11 +310,11 @@ resource "azurerm_lb_outbound_rule" "test" { name = "one-%d" } } -`, rInt, location, rInt, rInt, rInt, rInt, outboundRuleName, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, outboundRuleName, data.RandomInteger) } -func testAccAzureRMLoadBalancerOutboundRule_requiresImport(rInt int, name string, location string) string { - template := testAccAzureRMLoadBalancerOutboundRule_basic(rInt, name, location) +func testAccAzureRMLoadBalancerOutboundRule_requiresImport(data acceptance.TestData, name string) string { + template := testAccAzureRMLoadBalancerOutboundRule_basic(data, name) return fmt.Sprintf(` %s @@ -326,7 +332,7 @@ resource "azurerm_lb_outbound_rule" "import" { `, template) } -func testAccAzureRMLoadBalancerOutboundRule_removal(rInt int, location string) string { +func testAccAzureRMLoadBalancerOutboundRule_removal(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -358,10 +364,10 @@ resource "azurerm_lb" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLoadBalancerOutboundRule_multipleRules(rInt int, outboundRuleName, outboundRule2Name string, location string) string { +func testAccAzureRMLoadBalancerOutboundRule_multipleRules(data acceptance.TestData, outboundRuleName, outboundRule2Name string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -430,10 +436,10 @@ resource "azurerm_lb_outbound_rule" "test2" { name = "fe2-%d" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, outboundRuleName, rInt, outboundRule2Name, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, outboundRuleName, data.RandomInteger, outboundRule2Name, data.RandomInteger) } -func testAccAzureRMLoadBalancerOutboundRule_multipleRulesUpdate(rInt int, outboundRuleName, outboundRule2Name string, location string) string { +func testAccAzureRMLoadBalancerOutboundRule_multipleRulesUpdate(data acceptance.TestData, outboundRuleName, outboundRule2Name string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -502,10 +508,10 @@ resource "azurerm_lb_outbound_rule" "test2" { name = "fe2-%d" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, outboundRuleName, rInt, outboundRule2Name, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, outboundRuleName, data.RandomInteger, outboundRule2Name, data.RandomInteger) } -func testAccAzureRMLoadBalancerOutboundRule_withPublicIPPrefix(rInt int, outboundRuleName string, location string) string { +func testAccAzureRMLoadBalancerOutboundRule_withPublicIPPrefix(data acceptance.TestData, outboundRuleName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -548,5 +554,5 @@ resource "azurerm_lb_outbound_rule" "test" { name = "one-%d" } } -`, rInt, location, rInt, rInt, rInt, rInt, outboundRuleName, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, outboundRuleName, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_probe_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_probe_test.go similarity index 80% rename from azurerm/internal/services/network/resource_arm_loadbalancer_probe_test.go rename to azurerm/internal/services/network/tests/resource_arm_loadbalancer_probe_test.go index ecc72b2cce9a..bbc310957bcb 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_probe_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_probe_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -9,21 +9,22 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + nw "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" ) func TestAccAzureRMLoadBalancerProbe_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_probe", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - probeName := fmt.Sprintf("probe-%d", ri) + probeName := fmt.Sprintf("probe-%d", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") probeId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/probes/%s", - subscriptionID, ri, ri, probeName) + subscriptionID, data.RandomInteger, data.RandomInteger, probeName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -31,7 +32,7 @@ func TestAccAzureRMLoadBalancerProbe_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerProbe_basic(ri, probeName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerProbe_basic(data, probeName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerProbeExists(probeName, &lb), @@ -56,15 +57,15 @@ func TestAccAzureRMLoadBalancerProbe_requiresImport(t *testing.T) { return } + data := acceptance.BuildTestData(t, "azurerm_lb_probe", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - probeName := fmt.Sprintf("probe-%d", ri) - location := acceptance.Location() + probeName := fmt.Sprintf("probe-%d", data.RandomInteger) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") probeId := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/probes/%s", - subscriptionID, ri, ri, probeName) + subscriptionID, data.RandomInteger, data.RandomInteger, probeName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -72,7 +73,7 @@ func TestAccAzureRMLoadBalancerProbe_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerProbe_basic(ri, probeName, location), + Config: testAccAzureRMLoadBalancerProbe_basic(data, probeName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerProbeExists(probeName, &lb), @@ -81,7 +82,7 @@ func TestAccAzureRMLoadBalancerProbe_requiresImport(t *testing.T) { ), }, { - Config: testAccAzureRMLoadBalancerProbe_requiresImport(ri, probeName, location), + Config: testAccAzureRMLoadBalancerProbe_requiresImport(data, probeName), ExpectError: acceptance.RequiresImportError("azurerm_lb_probe"), }, }, @@ -89,10 +90,10 @@ func TestAccAzureRMLoadBalancerProbe_requiresImport(t *testing.T) { } func TestAccAzureRMLoadBalancerProbe_removal(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_probe", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - probeName := fmt.Sprintf("probe-%d", ri) - location := acceptance.Location() + probeName := fmt.Sprintf("probe-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -100,14 +101,14 @@ func TestAccAzureRMLoadBalancerProbe_removal(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerProbe_basic(ri, probeName, location), + Config: testAccAzureRMLoadBalancerProbe_basic(data, probeName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerProbeExists(probeName, &lb), ), }, { - Config: testAccAzureRMLoadBalancerProbe_removal(ri, location), + Config: testAccAzureRMLoadBalancerProbe_removal(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerProbeNotExists(probeName, &lb), @@ -118,10 +119,12 @@ func TestAccAzureRMLoadBalancerProbe_removal(t *testing.T) { } func TestAccAzureRMLoadBalancerProbe_update(t *testing.T) { + data1 := acceptance.BuildTestData(t, "azurerm_lb_probe", "test") + data2 := acceptance.BuildTestData(t, "azurerm_lb_probe", "test2") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - probeName := fmt.Sprintf("probe-%d", ri) - probe2Name := fmt.Sprintf("probe-%d", tf.AccRandTimeInt()) + probeName := fmt.Sprintf("probe-%d", data1.RandomInteger) + probe2Name := fmt.Sprintf("probe-%d", data2.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -129,21 +132,21 @@ func TestAccAzureRMLoadBalancerProbe_update(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerProbe_multipleProbes(ri, probeName, probe2Name, acceptance.Location()), + Config: testAccAzureRMLoadBalancerProbe_multipleProbes(data1, probeName, probe2Name), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerProbeExists(probeName, &lb), testCheckAzureRMLoadBalancerProbeExists(probe2Name, &lb), - resource.TestCheckResourceAttr("azurerm_lb_probe.test2", "port", "80"), + resource.TestCheckResourceAttr(data2.ResourceName, "port", "80"), ), }, { - Config: testAccAzureRMLoadBalancerProbe_multipleProbesUpdate(ri, probeName, probe2Name, acceptance.Location()), + Config: testAccAzureRMLoadBalancerProbe_multipleProbesUpdate(data1, probeName, probe2Name), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerProbeExists(probeName, &lb), testCheckAzureRMLoadBalancerProbeExists(probe2Name, &lb), - resource.TestCheckResourceAttr("azurerm_lb_probe.test2", "port", "8080"), + resource.TestCheckResourceAttr(data2.ResourceName, "port", "8080"), ), }, }, @@ -151,9 +154,10 @@ func TestAccAzureRMLoadBalancerProbe_update(t *testing.T) { } func TestAccAzureRMLoadBalancerProbe_updateProtocol(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_probe", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - probeName := fmt.Sprintf("probe-%d", ri) + probeName := fmt.Sprintf("probe-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -161,7 +165,7 @@ func TestAccAzureRMLoadBalancerProbe_updateProtocol(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerProbe_updateProtocolBefore(ri, probeName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerProbe_updateProtocolBefore(data, probeName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerProbeExists(probeName, &lb), @@ -169,7 +173,7 @@ func TestAccAzureRMLoadBalancerProbe_updateProtocol(t *testing.T) { ), }, { - Config: testAccAzureRMLoadBalancerProbe_updateProtocolAfter(ri, probeName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerProbe_updateProtocolAfter(data, probeName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerProbeExists(probeName, &lb), @@ -181,9 +185,10 @@ func TestAccAzureRMLoadBalancerProbe_updateProtocol(t *testing.T) { } func TestAccAzureRMLoadBalancerProbe_disappears(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb_probe", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - probeName := fmt.Sprintf("probe-%d", ri) + probeName := fmt.Sprintf("probe-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -191,7 +196,7 @@ func TestAccAzureRMLoadBalancerProbe_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerProbe_basic(ri, probeName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerProbe_basic(data, probeName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerProbeExists(probeName, &lb), @@ -205,7 +210,7 @@ func TestAccAzureRMLoadBalancerProbe_disappears(t *testing.T) { func testCheckAzureRMLoadBalancerProbeExists(natRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - _, _, exists := findLoadBalancerProbeByName(lb, natRuleName) + _, _, exists := nw.FindLoadBalancerProbeByName(lb, natRuleName) if !exists { return fmt.Errorf("A Probe with name %q cannot be found.", natRuleName) } @@ -216,7 +221,7 @@ func testCheckAzureRMLoadBalancerProbeExists(natRuleName string, lb *network.Loa func testCheckAzureRMLoadBalancerProbeNotExists(natRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - _, _, exists := findLoadBalancerProbeByName(lb, natRuleName) + _, _, exists := nw.FindLoadBalancerProbeByName(lb, natRuleName) if exists { return fmt.Errorf("A Probe with name %q has been found.", natRuleName) } @@ -230,7 +235,7 @@ func testCheckAzureRMLoadBalancerProbeDisappears(addressPoolName string, lb *net client := acceptance.AzureProvider.Meta().(*clients.Client).Network.LoadBalancersClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - _, i, exists := findLoadBalancerProbeByName(lb, addressPoolName) + _, i, exists := nw.FindLoadBalancerProbeByName(lb, addressPoolName) if !exists { return fmt.Errorf("A Probe with name %q cannot be found.", addressPoolName) } @@ -258,7 +263,7 @@ func testCheckAzureRMLoadBalancerProbeDisappears(addressPoolName string, lb *net } } -func testAccAzureRMLoadBalancerProbe_basic(rInt int, probeName string, location string) string { +func testAccAzureRMLoadBalancerProbe_basic(data acceptance.TestData, probeName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -290,11 +295,11 @@ resource "azurerm_lb_probe" "test" { name = "%s" port = 22 } -`, rInt, location, rInt, rInt, rInt, probeName) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, probeName) } -func testAccAzureRMLoadBalancerProbe_requiresImport(rInt int, name string, location string) string { - template := testAccAzureRMLoadBalancerProbe_basic(rInt, name, location) +func testAccAzureRMLoadBalancerProbe_requiresImport(data acceptance.TestData, name string) string { + template := testAccAzureRMLoadBalancerProbe_basic(data, name) return fmt.Sprintf(` %s @@ -308,7 +313,7 @@ resource "azurerm_lb_probe" "import" { `, template) } -func testAccAzureRMLoadBalancerProbe_removal(rInt int, location string) string { +func testAccAzureRMLoadBalancerProbe_removal(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -332,10 +337,10 @@ resource "azurerm_lb" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLoadBalancerProbe_multipleProbes(rInt int, probeName, probe2Name string, location string) string { +func testAccAzureRMLoadBalancerProbe_multipleProbes(data acceptance.TestData, probeName, probe2Name string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -375,10 +380,10 @@ resource "azurerm_lb_probe" "test2" { name = "%s" port = 80 } -`, rInt, location, rInt, rInt, rInt, probeName, probe2Name) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, probeName, probe2Name) } -func testAccAzureRMLoadBalancerProbe_multipleProbesUpdate(rInt int, probeName, probe2Name string, location string) string { +func testAccAzureRMLoadBalancerProbe_multipleProbesUpdate(data acceptance.TestData, probeName, probe2Name string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -418,10 +423,10 @@ resource "azurerm_lb_probe" "test2" { name = "%s" port = 8080 } -`, rInt, location, rInt, rInt, rInt, probeName, probe2Name) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, probeName, probe2Name) } -func testAccAzureRMLoadBalancerProbe_updateProtocolBefore(rInt int, probeName string, location string) string { +func testAccAzureRMLoadBalancerProbe_updateProtocolBefore(data acceptance.TestData, probeName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -455,10 +460,10 @@ resource "azurerm_lb_probe" "test" { request_path = "/" port = 80 } -`, rInt, location, rInt, rInt, rInt, probeName) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, probeName) } -func testAccAzureRMLoadBalancerProbe_updateProtocolAfter(rInt int, probeName string, location string) string { +func testAccAzureRMLoadBalancerProbe_updateProtocolAfter(data acceptance.TestData, probeName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -491,5 +496,5 @@ resource "azurerm_lb_probe" "test" { protocol = "Tcp" port = 80 } -`, rInt, location, rInt, rInt, rInt, probeName) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, probeName) } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_rule_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_rule_test.go similarity index 84% rename from azurerm/internal/services/network/resource_arm_loadbalancer_rule_test.go rename to azurerm/internal/services/network/tests/resource_arm_loadbalancer_rule_test.go index dd666642a1ec..8acd92fbe1f0 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_rule_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_rule_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -10,10 +10,10 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + nw "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" ) func TestResourceAzureRMLoadBalancerRuleNameLabel_validation(t *testing.T) { @@ -64,7 +64,7 @@ func TestResourceAzureRMLoadBalancerRuleNameLabel_validation(t *testing.T) { } for _, tc := range cases { - _, errors := validateArmLoadBalancerRuleName(tc.Value, "azurerm_lb_rule") + _, errors := nw.ValidateArmLoadBalancerRuleName(tc.Value, "azurerm_lb_rule") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Azure RM Load Balancer Rule Name Label to trigger a validation error") @@ -73,14 +73,14 @@ func TestResourceAzureRMLoadBalancerRuleNameLabel_validation(t *testing.T) { } func TestAccAzureRMLoadBalancerRule_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb", "test") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() lbRuleName := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") lbRule_id := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/loadBalancingRules/%s", - subscriptionID, ri, ri, lbRuleName) + subscriptionID, data.RandomInteger, data.RandomInteger, lbRuleName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -88,7 +88,7 @@ func TestAccAzureRMLoadBalancerRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerRule_basic(ri, lbRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerRule_basic(data, lbRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerRuleExists(lbRuleName, &lb), @@ -108,14 +108,14 @@ func TestAccAzureRMLoadBalancerRule_basic(t *testing.T) { } func TestAccAzureRMLoadBalancerRule_disableoutboundsnat(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb", "test") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() lbRuleName := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") lbRule_id := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/loadBalancingRules/%s", - subscriptionID, ri, ri, lbRuleName) + subscriptionID, data.RandomInteger, data.RandomInteger, lbRuleName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -123,7 +123,7 @@ func TestAccAzureRMLoadBalancerRule_disableoutboundsnat(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerRule_disableoutboundsnat(ri, lbRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerRule_disableoutboundsnat(data, lbRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerRuleExists(lbRuleName, &lb), @@ -148,15 +148,15 @@ func TestAccAzureRMLoadBalancerRule_requiresImport(t *testing.T) { return } + data := acceptance.BuildTestData(t, "azurerm_lb", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() lbRuleName := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)) - location := acceptance.Location() subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") lbRule_id := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/loadBalancingRules/%s", - subscriptionID, ri, ri, lbRuleName) + subscriptionID, data.RandomInteger, data.RandomInteger, lbRuleName) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -164,7 +164,7 @@ func TestAccAzureRMLoadBalancerRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerRule_basic(ri, lbRuleName, location), + Config: testAccAzureRMLoadBalancerRule_basic(data, lbRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerRuleExists(lbRuleName, &lb), @@ -173,7 +173,7 @@ func TestAccAzureRMLoadBalancerRule_requiresImport(t *testing.T) { ), }, { - Config: testAccAzureRMLoadBalancerRule_requiresImport(ri, lbRuleName, location), + Config: testAccAzureRMLoadBalancerRule_requiresImport(data, lbRuleName), ExpectError: acceptance.RequiresImportError("azurerm_lb_rule"), }, }, @@ -181,8 +181,8 @@ func TestAccAzureRMLoadBalancerRule_requiresImport(t *testing.T) { } func TestAccAzureRMLoadBalancerRule_removal(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb", "test") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() lbRuleName := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)) resource.ParallelTest(t, resource.TestCase{ @@ -191,14 +191,14 @@ func TestAccAzureRMLoadBalancerRule_removal(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerRule_basic(ri, lbRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerRule_basic(data, lbRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerRuleExists(lbRuleName, &lb), ), }, { - Config: testAccAzureRMLoadBalancerRule_removal(ri, acceptance.Location()), + Config: testAccAzureRMLoadBalancerRule_removal(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerRuleNotExists(lbRuleName, &lb), @@ -210,8 +210,8 @@ func TestAccAzureRMLoadBalancerRule_removal(t *testing.T) { // https://github.com/hashicorp/terraform/issues/9424 func TestAccAzureRMLoadBalancerRule_inconsistentReads(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb", "test") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() backendPoolName := fmt.Sprintf("LbPool-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)) lbRuleName := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)) probeName := fmt.Sprintf("LbProbe-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)) @@ -222,7 +222,7 @@ func TestAccAzureRMLoadBalancerRule_inconsistentReads(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerRule_inconsistentRead(ri, backendPoolName, probeName, lbRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerRule_inconsistentRead(data, backendPoolName, probeName, lbRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerBackEndAddressPoolExists(backendPoolName, &lb), @@ -235,19 +235,20 @@ func TestAccAzureRMLoadBalancerRule_inconsistentReads(t *testing.T) { } func TestAccAzureRMLoadBalancerRule_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() lbRuleName := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)) lbRule2Name := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)) subscriptionID := os.Getenv("ARM_SUBSCRIPTION_ID") lbRuleID := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/loadBalancingRules/%s", - subscriptionID, ri, ri, lbRuleName) + subscriptionID, data.RandomInteger, data.RandomInteger, lbRuleName) lbRule2ID := fmt.Sprintf( "/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/loadBalancers/arm-test-loadbalancer-%d/loadBalancingRules/%s", - subscriptionID, ri, ri, lbRule2Name) + subscriptionID, data.RandomInteger, data.RandomInteger, lbRule2Name) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -255,7 +256,7 @@ func TestAccAzureRMLoadBalancerRule_update(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerRule_multipleRules(ri, lbRuleName, lbRule2Name, acceptance.Location()), + Config: testAccAzureRMLoadBalancerRule_multipleRules(data, lbRuleName, lbRule2Name), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerRuleExists(lbRuleName, &lb), @@ -267,7 +268,7 @@ func TestAccAzureRMLoadBalancerRule_update(t *testing.T) { ), }, { - Config: testAccAzureRMLoadBalancerRule_multipleRulesUpdate(ri, lbRuleName, lbRule2Name, acceptance.Location()), + Config: testAccAzureRMLoadBalancerRule_multipleRulesUpdate(data, lbRuleName, lbRule2Name), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerRuleExists(lbRuleName, &lb), @@ -283,8 +284,9 @@ func TestAccAzureRMLoadBalancerRule_update(t *testing.T) { } func TestAccAzureRMLoadBalancerRule_disappears(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb", "test") + var lb network.LoadBalancer - ri := tf.AccRandTimeInt() lbRuleName := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)) resource.ParallelTest(t, resource.TestCase{ @@ -293,7 +295,7 @@ func TestAccAzureRMLoadBalancerRule_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancerRule_basic(ri, lbRuleName, acceptance.Location()), + Config: testAccAzureRMLoadBalancerRule_basic(data, lbRuleName), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), testCheckAzureRMLoadBalancerRuleExists(lbRuleName, &lb), @@ -307,7 +309,7 @@ func TestAccAzureRMLoadBalancerRule_disappears(t *testing.T) { func testCheckAzureRMLoadBalancerRuleExists(lbRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - _, _, exists := findLoadBalancerRuleByName(lb, lbRuleName) + _, _, exists := nw.FindLoadBalancerRuleByName(lb, lbRuleName) if !exists { return fmt.Errorf("A Load Balancer Rule with name %q cannot be found.", lbRuleName) } @@ -318,7 +320,7 @@ func testCheckAzureRMLoadBalancerRuleExists(lbRuleName string, lb *network.LoadB func testCheckAzureRMLoadBalancerRuleNotExists(lbRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc { return func(s *terraform.State) error { - _, _, exists := findLoadBalancerRuleByName(lb, lbRuleName) + _, _, exists := nw.FindLoadBalancerRuleByName(lb, lbRuleName) if exists { return fmt.Errorf("A Load Balancer Rule with name %q has been found.", lbRuleName) } @@ -332,7 +334,7 @@ func testCheckAzureRMLoadBalancerRuleDisappears(ruleName string, lb *network.Loa client := acceptance.AzureProvider.Meta().(*clients.Client).Network.LoadBalancersClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - _, i, exists := findLoadBalancerRuleByName(lb, ruleName) + _, i, exists := nw.FindLoadBalancerRuleByName(lb, ruleName) if !exists { return fmt.Errorf("A Rule with name %q cannot be found.", ruleName) } @@ -360,7 +362,7 @@ func testCheckAzureRMLoadBalancerRuleDisappears(ruleName string, lb *network.Loa } } -func testAccAzureRMLoadBalancerRule_basic(rInt int, lbRuleName string, location string) string { +func testAccAzureRMLoadBalancerRule_basic(data acceptance.TestData, lbRuleName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -395,10 +397,10 @@ resource "azurerm_lb_rule" "test" { backend_port = 3389 frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, lbRuleName, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, lbRuleName, data.RandomInteger) } -func testAccAzureRMLoadBalancerRule_disableoutboundsnat(rInt int, lbRuleName string, location string) string { +func testAccAzureRMLoadBalancerRule_disableoutboundsnat(data acceptance.TestData, lbRuleName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -436,11 +438,11 @@ resource "azurerm_lb_rule" "test" { frontend_ip_configuration_name = "one-%d" disable_outbound_snat = true } -`, rInt, location, rInt, rInt, rInt, lbRuleName, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, lbRuleName, data.RandomInteger) } -func testAccAzureRMLoadBalancerRule_requiresImport(rInt int, name string, location string) string { - template := testAccAzureRMLoadBalancerRule_basic(rInt, name, location) +func testAccAzureRMLoadBalancerRule_requiresImport(data acceptance.TestData, name string) string { + template := testAccAzureRMLoadBalancerRule_basic(data, name) return fmt.Sprintf(` %s @@ -457,7 +459,7 @@ resource "azurerm_lb_rule" "import" { `, template) } -func testAccAzureRMLoadBalancerRule_removal(rInt int, location string) string { +func testAccAzureRMLoadBalancerRule_removal(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -481,11 +483,11 @@ resource "azurerm_lb" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } // https://github.com/hashicorp/terraform/issues/9424 -func testAccAzureRMLoadBalancerRule_inconsistentRead(rInt int, backendPoolName, probeName, lbRuleName string, location string) string { +func testAccAzureRMLoadBalancerRule_inconsistentRead(data acceptance.TestData, backendPoolName, probeName, lbRuleName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -536,10 +538,10 @@ resource "azurerm_lb_rule" "test" { backend_port = 3389 frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, backendPoolName, probeName, lbRuleName, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, backendPoolName, probeName, lbRuleName, data.RandomInteger) } -func testAccAzureRMLoadBalancerRule_multipleRules(rInt int, lbRuleName, lbRule2Name string, location string) string { +func testAccAzureRMLoadBalancerRule_multipleRules(data acceptance.TestData, lbRuleName, lbRule2Name string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -585,10 +587,10 @@ resource "azurerm_lb_rule" "test2" { backend_port = 3390 frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, lbRuleName, rInt, lbRule2Name, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, lbRuleName, data.RandomInteger, lbRule2Name, data.RandomInteger) } -func testAccAzureRMLoadBalancerRule_multipleRulesUpdate(rInt int, lbRuleName, lbRule2Name string, location string) string { +func testAccAzureRMLoadBalancerRule_multipleRulesUpdate(data acceptance.TestData, lbRuleName, lbRule2Name string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -634,5 +636,5 @@ resource "azurerm_lb_rule" "test2" { backend_port = 3391 frontend_ip_configuration_name = "one-%d" } -`, rInt, location, rInt, rInt, rInt, lbRuleName, rInt, lbRule2Name, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, lbRuleName, data.RandomInteger, lbRule2Name, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_loadbalancer_test.go b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_test.go similarity index 73% rename from azurerm/internal/services/network/resource_arm_loadbalancer_test.go rename to azurerm/internal/services/network/tests/resource_arm_loadbalancer_test.go index 4a422608348b..578edab241ef 100644 --- a/azurerm/internal/services/network/resource_arm_loadbalancer_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_loadbalancer_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -8,51 +8,14 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) -func TestResourceAzureRMLoadBalancerPrivateIpAddressAllocation_validation(t *testing.T) { - cases := []struct { - Value string - ErrCount int - }{ - { - Value: "Random", - ErrCount: 1, - }, - { - Value: "Static", - ErrCount: 0, - }, - { - Value: "Dynamic", - ErrCount: 0, - }, - { - Value: "STATIC", - ErrCount: 0, - }, - { - Value: "static", - ErrCount: 0, - }, - } - - for _, tc := range cases { - _, errors := validateLoadBalancerPrivateIpAddressAllocation(tc.Value, "azurerm_lb") - - if len(errors) != tc.ErrCount { - t.Fatalf("Expected the Azure RM Load Balancer private_ip_address_allocation to trigger a validation error") - } - } -} - func TestAccAzureRMLoadBalancer_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb", "test") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -60,7 +23,7 @@ func TestAccAzureRMLoadBalancer_basic(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_basic(ri, acceptance.Location()), + Config: testAccAzureRMLoadBalancer_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), ), @@ -80,9 +43,8 @@ func TestAccAzureRMLoadBalancer_requiresImport(t *testing.T) { return } + data := acceptance.BuildTestData(t, "azurerm_lb", "test") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -90,13 +52,13 @@ func TestAccAzureRMLoadBalancer_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_basic(ri, location), + Config: testAccAzureRMLoadBalancer_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), ), }, { - Config: testAccAzureRMLoadBalancer_requiresImport(ri, location), + Config: testAccAzureRMLoadBalancer_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_lb"), }, }, @@ -104,8 +66,8 @@ func TestAccAzureRMLoadBalancer_requiresImport(t *testing.T) { } func TestAccAzureRMLoadBalancer_standard(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb", "test") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,7 +75,7 @@ func TestAccAzureRMLoadBalancer_standard(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_standard(ri, acceptance.Location()), + Config: testAccAzureRMLoadBalancer_standard(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb), ), @@ -127,10 +89,8 @@ func TestAccAzureRMLoadBalancer_standard(t *testing.T) { }) } func TestAccAzureRMLoadBalancer_frontEndConfigPublicIPPrefix(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb", "test") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() - location := acceptance.Location() - resourceName := "azurerm_lb.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -138,10 +98,10 @@ func TestAccAzureRMLoadBalancer_frontEndConfigPublicIPPrefix(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_frontEndConfigPublicIPPrefix(ri, location), + Config: testAccAzureRMLoadBalancer_frontEndConfigPublicIPPrefix(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), - resource.TestCheckResourceAttr(resourceName, "frontend_ip_configuration.#", "1"), + testCheckAzureRMLoadBalancerExists(data.ResourceName, &lb), + resource.TestCheckResourceAttr(data.ResourceName, "frontend_ip_configuration.#", "1"), ), }, { @@ -154,9 +114,7 @@ func TestAccAzureRMLoadBalancer_frontEndConfigPublicIPPrefix(t *testing.T) { } func TestAccAzureRMLoadBalancer_frontEndConfig(t *testing.T) { var lb network.LoadBalancer - resourceName := "azurerm_lb.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_lb", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -164,29 +122,25 @@ func TestAccAzureRMLoadBalancer_frontEndConfig(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_frontEndConfig(ri, location), + Config: testAccAzureRMLoadBalancer_frontEndConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), - resource.TestCheckResourceAttr(resourceName, "frontend_ip_configuration.#", "2"), + testCheckAzureRMLoadBalancerExists(data.ResourceName, &lb), + resource.TestCheckResourceAttr(data.ResourceName, "frontend_ip_configuration.#", "2"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMLoadBalancer_frontEndConfigRemovalWithIP(ri, location), + Config: testAccAzureRMLoadBalancer_frontEndConfigRemovalWithIP(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), - resource.TestCheckResourceAttr(resourceName, "frontend_ip_configuration.#", "1"), + testCheckAzureRMLoadBalancerExists(data.ResourceName, &lb), + resource.TestCheckResourceAttr(data.ResourceName, "frontend_ip_configuration.#", "1"), ), }, { - Config: testAccAzureRMLoadBalancer_frontEndConfigRemoval(ri, location), + Config: testAccAzureRMLoadBalancer_frontEndConfigRemoval(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), - resource.TestCheckResourceAttr(resourceName, "frontend_ip_configuration.#", "1"), + testCheckAzureRMLoadBalancerExists(data.ResourceName, &lb), + resource.TestCheckResourceAttr(data.ResourceName, "frontend_ip_configuration.#", "1"), ), }, }, @@ -194,10 +148,8 @@ func TestAccAzureRMLoadBalancer_frontEndConfig(t *testing.T) { } func TestAccAzureRMLoadBalancer_tags(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_lb", "test") var lb network.LoadBalancer - resourceName := "azurerm_lb.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -205,20 +157,20 @@ func TestAccAzureRMLoadBalancer_tags(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_basic(ri, location), + Config: testAccAzureRMLoadBalancer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.Environment", "production"), - resource.TestCheckResourceAttr(resourceName, "tags.Purpose", "AcceptanceTests"), + testCheckAzureRMLoadBalancerExists(data.ResourceName, &lb), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Environment", "production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Purpose", "AcceptanceTests"), ), }, { - Config: testAccAzureRMLoadBalancer_updatedTags(ri, location), + Config: testAccAzureRMLoadBalancer_updatedTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Purpose", "AcceptanceTests"), + testCheckAzureRMLoadBalancerExists(data.ResourceName, &lb), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Purpose", "AcceptanceTests"), ), }, }, @@ -226,9 +178,8 @@ func TestAccAzureRMLoadBalancer_tags(t *testing.T) { } func TestAccAzureRMLoadBalancer_emptyPrivateIP(t *testing.T) { - resourceName := "azurerm_lb.test" + data := acceptance.BuildTestData(t, "azurerm_lb", "test") var lb network.LoadBalancer - ri := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -236,10 +187,10 @@ func TestAccAzureRMLoadBalancer_emptyPrivateIP(t *testing.T) { CheckDestroy: testCheckAzureRMLoadBalancerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLoadBalancer_emptyIPAddress(ri, acceptance.Location()), + Config: testAccAzureRMLoadBalancer_emptyIPAddress(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLoadBalancerExists(resourceName, &lb), - resource.TestCheckResourceAttrSet(resourceName, "frontend_ip_configuration.0.private_ip_address"), + testCheckAzureRMLoadBalancerExists(data.ResourceName, &lb), + resource.TestCheckResourceAttrSet(data.ResourceName, "frontend_ip_configuration.0.private_ip_address"), ), }, }, @@ -303,7 +254,7 @@ func testCheckAzureRMLoadBalancerDestroy(s *terraform.State) error { return nil } -func testAccAzureRMLoadBalancer_basic(rInt int, location string) string { +func testAccAzureRMLoadBalancer_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -320,11 +271,11 @@ resource "azurerm_lb" "test" { Purpose = "AcceptanceTests" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLoadBalancer_requiresImport(rInt int, location string) string { - template := testAccAzureRMLoadBalancer_basic(rInt, location) +func testAccAzureRMLoadBalancer_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLoadBalancer_basic(data) return fmt.Sprintf(` %s @@ -341,7 +292,7 @@ resource "azurerm_lb" "import" { `, template) } -func testAccAzureRMLoadBalancer_standard(rInt int, location string) string { +func testAccAzureRMLoadBalancer_standard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -359,10 +310,10 @@ resource "azurerm_lb" "test" { Purpose = "AcceptanceTests" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLoadBalancer_updatedTags(rInt int, location string) string { +func testAccAzureRMLoadBalancer_updatedTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -378,10 +329,10 @@ resource "azurerm_lb" "test" { Purpose = "AcceptanceTests" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLoadBalancer_frontEndConfig(rInt int, location string) string { +func testAccAzureRMLoadBalancer_frontEndConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -417,10 +368,10 @@ resource "azurerm_lb" "test" { public_ip_address_id = "${azurerm_public_ip.test1.id}" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLoadBalancer_frontEndConfigRemovalWithIP(rInt int, location string) string { +func testAccAzureRMLoadBalancer_frontEndConfigRemovalWithIP(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -451,10 +402,10 @@ resource "azurerm_lb" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLoadBalancer_frontEndConfigPublicIPPrefix(rInt int, location string) string { +func testAccAzureRMLoadBalancer_frontEndConfigPublicIPPrefix(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -479,10 +430,10 @@ resource "azurerm_lb" "test" { public_ip_prefix_id = "${azurerm_public_ip_prefix.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLoadBalancer_frontEndConfigRemoval(rInt int, location string) string { +func testAccAzureRMLoadBalancer_frontEndConfigRemoval(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -506,10 +457,10 @@ resource "azurerm_lb" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMLoadBalancer_emptyIPAddress(rInt int, location string) string { +func testAccAzureRMLoadBalancer_emptyIPAddress(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -543,5 +494,5 @@ resource "azurerm_lb" "test" { subnet_id = "${azurerm_subnet.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_local_network_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_local_network_gateway_test.go similarity index 63% rename from azurerm/internal/services/network/resource_arm_local_network_gateway_test.go rename to azurerm/internal/services/network/tests/resource_arm_local_network_gateway_test.go index 4448b49a170c..5fb269bafa31 100644 --- a/azurerm/internal/services/network/resource_arm_local_network_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_local_network_gateway_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,27 +15,22 @@ import ( ) func TestAccAzureRMLocalNetworkGateway_basic(t *testing.T) { - resourceName := "azurerm_local_network_gateway.test" + data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - rInt := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLocalNetworkGatewayConfig_basic(rInt, acceptance.Location()), + Config: testAccAzureRMLocalNetworkGatewayConfig_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(resourceName, "address_space.0", "127.0.0.0/8"), + 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"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,23 +41,21 @@ func TestAccAzureRMLocalNetworkGateway_requiresImport(t *testing.T) { return } - resourceName := "azurerm_local_network_gateway.test" + data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - rInt := tf.AccRandTimeInt() - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLocalNetworkGatewayConfig_basic(rInt, location), + Config: testAccAzureRMLocalNetworkGatewayConfig_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(resourceName), + testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), ), }, { - Config: testAccAzureRMLocalNetworkGatewayConfig_requiresImport(rInt, location), + Config: testAccAzureRMLocalNetworkGatewayConfig_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_local_network_gateway"), }, }, @@ -71,8 +63,7 @@ func TestAccAzureRMLocalNetworkGateway_requiresImport(t *testing.T) { } func TestAccAzureRMLocalNetworkGateway_disappears(t *testing.T) { - resourceName := "azurerm_local_network_gateway.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,12 +71,12 @@ func TestAccAzureRMLocalNetworkGateway_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLocalNetworkGatewayConfig_basic(rInt, acceptance.Location()), + Config: testAccAzureRMLocalNetworkGatewayConfig_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(resourceName, "address_space.0", "127.0.0.0/8"), - testCheckAzureRMLocalNetworkGatewayDisappears(resourceName), + 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, }, @@ -94,35 +85,28 @@ func TestAccAzureRMLocalNetworkGateway_disappears(t *testing.T) { } func TestAccAzureRMLocalNetworkGateway_tags(t *testing.T) { - resourceName := "azurerm_local_network_gateway.test" + data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") - rInt := tf.AccRandTimeInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLocalNetworkGatewayConfig_tags(rInt, acceptance.Location()), + Config: testAccAzureRMLocalNetworkGatewayConfig_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "acctest"), + testCheckAzureRMLocalNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "acctest"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMLocalNetworkGateway_bgpSettings(t *testing.T) { - resourceName := "azurerm_local_network_gateway.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -130,27 +114,21 @@ func TestAccAzureRMLocalNetworkGateway_bgpSettings(t *testing.T) { CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(rInt, location), + Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(resourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.#", "1"), + 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"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMLocalNetworkGateway_bgpSettingsDisable(t *testing.T) { - resourceName := "azurerm_local_network_gateway.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -158,23 +136,23 @@ func TestAccAzureRMLocalNetworkGateway_bgpSettingsDisable(t *testing.T) { CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(rInt, location), + Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(resourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.0.asn", "2468"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.0.bgp_peering_address", "10.104.1.1"), + 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(rInt, location), + Config: testAccAzureRMLocalNetworkGatewayConfig_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(resourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.#", "0"), + 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"), ), }, }, @@ -182,9 +160,7 @@ func TestAccAzureRMLocalNetworkGateway_bgpSettingsDisable(t *testing.T) { } func TestAccAzureRMLocalNetworkGateway_bgpSettingsEnable(t *testing.T) { - resourceName := "azurerm_local_network_gateway.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -192,23 +168,23 @@ func TestAccAzureRMLocalNetworkGateway_bgpSettingsEnable(t *testing.T) { CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLocalNetworkGatewayConfig_basic(rInt, location), + Config: testAccAzureRMLocalNetworkGatewayConfig_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(resourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.#", "0"), + 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(rInt, location), + Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(resourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.0.asn", "2468"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.0.bgp_peering_address", "10.104.1.1"), + 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"), ), }, }, @@ -216,9 +192,7 @@ func TestAccAzureRMLocalNetworkGateway_bgpSettingsEnable(t *testing.T) { } func TestAccAzureRMLocalNetworkGateway_bgpSettingsComplete(t *testing.T) { - resourceName := "azurerm_local_network_gateway.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_local_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -226,22 +200,18 @@ func TestAccAzureRMLocalNetworkGateway_bgpSettingsComplete(t *testing.T) { CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettingsComplete(rInt, location), + Config: testAccAzureRMLocalNetworkGatewayConfig_bgpSettingsComplete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMLocalNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gateway_address", "127.0.0.1"), - resource.TestCheckResourceAttr(resourceName, "address_space.0", "127.0.0.0/8"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.0.asn", "2468"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.0.bgp_peering_address", "10.104.1.1"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.0.peer_weight", "15"), + 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"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -349,7 +319,7 @@ func testCheckAzureRMLocalNetworkGatewayDestroy(s *terraform.State) error { return nil } -func testAccAzureRMLocalNetworkGatewayConfig_basic(rInt int, location string) string { +func testAccAzureRMLocalNetworkGatewayConfig_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-%d" @@ -363,11 +333,11 @@ resource "azurerm_local_network_gateway" "test" { gateway_address = "127.0.0.1" address_space = ["127.0.0.0/8"] } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLocalNetworkGatewayConfig_requiresImport(rInt int, location string) string { - template := testAccAzureRMLocalNetworkGatewayConfig_basic(rInt, location) +func testAccAzureRMLocalNetworkGatewayConfig_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMLocalNetworkGatewayConfig_basic(data) return fmt.Sprintf(` %s @@ -381,7 +351,7 @@ resource "azurerm_local_network_gateway" "import" { `, template) } -func testAccAzureRMLocalNetworkGatewayConfig_tags(rInt int, location string) string { +func testAccAzureRMLocalNetworkGatewayConfig_tags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-%d" @@ -399,10 +369,10 @@ resource "azurerm_local_network_gateway" "test" { environment = "acctest" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(rInt int, location string) string { +func testAccAzureRMLocalNetworkGatewayConfig_bgpSettings(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-%d" @@ -421,10 +391,10 @@ resource "azurerm_local_network_gateway" "test" { bgp_peering_address = "10.104.1.1" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMLocalNetworkGatewayConfig_bgpSettingsComplete(rInt int, location string) string { +func testAccAzureRMLocalNetworkGatewayConfig_bgpSettingsComplete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-%d" @@ -444,5 +414,5 @@ resource "azurerm_local_network_gateway" "test" { peer_weight = 15 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_nat_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_nat_gateway_test.go similarity index 64% rename from azurerm/internal/services/network/resource_arm_nat_gateway_test.go rename to azurerm/internal/services/network/tests/resource_arm_nat_gateway_test.go index e5f9ce38d3a7..f5a60f34afaf 100644 --- a/azurerm/internal/services/network/resource_arm_nat_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_nat_gateway_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,17 +6,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMNatGateway_basic(t *testing.T) { - resourceName := "azurerm_nat_gateway.test" - ri := tf.AccRandTimeInt() - // Using alt location because the resource currently in private preview and is only available in eastus2. - location := acceptance.AltLocation() + data := acceptance.BuildTestData(t, "azurerm_nat_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,25 +20,18 @@ func TestAccAzureRMNatGateway_basic(t *testing.T) { CheckDestroy: testCheckAzureRMNatGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNatGateway_basic(ri, location), + Config: testAccAzureRMNatGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNatGatewayExists(resourceName), + testCheckAzureRMNatGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNatGateway_complete(t *testing.T) { - resourceName := "azurerm_nat_gateway.test" - ri := tf.AccRandTimeInt() - // Using alt location because the resource currently in private preview and is only available in eastus2. - location := acceptance.AltLocation() + data := acceptance.BuildTestData(t, "azurerm_nat_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,30 +39,23 @@ func TestAccAzureRMNatGateway_complete(t *testing.T) { CheckDestroy: testCheckAzureRMNatGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNatGateway_complete(ri, location), + Config: testAccAzureRMNatGateway_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNatGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "public_ip_address_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "public_ip_prefix_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "sku_name", "Standard"), - resource.TestCheckResourceAttr(resourceName, "idle_timeout_in_minutes", "10"), - resource.TestCheckResourceAttr(resourceName, "zones.#", "1"), + testCheckAzureRMNatGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "public_ip_address_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "public_ip_prefix_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "idle_timeout_in_minutes", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNatGateway_update(t *testing.T) { - resourceName := "azurerm_nat_gateway.test" - ri := tf.AccRandTimeInt() - // Using alt location because the resource currently in private preview and is only available in eastus2. - location := acceptance.AltLocation() + data := acceptance.BuildTestData(t, "azurerm_nat_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,27 +63,23 @@ func TestAccAzureRMNatGateway_update(t *testing.T) { CheckDestroy: testCheckAzureRMNatGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNatGateway_basic(ri, location), + Config: testAccAzureRMNatGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNatGatewayExists(resourceName), + testCheckAzureRMNatGatewayExists(data.ResourceName), ), }, { - Config: testAccAzureRMNatGateway_complete(ri, location), + Config: testAccAzureRMNatGateway_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNatGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "public_ip_address_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "public_ip_prefix_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "sku_name", "Standard"), - resource.TestCheckResourceAttr(resourceName, "idle_timeout_in_minutes", "10"), - resource.TestCheckResourceAttr(resourceName, "zones.#", "1"), + testCheckAzureRMNatGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "public_ip_address_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "public_ip_prefix_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "sku_name", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "idle_timeout_in_minutes", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -154,7 +132,8 @@ func testCheckAzureRMNatGatewayDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNatGateway_basic(rInt int, location string) string { +// Using alt location because the resource currently in private preview and is only available in eastus2. +func testAccAzureRMNatGateway_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-network-%d" @@ -166,10 +145,11 @@ resource "azurerm_nat_gateway" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Secondary, data.RandomInteger) } -func testAccAzureRMNatGateway_complete(rInt int, location string) string { +// Using alt location because the resource currently in private preview and is only available in eastus2. +func testAccAzureRMNatGateway_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-network-%d" @@ -203,5 +183,5 @@ resource "azurerm_nat_gateway" "test" { idle_timeout_in_minutes = 10 zones = ["1"] } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Secondary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_network_connection_monitor_test.go b/azurerm/internal/services/network/tests/resource_arm_network_connection_monitor_test.go similarity index 70% rename from azurerm/internal/services/network/resource_arm_network_connection_monitor_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_connection_monitor_test.go index b10c4b64b7fa..8bfb3e92ca86 100644 --- a/azurerm/internal/services/network/resource_arm_network_connection_monitor_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_connection_monitor_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -9,17 +9,13 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func testAccAzureRMNetworkConnectionMonitor_addressBasic(t *testing.T) { - resourceName := "azurerm_network_connection_monitor.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,20 +23,16 @@ func testAccAzureRMNetworkConnectionMonitor_addressBasic(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttr(resourceName, "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr(resourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "60"), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "60"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -51,10 +43,7 @@ func testAccAzureRMNetworkConnectionMonitor_requiresImport(t *testing.T) { return } - resourceName := "azurerm_network_connection_monitor.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -62,13 +51,13 @@ func testAccAzureRMNetworkConnectionMonitor_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkConnectionMonitor_requiresImportConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_requiresImportConfig(data), ExpectError: acceptance.RequiresImportError("azurerm_network_connection_monitor"), }, }, @@ -76,10 +65,8 @@ func testAccAzureRMNetworkConnectionMonitor_requiresImport(t *testing.T) { } func testAccAzureRMNetworkConnectionMonitor_addressComplete(t *testing.T) { - resourceName := "azurerm_network_connection_monitor.test" + data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test") - ri := tf.AccRandTimeInt() - location := acceptance.Location() autoStart := "false" resource.Test(t, resource.TestCase{ @@ -88,30 +75,24 @@ func testAccAzureRMNetworkConnectionMonitor_addressComplete(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkConnectionMonitor_completeAddressConfig(ri, location, autoStart), + Config: testAccAzureRMNetworkConnectionMonitor_completeAddressConfig(data, autoStart), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_start", "false"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(resourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMNetworkConnectionMonitor_addressUpdate(t *testing.T) { - resourceName := "azurerm_network_connection_monitor.test" + data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test") - ri := tf.AccRandTimeInt() - location := acceptance.Location() autoStart := "true" resource.Test(t, resource.TestCase{ @@ -120,36 +101,29 @@ func testAccAzureRMNetworkConnectionMonitor_addressUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkConnectionMonitor_completeAddressConfig(ri, location, autoStart), + Config: testAccAzureRMNetworkConnectionMonitor_completeAddressConfig(data, autoStart), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(resourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMNetworkConnectionMonitor_vmBasic(t *testing.T) { - resourceName := "azurerm_network_connection_monitor.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -157,29 +131,23 @@ func testAccAzureRMNetworkConnectionMonitor_vmBasic(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkConnectionMonitor_basicVmConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_basicVmConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttr(resourceName, "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr(resourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "60"), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "60"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMNetworkConnectionMonitor_vmComplete(t *testing.T) { - resourceName := "azurerm_network_connection_monitor.test" + data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test") - ri := tf.AccRandTimeInt() - location := acceptance.Location() autoStart := "false" resource.Test(t, resource.TestCase{ @@ -188,30 +156,23 @@ func testAccAzureRMNetworkConnectionMonitor_vmComplete(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkConnectionMonitor_completeVmConfig(ri, location, autoStart), + Config: testAccAzureRMNetworkConnectionMonitor_completeVmConfig(data, autoStart), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_start", "false"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(resourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMNetworkConnectionMonitor_vmUpdate(t *testing.T) { - resourceName := "azurerm_network_connection_monitor.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -219,36 +180,29 @@ func testAccAzureRMNetworkConnectionMonitor_vmUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkConnectionMonitor_basicVmConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_basicVmConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkConnectionMonitor_completeVmConfig(ri, location, "true"), + Config: testAccAzureRMNetworkConnectionMonitor_completeVmConfig(data, "true"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_start", "true"), - resource.TestCheckResourceAttr(resourceName, "interval_in_seconds", "30"), - resource.TestCheckResourceAttr(resourceName, "source.0.port", "20020"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_start", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "interval_in_seconds", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "source.0.port", "20020"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMNetworkConnectionMonitor_destinationUpdate(t *testing.T) { - resourceName := "azurerm_network_connection_monitor.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -256,38 +210,33 @@ func testAccAzureRMNetworkConnectionMonitor_destinationUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "destination.0.address"), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "destination.0.address"), ), }, { - Config: testAccAzureRMNetworkConnectionMonitor_basicVmConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_basicVmConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "destination.0.virtual_machine_id"), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "destination.0.virtual_machine_id"), ), }, { - Config: testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkConnectionMonitorExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "destination.0.address"), + testCheckAzureRMNetworkConnectionMonitorExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "destination.0.address"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMNetworkConnectionMonitor_missingDestination(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -295,7 +244,7 @@ func testAccAzureRMNetworkConnectionMonitor_missingDestination(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkConnectionMonitor_missingDestinationConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_missingDestinationConfig(data), ExpectError: regexp.MustCompile("Error: either `destination.virtual_machine_id` or `destination.address` must be specified"), }, }, @@ -303,8 +252,7 @@ func testAccAzureRMNetworkConnectionMonitor_missingDestination(t *testing.T) { } func testAccAzureRMNetworkConnectionMonitor_conflictingDestinations(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_connection_monitor", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -312,7 +260,7 @@ func testAccAzureRMNetworkConnectionMonitor_conflictingDestinations(t *testing.T CheckDestroy: testCheckAzureRMNetworkConnectionMonitorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkConnectionMonitor_conflictingDestinationsConfig(ri, location), + Config: testAccAzureRMNetworkConnectionMonitor_conflictingDestinationsConfig(data), ExpectError: regexp.MustCompile("conflicts with destination.0.address"), }, }, @@ -373,7 +321,7 @@ func testCheckAzureRMNetworkConnectionMonitorDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNetworkConnectionMonitor_baseConfig(rInt int, location string) string { +func testAccAzureRMNetworkConnectionMonitor_baseConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-watcher-%d" @@ -454,11 +402,11 @@ resource "azurerm_virtual_machine_extension" "src" { type_handler_version = "1.4" auto_upgrade_minor_version = true } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkConnectionMonitor_baseWithDestConfig(rInt int, location string) string { - config := testAccAzureRMNetworkConnectionMonitor_baseConfig(rInt, location) +func testAccAzureRMNetworkConnectionMonitor_baseWithDestConfig(data acceptance.TestData) string { + config := testAccAzureRMNetworkConnectionMonitor_baseConfig(data) return fmt.Sprintf(` %s @@ -505,11 +453,11 @@ resource "azurerm_virtual_machine" "dest" { disable_password_authentication = false } } -`, config, rInt, rInt, rInt, rInt) +`, config, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(rInt int, location string) string { - config := testAccAzureRMNetworkConnectionMonitor_baseConfig(rInt, location) +func testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(data acceptance.TestData) string { + config := testAccAzureRMNetworkConnectionMonitor_baseConfig(data) return fmt.Sprintf(` %s @@ -530,11 +478,11 @@ resource "azurerm_network_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAccAzureRMNetworkConnectionMonitor_completeAddressConfig(rInt int, location, autoStart string) string { - config := testAccAzureRMNetworkConnectionMonitor_baseConfig(rInt, location) +func testAccAzureRMNetworkConnectionMonitor_completeAddressConfig(data acceptance.TestData, autoStart string) string { + config := testAccAzureRMNetworkConnectionMonitor_baseConfig(data) return fmt.Sprintf(` %s @@ -563,11 +511,11 @@ resource "azurerm_network_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt, autoStart) +`, config, data.RandomInteger, autoStart) } -func testAccAzureRMNetworkConnectionMonitor_basicVmConfig(rInt int, location string) string { - config := testAccAzureRMNetworkConnectionMonitor_baseWithDestConfig(rInt, location) +func testAccAzureRMNetworkConnectionMonitor_basicVmConfig(data acceptance.TestData) string { + config := testAccAzureRMNetworkConnectionMonitor_baseWithDestConfig(data) return fmt.Sprintf(` %s @@ -588,11 +536,11 @@ resource "azurerm_network_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAccAzureRMNetworkConnectionMonitor_completeVmConfig(rInt int, location, autoStart string) string { - config := testAccAzureRMNetworkConnectionMonitor_baseWithDestConfig(rInt, location) +func testAccAzureRMNetworkConnectionMonitor_completeVmConfig(data acceptance.TestData, autoStart string) string { + config := testAccAzureRMNetworkConnectionMonitor_baseWithDestConfig(data) return fmt.Sprintf(` %s @@ -621,11 +569,11 @@ resource "azurerm_network_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt, autoStart) +`, config, data.RandomInteger, autoStart) } -func testAccAzureRMNetworkConnectionMonitor_missingDestinationConfig(rInt int, location string) string { - config := testAccAzureRMNetworkConnectionMonitor_baseConfig(rInt, location) +func testAccAzureRMNetworkConnectionMonitor_missingDestinationConfig(data acceptance.TestData) string { + config := testAccAzureRMNetworkConnectionMonitor_baseConfig(data) return fmt.Sprintf(` %s @@ -645,11 +593,11 @@ resource "azurerm_network_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAccAzureRMNetworkConnectionMonitor_conflictingDestinationsConfig(rInt int, location string) string { - config := testAccAzureRMNetworkConnectionMonitor_baseConfig(rInt, location) +func testAccAzureRMNetworkConnectionMonitor_conflictingDestinationsConfig(data acceptance.TestData) string { + config := testAccAzureRMNetworkConnectionMonitor_baseConfig(data) return fmt.Sprintf(` %s @@ -671,11 +619,11 @@ resource "azurerm_network_connection_monitor" "test" { depends_on = ["azurerm_virtual_machine_extension.src"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAccAzureRMNetworkConnectionMonitor_requiresImportConfig(rInt int, location string) string { - config := testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(rInt, location) +func testAccAzureRMNetworkConnectionMonitor_requiresImportConfig(data acceptance.TestData) string { + config := testAccAzureRMNetworkConnectionMonitor_basicAddressConfig(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_network_ddos_protection_plan_test.go b/azurerm/internal/services/network/tests/resource_arm_network_ddos_protection_plan_test.go similarity index 79% rename from azurerm/internal/services/network/resource_arm_network_ddos_protection_plan_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_ddos_protection_plan_test.go index 3d8d649fa87d..a7709494728b 100644 --- a/azurerm/internal/services/network/resource_arm_network_ddos_protection_plan_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_ddos_protection_plan_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -46,9 +45,7 @@ func TestAccAzureRMNetworkDDoSProtectionPlan(t *testing.T) { } func testAccAzureRMNetworkDDoSProtectionPlan_basic(t *testing.T) { - resourceName := "azurerm_network_ddos_protection_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_ddos_protection_plan", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,17 +53,13 @@ func testAccAzureRMNetworkDDoSProtectionPlan_basic(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkDDoSProtectionPlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(ri, location), + Config: testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkDDoSProtectionPlanExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "virtual_network_ids.#"), + testCheckAzureRMNetworkDDoSProtectionPlanExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_ids.#"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -77,9 +70,7 @@ func testAccAzureRMNetworkDDoSProtectionPlan_requiresImport(t *testing.T) { return } - resourceName := "azurerm_network_ddos_protection_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_ddos_protection_plan", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -87,13 +78,13 @@ func testAccAzureRMNetworkDDoSProtectionPlan_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkDDoSProtectionPlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(ri, location), + Config: testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkDDoSProtectionPlanExists(resourceName), + testCheckAzureRMNetworkDDoSProtectionPlanExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkDDoSProtectionPlan_requiresImportConfig(ri, location), + Config: testAccAzureRMNetworkDDoSProtectionPlan_requiresImportConfig(data), ExpectError: acceptance.RequiresImportError("azurerm_network_ddos_protection_plan"), }, }, @@ -101,9 +92,7 @@ func testAccAzureRMNetworkDDoSProtectionPlan_requiresImport(t *testing.T) { } func testAccAzureRMNetworkDDoSProtectionPlan_withTags(t *testing.T) { - resourceName := "azurerm_network_ddos_protection_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_ddos_protection_plan", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,35 +100,29 @@ func testAccAzureRMNetworkDDoSProtectionPlan_withTags(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkDDoSProtectionPlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkDDoSProtectionPlan_withTagsConfig(ri, location), + Config: testAccAzureRMNetworkDDoSProtectionPlan_withTagsConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkDDoSProtectionPlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMNetworkDDoSProtectionPlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { - Config: testAccAzureRMNetworkDDoSProtectionPlan_withUpdatedTagsConfig(ri, location), + Config: testAccAzureRMNetworkDDoSProtectionPlan_withUpdatedTagsConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkDDoSProtectionPlanExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Staging"), + testCheckAzureRMNetworkDDoSProtectionPlanExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Staging"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMNetworkDDoSProtectionPlan_disappears(t *testing.T) { - resourceName := "azurerm_network_ddos_protection_plan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_ddos_protection_plan", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -147,10 +130,10 @@ func testAccAzureRMNetworkDDoSProtectionPlan_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkDDoSProtectionPlanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(ri, location), + Config: testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkDDoSProtectionPlanExists(resourceName), - testCheckAzureRMNetworkDDoSProtectionPlanDisappears(resourceName), + testCheckAzureRMNetworkDDoSProtectionPlanExists(data.ResourceName), + testCheckAzureRMNetworkDDoSProtectionPlanDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -244,7 +227,7 @@ func testCheckAzureRMNetworkDDoSProtectionPlanDestroy(s *terraform.State) error return nil } -func testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(rInt int, location string) string { +func testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -256,11 +239,11 @@ resource "azurerm_network_ddos_protection_plan" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMNetworkDDoSProtectionPlan_requiresImportConfig(rInt int, location string) string { - basicConfig := testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(rInt, location) +func testAccAzureRMNetworkDDoSProtectionPlan_requiresImportConfig(data acceptance.TestData) string { + basicConfig := testAccAzureRMNetworkDDoSProtectionPlan_basicConfig(data) return fmt.Sprintf(` %s @@ -272,7 +255,7 @@ resource "azurerm_network_ddos_protection_plan" "import" { `, basicConfig) } -func testAccAzureRMNetworkDDoSProtectionPlan_withTagsConfig(rInt int, location string) string { +func testAccAzureRMNetworkDDoSProtectionPlan_withTagsConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -289,10 +272,10 @@ resource "azurerm_network_ddos_protection_plan" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMNetworkDDoSProtectionPlan_withUpdatedTagsConfig(rInt int, location string) string { +func testAccAzureRMNetworkDDoSProtectionPlan_withUpdatedTagsConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -308,5 +291,5 @@ resource "azurerm_network_ddos_protection_plan" "test" { environment = "Staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_network_interface_application_gateway_association_test.go b/azurerm/internal/services/network/tests/resource_arm_network_interface_application_gateway_association_test.go similarity index 90% rename from azurerm/internal/services/network/resource_arm_network_interface_application_gateway_association_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_interface_application_gateway_association_test.go index 8885ca152f4b..fc9e1ff2c6e5 100644 --- a/azurerm/internal/services/network/resource_arm_network_interface_application_gateway_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_interface_application_gateway_association_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(t *testing.T) { - resourceName := "azurerm_network_interface_application_gateway_backend_address_pool_association.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface_application_gateway_backend_address_pool_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -24,9 +22,9 @@ func TestAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociati CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationExists(resourceName), + testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationExists(data.ResourceName), ), }, }, @@ -39,9 +37,7 @@ func TestAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociati return } - resourceName := "azurerm_network_interface_application_gateway_backend_address_pool_association.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_interface_application_gateway_backend_address_pool_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -49,13 +45,13 @@ func TestAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociati CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(rInt, location), + Config: testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationExists(resourceName), + testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_requiresImport(rInt, location), + Config: testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_network_interface_application_gateway_backend_address_pool_association"), }, }, @@ -63,9 +59,7 @@ func TestAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociati } func TestAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_deleted(t *testing.T) { - resourceName := "azurerm_network_interface_application_gateway_backend_address_pool_association.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_interface_application_gateway_backend_address_pool_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,10 +68,10 @@ func TestAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociati CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(ri, location), + Config: testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationExists(resourceName), - testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationDisappears(resourceName), + testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationExists(data.ResourceName), + testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -190,7 +184,7 @@ func testCheckAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssocia } } -func testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(rInt int, location string) string { +func testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -306,11 +300,11 @@ resource "azurerm_network_interface_application_gateway_backend_address_pool_ass ip_configuration_name = "testconfiguration1" backend_address_pool_id = "${azurerm_application_gateway.test.backend_address_pool.0.id}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_requiresImport(rInt int, location string) string { - template := testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(rInt, location) +func testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceApplicationGatewayBackendAddressPoolAssociation_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association_test.go b/azurerm/internal/services/network/tests/resource_arm_network_interface_application_security_group_association_test.go similarity index 90% rename from azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_interface_application_security_group_association_test.go index 80868d466f11..1dc83acbff80 100644 --- a/azurerm/internal/services/network/resource_arm_network_interface_application_security_group_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_interface_application_security_group_association_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(t *testing.T) { - resourceName := "azurerm_network_interface_application_security_group_association.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface_application_security_group_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -24,9 +22,9 @@ func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(t * CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(resourceName), + testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(data.ResourceName), ), }, }, @@ -39,9 +37,7 @@ func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_requiresI return } - resourceName := "azurerm_network_interface_application_security_group_association.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_interface_application_security_group_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -49,13 +45,13 @@ func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_requiresI CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(rInt, location), + Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(resourceName), + testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_requiresImport(rInt, location), + Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_network_interface_application_security_group_association"), }, }, @@ -63,9 +59,7 @@ func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_requiresI } func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_deleted(t *testing.T) { - resourceName := "azurerm_network_interface_application_security_group_association.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_interface_application_security_group_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,10 +68,10 @@ func TestAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_deleted(t CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(ri, location), + Config: testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(resourceName), - testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationDisappears(resourceName), + testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationExists(data.ResourceName), + testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -190,7 +184,7 @@ func testCheckAzureRMNetworkInterfaceApplicationSecurityGroupAssociationDisappea } } -func testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(rInt int, location string) string { +func testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -235,11 +229,11 @@ resource "azurerm_network_interface_application_security_group_association" "tes ip_configuration_name = "testconfiguration1" application_security_group_id = "${azurerm_application_security_group.test.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_requiresImport(rInt int, location string) string { - template := testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(rInt, location) +func testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceApplicationSecurityGroupAssociation_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_network_interface_backend_address_pool_association_test.go b/azurerm/internal/services/network/tests/resource_arm_network_interface_backend_address_pool_association_test.go similarity index 91% rename from azurerm/internal/services/network/resource_arm_network_interface_backend_address_pool_association_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_interface_backend_address_pool_association_test.go index 954d0ce12d03..c467627086f4 100644 --- a/azurerm/internal/services/network/resource_arm_network_interface_backend_address_pool_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_interface_backend_address_pool_association_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(t *testing.T) { - resourceName := "azurerm_network_interface_backend_address_pool_association.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface_backend_address_pool_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -24,9 +22,9 @@ func TestAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(t *testin CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationExists(resourceName), + testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationExists(data.ResourceName), ), }, }, @@ -39,9 +37,7 @@ func TestAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_requiresImport( return } - resourceName := "azurerm_network_interface_backend_address_pool_association.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_interface_backend_address_pool_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -49,13 +45,13 @@ func TestAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_requiresImport( CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(rInt, location), + Config: testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationExists(resourceName), + testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_requiresImport(rInt, location), + Config: testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_network_interface_backend_address_pool_association"), }, }, @@ -63,9 +59,7 @@ func TestAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_requiresImport( } func TestAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_deleted(t *testing.T) { - resourceName := "azurerm_network_interface_backend_address_pool_association.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_interface_backend_address_pool_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,10 +68,10 @@ func TestAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_deleted(t *test CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(ri, location), + Config: testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationExists(resourceName), - testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationDisappears(resourceName), + testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationExists(data.ResourceName), + testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -190,7 +184,7 @@ func testCheckAzureRMNetworkInterfaceBackendAddressPoolAssociationDisappears(res } } -func testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(rInt int, location string) string { +func testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -253,11 +247,11 @@ resource "azurerm_network_interface_backend_address_pool_association" "test" { ip_configuration_name = "testconfiguration1" backend_address_pool_id = "${azurerm_lb_backend_address_pool.test.id}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_requiresImport(rInt int, location string) string { - template := testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(rInt, location) +func testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceBackendAddressPoolAssociation_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_network_interface_nat_rule_association_test.go b/azurerm/internal/services/network/tests/resource_arm_network_interface_nat_rule_association_test.go similarity index 90% rename from azurerm/internal/services/network/resource_arm_network_interface_nat_rule_association_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_interface_nat_rule_association_test.go index 0cb6e10f1de7..052a5af49249 100644 --- a/azurerm/internal/services/network/resource_arm_network_interface_nat_rule_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_interface_nat_rule_association_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMNetworkInterfaceNATRuleAssociation_basic(t *testing.T) { - resourceName := "azurerm_network_interface_nat_rule_association.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface_nat_rule_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -24,9 +22,9 @@ func TestAccAzureRMNetworkInterfaceNATRuleAssociation_basic(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceNATRuleAssociationExists(resourceName), + testCheckAzureRMNetworkInterfaceNATRuleAssociationExists(data.ResourceName), ), }, }, @@ -39,9 +37,7 @@ func TestAccAzureRMNetworkInterfaceNATRuleAssociation_requiresImport(t *testing. return } - resourceName := "azurerm_network_interface_nat_rule_association.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_interface_nat_rule_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -49,13 +45,13 @@ func TestAccAzureRMNetworkInterfaceNATRuleAssociation_requiresImport(t *testing. CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(rInt, location), + Config: testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceNATRuleAssociationExists(resourceName), + testCheckAzureRMNetworkInterfaceNATRuleAssociationExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkInterfaceNATRuleAssociation_requiresImport(rInt, location), + Config: testAccAzureRMNetworkInterfaceNATRuleAssociation_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_network_interface_nat_rule_association"), }, }, @@ -63,9 +59,7 @@ func TestAccAzureRMNetworkInterfaceNATRuleAssociation_requiresImport(t *testing. } func TestAccAzureRMNetworkInterfaceNATRuleAssociation_deleted(t *testing.T) { - resourceName := "azurerm_network_interface_nat_rule_association.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_interface_nat_rule_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,10 +68,10 @@ func TestAccAzureRMNetworkInterfaceNATRuleAssociation_deleted(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(ri, location), + Config: testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceNATRuleAssociationExists(resourceName), - testCheckAzureRMNetworkInterfaceNATRuleAssociationDisappears(resourceName), + testCheckAzureRMNetworkInterfaceNATRuleAssociationExists(data.ResourceName), + testCheckAzureRMNetworkInterfaceNATRuleAssociationDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -190,7 +184,7 @@ func testCheckAzureRMNetworkInterfaceNATRuleAssociationDisappears(resourceName s } } -func testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(rInt int, location string) string { +func testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -256,11 +250,11 @@ resource "azurerm_network_interface_nat_rule_association" "test" { ip_configuration_name = "testconfiguration1" nat_rule_id = "${azurerm_lb_nat_rule.test.id}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterfaceNATRuleAssociation_requiresImport(rInt int, location string) string { - template := testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(rInt, location) +func testAccAzureRMNetworkInterfaceNATRuleAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterfaceNATRuleAssociation_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_network_interface_test.go b/azurerm/internal/services/network/tests/resource_arm_network_interface_test.go similarity index 80% rename from azurerm/internal/services/network/resource_arm_network_interface_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_interface_test.go index ea9d0884a8ca..e8f21dfc0ea0 100644 --- a/azurerm/internal/services/network/resource_arm_network_interface_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_interface_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,18 +13,17 @@ import ( ) func TestAccAzureRMNetworkInterface_disappears(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_basic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - testCheckAzureRMNetworkInterfaceDisappears(resourceName), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + testCheckAzureRMNetworkInterfaceDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -39,22 +37,20 @@ func TestAccAzureRMNetworkInterface_requiresImport(t *testing.T) { return } - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_basic(rInt, location), + Config: testAccAzureRMNetworkInterface_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkInterface_requiresImport(rInt, location), + Config: testAccAzureRMNetworkInterface_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_network_interface"), }, }, @@ -62,34 +58,27 @@ func TestAccAzureRMNetworkInterface_requiresImport(t *testing.T) { } func TestAccAzureRMNetworkInterface_basic(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_basic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNetworkInterface_setNetworkSecurityGroupId(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMNetworkInterface_basic(rInt, location) - updatedConfig := testAccAzureRMNetworkInterface_basicWithNetworkSecurityGroup(rInt, location) + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") + config := testAccAzureRMNetworkInterface_basic(data) + updatedConfig := testAccAzureRMNetworkInterface_basicWithNetworkSecurityGroup(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -99,14 +88,14 @@ func TestAccAzureRMNetworkInterface_setNetworkSecurityGroupId(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), ), }, }, @@ -114,11 +103,9 @@ func TestAccAzureRMNetworkInterface_setNetworkSecurityGroupId(t *testing.T) { } func TestAccAzureRMNetworkInterface_removeNetworkSecurityGroupId(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMNetworkInterface_basicWithNetworkSecurityGroup(rInt, location) - updatedConfig := testAccAzureRMNetworkInterface_basic(rInt, location) + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") + config := testAccAzureRMNetworkInterface_basicWithNetworkSecurityGroup(data) + updatedConfig := testAccAzureRMNetworkInterface_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -128,14 +115,14 @@ func TestAccAzureRMNetworkInterface_removeNetworkSecurityGroupId(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_security_group_id", ""), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_security_group_id", ""), ), }, }, @@ -143,10 +130,8 @@ func TestAccAzureRMNetworkInterface_removeNetworkSecurityGroupId(t *testing.T) { } func TestAccAzureRMNetworkInterface_multipleSubnets(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMNetworkInterface_multipleSubnets(rInt, location) + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") + config := testAccAzureRMNetworkInterface_multipleSubnets(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -156,8 +141,8 @@ func TestAccAzureRMNetworkInterface_multipleSubnets(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.#", "2"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.#", "2"), ), }, }, @@ -165,11 +150,9 @@ func TestAccAzureRMNetworkInterface_multipleSubnets(t *testing.T) { } func TestAccAzureRMNetworkInterface_multipleSubnetsPrimary(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMNetworkInterface_multipleSubnets(rInt, location) - updatedConfig := testAccAzureRMNetworkInterface_multipleSubnetsUpdatedPrimary(rInt, location) + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") + config := testAccAzureRMNetworkInterface_multipleSubnets(data) + updatedConfig := testAccAzureRMNetworkInterface_multipleSubnetsUpdatedPrimary(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -179,21 +162,21 @@ func TestAccAzureRMNetworkInterface_multipleSubnetsPrimary(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.primary", "true"), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.name", "testconfiguration1"), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.1.primary", "false"), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.1.name", "testconfiguration2"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.primary", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "testconfiguration1"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.primary", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.name", "testconfiguration2"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.primary", "true"), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.name", "testconfiguration2"), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.1.primary", "false"), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.1.name", "testconfiguration1"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.primary", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.name", "testconfiguration2"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.primary", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.name", "testconfiguration1"), ), }, }, @@ -201,18 +184,17 @@ func TestAccAzureRMNetworkInterface_multipleSubnetsPrimary(t *testing.T) { } func TestAccAzureRMNetworkInterface_enableIPForwarding(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_ipForwarding(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_ipForwarding(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_ip_forwarding", "true"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_ip_forwarding", "true"), ), }, }, @@ -220,18 +202,17 @@ func TestAccAzureRMNetworkInterface_enableIPForwarding(t *testing.T) { } func TestAccAzureRMNetworkInterface_enableAcceleratedNetworking(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_acceleratedNetworking(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_acceleratedNetworking(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_accelerated_networking", "true"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_accelerated_networking", "true"), ), }, }, @@ -239,14 +220,15 @@ func TestAccAzureRMNetworkInterface_enableAcceleratedNetworking(t *testing.T) { } func TestAccAzureRMNetworkInterface_multipleLoadBalancers(t *testing.T) { - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test1") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_multipleLoadBalancers(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_multipleLoadBalancers(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test1"), testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test2"), @@ -257,18 +239,17 @@ func TestAccAzureRMNetworkInterface_multipleLoadBalancers(t *testing.T) { } func TestAccAzureRMNetworkInterface_applicationGateway(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_applicationGatewayBackendPool(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_applicationGatewayBackendPool(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.application_gateway_backend_address_pools_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.application_gateway_backend_address_pools_ids.#", "1"), ), }, }, @@ -276,28 +257,27 @@ func TestAccAzureRMNetworkInterface_applicationGateway(t *testing.T) { } func TestAccAzureRMNetworkInterface_withTags(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_withTags(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { - Config: testAccAzureRMNetworkInterface_withTagsUpdate(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, }, @@ -305,27 +285,26 @@ func TestAccAzureRMNetworkInterface_withTags(t *testing.T) { } func TestAccAzureRMNetworkInterface_IPAddressesBug1286(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_withIPAddresses(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_withIPAddresses(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_configuration.0.private_ip_address"), - resource.TestCheckResourceAttrSet(resourceName, "ip_configuration.0.public_ip_address_id"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.public_ip_address_id"), ), }, { - Config: testAccAzureRMNetworkInterface_withIPAddressesUpdate(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_withIPAddressesUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_configuration.0.private_ip_address"), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.public_ip_address_id", ""), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_configuration.0.private_ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.public_ip_address_id", ""), ), }, }, @@ -333,8 +312,7 @@ func TestAccAzureRMNetworkInterface_IPAddressesBug1286(t *testing.T) { } func TestAccAzureRMNetworkInterface_IPAddressesFeature2543(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -342,12 +320,12 @@ func TestAccAzureRMNetworkInterface_IPAddressesFeature2543(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_withIPv6Addresses(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_withIPv6Addresses(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.private_ip_address_version", "IPv4"), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.1.private_ip_address_version", "IPv6"), - resource.TestCheckResourceAttrSet(resourceName, "private_ip_address"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.private_ip_address_version", "IPv4"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.1.private_ip_address_version", "IPv6"), + resource.TestCheckResourceAttrSet(data.ResourceName, "private_ip_address"), ), }, }, @@ -355,14 +333,15 @@ func TestAccAzureRMNetworkInterface_IPAddressesFeature2543(t *testing.T) { } func TestAccAzureRMNetworkInterface_bug7986(t *testing.T) { - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test1") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_bug7986(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_bug7986(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test1"), testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test2"), @@ -373,18 +352,17 @@ func TestAccAzureRMNetworkInterface_bug7986(t *testing.T) { } func TestAccAzureRMNetworkInterface_applicationSecurityGroups(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_applicationSecurityGroup(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkInterface_applicationSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkInterfaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_configuration.0.application_security_group_ids.#", "1"), + testCheckAzureRMNetworkInterfaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_configuration.0.application_security_group_ids.#", "1"), ), }, }, @@ -392,8 +370,7 @@ func TestAccAzureRMNetworkInterface_applicationSecurityGroups(t *testing.T) { } func TestAccAzureRMNetworkInterface_importPublicIP(t *testing.T) { - resourceName := "azurerm_network_interface.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_interface", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -401,13 +378,9 @@ func TestAccAzureRMNetworkInterface_importPublicIP(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkInterface_publicIP(rInt, acceptance.Location()), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + Config: testAccAzureRMNetworkInterface_publicIP(data), }, + data.ImportStep(), }, }) } @@ -499,7 +472,7 @@ func testCheckAzureRMNetworkInterfaceDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNetworkInterface_basic(rInt int, location string) string { +func testAccAzureRMNetworkInterface_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -531,11 +504,11 @@ resource "azurerm_network_interface" "test" { private_ip_address_allocation = "Dynamic" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_requiresImport(rInt int, location string) string { - template := testAccAzureRMNetworkInterface_basic(rInt, location) +func testAccAzureRMNetworkInterface_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkInterface_basic(data) return fmt.Sprintf(` %s @@ -553,7 +526,7 @@ resource "azurerm_network_interface" "import" { `, template) } -func testAccAzureRMNetworkInterface_basicWithNetworkSecurityGroup(rInt int, location string) string { +func testAccAzureRMNetworkInterface_basicWithNetworkSecurityGroup(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -592,10 +565,10 @@ resource "azurerm_network_interface" "test" { private_ip_address_allocation = "Dynamic" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_multipleSubnets(rInt int, location string) string { +func testAccAzureRMNetworkInterface_multipleSubnets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -634,10 +607,10 @@ resource "azurerm_network_interface" "test" { private_ip_address_allocation = "Dynamic" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_multipleSubnetsUpdatedPrimary(rInt int, location string) string { +func testAccAzureRMNetworkInterface_multipleSubnetsUpdatedPrimary(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -676,10 +649,10 @@ resource "azurerm_network_interface" "test" { private_ip_address_allocation = "Dynamic" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_ipForwarding(rInt int, location string) string { +func testAccAzureRMNetworkInterface_ipForwarding(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -712,10 +685,10 @@ resource "azurerm_network_interface" "test" { private_ip_address_allocation = "Dynamic" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_acceleratedNetworking(rInt int, location string) string { +func testAccAzureRMNetworkInterface_acceleratedNetworking(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -749,10 +722,10 @@ resource "azurerm_network_interface" "test" { private_ip_address_allocation = "Dynamic" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_withTags(rInt int, location string) string { +func testAccAzureRMNetworkInterface_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -789,10 +762,10 @@ resource "azurerm_network_interface" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMNetworkInterface_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -828,10 +801,10 @@ resource "azurerm_network_interface" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_withIPAddresses(rInt int, location string) string { +func testAccAzureRMNetworkInterface_withIPAddresses(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -873,10 +846,10 @@ resource "azurerm_network_interface" "test" { public_ip_address_id = "${azurerm_public_ip.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_withIPAddressesUpdate(rInt int, location string) string { +func testAccAzureRMNetworkInterface_withIPAddressesUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -916,10 +889,10 @@ resource "azurerm_network_interface" "test" { private_ip_address_allocation = "Dynamic" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_withIPv6Addresses(rInt int, location string) string { +func testAccAzureRMNetworkInterface_withIPv6Addresses(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -966,10 +939,10 @@ resource "azurerm_network_interface" "test" { private_ip_address_allocation = "dynamic" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_multipleLoadBalancers(rInt int, location string) string { +func testAccAzureRMNetworkInterface_multipleLoadBalancers(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -1098,10 +1071,10 @@ resource "azurerm_network_interface" "test2" { ] } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_applicationGatewayBackendPool(rInt int, location string) string { +func testAccAzureRMNetworkInterface_applicationGatewayBackendPool(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1210,10 +1183,10 @@ resource "azurerm_network_interface" "test" { ] } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_bug7986(rInt int, location string) string { +func testAccAzureRMNetworkInterface_bug7986(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-%d" @@ -1314,10 +1287,10 @@ resource "azurerm_network_interface" "test2" { environment = "staging" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_publicIP(rInt int, location string) string { +func testAccAzureRMNetworkInterface_publicIP(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -1357,10 +1330,10 @@ resource "azurerm_network_interface" "test" { public_ip_address_id = "${azurerm_public_ip.testext.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkInterface_applicationSecurityGroup(rInt int, location string) string { +func testAccAzureRMNetworkInterface_applicationSecurityGroup(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-rg-%d" @@ -1399,5 +1372,5 @@ resource "azurerm_network_interface" "test" { application_security_group_ids = ["${azurerm_application_security_group.test.id}"] } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_network_packet_capture_test.go b/azurerm/internal/services/network/tests/resource_arm_network_packet_capture_test.go similarity index 79% rename from azurerm/internal/services/network/resource_arm_network_packet_capture_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_packet_capture_test.go index c057195a61fd..9a559313b828 100644 --- a/azurerm/internal/services/network/resource_arm_network_packet_capture_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_packet_capture_test.go @@ -1,24 +1,19 @@ -package network +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func testAccAzureRMNetworkPacketCapture_localDisk(t *testing.T) { - resourceName := "azurerm_network_packet_capture.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_packet_capture", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,16 +21,12 @@ func testAccAzureRMNetworkPacketCapture_localDisk(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkPacketCaptureDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNetworkPacketCapture_localDiskConfig(ri, location), + Config: testAzureRMNetworkPacketCapture_localDiskConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkPacketCaptureExists(resourceName), + testCheckAzureRMNetworkPacketCaptureExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,10 +37,7 @@ func testAccAzureRMNetworkPacketCapture_requiresImport(t *testing.T) { return } - resourceName := "azurerm_network_packet_capture.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_packet_capture", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,24 +45,20 @@ func testAccAzureRMNetworkPacketCapture_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkPacketCaptureDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNetworkPacketCapture_localDiskConfig(ri, location), + Config: testAzureRMNetworkPacketCapture_localDiskConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkPacketCaptureExists(resourceName), + testCheckAzureRMNetworkPacketCaptureExists(data.ResourceName), ), }, { - Config: testAzureRMNetworkPacketCapture_localDiskConfig_requiresImport(ri, location), + Config: testAzureRMNetworkPacketCapture_localDiskConfig_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_network_packet_capture"), }, }, }) } func testAccAzureRMNetworkPacketCapture_storageAccount(t *testing.T) { - resourceName := "azurerm_network_packet_capture.test" - - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_packet_capture", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,26 +66,18 @@ func testAccAzureRMNetworkPacketCapture_storageAccount(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkPacketCaptureDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNetworkPacketCapture_storageAccountConfig(ri, rs, location), + Config: testAzureRMNetworkPacketCapture_storageAccountConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkPacketCaptureExists(resourceName), + testCheckAzureRMNetworkPacketCaptureExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMNetworkPacketCapture_storageAccountAndLocalDisk(t *testing.T) { - resourceName := "azurerm_network_packet_capture.test" - - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_packet_capture", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -109,25 +85,18 @@ func testAccAzureRMNetworkPacketCapture_storageAccountAndLocalDisk(t *testing.T) CheckDestroy: testCheckAzureRMNetworkPacketCaptureDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNetworkPacketCapture_storageAccountAndLocalDiskConfig(ri, rs, location), + Config: testAzureRMNetworkPacketCapture_storageAccountAndLocalDiskConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkPacketCaptureExists(resourceName), + testCheckAzureRMNetworkPacketCaptureExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMNetworkPacketCapture_withFilters(t *testing.T) { - resourceName := "azurerm_network_packet_capture.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_packet_capture", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -135,16 +104,12 @@ func testAccAzureRMNetworkPacketCapture_withFilters(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkPacketCaptureDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMNetworkPacketCapture_localDiskConfigWithFilters(ri, location), + Config: testAzureRMNetworkPacketCapture_localDiskConfigWithFilters(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkPacketCaptureExists(resourceName), + testCheckAzureRMNetworkPacketCaptureExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -203,7 +168,7 @@ func testCheckAzureRMNetworkPacketCaptureDestroy(s *terraform.State) error { return nil } -func testAzureRMNetworkPacketCapture_base(rInt int, location string) string { +func testAzureRMNetworkPacketCapture_base(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-watcher-%d" @@ -284,11 +249,11 @@ resource "azurerm_virtual_machine_extension" "test" { type_handler_version = "1.4" auto_upgrade_minor_version = true } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAzureRMNetworkPacketCapture_localDiskConfig(rInt int, location string) string { - config := testAzureRMNetworkPacketCapture_base(rInt, location) +func testAzureRMNetworkPacketCapture_localDiskConfig(data acceptance.TestData) string { + config := testAzureRMNetworkPacketCapture_base(data) return fmt.Sprintf(` %s @@ -304,11 +269,11 @@ resource "azurerm_network_packet_capture" "test" { depends_on = ["azurerm_virtual_machine_extension.test"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAzureRMNetworkPacketCapture_localDiskConfig_requiresImport(rInt int, location string) string { - config := testAzureRMNetworkPacketCapture_localDiskConfig(rInt, location) +func testAzureRMNetworkPacketCapture_localDiskConfig_requiresImport(data acceptance.TestData) string { + config := testAzureRMNetworkPacketCapture_localDiskConfig(data) return fmt.Sprintf(` %s @@ -327,8 +292,8 @@ resource "azurerm_network_packet_capture" "import" { `, config) } -func testAzureRMNetworkPacketCapture_localDiskConfigWithFilters(rInt int, location string) string { - config := testAzureRMNetworkPacketCapture_base(rInt, location) +func testAzureRMNetworkPacketCapture_localDiskConfigWithFilters(data acceptance.TestData) string { + config := testAzureRMNetworkPacketCapture_base(data) return fmt.Sprintf(` %s @@ -356,11 +321,11 @@ resource "azurerm_network_packet_capture" "test" { depends_on = ["azurerm_virtual_machine_extension.test"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAzureRMNetworkPacketCapture_storageAccountConfig(rInt int, rString string, location string) string { - config := testAzureRMNetworkPacketCapture_base(rInt, location) +func testAzureRMNetworkPacketCapture_storageAccountConfig(data acceptance.TestData) string { + config := testAzureRMNetworkPacketCapture_base(data) return fmt.Sprintf(` %s @@ -384,11 +349,11 @@ resource "azurerm_network_packet_capture" "test" { depends_on = ["azurerm_virtual_machine_extension.test"] } -`, config, rString, rInt) +`, config, data.RandomString, data.RandomInteger) } -func testAzureRMNetworkPacketCapture_storageAccountAndLocalDiskConfig(rInt int, rString string, location string) string { - config := testAzureRMNetworkPacketCapture_base(rInt, location) +func testAzureRMNetworkPacketCapture_storageAccountAndLocalDiskConfig(data acceptance.TestData) string { + config := testAzureRMNetworkPacketCapture_base(data) return fmt.Sprintf(` %s @@ -413,5 +378,5 @@ resource "azurerm_network_packet_capture" "test" { depends_on = ["azurerm_virtual_machine_extension.test"] } -`, config, rString, rInt) +`, config, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_network_profile_test.go b/azurerm/internal/services/network/tests/resource_arm_network_profile_test.go similarity index 78% rename from azurerm/internal/services/network/resource_arm_network_profile_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_profile_test.go index f6d74dbade57..ce0310a0d6b5 100644 --- a/azurerm/internal/services/network/resource_arm_network_profile_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_profile_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMNetworkProfile_basic(t *testing.T) { - resourceName := "azurerm_network_profile.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,17 +21,13 @@ func TestAccAzureRMNetworkProfile_basic(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkProfile_basic(ri, location), + Config: testAccAzureRMNetworkProfile_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkProfileExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "container_network_interface_ids.#"), + testCheckAzureRMNetworkProfileExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "container_network_interface_ids.#"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,9 +38,7 @@ func TestAccAzureRMNetworkProfile_requiresImport(t *testing.T) { return } - resourceName := "azurerm_network_profile.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,13 +46,13 @@ func TestAccAzureRMNetworkProfile_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkProfile_basic(ri, location), + Config: testAccAzureRMNetworkProfile_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkProfileExists(resourceName), + testCheckAzureRMNetworkProfileExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkProfile_requiresImport(ri, location), + Config: testAccAzureRMNetworkProfile_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_network_profile"), }, }, @@ -69,9 +60,7 @@ func TestAccAzureRMNetworkProfile_requiresImport(t *testing.T) { } func TestAccAzureRMNetworkProfile_withTags(t *testing.T) { - resourceName := "azurerm_network_profile.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,35 +68,29 @@ func TestAccAzureRMNetworkProfile_withTags(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkProfile_withTags(ri, location), + Config: testAccAzureRMNetworkProfile_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMNetworkProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { - Config: testAccAzureRMNetworkProfile_withUpdatedTags(ri, location), + Config: testAccAzureRMNetworkProfile_withUpdatedTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Staging"), + testCheckAzureRMNetworkProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Staging"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNetworkProfile_disappears(t *testing.T) { - resourceName := "azurerm_network_profile.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -115,10 +98,10 @@ func TestAccAzureRMNetworkProfile_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkProfile_basic(ri, location), + Config: testAccAzureRMNetworkProfile_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkProfileExists(resourceName), - testCheckAzureRMNetworkProfileDisappears(resourceName), + testCheckAzureRMNetworkProfileExists(data.ResourceName), + testCheckAzureRMNetworkProfileDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -206,7 +189,7 @@ func testCheckAzureRMNetworkProfileDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNetworkProfile_basic(rInt int, location string) string { +func testAccAzureRMNetworkProfile_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -250,11 +233,11 @@ resource "azurerm_network_profile" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkProfile_requiresImport(rInt int, location string) string { - basicConfig := testAccAzureRMNetworkProfile_basic(rInt, location) +func testAccAzureRMNetworkProfile_requiresImport(data acceptance.TestData) string { + basicConfig := testAccAzureRMNetworkProfile_basic(data) return fmt.Sprintf(` %s @@ -275,7 +258,7 @@ resource "azurerm_network_profile" "import" { `, basicConfig) } -func testAccAzureRMNetworkProfile_withTags(rInt int, location string) string { +func testAccAzureRMNetworkProfile_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -324,10 +307,10 @@ resource "azurerm_network_profile" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMNetworkProfile_withUpdatedTags(rInt int, location string) string { +func testAccAzureRMNetworkProfile_withUpdatedTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -375,5 +358,5 @@ resource "azurerm_network_profile" "test" { environment = "Staging" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_network_security_group_test.go b/azurerm/internal/services/network/tests/resource_arm_network_security_group_test.go similarity index 73% rename from azurerm/internal/services/network/resource_arm_network_security_group_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_security_group_test.go index 6a2e42f9871f..fb53016410e9 100644 --- a/azurerm/internal/services/network/resource_arm_network_security_group_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_security_group_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,24 +14,19 @@ import ( ) func TestAccAzureRMNetworkSecurityGroup_basic(t *testing.T) { - resourceName := "azurerm_network_security_group.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityGroup_basic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,22 +37,20 @@ func TestAccAzureRMNetworkSecurityGroup_requiresImport(t *testing.T) { return } - resourceName := "azurerm_network_security_group.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityGroup_basic(rInt, location), + Config: testAccAzureRMNetworkSecurityGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkSecurityGroup_requiresImport(rInt, location), + Config: testAccAzureRMNetworkSecurityGroup_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_network_security_group"), }, }, @@ -66,67 +58,60 @@ func TestAccAzureRMNetworkSecurityGroup_requiresImport(t *testing.T) { } func TestAccAzureRMNetworkSecurityGroup_singleRule(t *testing.T) { - resourceName := "azurerm_network_security_group.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityGroup_singleRule(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityGroup_singleRule(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNetworkSecurityGroup_update(t *testing.T) { - resourceName := "azurerm_network_security_group.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityGroup_singleRule(rInt, location), + Config: testAccAzureRMNetworkSecurityGroup_singleRule(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), // The configuration for this step contains one security_rule // block, which should now be reflected in the state. - resource.TestCheckResourceAttr(resourceName, "security_rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.#", "1"), ), }, { - Config: testAccAzureRMNetworkSecurityGroup_basic(rInt, location), + Config: testAccAzureRMNetworkSecurityGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), // The configuration for this step contains no security_rule // blocks at all, which means "ignore any existing security groups" // and thus the one from the previous step is preserved. - resource.TestCheckResourceAttr(resourceName, "security_rule.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.#", "1"), ), }, { - Config: testAccAzureRMNetworkSecurityGroup_rulesExplicitZero(rInt, location), + Config: testAccAzureRMNetworkSecurityGroup_rulesExplicitZero(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), // The configuration for this step assigns security_rule = [] // to state explicitly that no rules are desired, so the // rule from the first step should now be removed. - resource.TestCheckResourceAttr(resourceName, "security_rule.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.#", "0"), ), }, }, @@ -134,18 +119,17 @@ func TestAccAzureRMNetworkSecurityGroup_update(t *testing.T) { } func TestAccAzureRMNetworkSecurityGroup_disappears(t *testing.T) { - resourceName := "azurerm_network_security_group.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityGroup_basic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), - testCheckAzureRMNetworkSecurityGroupDisappears(resourceName), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), + testCheckAzureRMNetworkSecurityGroupDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -154,65 +138,55 @@ func TestAccAzureRMNetworkSecurityGroup_disappears(t *testing.T) { } func TestAccAzureRMNetworkSecurityGroup_withTags(t *testing.T) { - resourceName := "azurerm_network_security_group.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityGroup_withTags(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityGroup_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMNetworkSecurityGroup_withTagsUpdate(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityGroup_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNetworkSecurityGroup_addingExtraRules(t *testing.T) { - resourceName := "azurerm_network_security_group.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityGroup_singleRule(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityGroup_singleRule(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "security_rule.#", "1"), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.#", "1"), ), }, { - Config: testAccAzureRMNetworkSecurityGroup_anotherRule(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityGroup_anotherRule(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "security_rule.#", "2"), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.#", "2"), ), }, }, @@ -220,49 +194,39 @@ func TestAccAzureRMNetworkSecurityGroup_addingExtraRules(t *testing.T) { } func TestAccAzureRMNetworkSecurityGroup_augmented(t *testing.T) { - resourceName := "azurerm_network_security_group.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityGroup_augmented(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityGroup_augmented(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "security_rule.#", "1"), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNetworkSecurityGroup_applicationSecurityGroup(t *testing.T) { - resourceName := "azurerm_network_security_group.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityGroup_applicationSecurityGroup(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityGroup_applicationSecurityGroup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "security_rule.#", "1"), + testCheckAzureRMNetworkSecurityGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "security_rule.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -348,7 +312,7 @@ func testCheckAzureRMNetworkSecurityGroupDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNetworkSecurityGroup_basic(rInt int, location string) string { +func testAccAzureRMNetworkSecurityGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -360,11 +324,11 @@ resource "azurerm_network_security_group" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityGroup_requiresImport(rInt int, location string) string { - template := testAccAzureRMNetworkSecurityGroup_basic(rInt, location) +func testAccAzureRMNetworkSecurityGroup_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkSecurityGroup_basic(data) return fmt.Sprintf(` %s @@ -376,7 +340,7 @@ resource "azurerm_network_security_group" "test" { `, template) } -func testAccAzureRMNetworkSecurityGroup_rulesExplicitZero(rInt int, location string) string { +func testAccAzureRMNetworkSecurityGroup_rulesExplicitZero(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -390,10 +354,10 @@ resource "azurerm_network_security_group" "test" { security_rule = [] } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityGroup_singleRule(rInt int, location string) string { +func testAccAzureRMNetworkSecurityGroup_singleRule(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -417,10 +381,10 @@ resource "azurerm_network_security_group" "test" { destination_address_prefix = "*" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityGroup_anotherRule(rInt int, location string) string { +func testAccAzureRMNetworkSecurityGroup_anotherRule(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -456,10 +420,10 @@ resource "azurerm_network_security_group" "test" { destination_address_prefix = "*" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityGroup_withTags(rInt int, location string) string { +func testAccAzureRMNetworkSecurityGroup_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -488,10 +452,10 @@ resource "azurerm_network_security_group" "test" { cost_center = "MSFT" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityGroup_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMNetworkSecurityGroup_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -519,10 +483,10 @@ resource "azurerm_network_security_group" "test" { environment = "staging" } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityGroup_augmented(rInt int, location string) string { +func testAccAzureRMNetworkSecurityGroup_augmented(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -546,10 +510,10 @@ resource "azurerm_network_security_group" "test" { destination_address_prefixes = ["172.16.0.0/20", "8.8.8.8"] } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityGroup_applicationSecurityGroup(rInt int, location string) string { +func testAccAzureRMNetworkSecurityGroup_applicationSecurityGroup(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -585,5 +549,5 @@ resource "azurerm_network_security_group" "test" { destination_port_ranges = ["80", "443", "8080", "8190"] } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_network_security_rule_test.go b/azurerm/internal/services/network/tests/resource_arm_network_security_rule_test.go similarity index 84% rename from azurerm/internal/services/network/resource_arm_network_security_rule_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_security_rule_test.go index cbfb69c9fd4f..4675ce9208c1 100644 --- a/azurerm/internal/services/network/resource_arm_network_security_rule_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_security_rule_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,24 +15,19 @@ import ( ) func TestAccAzureRMNetworkSecurityRule_basic(t *testing.T) { - resourceName := "azurerm_network_security_rule.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityRule_basic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityRuleExists(resourceName), + testCheckAzureRMNetworkSecurityRuleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,9 +38,7 @@ func TestAccAzureRMNetworkSecurityRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_network_security_rule.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_security_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,13 +46,13 @@ func TestAccAzureRMNetworkSecurityRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityRule_basic(rInt, location), + Config: testAccAzureRMNetworkSecurityRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityRuleExists(resourceName), + testCheckAzureRMNetworkSecurityRuleExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkSecurityRule_requiresImport(rInt, location), + Config: testAccAzureRMNetworkSecurityRule_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_network_security_rule"), }, }, @@ -68,8 +60,7 @@ func TestAccAzureRMNetworkSecurityRule_requiresImport(t *testing.T) { } func TestAccAzureRMNetworkSecurityRule_disappears(t *testing.T) { - resourceGroup := "azurerm_network_security_rule.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -77,10 +68,10 @@ func TestAccAzureRMNetworkSecurityRule_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityRule_basic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityRule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityRuleExists(resourceGroup), - testCheckAzureRMNetworkSecurityRuleDisappears(resourceGroup), + testCheckAzureRMNetworkSecurityRuleExists(data.ResourceName), + testCheckAzureRMNetworkSecurityRuleDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -89,7 +80,7 @@ func TestAccAzureRMNetworkSecurityRule_disappears(t *testing.T) { } func TestAccAzureRMNetworkSecurityRule_addingRules(t *testing.T) { - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -97,14 +88,14 @@ func TestAccAzureRMNetworkSecurityRule_addingRules(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityRule_updateBasic(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityRule_updateBasic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkSecurityRuleExists("azurerm_network_security_rule.test1"), ), }, { - Config: testAccAzureRMNetworkSecurityRule_updateExtraRule(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityRule_updateExtraRule(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMNetworkSecurityRuleExists("azurerm_network_security_rule.test2"), ), @@ -114,47 +105,37 @@ func TestAccAzureRMNetworkSecurityRule_addingRules(t *testing.T) { } func TestAccAzureRMNetworkSecurityRule_augmented(t *testing.T) { - resourceName := "azurerm_network_security_rule.test1" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_rule", "test1") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityRule_augmented(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityRule_augmented(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityRuleExists(resourceName), + testCheckAzureRMNetworkSecurityRuleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMNetworkSecurityRule_applicationSecurityGroups(t *testing.T) { - resourceName := "azurerm_network_security_rule.test1" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_security_rule", "test1") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkSecurityRule_applicationSecurityGroups(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkSecurityRule_applicationSecurityGroups(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkSecurityRuleExists(resourceName), + testCheckAzureRMNetworkSecurityRuleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -242,7 +223,7 @@ func testCheckAzureRMNetworkSecurityRuleDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNetworkSecurityRule_basic(rInt int, location string) string { +func testAccAzureRMNetworkSecurityRule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -268,11 +249,11 @@ resource "azurerm_network_security_rule" "test" { source_address_prefix = "*" destination_address_prefix = "*" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityRule_requiresImport(rInt int, location string) string { - template := testAccAzureRMNetworkSecurityRule_basic(rInt, location) +func testAccAzureRMNetworkSecurityRule_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMNetworkSecurityRule_basic(data) return fmt.Sprintf(` %s @@ -292,7 +273,7 @@ resource "azurerm_network_security_rule" "import" { `, template) } -func testAccAzureRMNetworkSecurityRule_updateBasic(rInt int, location string) string { +func testAccAzureRMNetworkSecurityRule_updateBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test1" { name = "acctestRG-%d" @@ -318,10 +299,10 @@ resource "azurerm_network_security_rule" "test1" { resource_group_name = "${azurerm_resource_group.test1.name}" network_security_group_name = "${azurerm_network_security_group.test1.name}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityRule_updateExtraRule(rInt int, location string) string { +func testAccAzureRMNetworkSecurityRule_updateExtraRule(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test1" { name = "acctestRG-%d" @@ -361,10 +342,10 @@ resource "azurerm_network_security_rule" "test2" { resource_group_name = "${azurerm_resource_group.test1.name}" network_security_group_name = "${azurerm_network_security_group.test1.name}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityRule_augmented(rInt int, location string) string { +func testAccAzureRMNetworkSecurityRule_augmented(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test1" { name = "acctestRG-%d" @@ -390,10 +371,10 @@ resource "azurerm_network_security_rule" "test1" { resource_group_name = "${azurerm_resource_group.test1.name}" network_security_group_name = "${azurerm_network_security_group.test1.name}" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMNetworkSecurityRule_applicationSecurityGroups(rInt int, location string) string { +func testAccAzureRMNetworkSecurityRule_applicationSecurityGroups(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -431,5 +412,5 @@ resource "azurerm_network_security_rule" "test1" { source_port_ranges = ["10000-40000"] destination_port_ranges = ["80", "443", "8080", "8190"] } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_network_watcher_flow_log_test.go b/azurerm/internal/services/network/tests/resource_arm_network_watcher_flow_log_test.go new file mode 100644 index 000000000000..7ab6e605bc27 --- /dev/null +++ b/azurerm/internal/services/network/tests/resource_arm_network_watcher_flow_log_test.go @@ -0,0 +1,495 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network" + "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/clients" + nw "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" +) + +func testAccAzureRMNetworkWatcherFlowLog_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_watcher_flow_log", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkWatcherFlowLog_basicConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + ), + }, + data.ImportStep(), + }, + }) +} + +func testAccAzureRMNetworkWatcherFlowLog_disabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_watcher_flow_log", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkWatcherFlowLog_disabledConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "retention_policy.0.enabled"), + resource.TestCheckResourceAttrSet(data.ResourceName, "retention_policy.0.days"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), + ), + }, + // disabled flow logs don't import all values + }, + }) +} + +func testAccAzureRMNetworkWatcherFlowLog_reenabled(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_watcher_flow_log", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkWatcherFlowLog_disabledConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "retention_policy.0.enabled"), + resource.TestCheckResourceAttrSet(data.ResourceName, "retention_policy.0.days"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "false"), + ), + }, + { + Config: testAccAzureRMNetworkWatcherFlowLog_basicConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + ), + }, + data.ImportStep(), + }, + }) +} + +func testAccAzureRMNetworkWatcherFlowLog_retentionPolicy(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_watcher_flow_log", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkWatcherFlowLog_basicConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + ), + }, + data.ImportStep(), + }, + }) +} + +func testAccAzureRMNetworkWatcherFlowLog_updateStorageAccount(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_watcher_flow_log", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfigUpdateStorageAccount(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + ), + }, + data.ImportStep(), + }, + }) +} + +func testAccAzureRMNetworkWatcherFlowLog_trafficAnalytics(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_network_watcher_flow_log", "test") + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetworkWatcherFlowLog_basicConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsDisabledConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + ), + }, + { + Config: testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsEnabledConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_analytics.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "traffic_analytics.0.enabled", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "traffic_analytics.0.workspace_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "traffic_analytics.0.workspace_region"), + resource.TestCheckResourceAttrSet(data.ResourceName, "traffic_analytics.0.workspace_resource_id"), + ), + }, + data.ImportStep(), + // flow log must be disabled before destroy + { + Config: testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsDisabledConfig(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetworkWatcherFlowLogExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_watcher_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "storage_account_id"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_policy.0.days", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "enabled", "true"), + ), + }, + }, + }) +} + +func testCheckAzureRMNetworkWatcherFlowLogExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Network.WatcherClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + id, err := nw.ParseNetworkWatcherFlowLogID(rs.Primary.Attributes["id"]) + if err != nil { + return err + } + + statusParameters := network.FlowLogStatusParameters{ + TargetResourceID: &id.NetworkSecurityGroupID, + } + future, err := client.GetFlowLogStatus(ctx, id.ResourceGroup, id.NetworkWatcherName, statusParameters) + if err != nil { + return fmt.Errorf("Error retrieving Flow Log Configuration for target %q (Network Watcher %q / Resource Group %q): %+v", id.NetworkSecurityGroupID, id.NetworkWatcherName, id.ResourceGroup, err) + } + + if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for retrieval of Flow Log Configuration for target %q (Network Watcher %q / Resource Group %q): %+v", id.NetworkSecurityGroupID, id.NetworkWatcherName, id.ResourceGroup, err) + } + + if _, err := future.Result(*client); err != nil { + return fmt.Errorf("Error retrieving of Flow Log Configuration for target %q (Network Watcher %q / Resource Group %q): %+v", id.NetworkSecurityGroupID, id.NetworkWatcherName, id.ResourceGroup, err) + } + + return nil + } +} + +func testAccAzureRMNetworkWatcherFlowLog_prerequisites(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-watcher-%d" + location = "%s" +} + +resource "azurerm_network_security_group" "test" { + name = "acctestNSG%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_network_watcher" "test" { + name = "acctest-NW-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_storage_account" "test" { + name = "acctestsa%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + + account_tier = "Standard" + account_kind = "StorageV2" + account_replication_type = "LRS" + enable_https_traffic_only = true +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger%1000000) +} + +func testAccAzureRMNetworkWatcherFlowLog_basicConfig(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_network_watcher_flow_log" "test" { + network_watcher_name = "${azurerm_network_watcher.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + + network_security_group_id = "${azurerm_network_security_group.test.id}" + storage_account_id = "${azurerm_storage_account.test.id}" + enabled = true + + retention_policy { + enabled = false + days = 0 + } +} +`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(data)) +} + +func testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfig(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_network_watcher_flow_log" "test" { + network_watcher_name = "${azurerm_network_watcher.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + + network_security_group_id = "${azurerm_network_security_group.test.id}" + storage_account_id = "${azurerm_storage_account.test.id}" + enabled = true + + retention_policy { + enabled = true + days = 7 + } +} +`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(data)) +} + +func testAccAzureRMNetworkWatcherFlowLog_retentionPolicyConfigUpdateStorageAccount(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_storage_account" "testb" { + name = "acctestsab%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + + account_tier = "Standard" + account_kind = "StorageV2" + account_replication_type = "LRS" + enable_https_traffic_only = true +} + +resource "azurerm_network_watcher_flow_log" "test" { + network_watcher_name = "${azurerm_network_watcher.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + + network_security_group_id = "${azurerm_network_security_group.test.id}" + storage_account_id = "${azurerm_storage_account.testb.id}" + enabled = true + + retention_policy { + enabled = true + days = 7 + } +} +`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(data), data.RandomInteger%1000000+1) +} + +func testAccAzureRMNetworkWatcherFlowLog_disabledConfig(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_network_watcher_flow_log" "test" { + network_watcher_name = "${azurerm_network_watcher.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + + network_security_group_id = "${azurerm_network_security_group.test.id}" + storage_account_id = "${azurerm_storage_account.test.id}" + enabled = false + + retention_policy { + enabled = true + days = 7 + } +} +`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(data)) +} + +func testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsEnabledConfig(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_log_analytics_workspace" "test" { + name = "acctestLAW-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "PerGB2018" +} + +resource "azurerm_network_watcher_flow_log" "test" { + network_watcher_name = "${azurerm_network_watcher.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + + network_security_group_id = "${azurerm_network_security_group.test.id}" + storage_account_id = "${azurerm_storage_account.test.id}" + enabled = true + + retention_policy { + enabled = true + days = 7 + } + + traffic_analytics { + enabled = true + workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}" + workspace_region = "${azurerm_log_analytics_workspace.test.location}" + workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + } +} +`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(data), data.RandomInteger) +} + +func testAccAzureRMNetworkWatcherFlowLog_TrafficAnalyticsDisabledConfig(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_log_analytics_workspace" "test" { + name = "acctestLAW-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + sku = "PerGB2018" +} + +resource "azurerm_network_watcher_flow_log" "test" { + network_watcher_name = "${azurerm_network_watcher.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" + + network_security_group_id = "${azurerm_network_security_group.test.id}" + storage_account_id = "${azurerm_storage_account.test.id}" + enabled = true + + retention_policy { + enabled = true + days = 7 + } + + traffic_analytics { + enabled = false + workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}" + workspace_region = "${azurerm_log_analytics_workspace.test.location}" + workspace_resource_id = "${azurerm_log_analytics_workspace.test.id}" + } +} +`, testAccAzureRMNetworkWatcherFlowLog_prerequisites(data), data.RandomInteger) +} diff --git a/azurerm/internal/services/network/resource_arm_network_watcher_test.go b/azurerm/internal/services/network/tests/resource_arm_network_watcher_test.go similarity index 83% rename from azurerm/internal/services/network/resource_arm_network_watcher_test.go rename to azurerm/internal/services/network/tests/resource_arm_network_watcher_test.go index 371730507fa5..7c71482eb208 100644 --- a/azurerm/internal/services/network/resource_arm_network_watcher_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_network_watcher_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -91,24 +90,19 @@ func TestAccAzureRMNetworkWatcher(t *testing.T) { } func testAccAzureRMNetworkWatcher_basic(t *testing.T) { - resourceName := "azurerm_network_watcher.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_watcher", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkWatcher_basicConfig(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkWatcher_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherExists(resourceName), + testCheckAzureRMNetworkWatcherExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -119,22 +113,20 @@ func testAccAzureRMNetworkWatcher_requiresImport(t *testing.T) { return } - resourceName := "azurerm_network_watcher.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_network_watcher", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkWatcher_basicConfig(rInt, location), + Config: testAccAzureRMNetworkWatcher_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherExists(resourceName), + testCheckAzureRMNetworkWatcherExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkWatcher_requiresImportConfig(rInt, location), + Config: testAccAzureRMNetworkWatcher_requiresImportConfig(data), ExpectError: acceptance.RequiresImportError("azurerm_network_watcher"), }, }, @@ -142,31 +134,25 @@ func testAccAzureRMNetworkWatcher_requiresImport(t *testing.T) { } func testAccAzureRMNetworkWatcher_complete(t *testing.T) { - resourceName := "azurerm_network_watcher.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_watcher", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkWatcher_completeConfig(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkWatcher_completeConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherExists(resourceName), + testCheckAzureRMNetworkWatcherExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMNetworkWatcher_update(t *testing.T) { - resourceName := "azurerm_network_watcher.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_watcher", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,15 +160,15 @@ func testAccAzureRMNetworkWatcher_update(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkWatcher_basicConfig(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkWatcher_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherExists(resourceName), + testCheckAzureRMNetworkWatcherExists(data.ResourceName), ), }, { - Config: testAccAzureRMNetworkWatcher_completeConfig(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkWatcher_completeConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherExists(resourceName), + testCheckAzureRMNetworkWatcherExists(data.ResourceName), ), }, }, @@ -190,8 +176,7 @@ func testAccAzureRMNetworkWatcher_update(t *testing.T) { } func testAccAzureRMNetworkWatcher_disappears(t *testing.T) { - resourceName := "azurerm_network_watcher.test" - rInt := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_network_watcher", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -199,10 +184,10 @@ func testAccAzureRMNetworkWatcher_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMNetworkWatcherDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMNetworkWatcher_basicConfig(rInt, acceptance.Location()), + Config: testAccAzureRMNetworkWatcher_basicConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMNetworkWatcherExists(resourceName), - testCheckAzureRMNetworkWatcherDisappears(resourceName), + testCheckAzureRMNetworkWatcherExists(data.ResourceName), + testCheckAzureRMNetworkWatcherDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -291,7 +276,7 @@ func testCheckAzureRMNetworkWatcherDestroy(s *terraform.State) error { return nil } -func testAccAzureRMNetworkWatcher_basicConfig(rInt int, location string) string { +func testAccAzureRMNetworkWatcher_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-watcher-%d" @@ -303,11 +288,11 @@ resource "azurerm_network_watcher" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMNetworkWatcher_requiresImportConfig(rInt int, location string) string { - template := testAccAzureRMNetworkWatcher_basicConfig(rInt, location) +func testAccAzureRMNetworkWatcher_requiresImportConfig(data acceptance.TestData) string { + template := testAccAzureRMNetworkWatcher_basicConfig(data) return fmt.Sprintf(` %s @@ -319,7 +304,7 @@ resource "azurerm_network_watcher" "import" { `, template) } -func testAccAzureRMNetworkWatcher_completeConfig(rInt int, location string) string { +func testAccAzureRMNetworkWatcher_completeConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-watcher-%d" @@ -335,5 +320,5 @@ resource "azurerm_network_watcher" "test" { "Source" = "AccTests" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_packet_capture_test.go b/azurerm/internal/services/network/tests/resource_arm_packet_capture_test.go similarity index 78% rename from azurerm/internal/services/network/resource_arm_packet_capture_test.go rename to azurerm/internal/services/network/tests/resource_arm_packet_capture_test.go index 060bf0404a20..007225577d65 100644 --- a/azurerm/internal/services/network/resource_arm_packet_capture_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_packet_capture_test.go @@ -1,24 +1,19 @@ -package network +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func testAccAzureRMPacketCapture_localDisk(t *testing.T) { - resourceName := "azurerm_packet_capture.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_packet_capture", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,16 +21,12 @@ func testAccAzureRMPacketCapture_localDisk(t *testing.T) { CheckDestroy: testCheckAzureRMPacketCaptureDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPacketCapture_localDiskConfig(ri, location), + Config: testAzureRMPacketCapture_localDiskConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPacketCaptureExists(resourceName), + testCheckAzureRMPacketCaptureExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,10 +37,7 @@ func testAccAzureRMPacketCapture_requiresImport(t *testing.T) { return } - resourceName := "azurerm_packet_capture.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_packet_capture", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,24 +45,20 @@ func testAccAzureRMPacketCapture_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMPacketCaptureDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPacketCapture_localDiskConfig(ri, location), + Config: testAzureRMPacketCapture_localDiskConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPacketCaptureExists(resourceName), + testCheckAzureRMPacketCaptureExists(data.ResourceName), ), }, { - Config: testAzureRMPacketCapture_localDiskConfig_requiresImport(ri, location), + Config: testAzureRMPacketCapture_localDiskConfig_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_packet_capture"), }, }, }) } func testAccAzureRMPacketCapture_storageAccount(t *testing.T) { - resourceName := "azurerm_packet_capture.test" - - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_packet_capture", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,26 +66,18 @@ func testAccAzureRMPacketCapture_storageAccount(t *testing.T) { CheckDestroy: testCheckAzureRMPacketCaptureDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPacketCapture_storageAccountConfig(ri, rs, location), + Config: testAzureRMPacketCapture_storageAccountConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPacketCaptureExists(resourceName), + testCheckAzureRMPacketCaptureExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMPacketCapture_storageAccountAndLocalDisk(t *testing.T) { - resourceName := "azurerm_packet_capture.test" - - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_packet_capture", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -109,25 +85,18 @@ func testAccAzureRMPacketCapture_storageAccountAndLocalDisk(t *testing.T) { CheckDestroy: testCheckAzureRMPacketCaptureDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPacketCapture_storageAccountAndLocalDiskConfig(ri, rs, location), + Config: testAzureRMPacketCapture_storageAccountAndLocalDiskConfig(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPacketCaptureExists(resourceName), + testCheckAzureRMPacketCaptureExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMPacketCapture_withFilters(t *testing.T) { - resourceName := "azurerm_packet_capture.test" - - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_packet_capture", "test") resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -135,16 +104,12 @@ func testAccAzureRMPacketCapture_withFilters(t *testing.T) { CheckDestroy: testCheckAzureRMPacketCaptureDestroy, Steps: []resource.TestStep{ { - Config: testAzureRMPacketCapture_localDiskConfigWithFilters(ri, location), + Config: testAzureRMPacketCapture_localDiskConfigWithFilters(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPacketCaptureExists(resourceName), + testCheckAzureRMPacketCaptureExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -203,7 +168,7 @@ func testCheckAzureRMPacketCaptureDestroy(s *terraform.State) error { return nil } -func testAzureRMPacketCapture_base(rInt int, location string) string { +func testAzureRMPacketCapture_base(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -284,11 +249,11 @@ resource "azurerm_virtual_machine_extension" "test" { type_handler_version = "1.4" auto_upgrade_minor_version = true } -`, rInt, location, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAzureRMPacketCapture_localDiskConfig(rInt int, location string) string { - config := testAzureRMPacketCapture_base(rInt, location) +func testAzureRMPacketCapture_localDiskConfig(data acceptance.TestData) string { + config := testAzureRMPacketCapture_base(data) return fmt.Sprintf(` %s @@ -304,11 +269,11 @@ resource "azurerm_packet_capture" "test" { depends_on = ["azurerm_virtual_machine_extension.test"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAzureRMPacketCapture_localDiskConfig_requiresImport(rInt int, location string) string { - config := testAzureRMPacketCapture_localDiskConfig(rInt, location) +func testAzureRMPacketCapture_localDiskConfig_requiresImport(data acceptance.TestData) string { + config := testAzureRMPacketCapture_localDiskConfig(data) return fmt.Sprintf(` %s @@ -327,8 +292,8 @@ resource "azurerm_packet_capture" "import" { `, config) } -func testAzureRMPacketCapture_localDiskConfigWithFilters(rInt int, location string) string { - config := testAzureRMPacketCapture_base(rInt, location) +func testAzureRMPacketCapture_localDiskConfigWithFilters(data acceptance.TestData) string { + config := testAzureRMPacketCapture_base(data) return fmt.Sprintf(` %s @@ -356,11 +321,11 @@ resource "azurerm_packet_capture" "test" { depends_on = ["azurerm_virtual_machine_extension.test"] } -`, config, rInt) +`, config, data.RandomInteger) } -func testAzureRMPacketCapture_storageAccountConfig(rInt int, rString string, location string) string { - config := testAzureRMPacketCapture_base(rInt, location) +func testAzureRMPacketCapture_storageAccountConfig(data acceptance.TestData) string { + config := testAzureRMPacketCapture_base(data) return fmt.Sprintf(` %s @@ -384,11 +349,11 @@ resource "azurerm_packet_capture" "test" { depends_on = ["azurerm_virtual_machine_extension.test"] } -`, config, rString, rInt) +`, config, data.RandomString, data.RandomInteger) } -func testAzureRMPacketCapture_storageAccountAndLocalDiskConfig(rInt int, rString string, location string) string { - config := testAzureRMPacketCapture_base(rInt, location) +func testAzureRMPacketCapture_storageAccountAndLocalDiskConfig(data acceptance.TestData) string { + config := testAzureRMPacketCapture_base(data) return fmt.Sprintf(` %s @@ -413,5 +378,5 @@ resource "azurerm_packet_capture" "test" { depends_on = ["azurerm_virtual_machine_extension.test"] } -`, config, rString, rInt) +`, config, data.RandomString, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_point_to_site_vpn_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go similarity index 78% rename from azurerm/internal/services/network/resource_arm_point_to_site_vpn_gateway_test.go rename to azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go index 03cf143c4f78..b63f080d2a45 100644 --- a/azurerm/internal/services/network/resource_arm_point_to_site_vpn_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMPointToSiteVPNGateway_basic(t *testing.T) { - resourceName := "azurerm_point_to_site_vpn_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_point_to_site_vpn_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +21,12 @@ func TestAccAzureRMPointToSiteVPNGateway_basic(t *testing.T) { CheckDestroy: testCheckAzureRMPointToSiteVPNGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAzureRMPointToSiteVPNGateway_basic(ri, location), + Config: testAccAzureRMAzureRMPointToSiteVPNGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPointToSiteVPNGatewayExists(resourceName), + testCheckAzureRMPointToSiteVPNGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,9 +37,7 @@ func TestAccAzureRMPointToSiteVPNGateway_requiresImport(t *testing.T) { return } - resourceName := "azurerm_point_to_site_vpn_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_point_to_site_vpn_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,13 +45,13 @@ func TestAccAzureRMPointToSiteVPNGateway_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMPointToSiteVPNGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAzureRMPointToSiteVPNGateway_basic(ri, location), + Config: testAccAzureRMAzureRMPointToSiteVPNGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPointToSiteVPNGatewayExists(resourceName), + testCheckAzureRMPointToSiteVPNGatewayExists(data.ResourceName), ), }, { - Config: testAccAzureRMAzureRMPointToSiteVPNGateway_requiresImport(ri, location), + Config: testAccAzureRMAzureRMPointToSiteVPNGateway_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_point_to_site_vpn_gateway"), }, }, @@ -68,9 +59,7 @@ func TestAccAzureRMPointToSiteVPNGateway_requiresImport(t *testing.T) { } func TestAccAzureRMPointToSiteVPNGateway_update(t *testing.T) { - resourceName := "azurerm_point_to_site_vpn_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_point_to_site_vpn_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,35 +67,25 @@ func TestAccAzureRMPointToSiteVPNGateway_update(t *testing.T) { CheckDestroy: testCheckAzureRMPointToSiteVPNGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAzureRMPointToSiteVPNGateway_basic(ri, location), + Config: testAccAzureRMAzureRMPointToSiteVPNGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPointToSiteVPNGatewayExists(resourceName), + testCheckAzureRMPointToSiteVPNGatewayExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAzureRMPointToSiteVPNGateway_updated(ri, location), + Config: testAccAzureRMAzureRMPointToSiteVPNGateway_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPointToSiteVPNGatewayExists(resourceName), + testCheckAzureRMPointToSiteVPNGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPointToSiteVPNGateway_tags(t *testing.T) { - resourceName := "azurerm_point_to_site_vpn_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_point_to_site_vpn_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,16 +93,12 @@ func TestAccAzureRMPointToSiteVPNGateway_tags(t *testing.T) { CheckDestroy: testCheckAzureRMPointToSiteVPNGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAzureRMPointToSiteVPNGateway_tags(ri, location), + Config: testAccAzureRMAzureRMPointToSiteVPNGateway_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPointToSiteVPNGatewayExists(resourceName), + testCheckAzureRMPointToSiteVPNGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -176,8 +151,8 @@ func testCheckAzureRMPointToSiteVPNGatewayDestroy(s *terraform.State) error { return nil } -func testAccAzureRMAzureRMPointToSiteVPNGateway_basic(rInt int, location string) string { - template := testAccAzureRMAzureRMPointToSiteVPNGateway_template(rInt, location) +func testAccAzureRMAzureRMPointToSiteVPNGateway_basic(data acceptance.TestData) string { + template := testAccAzureRMAzureRMPointToSiteVPNGateway_template(data) return fmt.Sprintf(` %s @@ -196,11 +171,11 @@ resource "azurerm_point_to_site_vpn_gateway" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAzureRMPointToSiteVPNGateway_updated(rInt int, location string) string { - template := testAccAzureRMAzureRMPointToSiteVPNGateway_template(rInt, location) +func testAccAzureRMAzureRMPointToSiteVPNGateway_updated(data acceptance.TestData) string { + template := testAccAzureRMAzureRMPointToSiteVPNGateway_template(data) return fmt.Sprintf(` %s @@ -219,11 +194,11 @@ resource "azurerm_point_to_site_vpn_gateway" "test" { } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAzureRMPointToSiteVPNGateway_requiresImport(rInt int, location string) string { - template := testAccAzureRMAzureRMPointToSiteVPNGateway_basic(rInt, location) +func testAccAzureRMAzureRMPointToSiteVPNGateway_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAzureRMPointToSiteVPNGateway_basic(data) return fmt.Sprintf(` %s @@ -245,8 +220,8 @@ resource "azurerm_point_to_site_vpn_gateway" "import" { `, template) } -func testAccAzureRMAzureRMPointToSiteVPNGateway_tags(rInt int, location string) string { - template := testAccAzureRMAzureRMPointToSiteVPNGateway_template(rInt, location) +func testAccAzureRMAzureRMPointToSiteVPNGateway_tags(data acceptance.TestData) string { + template := testAccAzureRMAzureRMPointToSiteVPNGateway_template(data) return fmt.Sprintf(` %s @@ -269,10 +244,10 @@ resource "azurerm_point_to_site_vpn_gateway" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAzureRMPointToSiteVPNGateway_template(rInt int, location string) string { +func testAccAzureRMAzureRMPointToSiteVPNGateway_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -326,5 +301,5 @@ M/s/1JRtO3bDSzD9TazRVzn2oBqzSa8VgIo5C1nOnoAKJTlsClJKvIhnRlaLQqk= EOF } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_private_endpoint_test.go b/azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go similarity index 75% rename from azurerm/internal/services/network/resource_arm_private_endpoint_test.go rename to azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go index 13736defac4e..91e671575a1b 100644 --- a/azurerm/internal/services/network/resource_arm_private_endpoint_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_private_endpoint_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,16 +6,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMPrivateEndpoint_basic(t *testing.T) { - resourceName := "azurerm_private_endpoint.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_private_endpoint", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,25 +20,19 @@ func TestAccAzureRMPrivateEndpoint_basic(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateEndpointDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateEndpoint_basic(ri, location), + Config: testAccAzureRMPrivateEndpoint_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateEndpointExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subnet_id"), + testCheckAzureRMPrivateEndpointExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPrivateEndpoint_requestMessage(t *testing.T) { - resourceName := "azurerm_private_endpoint.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_private_endpoint", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -49,31 +40,23 @@ func TestAccAzureRMPrivateEndpoint_requestMessage(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateEndpointDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateEndpoint_requestMessage(ri, location, "CATS: ALL YOUR BASE ARE BELONG TO US."), + Config: testAccAzureRMPrivateEndpoint_requestMessage(data, "CATS: ALL YOUR BASE ARE BELONG TO US."), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateEndpointExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subnet_id"), - resource.TestCheckResourceAttr(resourceName, "private_service_connection.0.request_message", "CATS: ALL YOUR BASE ARE BELONG TO US."), + testCheckAzureRMPrivateEndpointExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "private_service_connection.0.request_message", "CATS: ALL YOUR BASE ARE BELONG TO US."), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMPrivateEndpoint_requestMessage(ri, location, "CAPTAIN: WHAT YOU SAY!!"), + Config: testAccAzureRMPrivateEndpoint_requestMessage(data, "CAPTAIN: WHAT YOU SAY!!"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateEndpointExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subnet_id"), - resource.TestCheckResourceAttr(resourceName, "private_service_connection.0.request_message", "CAPTAIN: WHAT YOU SAY!!"), + testCheckAzureRMPrivateEndpointExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "private_service_connection.0.request_message", "CAPTAIN: WHAT YOU SAY!!"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -130,7 +113,7 @@ func testCheckAzureRMPrivateEndpointDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPrivateEndpointTemplate_template(rInt int, location string, seviceCfg string) string { +func testAccAzureRMPrivateEndpointTemplate_template(data acceptance.TestData, seviceCfg string) string { return fmt.Sprintf(` data "azurerm_subscription" "current" {} @@ -184,10 +167,10 @@ resource "azurerm_lb" "test" { } %s -`, rInt, location, rInt, rInt, rInt, rInt, rInt, seviceCfg) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, seviceCfg) } -func testAccAzureRMPrivateEndpoint_serviceAutoApprove(rInt int) string { +func testAccAzureRMPrivateEndpoint_serviceAutoApprove(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_private_link_service" "test" { name = "acctestPLS-%d" @@ -206,10 +189,10 @@ resource "azurerm_private_link_service" "test" { azurerm_lb.test.frontend_ip_configuration.0.id ] } -`, rInt, rInt) +`, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateEndpoint_serviceManualApprove(rInt int) string { +func testAccAzureRMPrivateEndpoint_serviceManualApprove(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_private_link_service" "test" { name = "acctestPLS-%d" @@ -226,10 +209,10 @@ resource "azurerm_private_link_service" "test" { azurerm_lb.test.frontend_ip_configuration.0.id ] } -`, rInt, rInt) +`, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateEndpoint_basic(rInt int, location string) string { +func testAccAzureRMPrivateEndpoint_basic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -245,10 +228,10 @@ resource "azurerm_private_endpoint" "test" { private_connection_resource_id = azurerm_private_link_service.test.id } } -`, testAccAzureRMPrivateEndpointTemplate_template(rInt, location, testAccAzureRMPrivateEndpoint_serviceAutoApprove(rInt)), rInt) +`, testAccAzureRMPrivateEndpointTemplate_template(data, testAccAzureRMPrivateEndpoint_serviceAutoApprove(data)), data.RandomInteger) } -func testAccAzureRMPrivateEndpoint_requestMessage(rInt int, location string, msg string) string { +func testAccAzureRMPrivateEndpoint_requestMessage(data acceptance.TestData, msg string) string { return fmt.Sprintf(` %s @@ -265,5 +248,5 @@ resource "azurerm_private_endpoint" "test" { request_message = %q } } -`, testAccAzureRMPrivateEndpointTemplate_template(rInt, location, testAccAzureRMPrivateEndpoint_serviceManualApprove(rInt)), rInt, msg) +`, testAccAzureRMPrivateEndpointTemplate_template(data, testAccAzureRMPrivateEndpoint_serviceManualApprove(data)), data.RandomInteger, msg) } diff --git a/azurerm/internal/services/network/resource_arm_private_link_endpoint_test.go b/azurerm/internal/services/network/tests/resource_arm_private_link_endpoint_test.go similarity index 54% rename from azurerm/internal/services/network/resource_arm_private_link_endpoint_test.go rename to azurerm/internal/services/network/tests/resource_arm_private_link_endpoint_test.go index bb20d1a94279..60749548ec85 100644 --- a/azurerm/internal/services/network/resource_arm_private_link_endpoint_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_private_link_endpoint_test.go @@ -1,18 +1,15 @@ -package network +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMPrivateLinkEndpoint_basic(t *testing.T) { - resourceName := "azurerm_private_link_endpoint.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_private_link_endpoint", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,25 +17,19 @@ func TestAccAzureRMPrivateLinkEndpoint_basic(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateEndpointDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateLinkEndpoint_basic(ri, location), + Config: testAccAzureRMPrivateLinkEndpoint_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateEndpointExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subnet_id"), + testCheckAzureRMPrivateEndpointExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPrivateLinkEndpoint_requestMessage(t *testing.T) { - resourceName := "azurerm_private_link_endpoint.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_private_link_endpoint", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -46,31 +37,23 @@ func TestAccAzureRMPrivateLinkEndpoint_requestMessage(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateEndpointDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateLinkEndpoint_requestMessage(ri, location, "CATS: ALL YOUR BASE ARE BELONG TO US."), + Config: testAccAzureRMPrivateLinkEndpoint_requestMessage(data, "CATS: ALL YOUR BASE ARE BELONG TO US."), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateEndpointExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subnet_id"), - resource.TestCheckResourceAttr(resourceName, "private_service_connection.0.request_message", "CATS: ALL YOUR BASE ARE BELONG TO US."), + testCheckAzureRMPrivateEndpointExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "private_service_connection.0.request_message", "CATS: ALL YOUR BASE ARE BELONG TO US."), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMPrivateLinkEndpoint_requestMessage(ri, location, "CAPTAIN: WHAT YOU SAY!!"), + Config: testAccAzureRMPrivateLinkEndpoint_requestMessage(data, "CAPTAIN: WHAT YOU SAY!!"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateEndpointExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "subnet_id"), - resource.TestCheckResourceAttr(resourceName, "private_service_connection.0.request_message", "CAPTAIN: WHAT YOU SAY!!"), + testCheckAzureRMPrivateEndpointExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "private_service_connection.0.request_message", "CAPTAIN: WHAT YOU SAY!!"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -79,7 +62,7 @@ func TestAccAzureRMPrivateLinkEndpoint_requestMessage(t *testing.T) { // tags has been removed, all other attributes are ForceNew. // API Issue "Unable to remove Tags from Private Link Endpoint": https://github.com/Azure/azure-sdk-for-go/issues/6467 -func testAccAzureRMPrivateLinkEndpoint_basic(rInt int, location string) string { +func testAccAzureRMPrivateLinkEndpoint_basic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -95,10 +78,10 @@ resource "azurerm_private_link_endpoint" "test" { private_connection_resource_id = azurerm_private_link_service.test.id } } -`, testAccAzureRMPrivateEndpointTemplate_template(rInt, location, testAccAzureRMPrivateEndpoint_serviceAutoApprove(rInt)), rInt) +`, testAccAzureRMPrivateEndpointTemplate_template(data, testAccAzureRMPrivateEndpoint_serviceAutoApprove(data)), data.RandomInteger) } -func testAccAzureRMPrivateLinkEndpoint_requestMessage(rInt int, location string, msg string) string { +func testAccAzureRMPrivateLinkEndpoint_requestMessage(data acceptance.TestData, msg string) string { return fmt.Sprintf(` %s @@ -115,5 +98,5 @@ resource "azurerm_private_link_endpoint" "test" { request_message = %q } } -`, testAccAzureRMPrivateEndpointTemplate_template(rInt, location, testAccAzureRMPrivateEndpoint_serviceManualApprove(rInt)), rInt, msg) +`, testAccAzureRMPrivateEndpointTemplate_template(data, testAccAzureRMPrivateEndpoint_serviceManualApprove(data)), data.RandomInteger, msg) } diff --git a/azurerm/internal/services/network/resource_arm_private_link_service_test.go b/azurerm/internal/services/network/tests/resource_arm_private_link_service_test.go similarity index 68% rename from azurerm/internal/services/network/resource_arm_private_link_service_test.go rename to azurerm/internal/services/network/tests/resource_arm_private_link_service_test.go index 0b7deb74bde4..ab88adc7122f 100644 --- a/azurerm/internal/services/network/resource_arm_private_link_service_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_private_link_service_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMPrivateLinkService_basic(t *testing.T) { - resourceName := "azurerm_private_link_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_private_link_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,19 +21,15 @@ func TestAccAzureRMPrivateLinkService_basic(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateLinkServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateLinkService_basic(ri, location), + Config: testAccAzureRMPrivateLinkService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctestPLS-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctestPLS-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,9 +40,7 @@ func TestAccAzureRMPrivateLinkService_requiresImport(t *testing.T) { return } - resourceName := "azurerm_private_link_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_private_link_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,13 +48,13 @@ func TestAccAzureRMPrivateLinkService_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateLinkServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateLinkService_basic(ri, location), + Config: testAccAzureRMPrivateLinkService_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), ), }, { - Config: testAccAzureRMPrivateLinkService_requiresImport(ri, location), + Config: testAccAzureRMPrivateLinkService_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_private_link_service"), }, }, @@ -71,9 +62,7 @@ func TestAccAzureRMPrivateLinkService_requiresImport(t *testing.T) { } func TestAccAzureRMPrivateLinkService_update(t *testing.T) { - resourceName := "azurerm_private_link_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_private_link_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,55 +70,41 @@ func TestAccAzureRMPrivateLinkService_update(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateLinkServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateLinkService_basicIp(ri, location), + Config: testAccAzureRMPrivateLinkService_basicIp(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMPrivateLinkService_update(ri, location), + Config: testAccAzureRMPrivateLinkService_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.#", "4"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.0.primary", "true"), - resource.TestCheckResourceAttr(resourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.0.primary", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMPrivateLinkService_basicIp(ri, location), + Config: testAccAzureRMPrivateLinkService_basicIp(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPrivateLinkService_move(t *testing.T) { - resourceName := "azurerm_private_link_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_private_link_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -137,90 +112,68 @@ func TestAccAzureRMPrivateLinkService_move(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateLinkServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateLinkService_moveSetup(ri, location), + Config: testAccAzureRMPrivateLinkService_moveSetup(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.#", "1"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.0.private_ip_address", "10.5.2.17"), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.0.private_ip_address", "10.5.2.17"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMPrivateLinkService_moveAdd(ri, location), + Config: testAccAzureRMPrivateLinkService_moveAdd(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.#", "4"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.0.private_ip_address", "10.5.2.17"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.1.private_ip_address", "10.5.2.18"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.2.private_ip_address", "10.5.2.19"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.3.private_ip_address", "10.5.2.20"), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.0.private_ip_address", "10.5.2.17"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.1.private_ip_address", "10.5.2.18"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.2.private_ip_address", "10.5.2.19"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.3.private_ip_address", "10.5.2.20"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMPrivateLinkService_moveChangeOne(ri, location), + Config: testAccAzureRMPrivateLinkService_moveChangeOne(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.#", "4"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.0.private_ip_address", "10.5.2.17"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.1.private_ip_address", "10.5.2.18"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.2.private_ip_address", "10.5.2.19"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.3.private_ip_address", "10.5.2.21"), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.0.private_ip_address", "10.5.2.17"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.1.private_ip_address", "10.5.2.18"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.2.private_ip_address", "10.5.2.19"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.3.private_ip_address", "10.5.2.21"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMPrivateLinkService_moveChangeTwo(ri, location), + Config: testAccAzureRMPrivateLinkService_moveChangeTwo(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.#", "4"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.0.private_ip_address", "10.5.2.17"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.1.private_ip_address", "10.5.2.20"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.2.private_ip_address", "10.5.2.19"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.3.private_ip_address", "10.5.2.21"), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.0.private_ip_address", "10.5.2.17"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.1.private_ip_address", "10.5.2.20"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.2.private_ip_address", "10.5.2.19"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.3.private_ip_address", "10.5.2.21"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMPrivateLinkService_moveChangeThree(ri, location), + Config: testAccAzureRMPrivateLinkService_moveChangeThree(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.#", "4"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.0.private_ip_address", "10.5.2.17"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.1.private_ip_address", "10.5.2.20"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.2.private_ip_address", "10.5.2.19"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.3.private_ip_address", "10.5.2.18"), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.0.private_ip_address", "10.5.2.17"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.1.private_ip_address", "10.5.2.20"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.2.private_ip_address", "10.5.2.19"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.3.private_ip_address", "10.5.2.18"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPrivateLinkService_enableProxyProtocol(t *testing.T) { - resourceName := "azurerm_private_link_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_private_link_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -229,48 +182,34 @@ func TestAccAzureRMPrivateLinkService_enableProxyProtocol(t *testing.T) { Steps: []resource.TestStep{ { // Enable - Config: testAccAzureRMPrivateLinkService_enableProxyProtocol(ri, location, true), + Config: testAccAzureRMPrivateLinkService_enableProxyProtocol(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { // Disable - Config: testAccAzureRMPrivateLinkService_enableProxyProtocol(ri, location, false), + Config: testAccAzureRMPrivateLinkService_enableProxyProtocol(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { // Enable - Config: testAccAzureRMPrivateLinkService_enableProxyProtocol(ri, location, true), + Config: testAccAzureRMPrivateLinkService_enableProxyProtocol(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPrivateLinkService_complete(t *testing.T) { - resourceName := "azurerm_private_link_service.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_private_link_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -278,26 +217,22 @@ func TestAccAzureRMPrivateLinkService_complete(t *testing.T) { CheckDestroy: testCheckAzureRMPrivateLinkServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPrivateLinkService_complete(ri, location), + Config: testAccAzureRMPrivateLinkService_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPrivateLinkServiceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "auto_approval_subscription_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "visibility_subscription_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.#", "2"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.0.private_ip_address", "10.5.1.40"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.0.private_ip_address_version", "IPv4"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.1.private_ip_address", "10.5.1.41"), - resource.TestCheckResourceAttr(resourceName, "nat_ip_configuration.1.private_ip_address_version", "IPv4"), - resource.TestCheckResourceAttr(resourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.env", "test"), + testCheckAzureRMPrivateLinkServiceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "auto_approval_subscription_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "visibility_subscription_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.0.private_ip_address", "10.5.1.40"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.0.private_ip_address_version", "IPv4"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.1.private_ip_address", "10.5.1.41"), + resource.TestCheckResourceAttr(data.ResourceName, "nat_ip_configuration.1.private_ip_address_version", "IPv4"), + resource.TestCheckResourceAttr(data.ResourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.env", "test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -350,8 +285,8 @@ func testCheckAzureRMPrivateLinkServiceDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPrivateLinkService_basic(rInt int, location string) string { - template := testAccAzureRMPrivateLinkService_template(rInt, location) +func testAccAzureRMPrivateLinkService_basic(data acceptance.TestData) string { + template := testAccAzureRMPrivateLinkService_template(data) return fmt.Sprintf(` %s @@ -379,10 +314,10 @@ resource "azurerm_private_link_service" "test" { azurerm_lb.test.frontend_ip_configuration.0.id ] } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_basicIp(rInt int, location string) string { +func testAccAzureRMPrivateLinkService_basicIp(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -412,11 +347,11 @@ resource "azurerm_private_link_service" "test" { azurerm_lb.test.frontend_ip_configuration.0.id ] } -`, testAccAzureRMPrivateLinkService_template(rInt, location), rInt, rInt, rInt) +`, testAccAzureRMPrivateLinkService_template(data), data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_requiresImport(rInt int, location string) string { - template := testAccAzureRMPrivateLinkService_basic(rInt, location) +func testAccAzureRMPrivateLinkService_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMPrivateLinkService_basic(data) return fmt.Sprintf(` %s @@ -435,11 +370,11 @@ resource "azurerm_private_link_service" "import" { azurerm_lb.test.frontend_ip_configuration.0.id ] } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_enableProxyProtocol(rInt int, location string, enabled bool) string { - template := testAccAzureRMPrivateLinkService_template(rInt, location) +func testAccAzureRMPrivateLinkService_enableProxyProtocol(data acceptance.TestData, enabled bool) string { + template := testAccAzureRMPrivateLinkService_template(data) return fmt.Sprintf(` %s @@ -468,11 +403,11 @@ resource "azurerm_private_link_service" "test" { azurerm_lb.test.frontend_ip_configuration.0.id ] } -`, template, rInt, rInt, enabled, rInt) +`, template, data.RandomInteger, data.RandomInteger, enabled, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_update(rInt int, location string) string { - template := testAccAzureRMPrivateLinkService_template(rInt, location) +func testAccAzureRMPrivateLinkService_update(data acceptance.TestData) string { + template := testAccAzureRMPrivateLinkService_template(data) return fmt.Sprintf(` %s @@ -532,11 +467,11 @@ resource "azurerm_private_link_service" "test" { env = "test" } } -`, template, rInt, rInt, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_moveSetup(rInt int, location string) string { - template := testAccAzureRMPrivateLinkService_template(rInt, location) +func testAccAzureRMPrivateLinkService_moveSetup(data acceptance.TestData) string { + template := testAccAzureRMPrivateLinkService_template(data) return fmt.Sprintf(` %s @@ -572,11 +507,11 @@ resource "azurerm_private_link_service" "test" { env = "test" } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_moveAdd(rInt int, location string) string { - template := testAccAzureRMPrivateLinkService_template(rInt, location) +func testAccAzureRMPrivateLinkService_moveAdd(data acceptance.TestData) string { + template := testAccAzureRMPrivateLinkService_template(data) return fmt.Sprintf(` %s @@ -636,11 +571,11 @@ resource "azurerm_private_link_service" "test" { env = "test" } } -`, template, rInt, rInt, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_moveChangeOne(rInt int, location string) string { - template := testAccAzureRMPrivateLinkService_template(rInt, location) +func testAccAzureRMPrivateLinkService_moveChangeOne(data acceptance.TestData) string { + template := testAccAzureRMPrivateLinkService_template(data) return fmt.Sprintf(` %s @@ -700,11 +635,11 @@ resource "azurerm_private_link_service" "test" { env = "test" } } -`, template, rInt, rInt, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_moveChangeTwo(rInt int, location string) string { - template := testAccAzureRMPrivateLinkService_template(rInt, location) +func testAccAzureRMPrivateLinkService_moveChangeTwo(data acceptance.TestData) string { + template := testAccAzureRMPrivateLinkService_template(data) return fmt.Sprintf(` %s @@ -764,11 +699,11 @@ resource "azurerm_private_link_service" "test" { env = "test" } } -`, template, rInt, rInt, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_moveChangeThree(rInt int, location string) string { - template := testAccAzureRMPrivateLinkService_template(rInt, location) +func testAccAzureRMPrivateLinkService_moveChangeThree(data acceptance.TestData) string { + template := testAccAzureRMPrivateLinkService_template(data) return fmt.Sprintf(` %s @@ -828,11 +763,11 @@ resource "azurerm_private_link_service" "test" { env = "test" } } -`, template, rInt, rInt, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_complete(rInt int, location string) string { - template := testAccAzureRMPrivateLinkService_template(rInt, location) +func testAccAzureRMPrivateLinkService_complete(data acceptance.TestData) string { + template := testAccAzureRMPrivateLinkService_template(data) return fmt.Sprintf(` %s @@ -876,10 +811,10 @@ resource "azurerm_private_link_service" "test" { env = "test" } } -`, template, rInt, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPrivateLinkService_template(rInt int, location string) string { +func testAccAzureRMPrivateLinkService_template(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_subscription" "current" {} @@ -914,5 +849,5 @@ resource "azurerm_lb" "test" { public_ip_address_id = azurerm_public_ip.test.id } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_public_ip_prefix_test.go b/azurerm/internal/services/network/tests/resource_arm_public_ip_prefix_test.go similarity index 72% rename from azurerm/internal/services/network/resource_arm_public_ip_prefix_test.go rename to azurerm/internal/services/network/tests/resource_arm_public_ip_prefix_test.go index b27930041ece..ce2f6c9963c0 100644 --- a/azurerm/internal/services/network/resource_arm_public_ip_prefix_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_public_ip_prefix_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) @@ -98,9 +97,8 @@ func testCheckAzureRMPublicIPPrefixDestroy(s *terraform.State) error { } func TestAccAzureRMPublicIpPrefix_basic(t *testing.T) { - resourceName := "azurerm_public_ip_prefix.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPPrefix_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_public_ip_prefix", "test") + config := testAccAzureRMPublicIPPrefix_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -110,24 +108,19 @@ func TestAccAzureRMPublicIpPrefix_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIPPrefixExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_prefix"), - resource.TestCheckResourceAttr(resourceName, "prefix_length", "28"), + testCheckAzureRMPublicIPPrefixExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_prefix"), + resource.TestCheckResourceAttr(data.ResourceName, "prefix_length", "28"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpPrefix_prefixLength(t *testing.T) { - resourceName := "azurerm_public_ip_prefix.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPPrefix_prefixLength(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_public_ip_prefix", "test") + config := testAccAzureRMPublicIPPrefix_prefixLength(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -137,26 +130,20 @@ func TestAccAzureRMPublicIpPrefix_prefixLength(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIPPrefixExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_prefix"), - resource.TestCheckResourceAttr(resourceName, "prefix_length", "31"), + testCheckAzureRMPublicIPPrefixExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_prefix"), + resource.TestCheckResourceAttr(data.ResourceName, "prefix_length", "31"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpPrefix_update(t *testing.T) { - resourceName := "azurerm_public_ip_prefix.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPublicIPPrefix_withTags(ri, location) - postConfig := testAccAzureRMPublicIPPrefix_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_public_ip_prefix", "test") + preConfig := testAccAzureRMPublicIPPrefix_withTags(data) + postConfig := testAccAzureRMPublicIPPrefix_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -166,18 +153,18 @@ func TestAccAzureRMPublicIpPrefix_update(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIPPrefixExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMPublicIPPrefixExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIPPrefixExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMPublicIPPrefixExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, }, @@ -185,9 +172,8 @@ func TestAccAzureRMPublicIpPrefix_update(t *testing.T) { } func TestAccAzureRMPublicIpPrefix_disappears(t *testing.T) { - resourceName := "azurerm_public_ip_prefix.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPPrefix_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_public_ip_prefix", "test") + config := testAccAzureRMPublicIPPrefix_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -197,8 +183,8 @@ func TestAccAzureRMPublicIpPrefix_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIPPrefixExists(resourceName), - testCheckAzureRMPublicIPPrefixDisappears(resourceName), + testCheckAzureRMPublicIPPrefixExists(data.ResourceName), + testCheckAzureRMPublicIPPrefixDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -206,7 +192,7 @@ func TestAccAzureRMPublicIpPrefix_disappears(t *testing.T) { }) } -func testAccAzureRMPublicIPPrefix_basic(rInt int, location string) string { +func testAccAzureRMPublicIPPrefix_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -218,10 +204,10 @@ resource "azurerm_public_ip_prefix" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPPrefix_withTags(rInt int, location string) string { +func testAccAzureRMPublicIPPrefix_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -238,10 +224,10 @@ resource "azurerm_public_ip_prefix" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPPrefix_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMPublicIPPrefix_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -257,10 +243,10 @@ resource "azurerm_public_ip_prefix" "test" { environment = "staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPPrefix_prefixLength(rInt int, location string) string { +func testAccAzureRMPublicIPPrefix_prefixLength(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -274,5 +260,5 @@ resource "azurerm_public_ip_prefix" "test" { prefix_length = 31 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_public_ip_test.go b/azurerm/internal/services/network/tests/resource_arm_public_ip_test.go similarity index 64% rename from azurerm/internal/services/network/resource_arm_public_ip_test.go rename to azurerm/internal/services/network/tests/resource_arm_public_ip_test.go index 6f873f4e3118..2c38b820f07d 100644 --- a/azurerm/internal/services/network/resource_arm_public_ip_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_public_ip_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -9,15 +9,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMPublicIpStatic_basic(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,19 +23,15 @@ func TestAccAzureRMPublicIpStatic_basic(t *testing.T) { CheckDestroy: testCheckAzureRMPublicIpDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPublicIPStatic_basic(ri, acceptance.Location()), + Config: testAccAzureRMPublicIPStatic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttr(resourceName, "allocation_method", "Static"), - resource.TestCheckResourceAttr(resourceName, "ip_version", "IPv4"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "allocation_method", "Static"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv4"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -48,8 +42,7 @@ func TestAccAzureRMPublicIpStatic_requiresImport(t *testing.T) { return } - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,16 +50,16 @@ func TestAccAzureRMPublicIpStatic_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMPublicIpDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPublicIPStatic_basic(ri, acceptance.Location()), + Config: testAccAzureRMPublicIPStatic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttr(resourceName, "allocation_method", "Static"), - resource.TestCheckResourceAttr(resourceName, "ip_version", "IPv4"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "allocation_method", "Static"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv4"), ), }, { - Config: testAccAzureRMPublicIPStatic_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMPublicIPStatic_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_public_ip"), }, }, @@ -74,8 +67,7 @@ func TestAccAzureRMPublicIpStatic_requiresImport(t *testing.T) { } func TestAccAzureRMPublicIpStatic_basicOld(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -83,35 +75,30 @@ func TestAccAzureRMPublicIpStatic_basicOld(t *testing.T) { CheckDestroy: testCheckAzureRMPublicIpDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPublicIPStatic_basicOld(ri, acceptance.Location()), + Config: testAccAzureRMPublicIPStatic_basicOld(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttr(resourceName, "public_ip_address_allocation", "Static"), - resource.TestCheckResourceAttr(resourceName, "ip_version", "IPv4"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "public_ip_address_allocation", "Static"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv4"), ), }, { - Config: testAccAzureRMPublicIPStatic_basic(ri, acceptance.Location()), + Config: testAccAzureRMPublicIPStatic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttr(resourceName, "allocation_method", "Static"), - resource.TestCheckResourceAttr(resourceName, "ip_version", "IPv4"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "allocation_method", "Static"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv4"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpStatic_zones(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -119,29 +106,24 @@ func TestAccAzureRMPublicIpStatic_zones(t *testing.T) { CheckDestroy: testCheckAzureRMPublicIpDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPublicIPStatic_withZone(ri, acceptance.Location()), + Config: testAccAzureRMPublicIPStatic_withZone(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttr(resourceName, "allocation_method", "Static"), - resource.TestCheckResourceAttr(resourceName, "zones.#", "1"), - resource.TestCheckResourceAttr(resourceName, "zones.0", "1"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "allocation_method", "Static"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "zones.0", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpStatic_basic_withDNSLabel(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - dnl := fmt.Sprintf("acctestdnl-%d", ri) - config := testAccAzureRMPublicIPStatic_basic_withDNSLabel(ri, acceptance.Location(), dnl) + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + dnl := fmt.Sprintf("acctestdnl-%d", data.RandomInteger) + config := testAccAzureRMPublicIPStatic_basic_withDNSLabel(data, dnl) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -151,24 +133,20 @@ func TestAccAzureRMPublicIpStatic_basic_withDNSLabel(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttr(resourceName, "allocation_method", "Static"), - resource.TestCheckResourceAttr(resourceName, "domain_name_label", dnl), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "allocation_method", "Static"), + resource.TestCheckResourceAttr(data.ResourceName, "domain_name_label", dnl), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpStatic_standard_withIPv6_fails(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPStatic_standard_withIPVersion(ri, acceptance.Location(), "IPv6") + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + config := testAccAzureRMPublicIPStatic_standard_withIPVersion(data, "IPv6") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -184,10 +162,9 @@ func TestAccAzureRMPublicIpStatic_standard_withIPv6_fails(t *testing.T) { } func TestAccAzureRMPublicIpDynamic_basic_withIPv6(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") ipVersion := "Ipv6" - config := testAccAzureRMPublicIPDynamic_basic_withIPVersion(ri, acceptance.Location(), ipVersion) + config := testAccAzureRMPublicIPDynamic_basic_withIPVersion(data, ipVersion) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -197,23 +174,18 @@ func TestAccAzureRMPublicIpDynamic_basic_withIPv6(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_version", "IPv6"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv6"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpStatic_basic_defaultsToIPv4(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPStatic_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + config := testAccAzureRMPublicIPStatic_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -223,23 +195,18 @@ func TestAccAzureRMPublicIpStatic_basic_defaultsToIPv4(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_version", "IPv4"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv4"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpStatic_basic_withIPv4(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") ipVersion := "IPv4" - config := testAccAzureRMPublicIPStatic_basic_withIPVersion(ri, acceptance.Location(), ipVersion) + config := testAccAzureRMPublicIPStatic_basic_withIPVersion(data, ipVersion) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -249,23 +216,18 @@ func TestAccAzureRMPublicIpStatic_basic_withIPv4(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ip_version", "IPv4"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ip_version", "IPv4"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpStatic_standard(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPStatic_standard(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + config := testAccAzureRMPublicIPStatic_standard(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -275,22 +237,17 @@ func TestAccAzureRMPublicIpStatic_standard(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), + testCheckAzureRMPublicIpExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpStatic_disappears(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPStatic_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + config := testAccAzureRMPublicIPStatic_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -300,8 +257,8 @@ func TestAccAzureRMPublicIpStatic_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - testCheckAzureRMPublicIpDisappears(resourceName), + testCheckAzureRMPublicIpExists(data.ResourceName), + testCheckAzureRMPublicIpDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -310,9 +267,8 @@ func TestAccAzureRMPublicIpStatic_disappears(t *testing.T) { } func TestAccAzureRMPublicIpStatic_idleTimeout(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPStatic_idleTimeout(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + config := testAccAzureRMPublicIPStatic_idleTimeout(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -322,25 +278,19 @@ func TestAccAzureRMPublicIpStatic_idleTimeout(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "idle_timeout_in_minutes", "30"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "idle_timeout_in_minutes", "30"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpStatic_withTags(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPublicIPStatic_withTags(ri, location) - postConfig := testAccAzureRMPublicIPStatic_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + preConfig := testAccAzureRMPublicIPStatic_withTags(data) + postConfig := testAccAzureRMPublicIPStatic_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -350,18 +300,18 @@ func TestAccAzureRMPublicIpStatic_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, }, @@ -369,11 +319,9 @@ func TestAccAzureRMPublicIpStatic_withTags(t *testing.T) { } func TestAccAzureRMPublicIpStatic_update(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPublicIPStatic_basic(ri, location) - postConfig := testAccAzureRMPublicIPStatic_update(ri, location) + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + preConfig := testAccAzureRMPublicIPStatic_basic(data) + postConfig := testAccAzureRMPublicIPStatic_update(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -383,29 +331,24 @@ func TestAccAzureRMPublicIpStatic_update(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), + testCheckAzureRMPublicIpExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "domain_name_label", fmt.Sprintf("acctest-%d", ri)), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "domain_name_label", fmt.Sprintf("acctest-%d", data.RandomInteger)), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpStatic_standardPrefix(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPStatic_standardPrefix(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + config := testAccAzureRMPublicIPStatic_standardPrefix(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -415,7 +358,7 @@ func TestAccAzureRMPublicIpStatic_standardPrefix(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), + testCheckAzureRMPublicIpExists(data.ResourceName), ), }, }, @@ -423,11 +366,9 @@ func TestAccAzureRMPublicIpStatic_standardPrefix(t *testing.T) { } func TestAccAzureRMPublicIpStatic_standardPrefixWithTags(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMPublicIPStatic_standardPrefixWithTags(ri, location) - postConfig := testAccAzureRMPublicIPStatic_standardPrefixWithTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + preConfig := testAccAzureRMPublicIPStatic_standardPrefixWithTags(data) + postConfig := testAccAzureRMPublicIPStatic_standardPrefixWithTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -437,18 +378,18 @@ func TestAccAzureRMPublicIpStatic_standardPrefixWithTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, }, @@ -456,9 +397,8 @@ func TestAccAzureRMPublicIpStatic_standardPrefixWithTags(t *testing.T) { } func TestAccAzureRMPublicIpDynamic_basic(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPDynamic_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") + config := testAccAzureRMPublicIPDynamic_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -468,23 +408,18 @@ func TestAccAzureRMPublicIpDynamic_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), + testCheckAzureRMPublicIpExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMPublicIpStatic_importIdError(t *testing.T) { - resourceName := "azurerm_public_ip.test" + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") - ri := tf.AccRandTimeInt() - config := testAccAzureRMPublicIPStatic_basic(ri, acceptance.Location()) + config := testAccAzureRMPublicIPStatic_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -494,10 +429,10 @@ func TestAccAzureRMPublicIpStatic_importIdError(t *testing.T) { Config: config, }, { - ResourceName: resourceName, + ResourceName: data.ResourceName, ImportState: true, ImportStateVerify: true, - ImportStateId: fmt.Sprintf("/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/publicIPAdresses/acctestpublicip-%d", os.Getenv("ARM_SUBSCRIPTION_ID"), ri, ri), + ImportStateId: fmt.Sprintf("/subscriptions/%s/resourceGroups/acctestRG-%d/providers/Microsoft.Network/publicIPAdresses/acctestpublicip-%d", os.Getenv("ARM_SUBSCRIPTION_ID"), data.RandomInteger, data.RandomInteger), ExpectError: regexp.MustCompile("Error parsing supplied resource id."), }, }, @@ -505,8 +440,7 @@ func TestAccAzureRMPublicIpStatic_importIdError(t *testing.T) { } func TestAccAzureRMPublicIpStatic_canLabelBe63(t *testing.T) { - resourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_public_ip", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -514,18 +448,14 @@ func TestAccAzureRMPublicIpStatic_canLabelBe63(t *testing.T) { CheckDestroy: testCheckAzureRMPublicIpDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMPublicIPStatic_canLabelBe63(ri, acceptance.Location()), + Config: testAccAzureRMPublicIPStatic_canLabelBe63(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMPublicIpExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "ip_address"), - resource.TestCheckResourceAttr(resourceName, "allocation_method", "Static"), + testCheckAzureRMPublicIpExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "ip_address"), + resource.TestCheckResourceAttr(data.ResourceName, "allocation_method", "Static"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -615,7 +545,7 @@ func testCheckAzureRMPublicIpDestroy(s *terraform.State) error { return nil } -func testAccAzureRMPublicIPStatic_basic(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -628,10 +558,10 @@ resource "azurerm_public_ip" "test" { resource_group_name = "${azurerm_resource_group.test.name}" allocation_method = "Static" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPStatic_requiresImport(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -641,10 +571,10 @@ resource "azurerm_public_ip" "import" { resource_group_name = "${azurerm_public_ip.test.resource_group_name}" allocation_method = "${azurerm_public_ip.test.allocation_method}" } -`, testAccAzureRMPublicIPStatic_basic(rInt, location)) +`, testAccAzureRMPublicIPStatic_basic(data)) } -func testAccAzureRMPublicIPStatic_basicOld(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_basicOld(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -657,10 +587,10 @@ resource "azurerm_public_ip" "test" { resource_group_name = "${azurerm_resource_group.test.name}" public_ip_address_allocation = "Static" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPStatic_withZone(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_withZone(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -674,10 +604,10 @@ resource "azurerm_public_ip" "test" { allocation_method = "Static" zones = ["1"] } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPStatic_basic_withDNSLabel(rInt int, location, dnsNameLabel string) string { +func testAccAzureRMPublicIPStatic_basic_withDNSLabel(data acceptance.TestData, dnsNameLabel string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -691,10 +621,10 @@ resource "azurerm_public_ip" "test" { allocation_method = "Static" domain_name_label = "%s" } -`, rInt, location, rInt, dnsNameLabel) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, dnsNameLabel) } -func testAccAzureRMPublicIPStatic_basic_withIPVersion(rInt int, location string, ipVersion string) string { +func testAccAzureRMPublicIPStatic_basic_withIPVersion(data acceptance.TestData, ipVersion string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -708,10 +638,10 @@ resource "azurerm_public_ip" "test" { allocation_method = "Static" ip_version = "%s" } -`, rInt, location, rInt, ipVersion) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, ipVersion) } -func testAccAzureRMPublicIPStatic_standard(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_standard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -725,10 +655,10 @@ resource "azurerm_public_ip" "test" { allocation_method = "Static" sku = "Standard" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPStatic_standardPrefix(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_standardPrefix(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -749,10 +679,10 @@ resource "azurerm_public_ip" "test" { sku = "Standard" public_ip_prefix_id = "${azurerm_public_ip_prefix.test.id}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPublicIPStatic_standardPrefixWithTags(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_standardPrefixWithTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -778,10 +708,10 @@ resource "azurerm_public_ip" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPublicIPStatic_standardPrefixWithTagsUpdate(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_standardPrefixWithTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -806,10 +736,10 @@ resource "azurerm_public_ip" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPublicIPStatic_standard_withIPVersion(rInt int, location string, ipVersion string) string { +func testAccAzureRMPublicIPStatic_standard_withIPVersion(data acceptance.TestData, ipVersion string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -824,10 +754,10 @@ resource "azurerm_public_ip" "test" { ip_version = "%s" sku = "Standard" } -`, rInt, location, rInt, ipVersion) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, ipVersion) } -func testAccAzureRMPublicIPStatic_update(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -841,10 +771,10 @@ resource "azurerm_public_ip" "test" { allocation_method = "Static" domain_name_label = "acctest-%d" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMPublicIPStatic_idleTimeout(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_idleTimeout(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -858,10 +788,10 @@ resource "azurerm_public_ip" "test" { allocation_method = "Static" idle_timeout_in_minutes = 30 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPDynamic_basic(rInt int, location string) string { +func testAccAzureRMPublicIPDynamic_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -874,10 +804,10 @@ resource "azurerm_public_ip" "test" { resource_group_name = "${azurerm_resource_group.test.name}" allocation_method = "Dynamic" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPDynamic_basic_withIPVersion(rInt int, location string, ipVersion string) string { +func testAccAzureRMPublicIPDynamic_basic_withIPVersion(data acceptance.TestData, ipVersion string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -892,10 +822,10 @@ resource "azurerm_public_ip" "test" { ip_version = "%s" } -`, rInt, location, rInt, ipVersion) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, ipVersion) } -func testAccAzureRMPublicIPStatic_withTags(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -913,10 +843,10 @@ resource "azurerm_public_ip" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPStatic_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -933,10 +863,10 @@ resource "azurerm_public_ip" "test" { environment = "staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMPublicIPStatic_canLabelBe63(rInt int, location string) string { +func testAccAzureRMPublicIPStatic_canLabelBe63(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -951,5 +881,5 @@ resource "azurerm_public_ip" "test" { allocation_method = "Static" domain_name_label = "k2345678-1-2345678-2-2345678-3-2345678-4-2345678-5-2345678-6-23" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_route_table_test.go b/azurerm/internal/services/network/tests/resource_arm_route_table_test.go similarity index 68% rename from azurerm/internal/services/network/resource_arm_route_table_test.go rename to azurerm/internal/services/network/tests/resource_arm_route_table_test.go index c21c42fc841a..7e8ed1a2daa7 100644 --- a/azurerm/internal/services/network/resource_arm_route_table_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_route_table_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +14,7 @@ import ( ) func TestAccAzureRMRouteTable_basic(t *testing.T) { - resourceName := "azurerm_route_table.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,18 +22,14 @@ func TestAccAzureRMRouteTable_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRouteTable_basic(ri, acceptance.Location()), + Config: testAccAzureRMRouteTable_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "disable_bgp_route_propagation", "false"), - resource.TestCheckResourceAttr(resourceName, "route.#", "0"), + testCheckAzureRMRouteTableExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,8 +40,7 @@ func TestAccAzureRMRouteTable_requiresImport(t *testing.T) { return } - resourceName := "azurerm_route_table.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,15 +48,15 @@ func TestAccAzureRMRouteTable_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRouteTable_basic(ri, acceptance.Location()), + Config: testAccAzureRMRouteTable_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "disable_bgp_route_propagation", "false"), - resource.TestCheckResourceAttr(resourceName, "route.#", "0"), + testCheckAzureRMRouteTableExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), ), }, { - Config: testAccAzureRMRouteTable_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMRouteTable_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_route_table"), }, }, @@ -71,8 +64,7 @@ func TestAccAzureRMRouteTable_requiresImport(t *testing.T) { } func TestAccAzureRMRouteTable_complete(t *testing.T) { - resourceName := "azurerm_route_table.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,25 +72,20 @@ func TestAccAzureRMRouteTable_complete(t *testing.T) { CheckDestroy: testCheckAzureRMRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRouteTable_complete(ri, acceptance.Location()), + Config: testAccAzureRMRouteTable_complete(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteTableExists("azurerm_route_table.test"), - resource.TestCheckResourceAttr(resourceName, "disable_bgp_route_propagation", "true"), - resource.TestCheckResourceAttr(resourceName, "route.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRouteTable_update(t *testing.T) { - resourceName := "azurerm_route_table.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -106,27 +93,27 @@ func TestAccAzureRMRouteTable_update(t *testing.T) { CheckDestroy: testCheckAzureRMRouteTableDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRouteTable_basic(ri, acceptance.Location()), + Config: testAccAzureRMRouteTable_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteTableExists("azurerm_route_table.test"), - resource.TestCheckResourceAttr(resourceName, "disable_bgp_route_propagation", "false"), - resource.TestCheckResourceAttr(resourceName, "route.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), ), }, { - Config: testAccAzureRMRouteTable_basicAppliance(ri, acceptance.Location()), + Config: testAccAzureRMRouteTable_basicAppliance(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteTableExists("azurerm_route_table.test"), - resource.TestCheckResourceAttr(resourceName, "disable_bgp_route_propagation", "false"), - resource.TestCheckResourceAttr(resourceName, "route.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), ), }, { - Config: testAccAzureRMRouteTable_complete(ri, acceptance.Location()), + Config: testAccAzureRMRouteTable_complete(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteTableExists("azurerm_route_table.test"), - resource.TestCheckResourceAttr(resourceName, "disable_bgp_route_propagation", "true"), - resource.TestCheckResourceAttr(resourceName, "route.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "disable_bgp_route_propagation", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), ), }, }, @@ -134,9 +121,8 @@ func TestAccAzureRMRouteTable_update(t *testing.T) { } func TestAccAzureRMRouteTable_singleRoute(t *testing.T) { - resourceName := "azurerm_route_table.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMRouteTable_singleRoute(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") + config := testAccAzureRMRouteTable_singleRoute(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -146,24 +132,19 @@ func TestAccAzureRMRouteTable_singleRoute(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), + testCheckAzureRMRouteTableExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRouteTable_removeRoute(t *testing.T) { - resourceName := "azurerm_route_table.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMRouteTable_singleRoute(ri, acceptance.Location()) - noBlocksConfig := testAccAzureRMRouteTable_noRouteBlocks(ri, acceptance.Location()) - blocksEmptyConfig := testAccAzureRMRouteTable_singleRouteRemoved(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") + config := testAccAzureRMRouteTable_singleRoute(data) + noBlocksConfig := testAccAzureRMRouteTable_noRouteBlocks(data) + blocksEmptyConfig := testAccAzureRMRouteTable_singleRouteRemoved(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,18 +155,18 @@ func TestAccAzureRMRouteTable_removeRoute(t *testing.T) { // This configuration includes a single explicit route block Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "route.#", "1"), + testCheckAzureRMRouteTableExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), ), }, { // This configuration has no route blocks at all. Config: noBlocksConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), + testCheckAzureRMRouteTableExists(data.ResourceName), // The route from the first step is preserved because no // blocks at all means "ignore existing blocks". - resource.TestCheckResourceAttr(resourceName, "route.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "1"), ), }, { @@ -193,10 +174,10 @@ func TestAccAzureRMRouteTable_removeRoute(t *testing.T) { // attribute syntax. Config: blocksEmptyConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), + testCheckAzureRMRouteTableExists(data.ResourceName), // The route from the first step is now removed, leaving us // with no routes at all. - resource.TestCheckResourceAttr(resourceName, "route.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "route.#", "0"), ), }, }, @@ -204,9 +185,8 @@ func TestAccAzureRMRouteTable_removeRoute(t *testing.T) { } func TestAccAzureRMRouteTable_disappears(t *testing.T) { - resourceName := "azurerm_route_table.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMRouteTable_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") + config := testAccAzureRMRouteTable_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -216,8 +196,8 @@ func TestAccAzureRMRouteTable_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), - testCheckAzureRMRouteTableDisappears(resourceName), + testCheckAzureRMRouteTableExists(data.ResourceName), + testCheckAzureRMRouteTableDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -226,10 +206,9 @@ func TestAccAzureRMRouteTable_disappears(t *testing.T) { } func TestAccAzureRMRouteTable_withTags(t *testing.T) { - resourceName := "azurerm_route_table.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMRouteTable_withTags(ri, acceptance.Location()) - postConfig := testAccAzureRMRouteTable_withTagsUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") + preConfig := testAccAzureRMRouteTable_withTags(data) + postConfig := testAccAzureRMRouteTable_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -239,18 +218,18 @@ func TestAccAzureRMRouteTable_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + 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: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMRouteTableExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, }, @@ -258,10 +237,9 @@ func TestAccAzureRMRouteTable_withTags(t *testing.T) { } func TestAccAzureRMRouteTable_multipleRoutes(t *testing.T) { - resourceName := "azurerm_route_table.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMRouteTable_singleRoute(ri, acceptance.Location()) - postConfig := testAccAzureRMRouteTable_multipleRoutes(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") + preConfig := testAccAzureRMRouteTable_singleRoute(data) + postConfig := testAccAzureRMRouteTable_multipleRoutes(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -271,39 +249,33 @@ func TestAccAzureRMRouteTable_multipleRoutes(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "route.#", "1"), - resource.TestCheckResourceAttr(resourceName, "route.0.name", "route1"), - resource.TestCheckResourceAttr(resourceName, "route.0.address_prefix", "10.1.0.0/16"), - resource.TestCheckResourceAttr(resourceName, "route.0.next_hop_type", "VnetLocal"), + 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: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "route.#", "2"), - resource.TestCheckResourceAttr(resourceName, "route.0.name", "route1"), - resource.TestCheckResourceAttr(resourceName, "route.0.address_prefix", "10.1.0.0/16"), - resource.TestCheckResourceAttr(resourceName, "route.0.next_hop_type", "VnetLocal"), - resource.TestCheckResourceAttr(resourceName, "route.1.name", "route2"), - resource.TestCheckResourceAttr(resourceName, "route.1.address_prefix", "10.2.0.0/16"), - resource.TestCheckResourceAttr(resourceName, "route.1.next_hop_type", "VnetLocal"), + 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"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMRouteTable_withTagsSubnet(t *testing.T) { - ri := tf.AccRandTimeInt() - configSetup := testAccAzureRMRouteTable_withTagsSubnet(ri, acceptance.Location()) - configTest := testAccAzureRMRouteTable_withAddTagsSubnet(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_route_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -311,7 +283,7 @@ func TestAccAzureRMRouteTable_withTagsSubnet(t *testing.T) { CheckDestroy: testCheckAzureRMRouteTableDestroy, Steps: []resource.TestStep{ { - Config: configSetup, + Config: testAccAzureRMRouteTable_withTagsSubnet(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteTableExists("azurerm_route_table.test"), testCheckAzureRMSubnetExists("azurerm_subnet.subnet1"), @@ -319,7 +291,7 @@ func TestAccAzureRMRouteTable_withTagsSubnet(t *testing.T) { ), }, { - Config: configTest, + Config: testAccAzureRMRouteTable_withAddTagsSubnet(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteTableExists("azurerm_route_table.test"), testCheckAzureRMSubnetExists("azurerm_subnet.subnet1"), @@ -417,7 +389,7 @@ func testCheckAzureRMRouteTableDestroy(s *terraform.State) error { return nil } -func testAccAzureRMRouteTable_basic(rInt int, location string) string { +func testAccAzureRMRouteTable_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -429,10 +401,10 @@ resource "azurerm_route_table" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_requiresImport(rInt int, location string) string { +func testAccAzureRMRouteTable_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -441,10 +413,10 @@ resource "azurerm_route_table" "import" { location = "${azurerm_route_table.test.location}" resource_group_name = "${azurerm_route_table.test.resource_group_name}" } -`, testAccAzureRMRouteTable_basic(rInt, location)) +`, testAccAzureRMRouteTable_basic(data)) } -func testAccAzureRMRouteTable_basicAppliance(rInt int, location string) string { +func testAccAzureRMRouteTable_basicAppliance(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -463,10 +435,10 @@ resource "azurerm_route_table" "test" { next_hop_in_ip_address = "192.168.0.1" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_complete(rInt int, location string) string { +func testAccAzureRMRouteTable_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -486,10 +458,10 @@ resource "azurerm_route_table" "test" { disable_bgp_route_propagation = true } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_singleRoute(rInt int, location string) string { +func testAccAzureRMRouteTable_singleRoute(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -507,10 +479,10 @@ resource "azurerm_route_table" "test" { next_hop_type = "vnetlocal" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_noRouteBlocks(rInt int, location string) string { +func testAccAzureRMRouteTable_noRouteBlocks(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -522,10 +494,10 @@ resource "azurerm_route_table" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_singleRouteRemoved(rInt int, location string) string { +func testAccAzureRMRouteTable_singleRouteRemoved(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -539,10 +511,10 @@ resource "azurerm_route_table" "test" { route = [] } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_multipleRoutes(rInt int, location string) string { +func testAccAzureRMRouteTable_multipleRoutes(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -566,10 +538,10 @@ resource "azurerm_route_table" "test" { next_hop_type = "vnetlocal" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_withTags(rInt int, location string) string { +func testAccAzureRMRouteTable_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -592,10 +564,10 @@ resource "azurerm_route_table" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMRouteTable_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -617,10 +589,10 @@ resource "azurerm_route_table" "test" { environment = "staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMRouteTable_withTagsSubnet(rInt int, location string) string { +func testAccAzureRMRouteTable_withTagsSubnet(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -665,10 +637,10 @@ resource "azurerm_route_table" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRouteTable_withAddTagsSubnet(rInt int, location string) string { +func testAccAzureRMRouteTable_withAddTagsSubnet(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -716,5 +688,5 @@ resource "azurerm_route_table" "test" { cloud = "Azure" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_route_test.go b/azurerm/internal/services/network/tests/resource_arm_route_test.go similarity index 78% rename from azurerm/internal/services/network/resource_arm_route_test.go rename to azurerm/internal/services/network/tests/resource_arm_route_test.go index d7f1dfb70109..3733128709a0 100644 --- a/azurerm/internal/services/network/resource_arm_route_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_route_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,7 +14,7 @@ import ( ) func TestAccAzureRMRoute_basic(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,16 +22,12 @@ func TestAccAzureRMRoute_basic(t *testing.T) { CheckDestroy: testCheckAzureRMRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRoute_basic(ri, acceptance.Location()), + Config: testAccAzureRMRoute_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteExists("azurerm_route.test"), ), }, - { - ResourceName: "azurerm_route.test", - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,8 +38,7 @@ func TestAccAzureRMRoute_requiresImport(t *testing.T) { return } - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,13 +46,13 @@ func TestAccAzureRMRoute_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRoute_basic(ri, location), + Config: testAccAzureRMRoute_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists("azurerm_route.test"), + testCheckAzureRMRouteExists(data.ResourceName), ), }, { - Config: testAccAzureRMRoute_requiresImport(ri, location), + Config: testAccAzureRMRoute_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_route"), }, }, @@ -66,8 +60,7 @@ func TestAccAzureRMRoute_requiresImport(t *testing.T) { } func TestAccAzureRMRoute_update(t *testing.T) { - resourceName := "azurerm_route.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -75,27 +68,27 @@ func TestAccAzureRMRoute_update(t *testing.T) { CheckDestroy: testCheckAzureRMRouteDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMRoute_basic(ri, acceptance.Location()), + Config: testAccAzureRMRoute_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "next_hop_type", "VnetLocal"), - resource.TestCheckResourceAttr(resourceName, "next_hop_in_ip_address", ""), + testCheckAzureRMRouteExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "next_hop_type", "VnetLocal"), + resource.TestCheckResourceAttr(data.ResourceName, "next_hop_in_ip_address", ""), ), }, { - Config: testAccAzureRMRoute_basicAppliance(ri, acceptance.Location()), + Config: testAccAzureRMRoute_basicAppliance(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "next_hop_type", "VirtualAppliance"), - resource.TestCheckResourceAttr(resourceName, "next_hop_in_ip_address", "192.168.0.1"), + 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(ri, acceptance.Location()), + Config: testAccAzureRMRoute_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMRouteExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "next_hop_type", "VnetLocal"), - resource.TestCheckResourceAttr(resourceName, "next_hop_in_ip_address", ""), + testCheckAzureRMRouteExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "next_hop_type", "VnetLocal"), + resource.TestCheckResourceAttr(data.ResourceName, "next_hop_in_ip_address", ""), ), }, }, @@ -103,8 +96,7 @@ func TestAccAzureRMRoute_update(t *testing.T) { } func TestAccAzureRMRoute_disappears(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMRoute_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -112,7 +104,7 @@ func TestAccAzureRMRoute_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMRouteDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMRoute_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteExists("azurerm_route.test"), testCheckAzureRMRouteDisappears("azurerm_route.test"), @@ -124,10 +116,7 @@ func TestAccAzureRMRoute_disappears(t *testing.T) { } func TestAccAzureRMRoute_multipleRoutes(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMRoute_basic(ri, location) - postConfig := testAccAzureRMRoute_multipleRoutes(ri, location) + data := acceptance.BuildTestData(t, "azurerm_route", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -135,14 +124,14 @@ func TestAccAzureRMRoute_multipleRoutes(t *testing.T) { CheckDestroy: testCheckAzureRMRouteDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMRoute_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteExists("azurerm_route.test"), ), }, { - Config: postConfig, + Config: testAccAzureRMRoute_multipleRoutes(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMRouteExists("azurerm_route.test1"), ), @@ -237,7 +226,7 @@ func testCheckAzureRMRouteDestroy(s *terraform.State) error { return nil } -func testAccAzureRMRoute_basic(rInt int, location string) string { +func testAccAzureRMRoute_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -258,10 +247,10 @@ resource "azurerm_route" "test" { address_prefix = "10.1.0.0/16" next_hop_type = "vnetlocal" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRoute_requiresImport(rInt int, location string) string { +func testAccAzureRMRoute_requiresImport(data acceptance.TestData) string { return fmt.Sprintf(` %s resource "azurerm_route" "import" { @@ -272,10 +261,10 @@ resource "azurerm_route" "import" { address_prefix = "${azurerm_route.test.address_prefix}" next_hop_type = "${azurerm_route.test.next_hop_type}" } -`, testAccAzureRMRoute_basic(rInt, location)) +`, testAccAzureRMRoute_basic(data)) } -func testAccAzureRMRoute_basicAppliance(rInt int, location string) string { +func testAccAzureRMRoute_basicAppliance(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -297,10 +286,10 @@ resource "azurerm_route" "test" { next_hop_type = "VirtualAppliance" next_hop_in_ip_address = "192.168.0.1" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMRoute_multipleRoutes(rInt int, location string) string { +func testAccAzureRMRoute_multipleRoutes(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -321,5 +310,5 @@ resource "azurerm_route" "test1" { address_prefix = "10.2.0.0/16" next_hop_type = "none" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_subnet_nat_gateway_association_test.go b/azurerm/internal/services/network/tests/resource_arm_subnet_nat_gateway_association_test.go similarity index 82% rename from azurerm/internal/services/network/resource_arm_subnet_nat_gateway_association_test.go rename to azurerm/internal/services/network/tests/resource_arm_subnet_nat_gateway_association_test.go index e5aec432bdb0..b38d79d2f8f2 100644 --- a/azurerm/internal/services/network/resource_arm_subnet_nat_gateway_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_subnet_nat_gateway_association_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,10 +14,7 @@ import ( ) func TestAccAzureRMSubnetNatGatewayAssociation_basic(t *testing.T) { - resourceName := "azurerm_subnet_nat_gateway_association.test" - ri := tf.AccRandTimeInt() - // Using alt location because the resource currently in private preview and is only available in eastus2. - location := acceptance.AltLocation() + data := acceptance.BuildTestData(t, "azurerm_subnet_nat_gateway_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,16 +23,12 @@ func TestAccAzureRMSubnetNatGatewayAssociation_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnetNatGatewayAssociation_basic(ri, location), + Config: testAccAzureRMSubnetNatGatewayAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetNatGatewayAssociationExists(resourceName), + testCheckAzureRMSubnetNatGatewayAssociationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,10 +39,8 @@ func TestAccAzureRMSubnetNatGatewayAssociation_requiresImport(t *testing.T) { return } - resourceName := "azurerm_subnet_nat_gateway_association.test" - ri := tf.AccRandTimeInt() - // Using alt location because the resource currently in private preview and is only available in eastus2. - location := acceptance.AltLocation() + data := acceptance.BuildTestData(t, "azurerm_subnet_nat_gateway_association", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -58,13 +48,13 @@ func TestAccAzureRMSubnetNatGatewayAssociation_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnetNatGatewayAssociation_basic(ri, location), + Config: testAccAzureRMSubnetNatGatewayAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetNatGatewayAssociationExists(resourceName), + testCheckAzureRMSubnetNatGatewayAssociationExists(data.ResourceName), ), }, { - Config: testAccAzureRMSubnetNatGatewayAssociation_requiresImport(ri, location), + Config: testAccAzureRMSubnetNatGatewayAssociation_requiresImport(data), ExpectError: acceptance.RequiresImportError(""), }, }, @@ -72,10 +62,8 @@ func TestAccAzureRMSubnetNatGatewayAssociation_requiresImport(t *testing.T) { } func TestAccAzureRMSubnetNatGatewayAssociation_deleted(t *testing.T) { - resourceName := "azurerm_subnet_nat_gateway_association.test" - ri := tf.AccRandTimeInt() - // Using alt location because the resource currently in private preview and is only available in eastus2. - location := acceptance.AltLocation() + data := acceptance.BuildTestData(t, "azurerm_subnet_nat_gateway_association", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -83,11 +71,11 @@ func TestAccAzureRMSubnetNatGatewayAssociation_deleted(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnetNatGatewayAssociation_basic(ri, location), + Config: testAccAzureRMSubnetNatGatewayAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetNatGatewayAssociationExists(resourceName), - testCheckAzureRMSubnetNatGatewayAssociationDisappears(resourceName), - testCheckAzureRMSubnetHasNoNatGateways(resourceName), + testCheckAzureRMSubnetNatGatewayAssociationExists(data.ResourceName), + testCheckAzureRMSubnetNatGatewayAssociationDisappears(data.ResourceName), + testCheckAzureRMSubnetHasNoNatGateways(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -215,7 +203,7 @@ func testCheckAzureRMSubnetHasNoNatGateways(resourceName string) resource.TestCh } } -func testAccAzureRMSubnetNatGatewayAssociation_basic(rInt int, location string) string { +func testAccAzureRMSubnetNatGatewayAssociation_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-network-%d" @@ -246,11 +234,11 @@ resource "azurerm_subnet_nat_gateway_association" "test" { subnet_id = "${azurerm_subnet.test.id}" nat_gateway_id = "${azurerm_nat_gateway.test.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnetNatGatewayAssociation_requiresImport(rInt int, location string) string { - template := testAccAzureRMSubnetNatGatewayAssociation_basic(rInt, location) +func testAccAzureRMSubnetNatGatewayAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMSubnetNatGatewayAssociation_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_subnet_network_security_group_association_test.go b/azurerm/internal/services/network/tests/resource_arm_subnet_network_security_group_association_test.go similarity index 89% rename from azurerm/internal/services/network/resource_arm_subnet_network_security_group_association_test.go rename to azurerm/internal/services/network/tests/resource_arm_subnet_network_security_group_association_test.go index 0bfd42b33e89..0df8ed9fc786 100644 --- a/azurerm/internal/services/network/resource_arm_subnet_network_security_group_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_subnet_network_security_group_association_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,7 @@ import ( ) func TestAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(t *testing.T) { - resourceName := "azurerm_subnet_network_security_group_association.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_subnet_network_security_group_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,16 +23,12 @@ func TestAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(ri, location), + Config: testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetNetworkSecurityGroupAssociationExists(resourceName), + testCheckAzureRMSubnetNetworkSecurityGroupAssociationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +39,7 @@ func TestAccAzureRMSubnetNetworkSecurityGroupAssociation_requiresImport(t *testi return } - resourceName := "azurerm_subnet_network_security_group_association.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_subnet_network_security_group_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,13 +48,13 @@ func TestAccAzureRMSubnetNetworkSecurityGroupAssociation_requiresImport(t *testi CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(ri, location), + Config: testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetNetworkSecurityGroupAssociationExists(resourceName), + testCheckAzureRMSubnetNetworkSecurityGroupAssociationExists(data.ResourceName), ), }, { - Config: testAccAzureRMSubnetNetworkSecurityGroupAssociation_requiresImport(ri, location), + Config: testAccAzureRMSubnetNetworkSecurityGroupAssociation_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_subnet_network_security_group_association"), }, }, @@ -71,9 +62,7 @@ func TestAccAzureRMSubnetNetworkSecurityGroupAssociation_requiresImport(t *testi } func TestAccAzureRMSubnetNetworkSecurityGroupAssociation_deleted(t *testing.T) { - resourceName := "azurerm_subnet_network_security_group_association.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_subnet_network_security_group_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,11 +71,11 @@ func TestAccAzureRMSubnetNetworkSecurityGroupAssociation_deleted(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(ri, location), + Config: testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetNetworkSecurityGroupAssociationExists(resourceName), - testCheckAzureRMSubnetNetworkSecurityGroupAssociationDisappears(resourceName), - testCheckAzureRMSubnetHasNoNetworkSecurityGroup(resourceName), + testCheckAzureRMSubnetNetworkSecurityGroupAssociationExists(data.ResourceName), + testCheckAzureRMSubnetNetworkSecurityGroupAssociationDisappears(data.ResourceName), + testCheckAzureRMSubnetHasNoNetworkSecurityGroup(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -219,7 +208,7 @@ func testCheckAzureRMSubnetHasNoNetworkSecurityGroup(resourceName string) resour } } -func testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(rInt int, location string) string { +func testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -263,11 +252,11 @@ resource "azurerm_subnet_network_security_group_association" "test" { subnet_id = "${azurerm_subnet.test.id}" network_security_group_id = "${azurerm_network_security_group.test.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnetNetworkSecurityGroupAssociation_requiresImport(rInt int, location string) string { - template := testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(rInt, location) +func testAccAzureRMSubnetNetworkSecurityGroupAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMSubnetNetworkSecurityGroupAssociation_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_subnet_route_table_association_test.go b/azurerm/internal/services/network/tests/resource_arm_subnet_route_table_association_test.go similarity index 85% rename from azurerm/internal/services/network/resource_arm_subnet_route_table_association_test.go rename to azurerm/internal/services/network/tests/resource_arm_subnet_route_table_association_test.go index fbe97c24f9fc..3bca09d2dca3 100644 --- a/azurerm/internal/services/network/resource_arm_subnet_route_table_association_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_subnet_route_table_association_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "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/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,7 @@ import ( ) func TestAccAzureRMSubnetRouteTableAssociation_basic(t *testing.T) { - resourceName := "azurerm_subnet_route_table_association.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_subnet_route_table_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,16 +23,12 @@ func TestAccAzureRMSubnetRouteTableAssociation_basic(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnetRouteTableAssociation_basic(ri, location), + Config: testAccAzureRMSubnetRouteTableAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetRouteTableAssociationExists(resourceName), + testCheckAzureRMSubnetRouteTableAssociationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,9 +38,7 @@ func TestAccAzureRMSubnetRouteTableAssociation_requiresImport(t *testing.T) { return } - resourceName := "azurerm_subnet_route_table_association.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_subnet_route_table_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +47,13 @@ func TestAccAzureRMSubnetRouteTableAssociation_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnetRouteTableAssociation_basic(ri, location), + Config: testAccAzureRMSubnetRouteTableAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetRouteTableAssociationExists(resourceName), + testCheckAzureRMSubnetRouteTableAssociationExists(data.ResourceName), ), }, { - Config: testAccAzureRMSubnetRouteTableAssociation_requiresImport(ri, location), + Config: testAccAzureRMSubnetRouteTableAssociation_requiresImport(data), ExpectError: acceptance.RequiresImportError(""), }, }, @@ -70,9 +61,7 @@ func TestAccAzureRMSubnetRouteTableAssociation_requiresImport(t *testing.T) { } func TestAccAzureRMSubnetRouteTableAssociation_deleted(t *testing.T) { - resourceName := "azurerm_subnet_route_table_association.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_subnet_route_table_association", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,11 +70,11 @@ func TestAccAzureRMSubnetRouteTableAssociation_deleted(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnetRouteTableAssociation_basic(ri, location), + Config: testAccAzureRMSubnetRouteTableAssociation_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetRouteTableAssociationExists(resourceName), - testCheckAzureRMSubnetRouteTableAssociationDisappears(resourceName), - testCheckAzureRMSubnetHasNoRouteTable(resourceName), + testCheckAzureRMSubnetRouteTableAssociationExists(data.ResourceName), + testCheckAzureRMSubnetRouteTableAssociationDisappears(data.ResourceName), + testCheckAzureRMSubnetHasNoRouteTable(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -218,7 +207,7 @@ func testCheckAzureRMSubnetHasNoRouteTable(resourceName string) resource.TestChe } } -func testAccAzureRMSubnetRouteTableAssociation_basic(rInt int, location string) string { +func testAccAzureRMSubnetRouteTableAssociation_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -257,11 +246,11 @@ resource "azurerm_subnet_route_table_association" "test" { subnet_id = "${azurerm_subnet.test.id}" route_table_id = "${azurerm_route_table.test.id}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnetRouteTableAssociation_requiresImport(rInt int, location string) string { - template := testAccAzureRMSubnetRouteTableAssociation_basic(rInt, location) +func testAccAzureRMSubnetRouteTableAssociation_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMSubnetRouteTableAssociation_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/network/resource_arm_subnet_test.go b/azurerm/internal/services/network/tests/resource_arm_subnet_test.go similarity index 81% rename from azurerm/internal/services/network/resource_arm_subnet_test.go rename to azurerm/internal/services/network/tests/resource_arm_subnet_test.go index 54729a0124fc..a1847118f7cb 100644 --- a/azurerm/internal/services/network/resource_arm_subnet_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_subnet_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -17,9 +16,8 @@ import ( ) func TestAccAzureRMSubnet_basic(t *testing.T) { - resourceName := "azurerm_subnet.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSubnet_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") + config := testAccAzureRMSubnet_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,14 +27,10 @@ func TestAccAzureRMSubnet_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), + testCheckAzureRMSubnetExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,9 +41,7 @@ func TestAccAzureRMSubnet_requiresImport(t *testing.T) { return } - resourceName := "azurerm_subnet.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -57,13 +49,13 @@ func TestAccAzureRMSubnet_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMSubnetDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMSubnet_basic(ri, location), + Config: testAccAzureRMSubnet_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), + testCheckAzureRMSubnetExists(data.ResourceName), ), }, { - Config: testAccAzureRMSubnet_requiresImport(ri, location), + Config: testAccAzureRMSubnet_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_subnet"), }, }, @@ -71,10 +63,9 @@ func TestAccAzureRMSubnet_requiresImport(t *testing.T) { } func TestAccAzureRMSubnet_delegation(t *testing.T) { - resourceName := "azurerm_subnet.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") - config := testAccAzureRMSubnet_delegation(ri, acceptance.Location()) + config := testAccAzureRMSubnet_delegation(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,8 +75,8 @@ func TestAccAzureRMSubnet_delegation(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "delegation.#", "1"), + testCheckAzureRMSubnetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "delegation.#", "1"), ), }, }, @@ -93,11 +84,9 @@ func TestAccAzureRMSubnet_delegation(t *testing.T) { } func TestAccAzureRMSubnet_routeTableUpdate(t *testing.T) { - resourceName := "azurerm_subnet.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - initConfig := testAccAzureRMSubnet_routeTable(ri, location) - updatedConfig := testAccAzureRMSubnet_updatedRouteTable(ri, location) + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") + initConfig := testAccAzureRMSubnet_routeTable(data) + updatedConfig := testAccAzureRMSubnet_updatedRouteTable(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -107,14 +96,14 @@ func TestAccAzureRMSubnet_routeTableUpdate(t *testing.T) { { Config: initConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), + testCheckAzureRMSubnetExists(data.ResourceName), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetRouteTableExists(resourceName, fmt.Sprintf("acctest-%d", ri)), + testCheckAzureRMSubnetRouteTableExists(data.ResourceName, fmt.Sprintf("acctest-%d", data.RandomInteger)), ), }, }, @@ -122,11 +111,9 @@ func TestAccAzureRMSubnet_routeTableUpdate(t *testing.T) { } func TestAccAzureRMSubnet_routeTableRemove(t *testing.T) { - resourceName := "azurerm_subnet.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - initConfig := testAccAzureRMSubnet_routeTable(ri, location) - updatedConfig := testAccAzureRMSubnet_routeTableUnlinked(ri, location) + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") + initConfig := testAccAzureRMSubnet_routeTable(data) + updatedConfig := testAccAzureRMSubnet_routeTableUnlinked(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -136,32 +123,26 @@ func TestAccAzureRMSubnet_routeTableRemove(t *testing.T) { { Config: initConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "route_table_id"), + testCheckAzureRMSubnetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "route_table_id"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "route_table_id", ""), + testCheckAzureRMSubnetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "route_table_id", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSubnet_removeNetworkSecurityGroup(t *testing.T) { - resourceName := "azurerm_subnet.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - initConfig := testAccAzureRMSubnet_networkSecurityGroup(ri, location) - updatedConfig := testAccAzureRMSubnet_networkSecurityGroupDetached(ri, location) + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") + initConfig := testAccAzureRMSubnet_networkSecurityGroup(data) + updatedConfig := testAccAzureRMSubnet_networkSecurityGroupDetached(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -171,29 +152,25 @@ func TestAccAzureRMSubnet_removeNetworkSecurityGroup(t *testing.T) { { Config: initConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "network_security_group_id"), + testCheckAzureRMSubnetExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_security_group_id"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_security_group_id", ""), + testCheckAzureRMSubnetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_security_group_id", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMSubnet_bug7986(t *testing.T) { - ri := tf.AccRandTimeInt() - initConfig := testAccAzureRMSubnet_bug7986(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") + initConfig := testAccAzureRMSubnet_bug7986(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -212,9 +189,8 @@ func TestAccAzureRMSubnet_bug7986(t *testing.T) { } func TestAccAzureRMSubnet_bug15204(t *testing.T) { - resourceName := "azurerm_subnet.test" - ri := tf.AccRandTimeInt() - initConfig := testAccAzureRMSubnet_bug15204(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") + initConfig := testAccAzureRMSubnet_bug15204(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -224,7 +200,7 @@ func TestAccAzureRMSubnet_bug15204(t *testing.T) { { Config: initConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), + testCheckAzureRMSubnetExists(data.ResourceName), ), }, }, @@ -232,9 +208,8 @@ func TestAccAzureRMSubnet_bug15204(t *testing.T) { } func TestAccAzureRMSubnet_disappears(t *testing.T) { - resourceName := "azurerm_subnet.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSubnet_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") + config := testAccAzureRMSubnet_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -244,8 +219,8 @@ func TestAccAzureRMSubnet_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), - testCheckAzureRMSubnetDisappears(resourceName), + testCheckAzureRMSubnetExists(data.ResourceName), + testCheckAzureRMSubnetDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -254,9 +229,8 @@ func TestAccAzureRMSubnet_disappears(t *testing.T) { } func TestAccAzureRMSubnet_serviceEndpoints(t *testing.T) { - resourceName := "azurerm_subnet.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMSubnet_serviceEndpoints(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") + config := testAccAzureRMSubnet_serviceEndpoints(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -267,7 +241,7 @@ func TestAccAzureRMSubnet_serviceEndpoints(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMSubnetExists("azurerm_subnet.test"), - resource.TestCheckResourceAttr(resourceName, "service_endpoints.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "service_endpoints.#", "2"), ), }, }, @@ -275,11 +249,9 @@ func TestAccAzureRMSubnet_serviceEndpoints(t *testing.T) { } func TestAccAzureRMSubnet_serviceEndpointsVNetUpdate(t *testing.T) { - resourceName := "azurerm_subnet.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMSubnet_serviceEndpoints(ri, location) - updatedConfig := testAccAzureRMSubnet_serviceEndpointsVNetUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_subnet", "test") + config := testAccAzureRMSubnet_serviceEndpoints(data) + updatedConfig := testAccAzureRMSubnet_serviceEndpointsVNetUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -289,15 +261,15 @@ func TestAccAzureRMSubnet_serviceEndpointsVNetUpdate(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "service_endpoints.#", "2"), + testCheckAzureRMSubnetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "service_endpoints.#", "2"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMSubnetExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "service_endpoints.#", "2"), + testCheckAzureRMSubnetExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "service_endpoints.#", "2"), ), }, }, @@ -445,7 +417,7 @@ func testCheckAzureRMSubnetDestroy(s *terraform.State) error { return nil } -func testAccAzureRMSubnet_basic(rInt int, location string) string { +func testAccAzureRMSubnet_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -465,11 +437,11 @@ resource "azurerm_subnet" "test" { virtual_network_name = "${azurerm_virtual_network.test.name}" address_prefix = "10.0.2.0/24" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnet_requiresImport(rInt int, location string) string { - template := testAccAzureRMSubnet_basic(rInt, location) +func testAccAzureRMSubnet_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMSubnet_basic(data) return fmt.Sprintf(` %s @@ -482,7 +454,7 @@ resource "azurerm_subnet" "import" { `, template) } -func testAccAzureRMSubnet_delegation(rInt int, location string) string { +func testAccAzureRMSubnet_delegation(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -511,10 +483,10 @@ resource "azurerm_subnet" "test" { } } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnet_routeTable(rInt int, location string) string { +func testAccAzureRMSubnet_routeTable(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -548,10 +520,10 @@ resource "azurerm_route_table" "test" { next_hop_in_ip_address = "10.10.1.1" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnet_routeTableUnlinked(rInt int, location string) string { +func testAccAzureRMSubnet_routeTableUnlinked(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -585,10 +557,10 @@ resource "azurerm_route_table" "test" { next_hop_in_ip_address = "10.10.1.1" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnet_updatedRouteTable(rInt int, location string) string { +func testAccAzureRMSubnet_updatedRouteTable(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -656,10 +628,10 @@ resource "azurerm_route_table" "test" { environment = "Testing" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnet_networkSecurityGroup(rInt int, location string) string { +func testAccAzureRMSubnet_networkSecurityGroup(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest%d-rg" @@ -698,10 +670,10 @@ resource "azurerm_subnet" "test" { address_prefix = "10.0.0.0/24" network_security_group_id = "${azurerm_network_security_group.test.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnet_networkSecurityGroupDetached(rInt int, location string) string { +func testAccAzureRMSubnet_networkSecurityGroupDetached(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest%d-rg" @@ -739,10 +711,10 @@ resource "azurerm_subnet" "test" { virtual_network_name = "${azurerm_virtual_network.test.name}" address_prefix = "10.0.0.0/24" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnet_bug7986(rInt int, location string) string { +func testAccAzureRMSubnet_bug7986(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest%d-rg" @@ -795,10 +767,10 @@ resource "azurerm_subnet" "second" { address_prefix = "10.0.1.0/24" route_table_id = "${azurerm_route_table.second.id}" } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnet_bug15204(rInt int, location string) string { +func testAccAzureRMSubnet_bug15204(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctest-%d" @@ -832,10 +804,10 @@ resource "azurerm_subnet" "test" { route_table_id = "${azurerm_route_table.test.id}" network_security_group_id = "${azurerm_network_security_group.test.id}" } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnet_serviceEndpoints(rInt int, location string) string { +func testAccAzureRMSubnet_serviceEndpoints(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -856,10 +828,10 @@ resource "azurerm_subnet" "test" { address_prefix = "10.0.2.0/24" service_endpoints = ["Microsoft.Sql", "Microsoft.Storage"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMSubnet_serviceEndpointsVNetUpdate(rInt int, location string) string { +func testAccAzureRMSubnet_serviceEndpointsVNetUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -884,5 +856,5 @@ resource "azurerm_subnet" "test" { address_prefix = "10.0.2.0/24" service_endpoints = ["Microsoft.Sql", "Microsoft.Storage"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_virtual_hub_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go similarity index 67% rename from azurerm/internal/services/network/resource_arm_virtual_hub_test.go rename to azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go index 7a069591b37b..28edba603616 100644 --- a/azurerm/internal/services/network/resource_arm_virtual_hub_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMVirtualHub_basic(t *testing.T) { - resourceName := "azurerm_virtual_hub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_hub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +21,12 @@ func TestAccAzureRMVirtualHub_basic(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualHub_basic(ri, location), + Config: testAccAzureRMVirtualHub_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualHubExists(resourceName), + testCheckAzureRMVirtualHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,8 +37,7 @@ func TestAccAzureRMVirtualHub_requiresImport(t *testing.T) { return } - resourceName := "azurerm_virtual_hub.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_virtual_hub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,13 +45,13 @@ func TestAccAzureRMVirtualHub_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualHub_basic(ri, acceptance.Location()), + Config: testAccAzureRMVirtualHub_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualHubExists(resourceName), + testCheckAzureRMVirtualHubExists(data.ResourceName), ), }, { - Config: testAccAzureRMVirtualHub_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMVirtualHub_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_virtual_hub"), }, }, @@ -67,9 +59,7 @@ func TestAccAzureRMVirtualHub_requiresImport(t *testing.T) { } func TestAccAzureRMVirtualHub_update(t *testing.T) { - resourceName := "azurerm_virtual_hub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_hub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -77,35 +67,25 @@ func TestAccAzureRMVirtualHub_update(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualHub_basic(ri, location), + Config: testAccAzureRMVirtualHub_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualHubExists(resourceName), + testCheckAzureRMVirtualHubExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMVirtualHub_updated(ri, location), + Config: testAccAzureRMVirtualHub_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualHubExists(resourceName), + testCheckAzureRMVirtualHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVirtualHub_routes(t *testing.T) { - resourceName := "azurerm_virtual_hub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_hub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,35 +93,25 @@ func TestAccAzureRMVirtualHub_routes(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualHub_route(ri, location), + Config: testAccAzureRMVirtualHub_route(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualHubExists(resourceName), + testCheckAzureRMVirtualHubExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMVirtualHub_routeUpdated(ri, location), + Config: testAccAzureRMVirtualHub_routeUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualHubExists(resourceName), + testCheckAzureRMVirtualHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVirtualHub_tags(t *testing.T) { - resourceName := "azurerm_virtual_hub.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_hub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -149,16 +119,12 @@ func TestAccAzureRMVirtualHub_tags(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualHub_tags(ri, location), + Config: testAccAzureRMVirtualHub_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualHubExists(resourceName), + testCheckAzureRMVirtualHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -211,8 +177,8 @@ func testCheckAzureRMVirtualHubDestroy(s *terraform.State) error { return nil } -func testAccAzureRMVirtualHub_basic(rInt int, location string) string { - template := testAccAzureRMVirtualHub_template(rInt, location) +func testAccAzureRMVirtualHub_basic(data acceptance.TestData) string { + template := testAccAzureRMVirtualHub_template(data) return fmt.Sprintf(` %s @@ -223,11 +189,11 @@ resource "azurerm_virtual_hub" "test" { virtual_wan_id = azurerm_virtual_wan.test.id address_prefix = "10.0.1.0/24" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualHub_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualHub_basic(rInt, location) +func testAccAzureRMVirtualHub_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualHub_basic(data) return fmt.Sprintf(` %s @@ -240,8 +206,8 @@ resource "azurerm_virtual_hub" "import" { `, template) } -func testAccAzureRMVirtualHub_updated(rInt int, location string) string { - template := testAccAzureRMVirtualHub_template(rInt, location) +func testAccAzureRMVirtualHub_updated(data acceptance.TestData) string { + template := testAccAzureRMVirtualHub_template(data) return fmt.Sprintf(` %s @@ -252,11 +218,11 @@ resource "azurerm_virtual_hub" "test" { virtual_wan_id = azurerm_virtual_wan.test.id address_prefix = "10.0.2.0/24" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualHub_route(rInt int, location string) string { - template := testAccAzureRMVirtualHub_template(rInt, location) +func testAccAzureRMVirtualHub_route(data acceptance.TestData) string { + template := testAccAzureRMVirtualHub_template(data) return fmt.Sprintf(` %s @@ -272,11 +238,11 @@ resource "azurerm_virtual_hub" "test" { next_hop_ip_address = "12.34.56.78" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualHub_routeUpdated(rInt int, location string) string { - template := testAccAzureRMVirtualHub_template(rInt, location) +func testAccAzureRMVirtualHub_routeUpdated(data acceptance.TestData) string { + template := testAccAzureRMVirtualHub_template(data) return fmt.Sprintf(` %s @@ -292,11 +258,11 @@ resource "azurerm_virtual_hub" "test" { next_hop_ip_address = "87.65.43.21" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualHub_tags(rInt int, location string) string { - template := testAccAzureRMVirtualHub_template(rInt, location) +func testAccAzureRMVirtualHub_tags(data acceptance.TestData) string { + template := testAccAzureRMVirtualHub_template(data) return fmt.Sprintf(` %s @@ -311,10 +277,10 @@ resource "azurerm_virtual_hub" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVirtualHub_template(rInt int, location string) string { +func testAccAzureRMVirtualHub_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -326,5 +292,5 @@ resource "azurerm_virtual_wan" "test" { resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_virtual_network_gateway_connection_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_connection_test.go similarity index 84% rename from azurerm/internal/services/network/resource_arm_virtual_network_gateway_connection_test.go rename to azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_connection_test.go index 3f1213c4eb0a..61677d4ff22a 100644 --- a/azurerm/internal/services/network/resource_arm_virtual_network_gateway_connection_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_connection_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,8 @@ import ( ) func TestAccAzureRMVirtualNetworkGatewayConnection_sitetosite(t *testing.T) { - resourceName := "azurerm_virtual_network_gateway_connection.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkGatewayConnection_sitetosite(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test") + config := testAccAzureRMVirtualNetworkGatewayConnection_sitetosite(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,14 +24,10 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_sitetosite(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayConnectionExists(resourceName), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,9 +38,7 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_requiresImport(t *testing.T) return } - resourceName := "azurerm_virtual_network_gateway_connection.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,13 +46,13 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_requiresImport(t *testing.T) CheckDestroy: testCheckAzureRMVirtualNetworkGatewayConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualNetworkGatewayConnection_sitetosite(ri, location), + Config: testAccAzureRMVirtualNetworkGatewayConnection_sitetosite(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayConnectionExists(resourceName), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data.ResourceName), ), }, { - Config: testAccAzureRMVirtualNetworkGatewayConnection_requiresImport(ri, location), + Config: testAccAzureRMVirtualNetworkGatewayConnection_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_virtual_network_gateway_connection"), }, }, @@ -68,13 +60,10 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_requiresImport(t *testing.T) } func TestAccAzureRMVirtualNetworkGatewayConnection_vnettonet(t *testing.T) { - firstResourceName := "azurerm_virtual_network_gateway_connection.test_1" - secondResourceName := "azurerm_virtual_network_gateway_connection.test_2" + data1 := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test_1") + data2 := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test_2") - ri := tf.AccRandTimeInt() - ri2 := tf.AccRandTimeInt() sharedKey := "4-v3ry-53cr37-1p53c-5h4r3d-k3y" - config := testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(ri, ri2, sharedKey, acceptance.Location(), acceptance.AltLocation()) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,12 +71,12 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_vnettonet(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkGatewayConnectionDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(data1, data2.RandomInteger, sharedKey), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayConnectionExists(firstResourceName), - testCheckAzureRMVirtualNetworkGatewayConnectionExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "shared_key", sharedKey), - resource.TestCheckResourceAttr(secondResourceName, "shared_key", sharedKey), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data1.ResourceName), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data2.ResourceName), + resource.TestCheckResourceAttr(data1.ResourceName, "shared_key", sharedKey), + resource.TestCheckResourceAttr(data2.ResourceName, "shared_key", sharedKey), ), }, }, @@ -95,8 +84,8 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_vnettonet(t *testing.T) { } func TestAccAzureRMVirtualNetworkGatewayConnection_ipsecpolicy(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkGatewayConnection_ipsecpolicy(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test") + config := testAccAzureRMVirtualNetworkGatewayConnection_ipsecpolicy(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -106,7 +95,7 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_ipsecpolicy(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayConnectionExists("azurerm_virtual_network_gateway_connection.test"), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data.ResourceName), ), }, }, @@ -115,10 +104,9 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_ipsecpolicy(t *testing.T) { func TestAccAzureRMVirtualNetworkGatewayConnection_connectionprotocol(t *testing.T) { expectedConnectionProtocol := "IKEv1" - resourceName := "azurerm_virtual_network_gateway_connection.test" + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test") - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkGatewayConnection_connectionprotocol(ri, acceptance.Location()) + config := testAccAzureRMVirtualNetworkGatewayConnection_connectionprotocol(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -128,8 +116,8 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_connectionprotocol(t *testing { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayConnectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "connection_protocol", expectedConnectionProtocol), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "connection_protocol", expectedConnectionProtocol), ), }, }, @@ -137,13 +125,8 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_connectionprotocol(t *testing } func TestAccAzureRMVirtualNetworkGatewayConnection_updatingSharedKey(t *testing.T) { - firstResourceName := "azurerm_virtual_network_gateway_connection.test_1" - secondResourceName := "azurerm_virtual_network_gateway_connection.test_2" - - ri := tf.AccRandTimeInt() - ri2 := tf.AccRandTimeInt() - loc1 := acceptance.Location() - loc2 := acceptance.AltLocation() + data1 := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test_1") + data2 := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway_connection", "test_2") firstSharedKey := "4-v3ry-53cr37-1p53c-5h4r3d-k3y" secondSharedKey := "4-r33ly-53cr37-1p53c-5h4r3d-k3y" @@ -154,21 +137,21 @@ func TestAccAzureRMVirtualNetworkGatewayConnection_updatingSharedKey(t *testing. CheckDestroy: testCheckAzureRMVirtualNetworkGatewayConnectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(ri, ri2, firstSharedKey, loc1, loc2), + Config: testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(data1, data2.RandomInteger, firstSharedKey), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayConnectionExists(firstResourceName), - testCheckAzureRMVirtualNetworkGatewayConnectionExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "shared_key", firstSharedKey), - resource.TestCheckResourceAttr(secondResourceName, "shared_key", firstSharedKey), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data1.ResourceName), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data2.ResourceName), + resource.TestCheckResourceAttr(data1.ResourceName, "shared_key", firstSharedKey), + resource.TestCheckResourceAttr(data2.ResourceName, "shared_key", firstSharedKey), ), }, { - Config: testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(ri, ri2, secondSharedKey, loc1, loc2), + Config: testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(data1, data2.RandomInteger, secondSharedKey), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayConnectionExists(firstResourceName), - testCheckAzureRMVirtualNetworkGatewayConnectionExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "shared_key", secondSharedKey), - resource.TestCheckResourceAttr(secondResourceName, "shared_key", secondSharedKey), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data1.ResourceName), + testCheckAzureRMVirtualNetworkGatewayConnectionExists(data2.ResourceName), + resource.TestCheckResourceAttr(data1.ResourceName, "shared_key", secondSharedKey), + resource.TestCheckResourceAttr(data2.ResourceName, "shared_key", secondSharedKey), ), }, }, @@ -227,7 +210,7 @@ func testCheckAzureRMVirtualNetworkGatewayConnectionDestroy(s *terraform.State) return nil } -func testAccAzureRMVirtualNetworkGatewayConnection_sitetosite(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGatewayConnection_sitetosite(data acceptance.TestData) string { return fmt.Sprintf(` variable "random" { default = "%d" @@ -296,11 +279,11 @@ resource "azurerm_virtual_network_gateway_connection" "test" { shared_key = "4-v3ry-53cr37-1p53c-5h4r3d-k3y" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualNetworkGatewayConnection_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualNetworkGatewayConnection_sitetosite(rInt, location) +func testAccAzureRMVirtualNetworkGatewayConnection_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualNetworkGatewayConnection_sitetosite(data) return fmt.Sprintf(` %s @@ -316,7 +299,7 @@ resource "azurerm_virtual_network_gateway_connection" "import" { `, template) } -func testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(rInt, rInt2 int, sharedKey, location, altLocation string) string { +func testAccAzureRMVirtualNetworkGatewayConnection_vnettovnet(data acceptance.TestData, rInt2 int, sharedKey string) string { return fmt.Sprintf(` variable "random1" { default = "%d" @@ -439,10 +422,10 @@ resource "azurerm_virtual_network_gateway_connection" "test_2" { shared_key = "${var.shared_key}" } -`, rInt, rInt2, sharedKey, location, altLocation) +`, data.RandomInteger, rInt2, sharedKey, data.Locations.Primary, data.Locations.Secondary) } -func testAccAzureRMVirtualNetworkGatewayConnection_ipsecpolicy(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGatewayConnection_ipsecpolicy(data acceptance.TestData) string { return fmt.Sprintf(` variable "random" { default = "%d" @@ -525,10 +508,10 @@ resource "azurerm_virtual_network_gateway_connection" "test" { shared_key = "4-v3ry-53cr37-1p53c-5h4r3d-k3y" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMVirtualNetworkGatewayConnection_connectionprotocol(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGatewayConnection_connectionprotocol(data acceptance.TestData) string { return fmt.Sprintf(` variable "random" { default = "%d" @@ -610,5 +593,5 @@ resource "azurerm_virtual_network_gateway_connection" "test" { shared_key = "4-v3ry-53cr37-1p53c-5h4r3d-k3y" } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/network/resource_arm_virtual_network_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_test.go similarity index 79% rename from azurerm/internal/services/network/resource_arm_virtual_network_gateway_test.go rename to azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_test.go index 9514b264f7d6..d796f013f74e 100644 --- a/azurerm/internal/services/network/resource_arm_virtual_network_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_network_gateway_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,8 @@ import ( ) func TestAccAzureRMVirtualNetworkGateway_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_virtual_network_gateway.test" - config := testAccAzureRMVirtualNetworkGateway_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") + config := testAccAzureRMVirtualNetworkGateway_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,15 +24,11 @@ func TestAccAzureRMVirtualNetworkGateway_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Basic"), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Basic"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,9 +39,7 @@ func TestAccAzureRMVirtualNetworkGateway_requiresImport(t *testing.T) { return } - resourceName := "azurerm_virtual_network_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,13 +47,13 @@ func TestAccAzureRMVirtualNetworkGateway_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualNetworkGateway_basic(ri, location), + Config: testAccAzureRMVirtualNetworkGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), ), }, { - Config: testAccAzureRMVirtualNetworkGateway_requiresImport(ri, location), + Config: testAccAzureRMVirtualNetworkGateway_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_virtual_network_gateway"), }, }, @@ -69,9 +61,7 @@ func TestAccAzureRMVirtualNetworkGateway_requiresImport(t *testing.T) { } func TestAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_virtual_network_gateway.test" - config := testAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,24 +69,19 @@ func TestAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Basic"), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Basic"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVirtualNetworkGateway_vpnGw1(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkGateway_vpnGw1(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,7 +89,7 @@ func TestAccAzureRMVirtualNetworkGateway_vpnGw1(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMVirtualNetworkGateway_vpnGw1(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualNetworkGatewayExists("azurerm_virtual_network_gateway.test"), ), @@ -114,8 +99,7 @@ func TestAccAzureRMVirtualNetworkGateway_vpnGw1(t *testing.T) { } func TestAccAzureRMVirtualNetworkGateway_activeActive(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkGateway_activeActive(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -123,7 +107,7 @@ func TestAccAzureRMVirtualNetworkGateway_activeActive(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMVirtualNetworkGateway_activeActive(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMVirtualNetworkGatewayExists("azurerm_virtual_network_gateway.test"), ), @@ -133,9 +117,7 @@ func TestAccAzureRMVirtualNetworkGateway_activeActive(t *testing.T) { } func TestAccAzureRMVirtualNetworkGateway_standard(t *testing.T) { - resourceName := "azurerm_virtual_network_gateway.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkGateway_sku(ri, acceptance.Location(), "Standard") + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -143,10 +125,10 @@ func TestAccAzureRMVirtualNetworkGateway_standard(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkGatewayDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMVirtualNetworkGateway_sku(data, "Standard"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Standard"), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), ), }, }, @@ -154,9 +136,8 @@ func TestAccAzureRMVirtualNetworkGateway_standard(t *testing.T) { } func TestAccAzureRMVirtualNetworkGateway_vpnGw2(t *testing.T) { - resourceName := "azurerm_virtual_network_gateway.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkGateway_sku(ri, acceptance.Location(), "VpnGw2") + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") + config := testAccAzureRMVirtualNetworkGateway_sku(data, "VpnGw2") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -166,8 +147,8 @@ func TestAccAzureRMVirtualNetworkGateway_vpnGw2(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "VpnGw2"), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "VpnGw2"), ), }, }, @@ -175,9 +156,8 @@ func TestAccAzureRMVirtualNetworkGateway_vpnGw2(t *testing.T) { } func TestAccAzureRMVirtualNetworkGateway_vpnGw3(t *testing.T) { - resourceName := "azurerm_virtual_network_gateway.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkGateway_sku(ri, acceptance.Location(), "VpnGw3") + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") + config := testAccAzureRMVirtualNetworkGateway_sku(data, "VpnGw3") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -187,8 +167,8 @@ func TestAccAzureRMVirtualNetworkGateway_vpnGw3(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "VpnGw3"), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "VpnGw3"), ), }, }, @@ -196,9 +176,8 @@ func TestAccAzureRMVirtualNetworkGateway_vpnGw3(t *testing.T) { } func TestAccAzureRMVirtualNetworkGateway_generation(t *testing.T) { - resourceName := "azurerm_virtual_network_gateway.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkGateway_generation(ri, acceptance.Location(), "Generation2") + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") + config := testAccAzureRMVirtualNetworkGateway_generation(data, "Generation2") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -208,8 +187,8 @@ func TestAccAzureRMVirtualNetworkGateway_generation(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "generation", "Generation2"), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "generation", "Generation2"), ), }, }, @@ -217,9 +196,8 @@ func TestAccAzureRMVirtualNetworkGateway_generation(t *testing.T) { } func TestAccAzureRMVirtualNetworkGateway_vpnClientConfig(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_virtual_network_gateway.test" - config := testAccAzureRMVirtualNetworkGateway_vpnClientConfig(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") + config := testAccAzureRMVirtualNetworkGateway_vpnClientConfig(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -229,9 +207,9 @@ func TestAccAzureRMVirtualNetworkGateway_vpnClientConfig(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vpn_client_configuration.0.radius_server_address", "1.2.3.4"), - resource.TestCheckResourceAttr(resourceName, "vpn_client_configuration.0.vpn_client_protocols.#", "2"), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vpn_client_configuration.0.radius_server_address", "1.2.3.4"), + resource.TestCheckResourceAttr(data.ResourceName, "vpn_client_configuration.0.vpn_client_protocols.#", "2"), ), }, }, @@ -239,9 +217,8 @@ func TestAccAzureRMVirtualNetworkGateway_vpnClientConfig(t *testing.T) { } func TestAccAzureRMVirtualNetworkGateway_vpnClientConfigOpenVPN(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_virtual_network_gateway.test" - config := testAccAzureRMVirtualNetworkGateway_vpnClientConfigOpenVPN(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") + config := testAccAzureRMVirtualNetworkGateway_vpnClientConfigOpenVPN(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -251,8 +228,8 @@ func TestAccAzureRMVirtualNetworkGateway_vpnClientConfigOpenVPN(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vpn_client_configuration.0.vpn_client_protocols.#", "1"), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vpn_client_configuration.0.vpn_client_protocols.#", "1"), ), }, }, @@ -260,9 +237,8 @@ func TestAccAzureRMVirtualNetworkGateway_vpnClientConfigOpenVPN(t *testing.T) { } func TestAccAzureRMVirtualNetworkGateway_enableBgp(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_virtual_network_gateway.test" - config := testAccAzureRMVirtualNetworkGateway_enableBgp(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") + config := testAccAzureRMVirtualNetworkGateway_enableBgp(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -272,9 +248,9 @@ func TestAccAzureRMVirtualNetworkGateway_enableBgp(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_bgp", "true"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.#", "1"), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_bgp", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.#", "1"), ), }, }, @@ -282,9 +258,8 @@ func TestAccAzureRMVirtualNetworkGateway_enableBgp(t *testing.T) { } func TestAccAzureRMVirtualNetworkGateway_expressRoute(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_virtual_network_gateway.test" - config := testAccAzureRMVirtualNetworkGateway_expressRoute(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test") + config := testAccAzureRMVirtualNetworkGateway_expressRoute(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -294,9 +269,9 @@ func TestAccAzureRMVirtualNetworkGateway_expressRoute(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkGatewayExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "type", "ExpressRoute"), - resource.TestCheckResourceAttr(resourceName, "bgp_settings.#", "0"), + testCheckAzureRMVirtualNetworkGatewayExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "type", "ExpressRoute"), + resource.TestCheckResourceAttr(data.ResourceName, "bgp_settings.#", "0"), ), }, }, @@ -355,7 +330,7 @@ func testCheckAzureRMVirtualNetworkGatewayDestroy(s *terraform.State) error { return nil } -func testAccAzureRMVirtualNetworkGateway_basic(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGateway_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -398,11 +373,11 @@ resource "azurerm_virtual_network_gateway" "test" { subnet_id = "${azurerm_subnet.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualNetworkGateway_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualNetworkGateway_basic(rInt, location) +func testAccAzureRMVirtualNetworkGateway_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualNetworkGateway_basic(data) return fmt.Sprintf(` %s @@ -423,7 +398,7 @@ resource "azurerm_virtual_network_gateway" "import" { `, template) } -func testAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGateway_lowerCaseSubnetName(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -466,10 +441,10 @@ resource "azurerm_virtual_network_gateway" "test" { subnet_id = "${azurerm_subnet.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualNetworkGateway_vpnGw1(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGateway_vpnGw1(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -512,10 +487,10 @@ resource "azurerm_virtual_network_gateway" "test" { subnet_id = "${azurerm_subnet.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualNetworkGateway_activeActive(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGateway_activeActive(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -583,10 +558,10 @@ resource "azurerm_virtual_network_gateway" "test" { asn = "65010" } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualNetworkGateway_vpnClientConfig(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGateway_vpnClientConfig(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -638,10 +613,10 @@ resource "azurerm_virtual_network_gateway" "test" { radius_server_secret = "1234" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualNetworkGateway_vpnClientConfigOpenVPN(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGateway_vpnClientConfigOpenVPN(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -690,10 +665,10 @@ resource "azurerm_virtual_network_gateway" "test" { vpn_client_protocols = ["OpenVPN"] } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualNetworkGateway_sku(rInt int, location string, sku string) string { +func testAccAzureRMVirtualNetworkGateway_sku(data acceptance.TestData, sku string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -736,10 +711,10 @@ resource "azurerm_virtual_network_gateway" "test" { subnet_id = "${azurerm_subnet.test.id}" } } -`, rInt, location, rInt, rInt, rInt, sku) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, sku) } -func testAccAzureRMVirtualNetworkGateway_enableBgp(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGateway_enableBgp(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -783,10 +758,10 @@ resource "azurerm_virtual_network_gateway" "test" { subnet_id = "${azurerm_subnet.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualNetworkGateway_expressRoute(rInt int, location string) string { +func testAccAzureRMVirtualNetworkGateway_expressRoute(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -829,10 +804,10 @@ resource "azurerm_virtual_network_gateway" "test" { subnet_id = "${azurerm_subnet.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualNetworkGateway_generation(rInt int, location string, generation string) string { +func testAccAzureRMVirtualNetworkGateway_generation(data acceptance.TestData, generation string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -876,5 +851,5 @@ resource "azurerm_virtual_network_gateway" "test" { subnet_id = "${azurerm_subnet.test.id}" } } -`, rInt, location, rInt, rInt, rInt, generation) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, generation) } diff --git a/azurerm/internal/services/network/resource_arm_virtual_network_peering_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_network_peering_test.go similarity index 81% rename from azurerm/internal/services/network/resource_arm_virtual_network_peering_test.go rename to azurerm/internal/services/network/tests/resource_arm_virtual_network_peering_test.go index e9f4e2fa1b21..aa6d50804198 100644 --- a/azurerm/internal/services/network/resource_arm_virtual_network_peering_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_network_peering_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,18 +7,16 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMVirtualNetworkPeering_basic(t *testing.T) { - firstResourceName := "azurerm_virtual_network_peering.test1" + data := acceptance.BuildTestData(t, "azurerm_virtual_network_peering", "test1") secondResourceName := "azurerm_virtual_network_peering.test2" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkPeering_basic(ri, acceptance.Location()) + config := testAccAzureRMVirtualNetworkPeering_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -28,17 +26,13 @@ func TestAccAzureRMVirtualNetworkPeering_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkPeeringExists(firstResourceName), + testCheckAzureRMVirtualNetworkPeeringExists(data.ResourceName), testCheckAzureRMVirtualNetworkPeeringExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "allow_virtual_network_access", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "allow_virtual_network_access", "true"), resource.TestCheckResourceAttr(secondResourceName, "allow_virtual_network_access", "true"), ), }, - { - ResourceName: firstResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -49,10 +43,8 @@ func TestAccAzureRMVirtualNetworkPeering_requiresImport(t *testing.T) { return } - firstResourceName := "azurerm_virtual_network_peering.test1" + data := acceptance.BuildTestData(t, "azurerm_virtual_network_peering", "test1") secondResourceName := "azurerm_virtual_network_peering.test2" - ri := tf.AccRandTimeInt() - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -60,26 +52,22 @@ func TestAccAzureRMVirtualNetworkPeering_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkPeeringDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualNetworkPeering_basic(ri, location), + Config: testAccAzureRMVirtualNetworkPeering_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkPeeringExists(firstResourceName), + testCheckAzureRMVirtualNetworkPeeringExists(data.ResourceName), testCheckAzureRMVirtualNetworkPeeringExists(secondResourceName), ), }, - { - Config: testAccAzureRMVirtualNetworkPeering_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_virtual_network_peering"), - }, + data.RequiresImportErrorStep(testAccAzureRMVirtualNetworkPeering_requiresImport), }, }) } func TestAccAzureRMVirtualNetworkPeering_disappears(t *testing.T) { - firstResourceName := "azurerm_virtual_network_peering.test1" + data := acceptance.BuildTestData(t, "azurerm_virtual_network_peering", "test1") secondResourceName := "azurerm_virtual_network_peering.test2" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetworkPeering_basic(ri, acceptance.Location()) + config := testAccAzureRMVirtualNetworkPeering_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -89,11 +77,11 @@ func TestAccAzureRMVirtualNetworkPeering_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkPeeringExists(firstResourceName), + testCheckAzureRMVirtualNetworkPeeringExists(data.ResourceName), testCheckAzureRMVirtualNetworkPeeringExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "allow_virtual_network_access", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "allow_virtual_network_access", "true"), resource.TestCheckResourceAttr(secondResourceName, "allow_virtual_network_access", "true"), - testCheckAzureRMVirtualNetworkPeeringDisappears(firstResourceName), + testCheckAzureRMVirtualNetworkPeeringDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -102,12 +90,11 @@ func TestAccAzureRMVirtualNetworkPeering_disappears(t *testing.T) { } func TestAccAzureRMVirtualNetworkPeering_update(t *testing.T) { - firstResourceName := "azurerm_virtual_network_peering.test1" + data := acceptance.BuildTestData(t, "azurerm_virtual_network_peering", "test1") secondResourceName := "azurerm_virtual_network_peering.test2" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualNetworkPeering_basic(ri, acceptance.Location()) - postConfig := testAccAzureRMVirtualNetworkPeering_basicUpdate(ri, acceptance.Location()) + preConfig := testAccAzureRMVirtualNetworkPeering_basic(data) + postConfig := testAccAzureRMVirtualNetworkPeering_basicUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -117,11 +104,11 @@ func TestAccAzureRMVirtualNetworkPeering_update(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkPeeringExists(firstResourceName), + testCheckAzureRMVirtualNetworkPeeringExists(data.ResourceName), testCheckAzureRMVirtualNetworkPeeringExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "allow_virtual_network_access", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "allow_virtual_network_access", "true"), resource.TestCheckResourceAttr(secondResourceName, "allow_virtual_network_access", "true"), - resource.TestCheckResourceAttr(firstResourceName, "allow_forwarded_traffic", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "allow_forwarded_traffic", "false"), resource.TestCheckResourceAttr(secondResourceName, "allow_forwarded_traffic", "false"), ), }, @@ -129,11 +116,11 @@ func TestAccAzureRMVirtualNetworkPeering_update(t *testing.T) { { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkPeeringExists(firstResourceName), + testCheckAzureRMVirtualNetworkPeeringExists(data.ResourceName), testCheckAzureRMVirtualNetworkPeeringExists(secondResourceName), - resource.TestCheckResourceAttr(firstResourceName, "allow_virtual_network_access", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "allow_virtual_network_access", "true"), resource.TestCheckResourceAttr(secondResourceName, "allow_virtual_network_access", "true"), - resource.TestCheckResourceAttr(firstResourceName, "allow_forwarded_traffic", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "allow_forwarded_traffic", "true"), resource.TestCheckResourceAttr(secondResourceName, "allow_forwarded_traffic", "true"), ), }, @@ -231,7 +218,7 @@ func testCheckAzureRMVirtualNetworkPeeringDestroy(s *terraform.State) error { return nil } -func testAccAzureRMVirtualNetworkPeering_basic(rInt int, location string) string { +func testAccAzureRMVirtualNetworkPeering_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -267,11 +254,11 @@ resource "azurerm_virtual_network_peering" "test2" { remote_virtual_network_id = "${azurerm_virtual_network.test1.id}" allow_virtual_network_access = true } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualNetworkPeering_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualNetworkPeering_basic(rInt, location) +func testAccAzureRMVirtualNetworkPeering_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualNetworkPeering_basic(data) return fmt.Sprintf(` %s @@ -285,7 +272,7 @@ resource "azurerm_virtual_network_peering" "import" { `, template) } -func testAccAzureRMVirtualNetworkPeering_basicUpdate(rInt int, location string) string { +func testAccAzureRMVirtualNetworkPeering_basicUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -323,5 +310,5 @@ resource "azurerm_virtual_network_peering" "test2" { allow_forwarded_traffic = true allow_virtual_network_access = true } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_virtual_network_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_network_test.go similarity index 72% rename from azurerm/internal/services/network/resource_arm_virtual_network_test.go rename to azurerm/internal/services/network/tests/resource_arm_virtual_network_test.go index 7dbb97caf088..baab252e43d7 100644 --- a/azurerm/internal/services/network/resource_arm_virtual_network_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_network_test.go @@ -1,22 +1,19 @@ -package network +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMVirtualNetwork_basic(t *testing.T) { - resourceName := "azurerm_virtual_network.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_virtual_network", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,25 +21,20 @@ func TestAccAzureRMVirtualNetwork_basic(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualNetwork_basic(ri, acceptance.Location()), + Config: testAccAzureRMVirtualNetwork_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subnet.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "subnet.1472110187.id"), + testCheckAzureRMVirtualNetworkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet.1472110187.id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVirtualNetwork_basicUpdated(t *testing.T) { - resourceName := "azurerm_virtual_network.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_virtual_network", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,26 +42,22 @@ func TestAccAzureRMVirtualNetwork_basicUpdated(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualNetwork_basic(ri, acceptance.Location()), + Config: testAccAzureRMVirtualNetwork_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subnet.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "subnet.1472110187.id"), + testCheckAzureRMVirtualNetworkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet.1472110187.id"), ), }, { - Config: testAccAzureRMVirtualNetwork_basicUpdated(ri, acceptance.Location()), + Config: testAccAzureRMVirtualNetwork_basicUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subnet.#", "2"), - resource.TestCheckResourceAttrSet(resourceName, "subnet.1472110187.id"), + testCheckAzureRMVirtualNetworkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.#", "2"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet.1472110187.id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -80,9 +68,7 @@ func TestAccAzureRMVirtualNetwork_requiresImport(t *testing.T) { return } - resourceName := "azurerm_virtual_network.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_network", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -90,13 +76,13 @@ func TestAccAzureRMVirtualNetwork_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualNetworkDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualNetwork_basic(ri, location), + Config: testAccAzureRMVirtualNetwork_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkExists(resourceName), + testCheckAzureRMVirtualNetworkExists(data.ResourceName), ), }, { - Config: testAccAzureRMVirtualNetwork_requiresImport(ri, location), + Config: testAccAzureRMVirtualNetwork_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_virtual_network"), }, }, @@ -104,9 +90,8 @@ func TestAccAzureRMVirtualNetwork_requiresImport(t *testing.T) { } func TestAccAzureRMVirtualNetwork_ddosProtectionPlan(t *testing.T) { - resourceName := "azurerm_virtual_network.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetwork_ddosProtectionPlan(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network", "test") + config := testAccAzureRMVirtualNetwork_ddosProtectionPlan(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -116,24 +101,19 @@ func TestAccAzureRMVirtualNetwork_ddosProtectionPlan(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "ddos_protection_plan.0.enable", "true"), - resource.TestCheckResourceAttrSet(resourceName, "ddos_protection_plan.0.id"), + testCheckAzureRMVirtualNetworkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "ddos_protection_plan.0.enable", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "ddos_protection_plan.0.id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVirtualNetwork_disappears(t *testing.T) { - resourceName := "azurerm_virtual_network.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMVirtualNetwork_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network", "test") + config := testAccAzureRMVirtualNetwork_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -143,8 +123,8 @@ func TestAccAzureRMVirtualNetwork_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkExists(resourceName), - testCheckAzureRMVirtualNetworkDisappears(resourceName), + testCheckAzureRMVirtualNetworkExists(data.ResourceName), + testCheckAzureRMVirtualNetworkDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -153,11 +133,9 @@ func TestAccAzureRMVirtualNetwork_disappears(t *testing.T) { } func TestAccAzureRMVirtualNetwork_withTags(t *testing.T) { - resourceName := "azurerm_virtual_network.test" - location := acceptance.Location() - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMVirtualNetwork_withTags(ri, location) - postConfig := testAccAzureRMVirtualNetwork_withTagsUpdated(ri, location) + data := acceptance.BuildTestData(t, "azurerm_virtual_network", "test") + preConfig := testAccAzureRMVirtualNetwork_withTags(data) + postConfig := testAccAzureRMVirtualNetwork_withTagsUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -167,22 +145,22 @@ func TestAccAzureRMVirtualNetwork_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subnet.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "subnet.1472110187.id"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMVirtualNetworkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet.1472110187.id"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subnet.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "subnet.1472110187.id"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMVirtualNetworkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "subnet.1472110187.id"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, }, @@ -190,9 +168,8 @@ func TestAccAzureRMVirtualNetwork_withTags(t *testing.T) { } func TestAccAzureRMVirtualNetwork_bug373(t *testing.T) { - resourceName := "azurerm_virtual_network.test" - rs := acctest.RandString(6) - config := testAccAzureRMVirtualNetwork_bug373(rs, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_virtual_network", "test") + config := testAccAzureRMVirtualNetwork_bug373(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -202,7 +179,7 @@ func TestAccAzureRMVirtualNetwork_bug373(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualNetworkExists(resourceName), + testCheckAzureRMVirtualNetworkExists(data.ResourceName), ), }, }, @@ -297,7 +274,7 @@ func testCheckAzureRMVirtualNetworkDestroy(s *terraform.State) error { return nil } -func testAccAzureRMVirtualNetwork_basic(rInt int, location string) string { +func testAccAzureRMVirtualNetwork_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -315,10 +292,10 @@ resource "azurerm_virtual_network" "test" { address_prefix = "10.0.1.0/24" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMVirtualNetwork_basicUpdated(rInt int, location string) string { +func testAccAzureRMVirtualNetwork_basicUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -341,11 +318,11 @@ resource "azurerm_virtual_network" "test" { address_prefix = "10.10.1.0/24" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMVirtualNetwork_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualNetwork_basic(rInt, location) +func testAccAzureRMVirtualNetwork_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualNetwork_basic(data) return fmt.Sprintf(` %s @@ -363,7 +340,7 @@ resource "azurerm_virtual_network" "import" { `, template) } -func testAccAzureRMVirtualNetwork_ddosProtectionPlan(rInt int, location string) string { +func testAccAzureRMVirtualNetwork_ddosProtectionPlan(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -392,10 +369,10 @@ resource "azurerm_virtual_network" "test" { address_prefix = "10.0.1.0/24" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMVirtualNetwork_withTags(rInt int, location string) string { +func testAccAzureRMVirtualNetwork_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -418,10 +395,10 @@ resource "azurerm_virtual_network" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMVirtualNetwork_withTagsUpdated(rInt int, location string) string { +func testAccAzureRMVirtualNetwork_withTagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -443,10 +420,10 @@ resource "azurerm_virtual_network" "test" { environment = "staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMVirtualNetwork_bug373(rString string, location string) string { +func testAccAzureRMVirtualNetwork_bug373(data acceptance.TestData) string { return fmt.Sprintf(` variable "environment" { default = "TestVirtualNetworkBug373" @@ -509,5 +486,5 @@ resource "azurerm_network_security_group" "test" { environment = "${var.environment}" } } -`, rString, location) +`, data.RandomString, data.Locations.Primary) } diff --git a/azurerm/internal/services/network/resource_arm_virtual_wan_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_wan_test.go similarity index 77% rename from azurerm/internal/services/network/resource_arm_virtual_wan_test.go rename to azurerm/internal/services/network/tests/resource_arm_virtual_wan_test.go index f346e51b8c26..b92322278ff2 100644 --- a/azurerm/internal/services/network/resource_arm_virtual_wan_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_wan_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,7 @@ import ( ) func TestAccAzureRMVirtualWan_basic(t *testing.T) { - resourceName := "azurerm_virtual_wan.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_virtual_wan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,16 +22,12 @@ func TestAccAzureRMVirtualWan_basic(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualWanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualWan_basic(ri, location), + Config: testAccAzureRMVirtualWan_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualWanExists(resourceName), + testCheckAzureRMVirtualWanExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,8 +37,7 @@ func TestAccAzureRMVirtualWan_requiresImport(t *testing.T) { t.Skip("Skipping since resources aren't required to be imported") return } - resourceName := "azurerm_virtual_wan.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_virtual_wan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,13 +45,13 @@ func TestAccAzureRMVirtualWan_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualWanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualWan_basic(ri, acceptance.Location()), + Config: testAccAzureRMVirtualWan_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualWanExists(resourceName), + testCheckAzureRMVirtualWanExists(data.ResourceName), ), }, { - Config: testAccAzureRMVirtualWan_requiresImport(ri, acceptance.Location()), + Config: testAccAzureRMVirtualWan_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_virtual_wan"), }, }, @@ -67,8 +59,7 @@ func TestAccAzureRMVirtualWan_requiresImport(t *testing.T) { } func TestAccAzureRMVirtualWan_complete(t *testing.T) { - resourceName := "azurerm_virtual_wan.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_virtual_wan", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -76,16 +67,12 @@ func TestAccAzureRMVirtualWan_complete(t *testing.T) { CheckDestroy: testCheckAzureRMVirtualWanDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVirtualWan_complete(ri, acceptance.Location()), + Config: testAccAzureRMVirtualWan_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVirtualWanExists(resourceName), + testCheckAzureRMVirtualWanExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -148,7 +135,7 @@ func testCheckAzureRMVirtualWanExists(resourceName string) resource.TestCheckFun } } -func testAccAzureRMVirtualWan_basic(rInt int, location string) string { +func testAccAzureRMVirtualWan_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -160,11 +147,11 @@ resource "azurerm_virtual_wan" "test" { resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMVirtualWan_requiresImport(rInt int, location string) string { - template := testAccAzureRMVirtualWan_basic(rInt, location) +func testAccAzureRMVirtualWan_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVirtualWan_basic(data) return fmt.Sprintf(` %s @@ -176,7 +163,7 @@ resource "azurerm_virtual_wan" "import" { `, template) } -func testAccAzureRMVirtualWan_complete(rInt int, location string) string { +func testAccAzureRMVirtualWan_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -198,5 +185,5 @@ resource "azurerm_virtual_wan" "test" { World = "Example" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_vpn_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go similarity index 66% rename from azurerm/internal/services/network/resource_arm_vpn_gateway_test.go rename to azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go index 89c7dedbe5ab..bb3fcbf71b67 100644 --- a/azurerm/internal/services/network/resource_arm_vpn_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMVPNGateway_basic(t *testing.T) { - resourceName := "azurerm_vpn_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +21,12 @@ func TestAccAzureRMVPNGateway_basic(t *testing.T) { CheckDestroy: testCheckAzureRMVPNGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVPNGateway_basic(ri, location), + Config: testAccAzureRMVPNGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNGatewayExists(resourceName), + testCheckAzureRMVPNGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,9 +37,7 @@ func TestAccAzureRMVPNGateway_requiresImport(t *testing.T) { return } - resourceName := "azurerm_vpn_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,13 +45,13 @@ func TestAccAzureRMVPNGateway_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMVPNGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVPNGateway_basic(ri, location), + Config: testAccAzureRMVPNGateway_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNGatewayExists(resourceName), + testCheckAzureRMVPNGatewayExists(data.ResourceName), ), }, { - Config: testAccAzureRMVPNGateway_requiresImport(ri, location), + Config: testAccAzureRMVPNGateway_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_vpn_gateway"), }, }, @@ -68,9 +59,7 @@ func TestAccAzureRMVPNGateway_requiresImport(t *testing.T) { } func TestAccAzureRMVPNGateway_bgpSettings(t *testing.T) { - resourceName := "azurerm_vpn_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,24 +67,18 @@ func TestAccAzureRMVPNGateway_bgpSettings(t *testing.T) { CheckDestroy: testCheckAzureRMVPNGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVPNGateway_bgpSettings(ri, location), + Config: testAccAzureRMVPNGateway_bgpSettings(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNGatewayExists(resourceName), + testCheckAzureRMVPNGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVPNGateway_scaleUnit(t *testing.T) { - resourceName := "azurerm_vpn_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -103,35 +86,25 @@ func TestAccAzureRMVPNGateway_scaleUnit(t *testing.T) { CheckDestroy: testCheckAzureRMVPNGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVPNGateway_scaleUnit(ri, location, 2), + Config: testAccAzureRMVPNGateway_scaleUnit(data, 2), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNGatewayExists(resourceName), + testCheckAzureRMVPNGatewayExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMVPNGateway_scaleUnit(ri, location, 3), + Config: testAccAzureRMVPNGateway_scaleUnit(data, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNGatewayExists(resourceName), + testCheckAzureRMVPNGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVPNGateway_tags(t *testing.T) { - resourceName := "azurerm_vpn_gateway.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_gateway", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -139,38 +112,26 @@ func TestAccAzureRMVPNGateway_tags(t *testing.T) { CheckDestroy: testCheckAzureRMVPNGatewayDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMVPNGateway_tags(ri, location), + Config: testAccAzureRMVPNGateway_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNGatewayExists(resourceName), + testCheckAzureRMVPNGatewayExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMVPNGateway_tagsUpdated(ri, location), + Config: testAccAzureRMVPNGateway_tagsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNGatewayExists(resourceName), + testCheckAzureRMVPNGatewayExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMVPNGateway_tags(ri, location), + Config: testAccAzureRMVPNGateway_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNGatewayExists(resourceName), + testCheckAzureRMVPNGatewayExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -225,8 +186,8 @@ func testCheckAzureRMVPNGatewayDestroy(s *terraform.State) error { return nil } -func testAccAzureRMVPNGateway_basic(rInt int, location string) string { - template := testAccAzureRMVPNGateway_template(rInt, location) +func testAccAzureRMVPNGateway_basic(data acceptance.TestData) string { + template := testAccAzureRMVPNGateway_template(data) return fmt.Sprintf(` %s @@ -236,11 +197,11 @@ resource "azurerm_vpn_gateway" "test" { resource_group_name = azurerm_resource_group.test.name virtual_hub_id = azurerm_virtual_hub.test.id } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVPNGateway_requiresImport(rInt int, location string) string { - template := testAccAzureRMVPNGateway_basic(rInt, location) +func testAccAzureRMVPNGateway_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMVPNGateway_basic(data) return fmt.Sprintf(` %s @@ -253,8 +214,8 @@ resource "azurerm_vpn_gateway" "import" { `, template) } -func testAccAzureRMVPNGateway_bgpSettings(rInt int, location string) string { - template := testAccAzureRMVPNGateway_template(rInt, location) +func testAccAzureRMVPNGateway_bgpSettings(data acceptance.TestData) string { + template := testAccAzureRMVPNGateway_template(data) return fmt.Sprintf(` %s @@ -269,11 +230,11 @@ resource "azurerm_vpn_gateway" "test" { peer_weight = 0 } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVPNGateway_scaleUnit(rInt int, location string, scaleUnit int) string { - template := testAccAzureRMVPNGateway_template(rInt, location) +func testAccAzureRMVPNGateway_scaleUnit(data acceptance.TestData, scaleUnit int) string { + template := testAccAzureRMVPNGateway_template(data) return fmt.Sprintf(` %s @@ -284,11 +245,11 @@ resource "azurerm_vpn_gateway" "test" { virtual_hub_id = azurerm_virtual_hub.test.id scale_unit = %d } -`, template, rInt, scaleUnit) +`, template, data.RandomInteger, scaleUnit) } -func testAccAzureRMVPNGateway_tags(rInt int, location string) string { - template := testAccAzureRMVPNGateway_template(rInt, location) +func testAccAzureRMVPNGateway_tags(data acceptance.TestData) string { + template := testAccAzureRMVPNGateway_template(data) return fmt.Sprintf(` %s @@ -302,11 +263,11 @@ resource "azurerm_vpn_gateway" "test" { Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVPNGateway_tagsUpdated(rInt int, location string) string { - template := testAccAzureRMVPNGateway_template(rInt, location) +func testAccAzureRMVPNGateway_tagsUpdated(data acceptance.TestData) string { + template := testAccAzureRMVPNGateway_template(data) return fmt.Sprintf(` %s @@ -321,10 +282,10 @@ resource "azurerm_vpn_gateway" "test" { Rick = "C-137" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMVPNGateway_template(rInt int, location string) string { +func testAccAzureRMVPNGateway_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -351,5 +312,5 @@ resource "azurerm_virtual_hub" "test" { address_prefix = "10.0.1.0/24" virtual_wan_id = azurerm_virtual_wan.test.id } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/resource_arm_vpn_server_configuration_test.go b/azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go similarity index 81% rename from azurerm/internal/services/network/resource_arm_vpn_server_configuration_test.go rename to azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go index 85dd5496a74d..3d38a19d0711 100644 --- a/azurerm/internal/services/network/resource_arm_vpn_server_configuration_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go @@ -1,4 +1,4 @@ -package network +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,9 +13,7 @@ import ( ) func TestAccAzureRMVPNServerConfiguration_azureAD(t *testing.T) { - resourceName := "azurerm_vpn_server_configuration.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_server_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,24 +21,18 @@ func TestAccAzureRMVPNServerConfiguration_azureAD(t *testing.T) { CheckDestroy: testCheckAzureRMVPNServerConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAzureRMVPNServerConfiguration_azureAD(ri, location), + Config: testAccAzureRMAzureRMVPNServerConfiguration_azureAD(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNServerConfigurationExists(resourceName), + testCheckAzureRMVPNServerConfigurationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVPNServerConfiguration_certificate(t *testing.T) { - resourceName := "azurerm_vpn_server_configuration.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_server_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -49,27 +40,19 @@ func TestAccAzureRMVPNServerConfiguration_certificate(t *testing.T) { CheckDestroy: testCheckAzureRMVPNServerConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAzureRMVPNServerConfiguration_certificate(ri, location), + Config: testAccAzureRMAzureRMVPNServerConfiguration_certificate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNServerConfigurationExists(resourceName), + testCheckAzureRMVPNServerConfigurationExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAzureRMVPNServerConfiguration_certificateUpdated(ri, location), + Config: testAccAzureRMAzureRMVPNServerConfiguration_certificateUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNServerConfigurationExists(resourceName), + testCheckAzureRMVPNServerConfigurationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -80,9 +63,7 @@ func TestAccAzureRMVPNServerConfiguration_requiresImport(t *testing.T) { return } - resourceName := "azurerm_vpn_server_configuration.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_server_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -90,18 +71,14 @@ func TestAccAzureRMVPNServerConfiguration_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMVPNServerConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAzureRMVPNServerConfiguration_certificate(ri, location), + Config: testAccAzureRMAzureRMVPNServerConfiguration_certificate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNServerConfigurationExists(resourceName), + testCheckAzureRMVPNServerConfigurationExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAzureRMVPNServerConfiguration_requiresImport(ri, location), + Config: testAccAzureRMAzureRMVPNServerConfiguration_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_vpn_server_configuration"), }, }, @@ -109,9 +86,7 @@ func TestAccAzureRMVPNServerConfiguration_requiresImport(t *testing.T) { } func TestAccAzureRMVPNServerConfiguration_radius(t *testing.T) { - resourceName := "azurerm_vpn_server_configuration.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_server_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -119,24 +94,18 @@ func TestAccAzureRMVPNServerConfiguration_radius(t *testing.T) { CheckDestroy: testCheckAzureRMVPNServerConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAzureRMVPNServerConfiguration_radius(ri, location), + Config: testAccAzureRMAzureRMVPNServerConfiguration_radius(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNServerConfigurationExists(resourceName), + testCheckAzureRMVPNServerConfigurationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVPNServerConfiguration_multipleAuth(t *testing.T) { - resourceName := "azurerm_vpn_server_configuration.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_server_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -144,46 +113,32 @@ func TestAccAzureRMVPNServerConfiguration_multipleAuth(t *testing.T) { CheckDestroy: testCheckAzureRMVPNServerConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAzureRMVPNServerConfiguration_azureAD(ri, location), + Config: testAccAzureRMAzureRMVPNServerConfiguration_azureAD(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNServerConfigurationExists(resourceName), + testCheckAzureRMVPNServerConfigurationExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAzureRMVPNServerConfiguration_certificate(ri, location), + Config: testAccAzureRMAzureRMVPNServerConfiguration_certificate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNServerConfigurationExists(resourceName), + testCheckAzureRMVPNServerConfigurationExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMAzureRMVPNServerConfiguration_radius(ri, location), + Config: testAccAzureRMAzureRMVPNServerConfiguration_radius(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNServerConfigurationExists(resourceName), + testCheckAzureRMVPNServerConfigurationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMVPNServerConfiguration_tags(t *testing.T) { - resourceName := "azurerm_vpn_server_configuration.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_vpn_server_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -191,16 +146,12 @@ func TestAccAzureRMVPNServerConfiguration_tags(t *testing.T) { CheckDestroy: testCheckAzureRMVPNServerConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAzureRMVPNServerConfiguration_tags(ri, location), + Config: testAccAzureRMAzureRMVPNServerConfiguration_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMVPNServerConfigurationExists(resourceName), + testCheckAzureRMVPNServerConfigurationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -253,8 +204,8 @@ func testCheckAzureRMVPNServerConfigurationDestroy(s *terraform.State) error { return nil } -func testAccAzureRMAzureRMVPNServerConfiguration_azureAD(rInt int, location string) string { - template := testAccAzureRMAzureRMVPNServerConfiguration_template(rInt, location) +func testAccAzureRMAzureRMVPNServerConfiguration_azureAD(data acceptance.TestData) string { + template := testAccAzureRMAzureRMVPNServerConfiguration_template(data) return fmt.Sprintf(` %s @@ -270,11 +221,11 @@ resource "azurerm_vpn_server_configuration" "test" { tenant = "example.onmicrosoft.com" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAzureRMVPNServerConfiguration_certificate(rInt int, location string) string { - template := testAccAzureRMAzureRMVPNServerConfiguration_template(rInt, location) +func testAccAzureRMAzureRMVPNServerConfiguration_certificate(data acceptance.TestData) string { + template := testAccAzureRMAzureRMVPNServerConfiguration_template(data) return fmt.Sprintf(` %s @@ -310,11 +261,11 @@ M/s/1JRtO3bDSzD9TazRVzn2oBqzSa8VgIo5C1nOnoAKJTlsClJKvIhnRlaLQqk= EOF } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAzureRMVPNServerConfiguration_certificateUpdated(rInt int, location string) string { - template := testAccAzureRMAzureRMVPNServerConfiguration_template(rInt, location) +func testAccAzureRMAzureRMVPNServerConfiguration_certificateUpdated(data acceptance.TestData) string { + template := testAccAzureRMAzureRMVPNServerConfiguration_template(data) return fmt.Sprintf(` %s @@ -355,11 +306,11 @@ EOF thumbprint = "83FFBFC8848B5A5836C94D0112367E16148A286F" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAzureRMVPNServerConfiguration_radius(rInt int, location string) string { - template := testAccAzureRMAzureRMVPNServerConfiguration_template(rInt, location) +func testAccAzureRMAzureRMVPNServerConfiguration_radius(data acceptance.TestData) string { + template := testAccAzureRMAzureRMVPNServerConfiguration_template(data) return fmt.Sprintf(` %s @@ -400,11 +351,11 @@ EOF } } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAzureRMVPNServerConfiguration_requiresImport(rInt int, location string) string { - template := testAccAzureRMAzureRMVPNServerConfiguration_certificate(rInt, location) +func testAccAzureRMAzureRMVPNServerConfiguration_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAzureRMVPNServerConfiguration_certificate(data) return fmt.Sprintf(` %s @@ -443,8 +394,8 @@ EOF `, template) } -func testAccAzureRMAzureRMVPNServerConfiguration_tags(rInt int, location string) string { - template := testAccAzureRMAzureRMVPNServerConfiguration_template(rInt, location) +func testAccAzureRMAzureRMVPNServerConfiguration_tags(data acceptance.TestData) string { + template := testAccAzureRMAzureRMVPNServerConfiguration_template(data) return fmt.Sprintf(` %s @@ -484,10 +435,10 @@ EOF Hello = "World" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMAzureRMVPNServerConfiguration_template(rInt int, location string) string { +func testAccAzureRMAzureRMVPNServerConfiguration_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -506,5 +457,5 @@ resource "azurerm_virtual_wan" "test" { resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/network/tests/resource_arm_web_application_firewall_policy_test.go b/azurerm/internal/services/network/tests/resource_arm_web_application_firewall_policy_test.go new file mode 100644 index 000000000000..8beb101215d3 --- /dev/null +++ b/azurerm/internal/services/network/tests/resource_arm_web_application_firewall_policy_test.go @@ -0,0 +1,262 @@ +package tests + +import ( + "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/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMWebApplicationFirewallPolicy_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_web_application_firewall_policy", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMWebApplicationFirewallPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMWebApplicationFirewallPolicy_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMWebApplicationFirewallPolicyExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMWebApplicationFirewallPolicy_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_web_application_firewall_policy", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMWebApplicationFirewallPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMWebApplicationFirewallPolicy_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMWebApplicationFirewallPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.name", "Rule1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.priority", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.rule_type", "MatchRule"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.match_variables.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.match_variables.0.variable_name", "RemoteAddr"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.operator", "IPMatch"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.negation_condition", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.match_values.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.match_values.0", "192.168.1.0/24"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.match_values.1", "10.0.0.0/24"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.action", "Block"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.name", "Rule2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.priority", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.rule_type", "MatchRule"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.match_variables.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.match_variables.0.variable_name", "RemoteAddr"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.operator", "IPMatch"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.negation_condition", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.match_values.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.match_values.0", "192.168.1.0/24"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.match_variables.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.match_variables.0.variable_name", "RequestHeaders"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.match_variables.0.selector", "UserAgent"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.operator", "Contains"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.negation_condition", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.match_values.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.match_values.0", "Windows"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.action", "Block"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMWebApplicationFirewallPolicy_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_web_application_firewall_policy", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMWebApplicationFirewallPolicyDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMWebApplicationFirewallPolicy_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMWebApplicationFirewallPolicyExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMWebApplicationFirewallPolicy_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMWebApplicationFirewallPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.name", "Rule1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.priority", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.rule_type", "MatchRule"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.match_variables.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.match_variables.0.variable_name", "RemoteAddr"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.operator", "IPMatch"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.negation_condition", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.match_values.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.match_values.0", "192.168.1.0/24"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.match_conditions.0.match_values.1", "10.0.0.0/24"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.0.action", "Block"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.name", "Rule2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.priority", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.rule_type", "MatchRule"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.match_variables.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.match_variables.0.variable_name", "RemoteAddr"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.operator", "IPMatch"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.negation_condition", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.match_values.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.0.match_values.0", "192.168.1.0/24"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.match_variables.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.match_variables.0.variable_name", "RequestHeaders"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.match_variables.0.selector", "UserAgent"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.operator", "Contains"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.negation_condition", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.match_values.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.match_conditions.1.match_values.0", "Windows"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rules.1.action", "Block"), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMWebApplicationFirewallPolicyExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Web Application Firewall Policy not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + client := acceptance.AzureProvider.Meta().(*clients.Client).Network.WebApplicationFirewallPoliciesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + if resp, err := client.Get(ctx, resourceGroup, name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Web Application Firewall Policy %q (Resource Group %q) does not exist", name, resourceGroup) + } + return fmt.Errorf("Bad: Get on network.WebApplicationFirewallPoliciesClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMWebApplicationFirewallPolicyDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Network.WebApplicationFirewallPoliciesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_web_application_firewall_policy" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + if resp, err := client.Get(ctx, resourceGroup, name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on network.WebApplicationFirewallPoliciesClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMWebApplicationFirewallPolicy_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_web_application_firewall_policy" "test" { + name = "acctestwafpolicy-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMWebApplicationFirewallPolicy_complete(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_web_application_firewall_policy" "test" { + name = "acctestwafpolicy-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + + custom_rules { + name = "Rule1" + priority = 1 + rule_type = "MatchRule" + + match_conditions { + match_variables { + variable_name = "RemoteAddr" + } + + operator = "IPMatch" + negation_condition = false + match_values = ["192.168.1.0/24", "10.0.0.0/24"] + } + + action = "Block" + } + + custom_rules { + name = "Rule2" + priority = 2 + rule_type = "MatchRule" + + match_conditions { + match_variables { + variable_name = "RemoteAddr" + } + + operator = "IPMatch" + negation_condition = false + match_values = ["192.168.1.0/24"] + } + + match_conditions { + match_variables { + variable_name = "RequestHeaders" + selector = "UserAgent" + } + + operator = "Contains" + negation_condition = false + match_values = ["Windows"] + } + + action = "Block" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} diff --git a/azurerm/internal/services/network/testdata/app_service_certificate.pfx b/azurerm/internal/services/network/tests/testdata/app_service_certificate.pfx similarity index 100% rename from azurerm/internal/services/network/testdata/app_service_certificate.pfx rename to azurerm/internal/services/network/tests/testdata/app_service_certificate.pfx diff --git a/azurerm/internal/services/network/testdata/application_gateway_test.cer b/azurerm/internal/services/network/tests/testdata/application_gateway_test.cer similarity index 100% rename from azurerm/internal/services/network/testdata/application_gateway_test.cer rename to azurerm/internal/services/network/tests/testdata/application_gateway_test.cer diff --git a/azurerm/internal/services/network/testdata/application_gateway_test.pfx b/azurerm/internal/services/network/tests/testdata/application_gateway_test.pfx similarity index 100% rename from azurerm/internal/services/network/testdata/application_gateway_test.pfx rename to azurerm/internal/services/network/tests/testdata/application_gateway_test.pfx diff --git a/azurerm/internal/services/network/testdata/application_gateway_test_2.crt b/azurerm/internal/services/network/tests/testdata/application_gateway_test_2.crt similarity index 100% rename from azurerm/internal/services/network/testdata/application_gateway_test_2.crt rename to azurerm/internal/services/network/tests/testdata/application_gateway_test_2.crt diff --git a/azurerm/internal/services/network/testdata/application_gateway_test_2.pfx b/azurerm/internal/services/network/tests/testdata/application_gateway_test_2.pfx similarity index 100% rename from azurerm/internal/services/network/testdata/application_gateway_test_2.pfx rename to azurerm/internal/services/network/tests/testdata/application_gateway_test_2.pfx From 8b258f44a13a854d90a3b74a8ec747d72902eb29 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 11:11:53 -0800 Subject: [PATCH 140/203] move batch testdata into tests package --- .../{ => tests}/testdata/batch_certificate.cer | 0 .../{ => tests}/testdata/batch_certificate.pfx | Bin 2 files changed, 0 insertions(+), 0 deletions(-) rename azurerm/internal/services/batch/{ => tests}/testdata/batch_certificate.cer (100%) rename azurerm/internal/services/batch/{ => tests}/testdata/batch_certificate.pfx (100%) diff --git a/azurerm/internal/services/batch/testdata/batch_certificate.cer b/azurerm/internal/services/batch/tests/testdata/batch_certificate.cer similarity index 100% rename from azurerm/internal/services/batch/testdata/batch_certificate.cer rename to azurerm/internal/services/batch/tests/testdata/batch_certificate.cer diff --git a/azurerm/internal/services/batch/testdata/batch_certificate.pfx b/azurerm/internal/services/batch/tests/testdata/batch_certificate.pfx similarity index 100% rename from azurerm/internal/services/batch/testdata/batch_certificate.pfx rename to azurerm/internal/services/batch/tests/testdata/batch_certificate.pfx From ac32aec279a6469a3b86c3066c0bbae205b55c54 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 11:38:49 -0800 Subject: [PATCH 141/203] move eventhub testdata into tests package --- .../eventhub/resource_arm_eventhub.go | 12 +- .../data_source_eventhub_namespace_test.go | 33 ++- ...ce_arm_eventhub_authorization_rule_test.go | 94 ++++---- ...source_arm_eventhub_consumer_group_test.go | 71 ++---- ...nthub_namespace_authorization_rule_test.go | 92 +++---- ...namespace_disaster_recovery_config_test.go | 64 ++--- .../resource_arm_eventhub_namespace_test.go | 227 ++++++++---------- .../{ => tests}/resource_arm_eventhub_test.go | 152 +++++------- 8 files changed, 308 insertions(+), 437 deletions(-) rename azurerm/internal/services/eventhub/{ => tests}/data_source_eventhub_namespace_test.go (65%) rename azurerm/internal/services/eventhub/{ => tests}/resource_arm_eventhub_authorization_rule_test.go (65%) rename azurerm/internal/services/eventhub/{ => tests}/resource_arm_eventhub_consumer_group_test.go (76%) rename azurerm/internal/services/eventhub/{ => tests}/resource_arm_eventhub_namespace_authorization_rule_test.go (67%) rename azurerm/internal/services/eventhub/{ => tests}/resource_arm_eventhub_namespace_disaster_recovery_config_test.go (85%) rename azurerm/internal/services/eventhub/{ => tests}/resource_arm_eventhub_namespace_test.go (68%) rename azurerm/internal/services/eventhub/{ => tests}/resource_arm_eventhub_test.go (75%) diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub.go b/azurerm/internal/services/eventhub/resource_arm_eventhub.go index 504604bb2618..a16f9b115fcd 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub.go +++ b/azurerm/internal/services/eventhub/resource_arm_eventhub.go @@ -59,13 +59,13 @@ func resourceArmEventHub() *schema.Resource { Type: schema.TypeInt, Required: true, ForceNew: true, - ValidateFunc: validateEventHubPartitionCount, + ValidateFunc: ValidateEventHubPartitionCount, }, "message_retention": { Type: schema.TypeInt, Required: true, - ValidateFunc: validateEventHubMessageRetentionCount, + ValidateFunc: ValidateEventHubMessageRetentionCount, }, "capture_description": { @@ -123,7 +123,7 @@ func resourceArmEventHub() *schema.Resource { "archive_name_format": { Type: schema.TypeString, Required: true, - ValidateFunc: validateEventHubArchiveNameFormat, + ValidateFunc: ValidateEventHubArchiveNameFormat, }, "blob_container_name": { Type: schema.TypeString, @@ -276,7 +276,7 @@ func resourceArmEventHubDelete(d *schema.ResourceData, meta interface{}) error { return nil } -func validateEventHubPartitionCount(v interface{}, _ string) (warnings []string, errors []error) { +func ValidateEventHubPartitionCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) if !(32 >= value && value >= 1) { @@ -286,7 +286,7 @@ func validateEventHubPartitionCount(v interface{}, _ string) (warnings []string, return warnings, errors } -func validateEventHubMessageRetentionCount(v interface{}, _ string) (warnings []string, errors []error) { +func ValidateEventHubMessageRetentionCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) if !(7 >= value && value >= 1) { @@ -296,7 +296,7 @@ func validateEventHubMessageRetentionCount(v interface{}, _ string) (warnings [] return warnings, errors } -func validateEventHubArchiveNameFormat(v interface{}, k string) (warnings []string, errors []error) { +func ValidateEventHubArchiveNameFormat(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) requiredComponents := []string{ diff --git a/azurerm/internal/services/eventhub/data_source_eventhub_namespace_test.go b/azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_test.go similarity index 65% rename from azurerm/internal/services/eventhub/data_source_eventhub_namespace_test.go rename to azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_test.go index a7f69e2ab7eb..70480fb0f447 100644 --- a/azurerm/internal/services/eventhub/data_source_eventhub_namespace_test.go +++ b/azurerm/internal/services/eventhub/tests/data_source_eventhub_namespace_test.go @@ -1,27 +1,24 @@ -package eventhub +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMEventHubNamespace_basic(t *testing.T) { - dataSourceName := "data.azurerm_eventhub_namespace.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_eventhub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceEventHubNamespace_basic(rInt, location), + Config: testAccDataSourceEventHubNamespace_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "sku", "Basic"), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Basic"), ), }, }, @@ -29,28 +26,26 @@ func TestAccDataSourceAzureRMEventHubNamespace_basic(t *testing.T) { } func TestAccDataSourceAzureRMEventHubNamespace_complete(t *testing.T) { - dataSourceName := "data.azurerm_eventhub_namespace.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_eventhub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceEventHubNamespace_complete(rInt, location), + Config: testAccDataSourceEventHubNamespace_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "sku", "Standard"), - resource.TestCheckResourceAttr(dataSourceName, "capacity", "2"), - resource.TestCheckResourceAttr(dataSourceName, "auto_inflate_enabled", "true"), - resource.TestCheckResourceAttr(dataSourceName, "maximum_throughput_units", "20"), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "auto_inflate_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "maximum_throughput_units", "20"), ), }, }, }) } -func testAccDataSourceEventHubNamespace_basic(rInt int, location string) string { +func testAccDataSourceEventHubNamespace_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -68,10 +63,10 @@ data "azurerm_eventhub_namespace" "test" { name = "${azurerm_eventhub_namespace.test.name}" resource_group_name = "${azurerm_eventhub_namespace.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceEventHubNamespace_complete(rInt int, location string) string { +func testAccDataSourceEventHubNamespace_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -92,5 +87,5 @@ data "azurerm_eventhub_namespace" "test" { name = "${azurerm_eventhub_namespace.test.name}" resource_group_name = "${azurerm_eventhub_namespace.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_authorization_rule_test.go similarity index 65% rename from azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule_test.go rename to azurerm/internal/services/eventhub/tests/resource_arm_eventhub_authorization_rule_test.go index 3900818828f8..a5988f25d892 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub_authorization_rule_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_authorization_rule_test.go @@ -1,4 +1,4 @@ -package eventhub +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -31,7 +30,7 @@ func TestAccAzureRMEventHubAuthorizationRule_manage(t *testing.T) { } func testAccAzureRMEventHubAuthorizationRule(t *testing.T, listen, send, manage bool) { - resourceName := "azurerm_eventhub_authorization_rule.test" + data := acceptance.BuildTestData(t, "azurerm_eventhub_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -39,26 +38,22 @@ func testAccAzureRMEventHubAuthorizationRule(t *testing.T, listen, send, manage CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), listen, send, manage), + Config: testAccAzureRMEventHubAuthorizationRule_base(data, listen, send, manage), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "eventhub_name"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttr(resourceName, "listen", strconv.FormatBool(listen)), - resource.TestCheckResourceAttr(resourceName, "send", strconv.FormatBool(send)), - resource.TestCheckResourceAttr(resourceName, "manage", strconv.FormatBool(manage)), + testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "eventhub_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", strconv.FormatBool(listen)), + resource.TestCheckResourceAttr(data.ResourceName, "send", strconv.FormatBool(send)), + resource.TestCheckResourceAttr(data.ResourceName, "manage", strconv.FormatBool(manage)), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -69,10 +64,7 @@ func TestAccAzureRMEventHubAuthorizationRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_eventhub_authorization_rule.test" - rInt := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventhub_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,13 +72,13 @@ func TestAccAzureRMEventHubAuthorizationRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubAuthorizationRule_base(rInt, location, true, true, true), + Config: testAccAzureRMEventHubAuthorizationRule_base(data, true, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubAuthorizationRuleExists(resourceName), + testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName), ), }, { - Config: testAccAzureRMEventHubAuthorizationRule_requiresImport(rInt, location, true, true, true), + Config: testAccAzureRMEventHubAuthorizationRule_requiresImport(data, true, true, true), ExpectError: acceptance.RequiresImportError("azurerm_eventhub_authorization_rule"), }, }, @@ -94,7 +86,7 @@ func TestAccAzureRMEventHubAuthorizationRule_requiresImport(t *testing.T) { } func TestAccAzureRMEventHubAuthorizationRule_rightsUpdate(t *testing.T) { - resourceName := "azurerm_eventhub_authorization_rule.test" + data := acceptance.BuildTestData(t, "azurerm_eventhub_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -102,34 +94,30 @@ func TestAccAzureRMEventHubAuthorizationRule_rightsUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), true, false, false), + Config: testAccAzureRMEventHubAuthorizationRule_base(data, true, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), + testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), ), }, { - Config: testAccAzureRMEventHubAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), true, true, true), + Config: testAccAzureRMEventHubAuthorizationRule_base(data, true, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "true"), - resource.TestCheckResourceAttr(resourceName, "manage", "true"), + testCheckAzureRMEventHubAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -190,7 +178,7 @@ func testCheckAzureRMEventHubAuthorizationRuleExists(resourceName string) resour } } -func testAccAzureRMEventHubAuthorizationRule_base(rInt int, location string, listen, send, manage bool) string { +func testAccAzureRMEventHubAuthorizationRule_base(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -224,11 +212,11 @@ resource "azurerm_eventhub_authorization_rule" "test" { send = %[4]t manage = %[5]t } -`, rInt, location, listen, send, manage) +`, data.RandomInteger, data.Locations.Primary, listen, send, manage) } -func testAccAzureRMEventHubAuthorizationRule_requiresImport(rInt int, location string, listen, send, manage bool) string { - template := testAccAzureRMEventHubAuthorizationRule_base(rInt, location, listen, send, manage) +func testAccAzureRMEventHubAuthorizationRule_requiresImport(data acceptance.TestData, listen, send, manage bool) string { + template := testAccAzureRMEventHubAuthorizationRule_base(data, listen, send, manage) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_consumer_group_test.go similarity index 76% rename from azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group_test.go rename to azurerm/internal/services/eventhub/tests/resource_arm_eventhub_consumer_group_test.go index 2e3162d92856..43442993f452 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub_consumer_group_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_consumer_group_test.go @@ -1,4 +1,4 @@ -package eventhub +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,8 +13,7 @@ import ( ) func TestAccAzureRMEventHubConsumerGroup_basic(t *testing.T) { - resourceName := "azurerm_eventhub_consumer_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_consumer_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,16 +21,12 @@ func TestAccAzureRMEventHubConsumerGroup_basic(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubConsumerGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubConsumerGroup_basic(ri, acceptance.Location()), + Config: testAccAzureRMEventHubConsumerGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubConsumerGroupExists(resourceName), + testCheckAzureRMEventHubConsumerGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -43,10 +37,7 @@ func TestAccAzureRMEventHubConsumerGroup_requiresImport(t *testing.T) { return } - resourceName := "azurerm_eventhub_consumer_group.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventhub_consumer_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,13 +45,13 @@ func TestAccAzureRMEventHubConsumerGroup_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubConsumerGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubConsumerGroup_basic(ri, location), + Config: testAccAzureRMEventHubConsumerGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubConsumerGroupExists(resourceName), + testCheckAzureRMEventHubConsumerGroupExists(data.ResourceName), ), }, { - Config: testAccAzureRMEventHubConsumerGroup_requiresImport(ri, location), + Config: testAccAzureRMEventHubConsumerGroup_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_eventhub_consumer_group"), }, }, @@ -68,8 +59,7 @@ func TestAccAzureRMEventHubConsumerGroup_requiresImport(t *testing.T) { } func TestAccAzureRMEventHubConsumerGroup_complete(t *testing.T) { - resourceName := "azurerm_eventhub_consumer_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_consumer_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -77,23 +67,18 @@ func TestAccAzureRMEventHubConsumerGroup_complete(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubConsumerGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubConsumerGroup_complete(ri, acceptance.Location()), + Config: testAccAzureRMEventHubConsumerGroup_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubConsumerGroupExists(resourceName), + testCheckAzureRMEventHubConsumerGroupExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventHubConsumerGroup_userMetadataUpdate(t *testing.T) { - resourceName := "azurerm_eventhub_consumer_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_consumer_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -101,23 +86,19 @@ func TestAccAzureRMEventHubConsumerGroup_userMetadataUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubConsumerGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubConsumerGroup_basic(ri, acceptance.Location()), + Config: testAccAzureRMEventHubConsumerGroup_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubConsumerGroupExists(resourceName), + testCheckAzureRMEventHubConsumerGroupExists(data.ResourceName), ), }, { - Config: testAccAzureRMEventHubConsumerGroup_complete(ri, acceptance.Location()), + Config: testAccAzureRMEventHubConsumerGroup_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubConsumerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "user_metadata", "some-meta-data"), + testCheckAzureRMEventHubConsumerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "user_metadata", "some-meta-data"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -181,7 +162,7 @@ func testCheckAzureRMEventHubConsumerGroupExists(resourceName string) resource.T } } -func testAccAzureRMEventHubConsumerGroup_basic(rInt int, location string) string { +func testAccAzureRMEventHubConsumerGroup_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -209,11 +190,11 @@ resource "azurerm_eventhub_consumer_group" "test" { eventhub_name = "${azurerm_eventhub.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMEventHubConsumerGroup_requiresImport(rInt int, location string) string { - template := testAccAzureRMEventHubConsumerGroup_basic(rInt, location) +func testAccAzureRMEventHubConsumerGroup_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMEventHubConsumerGroup_basic(data) return fmt.Sprintf(` %s @@ -226,7 +207,7 @@ resource "azurerm_eventhub_consumer_group" "import" { `, template) } -func testAccAzureRMEventHubConsumerGroup_complete(rInt int, location string) string { +func testAccAzureRMEventHubConsumerGroup_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -255,5 +236,5 @@ resource "azurerm_eventhub_consumer_group" "test" { resource_group_name = "${azurerm_resource_group.test.name}" user_metadata = "some-meta-data" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_authorization_rule_test.go similarity index 67% rename from azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule_test.go rename to azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_authorization_rule_test.go index 27d6075ff11e..d82e9e238fb6 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_authorization_rule_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_authorization_rule_test.go @@ -1,4 +1,4 @@ -package eventhub +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -31,7 +30,7 @@ func TestAccAzureRMEventHubNamespaceAuthorizationRule_manage(t *testing.T) { } func testAccAzureRMEventHubNamespaceAuthorizationRule(t *testing.T, listen, send, manage bool) { - resourceName := "azurerm_eventhub_namespace_authorization_rule.test" + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -39,25 +38,21 @@ func testAccAzureRMEventHubNamespaceAuthorizationRule(t *testing.T, listen, send CheckDestroy: testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), listen, send, manage), + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(data, listen, send, manage), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttr(resourceName, "listen", strconv.FormatBool(listen)), - resource.TestCheckResourceAttr(resourceName, "send", strconv.FormatBool(send)), - resource.TestCheckResourceAttr(resourceName, "manage", strconv.FormatBool(manage)), + testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", strconv.FormatBool(listen)), + resource.TestCheckResourceAttr(data.ResourceName, "send", strconv.FormatBool(send)), + resource.TestCheckResourceAttr(data.ResourceName, "manage", strconv.FormatBool(manage)), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -68,10 +63,7 @@ func TestAccAzureRMEventHubNamespaceAuthorizationRule_requiresImport(t *testing. return } - resourceName := "azurerm_eventhub_namespace_authorization_rule.test" - rInt := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,13 +71,13 @@ func TestAccAzureRMEventHubNamespaceAuthorizationRule_requiresImport(t *testing. CheckDestroy: testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(rInt, location, true, true, true), + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(data, true, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName), + testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(data.ResourceName), ), }, { - Config: testAccAzureRMEventHubNamespaceAuthorizationRule_requiresImport(rInt, location, true, true, true), + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_requiresImport(data, true, true, true), ExpectError: acceptance.RequiresImportError("azurerm_eventhub_namespace_authorization_rule"), }, }, @@ -93,7 +85,7 @@ func TestAccAzureRMEventHubNamespaceAuthorizationRule_requiresImport(t *testing. } func TestAccAzureRMEventHubNamespaceAuthorizationRule_rightsUpdate(t *testing.T) { - resourceName := "azurerm_eventhub_namespace_authorization_rule.test" + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_authorization_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -101,34 +93,30 @@ func TestAccAzureRMEventHubNamespaceAuthorizationRule_rightsUpdate(t *testing.T) CheckDestroy: testCheckAzureRMEventHubNamespaceAuthorizationRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), true, false, false), + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(data, true, false, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "false"), - resource.TestCheckResourceAttr(resourceName, "manage", "false"), + testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "false"), ), }, { - Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(tf.AccRandTimeInt(), acceptance.Location(), true, true, true), + Config: testAccAzureRMEventHubNamespaceAuthorizationRule_base(data, true, true, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "namespace_name"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), - resource.TestCheckResourceAttr(resourceName, "listen", "true"), - resource.TestCheckResourceAttr(resourceName, "send", "true"), - resource.TestCheckResourceAttr(resourceName, "manage", "true"), + testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "namespace_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), + resource.TestCheckResourceAttr(data.ResourceName, "listen", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "send", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "manage", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -188,7 +176,7 @@ func testCheckAzureRMEventHubNamespaceAuthorizationRuleExists(resourceName strin } } -func testAccAzureRMEventHubNamespaceAuthorizationRule_base(rInt int, location string, listen, send, manage bool) string { +func testAccAzureRMEventHubNamespaceAuthorizationRule_base(data acceptance.TestData, listen, send, manage bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" @@ -212,11 +200,11 @@ resource "azurerm_eventhub_namespace_authorization_rule" "test" { send = %[4]t manage = %[5]t } -`, rInt, location, listen, send, manage) +`, data.RandomInteger, data.Locations.Primary, listen, send, manage) } -func testAccAzureRMEventHubNamespaceAuthorizationRule_requiresImport(rInt int, location string, listen, send, manage bool) string { - template := testAccAzureRMEventHubNamespaceAuthorizationRule_base(rInt, location, listen, send, manage) +func testAccAzureRMEventHubNamespaceAuthorizationRule_requiresImport(data acceptance.TestData, listen, send, manage bool) string { + template := testAccAzureRMEventHubNamespaceAuthorizationRule_base(data, listen, send, manage) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_disaster_recovery_config_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go similarity index 85% rename from azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_disaster_recovery_config_test.go rename to azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go index 8f07e2beb3f7..b8a4b5b91f6f 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_disaster_recovery_config_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go @@ -1,4 +1,4 @@ -package eventhub +package tests import ( "fmt" @@ -6,15 +6,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(t *testing.T) { - resourceName := "azurerm_eventhub_namespace_disaster_recovery_config.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_disaster_recovery_config", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,23 +20,18 @@ func TestAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName), + testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(t *testing.T) { - resourceName := "azurerm_eventhub_namespace_disaster_recovery_config.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_disaster_recovery_config", "test") // skipping due to there being no way to delete a DRC once an alternate name has been set // sdk bug: https://github.com/Azure/azure-sdk-for-go/issues/5893 @@ -50,23 +43,18 @@ func TestAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(t *testing.T CheckDestroy: testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName), + testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventHubNamespaceDisasterRecoveryConfig_update(t *testing.T) { - resourceName := "azurerm_eventhub_namespace_disaster_recovery_config.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace_disaster_recovery_config", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,24 +62,20 @@ func TestAccAzureRMEventHubNamespaceDisasterRecoveryConfig_update(t *testing.T) CheckDestroy: testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName), + testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(data.ResourceName), ), }, { - Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName), + testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated_removed(ri, acceptance.Location(), acceptance.AltLocation()), + Config: testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated_removed(data), }, }, }) @@ -149,7 +133,7 @@ func testCheckAzureRMEventHubNamespaceDisasterRecoveryConfigExists(resourceName } } -func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(rInt int, location string, altlocation string) string { +func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" @@ -177,10 +161,10 @@ resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { partner_namespace_id = "${azurerm_eventhub_namespace.testb.id}" } -`, rInt, location, altlocation) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Primary) } -func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(rInt int, location string, altlocation string) string { +func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" @@ -209,10 +193,10 @@ resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { alternate_name = "acctest-EHN-DRC-%[1]d-alt" } -`, rInt, location, altlocation) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) } -func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated(rInt int, location string, altlocation string) string { +func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" @@ -247,10 +231,10 @@ resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { partner_namespace_id = "${azurerm_eventhub_namespace.testc.id}" } -`, rInt, location, altlocation) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Primary) } -func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated_removed(rInt int, location string, altlocation string) string { +func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated_removed(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%[1]d" @@ -277,5 +261,5 @@ resource "azurerm_eventhub_namespace" "testc" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } -`, rInt, location, altlocation) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Primary) } diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_test.go similarity index 68% rename from azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_test.go rename to azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_test.go index f47a19679e75..6cfae0d74713 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub_namespace_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_test.go @@ -1,4 +1,4 @@ -package eventhub +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +14,7 @@ import ( ) func TestAccAzureRMEventHubNamespace_basic(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,16 +22,12 @@ func TestAccAzureRMEventHubNamespace_basic(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespace_basic(ri, acceptance.Location()), + Config: testAccAzureRMEventHubNamespace_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,10 +38,7 @@ func TestAccAzureRMEventHubNamespace_requiresImport(t *testing.T) { return } - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,13 +46,13 @@ func TestAccAzureRMEventHubNamespace_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespace_basic(ri, location), + Config: testAccAzureRMEventHubNamespace_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), ), }, { - Config: testAccAzureRMEventHubNamespace_requiresImport(ri, location), + Config: testAccAzureRMEventHubNamespace_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_eventhub_namespace"), }, }, @@ -69,8 +60,7 @@ func TestAccAzureRMEventHubNamespace_requiresImport(t *testing.T) { } func TestAccAzureRMEventHubNamespace_standard(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,23 +68,18 @@ func TestAccAzureRMEventHubNamespace_standard(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespace_standard(ri, acceptance.Location()), + Config: testAccAzureRMEventHubNamespace_standard(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventHubNamespace_networkrule_iprule(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -102,23 +87,18 @@ func TestAccAzureRMEventHubNamespace_networkrule_iprule(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespace_networkrule_iprule(ri, acceptance.Location()), + Config: testAccAzureRMEventHubNamespace_networkrule_iprule(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventHubNamespace_networkrule_vnet(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -126,23 +106,18 @@ func TestAccAzureRMEventHubNamespace_networkrule_vnet(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespace_networkrule_vnet(ri, acceptance.Location()), + Config: testAccAzureRMEventHubNamespace_networkrule_vnet(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventHubNamespace_readDefaultKeys(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -150,13 +125,13 @@ func TestAccAzureRMEventHubNamespace_readDefaultKeys(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespace_basic(ri, acceptance.Location()), + Config: testAccAzureRMEventHubNamespace_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), - resource.TestMatchResourceAttr(resourceName, "default_primary_connection_string", regexp.MustCompile("Endpoint=.+")), - resource.TestMatchResourceAttr(resourceName, "default_secondary_connection_string", regexp.MustCompile("Endpoint=.+")), - resource.TestMatchResourceAttr(resourceName, "default_primary_key", regexp.MustCompile(".+")), - resource.TestMatchResourceAttr(resourceName, "default_secondary_key", regexp.MustCompile(".+")), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + resource.TestMatchResourceAttr(data.ResourceName, "default_primary_connection_string", regexp.MustCompile("Endpoint=.+")), + resource.TestMatchResourceAttr(data.ResourceName, "default_secondary_connection_string", regexp.MustCompile("Endpoint=.+")), + resource.TestMatchResourceAttr(data.ResourceName, "default_primary_key", regexp.MustCompile(".+")), + resource.TestMatchResourceAttr(data.ResourceName, "default_secondary_key", regexp.MustCompile(".+")), ), }, }, @@ -164,8 +139,7 @@ func TestAccAzureRMEventHubNamespace_readDefaultKeys(t *testing.T) { } func TestAccAzureRMEventHubNamespace_maximumThroughputUnits(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -173,23 +147,20 @@ func TestAccAzureRMEventHubNamespace_maximumThroughputUnits(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespace_maximumThroughputUnits(ri, acceptance.Location()), + Config: testAccAzureRMEventHubNamespace_maximumThroughputUnits(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventHubNamespace_NonStandardCasing(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMEventHubNamespaceNonStandardCasing(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") + + config := testAccAzureRMEventHubNamespaceNonStandardCasing(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -212,10 +183,9 @@ func TestAccAzureRMEventHubNamespace_NonStandardCasing(t *testing.T) { } func TestAccAzureRMEventHubNamespace_BasicWithTagsUpdate(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMEventHubNamespace_basic(ri, acceptance.Location()) - postConfig := testAccAzureRMEventHubNamespace_basicWithTagsUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") + preConfig := testAccAzureRMEventHubNamespace_basic(data) + postConfig := testAccAzureRMEventHubNamespace_basicWithTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -225,14 +195,14 @@ func TestAccAzureRMEventHubNamespace_BasicWithTagsUpdate(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, }, @@ -240,9 +210,8 @@ func TestAccAzureRMEventHubNamespace_BasicWithTagsUpdate(t *testing.T) { } func TestAccAzureRMEventHubNamespace_BasicWithCapacity(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMEventHubNamespace_capacity(ri, acceptance.Location(), 20) + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") + config := testAccAzureRMEventHubNamespace_capacity(data, 20) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -252,8 +221,8 @@ func TestAccAzureRMEventHubNamespace_BasicWithCapacity(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "capacity", "20"), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "20"), ), }, }, @@ -261,10 +230,9 @@ func TestAccAzureRMEventHubNamespace_BasicWithCapacity(t *testing.T) { } func TestAccAzureRMEventHubNamespace_BasicWithCapacityUpdate(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMEventHubNamespace_capacity(ri, acceptance.Location(), 20) - postConfig := testAccAzureRMEventHubNamespace_capacity(ri, acceptance.Location(), 2) + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") + preConfig := testAccAzureRMEventHubNamespace_capacity(data, 20) + postConfig := testAccAzureRMEventHubNamespace_capacity(data, 2) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -274,15 +242,15 @@ func TestAccAzureRMEventHubNamespace_BasicWithCapacityUpdate(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "capacity", "20"), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "20"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "capacity", "2"), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "2"), ), }, }, @@ -290,10 +258,9 @@ func TestAccAzureRMEventHubNamespace_BasicWithCapacityUpdate(t *testing.T) { } func TestAccAzureRMEventHubNamespace_BasicWithSkuUpdate(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMEventHubNamespace_basic(ri, acceptance.Location()) - postConfig := testAccAzureRMEventHubNamespace_standard(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") + preConfig := testAccAzureRMEventHubNamespace_basic(data) + postConfig := testAccAzureRMEventHubNamespace_standard(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -303,16 +270,16 @@ func TestAccAzureRMEventHubNamespace_BasicWithSkuUpdate(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Basic"), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Basic"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Standard"), - resource.TestCheckResourceAttr(resourceName, "capacity", "2"), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "2"), ), }, }, @@ -320,10 +287,9 @@ func TestAccAzureRMEventHubNamespace_BasicWithSkuUpdate(t *testing.T) { } func TestAccAzureRMEventHubNamespace_maximumThroughputUnitsUpdate(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMEventHubNamespace_maximumThroughputUnits(ri, acceptance.Location()) - postConfig := testAccAzureRMEventHubNamespace_maximumThroughputUnitsUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") + preConfig := testAccAzureRMEventHubNamespace_maximumThroughputUnits(data) + postConfig := testAccAzureRMEventHubNamespace_maximumThroughputUnitsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -333,19 +299,19 @@ func TestAccAzureRMEventHubNamespace_maximumThroughputUnitsUpdate(t *testing.T) { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Standard"), - resource.TestCheckResourceAttr(resourceName, "capacity", "2"), - resource.TestCheckResourceAttr(resourceName, "maximum_throughput_units", "20"), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "maximum_throughput_units", "20"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Standard"), - resource.TestCheckResourceAttr(resourceName, "capacity", "1"), - resource.TestCheckResourceAttr(resourceName, "maximum_throughput_units", "1"), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "capacity", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "maximum_throughput_units", "1"), ), }, }, @@ -353,8 +319,7 @@ func TestAccAzureRMEventHubNamespace_maximumThroughputUnitsUpdate(t *testing.T) } func TestAccAzureRMEventHubNamespace_autoInfalteDisabledWithAutoInflateUnits(t *testing.T) { - resourceName := "azurerm_eventhub_namespace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub_namespace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -362,9 +327,9 @@ func TestAccAzureRMEventHubNamespace_autoInfalteDisabledWithAutoInflateUnits(t * CheckDestroy: testCheckAzureRMEventHubNamespaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHubNamespace_autoInfalteDisabledWithAutoInflateUnits(ri, acceptance.Location()), + Config: testAccAzureRMEventHubNamespace_autoInfalteDisabledWithAutoInflateUnits(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubNamespaceExists(resourceName), + testCheckAzureRMEventHubNamespaceExists(data.ResourceName), ), }, }, @@ -425,7 +390,7 @@ func testCheckAzureRMEventHubNamespaceExists(resourceName string) resource.TestC } } -func testAccAzureRMEventHubNamespace_basic(rInt int, location string) string { +func testAccAzureRMEventHubNamespace_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -438,11 +403,11 @@ resource "azurerm_eventhub_namespace" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "Basic" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMEventHubNamespace_requiresImport(rInt int, location string) string { - template := testAccAzureRMEventHubNamespace_basic(rInt, location) +func testAccAzureRMEventHubNamespace_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMEventHubNamespace_basic(data) return fmt.Sprintf(` %s @@ -455,7 +420,7 @@ resource "azurerm_eventhub_namespace" "import" { `, template) } -func testAccAzureRMEventHubNamespace_standard(rInt int, location string) string { +func testAccAzureRMEventHubNamespace_standard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -469,10 +434,10 @@ resource "azurerm_eventhub_namespace" "test" { sku = "Standard" capacity = "2" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMEventHubNamespace_networkrule_iprule(rInt int, location string) string { +func testAccAzureRMEventHubNamespace_networkrule_iprule(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -493,10 +458,10 @@ resource "azurerm_eventhub_namespace" "test" { } } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMEventHubNamespace_networkrule_vnet(rInt int, location string) string { +func testAccAzureRMEventHubNamespace_networkrule_vnet(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -533,10 +498,10 @@ resource "azurerm_eventhub_namespace" "test" { } } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMEventHubNamespaceNonStandardCasing(rInt int, location string) string { +func testAccAzureRMEventHubNamespaceNonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -549,10 +514,10 @@ resource "azurerm_eventhub_namespace" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "basic" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMEventHubNamespace_maximumThroughputUnits(rInt int, location string) string { +func testAccAzureRMEventHubNamespace_maximumThroughputUnits(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -568,10 +533,10 @@ resource "azurerm_eventhub_namespace" "test" { auto_inflate_enabled = true maximum_throughput_units = 20 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMEventHubNamespace_basicWithTagsUpdate(rInt int, location string) string { +func testAccAzureRMEventHubNamespace_basicWithTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -588,10 +553,10 @@ resource "azurerm_eventhub_namespace" "test" { environment = "Production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMEventHubNamespace_capacity(rInt int, location string, capacity int) string { +func testAccAzureRMEventHubNamespace_capacity(data acceptance.TestData, capacity int) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -605,10 +570,10 @@ resource "azurerm_eventhub_namespace" "test" { sku = "Basic" capacity = %d } -`, rInt, location, rInt, capacity) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, capacity) } -func testAccAzureRMEventHubNamespace_maximumThroughputUnitsUpdate(rInt int, location string) string { +func testAccAzureRMEventHubNamespace_maximumThroughputUnitsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -624,10 +589,10 @@ resource "azurerm_eventhub_namespace" "test" { auto_inflate_enabled = true maximum_throughput_units = 1 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMEventHubNamespace_autoInfalteDisabledWithAutoInflateUnits(rInt int, location string) string { +func testAccAzureRMEventHubNamespace_autoInfalteDisabledWithAutoInflateUnits(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -643,5 +608,5 @@ resource "azurerm_eventhub_namespace" "test" { auto_inflate_enabled = false maximum_throughput_units = 0 } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/eventhub/resource_arm_eventhub_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_test.go similarity index 75% rename from azurerm/internal/services/eventhub/resource_arm_eventhub_test.go rename to azurerm/internal/services/eventhub/tests/resource_arm_eventhub_test.go index 63cb17d9f0fa..2ea34ae38cf9 100644 --- a/azurerm/internal/services/eventhub/resource_arm_eventhub_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_test.go @@ -1,4 +1,4 @@ -package eventhub +package tests import ( "fmt" @@ -7,13 +7,12 @@ import ( "strconv" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/eventhub" ) func TestAccAzureRMEventHubPartitionCount_validation(t *testing.T) { @@ -52,7 +51,7 @@ func TestAccAzureRMEventHubPartitionCount_validation(t *testing.T) { } for _, tc := range cases { - _, errors := validateEventHubPartitionCount(tc.Value, "azurerm_eventhub") + _, errors := eventhub.ValidateEventHubPartitionCount(tc.Value, "azurerm_eventhub") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Azure RM EventHub Partition Count to trigger a validation error") @@ -96,7 +95,7 @@ func TestAccAzureRMEventHubMessageRetentionCount_validation(t *testing.T) { } for _, tc := range cases { - _, errors := validateEventHubMessageRetentionCount(tc.Value, "azurerm_eventhub") + _, errors := eventhub.ValidateEventHubMessageRetentionCount(tc.Value, "azurerm_eventhub") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Azure RM EventHub Message Retention Count to trigger a validation error") @@ -164,7 +163,7 @@ func TestAccAzureRMEventHubArchiveNameFormat_validation(t *testing.T) { } for _, tc := range cases { - _, errors := validateEventHubArchiveNameFormat(tc.Value, "azurerm_eventhub") + _, errors := eventhub.ValidateEventHubArchiveNameFormat(tc.Value, "azurerm_eventhub") if len(errors) != tc.ErrCount { t.Fatalf("Expected %q to trigger a validation error", tc.Value) @@ -173,8 +172,7 @@ func TestAccAzureRMEventHubArchiveNameFormat_validation(t *testing.T) { } func TestAccAzureRMEventHub_basic(t *testing.T) { - resourceName := "azurerm_eventhub.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -182,23 +180,18 @@ func TestAccAzureRMEventHub_basic(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHub_basic(ri, acceptance.Location(), 2), + Config: testAccAzureRMEventHub_basic(data, 2), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), + testCheckAzureRMEventHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventHub_basicOnePartition(t *testing.T) { - resourceName := "azurerm_eventhub.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -206,17 +199,13 @@ func TestAccAzureRMEventHub_basicOnePartition(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHub_basic(ri, acceptance.Location(), 1), + Config: testAccAzureRMEventHub_basic(data, 1), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "partition_count", "1"), + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "partition_count", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -227,10 +216,7 @@ func TestAccAzureRMEventHub_requiresImport(t *testing.T) { return } - resourceName := "azurerm_eventhub.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -238,13 +224,13 @@ func TestAccAzureRMEventHub_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHub_basic(ri, location, 2), + Config: testAccAzureRMEventHub_basic(data, 2), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), + testCheckAzureRMEventHubExists(data.ResourceName), ), }, { - Config: testAccAzureRMEventHub_requiresImport(ri, location), + Config: testAccAzureRMEventHub_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_eventhub"), }, }, @@ -252,10 +238,9 @@ func TestAccAzureRMEventHub_requiresImport(t *testing.T) { } func TestAccAzureRMEventHub_partitionCountUpdate(t *testing.T) { - resourceName := "azurerm_eventhub.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMEventHub_basic(ri, acceptance.Location(), 2) - postConfig := testAccAzureRMEventHub_partitionCountUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_eventhub", "test") + preConfig := testAccAzureRMEventHub_basic(data, 2) + postConfig := testAccAzureRMEventHub_partitionCountUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -265,15 +250,15 @@ func TestAccAzureRMEventHub_partitionCountUpdate(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "partition_count", "2"), + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "partition_count", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "partition_count", "10"), + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "partition_count", "10"), ), }, }, @@ -281,8 +266,7 @@ func TestAccAzureRMEventHub_partitionCountUpdate(t *testing.T) { } func TestAccAzureRMEventHub_standard(t *testing.T) { - resourceName := "azurerm_eventhub.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -290,24 +274,18 @@ func TestAccAzureRMEventHub_standard(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHub_standard(ri, acceptance.Location()), + Config: testAccAzureRMEventHub_standard(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), + testCheckAzureRMEventHubExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventHub_captureDescription(t *testing.T) { - resourceName := "azurerm_eventhub.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) + data := acceptance.BuildTestData(t, "azurerm_eventhub", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -315,30 +293,23 @@ func TestAccAzureRMEventHub_captureDescription(t *testing.T) { CheckDestroy: testCheckAzureRMEventHubDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventHub_captureDescription(ri, rs, acceptance.Location(), true), + Config: testAccAzureRMEventHub_captureDescription(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "capture_description.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "capture_description.0.skip_empty_archives", "true"), + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.skip_empty_archives", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventHub_captureDescriptionDisabled(t *testing.T) { - resourceName := "azurerm_eventhub.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(5) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventhub", "test") - config := testAccAzureRMEventHub_captureDescription(ri, rs, location, true) - updatedConfig := testAccAzureRMEventHub_captureDescription(ri, rs, location, false) + config := testAccAzureRMEventHub_captureDescription(data, true) + updatedConfig := testAccAzureRMEventHub_captureDescription(data, false) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -348,15 +319,15 @@ func TestAccAzureRMEventHub_captureDescriptionDisabled(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "capture_description.0.enabled", "true"), + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.enabled", "true"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "capture_description.0.enabled", "false"), + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "capture_description.0.enabled", "false"), ), }, }, @@ -364,10 +335,9 @@ func TestAccAzureRMEventHub_captureDescriptionDisabled(t *testing.T) { } func TestAccAzureRMEventHub_messageRetentionUpdate(t *testing.T) { - resourceName := "azurerm_eventhub.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMEventHub_standard(ri, acceptance.Location()) - postConfig := testAccAzureRMEventHub_messageRetentionUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_eventhub", "test") + preConfig := testAccAzureRMEventHub_standard(data) + postConfig := testAccAzureRMEventHub_messageRetentionUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -377,15 +347,15 @@ func TestAccAzureRMEventHub_messageRetentionUpdate(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "message_retention", "7"), + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "message_retention", "7"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventHubExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "message_retention", "5"), + testCheckAzureRMEventHubExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "message_retention", "5"), ), }, }, @@ -450,7 +420,7 @@ func testCheckAzureRMEventHubExists(resourceName string) resource.TestCheckFunc } } -func testAccAzureRMEventHub_basic(rInt int, location string, partitionCount int) string { +func testAccAzureRMEventHub_basic(data acceptance.TestData, partitionCount int) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%d" @@ -471,11 +441,11 @@ resource "azurerm_eventhub" "test" { partition_count = %d message_retention = 1 } -`, rInt, location, rInt, rInt, partitionCount) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, partitionCount) } -func testAccAzureRMEventHub_requiresImport(rInt int, location string) string { - template := testAccAzureRMEventHub_basic(rInt, location, 2) +func testAccAzureRMEventHub_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMEventHub_basic(data, 2) return fmt.Sprintf(` %s @@ -489,7 +459,7 @@ resource "azurerm_eventhub" "import" { `, template) } -func testAccAzureRMEventHub_partitionCountUpdate(rInt int, location string) string { +func testAccAzureRMEventHub_partitionCountUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%d" @@ -510,10 +480,10 @@ resource "azurerm_eventhub" "test" { partition_count = 10 message_retention = 1 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMEventHub_standard(rInt int, location string) string { +func testAccAzureRMEventHub_standard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%d" @@ -534,10 +504,10 @@ resource "azurerm_eventhub" "test" { partition_count = 2 message_retention = 7 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMEventHub_captureDescription(rInt int, rString string, location string, enabled bool) string { +func testAccAzureRMEventHub_captureDescription(data acceptance.TestData, enabled bool) string { enabledString := strconv.FormatBool(enabled) return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -589,10 +559,10 @@ resource "azurerm_eventhub" "test" { } } } -`, rInt, location, rString, rInt, rInt, enabledString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger, enabledString) } -func testAccAzureRMEventHub_messageRetentionUpdate(rInt int, location string) string { +func testAccAzureRMEventHub_messageRetentionUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-eventhub-%d" @@ -613,5 +583,5 @@ resource "azurerm_eventhub" "test" { partition_count = 2 message_retention = 5 } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } From 2a2c542b1cca2f8f782b0af3753d17e6f35c55c6 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 11:45:48 -0800 Subject: [PATCH 142/203] move eventgrid testdata into tests package --- .../resource_arm_eventgrid_domain_test.go | 75 ++++------ ...e_arm_eventgrid_event_subscription_test.go | 141 +++++++----------- .../resource_arm_eventgrid_topic_test.go | 66 ++++---- 3 files changed, 111 insertions(+), 171 deletions(-) rename azurerm/internal/services/eventgrid/{ => tests}/resource_arm_eventgrid_domain_test.go (67%) rename azurerm/internal/services/eventgrid/{ => tests}/resource_arm_eventgrid_event_subscription_test.go (65%) rename azurerm/internal/services/eventgrid/{ => tests}/resource_arm_eventgrid_topic_test.go (72%) diff --git a/azurerm/internal/services/eventgrid/resource_arm_eventgrid_domain_test.go b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_domain_test.go similarity index 67% rename from azurerm/internal/services/eventgrid/resource_arm_eventgrid_domain_test.go rename to azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_domain_test.go index 2e2aa2b83991..7df3d399a2e1 100644 --- a/azurerm/internal/services/eventgrid/resource_arm_eventgrid_domain_test.go +++ b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_domain_test.go @@ -1,4 +1,4 @@ -package eventgrid +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMEventGridDomain_basic(t *testing.T) { - resourceName := "azurerm_eventgrid_domain.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventgrid_domain", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,27 +21,21 @@ func TestAccAzureRMEventGridDomain_basic(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridDomainDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridDomain_basic(ri, location), + Config: testAccAzureRMEventGridDomain_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridDomainExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMEventGridDomainExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventGridDomain_mapping(t *testing.T) { - resourceName := "azurerm_eventgrid_domain.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventgrid_domain", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,28 +43,22 @@ func TestAccAzureRMEventGridDomain_mapping(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridDomainDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridDomain_mapping(ri, location), + Config: testAccAzureRMEventGridDomain_mapping(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridDomainExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "input_mapping_fields.0.topic", "test"), - resource.TestCheckResourceAttr(resourceName, "input_mapping_fields.0.topic", "test"), - resource.TestCheckResourceAttr(resourceName, "input_mapping_default_values.0.data_version", "1.0"), - resource.TestCheckResourceAttr(resourceName, "input_mapping_default_values.0.subject", "DefaultSubject"), + testCheckAzureRMEventGridDomainExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "input_mapping_fields.0.topic", "test"), + resource.TestCheckResourceAttr(data.ResourceName, "input_mapping_fields.0.topic", "test"), + resource.TestCheckResourceAttr(data.ResourceName, "input_mapping_default_values.0.data_version", "1.0"), + resource.TestCheckResourceAttr(data.ResourceName, "input_mapping_default_values.0.subject", "DefaultSubject"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventGridDomain_basicWithTags(t *testing.T) { - resourceName := "azurerm_eventgrid_domain.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventgrid_domain", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,18 +66,14 @@ func TestAccAzureRMEventGridDomain_basicWithTags(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridDomainDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridDomain_basicWithTags(ri, location), + Config: testAccAzureRMEventGridDomain_basicWithTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridDomainExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"), + testCheckAzureRMEventGridDomainExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.foo", "bar"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -155,7 +136,7 @@ func testCheckAzureRMEventGridDomainExists(resourceName string) resource.TestChe } } -func testAccAzureRMEventGridDomain_basic(rInt int, location string) string { +func testAccAzureRMEventGridDomain_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -167,10 +148,10 @@ resource "azurerm_eventgrid_domain" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMEventGridDomain_mapping(rInt int, location string) string { +func testAccAzureRMEventGridDomain_mapping(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -194,10 +175,10 @@ resource "azurerm_eventgrid_domain" "test" { subject = "DefaultSubject" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMEventGridDomain_basicWithTags(rInt int, location string) string { +func testAccAzureRMEventGridDomain_basicWithTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -213,5 +194,5 @@ resource "azurerm_eventgrid_domain" "test" { "foo" = "bar" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription_test.go b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go similarity index 65% rename from azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription_test.go rename to azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go index cbdc77d7e354..9b1aa9c282a6 100644 --- a/azurerm/internal/services/eventgrid/resource_arm_eventgrid_event_subscription_test.go +++ b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go @@ -1,26 +1,19 @@ -package eventgrid +package tests import ( "fmt" "net/http" - "strings" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMEventGridEventSubscription_basic(t *testing.T) { - resourceName := "azurerm_eventgrid_event_subscription.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventgrid_event_subscription", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -28,33 +21,26 @@ func TestAccAzureRMEventGridEventSubscription_basic(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridEventSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridEventSubscription_basic(ri, rs, location), + Config: testAccAzureRMEventGridEventSubscription_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridEventSubscriptionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "event_delivery_schema", "EventGridSchema"), - resource.TestCheckResourceAttr(resourceName, "storage_queue_endpoint.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_blob_dead_letter_destination.#", "1"), - resource.TestCheckResourceAttr(resourceName, "included_event_types.0", "All"), - resource.TestCheckResourceAttr(resourceName, "retry_policy.0.max_delivery_attempts", "11"), - resource.TestCheckResourceAttr(resourceName, "retry_policy.0.event_time_to_live", "11"), - resource.TestCheckResourceAttr(resourceName, "labels.0", "test"), - resource.TestCheckResourceAttr(resourceName, "labels.2", "test2"), + testCheckAzureRMEventGridEventSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "event_delivery_schema", "EventGridSchema"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_queue_endpoint.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_blob_dead_letter_destination.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "included_event_types.0", "All"), + resource.TestCheckResourceAttr(data.ResourceName, "retry_policy.0.max_delivery_attempts", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "retry_policy.0.event_time_to_live", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "labels.0", "test"), + resource.TestCheckResourceAttr(data.ResourceName, "labels.2", "test2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventGridEventSubscription_eventhub(t *testing.T) { - resourceName := "azurerm_eventgrid_event_subscription.test" - ri := tf.AccRandTimeInt() - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventgrid_event_subscription", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -62,27 +48,20 @@ func TestAccAzureRMEventGridEventSubscription_eventhub(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridEventSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridEventSubscription_eventhub(ri, location), + Config: testAccAzureRMEventGridEventSubscription_eventhub(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridEventSubscriptionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "event_delivery_schema", "CloudEventV01Schema"), - resource.TestCheckResourceAttr(resourceName, "eventhub_endpoint.#", "1"), + testCheckAzureRMEventGridEventSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "event_delivery_schema", "CloudEventV01Schema"), + resource.TestCheckResourceAttr(data.ResourceName, "eventhub_endpoint.#", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMEventGridEventSubscription_update(t *testing.T) { - resourceName := "azurerm_eventgrid_event_subscription.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventgrid_event_subscription", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -90,31 +69,31 @@ func TestAccAzureRMEventGridEventSubscription_update(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridEventSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridEventSubscription_basic(ri, rs, location), + Config: testAccAzureRMEventGridEventSubscription_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridEventSubscriptionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "event_delivery_schema", "EventGridSchema"), - resource.TestCheckResourceAttr(resourceName, "storage_queue_endpoint.#", "1"), - resource.TestCheckResourceAttr(resourceName, "storage_blob_dead_letter_destination.#", "1"), - resource.TestCheckResourceAttr(resourceName, "included_event_types.0", "All"), - resource.TestCheckResourceAttr(resourceName, "retry_policy.0.max_delivery_attempts", "11"), - resource.TestCheckResourceAttr(resourceName, "retry_policy.0.event_time_to_live", "11"), - resource.TestCheckResourceAttr(resourceName, "labels.0", "test"), - resource.TestCheckResourceAttr(resourceName, "labels.2", "test2"), + testCheckAzureRMEventGridEventSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "event_delivery_schema", "EventGridSchema"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_queue_endpoint.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_blob_dead_letter_destination.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "included_event_types.0", "All"), + resource.TestCheckResourceAttr(data.ResourceName, "retry_policy.0.max_delivery_attempts", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "retry_policy.0.event_time_to_live", "11"), + resource.TestCheckResourceAttr(data.ResourceName, "labels.0", "test"), + resource.TestCheckResourceAttr(data.ResourceName, "labels.2", "test2"), ), }, { - Config: testAccAzureRMEventGridEventSubscription_update(ri, rs, location), + Config: testAccAzureRMEventGridEventSubscription_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridEventSubscriptionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "included_event_types.0", "Microsoft.Storage.BlobCreated"), - resource.TestCheckResourceAttr(resourceName, "included_event_types.1", "Microsoft.Storage.BlobDeleted"), - resource.TestCheckResourceAttr(resourceName, "subject_filter.0.subject_ends_with", ".jpg"), - resource.TestCheckResourceAttr(resourceName, "subject_filter.0.subject_begins_with", "test/test"), - resource.TestCheckResourceAttr(resourceName, "retry_policy.0.max_delivery_attempts", "10"), - resource.TestCheckResourceAttr(resourceName, "retry_policy.0.event_time_to_live", "12"), - resource.TestCheckResourceAttr(resourceName, "labels.0", "test4"), - resource.TestCheckResourceAttr(resourceName, "labels.2", "test6"), + testCheckAzureRMEventGridEventSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "included_event_types.0", "Microsoft.Storage.BlobCreated"), + resource.TestCheckResourceAttr(data.ResourceName, "included_event_types.1", "Microsoft.Storage.BlobDeleted"), + resource.TestCheckResourceAttr(data.ResourceName, "subject_filter.0.subject_ends_with", ".jpg"), + resource.TestCheckResourceAttr(data.ResourceName, "subject_filter.0.subject_begins_with", "test/test"), + resource.TestCheckResourceAttr(data.ResourceName, "retry_policy.0.max_delivery_attempts", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "retry_policy.0.event_time_to_live", "12"), + resource.TestCheckResourceAttr(data.ResourceName, "labels.0", "test4"), + resource.TestCheckResourceAttr(data.ResourceName, "labels.2", "test6"), ), }, }, @@ -122,11 +101,7 @@ func TestAccAzureRMEventGridEventSubscription_update(t *testing.T) { } func TestAccAzureRMEventGridEventSubscription_filter(t *testing.T) { - resourceName := "azurerm_eventgrid_event_subscription.test" - ri := tf.AccRandTimeInt() - rs := strings.ToLower(acctest.RandString(11)) - - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_eventgrid_event_subscription", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -134,20 +109,16 @@ func TestAccAzureRMEventGridEventSubscription_filter(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridEventSubscriptionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridEventSubscription_filter(ri, rs, location), + Config: testAccAzureRMEventGridEventSubscription_filter(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridEventSubscriptionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "included_event_types.0", "Microsoft.Storage.BlobCreated"), - resource.TestCheckResourceAttr(resourceName, "included_event_types.1", "Microsoft.Storage.BlobDeleted"), - resource.TestCheckResourceAttr(resourceName, "subject_filter.0.subject_ends_with", ".jpg"), - resource.TestCheckResourceAttr(resourceName, "subject_filter.0.subject_begins_with", "test/test"), + testCheckAzureRMEventGridEventSubscriptionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "included_event_types.0", "Microsoft.Storage.BlobCreated"), + resource.TestCheckResourceAttr(data.ResourceName, "included_event_types.1", "Microsoft.Storage.BlobDeleted"), + resource.TestCheckResourceAttr(data.ResourceName, "subject_filter.0.subject_ends_with", ".jpg"), + resource.TestCheckResourceAttr(data.ResourceName, "subject_filter.0.subject_begins_with", "test/test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -210,7 +181,7 @@ func testCheckAzureRMEventGridEventSubscriptionExists(resourceName string) resou } } -func testAccAzureRMEventGridEventSubscription_basic(rInt int, rString string, location string) string { +func testAccAzureRMEventGridEventSubscription_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -274,10 +245,10 @@ resource "azurerm_eventgrid_event_subscription" "test" { labels = ["test", "test1", "test2"] } -`, rInt, location, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMEventGridEventSubscription_update(rInt int, rString string, location string) string { +func testAccAzureRMEventGridEventSubscription_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -347,10 +318,10 @@ resource "azurerm_eventgrid_event_subscription" "test" { included_event_types = ["Microsoft.Storage.BlobCreated", "Microsoft.Storage.BlobDeleted"] labels = ["test4", "test5", "test6"] } -`, rInt, location, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMEventGridEventSubscription_eventhub(rInt int, location string) string { +func testAccAzureRMEventGridEventSubscription_eventhub(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -381,10 +352,10 @@ resource "azurerm_eventgrid_event_subscription" "test" { eventhub_id = "${azurerm_eventhub.test.id}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMEventGridEventSubscription_filter(rInt int, rString string, location string) string { +func testAccAzureRMEventGridEventSubscription_filter(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -425,5 +396,5 @@ resource "azurerm_eventgrid_event_subscription" "test" { subject_ends_with = ".jpg" } } -`, rInt, location, rString, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/eventgrid/resource_arm_eventgrid_topic_test.go b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_topic_test.go similarity index 72% rename from azurerm/internal/services/eventgrid/resource_arm_eventgrid_topic_test.go rename to azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_topic_test.go index 17c737fd5765..e0065d69856b 100644 --- a/azurerm/internal/services/eventgrid/resource_arm_eventgrid_topic_test.go +++ b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_topic_test.go @@ -1,4 +1,4 @@ -package eventgrid +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,8 +14,7 @@ import ( ) func TestAccAzureRMEventGridTopic_basic(t *testing.T) { - resourceName := "azurerm_eventgrid_topic.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventgrid_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,19 +22,15 @@ func TestAccAzureRMEventGridTopic_basic(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridTopic_basic(ri), + Config: testAccAzureRMEventGridTopic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridTopicExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMEventGridTopicExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,8 +41,7 @@ func TestAccAzureRMEventGridTopic_requiresImport(t *testing.T) { return } - resourceName := "azurerm_eventgrid_topic.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventgrid_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +49,13 @@ func TestAccAzureRMEventGridTopic_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridTopic_basic(ri), + Config: testAccAzureRMEventGridTopic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridTopicExists(resourceName), + testCheckAzureRMEventGridTopicExists(data.ResourceName), ), }, { - Config: testAccAzureRMEventGridTopic_requiresImport(ri), + Config: testAccAzureRMEventGridTopic_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_eventgrid_topic"), }, }, @@ -70,8 +63,7 @@ func TestAccAzureRMEventGridTopic_requiresImport(t *testing.T) { } func TestAccAzureRMEventGridTopic_basicWithTags(t *testing.T) { - resourceName := "azurerm_eventgrid_topic.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_eventgrid_topic", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,21 +71,17 @@ func TestAccAzureRMEventGridTopic_basicWithTags(t *testing.T) { CheckDestroy: testCheckAzureRMEventGridTopicDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMEventGridTopic_basicWithTags(ri), + Config: testAccAzureRMEventGridTopic_basicWithTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMEventGridTopicExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.foo", "bar"), - resource.TestCheckResourceAttrSet(resourceName, "endpoint"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMEventGridTopicExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.foo", "bar"), + resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -156,7 +144,7 @@ func testCheckAzureRMEventGridTopicExists(resourceName string) resource.TestChec } } -func testAccAzureRMEventGridTopic_basic(rInt int) string { +func testAccAzureRMEventGridTopic_basic(data acceptance.TestData) string { // TODO: confirm if this is still the case // currently only supported in "West Central US" & "West US 2" location := "westus2" @@ -171,11 +159,11 @@ resource "azurerm_eventgrid_topic" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, location, data.RandomInteger) } -func testAccAzureRMEventGridTopic_requiresImport(rInt int) string { - template := testAccAzureRMEventGridTopic_basic(rInt) +func testAccAzureRMEventGridTopic_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMEventGridTopic_basic(data) return fmt.Sprintf(` %s @@ -187,7 +175,7 @@ resource "azurerm_eventgrid_topic" "import" { `, template) } -func testAccAzureRMEventGridTopic_basicWithTags(rInt int) string { +func testAccAzureRMEventGridTopic_basicWithTags(data acceptance.TestData) string { // currently only supported in "West Central US" & "West US 2" location := "westus2" return fmt.Sprintf(` @@ -205,5 +193,5 @@ resource "azurerm_eventgrid_topic" "test" { "foo" = "bar" } } -`, rInt, location, rInt) +`, data.RandomInteger, location, data.RandomInteger) } From aaa5f007cc59c2f30d1c1db1c4293289c1056bd6 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Sat, 21 Dec 2019 11:12:15 -0800 Subject: [PATCH 143/203] tests: bot --- .../resource_arm_bot_channel_email_test.go | 56 +++++---------- .../resource_arm_bot_channel_ms_teams_test.go | 55 +++++---------- .../resource_arm_bot_channel_slack_test.go | 62 +++++------------ ...urce_arm_bot_channels_registration_test.go | 68 ++++++------------ .../resource_arm_bot_connection_test.go | 69 ++++++------------- .../resource_arm_bot_web_app_test.go | 68 ++++++------------ 6 files changed, 115 insertions(+), 263 deletions(-) rename azurerm/internal/services/bot/{ => tests}/resource_arm_bot_channel_email_test.go (75%) rename azurerm/internal/services/bot/{ => tests}/resource_arm_bot_channel_ms_teams_test.go (72%) rename azurerm/internal/services/bot/{ => tests}/resource_arm_bot_channel_slack_test.go (74%) rename azurerm/internal/services/bot/{ => tests}/resource_arm_bot_channels_registration_test.go (77%) rename azurerm/internal/services/bot/{ => tests}/resource_arm_bot_connection_test.go (71%) rename azurerm/internal/services/bot/{ => tests}/resource_arm_bot_web_app_test.go (74%) diff --git a/azurerm/internal/services/bot/resource_arm_bot_channel_email_test.go b/azurerm/internal/services/bot/tests/resource_arm_bot_channel_email_test.go similarity index 75% rename from azurerm/internal/services/bot/resource_arm_bot_channel_email_test.go rename to azurerm/internal/services/bot/tests/resource_arm_bot_channel_email_test.go index 1b581bd496cf..a65e7baa30b0 100644 --- a/azurerm/internal/services/bot/resource_arm_bot_channel_email_test.go +++ b/azurerm/internal/services/bot/tests/resource_arm_bot_channel_email_test.go @@ -1,4 +1,4 @@ -package bot +package tests import ( "fmt" @@ -9,7 +9,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/preview/botservice/mgmt/2018-07-12/botservice" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -19,9 +18,8 @@ func TestAccAzureRMBotChannelEmail_basic(t *testing.T) { if ok := skipEmailChannel(); ok { t.Skip("Skipping as one of `ARM_TEST_EMAIL`, AND `ARM_TEST_EMAIL_PASSWORD` was not specified") } - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotChannelEmail_basicConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_channel_email.test" + data := acceptance.BuildTestData(t, "azurerm_bot_channel_email", "test") + config := testAccAzureRMBotChannelEmail_basicConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -31,17 +29,10 @@ func TestAccAzureRMBotChannelEmail_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelEmailExists(resourceName), + testCheckAzureRMBotChannelEmailExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "email_password", - }, - }, + data.ImportStep("email_password"), }, }) } @@ -53,10 +44,9 @@ func TestAccAzureRMBotChannelEmail_update(t *testing.T) { if ok := skipSlackChannel(); ok { t.Skip("Skipping as one of `ARM_TEST_SLACK_CLIENT_ID`, `ARM_TEST_SLACK_CLIENT_SECRET`, or `ARM_TEST_SLACK_VERIFICATION_TOKEN` was not specified") } - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotChannelEmail_basicConfig(ri, acceptance.Location()) - config2 := testAccAzureRMBotChannelEmail_basicUpdate(ri, acceptance.Location()) - resourceName := "azurerm_bot_channel_email.test" + data := acceptance.BuildTestData(t, "azurerm_bot_channel_email", "test") + config := testAccAzureRMBotChannelEmail_basicConfig(data) + config2 := testAccAzureRMBotChannelEmail_basicUpdate(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -66,31 +56,17 @@ func TestAccAzureRMBotChannelEmail_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelEmailExists(resourceName), + testCheckAzureRMBotChannelEmailExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "email_password", - }, - }, + data.ImportStep("email_password"), { Config: config2, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelEmailExists(resourceName), + testCheckAzureRMBotChannelEmailExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "email_password", - }, - }, + data.ImportStep("email_password"), }, }) } @@ -151,8 +127,8 @@ func testCheckAzureRMBotChannelEmailDestroy(s *terraform.State) error { return nil } -func testAccAzureRMBotChannelEmail_basicConfig(rInt int, location string) string { - template := testAccAzureRMBotChannelsRegistration_basicConfig(rInt, location) +func testAccAzureRMBotChannelEmail_basicConfig(data acceptance.TestData) string { + template := testAccAzureRMBotChannelsRegistration_basicConfig(data) return fmt.Sprintf(` %s @@ -166,8 +142,8 @@ resource "azurerm_bot_channel_email" "test" { `, template, os.Getenv("ARM_TEST_EMAIL"), os.Getenv("ARM_TEST_EMAIL_PASSWORD")) } -func testAccAzureRMBotChannelEmail_basicUpdate(rInt int, location string) string { - template := testAccAzureRMBotChannelsRegistration_basicConfig(rInt, location) +func testAccAzureRMBotChannelEmail_basicUpdate(data acceptance.TestData) string { + template := testAccAzureRMBotChannelsRegistration_basicConfig(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/bot/resource_arm_bot_channel_ms_teams_test.go b/azurerm/internal/services/bot/tests/resource_arm_bot_channel_ms_teams_test.go similarity index 72% rename from azurerm/internal/services/bot/resource_arm_bot_channel_ms_teams_test.go rename to azurerm/internal/services/bot/tests/resource_arm_bot_channel_ms_teams_test.go index 86f8ba565513..e0d7bf287496 100644 --- a/azurerm/internal/services/bot/resource_arm_bot_channel_ms_teams_test.go +++ b/azurerm/internal/services/bot/tests/resource_arm_bot_channel_ms_teams_test.go @@ -1,4 +1,4 @@ -package bot +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/Azure/azure-sdk-for-go/services/preview/botservice/mgmt/2018-07-12/botservice" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func testAccAzureRMBotChannelMsTeams_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotChannelMsTeams_basicConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_channel_ms_teams.test" + data := acceptance.BuildTestData(t, "azurerm_bot_channel_ms_teams", "test") + config := testAccAzureRMBotChannelMsTeams_basicConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,23 +25,18 @@ func testAccAzureRMBotChannelMsTeams_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelMsTeamsExists(resourceName), + testCheckAzureRMBotChannelMsTeamsExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMBotChannelMsTeams_update(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotChannelMsTeams_basicConfig(ri, acceptance.Location()) - config2 := testAccAzureRMBotChannelMsTeams_basicUpdate(ri, acceptance.Location()) - resourceName := "azurerm_bot_channel_ms_teams.test" + data := acceptance.BuildTestData(t, "azurerm_bot_channel_ms_teams", "test") + config := testAccAzureRMBotChannelMsTeams_basicConfig(data) + config2 := testAccAzureRMBotChannelMsTeams_basicUpdate(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,36 +46,24 @@ func testAccAzureRMBotChannelMsTeams_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelMsTeamsExists(resourceName), + testCheckAzureRMBotChannelMsTeamsExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: config2, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelMsTeamsExists(resourceName), + testCheckAzureRMBotChannelMsTeamsExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelMsTeamsExists(resourceName), + testCheckAzureRMBotChannelMsTeamsExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -143,8 +124,8 @@ func testCheckAzureRMBotChannelMsTeamsDestroy(s *terraform.State) error { return nil } -func testAccAzureRMBotChannelMsTeams_basicConfig(rInt int, location string) string { - template := testAccAzureRMBotChannelsRegistration_basicConfig(rInt, location) +func testAccAzureRMBotChannelMsTeams_basicConfig(data acceptance.TestData) string { + template := testAccAzureRMBotChannelsRegistration_basicConfig(data) return fmt.Sprintf(` %s @@ -158,8 +139,8 @@ resource "azurerm_bot_channel_ms_teams" "test" { `, template) } -func testAccAzureRMBotChannelMsTeams_basicUpdate(rInt int, location string) string { - template := testAccAzureRMBotChannelsRegistration_basicConfig(rInt, location) +func testAccAzureRMBotChannelMsTeams_basicUpdate(data acceptance.TestData) string { + template := testAccAzureRMBotChannelsRegistration_basicConfig(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/bot/resource_arm_bot_channel_slack_test.go b/azurerm/internal/services/bot/tests/resource_arm_bot_channel_slack_test.go similarity index 74% rename from azurerm/internal/services/bot/resource_arm_bot_channel_slack_test.go rename to azurerm/internal/services/bot/tests/resource_arm_bot_channel_slack_test.go index 96ccefdfcd25..fd7a0b3771c4 100644 --- a/azurerm/internal/services/bot/resource_arm_bot_channel_slack_test.go +++ b/azurerm/internal/services/bot/tests/resource_arm_bot_channel_slack_test.go @@ -1,4 +1,4 @@ -package bot +package tests import ( "fmt" @@ -9,7 +9,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/preview/botservice/mgmt/2018-07-12/botservice" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -19,9 +18,8 @@ func testAccAzureRMBotChannelSlack_basic(t *testing.T) { if ok := skipSlackChannel(); ok { t.Skip("Skipping as one of `ARM_TEST_SLACK_CLIENT_ID`, `ARM_TEST_SLACK_CLIENT_SECRET`, or `ARM_TEST_SLACK_VERIFICATION_TOKEN` was not specified") } - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotChannelSlack_basicConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_channel_slack.test" + data := acceptance.BuildTestData(t, "azurerm_bot_channel_slack", "test") + config := testAccAzureRMBotChannelSlack_basicConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -31,19 +29,10 @@ func testAccAzureRMBotChannelSlack_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelSlackExists(resourceName), + testCheckAzureRMBotChannelSlackExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "client_secret", - "verification_token", - "landing_page_url", - }, - }, + data.ImportStep("client_secret", "verification_token", "landing_page_url"), }, }) } @@ -52,10 +41,9 @@ func testAccAzureRMBotChannelSlack_update(t *testing.T) { if ok := skipSlackChannel(); ok { t.Skip("Skipping as one of `ARM_TEST_SLACK_CLIENT_ID`, `ARM_TEST_SLACK_CLIENT_SECRET`, or `ARM_TEST_SLACK_VERIFICATION_TOKEN` was not specified") } - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotChannelSlack_basicConfig(ri, acceptance.Location()) - config2 := testAccAzureRMBotChannelSlack_basicUpdate(ri, acceptance.Location()) - resourceName := "azurerm_bot_channel_slack.test" + data := acceptance.BuildTestData(t, "azurerm_bot_channel_slack", "test") + config := testAccAzureRMBotChannelSlack_basicConfig(data) + config2 := testAccAzureRMBotChannelSlack_basicUpdate(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -65,35 +53,17 @@ func testAccAzureRMBotChannelSlack_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelSlackExists(resourceName), + testCheckAzureRMBotChannelSlackExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "client_secret", - "verification_token", - "landing_page_url", - }, - }, + data.ImportStep("client_secret", "verification_token", "landing_page_url"), { Config: config2, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelSlackExists(resourceName), + testCheckAzureRMBotChannelSlackExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "client_secret", - "verification_token", - "landing_page_url", - }, - }, + data.ImportStep("client_secret", "verification_token", "landing_page_url"), }, }) } @@ -154,8 +124,8 @@ func testCheckAzureRMBotChannelSlackDestroy(s *terraform.State) error { return nil } -func testAccAzureRMBotChannelSlack_basicConfig(rInt int, location string) string { - template := testAccAzureRMBotChannelsRegistration_basicConfig(rInt, location) +func testAccAzureRMBotChannelSlack_basicConfig(data acceptance.TestData) string { + template := testAccAzureRMBotChannelsRegistration_basicConfig(data) return fmt.Sprintf(` %s @@ -170,8 +140,8 @@ resource "azurerm_bot_channel_slack" "test" { `, template, os.Getenv("ARM_TEST_SLACK_CLIENT_ID"), os.Getenv("ARM_TEST_SLACK_CLIENT_SECRET"), os.Getenv("ARM_TEST_SLACK_VERIFICATION_TOKEN")) } -func testAccAzureRMBotChannelSlack_basicUpdate(rInt int, location string) string { - template := testAccAzureRMBotChannelsRegistration_basicConfig(rInt, location) +func testAccAzureRMBotChannelSlack_basicUpdate(data acceptance.TestData) string { + template := testAccAzureRMBotChannelsRegistration_basicConfig(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/bot/resource_arm_bot_channels_registration_test.go b/azurerm/internal/services/bot/tests/resource_arm_bot_channels_registration_test.go similarity index 77% rename from azurerm/internal/services/bot/resource_arm_bot_channels_registration_test.go rename to azurerm/internal/services/bot/tests/resource_arm_bot_channels_registration_test.go index 85465bb843b0..2c4ebdc45f95 100644 --- a/azurerm/internal/services/bot/resource_arm_bot_channels_registration_test.go +++ b/azurerm/internal/services/bot/tests/resource_arm_bot_channels_registration_test.go @@ -1,4 +1,4 @@ -package bot +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -53,9 +52,8 @@ func TestAccAzureRMBotChannelsRegistration(t *testing.T) { } func testAccAzureRMBotChannelsRegistration_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotChannelsRegistration_basicConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_channels_registration.test" + data := acceptance.BuildTestData(t, "azurerm_bot_channels_registration", "test") + config := testAccAzureRMBotChannelsRegistration_basicConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -65,24 +63,18 @@ func testAccAzureRMBotChannelsRegistration_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelsRegistrationExists(resourceName), + testCheckAzureRMBotChannelsRegistrationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"developer_app_insights_api_key"}, - }, + data.ImportStep("developer_app_insights_api_key"), }, }) } func testAccAzureRMBotChannelsRegistration_update(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotChannelsRegistration_basicConfig(ri, acceptance.Location()) - config2 := testAccAzureRMBotChannelsRegistration_updateConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_channels_registration.test" + data := acceptance.BuildTestData(t, "azurerm_bot_channels_registration", "test") + config := testAccAzureRMBotChannelsRegistration_basicConfig(data) + config2 := testAccAzureRMBotChannelsRegistration_updateConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -92,35 +84,24 @@ func testAccAzureRMBotChannelsRegistration_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelsRegistrationExists(resourceName), + testCheckAzureRMBotChannelsRegistrationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"developer_app_insights_api_key"}, - }, + data.ImportStep("developer_app_insights_api_key"), { Config: config2, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelsRegistrationExists(resourceName), + testCheckAzureRMBotChannelsRegistrationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"developer_app_insights_api_key"}, - }, + data.ImportStep("developer_app_insights_api_key"), }, }) } func testAccAzureRMBotChannelsRegistration_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotChannelsRegistration_completeConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_channels_registration.test" + data := acceptance.BuildTestData(t, "azurerm_bot_channels_registration", "test") + config := testAccAzureRMBotChannelsRegistration_completeConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -130,15 +111,10 @@ func testAccAzureRMBotChannelsRegistration_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotChannelsRegistrationExists(resourceName), + testCheckAzureRMBotChannelsRegistrationExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"developer_app_insights_api_key"}, - }, + data.ImportStep("developer_app_insights_api_key"), }, }) } @@ -199,7 +175,7 @@ func testCheckAzureRMBotChannelsRegistrationDestroy(s *terraform.State) error { return nil } -func testAccAzureRMBotChannelsRegistration_basicConfig(rInt int, location string) string { +func testAccAzureRMBotChannelsRegistration_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -219,10 +195,10 @@ resource "azurerm_bot_channels_registration" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMBotChannelsRegistration_updateConfig(rInt int, location string) string { +func testAccAzureRMBotChannelsRegistration_updateConfig(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -242,10 +218,10 @@ resource "azurerm_bot_channels_registration" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMBotChannelsRegistration_completeConfig(rInt int, location string) string { +func testAccAzureRMBotChannelsRegistration_completeConfig(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -282,5 +258,5 @@ resource "azurerm_bot_channels_registration" "test" { environment = "production" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/bot/resource_arm_bot_connection_test.go b/azurerm/internal/services/bot/tests/resource_arm_bot_connection_test.go similarity index 71% rename from azurerm/internal/services/bot/resource_arm_bot_connection_test.go rename to azurerm/internal/services/bot/tests/resource_arm_bot_connection_test.go index 2f206140ec26..7f24ac21ecca 100644 --- a/azurerm/internal/services/bot/resource_arm_bot_connection_test.go +++ b/azurerm/internal/services/bot/tests/resource_arm_bot_connection_test.go @@ -1,4 +1,4 @@ -package bot +package tests import ( "fmt" @@ -7,16 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func testAccAzureRMBotConnection_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotConnection_basicConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_connection.test" + data := acceptance.BuildTestData(t, "azurerm_bot_connection", "test") + config := testAccAzureRMBotConnection_basicConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,27 +24,18 @@ func testAccAzureRMBotConnection_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotConnectionExists(resourceName), + testCheckAzureRMBotConnectionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "client_secret", - "service_provider_name", - }, - }, + data.ImportStep("client_secret", "service_provider_name"), }, }) } func testAccAzureRMBotConnection_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotConnection_completeConfig(ri, acceptance.Location()) - config2 := testAccAzureRMBotConnection_completeUpdateConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_connection.test" + data := acceptance.BuildTestData(t, "azurerm_bot_connection", "test") + config := testAccAzureRMBotConnection_completeConfig(data) + config2 := testAccAzureRMBotConnection_completeUpdateConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,33 +45,17 @@ func testAccAzureRMBotConnection_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotConnectionExists(resourceName), + testCheckAzureRMBotConnectionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "client_secret", - "service_provider_name", - }, - }, + data.ImportStep("client_secret", "service_provider_name"), { Config: config2, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotConnectionExists(resourceName), + testCheckAzureRMBotConnectionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "client_secret", - "service_provider_name", - }, - }, + data.ImportStep("client_secret", "service_provider_name"), }, }) } @@ -145,8 +118,8 @@ func testCheckAzureRMBotConnectionDestroy(s *terraform.State) error { return nil } -func testAccAzureRMBotConnection_basicConfig(rInt int, location string) string { - template := testAccAzureRMBotChannelsRegistration_basicConfig(rInt, location) +func testAccAzureRMBotConnection_basicConfig(data acceptance.TestData) string { + template := testAccAzureRMBotChannelsRegistration_basicConfig(data) return fmt.Sprintf(` %s @@ -159,11 +132,11 @@ resource "azurerm_bot_connection" "test" { client_id = "test" client_secret = "secret" } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMBotConnection_completeConfig(rInt int, location string) string { - template := testAccAzureRMBotChannelsRegistration_basicConfig(rInt, location) +func testAccAzureRMBotConnection_completeConfig(data acceptance.TestData) string { + template := testAccAzureRMBotChannelsRegistration_basicConfig(data) return fmt.Sprintf(` %s @@ -181,11 +154,11 @@ resource "azurerm_bot_connection" "test" { loginUri = "www.example.com" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMBotConnection_completeUpdateConfig(rInt int, location string) string { - template := testAccAzureRMBotChannelsRegistration_basicConfig(rInt, location) +func testAccAzureRMBotConnection_completeUpdateConfig(data acceptance.TestData) string { + template := testAccAzureRMBotChannelsRegistration_basicConfig(data) return fmt.Sprintf(` %s @@ -203,5 +176,5 @@ resource "azurerm_bot_connection" "test" { loginUri = "www.example2.com" } } -`, template, rInt) +`, template, data.RandomInteger) } diff --git a/azurerm/internal/services/bot/resource_arm_bot_web_app_test.go b/azurerm/internal/services/bot/tests/resource_arm_bot_web_app_test.go similarity index 74% rename from azurerm/internal/services/bot/resource_arm_bot_web_app_test.go rename to azurerm/internal/services/bot/tests/resource_arm_bot_web_app_test.go index c21439414bf5..f9135ee44e56 100644 --- a/azurerm/internal/services/bot/resource_arm_bot_web_app_test.go +++ b/azurerm/internal/services/bot/tests/resource_arm_bot_web_app_test.go @@ -1,4 +1,4 @@ -package bot +package tests import ( "fmt" @@ -7,16 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func testAccAzureRMBotWebApp_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotWebApp_basicConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_web_app.test" + data := acceptance.BuildTestData(t, "azurerm_bot_web_app", "test") + config := testAccAzureRMBotWebApp_basicConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,24 +24,18 @@ func testAccAzureRMBotWebApp_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotWebAppExists(resourceName), + testCheckAzureRMBotWebAppExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"developer_app_insights_api_key"}, - }, + data.ImportStep("developer_app_insights_api_key"), }, }) } func testAccAzureRMBotWebApp_update(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotWebApp_basicConfig(ri, acceptance.Location()) - config2 := testAccAzureRMBotWebApp_updateConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_web_app.test" + data := acceptance.BuildTestData(t, "azurerm_bot_web_app", "test") + config := testAccAzureRMBotWebApp_basicConfig(data) + config2 := testAccAzureRMBotWebApp_updateConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,35 +45,24 @@ func testAccAzureRMBotWebApp_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotWebAppExists(resourceName), + testCheckAzureRMBotWebAppExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"developer_app_insights_api_key"}, - }, + data.ImportStep("developer_app_insights_api_key"), { Config: config2, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotWebAppExists(resourceName), + testCheckAzureRMBotWebAppExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"developer_app_insights_api_key"}, - }, + data.ImportStep("developer_app_insights_api_key"), }, }) } func testAccAzureRMBotWebApp_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMBotWebApp_completeConfig(ri, acceptance.Location()) - resourceName := "azurerm_bot_web_app.test" + data := acceptance.BuildTestData(t, "azurerm_bot_web_app", "test") + config := testAccAzureRMBotWebApp_completeConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -91,15 +72,10 @@ func testAccAzureRMBotWebApp_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMBotWebAppExists(resourceName), + testCheckAzureRMBotWebAppExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"developer_app_insights_api_key"}, - }, + data.ImportStep("developer_app_insights_api_key"), }, }) } @@ -160,7 +136,7 @@ func testCheckAzureRMBotWebAppDestroy(s *terraform.State) error { return nil } -func testAccAzureRMBotWebApp_basicConfig(rInt int, location string) string { +func testAccAzureRMBotWebApp_basicConfig(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -180,10 +156,10 @@ resource "azurerm_bot_web_app" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMBotWebApp_updateConfig(rInt int, location string) string { +func testAccAzureRMBotWebApp_updateConfig(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -203,10 +179,10 @@ resource "azurerm_bot_web_app" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMBotWebApp_completeConfig(rInt int, location string) string { +func testAccAzureRMBotWebApp_completeConfig(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_client_config" "current" {} @@ -243,5 +219,5 @@ resource "azurerm_bot_web_app" "test" { environment = "production" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } From dd8f99b3904ffce52be5a302620eb04b73fa99ba Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 11:53:18 -0800 Subject: [PATCH 144/203] dns: switching to the new test structure --- .../{ => tests}/data_source_dns_zone_test.go | 43 ++-- .../resource_arm_dns_a_record_test.go | 172 +++++++--------- .../resource_arm_dns_aaaa_record_test.go | 172 +++++++--------- .../resource_arm_dns_caa_record_test.go | 86 ++++---- .../resource_arm_dns_cname_record_test.go | 183 +++++++----------- .../resource_arm_dns_mx_record_test.go | 105 ++++------ .../resource_arm_dns_ns_record_test.go | 161 +++++++-------- .../resource_arm_dns_ptr_record_test.go | 87 ++++----- .../resource_arm_dns_srv_record_test.go | 86 ++++---- .../resource_arm_dns_txt_record_test.go | 84 ++++---- .../{ => tests}/resource_arm_dns_zone_test.go | 81 +++----- 11 files changed, 510 insertions(+), 750 deletions(-) rename azurerm/internal/services/dns/{ => tests}/data_source_dns_zone_test.go (65%) rename azurerm/internal/services/dns/{ => tests}/resource_arm_dns_a_record_test.go (69%) rename azurerm/internal/services/dns/{ => tests}/resource_arm_dns_aaaa_record_test.go (70%) rename azurerm/internal/services/dns/{ => tests}/resource_arm_dns_caa_record_test.go (76%) rename azurerm/internal/services/dns/{ => tests}/resource_arm_dns_cname_record_test.go (70%) rename azurerm/internal/services/dns/{ => tests}/resource_arm_dns_mx_record_test.go (74%) rename azurerm/internal/services/dns/{ => tests}/resource_arm_dns_ns_record_test.go (73%) rename azurerm/internal/services/dns/{ => tests}/resource_arm_dns_ptr_record_test.go (73%) rename azurerm/internal/services/dns/{ => tests}/resource_arm_dns_srv_record_test.go (76%) rename azurerm/internal/services/dns/{ => tests}/resource_arm_dns_txt_record_test.go (74%) rename azurerm/internal/services/dns/{ => tests}/resource_arm_dns_zone_test.go (73%) diff --git a/azurerm/internal/services/dns/data_source_dns_zone_test.go b/azurerm/internal/services/dns/tests/data_source_dns_zone_test.go similarity index 65% rename from azurerm/internal/services/dns/data_source_dns_zone_test.go rename to azurerm/internal/services/dns/tests/data_source_dns_zone_test.go index abcfad28f1c2..044cbeacf9bb 100644 --- a/azurerm/internal/services/dns/data_source_dns_zone_test.go +++ b/azurerm/internal/services/dns/tests/data_source_dns_zone_test.go @@ -1,18 +1,15 @@ -package dns +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMDNSZone_basic(t *testing.T) { - dataSourceName := "data.azurerm_dns_zone.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_dns_zone", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,9 +17,9 @@ func TestAccDataSourceAzureRMDNSZone_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDnsZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceDNSZone_basic(rInt, location), + Config: testAccDataSourceDNSZone_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -30,9 +27,7 @@ func TestAccDataSourceAzureRMDNSZone_basic(t *testing.T) { } func TestAccDataSourceAzureRMDNSZone_tags(t *testing.T) { - dataSourceName := "data.azurerm_dns_zone.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_dns_zone", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -40,10 +35,10 @@ func TestAccDataSourceAzureRMDNSZone_tags(t *testing.T) { CheckDestroy: testCheckAzureRMDnsZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceDNSZone_tags(rInt, location), + Config: testAccDataSourceDNSZone_tags(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.hello", "world"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.hello", "world"), ), }, }, @@ -51,10 +46,8 @@ func TestAccDataSourceAzureRMDNSZone_tags(t *testing.T) { } func TestAccDataSourceAzureRMDNSZone_withoutResourceGroupName(t *testing.T) { - dataSourceName := "data.azurerm_dns_zone.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() - resourceGroupName := fmt.Sprintf("acctestRG-%d", rInt) + data := acceptance.BuildTestData(t, "data.azurerm_dns_zone", "test") + resourceGroupName := fmt.Sprintf("acctestRG-%d", data.RandomInteger) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -62,16 +55,16 @@ func TestAccDataSourceAzureRMDNSZone_withoutResourceGroupName(t *testing.T) { CheckDestroy: testCheckAzureRMDnsZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccDataSourceDNSZone_onlyName(rInt, location, resourceGroupName), + Config: testAccDataSourceDNSZone_onlyName(data, resourceGroupName), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "resource_group_name", resourceGroupName), + resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resourceGroupName), ), }, }, }) } -func testAccDataSourceDNSZone_basic(rInt int, location string) string { +func testAccDataSourceDNSZone_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -87,10 +80,10 @@ data "azurerm_dns_zone" "test" { name = "${azurerm_dns_zone.test.name}" resource_group_name = "${azurerm_dns_zone.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceDNSZone_tags(rInt int, location string) string { +func testAccDataSourceDNSZone_tags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -110,10 +103,10 @@ data "azurerm_dns_zone" "test" { name = "${azurerm_dns_zone.test.name}" resource_group_name = "${azurerm_dns_zone.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceDNSZone_onlyName(rInt int, location, resourceGroupName string) string { +func testAccDataSourceDNSZone_onlyName(data acceptance.TestData, resourceGroupName string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "%s" @@ -128,5 +121,5 @@ resource "azurerm_dns_zone" "test" { data "azurerm_dns_zone" "test" { name = "${azurerm_dns_zone.test.name}" } -`, resourceGroupName, location, rInt) +`, resourceGroupName, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/resource_arm_dns_a_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_a_record_test.go similarity index 69% rename from azurerm/internal/services/dns/resource_arm_dns_a_record_test.go rename to azurerm/internal/services/dns/tests/resource_arm_dns_a_record_test.go index 1ab4c2fa7571..cec2e41e9282 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_a_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_a_record_test.go @@ -1,4 +1,4 @@ -package dns +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDnsARecord_basic(t *testing.T) { - resourceName := "azurerm_dns_a_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsARecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_a_record", "test") + config := testAccAzureRMDnsARecord_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,15 +25,11 @@ func TestAccAzureRMDnsARecord_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +40,7 @@ func TestAccAzureRMDnsARecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dns_a_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dns_a_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +48,13 @@ func TestAccAzureRMDnsARecord_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDnsARecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDnsARecord_basic(ri, location), + Config: testAccAzureRMDnsARecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), + testCheckAzureRMDnsARecordExists(data.ResourceName), ), }, { - Config: testAccAzureRMDnsARecord_requiresImport(ri, location), + Config: testAccAzureRMDnsARecord_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dns_a_record"), }, }, @@ -70,11 +62,9 @@ func TestAccAzureRMDnsARecord_requiresImport(t *testing.T) { } func TestAccAzureRMDnsARecord_updateRecords(t *testing.T) { - resourceName := "azurerm_dns_a_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsARecord_basic(ri, location) - postConfig := testAccAzureRMDnsARecord_updateRecords(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_a_record", "test") + preConfig := testAccAzureRMDnsARecord_basic(data) + postConfig := testAccAzureRMDnsARecord_updateRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,15 +74,15 @@ func TestAccAzureRMDnsARecord_updateRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "3"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "3"), ), }, }, @@ -100,11 +90,9 @@ func TestAccAzureRMDnsARecord_updateRecords(t *testing.T) { } func TestAccAzureRMDnsARecord_withTags(t *testing.T) { - resourceName := "azurerm_dns_a_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsARecord_withTags(ri, location) - postConfig := testAccAzureRMDnsARecord_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_a_record", "test") + preConfig := testAccAzureRMDnsARecord_withTags(data) + postConfig := testAccAzureRMDnsARecord_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,34 +102,28 @@ func TestAccAzureRMDnsARecord_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsARecord_withAlias(t *testing.T) { - resourceName := "azurerm_dns_a_record.test" + data := acceptance.BuildTestData(t, "azurerm_dns_a_record", "test") targetResourceName := "azurerm_public_ip.test" targetResourceName2 := "azurerm_public_ip.test2" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsARecord_withAlias(ri, location) - postConfig := testAccAzureRMDnsARecord_withAliasUpdate(ri, location) + preConfig := testAccAzureRMDnsARecord_withAlias(data) + postConfig := testAccAzureRMDnsARecord_withAliasUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -151,33 +133,27 @@ func TestAccAzureRMDnsARecord_withAlias(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName, "id"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName2, "id"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName2, "id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsARecord_RecordsToAlias(t *testing.T) { - resourceName := "azurerm_dns_a_record.test" + data := acceptance.BuildTestData(t, "azurerm_dns_a_record", "test") targetResourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsARecord_AliasToRecordsUpdate(ri, location) - postConfig := testAccAzureRMDnsARecord_AliasToRecords(ri, location) + preConfig := testAccAzureRMDnsARecord_AliasToRecordsUpdate(data) + postConfig := testAccAzureRMDnsARecord_AliasToRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -187,34 +163,28 @@ func TestAccAzureRMDnsARecord_RecordsToAlias(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName, "id"), - resource.TestCheckNoResourceAttr(resourceName, "records"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), + resource.TestCheckNoResourceAttr(data.ResourceName, "records"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsARecord_AliasToRecords(t *testing.T) { - resourceName := "azurerm_dns_a_record.test" + data := acceptance.BuildTestData(t, "azurerm_dns_a_record", "test") targetResourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsARecord_AliasToRecords(ri, location) - postConfig := testAccAzureRMDnsARecord_AliasToRecordsUpdate(ri, location) + preConfig := testAccAzureRMDnsARecord_AliasToRecords(data) + postConfig := testAccAzureRMDnsARecord_AliasToRecordsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -224,23 +194,19 @@ func TestAccAzureRMDnsARecord_AliasToRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName, "id"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsARecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), - resource.TestCheckNoResourceAttr(resourceName, "target_resource_id"), + testCheckAzureRMDnsARecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), + resource.TestCheckNoResourceAttr(data.ResourceName, "target_resource_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -304,7 +270,7 @@ func testCheckAzureRMDnsARecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDnsARecord_basic(rInt int, location string) string { +func testAccAzureRMDnsARecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -323,11 +289,11 @@ resource "azurerm_dns_a_record" "test" { ttl = 300 records = ["1.2.3.4", "1.2.4.5"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsARecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMDnsARecord_basic(rInt, location) +func testAccAzureRMDnsARecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDnsARecord_basic(data) return fmt.Sprintf(` %s @@ -341,7 +307,7 @@ resource "azurerm_dns_a_record" "import" { `, template) } -func testAccAzureRMDnsARecord_updateRecords(rInt int, location string) string { +func testAccAzureRMDnsARecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -360,10 +326,10 @@ resource "azurerm_dns_a_record" "test" { ttl = 300 records = ["1.2.3.4", "1.2.4.5", "1.2.3.7"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsARecord_withTags(rInt int, location string) string { +func testAccAzureRMDnsARecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -387,10 +353,10 @@ resource "azurerm_dns_a_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsARecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsARecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -413,10 +379,10 @@ resource "azurerm_dns_a_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsARecord_withAlias(rInt int, location string) string { +func testAccAzureRMDnsARecord_withAlias(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -443,10 +409,10 @@ resource "azurerm_dns_a_record" "test" { ttl = 300 target_resource_id = "${azurerm_public_ip.test.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsARecord_withAliasUpdate(rInt int, location string) string { +func testAccAzureRMDnsARecord_withAliasUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -473,10 +439,10 @@ resource "azurerm_dns_a_record" "test" { ttl = 300 target_resource_id = "${azurerm_public_ip.test2.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsARecord_AliasToRecords(rInt int, location string) string { +func testAccAzureRMDnsARecord_AliasToRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -503,10 +469,10 @@ resource "azurerm_dns_a_record" "test" { ttl = 300 target_resource_id = "${azurerm_public_ip.test.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsARecord_AliasToRecordsUpdate(rInt int, location string) string { +func testAccAzureRMDnsARecord_AliasToRecordsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -525,5 +491,5 @@ resource "azurerm_dns_a_record" "test" { ttl = 300 records = ["1.2.3.4", "1.2.4.5"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/resource_arm_dns_aaaa_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_aaaa_record_test.go similarity index 70% rename from azurerm/internal/services/dns/resource_arm_dns_aaaa_record_test.go rename to azurerm/internal/services/dns/tests/resource_arm_dns_aaaa_record_test.go index 867a90d3d991..d850aeb6ddc9 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_aaaa_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_aaaa_record_test.go @@ -1,4 +1,4 @@ -package dns +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDnsAAAARecord_basic(t *testing.T) { - resourceName := "azurerm_dns_aaaa_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsAAAARecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_aaaa_record", "test") + config := testAccAzureRMDnsAAAARecord_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,15 +25,11 @@ func TestAccAzureRMDnsAAAARecord_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +40,7 @@ func TestAccAzureRMDnsAAAARecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dns_aaaa_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dns_aaaa_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +48,13 @@ func TestAccAzureRMDnsAAAARecord_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDnsAaaaRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDnsAAAARecord_basic(ri, location), + Config: testAccAzureRMDnsAAAARecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), ), }, { - Config: testAccAzureRMDnsAAAARecord_requiresImport(ri, location), + Config: testAccAzureRMDnsAAAARecord_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dns_aaaa_record"), }, }, @@ -70,11 +62,9 @@ func TestAccAzureRMDnsAAAARecord_requiresImport(t *testing.T) { } func TestAccAzureRMDnsAAAARecord_updateRecords(t *testing.T) { - resourceName := "azurerm_dns_aaaa_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsAAAARecord_basic(ri, location) - postConfig := testAccAzureRMDnsAAAARecord_updateRecords(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_aaaa_record", "test") + preConfig := testAccAzureRMDnsAAAARecord_basic(data) + postConfig := testAccAzureRMDnsAAAARecord_updateRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,15 +74,15 @@ func TestAccAzureRMDnsAAAARecord_updateRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "3"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "3"), ), }, }, @@ -100,11 +90,9 @@ func TestAccAzureRMDnsAAAARecord_updateRecords(t *testing.T) { } func TestAccAzureRMDnsAAAARecord_withTags(t *testing.T) { - resourceName := "azurerm_dns_aaaa_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsAAAARecord_withTags(ri, location) - postConfig := testAccAzureRMDnsAAAARecord_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_aaaa_record", "test") + preConfig := testAccAzureRMDnsAAAARecord_withTags(data) + postConfig := testAccAzureRMDnsAAAARecord_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,34 +102,28 @@ func TestAccAzureRMDnsAAAARecord_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsAAAARecord_withAlias(t *testing.T) { - resourceName := "azurerm_dns_aaaa_record.test" + data := acceptance.BuildTestData(t, "azurerm_dns_aaaa_record", "test") targetResourceName := "azurerm_public_ip.test" targetResourceName2 := "azurerm_public_ip.test2" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsAAAARecord_withAlias(ri, location) - postConfig := testAccAzureRMDnsAAAARecord_withAliasUpdate(ri, location) + preConfig := testAccAzureRMDnsAAAARecord_withAlias(data) + postConfig := testAccAzureRMDnsAAAARecord_withAliasUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -151,33 +133,27 @@ func TestAccAzureRMDnsAAAARecord_withAlias(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName, "id"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName2, "id"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName2, "id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsAAAARecord_RecordsToAlias(t *testing.T) { - resourceName := "azurerm_dns_aaaa_record.test" + data := acceptance.BuildTestData(t, "azurerm_dns_aaaa_record", "test") targetResourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsAaaaRecord_AliasToRecordsUpdate(ri, location) - postConfig := testAccAzureRMDnsAaaaRecord_AliasToRecords(ri, location) + preConfig := testAccAzureRMDnsAaaaRecord_AliasToRecordsUpdate(data) + postConfig := testAccAzureRMDnsAaaaRecord_AliasToRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -187,34 +163,28 @@ func TestAccAzureRMDnsAAAARecord_RecordsToAlias(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName, "id"), - resource.TestCheckNoResourceAttr(resourceName, "records"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), + resource.TestCheckNoResourceAttr(data.ResourceName, "records"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsAaaaRecord_AliasToRecords(t *testing.T) { - resourceName := "azurerm_dns_aaaa_record.test" + data := acceptance.BuildTestData(t, "azurerm_dns_aaaa_record", "test") targetResourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsAaaaRecord_AliasToRecords(ri, location) - postConfig := testAccAzureRMDnsAaaaRecord_AliasToRecordsUpdate(ri, location) + preConfig := testAccAzureRMDnsAaaaRecord_AliasToRecords(data) + postConfig := testAccAzureRMDnsAaaaRecord_AliasToRecordsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -224,23 +194,19 @@ func TestAccAzureRMDnsAaaaRecord_AliasToRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName, "id"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsAaaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), - resource.TestCheckNoResourceAttr(resourceName, "target_resource_id"), + testCheckAzureRMDnsAaaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), + resource.TestCheckNoResourceAttr(data.ResourceName, "target_resource_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -304,7 +270,7 @@ func testCheckAzureRMDnsAaaaRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDnsAAAARecord_basic(rInt int, location string) string { +func testAccAzureRMDnsAAAARecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -323,11 +289,11 @@ resource "azurerm_dns_aaaa_record" "test" { ttl = 300 records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsAAAARecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMDnsAAAARecord_basic(rInt, location) +func testAccAzureRMDnsAAAARecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDnsAAAARecord_basic(data) return fmt.Sprintf(` %s @@ -341,7 +307,7 @@ resource "azurerm_dns_aaaa_record" "import" { `, template) } -func testAccAzureRMDnsAAAARecord_updateRecords(rInt int, location string) string { +func testAccAzureRMDnsAAAARecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -360,10 +326,10 @@ resource "azurerm_dns_aaaa_record" "test" { ttl = 300 records = ["2607:f8b0:4009:1803::1005", "2607:f8b0:4009:1803::1006", "::1"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsAAAARecord_withTags(rInt int, location string) string { +func testAccAzureRMDnsAAAARecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -387,10 +353,10 @@ resource "azurerm_dns_aaaa_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsAAAARecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsAAAARecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -413,10 +379,10 @@ resource "azurerm_dns_aaaa_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsAAAARecord_withAlias(rInt int, location string) string { +func testAccAzureRMDnsAAAARecord_withAlias(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -443,10 +409,10 @@ resource "azurerm_dns_aaaa_record" "test" { ttl = 300 target_resource_id = "${azurerm_public_ip.test.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsAAAARecord_withAliasUpdate(rInt int, location string) string { +func testAccAzureRMDnsAAAARecord_withAliasUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -473,10 +439,10 @@ resource "azurerm_dns_aaaa_record" "test" { ttl = 300 target_resource_id = "${azurerm_public_ip.test2.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsAaaaRecord_AliasToRecords(rInt int, location string) string { +func testAccAzureRMDnsAaaaRecord_AliasToRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -503,10 +469,10 @@ resource "azurerm_dns_aaaa_record" "test" { ttl = 300 target_resource_id = "${azurerm_public_ip.test.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsAaaaRecord_AliasToRecordsUpdate(rInt int, location string) string { +func testAccAzureRMDnsAaaaRecord_AliasToRecordsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -525,5 +491,5 @@ resource "azurerm_dns_aaaa_record" "test" { ttl = 300 records = ["3a62:353:8885:293c:a218:45cc:9ee9:4e27", "3a62:353:8885:293c:a218:45cc:9ee9:4e27"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/resource_arm_dns_caa_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_caa_record_test.go similarity index 76% rename from azurerm/internal/services/dns/resource_arm_dns_caa_record_test.go rename to azurerm/internal/services/dns/tests/resource_arm_dns_caa_record_test.go index a50ce58cfccb..be9666f3e347 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_caa_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_caa_record_test.go @@ -1,4 +1,4 @@ -package dns +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDnsCaaRecord_basic(t *testing.T) { - resourceName := "azurerm_dns_caa_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsCaaRecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_caa_record", "test") + config := testAccAzureRMDnsCaaRecord_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,15 +25,11 @@ func TestAccAzureRMDnsCaaRecord_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCaaRecordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + testCheckAzureRMDnsCaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +40,7 @@ func TestAccAzureRMDnsCaaRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dns_caa_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dns_caa_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +48,13 @@ func TestAccAzureRMDnsCaaRecord_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDnsCaaRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDnsCaaRecord_basic(ri, location), + Config: testAccAzureRMDnsCaaRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCaaRecordExists(resourceName), + testCheckAzureRMDnsCaaRecordExists(data.ResourceName), ), }, { - Config: testAccAzureRMDnsCaaRecord_requiresImport(ri, location), + Config: testAccAzureRMDnsCaaRecord_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dns_caa_record"), }, }, @@ -70,11 +62,9 @@ func TestAccAzureRMDnsCaaRecord_requiresImport(t *testing.T) { } func TestAccAzureRMDnsCaaRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_dns_caa_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsCaaRecord_basic(ri, location) - postConfig := testAccAzureRMDnsCaaRecord_updateRecords(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_caa_record", "test") + preConfig := testAccAzureRMDnsCaaRecord_basic(data) + postConfig := testAccAzureRMDnsCaaRecord_updateRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,15 +74,15 @@ func TestAccAzureRMDnsCaaRecord_updateRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "4"), + testCheckAzureRMDnsCaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "4"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "5"), + testCheckAzureRMDnsCaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "5"), ), }, }, @@ -100,11 +90,9 @@ func TestAccAzureRMDnsCaaRecord_updateRecords(t *testing.T) { } func TestAccAzureRMDnsCaaRecord_withTags(t *testing.T) { - resourceName := "azurerm_dns_caa_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsCaaRecord_withTags(ri, location) - postConfig := testAccAzureRMDnsCaaRecord_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_caa_record", "test") + preConfig := testAccAzureRMDnsCaaRecord_withTags(data) + postConfig := testAccAzureRMDnsCaaRecord_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,22 +102,18 @@ func TestAccAzureRMDnsCaaRecord_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsCaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCaaRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsCaaRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -193,7 +177,7 @@ func testCheckAzureRMDnsCaaRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDnsCaaRecord_basic(rInt int, location string) string { +func testAccAzureRMDnsCaaRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -235,11 +219,11 @@ resource "azurerm_dns_caa_record" "test" { value = "mailto:terraform@nonexist.tld" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCaaRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMDnsCaaRecord_basic(rInt, location) +func testAccAzureRMDnsCaaRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDnsCaaRecord_basic(data) return fmt.Sprintf(` %s @@ -276,7 +260,7 @@ resource "azurerm_dns_caa_record" "import" { `, template) } -func testAccAzureRMDnsCaaRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMDnsCaaRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -324,10 +308,10 @@ resource "azurerm_dns_caa_record" "test" { value = "letsencrypt.org" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCaaRecord_withTags(rInt int, location string) string { +func testAccAzureRMDnsCaaRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -362,10 +346,10 @@ resource "azurerm_dns_caa_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCaaRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsCaaRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -399,5 +383,5 @@ resource "azurerm_dns_caa_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/resource_arm_dns_cname_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_cname_record_test.go similarity index 70% rename from azurerm/internal/services/dns/resource_arm_dns_cname_record_test.go rename to azurerm/internal/services/dns/tests/resource_arm_dns_cname_record_test.go index 80d70f5a00c9..fa380ec0c32f 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_cname_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_cname_record_test.go @@ -1,4 +1,4 @@ -package dns +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDnsCNameRecord_basic(t *testing.T) { - resourceName := "azurerm_dns_cname_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsCNameRecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_cname_record", "test") + config := testAccAzureRMDnsCNameRecord_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,15 +25,11 @@ func TestAccAzureRMDnsCNameRecord_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +40,7 @@ func TestAccAzureRMDnsCNameRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dns_cname_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dns_cname_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +48,13 @@ func TestAccAzureRMDnsCNameRecord_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDnsCNameRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDnsCNameRecord_basic(ri, location), + Config: testAccAzureRMDnsCNameRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), ), }, { - Config: testAccAzureRMDnsCNameRecord_requiresImport(ri, location), + Config: testAccAzureRMDnsCNameRecord_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dns_cname_record"), }, }, @@ -70,9 +62,8 @@ func TestAccAzureRMDnsCNameRecord_requiresImport(t *testing.T) { } func TestAccAzureRMDnsCNameRecord_subdomain(t *testing.T) { - resourceName := "azurerm_dns_cname_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsCNameRecord_subdomain(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_cname_record", "test") + config := testAccAzureRMDnsCNameRecord_subdomain(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,25 +73,19 @@ func TestAccAzureRMDnsCNameRecord_subdomain(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record", "test.contoso.com"), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record", "test.contoso.com"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsCNameRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_dns_cname_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsCNameRecord_basic(ri, location) - postConfig := testAccAzureRMDnsCNameRecord_updateRecords(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_cname_record", "test") + preConfig := testAccAzureRMDnsCNameRecord_basic(data) + postConfig := testAccAzureRMDnsCNameRecord_updateRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -110,13 +95,13 @@ func TestAccAzureRMDnsCNameRecord_updateRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), ), }, }, @@ -124,11 +109,9 @@ func TestAccAzureRMDnsCNameRecord_updateRecords(t *testing.T) { } func TestAccAzureRMDnsCNameRecord_withTags(t *testing.T) { - resourceName := "azurerm_dns_cname_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsCNameRecord_withTags(ri, location) - postConfig := testAccAzureRMDnsCNameRecord_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_cname_record", "test") + preConfig := testAccAzureRMDnsCNameRecord_withTags(data) + postConfig := testAccAzureRMDnsCNameRecord_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -138,34 +121,28 @@ func TestAccAzureRMDnsCNameRecord_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsCNameRecord_withAlias(t *testing.T) { - resourceName := "azurerm_dns_cname_record.test" + data := acceptance.BuildTestData(t, "azurerm_dns_cname_record", "test") targetResourceName := "azurerm_dns_cname_record.target" targetResourceName2 := "azurerm_dns_cname_record.target2" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsCNameRecord_withAlias(ri, location) - postConfig := testAccAzureRMDnsCNameRecord_withAliasUpdate(ri, location) + preConfig := testAccAzureRMDnsCNameRecord_withAlias(data) + postConfig := testAccAzureRMDnsCNameRecord_withAliasUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -175,33 +152,27 @@ func TestAccAzureRMDnsCNameRecord_withAlias(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName, "id"), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName2, "id"), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName2, "id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsCNameRecord_RecordToAlias(t *testing.T) { - resourceName := "azurerm_dns_cname_record.test" + data := acceptance.BuildTestData(t, "azurerm_dns_cname_record", "test") targetResourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsCNameRecord_AliasToRecordUpdate(ri, location) - postConfig := testAccAzureRMDnsCNameRecord_AliasToRecord(ri, location) + preConfig := testAccAzureRMDnsCNameRecord_AliasToRecordUpdate(data) + postConfig := testAccAzureRMDnsCNameRecord_AliasToRecord(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -211,33 +182,27 @@ func TestAccAzureRMDnsCNameRecord_RecordToAlias(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName, "id"), - resource.TestCheckNoResourceAttr(resourceName, "record"), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), + resource.TestCheckNoResourceAttr(data.ResourceName, "record"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsCNameRecord_AliasToRecord(t *testing.T) { - resourceName := "azurerm_dns_cname_record.test" + data := acceptance.BuildTestData(t, "azurerm_dns_cname_record", "test") targetResourceName := "azurerm_public_ip.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsCNameRecord_AliasToRecord(ri, location) - postConfig := testAccAzureRMDnsCNameRecord_AliasToRecordUpdate(ri, location) + preConfig := testAccAzureRMDnsCNameRecord_AliasToRecord(data) + postConfig := testAccAzureRMDnsCNameRecord_AliasToRecordUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -247,22 +212,18 @@ func TestAccAzureRMDnsCNameRecord_AliasToRecord(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), - resource.TestCheckResourceAttrPair(resourceName, "target_resource_id", targetResourceName, "id"), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), + resource.TestCheckResourceAttrPair(data.ResourceName, "target_resource_id", targetResourceName, "id"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsCNameRecordExists(resourceName), - resource.TestCheckNoResourceAttr(resourceName, "target_resource_id"), + testCheckAzureRMDnsCNameRecordExists(data.ResourceName), + resource.TestCheckNoResourceAttr(data.ResourceName, "target_resource_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -326,7 +287,7 @@ func testCheckAzureRMDnsCNameRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDnsCNameRecord_basic(rInt int, location string) string { +func testAccAzureRMDnsCNameRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -345,11 +306,11 @@ resource "azurerm_dns_cname_record" "test" { ttl = 300 record = "contoso.com" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCNameRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMDnsCNameRecord_basic(rInt, location) +func testAccAzureRMDnsCNameRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDnsCNameRecord_basic(data) return fmt.Sprintf(` %s @@ -363,7 +324,7 @@ resource "azurerm_dns_cname_record" "import" { `, template) } -func testAccAzureRMDnsCNameRecord_subdomain(rInt int, location string) string { +func testAccAzureRMDnsCNameRecord_subdomain(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -382,10 +343,10 @@ resource "azurerm_dns_cname_record" "test" { ttl = 300 record = "test.contoso.com" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCNameRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMDnsCNameRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -404,10 +365,10 @@ resource "azurerm_dns_cname_record" "test" { ttl = 300 record = "contoso.co.uk" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCNameRecord_withTags(rInt int, location string) string { +func testAccAzureRMDnsCNameRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -431,10 +392,10 @@ resource "azurerm_dns_cname_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCNameRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsCNameRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -457,10 +418,10 @@ resource "azurerm_dns_cname_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCNameRecord_withAlias(rInt int, location string) string { +func testAccAzureRMDnsCNameRecord_withAlias(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -487,10 +448,10 @@ resource "azurerm_dns_cname_record" "test" { ttl = 300 target_resource_id = "${azurerm_dns_cname_record.target.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCNameRecord_withAliasUpdate(rInt int, location string) string { +func testAccAzureRMDnsCNameRecord_withAliasUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -517,10 +478,10 @@ resource "azurerm_dns_cname_record" "test" { ttl = 300 target_resource_id = "${azurerm_dns_cname_record.target2.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCNameRecord_AliasToRecord(rInt int, location string) string { +func testAccAzureRMDnsCNameRecord_AliasToRecord(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -547,10 +508,10 @@ resource "azurerm_dns_cname_record" "test" { ttl = 300 target_resource_id = "${azurerm_dns_cname_record.target2.id}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsCNameRecord_AliasToRecordUpdate(rInt int, location string) string { +func testAccAzureRMDnsCNameRecord_AliasToRecordUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -569,5 +530,5 @@ resource "azurerm_dns_cname_record" "test" { ttl = 300 record = "1.2.3.4" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/resource_arm_dns_mx_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_mx_record_test.go similarity index 74% rename from azurerm/internal/services/dns/resource_arm_dns_mx_record_test.go rename to azurerm/internal/services/dns/tests/resource_arm_dns_mx_record_test.go index 3315571e379b..72be19fcc328 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_mx_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_mx_record_test.go @@ -1,4 +1,4 @@ -package dns +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDnsMxRecord_basic(t *testing.T) { - resourceName := "azurerm_dns_mx_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsMxRecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_mx_record", "test") + config := testAccAzureRMDnsMxRecord_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,23 +25,18 @@ func TestAccAzureRMDnsMxRecord_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsMxRecordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + testCheckAzureRMDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsMxRecord_rootrecord(t *testing.T) { - resourceName := "azurerm_dns_mx_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsMxRecord_rootrecord(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_mx_record", "test") + config := testAccAzureRMDnsMxRecord_rootrecord(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,15 +46,11 @@ func TestAccAzureRMDnsMxRecord_rootrecord(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsMxRecordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + testCheckAzureRMDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -72,9 +61,7 @@ func TestAccAzureRMDnsMxRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dns_mx_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dns_mx_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,13 +69,13 @@ func TestAccAzureRMDnsMxRecord_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDnsMxRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDnsMxRecord_basic(ri, location), + Config: testAccAzureRMDnsMxRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsMxRecordExists(resourceName), + testCheckAzureRMDnsMxRecordExists(data.ResourceName), ), }, { - Config: testAccAzureRMDnsMxRecord_requiresImport(ri, location), + Config: testAccAzureRMDnsMxRecord_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dns_mx_record"), }, }, @@ -96,11 +83,9 @@ func TestAccAzureRMDnsMxRecord_requiresImport(t *testing.T) { } func TestAccAzureRMDnsMxRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_dns_mx_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsMxRecord_basic(ri, location) - postConfig := testAccAzureRMDnsMxRecord_updateRecords(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_mx_record", "test") + preConfig := testAccAzureRMDnsMxRecord_basic(data) + postConfig := testAccAzureRMDnsMxRecord_updateRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -110,15 +95,15 @@ func TestAccAzureRMDnsMxRecord_updateRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsMxRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "2"), + testCheckAzureRMDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsMxRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "3"), + testCheckAzureRMDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "3"), ), }, }, @@ -126,11 +111,9 @@ func TestAccAzureRMDnsMxRecord_updateRecords(t *testing.T) { } func TestAccAzureRMDnsMxRecord_withTags(t *testing.T) { - resourceName := "azurerm_dns_mx_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsMxRecord_withTags(ri, location) - postConfig := testAccAzureRMDnsMxRecord_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_mx_record", "test") + preConfig := testAccAzureRMDnsMxRecord_withTags(data) + postConfig := testAccAzureRMDnsMxRecord_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -140,22 +123,18 @@ func TestAccAzureRMDnsMxRecord_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsMxRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsMxRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsMxRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -219,7 +198,7 @@ func testCheckAzureRMDnsMxRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDnsMxRecord_basic(rInt int, location string) string { +func testAccAzureRMDnsMxRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -247,10 +226,10 @@ resource "azurerm_dns_mx_record" "test" { exchange = "mail2.contoso.com" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsMxRecord_rootrecord(rInt int, location string) string { +func testAccAzureRMDnsMxRecord_rootrecord(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -277,11 +256,11 @@ resource "azurerm_dns_mx_record" "test" { exchange = "mail2.contoso.com" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDnsMxRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMDnsMxRecord_basic(rInt, location) +func testAccAzureRMDnsMxRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDnsMxRecord_basic(data) return fmt.Sprintf(` %s @@ -304,7 +283,7 @@ resource "azurerm_dns_mx_record" "import" { `, template) } -func testAccAzureRMDnsMxRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMDnsMxRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -337,10 +316,10 @@ resource "azurerm_dns_mx_record" "test" { exchange = "mail3.contoso.com" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsMxRecord_withTags(rInt int, location string) string { +func testAccAzureRMDnsMxRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -373,10 +352,10 @@ resource "azurerm_dns_mx_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsMxRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsMxRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -408,5 +387,5 @@ resource "azurerm_dns_mx_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/resource_arm_dns_ns_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_ns_record_test.go similarity index 73% rename from azurerm/internal/services/dns/resource_arm_dns_ns_record_test.go rename to azurerm/internal/services/dns/tests/resource_arm_dns_ns_record_test.go index e95c37c63f3a..a2d6c5915bbf 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_ns_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_ns_record_test.go @@ -1,4 +1,4 @@ -package dns +package tests import ( "fmt" @@ -8,7 +8,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -16,9 +15,8 @@ import ( //TODO: remove this once we remove the `record` attribute func TestAccAzureRMDnsNsRecord_deprecatedBasic(t *testing.T) { - resourceName := "azurerm_dns_ns_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsNsRecord_deprecatedBasic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") + config := testAccAzureRMDnsNsRecord_deprecatedBasic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -28,7 +26,7 @@ func TestAccAzureRMDnsNsRecord_deprecatedBasic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), ), }, }, @@ -36,9 +34,8 @@ func TestAccAzureRMDnsNsRecord_deprecatedBasic(t *testing.T) { } func TestAccAzureRMDnsNsRecord_basic(t *testing.T) { - resourceName := "azurerm_dns_ns_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsNsRecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") + config := testAccAzureRMDnsNsRecord_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -48,15 +45,11 @@ func TestAccAzureRMDnsNsRecord_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -67,9 +60,7 @@ func TestAccAzureRMDnsNsRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dns_ns_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -77,13 +68,13 @@ func TestAccAzureRMDnsNsRecord_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDnsNsRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDnsNsRecord_basic(ri, location), + Config: testAccAzureRMDnsNsRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), ), }, { - Config: testAccAzureRMDnsNsRecord_requiresImport(ri, location), + Config: testAccAzureRMDnsNsRecord_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dns_ns_record"), }, }, @@ -92,11 +83,9 @@ func TestAccAzureRMDnsNsRecord_requiresImport(t *testing.T) { //TODO: remove this once we remove the `record` attribute func TestAccAzureRMDnsNsRecord_deprecatedUpdateRecords(t *testing.T) { - resourceName := "azurerm_dns_ns_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsNsRecord_deprecatedBasic(ri, location) - postConfig := testAccAzureRMDnsNsRecord_deprecatedUpdateRecords(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") + preConfig := testAccAzureRMDnsNsRecord_deprecatedBasic(data) + postConfig := testAccAzureRMDnsNsRecord_deprecatedUpdateRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -106,15 +95,15 @@ func TestAccAzureRMDnsNsRecord_deprecatedUpdateRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "2"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "3"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "3"), ), }, }, @@ -122,11 +111,9 @@ func TestAccAzureRMDnsNsRecord_deprecatedUpdateRecords(t *testing.T) { } func TestAccAzureRMDnsNsRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_dns_ns_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsNsRecord_basic(ri, location) - postConfig := testAccAzureRMDnsNsRecord_updateRecords(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") + preConfig := testAccAzureRMDnsNsRecord_basic(data) + postConfig := testAccAzureRMDnsNsRecord_updateRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -136,15 +123,15 @@ func TestAccAzureRMDnsNsRecord_updateRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "3"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "3"), ), }, }, @@ -153,11 +140,9 @@ func TestAccAzureRMDnsNsRecord_updateRecords(t *testing.T) { //TODO: remove this once we remove the `record` attribute func TestAccAzureRMDnsNsRecord_deprecatedChangeRecordToRecords(t *testing.T) { - resourceName := "azurerm_dns_ns_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsNsRecord_deprecatedBasic(ri, location) - postConfig := testAccAzureRMDnsNsRecord_deprecatedBasicNewRecords(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") + preConfig := testAccAzureRMDnsNsRecord_deprecatedBasic(data) + postConfig := testAccAzureRMDnsNsRecord_deprecatedBasicNewRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -167,15 +152,15 @@ func TestAccAzureRMDnsNsRecord_deprecatedChangeRecordToRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "records.#", "2"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, }, @@ -184,11 +169,9 @@ func TestAccAzureRMDnsNsRecord_deprecatedChangeRecordToRecords(t *testing.T) { //TODO: remove this once we remove the `record` attribute func TestAccAzureRMDnsNsRecord_deprecatedWithTags(t *testing.T) { - resourceName := "azurerm_dns_ns_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsNsRecord_deprecatedWithTags(ri, location) - postConfig := testAccAzureRMDnsNsRecord_deprecatedWithTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") + preConfig := testAccAzureRMDnsNsRecord_deprecatedWithTags(data) + postConfig := testAccAzureRMDnsNsRecord_deprecatedWithTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -198,15 +181,15 @@ func TestAccAzureRMDnsNsRecord_deprecatedWithTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, }, @@ -214,11 +197,9 @@ func TestAccAzureRMDnsNsRecord_deprecatedWithTags(t *testing.T) { } func TestAccAzureRMDnsNsRecord_withTags(t *testing.T) { - resourceName := "azurerm_dns_ns_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsNsRecord_withTags(ri, location) - postConfig := testAccAzureRMDnsNsRecord_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_ns_record", "test") + preConfig := testAccAzureRMDnsNsRecord_withTags(data) + postConfig := testAccAzureRMDnsNsRecord_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -228,22 +209,18 @@ func TestAccAzureRMDnsNsRecord_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsNsRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsNsRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -305,7 +282,7 @@ func testCheckAzureRMDnsNsRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDnsNsRecord_basic(rInt int, location string) string { +func testAccAzureRMDnsNsRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -325,11 +302,11 @@ resource "azurerm_dns_ns_record" "test" { records = ["ns1.contoso.com", "ns2.contoso.com"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsNsRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMDnsNsRecord_basic(rInt, location) +func testAccAzureRMDnsNsRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDnsNsRecord_basic(data) return fmt.Sprintf(` %s @@ -345,7 +322,7 @@ resource "azurerm_dns_ns_record" "import" { } //TODO: remove this once we remove the `record` attribute -func testAccAzureRMDnsNsRecord_deprecatedBasic(rInt int, location string) string { +func testAccAzureRMDnsNsRecord_deprecatedBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -371,11 +348,11 @@ resource "azurerm_dns_ns_record" "test" { nsdname = "ns2.contoso.com" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } //TODO: remove this once we remove the `record` attribute -func testAccAzureRMDnsNsRecord_deprecatedBasicNewRecords(rInt int, location string) string { +func testAccAzureRMDnsNsRecord_deprecatedBasicNewRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -395,10 +372,10 @@ resource "azurerm_dns_ns_record" "test" { records = ["ns2.contoso.com", "ns1.contoso.com"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsNsRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMDnsNsRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -418,11 +395,11 @@ resource "azurerm_dns_ns_record" "test" { records = ["ns1.contoso.com", "ns2.contoso.com", "ns3.contoso.com"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } //TODO: remove this once we remove the `record` attribute -func testAccAzureRMDnsNsRecord_deprecatedUpdateRecords(rInt int, location string) string { +func testAccAzureRMDnsNsRecord_deprecatedUpdateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -452,10 +429,10 @@ resource "azurerm_dns_ns_record" "test" { nsdname = "ns3.contoso.com" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsNsRecord_withTags(rInt int, location string) string { +func testAccAzureRMDnsNsRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -480,11 +457,11 @@ resource "azurerm_dns_ns_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } //TODO: remove this once we remove the `record` attribute -func testAccAzureRMDnsNsRecord_deprecatedWithTags(rInt int, location string) string { +func testAccAzureRMDnsNsRecord_deprecatedWithTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -515,10 +492,10 @@ resource "azurerm_dns_ns_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsNsRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsNsRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -542,11 +519,11 @@ resource "azurerm_dns_ns_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } //TODO: remove this once we remove the `record` attribute -func testAccAzureRMDnsNsRecord_deprecatedWithTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsNsRecord_deprecatedWithTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -576,5 +553,5 @@ resource "azurerm_dns_ns_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/resource_arm_dns_ptr_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_ptr_record_test.go similarity index 73% rename from azurerm/internal/services/dns/resource_arm_dns_ptr_record_test.go rename to azurerm/internal/services/dns/tests/resource_arm_dns_ptr_record_test.go index b35b26ad15a7..5d02df88f9cb 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_ptr_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_ptr_record_test.go @@ -1,4 +1,4 @@ -package dns +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDnsPtrRecord_basic(t *testing.T) { - resourceName := "azurerm_dns_ptr_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsPtrRecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_ptr_record", "test") + config := testAccAzureRMDnsPtrRecord_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,15 +25,11 @@ func TestAccAzureRMDnsPtrRecord_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsPtrRecordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + testCheckAzureRMDnsPtrRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +40,7 @@ func TestAccAzureRMDnsPtrRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dns_ptr_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dns_ptr_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +48,13 @@ func TestAccAzureRMDnsPtrRecord_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDnsPtrRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDnsPtrRecord_basic(ri, location), + Config: testAccAzureRMDnsPtrRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsPtrRecordExists(resourceName), + testCheckAzureRMDnsPtrRecordExists(data.ResourceName), ), }, { - Config: testAccAzureRMDnsPtrRecord_requiresImport(ri, location), + Config: testAccAzureRMDnsPtrRecord_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dns_ptr_record"), }, }, @@ -70,10 +62,7 @@ func TestAccAzureRMDnsPtrRecord_requiresImport(t *testing.T) { } func TestAccAzureRMDnsPtrRecord_updateRecords(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsPtrRecord_basic(ri, location) - postConfig := testAccAzureRMDnsPtrRecord_updateRecords(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_ptr_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,18 +70,18 @@ func TestAccAzureRMDnsPtrRecord_updateRecords(t *testing.T) { CheckDestroy: testCheckAzureRMDnsPtrRecordDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccAzureRMDnsPtrRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsPtrRecordExists("azurerm_dns_ptr_record.test"), - resource.TestCheckResourceAttr("azurerm_dns_ptr_record.test", "records.#", "2"), + testCheckAzureRMDnsPtrRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "2"), ), }, { - Config: postConfig, + Config: testAccAzureRMDnsPtrRecord_updateRecords(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsPtrRecordExists("azurerm_dns_ptr_record.test"), - resource.TestCheckResourceAttr("azurerm_dns_ptr_record.test", "records.#", "3"), + testCheckAzureRMDnsPtrRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "records.#", "3"), ), }, }, @@ -100,11 +89,9 @@ func TestAccAzureRMDnsPtrRecord_updateRecords(t *testing.T) { } func TestAccAzureRMDnsPtrRecord_withTags(t *testing.T) { - resourceName := "azurerm_dns_ptr_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsPtrRecord_withTags(ri, location) - postConfig := testAccAzureRMDnsPtrRecord_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_ptr_record", "test") + preConfig := testAccAzureRMDnsPtrRecord_withTags(data) + postConfig := testAccAzureRMDnsPtrRecord_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,23 +101,19 @@ func TestAccAzureRMDnsPtrRecord_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsPtrRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsPtrRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsPtrRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsPtrRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -194,7 +177,7 @@ func testCheckAzureRMDnsPtrRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDnsPtrRecord_basic(rInt int, location string) string { +func testAccAzureRMDnsPtrRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -213,11 +196,11 @@ resource "azurerm_dns_ptr_record" "test" { ttl = 300 records = ["hashicorp.com", "microsoft.com"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsPtrRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMDnsPtrRecord_basic(rInt, location) +func testAccAzureRMDnsPtrRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDnsPtrRecord_basic(data) return fmt.Sprintf(` %s @@ -231,7 +214,7 @@ resource "azurerm_dns_ptr_record" "import" { `, template) } -func testAccAzureRMDnsPtrRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMDnsPtrRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -250,10 +233,10 @@ resource "azurerm_dns_ptr_record" "test" { ttl = 300 records = ["hashicorp.com", "microsoft.com", "reddit.com"] } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsPtrRecord_withTags(rInt int, location string) string { +func testAccAzureRMDnsPtrRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -277,10 +260,10 @@ resource "azurerm_dns_ptr_record" "test" { cost_center = "Ops" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsPtrRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsPtrRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -303,5 +286,5 @@ resource "azurerm_dns_ptr_record" "test" { environment = "Stage" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/resource_arm_dns_srv_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_srv_record_test.go similarity index 76% rename from azurerm/internal/services/dns/resource_arm_dns_srv_record_test.go rename to azurerm/internal/services/dns/tests/resource_arm_dns_srv_record_test.go index 29ab0d042d1c..47f7041771ab 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_srv_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_srv_record_test.go @@ -1,4 +1,4 @@ -package dns +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDnsSrvRecord_basic(t *testing.T) { - resourceName := "azurerm_dns_srv_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsSrvRecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_srv_record", "test") + config := testAccAzureRMDnsSrvRecord_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,15 +25,11 @@ func TestAccAzureRMDnsSrvRecord_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsSrvRecordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + testCheckAzureRMDnsSrvRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +40,7 @@ func TestAccAzureRMDnsSrvRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dns_srv_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dns_srv_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +48,13 @@ func TestAccAzureRMDnsSrvRecord_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDnsSrvRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDnsSrvRecord_basic(ri, location), + Config: testAccAzureRMDnsSrvRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsSrvRecordExists(resourceName), + testCheckAzureRMDnsSrvRecordExists(data.ResourceName), ), }, { - Config: testAccAzureRMDnsSrvRecord_requiresImport(ri, location), + Config: testAccAzureRMDnsSrvRecord_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dns_srv_record"), }, }, @@ -70,11 +62,9 @@ func TestAccAzureRMDnsSrvRecord_requiresImport(t *testing.T) { } func TestAccAzureRMDnsSrvRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_dns_srv_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsSrvRecord_basic(ri, location) - postConfig := testAccAzureRMDnsSrvRecord_updateRecords(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_srv_record", "test") + preConfig := testAccAzureRMDnsSrvRecord_basic(data) + postConfig := testAccAzureRMDnsSrvRecord_updateRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -84,15 +74,15 @@ func TestAccAzureRMDnsSrvRecord_updateRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsSrvRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "2"), + testCheckAzureRMDnsSrvRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsSrvRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "3"), + testCheckAzureRMDnsSrvRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "3"), ), }, }, @@ -100,11 +90,9 @@ func TestAccAzureRMDnsSrvRecord_updateRecords(t *testing.T) { } func TestAccAzureRMDnsSrvRecord_withTags(t *testing.T) { - resourceName := "azurerm_dns_srv_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsSrvRecord_withTags(ri, location) - postConfig := testAccAzureRMDnsSrvRecord_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_srv_record", "test") + preConfig := testAccAzureRMDnsSrvRecord_withTags(data) + postConfig := testAccAzureRMDnsSrvRecord_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,22 +102,18 @@ func TestAccAzureRMDnsSrvRecord_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsSrvRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsSrvRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsSrvRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsSrvRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -193,7 +177,7 @@ func testCheckAzureRMDnsSrvRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDnsSrvRecord_basic(rInt int, location string) string { +func testAccAzureRMDnsSrvRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -225,11 +209,11 @@ resource "azurerm_dns_srv_record" "test" { target = "target2.contoso.com" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsSrvRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMDnsSrvRecord_basic(rInt, location) +func testAccAzureRMDnsSrvRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDnsSrvRecord_basic(data) return fmt.Sprintf(` %s @@ -256,7 +240,7 @@ resource "azurerm_dns_srv_record" "import" { `, template) } -func testAccAzureRMDnsSrvRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMDnsSrvRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -295,10 +279,10 @@ resource "azurerm_dns_srv_record" "test" { target = "target3.contoso.com" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsSrvRecord_withTags(rInt int, location string) string { +func testAccAzureRMDnsSrvRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -335,10 +319,10 @@ resource "azurerm_dns_srv_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsSrvRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsSrvRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -374,5 +358,5 @@ resource "azurerm_dns_srv_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/resource_arm_dns_txt_record_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_txt_record_test.go similarity index 74% rename from azurerm/internal/services/dns/resource_arm_dns_txt_record_test.go rename to azurerm/internal/services/dns/tests/resource_arm_dns_txt_record_test.go index 58d4a7310eda..a77ee43d5922 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_txt_record_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_txt_record_test.go @@ -1,4 +1,4 @@ -package dns +package tests import ( "fmt" @@ -8,16 +8,14 @@ import ( "github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2018-05-01/dns" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDnsTxtRecord_basic(t *testing.T) { - resourceName := "azurerm_dns_txt_record.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsTxtRecord_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_txt_record", "test") + config := testAccAzureRMDnsTxtRecord_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,15 +25,11 @@ func TestAccAzureRMDnsTxtRecord_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsTxtRecordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "fqdn"), + testCheckAzureRMDnsTxtRecordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "fqdn"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +40,7 @@ func TestAccAzureRMDnsTxtRecord_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dns_txt_record.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dns_txt_record", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +48,13 @@ func TestAccAzureRMDnsTxtRecord_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDnsTxtRecordDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDnsTxtRecord_basic(ri, location), + Config: testAccAzureRMDnsTxtRecord_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsTxtRecordExists(resourceName), + testCheckAzureRMDnsTxtRecordExists(data.ResourceName), ), }, { - Config: testAccAzureRMDnsTxtRecord_requiresImport(ri, location), + Config: testAccAzureRMDnsTxtRecord_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dns_txt_record"), }, }, @@ -70,10 +62,9 @@ func TestAccAzureRMDnsTxtRecord_requiresImport(t *testing.T) { } func TestAccAzureRMDnsTxtRecord_updateRecords(t *testing.T) { - resourceName := "azurerm_dns_txt_record.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMDnsTxtRecord_basic(ri, acceptance.Location()) - postConfig := testAccAzureRMDnsTxtRecord_updateRecords(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_txt_record", "test") + preConfig := testAccAzureRMDnsTxtRecord_basic(data) + postConfig := testAccAzureRMDnsTxtRecord_updateRecords(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -83,15 +74,15 @@ func TestAccAzureRMDnsTxtRecord_updateRecords(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsTxtRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "2"), + testCheckAzureRMDnsTxtRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsTxtRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "record.#", "3"), + testCheckAzureRMDnsTxtRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "record.#", "3"), ), }, }, @@ -99,10 +90,9 @@ func TestAccAzureRMDnsTxtRecord_updateRecords(t *testing.T) { } func TestAccAzureRMDnsTxtRecord_withTags(t *testing.T) { - resourceName := "azurerm_dns_txt_record.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMDnsTxtRecord_withTags(ri, acceptance.Location()) - postConfig := testAccAzureRMDnsTxtRecord_withTagsUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_txt_record", "test") + preConfig := testAccAzureRMDnsTxtRecord_withTags(data) + postConfig := testAccAzureRMDnsTxtRecord_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -112,22 +102,18 @@ func TestAccAzureRMDnsTxtRecord_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsTxtRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsTxtRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsTxtRecordExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsTxtRecordExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -191,7 +177,7 @@ func testCheckAzureRMDnsTxtRecordDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDnsTxtRecord_basic(rInt int, location string) string { +func testAccAzureRMDnsTxtRecord_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -217,11 +203,11 @@ resource "azurerm_dns_txt_record" "test" { value = "Another test txt string" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsTxtRecord_requiresImport(rInt int, location string) string { - template := testAccAzureRMDnsTxtRecord_basic(rInt, location) +func testAccAzureRMDnsTxtRecord_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDnsTxtRecord_basic(data) return fmt.Sprintf(` %s @@ -242,7 +228,7 @@ resource "azurerm_dns_txt_record" "import" { `, template) } -func testAccAzureRMDnsTxtRecord_updateRecords(rInt int, location string) string { +func testAccAzureRMDnsTxtRecord_updateRecords(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -272,10 +258,10 @@ resource "azurerm_dns_txt_record" "test" { value = "A wild 3rd record appears" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsTxtRecord_withTags(rInt int, location string) string { +func testAccAzureRMDnsTxtRecord_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -306,10 +292,10 @@ resource "azurerm_dns_txt_record" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDnsTxtRecord_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsTxtRecord_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -339,5 +325,5 @@ resource "azurerm_dns_txt_record" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/dns/resource_arm_dns_zone_test.go b/azurerm/internal/services/dns/tests/resource_arm_dns_zone_test.go similarity index 73% rename from azurerm/internal/services/dns/resource_arm_dns_zone_test.go rename to azurerm/internal/services/dns/tests/resource_arm_dns_zone_test.go index 6a007cf03411..8e6d587bd7d0 100644 --- a/azurerm/internal/services/dns/resource_arm_dns_zone_test.go +++ b/azurerm/internal/services/dns/tests/resource_arm_dns_zone_test.go @@ -1,4 +1,4 @@ -package dns +package tests import ( "fmt" @@ -7,16 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDnsZone_basic(t *testing.T) { - resourceName := "azurerm_dns_zone.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsZone_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_zone", "test") + config := testAccAzureRMDnsZone_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,14 +24,10 @@ func TestAccAzureRMDnsZone_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsZoneExists(resourceName), + testCheckAzureRMDnsZoneExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,9 +38,7 @@ func TestAccAzureRMDnsZone_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dns_zone.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dns_zone", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,13 +46,13 @@ func TestAccAzureRMDnsZone_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDnsZoneDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDnsZone_basic(ri, location), + Config: testAccAzureRMDnsZone_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsZoneExists(resourceName), + testCheckAzureRMDnsZoneExists(data.ResourceName), ), }, { - Config: testAccAzureRMDnsZone_requiresImport(ri, location), + Config: testAccAzureRMDnsZone_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dns_zone"), }, }, @@ -68,9 +60,8 @@ func TestAccAzureRMDnsZone_requiresImport(t *testing.T) { } func TestAccAzureRMDnsZone_withVNets(t *testing.T) { - resourceName := "azurerm_dns_zone.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDnsZone_withVNets(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_dns_zone", "test") + config := testAccAzureRMDnsZone_withVNets(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,24 +71,18 @@ func TestAccAzureRMDnsZone_withVNets(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsZoneExists(resourceName), + testCheckAzureRMDnsZoneExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDnsZone_withTags(t *testing.T) { - resourceName := "azurerm_dns_zone.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDnsZone_withTags(ri, location) - postConfig := testAccAzureRMDnsZone_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dns_zone", "test") + preConfig := testAccAzureRMDnsZone_withTags(data) + postConfig := testAccAzureRMDnsZone_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -107,22 +92,18 @@ func TestAccAzureRMDnsZone_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsZoneExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDnsZoneExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDnsZoneExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDnsZoneExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -183,7 +164,7 @@ func testCheckAzureRMDnsZoneDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDnsZone_basic(rInt int, location string) string { +func testAccAzureRMDnsZone_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -194,11 +175,11 @@ resource "azurerm_dns_zone" "test" { name = "acctestzone%d.com" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDnsZone_requiresImport(rInt int, location string) string { - template := testAccAzureRMDnsZone_basic(rInt, location) +func testAccAzureRMDnsZone_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDnsZone_basic(data) return fmt.Sprintf(` %s @@ -209,7 +190,7 @@ resource "azurerm_dns_zone" "import" { `, template) } -func testAccAzureRMDnsZone_withVNets(rInt int, location string) string { +func testAccAzureRMDnsZone_withVNets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG_%d" @@ -230,10 +211,10 @@ resource "azurerm_dns_zone" "test" { zone_type = "Private" registration_virtual_network_ids = ["${azurerm_virtual_network.test.id}"] } -`, rInt, location, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDnsZone_withTags(rInt int, location string) string { +func testAccAzureRMDnsZone_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -249,10 +230,10 @@ resource "azurerm_dns_zone" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDnsZone_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDnsZone_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -267,5 +248,5 @@ resource "azurerm_dns_zone" "test" { environment = "staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 24ba657da65930a129bc63f55cc51cc7addeea81 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 12:00:02 -0800 Subject: [PATCH 145/203] devtestlabs: switching to the new test structure --- .../resource_arm_dev_test_virtual_network.go | 4 +- .../data_source_dev_test_lab_test.go | 33 ++-- ...ta_source_dev_test_virtual_network_test.go | 40 ++--- ...resource_arm_dev_test_lab_schedule_test.go | 112 ++++++------ .../resource_arm_dev_test_lab_test.go | 63 +++---- ...arm_dev_test_linux_virtual_machine_test.go | 162 ++++++++---------- .../resource_arm_dev_test_policy_test.go | 61 +++---- ...ource_arm_dev_test_virtual_network_test.go | 70 +++----- ...m_dev_test_windows_virtual_machine_test.go | 127 ++++++-------- 9 files changed, 280 insertions(+), 392 deletions(-) rename azurerm/internal/services/devtestlabs/{ => tests}/data_source_dev_test_lab_test.go (64%) rename azurerm/internal/services/devtestlabs/{ => tests}/data_source_dev_test_virtual_network_test.go (50%) rename azurerm/internal/services/devtestlabs/{ => tests}/resource_arm_dev_test_lab_schedule_test.go (70%) rename azurerm/internal/services/devtestlabs/{ => tests}/resource_arm_dev_test_lab_test.go (71%) rename azurerm/internal/services/devtestlabs/{ => tests}/resource_arm_dev_test_linux_virtual_machine_test.go (69%) rename azurerm/internal/services/devtestlabs/{ => tests}/resource_arm_dev_test_policy_test.go (76%) rename azurerm/internal/services/devtestlabs/{ => tests}/resource_arm_dev_test_virtual_network_test.go (74%) rename azurerm/internal/services/devtestlabs/{ => tests}/resource_arm_dev_test_windows_virtual_machine_test.go (70%) diff --git a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network.go b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network.go index 1d9b06927fce..fab36f1fa74b 100644 --- a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network.go +++ b/azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network.go @@ -41,7 +41,7 @@ func resourceArmDevTestVirtualNetwork() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateDevTestVirtualNetworkName(), + ValidateFunc: ValidateDevTestVirtualNetworkName(), }, "lab_name": { @@ -290,7 +290,7 @@ func resourceArmDevTestVirtualNetworkDelete(d *schema.ResourceData, meta interfa return err } -func validateDevTestVirtualNetworkName() schema.SchemaValidateFunc { +func ValidateDevTestVirtualNetworkName() schema.SchemaValidateFunc { return validation.StringMatch( regexp.MustCompile("^[A-Za-z0-9_-]+$"), "Virtual Network Name can only include alphanumeric characters, underscores, hyphens.") diff --git a/azurerm/internal/services/devtestlabs/data_source_dev_test_lab_test.go b/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_lab_test.go similarity index 64% rename from azurerm/internal/services/devtestlabs/data_source_dev_test_lab_test.go rename to azurerm/internal/services/devtestlabs/tests/data_source_dev_test_lab_test.go index 707e87275696..3cc99acb9e86 100644 --- a/azurerm/internal/services/devtestlabs/data_source_dev_test_lab_test.go +++ b/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_lab_test.go @@ -1,28 +1,25 @@ -package devtestlabs +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMDevTestLab_basic(t *testing.T) { - dataSourceName := "data.azurerm_dev_test_lab.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_dev_test_lab", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceDevTestLab_basic(rInt, location), + Config: testAccDataSourceDevTestLab_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "storage_type", "Premium"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_type", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -30,27 +27,25 @@ func TestAccDataSourceAzureRMDevTestLab_basic(t *testing.T) { } func TestAccDataSourceAzureRMDevTestLab_complete(t *testing.T) { - dataSourceName := "data.azurerm_dev_test_lab.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_dev_test_lab", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceDevTestLab_complete(rInt, location), + Config: testAccDataSourceDevTestLab_complete(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "storage_type", "Standard"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.Hello", "World"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_type", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), ), }, }, }) } -func testAccDataSourceDevTestLab_basic(rInt int, location string) string { +func testAccDataSourceDevTestLab_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -67,10 +62,10 @@ data "azurerm_dev_test_lab" "test" { name = "${azurerm_dev_test_lab.test.name}" resource_group_name = "${azurerm_dev_test_lab.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceDevTestLab_complete(rInt int, location string) string { +func testAccDataSourceDevTestLab_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -92,5 +87,5 @@ data "azurerm_dev_test_lab" "test" { name = "${azurerm_dev_test_lab.test.name}" resource_group_name = "${azurerm_dev_test_lab.test.resource_group_name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/devtestlabs/data_source_dev_test_virtual_network_test.go b/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_virtual_network_test.go similarity index 50% rename from azurerm/internal/services/devtestlabs/data_source_dev_test_virtual_network_test.go rename to azurerm/internal/services/devtestlabs/tests/data_source_dev_test_virtual_network_test.go index 03994fc6f493..eb3c5e134306 100644 --- a/azurerm/internal/services/devtestlabs/data_source_dev_test_virtual_network_test.go +++ b/azurerm/internal/services/devtestlabs/tests/data_source_dev_test_virtual_network_test.go @@ -1,4 +1,4 @@ -package devtestlabs +package tests import ( "fmt" @@ -6,21 +6,19 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceArmDevTestVirtualNetwork_basic(t *testing.T) { - dataSourceName := "data.azurerm_dev_test_virtual_network.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "data.azurerm_dev_test_virtual_network", "test") - name := fmt.Sprintf("acctestdtvn%d", ri) - labName := fmt.Sprintf("acctestdtl%d", ri) - resGroup := fmt.Sprintf("acctestRG-%d", ri) + name := fmt.Sprintf("acctestdtvn%d", data.RandomInteger) + labName := fmt.Sprintf("acctestdtl%d", data.RandomInteger) + resGroup := fmt.Sprintf("acctestRG-%d", data.RandomInteger) subnetName := name + "Subnet" subnetResourceID := fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s", os.Getenv("ARM_SUBSCRIPTION_ID"), resGroup, name, subnetName) - config := testAccDataSourceArmDevTestVirtualNetwork_basic(ri, acceptance.Location()) + config := testAccDataSourceArmDevTestVirtualNetwork_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,24 +27,24 @@ func TestAccDataSourceArmDevTestVirtualNetwork_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "name", name), - resource.TestCheckResourceAttr(dataSourceName, "lab_name", labName), - resource.TestCheckResourceAttr(dataSourceName, "resource_group_name", resGroup), - resource.TestCheckResourceAttr(dataSourceName, "allowed_subnets.0.allow_public_ip", "Allow"), - resource.TestCheckResourceAttr(dataSourceName, "allowed_subnets.0.lab_subnet_name", subnetName), - resource.TestCheckResourceAttr(dataSourceName, "allowed_subnets.0.resource_id", subnetResourceID), - resource.TestCheckResourceAttr(dataSourceName, "subnet_overrides.0.lab_subnet_name", subnetName), - resource.TestCheckResourceAttr(dataSourceName, "subnet_overrides.0.resource_id", subnetResourceID), - resource.TestCheckResourceAttr(dataSourceName, "subnet_overrides.0.use_in_vm_creation_permission", "Allow"), - resource.TestCheckResourceAttr(dataSourceName, "subnet_overrides.0.use_public_ip_address_permission", "Allow"), - resource.TestCheckResourceAttr(dataSourceName, "subnet_overrides.0.virtual_network_pool_name", ""), + resource.TestCheckResourceAttr(data.ResourceName, "name", name), + resource.TestCheckResourceAttr(data.ResourceName, "lab_name", labName), + resource.TestCheckResourceAttr(data.ResourceName, "resource_group_name", resGroup), + resource.TestCheckResourceAttr(data.ResourceName, "allowed_subnets.0.allow_public_ip", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "allowed_subnets.0.lab_subnet_name", subnetName), + resource.TestCheckResourceAttr(data.ResourceName, "allowed_subnets.0.resource_id", subnetResourceID), + resource.TestCheckResourceAttr(data.ResourceName, "subnet_overrides.0.lab_subnet_name", subnetName), + resource.TestCheckResourceAttr(data.ResourceName, "subnet_overrides.0.resource_id", subnetResourceID), + resource.TestCheckResourceAttr(data.ResourceName, "subnet_overrides.0.use_in_vm_creation_permission", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "subnet_overrides.0.use_public_ip_address_permission", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "subnet_overrides.0.virtual_network_pool_name", ""), ), }, }, }) } -func testAccDataSourceArmDevTestVirtualNetwork_basic(rInt int, location string) string { +func testAccDataSourceArmDevTestVirtualNetwork_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -77,5 +75,5 @@ data "azurerm_dev_test_virtual_network" "test" { } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_schedule_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go similarity index 70% rename from azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_schedule_test.go rename to azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go index 2ebe5f975869..7893e29f7815 100644 --- a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_schedule_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go @@ -1,4 +1,4 @@ -package devtestlabs +package tests import ( "fmt" @@ -7,17 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) func TestAccAzureRMDevTestLabSchedule_autoShutdownBasic(t *testing.T) { - resourceName := "azurerm_dev_test_schedule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDevTestLabSchedule_autoShutdownBasic(ri, location) - postConfig := testAccAzureRMDevTestLabSchedule_autoShutdownBasicUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dev_test_schedule", "test") + preConfig := testAccAzureRMDevTestLabSchedule_autoShutdownBasic(data) + postConfig := testAccAzureRMDevTestLabSchedule_autoShutdownBasicUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -26,30 +23,26 @@ func TestAccAzureRMDevTestLabSchedule_autoShutdownBasic(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLabScheduleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "status", "Disabled"), - resource.TestCheckResourceAttr(resourceName, "notification_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "notification_settings.0.status", "Disabled"), - resource.TestCheckResourceAttr(resourceName, "daily_recurrence.#", "1"), - resource.TestCheckResourceAttr(resourceName, "daily_recurrence.0.time", "0100"), + testCheckAzureRMDevTestLabScheduleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "status", "Disabled"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.0.status", "Disabled"), + resource.TestCheckResourceAttr(data.ResourceName, "daily_recurrence.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "daily_recurrence.0.time", "0100"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLabScheduleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "status", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "notification_settings.#", "1"), - resource.TestCheckResourceAttr(resourceName, "notification_settings.0.status", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "notification_settings.0.time_in_minutes", "30"), - resource.TestCheckResourceAttr(resourceName, "notification_settings.0.webhook_url", "https://www.bing.com/2/4"), - resource.TestCheckResourceAttr(resourceName, "daily_recurrence.#", "1"), - resource.TestCheckResourceAttr(resourceName, "daily_recurrence.0.time", "0900"), + testCheckAzureRMDevTestLabScheduleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "status", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.0.status", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.0.time_in_minutes", "30"), + resource.TestCheckResourceAttr(data.ResourceName, "notification_settings.0.webhook_url", "https://www.bing.com/2/4"), + resource.TestCheckResourceAttr(data.ResourceName, "daily_recurrence.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "daily_recurrence.0.time", "0900"), ), }, }, @@ -57,11 +50,9 @@ func TestAccAzureRMDevTestLabSchedule_autoShutdownBasic(t *testing.T) { } func TestAccAzureRMDevTestLabSchedule_autoStartupBasic(t *testing.T) { - resourceName := "azurerm_dev_test_schedule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMDevTestLabSchedule_autoStartupBasic(ri, location) - postConfig := testAccAzureRMDevTestLabSchedule_autoStartupBasicUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_dev_test_schedule", "test") + preConfig := testAccAzureRMDevTestLabSchedule_autoStartupBasic(data) + postConfig := testAccAzureRMDevTestLabSchedule_autoStartupBasicUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -70,29 +61,24 @@ func TestAccAzureRMDevTestLabSchedule_autoStartupBasic(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLabScheduleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "status", "Disabled"), - resource.TestCheckResourceAttr(resourceName, "weekly_recurrence.#", "1"), - resource.TestCheckResourceAttr(resourceName, "weekly_recurrence.0.time", "1100"), - resource.TestCheckResourceAttr(resourceName, "weekly_recurrence.0.week_days.#", "2"), - resource.TestCheckResourceAttr(resourceName, "weekly_recurrence.0.week_days.1", "Tuesday"), + testCheckAzureRMDevTestLabScheduleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "status", "Disabled"), + resource.TestCheckResourceAttr(data.ResourceName, "weekly_recurrence.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "weekly_recurrence.0.time", "1100"), + resource.TestCheckResourceAttr(data.ResourceName, "weekly_recurrence.0.week_days.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "weekly_recurrence.0.week_days.1", "Tuesday"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"task_type"}, - }, + data.ImportStep("task_type"), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLabScheduleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "status", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "weekly_recurrence.#", "1"), - resource.TestCheckResourceAttr(resourceName, "weekly_recurrence.0.time", "1000"), - resource.TestCheckResourceAttr(resourceName, "weekly_recurrence.0.week_days.#", "3"), - resource.TestCheckResourceAttr(resourceName, "weekly_recurrence.0.week_days.1", "Thursday"), + testCheckAzureRMDevTestLabScheduleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "status", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "weekly_recurrence.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "weekly_recurrence.0.time", "1000"), + resource.TestCheckResourceAttr(data.ResourceName, "weekly_recurrence.0.week_days.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "weekly_recurrence.0.week_days.1", "Thursday"), ), }, }, @@ -100,10 +86,8 @@ func TestAccAzureRMDevTestLabSchedule_autoStartupBasic(t *testing.T) { } func TestAccAzureRMDevTestLabSchedule_concurrent(t *testing.T) { - firstResourceName := "azurerm_dev_test_schedule.test" + data := acceptance.BuildTestData(t, "azurerm_dev_test_schedule", "test") secondResourceName := "azurerm_dev_test_schedule.test2" - ri := tf.AccRandTimeInt() - config := testAccAzureRMDevTestLabSchedule_concurrent(ri, acceptance.Location()) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,9 +95,9 @@ func TestAccAzureRMDevTestLabSchedule_concurrent(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestLabScheduleDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDevTestLabSchedule_concurrent(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLabScheduleExists(firstResourceName), + testCheckAzureRMDevTestLabScheduleExists(data.ResourceName), testCheckAzureRMDevTestLabScheduleExists(secondResourceName), ), }, @@ -175,7 +159,7 @@ func testCheckAzureRMDevTestLabScheduleDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDevTestLabSchedule_autoShutdownBasic(rInt int, location string) string { +func testAccAzureRMDevTestLabSchedule_autoShutdownBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -207,10 +191,10 @@ resource "azurerm_dev_test_schedule" "test" { environment = "Production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDevTestLabSchedule_autoShutdownBasicUpdate(rInt int, location string) string { +func testAccAzureRMDevTestLabSchedule_autoShutdownBasicUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -245,10 +229,10 @@ resource "azurerm_dev_test_schedule" "test" { } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDevTestLabSchedule_autoStartupBasic(rInt int, location string) string { +func testAccAzureRMDevTestLabSchedule_autoStartupBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -283,10 +267,10 @@ resource "azurerm_dev_test_schedule" "test" { environment = "Production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDevTestLabSchedule_autoStartupBasicUpdate(rInt int, location string) string { +func testAccAzureRMDevTestLabSchedule_autoStartupBasicUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -324,10 +308,10 @@ resource "azurerm_dev_test_schedule" "test" { } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDevTestLabSchedule_concurrent(rInt int, location string) string { +func testAccAzureRMDevTestLabSchedule_concurrent(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -381,5 +365,5 @@ resource "azurerm_dev_test_schedule" "test2" { environment = "Production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_test.go similarity index 71% rename from azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_test.go rename to azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_test.go index 167ad4485dfb..89ab1c87a0c6 100644 --- a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_lab_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_test.go @@ -1,4 +1,4 @@ -package devtestlabs +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDevTestLab_basic(t *testing.T) { - resourceName := "azurerm_dev_test_lab.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_lab", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,18 +21,14 @@ func TestAccAzureRMDevTestLab_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestLabDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestLab_basic(rInt, location), + Config: testAccAzureRMDevTestLab_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLabExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_type", "Premium"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestLabExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_type", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +39,7 @@ func TestAccAzureRMDevTestLab_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dev_test_lab.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_lab", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +47,13 @@ func TestAccAzureRMDevTestLab_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestLabDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestLab_basic(rInt, location), + Config: testAccAzureRMDevTestLab_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLabExists(resourceName), + testCheckAzureRMDevTestLabExists(data.ResourceName), ), }, { - Config: testAccAzureRMDevTestLab_requiresImport(rInt, location), + Config: testAccAzureRMDevTestLab_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dev_test_lab"), }, }, @@ -70,9 +61,7 @@ func TestAccAzureRMDevTestLab_requiresImport(t *testing.T) { } func TestAccAzureRMDevTestLab_complete(t *testing.T) { - resourceName := "azurerm_dev_test_lab.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_lab", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,19 +69,15 @@ func TestAccAzureRMDevTestLab_complete(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestLabDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestLab_complete(rInt, location), + Config: testAccAzureRMDevTestLab_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLabExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "storage_type", "Standard"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), + testCheckAzureRMDevTestLabExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "storage_type", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -154,7 +139,7 @@ func testCheckAzureRMDevTestLabDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDevTestLab_basic(rInt int, location string) string { +func testAccAzureRMDevTestLab_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -166,11 +151,11 @@ resource "azurerm_dev_test_lab" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDevTestLab_requiresImport(rInt int, location string) string { - template := testAccAzureRMDevTestLab_basic(rInt, location) +func testAccAzureRMDevTestLab_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDevTestLab_basic(data) return fmt.Sprintf(` %s @@ -182,7 +167,7 @@ resource "azurerm_dev_test_lab" "import" { `, template) } -func testAccAzureRMDevTestLab_complete(rInt int, location string) string { +func testAccAzureRMDevTestLab_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -199,5 +184,5 @@ resource "azurerm_dev_test_lab" "test" { Hello = "World" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_linux_virtual_machine_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_linux_virtual_machine_test.go similarity index 69% rename from azurerm/internal/services/devtestlabs/resource_arm_dev_test_linux_virtual_machine_test.go rename to azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_linux_virtual_machine_test.go index 10dfb3813c53..673d4644b77d 100644 --- a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_linux_virtual_machine_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_linux_virtual_machine_test.go @@ -1,4 +1,4 @@ -package devtestlabs +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDevTestLinuxVirtualMachine_basic(t *testing.T) { - resourceName := "azurerm_dev_test_linux_virtual_machine.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_linux_virtual_machine", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,24 +21,19 @@ func TestAccAzureRMDevTestLinuxVirtualMachine_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestLinuxVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestLinuxVirtualMachine_basic(rInt, location), + Config: testAccAzureRMDevTestLinuxVirtualMachine_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLinuxVirtualMachineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gallery_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestLinuxVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "gallery_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "lab_subnet_name", - "lab_virtual_network_id", - "password", - }, - }, + data.ImportStep( + // not returned from the API + "lab_subnet_name", + "lab_virtual_network_id", + "password", + ), }, }) } @@ -52,9 +44,7 @@ func TestAccAzureRMDevTestLinuxVirtualMachine_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dev_test_linux_virtual_machine.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_linux_virtual_machine", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -62,13 +52,13 @@ func TestAccAzureRMDevTestLinuxVirtualMachine_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestLinuxVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestLinuxVirtualMachine_basic(rInt, location), + Config: testAccAzureRMDevTestLinuxVirtualMachine_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLinuxVirtualMachineExists(resourceName), + testCheckAzureRMDevTestLinuxVirtualMachineExists(data.ResourceName), ), }, { - Config: testAccAzureRMDevTestLinuxVirtualMachine_requiresImport(rInt, location), + Config: testAccAzureRMDevTestLinuxVirtualMachine_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dev_test_lab_linux_virtual_machine"), }, }, @@ -76,9 +66,7 @@ func TestAccAzureRMDevTestLinuxVirtualMachine_requiresImport(t *testing.T) { } func TestAccAzureRMDevTestLinuxVirtualMachine_basicSSH(t *testing.T) { - resourceName := "azurerm_dev_test_linux_virtual_machine.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_linux_virtual_machine", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,32 +74,25 @@ func TestAccAzureRMDevTestLinuxVirtualMachine_basicSSH(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestLinuxVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestLinuxVirtualMachine_basicSSH(rInt, location), + Config: testAccAzureRMDevTestLinuxVirtualMachine_basicSSH(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLinuxVirtualMachineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gallery_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestLinuxVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "gallery_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "lab_subnet_name", - "lab_virtual_network_id", - "ssh_key", - }, - }, + data.ImportStep( + // not returned from the API + "lab_subnet_name", + "lab_virtual_network_id", + "password", + ), }, }) } func TestAccAzureRMDevTestLinuxVirtualMachine_inboundNatRules(t *testing.T) { - resourceName := "azurerm_dev_test_linux_virtual_machine.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_linux_virtual_machine", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -119,35 +100,28 @@ func TestAccAzureRMDevTestLinuxVirtualMachine_inboundNatRules(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestLinuxVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestLinuxVirtualMachine_inboundNatRules(rInt, location), + Config: testAccAzureRMDevTestLinuxVirtualMachine_inboundNatRules(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLinuxVirtualMachineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "disallow_public_ip_address", "true"), - resource.TestCheckResourceAttr(resourceName, "gallery_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Acceptance", "Test"), + testCheckAzureRMDevTestLinuxVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "disallow_public_ip_address", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "gallery_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Acceptance", "Test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "inbound_nat_rule", - "lab_subnet_name", - "lab_virtual_network_id", - "password", - }, - }, + data.ImportStep( + // not returned from the API + "inbound_nat_rule", + "lab_subnet_name", + "lab_virtual_network_id", + "password", + ), }, }) } func TestAccAzureRMDevTestLinuxVirtualMachine_updateStorage(t *testing.T) { - resourceName := "azurerm_dev_test_linux_virtual_machine.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_linux_virtual_machine", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -155,21 +129,21 @@ func TestAccAzureRMDevTestLinuxVirtualMachine_updateStorage(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestLinuxVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestLinuxVirtualMachine_storage(rInt, location, "Standard"), + Config: testAccAzureRMDevTestLinuxVirtualMachine_storage(data, "Standard"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLinuxVirtualMachineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gallery_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "storage_type", "Standard"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestLinuxVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "gallery_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_type", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, { - Config: testAccAzureRMDevTestLinuxVirtualMachine_storage(rInt, location, "Premium"), + Config: testAccAzureRMDevTestLinuxVirtualMachine_storage(data, "Premium"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestLinuxVirtualMachineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gallery_image_reference.0.publisher", "Canonical"), - resource.TestCheckResourceAttr(resourceName, "storage_type", "Premium"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestLinuxVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "gallery_image_reference.0.publisher", "Canonical"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_type", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -233,8 +207,8 @@ func testCheckAzureRMDevTestLinuxVirtualMachineDestroy(s *terraform.State) error return nil } -func testAccAzureRMDevTestLinuxVirtualMachine_basic(rInt int, location string) string { - template := testAccAzureRMDevTestLinuxVirtualMachine_template(rInt, location) +func testAccAzureRMDevTestLinuxVirtualMachine_basic(data acceptance.TestData) string { + template := testAccAzureRMDevTestLinuxVirtualMachine_template(data) return fmt.Sprintf(` %s @@ -257,11 +231,11 @@ resource "azurerm_dev_test_linux_virtual_machine" "test" { version = "latest" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMDevTestLinuxVirtualMachine_requiresImport(rInt int, location string) string { - template := testAccAzureRMDevTestLinuxVirtualMachine_basic(rInt, location) +func testAccAzureRMDevTestLinuxVirtualMachine_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDevTestLinuxVirtualMachine_basic(data) return fmt.Sprintf(` %s @@ -287,8 +261,8 @@ resource "azurerm_dev_test_linux_virtual_machine" "import" { `, template) } -func testAccAzureRMDevTestLinuxVirtualMachine_basicSSH(rInt int, location string) string { - template := testAccAzureRMDevTestLinuxVirtualMachine_template(rInt, location) +func testAccAzureRMDevTestLinuxVirtualMachine_basicSSH(data acceptance.TestData) string { + template := testAccAzureRMDevTestLinuxVirtualMachine_template(data) return fmt.Sprintf(` %s @@ -311,11 +285,11 @@ resource "azurerm_dev_test_linux_virtual_machine" "test" { version = "latest" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMDevTestLinuxVirtualMachine_inboundNatRules(rInt int, location string) string { - template := testAccAzureRMDevTestLinuxVirtualMachine_template(rInt, location) +func testAccAzureRMDevTestLinuxVirtualMachine_inboundNatRules(data acceptance.TestData) string { + template := testAccAzureRMDevTestLinuxVirtualMachine_template(data) return fmt.Sprintf(` %s @@ -353,11 +327,11 @@ resource "azurerm_dev_test_linux_virtual_machine" "test" { "Acceptance" = "Test" } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMDevTestLinuxVirtualMachine_storage(rInt int, location, storageType string) string { - template := testAccAzureRMDevTestLinuxVirtualMachine_template(rInt, location) +func testAccAzureRMDevTestLinuxVirtualMachine_storage(data acceptance.TestData, storageType string) string { + template := testAccAzureRMDevTestLinuxVirtualMachine_template(data) return fmt.Sprintf(` %s @@ -380,10 +354,10 @@ resource "azurerm_dev_test_linux_virtual_machine" "test" { version = "latest" } } -`, template, rInt, storageType) +`, template, data.RandomInteger, storageType) } -func testAccAzureRMDevTestLinuxVirtualMachine_template(rInt int, location string) string { +func testAccAzureRMDevTestLinuxVirtualMachine_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -406,5 +380,5 @@ resource "azurerm_dev_test_virtual_network" "test" { use_in_virtual_machine_creation = "Allow" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_policy_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_policy_test.go similarity index 76% rename from azurerm/internal/services/devtestlabs/resource_arm_dev_test_policy_test.go rename to azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_policy_test.go index b126e67d3a8a..30861ac408ed 100644 --- a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_policy_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_policy_test.go @@ -1,4 +1,4 @@ -package devtestlabs +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDevTestPolicy_basic(t *testing.T) { - resourceName := "azurerm_dev_test_policy.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,17 +21,13 @@ func TestAccAzureRMDevTestPolicy_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestPolicy_basic(rInt, location), + Config: testAccAzureRMDevTestPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,9 +38,7 @@ func TestAccAzureRMDevTestPolicy_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dev_test_policy.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,14 +46,14 @@ func TestAccAzureRMDevTestPolicy_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestPolicy_basic(rInt, location), + Config: testAccAzureRMDevTestPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, { - Config: testAccAzureRMDevTestPolicy_requiresImport(rInt, location), + Config: testAccAzureRMDevTestPolicy_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dev_test_policy"), }, }, @@ -70,9 +61,7 @@ func TestAccAzureRMDevTestPolicy_requiresImport(t *testing.T) { } func TestAccAzureRMDevTestPolicy_complete(t *testing.T) { - resourceName := "azurerm_dev_test_policy.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,18 +69,14 @@ func TestAccAzureRMDevTestPolicy_complete(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestPolicy_complete(rInt, location), + Config: testAccAzureRMDevTestPolicy_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Acceptance", "Test"), + testCheckAzureRMDevTestPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Acceptance", "Test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -155,7 +140,7 @@ func testCheckAzureRMDevTestPolicyDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDevTestPolicy_basic(rInt int, location string) string { +func testAccAzureRMDevTestPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -176,11 +161,11 @@ resource "azurerm_dev_test_policy" "test" { threshold = "999" evaluator_type = "MaxValuePolicy" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDevTestPolicy_requiresImport(rInt int, location string) string { - template := testAccAzureRMDevTestPolicy_basic(rInt, location) +func testAccAzureRMDevTestPolicy_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDevTestPolicy_basic(data) return fmt.Sprintf(` %s @@ -195,7 +180,7 @@ resource "azurerm_dev_test_policy" "import" { `, template) } -func testAccAzureRMDevTestPolicy_complete(rInt int, location string) string { +func testAccAzureRMDevTestPolicy_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -221,5 +206,5 @@ resource "azurerm_dev_test_policy" "test" { "Acceptance" = "Test" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_virtual_network_test.go similarity index 74% rename from azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network_test.go rename to azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_virtual_network_test.go index 2a43fdae1123..3df1386c58c9 100644 --- a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_virtual_network_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_virtual_network_test.go @@ -1,4 +1,4 @@ -package devtestlabs +package tests import ( "fmt" @@ -7,10 +7,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/devtestlabs" ) func TestValidateDevTestVirtualNetworkName(t *testing.T) { @@ -23,7 +23,7 @@ func TestValidateDevTestVirtualNetworkName(t *testing.T) { "double-hyphen--valid", } for _, v := range validNames { - _, errors := validateDevTestVirtualNetworkName()(v, "example") + _, errors := devtestlabs.ValidateDevTestVirtualNetworkName()(v, "example") if len(errors) != 0 { t.Fatalf("%q should be a valid Dev Test Virtual Network Name: %q", v, errors) } @@ -34,7 +34,7 @@ func TestValidateDevTestVirtualNetworkName(t *testing.T) { "!@£", } for _, v := range invalidNames { - _, errors := validateDevTestVirtualNetworkName()(v, "name") + _, errors := devtestlabs.ValidateDevTestVirtualNetworkName()(v, "name") if len(errors) == 0 { t.Fatalf("%q should be an invalid Dev Test Virtual Network Name", v) } @@ -42,9 +42,7 @@ func TestValidateDevTestVirtualNetworkName(t *testing.T) { } func TestAccAzureRMDevTestVirtualNetwork_basic(t *testing.T) { - resourceName := "azurerm_dev_test_virtual_network.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_virtual_network", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,17 +50,13 @@ func TestAccAzureRMDevTestVirtualNetwork_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestVirtualNetworkDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestVirtualNetwork_basic(rInt, location), + Config: testAccAzureRMDevTestVirtualNetwork_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestVirtualNetworkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestVirtualNetworkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -73,9 +67,7 @@ func TestAccAzureRMDevTestVirtualNetwork_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dev_test_virtual_network.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_virtual_network", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -83,14 +75,14 @@ func TestAccAzureRMDevTestVirtualNetwork_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestVirtualNetworkDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestVirtualNetwork_basic(rInt, location), + Config: testAccAzureRMDevTestVirtualNetwork_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestVirtualNetworkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestVirtualNetworkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, { - Config: testAccAzureRMDevTestVirtualNetwork_requiresImport(rInt, location), + Config: testAccAzureRMDevTestVirtualNetwork_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dev_test_virtual_network"), }, }, @@ -98,9 +90,7 @@ func TestAccAzureRMDevTestVirtualNetwork_requiresImport(t *testing.T) { } func TestAccAzureRMDevTestVirtualNetwork_subnet(t *testing.T) { - resourceName := "azurerm_dev_test_virtual_network.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_virtual_network", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -108,20 +98,16 @@ func TestAccAzureRMDevTestVirtualNetwork_subnet(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestVirtualNetworkDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestVirtualNetwork_subnets(rInt, location), + Config: testAccAzureRMDevTestVirtualNetwork_subnets(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestVirtualNetworkExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "subnet.#", "1"), - resource.TestCheckResourceAttr(resourceName, "subnet.0.use_public_ip_address", "Deny"), - resource.TestCheckResourceAttr(resourceName, "subnet.0.use_in_virtual_machine_creation", "Allow"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestVirtualNetworkExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.0.use_public_ip_address", "Deny"), + resource.TestCheckResourceAttr(data.ResourceName, "subnet.0.use_in_virtual_machine_creation", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -183,7 +169,7 @@ func testCheckAzureRMDevTestVirtualNetworkDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDevTestVirtualNetwork_basic(rInt int, location string) string { +func testAccAzureRMDevTestVirtualNetwork_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -201,11 +187,11 @@ resource "azurerm_dev_test_virtual_network" "test" { lab_name = "${azurerm_dev_test_lab.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDevTestVirtualNetwork_requiresImport(rInt int, location string) string { - template := testAccAzureRMDevTestVirtualNetwork_basic(rInt, location) +func testAccAzureRMDevTestVirtualNetwork_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDevTestVirtualNetwork_basic(data) return fmt.Sprintf(` %s @@ -217,7 +203,7 @@ resource "azurerm_dev_test_virtual_network" "import" { `, template) } -func testAccAzureRMDevTestVirtualNetwork_subnets(rInt int, location string) string { +func testAccAzureRMDevTestVirtualNetwork_subnets(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -240,5 +226,5 @@ resource "azurerm_dev_test_virtual_network" "test" { use_in_virtual_machine_creation = "Allow" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_windows_virtual_machine_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_windows_virtual_machine_test.go similarity index 70% rename from azurerm/internal/services/devtestlabs/resource_arm_dev_test_windows_virtual_machine_test.go rename to azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_windows_virtual_machine_test.go index c401a05b80e3..b9d157aaba4c 100644 --- a/azurerm/internal/services/devtestlabs/resource_arm_dev_test_windows_virtual_machine_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_windows_virtual_machine_test.go @@ -1,4 +1,4 @@ -package devtestlabs +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDevTestVirtualMachine_basic(t *testing.T) { - resourceName := "azurerm_dev_test_windows_virtual_machine.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_windows_virtual_machine", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,24 +21,19 @@ func TestAccAzureRMDevTestVirtualMachine_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestWindowsVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestWindowsVirtualMachine_basic(rInt, location), + Config: testAccAzureRMDevTestWindowsVirtualMachine_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestWindowsVirtualMachineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gallery_image_reference.0.publisher", "MicrosoftWindowsServer"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestWindowsVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "gallery_image_reference.0.publisher", "MicrosoftWindowsServer"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "lab_subnet_name", - "lab_virtual_network_id", - "password", - }, - }, + data.ImportStep( + // not returned from the API + "lab_subnet_name", + "lab_virtual_network_id", + "password", + ), }, }) } @@ -52,9 +44,7 @@ func TestAccAzureRMDevTestVirtualMachine_requiresImport(t *testing.T) { return } - resourceName := "azurerm_dev_test_windows_virtual_machine.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_windows_virtual_machine", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -62,13 +52,13 @@ func TestAccAzureRMDevTestVirtualMachine_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestWindowsVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestWindowsVirtualMachine_basic(rInt, location), + Config: testAccAzureRMDevTestWindowsVirtualMachine_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestWindowsVirtualMachineExists(resourceName), + testCheckAzureRMDevTestWindowsVirtualMachineExists(data.ResourceName), ), }, { - Config: testAccAzureRMDevTestWindowsVirtualMachine_requiresImport(rInt, location), + Config: testAccAzureRMDevTestWindowsVirtualMachine_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_dev_test_windows_virtual_machine"), }, }, @@ -76,9 +66,7 @@ func TestAccAzureRMDevTestVirtualMachine_requiresImport(t *testing.T) { } func TestAccAzureRMDevTestWindowsVirtualMachine_inboundNatRules(t *testing.T) { - resourceName := "azurerm_dev_test_windows_virtual_machine.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_windows_virtual_machine", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,35 +74,28 @@ func TestAccAzureRMDevTestWindowsVirtualMachine_inboundNatRules(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestWindowsVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestWindowsVirtualMachine_inboundNatRules(rInt, location), + Config: testAccAzureRMDevTestWindowsVirtualMachine_inboundNatRules(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestWindowsVirtualMachineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "disallow_public_ip_address", "true"), - resource.TestCheckResourceAttr(resourceName, "gallery_image_reference.0.publisher", "MicrosoftWindowsServer"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Acceptance", "Test"), + testCheckAzureRMDevTestWindowsVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "disallow_public_ip_address", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "gallery_image_reference.0.publisher", "MicrosoftWindowsServer"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Acceptance", "Test"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // not returned from the API - "inbound_nat_rule", - "lab_subnet_name", - "lab_virtual_network_id", - "password", - }, - }, + data.ImportStep( + // not returned from the API + "inbound_nat_rule", + "lab_subnet_name", + "lab_virtual_network_id", + "password", + ), }, }) } func TestAccAzureRMDevTestWindowsVirtualMachine_updateStorage(t *testing.T) { - resourceName := "azurerm_dev_test_windows_virtual_machine.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_dev_test_windows_virtual_machine", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -122,21 +103,21 @@ func TestAccAzureRMDevTestWindowsVirtualMachine_updateStorage(t *testing.T) { CheckDestroy: testCheckAzureRMDevTestWindowsVirtualMachineDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevTestWindowsVirtualMachine_storage(rInt, location, "Standard"), + Config: testAccAzureRMDevTestWindowsVirtualMachine_storage(data, "Standard"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestWindowsVirtualMachineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gallery_image_reference.0.publisher", "MicrosoftWindowsServer"), - resource.TestCheckResourceAttr(resourceName, "storage_type", "Standard"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestWindowsVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "gallery_image_reference.0.publisher", "MicrosoftWindowsServer"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_type", "Standard"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, { - Config: testAccAzureRMDevTestWindowsVirtualMachine_storage(rInt, location, "Premium"), + Config: testAccAzureRMDevTestWindowsVirtualMachine_storage(data, "Premium"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevTestWindowsVirtualMachineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "gallery_image_reference.0.publisher", "MicrosoftWindowsServer"), - resource.TestCheckResourceAttr(resourceName, "storage_type", "Premium"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevTestWindowsVirtualMachineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "gallery_image_reference.0.publisher", "MicrosoftWindowsServer"), + resource.TestCheckResourceAttr(data.ResourceName, "storage_type", "Premium"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -200,8 +181,8 @@ func testCheckAzureRMDevTestWindowsVirtualMachineDestroy(s *terraform.State) err return nil } -func testAccAzureRMDevTestWindowsVirtualMachine_basic(rInt int, location string) string { - template := testAccAzureRMDevTestWindowsVirtualMachine_template(rInt, location) +func testAccAzureRMDevTestWindowsVirtualMachine_basic(data acceptance.TestData) string { + template := testAccAzureRMDevTestWindowsVirtualMachine_template(data) return fmt.Sprintf(` %s @@ -224,11 +205,11 @@ resource "azurerm_dev_test_windows_virtual_machine" "test" { version = "latest" } } -`, template, rInt%1000000) +`, template, data.RandomInteger%1000000) } -func testAccAzureRMDevTestWindowsVirtualMachine_requiresImport(rInt int, location string) string { - template := testAccAzureRMDevTestWindowsVirtualMachine_basic(rInt, location) +func testAccAzureRMDevTestWindowsVirtualMachine_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDevTestWindowsVirtualMachine_basic(data) return fmt.Sprintf(` %s @@ -254,8 +235,8 @@ resource "azurerm_dev_test_windows_virtual_machine" "import" { `, template) } -func testAccAzureRMDevTestWindowsVirtualMachine_inboundNatRules(rInt int, location string) string { - template := testAccAzureRMDevTestWindowsVirtualMachine_template(rInt, location) +func testAccAzureRMDevTestWindowsVirtualMachine_inboundNatRules(data acceptance.TestData) string { + template := testAccAzureRMDevTestWindowsVirtualMachine_template(data) return fmt.Sprintf(` %s @@ -293,11 +274,11 @@ resource "azurerm_dev_test_windows_virtual_machine" "test" { "Acceptance" = "Test" } } -`, template, rInt%1000000) +`, template, data.RandomInteger%1000000) } -func testAccAzureRMDevTestWindowsVirtualMachine_storage(rInt int, location, storageType string) string { - template := testAccAzureRMDevTestWindowsVirtualMachine_template(rInt, location) +func testAccAzureRMDevTestWindowsVirtualMachine_storage(data acceptance.TestData, storageType string) string { + template := testAccAzureRMDevTestWindowsVirtualMachine_template(data) return fmt.Sprintf(` %s @@ -320,10 +301,10 @@ resource "azurerm_dev_test_windows_virtual_machine" "test" { version = "latest" } } -`, template, rInt%1000000, storageType) +`, template, data.RandomInteger%1000000, storageType) } -func testAccAzureRMDevTestWindowsVirtualMachine_template(rInt int, location string) string { +func testAccAzureRMDevTestWindowsVirtualMachine_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -346,5 +327,5 @@ resource "azurerm_dev_test_virtual_network" "test" { use_in_virtual_machine_creation = "Allow" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } From 5a7a6582195593437ccd63cb25bce916bfa967b9 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 20:43:05 +0100 Subject: [PATCH 146/203] frontdoor: fixing up the tests --- ...rce_arm_front_door_firewall_policy_test.go | 136 +++++++----------- .../resource_arm_front_door_test.go | 117 +++++---------- 2 files changed, 90 insertions(+), 163 deletions(-) rename azurerm/internal/services/frontdoor/{ => tests}/resource_arm_front_door_firewall_policy_test.go (62%) rename azurerm/internal/services/frontdoor/{ => tests}/resource_arm_front_door_test.go (79%) diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door_firewall_policy_test.go b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go similarity index 62% rename from azurerm/internal/services/frontdoor/resource_arm_front_door_firewall_policy_test.go rename to azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go index cabccf6bf82f..1bef28f9dd03 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door_firewall_policy_test.go +++ b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_firewall_policy_test.go @@ -1,4 +1,4 @@ -package frontdoor +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,28 +13,21 @@ import ( ) func TestAccAzureRMFrontDoorFirewallPolicy_basic(t *testing.T) { - resourceName := "azurerm_frontdoor_firewall_policy.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMFrontDoorFirewallPolicy_basic(ri, acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_frontdoor_firewall_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMFrontDoorFirewallPolicyDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFrontDoorFirewallPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorFirewallPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("testAccFrontDoorWAF%d", ri)), - resource.TestCheckResourceAttr(resourceName, "mode", "Prevention"), + testCheckAzureRMFrontDoorFirewallPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testAccFrontDoorWAF%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "mode", "Prevention"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,104 +38,83 @@ func TestAccAzureRMFrontDoorFirewallPolicy_requiresImport(t *testing.T) { return } - resourceName := "azurerm_frontdoor_firewall_policy.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_frontdoor_firewall_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMFrontDoorFirewallPolicyDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFrontDoorFirewallPolicy_basic(ri, location), + Config: testAccAzureRMFrontDoorFirewallPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorFirewallPolicyExists(resourceName), + testCheckAzureRMFrontDoorFirewallPolicyExists(data.ResourceName), ), }, - { - Config: testAccAzureRMFrontDoorFirewallPolicy_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_frontdoor_firewall_policy"), - }, + data.RequiresImportErrorStep(testAccAzureRMFrontDoorFirewallPolicy_requiresImport), }, }) } func TestAccAzureRMFrontDoorFirewallPolicy_update(t *testing.T) { - resourceName := "azurerm_frontdoor_firewall_policy.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMFrontDoorFirewallPolicy_update(ri, "", acceptance.Location()) - configUpdate := testAccAzureRMFrontDoorFirewallPolicy_update(ri, testAccAzureRMFrontDoorFirewallPolicy_updateTemplate(), acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_frontdoor_firewall_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMFrontDoorFirewallPolicyDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFrontDoorFirewallPolicy_update(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorFirewallPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("testAccFrontDoorWAF%d", ri)), - resource.TestCheckResourceAttr(resourceName, "mode", "Prevention"), + testCheckAzureRMFrontDoorFirewallPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testAccFrontDoorWAF%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "mode", "Prevention"), ), }, { - Config: configUpdate, + Config: testAccAzureRMFrontDoorFirewallPolicy_update(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorFirewallPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("testAccFrontDoorWAF%d", ri)), - resource.TestCheckResourceAttr(resourceName, "mode", "Prevention"), - resource.TestCheckResourceAttr(resourceName, "custom_rule.1.name", "Rule2"), + testCheckAzureRMFrontDoorFirewallPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testAccFrontDoorWAF%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "mode", "Prevention"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rule.1.name", "Rule2"), ), }, { - Config: config, + Config: testAccAzureRMFrontDoorFirewallPolicy_update(data, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorFirewallPolicyExists(resourceName), - testCheckAzureRMFrontDoorFirewallPolicyAttrNotExists(resourceName, "custom_rule.1.name"), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("testAccFrontDoorWAF%d", ri)), - resource.TestCheckResourceAttr(resourceName, "mode", "Prevention"), + testCheckAzureRMFrontDoorFirewallPolicyExists(data.ResourceName), + testCheckAzureRMFrontDoorFirewallPolicyAttrNotExists(data.ResourceName, "custom_rule.1.name"), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testAccFrontDoorWAF%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "mode", "Prevention"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFrontDoorFirewallPolicy_complete(t *testing.T) { - resourceName := "azurerm_frontdoor_firewall_policy.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMFrontDoorFirewallPolicy_update(ri, testAccAzureRMFrontDoorFirewallPolicy_updateTemplate(), acceptance.Location()) - + data := acceptance.BuildTestData(t, "azurerm_frontdoor_firewall_policy", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMFrontDoorFirewallPolicyDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFrontDoorFirewallPolicy_update(data, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorFirewallPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("testAccFrontDoorWAF%d", ri)), - resource.TestCheckResourceAttr(resourceName, "mode", "Prevention"), - resource.TestCheckResourceAttr(resourceName, "redirect_url", "https://www.contoso.com"), - resource.TestCheckResourceAttr(resourceName, "custom_block_response_status_code", "403"), - resource.TestCheckResourceAttr(resourceName, "custom_rule.0.name", "Rule1"), - resource.TestCheckResourceAttr(resourceName, "custom_rule.1.name", "Rule2"), - resource.TestCheckResourceAttr(resourceName, "managed_rule.0.type", "DefaultRuleSet"), - resource.TestCheckResourceAttr(resourceName, "managed_rule.1.type", "BotProtection"), + testCheckAzureRMFrontDoorFirewallPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("testAccFrontDoorWAF%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "mode", "Prevention"), + resource.TestCheckResourceAttr(data.ResourceName, "redirect_url", "https://www.contoso.com"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_block_response_status_code", "403"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rule.0.name", "Rule1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_rule.1.name", "Rule2"), + resource.TestCheckResourceAttr(data.ResourceName, "managed_rule.0.type", "DefaultRuleSet"), + resource.TestCheckResourceAttr(data.ResourceName, "managed_rule.1.type", "BotProtection"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -211,22 +182,22 @@ func testCheckAzureRMFrontDoorFirewallPolicyAttrNotExists(name string, attribute } } -func testAccAzureRMFrontDoorFirewallPolicy_basic(rInt int, location string) string { +func testAccAzureRMFrontDoorFirewallPolicy_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "testAccRG-%[1]d" - location = "%[2]s" + name = "testAccRG-%d" + location = "%s" } resource "azurerm_frontdoor_firewall_policy" "test" { name = "testAccFrontDoorWAF%[1]d" resource_group_name = azurerm_resource_group.test.name } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMFrontDoorFirewallPolicy_requiresImport(rInt int, location string) string { - template := testAccAzureRMFrontDoorFirewallPolicy_basic(rInt, location) +func testAccAzureRMFrontDoorFirewallPolicy_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMFrontDoorFirewallPolicy_basic(data) return fmt.Sprintf(` %s @@ -237,8 +208,10 @@ resource "azurerm_frontdoor_firewall_policy" "import" { `, template) } -func testAccAzureRMFrontDoorFirewallPolicy_updateTemplate() string { - return fmt.Sprintf(` +func testAccAzureRMFrontDoorFirewallPolicy_update(data acceptance.TestData, update bool) string { + inner := "" + if update { + inner = fmt.Sprintf(` custom_rule { name = "Rule2" enabled = true @@ -265,13 +238,12 @@ custom_rule { } } `) -} + } -func testAccAzureRMFrontDoorFirewallPolicy_update(rInt int, sTemplate string, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "testAccRG-%[1]d" - location = "%[3]s" + name = "testAccRG-%d" + location = "%s" } resource "azurerm_frontdoor_firewall_policy" "test" { @@ -300,7 +272,7 @@ resource "azurerm_frontdoor_firewall_policy" "test" { } } - %[2]s + %s managed_rule { type = "DefaultRuleSet" @@ -322,5 +294,5 @@ resource "azurerm_frontdoor_firewall_policy" "test" { version = "preview-0.1" } } -`, rInt, sTemplate, location) +`, data.RandomInteger, data.Locations.Primary, inner) } diff --git a/azurerm/internal/services/frontdoor/resource_arm_front_door_test.go b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go similarity index 79% rename from azurerm/internal/services/frontdoor/resource_arm_front_door_test.go rename to azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go index 0e6f096cd737..a197a9acad7f 100644 --- a/azurerm/internal/services/frontdoor/resource_arm_front_door_test.go +++ b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go @@ -1,4 +1,4 @@ -package frontdoor +package tests import ( "fmt" @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,26 +13,19 @@ import ( ) func TestAccAzureRMFrontDoor_basic(t *testing.T) { - resourceName := "azurerm_frontdoor.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_frontdoor", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMFrontDoorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFrontDoor_basic(ri, location), + Config: testAccAzureRMFrontDoor_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorExists(resourceName), + testCheckAzureRMFrontDoorExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,124 +36,87 @@ func TestAccAzureRMFrontDoor_requiresImport(t *testing.T) { return } - resourceName := "azurerm_frontdoor.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_frontdoor", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMFrontDoorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFrontDoor_basic(ri, location), + Config: testAccAzureRMFrontDoor_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorExists(resourceName), + testCheckAzureRMFrontDoorExists(data.ResourceName), ), }, - { - Config: testAccAzureRMFrontDoor_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_frontdoor"), - }, + data.RequiresImportErrorStep(testAccAzureRMFrontDoor_requiresImport), }, }) } func TestAccAzureRMFrontDoor_update(t *testing.T) { - resourceName := "azurerm_frontdoor.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_frontdoor", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMFrontDoorDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMFrontDoor_basic(ri, location), + Config: testAccAzureRMFrontDoor_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorExists(resourceName), + testCheckAzureRMFrontDoorExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMFrontDoor_complete(ri, location), + Config: testAccAzureRMFrontDoor_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorExists(resourceName), + testCheckAzureRMFrontDoorExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMFrontDoor_basic(ri, location), + Config: testAccAzureRMFrontDoor_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorExists(resourceName), + testCheckAzureRMFrontDoorExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFrontDoor_complete(t *testing.T) { - resourceName := "azurerm_frontdoor.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMFrontDoor_complete(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_frontdoor", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMFrontDoorDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFrontDoor_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorExists(resourceName), + testCheckAzureRMFrontDoorExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMFrontDoor_waf(t *testing.T) { - resourceName := "azurerm_frontdoor.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMFrontDoor_waf(ri, location) - + data := acceptance.BuildTestData(t, "azurerm_frontdoor", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMFrontDoorDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMFrontDoor_waf(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMFrontDoorExists(resourceName), + testCheckAzureRMFrontDoorExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -214,7 +169,7 @@ func testCheckAzureRMFrontDoorDestroy(s *terraform.State) error { return nil } -func testAccAzureRMFrontDoor_basic(rInt int, location string) string { +func testAccAzureRMFrontDoor_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -272,11 +227,11 @@ resource "azurerm_frontdoor" "test" { custom_https_provisioning_enabled = false } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFrontDoor_requiresImport(rInt int, location string) string { - template := testAccAzureRMFrontDoor_basic(rInt, location) +func testAccAzureRMFrontDoor_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMFrontDoor_basic(data) return fmt.Sprintf(` %s @@ -324,10 +279,10 @@ resource "azurerm_frontdoor" "import" { custom_https_provisioning_enabled = false } } -`, template, rInt) +`, template, data.RandomInteger) } -func testAccAzureRMFrontDoor_complete(rInt int, location string) string { +func testAccAzureRMFrontDoor_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -385,10 +340,10 @@ resource "azurerm_frontdoor" "test" { custom_https_provisioning_enabled = false } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMFrontDoor_waf(rInt int, location string) string { +func testAccAzureRMFrontDoor_waf(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -453,5 +408,5 @@ resource "azurerm_frontdoor" "test" { web_application_firewall_policy_link_id = azurerm_frontdoor_firewall_policy.test.id } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } From 1e5e1bff8193c4199b726daf1d6c9478dcf85f80 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 21 Dec 2019 20:56:22 +0100 Subject: [PATCH 147/203] acceptance: fixing compiler errors --- .../data_source_automation_account_test.go | 4 +- ...ta_source_automation_variable_bool_test.go | 5 +- ...ource_automation_variable_datetime_test.go | 5 +- ...ata_source_automation_variable_int_test.go | 5 +- ..._source_automation_variable_string_test.go | 5 +- ...e_arm_automation_dsc_configuration_test.go | 47 +++++++------------ 6 files changed, 27 insertions(+), 44 deletions(-) diff --git a/azurerm/internal/services/automation/tests/data_source_automation_account_test.go b/azurerm/internal/services/automation/tests/data_source_automation_account_test.go index 7d9654a337b3..ff9cb0ed4ded 100644 --- a/azurerm/internal/services/automation/tests/data_source_automation_account_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_account_test.go @@ -26,7 +26,7 @@ func TestAccDataSourceAutomationAccount(t *testing.T) { }) } -func testAccDataSourceAutomationAccount_complete(resourceGroupName string, location string, ri int) string { +func testAccDataSourceAutomationAccount_complete(resourceGroupName string, data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "%s" @@ -42,5 +42,5 @@ data "azurerm_automation_account" "test" { resource_group_name = "${azurerm_resource_group.test.name}" name = "${azurerm_automation_account.test.name}" } -`, resourceGroupName, location, ri) +`, resourceGroupName, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go index 21129d5bfb9d..a8ea6810cd82 100644 --- a/azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_bool_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) @@ -26,8 +25,8 @@ func TestAccDataSourceAzureRMAutomationVariableBool_basic(t *testing.T) { }) } -func testAccDataSourceAutomationVariableBool_basic(rInt int, location string) string { - config := testAccAzureRMAutomationVariableBool_basic(rInt, location) +func testAccDataSourceAutomationVariableBool_basic(data acceptance.TestData) string { + config := testAccAzureRMAutomationVariableBool_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go index 983c71a39d1a..34ba86460c1e 100644 --- a/azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_datetime_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) @@ -26,8 +25,8 @@ func TestAccDataSourceAzureRMAutomationVariableDateTime_basic(t *testing.T) { }) } -func testAccDataSourceAutomationVariableDateTime_basic(rInt int, location string) string { - config := testAccAzureRMAutomationVariableDateTime_basic(rInt, location) +func testAccDataSourceAutomationVariableDateTime_basic(data acceptance.TestData) string { + config := testAccAzureRMAutomationVariableDateTime_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go index 20abed0d6197..8a982d34dfb0 100644 --- a/azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_int_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) @@ -26,8 +25,8 @@ func TestAccDataSourceAzureRMAutomationVariableInt_basic(t *testing.T) { }) } -func testAccDataSourceAutomationVariableInt_basic(rInt int, location string) string { - config := testAccAzureRMAutomationVariableInt_basic(rInt, location) +func testAccDataSourceAutomationVariableInt_basic(data acceptance.TestData) string { + config := testAccAzureRMAutomationVariableInt_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go b/azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go index fd3df40904ea..995bcd8d32de 100644 --- a/azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go +++ b/azurerm/internal/services/automation/tests/data_source_automation_variable_string_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) @@ -26,8 +25,8 @@ func TestAccDataSourceAzureRMAutomationVariableString_basic(t *testing.T) { }) } -func testAccDataSourceAutomationVariableString_basic(rInt int, location string) string { - config := testAccAzureRMAutomationVariableString_basic(rInt, location) +func testAccDataSourceAutomationVariableString_basic(data acceptance.TestData) string { + config := testAccAzureRMAutomationVariableString_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go index 589c2701117f..ed4cef5d5561 100644 --- a/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_dsc_configuration_test.go @@ -6,7 +6,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -14,30 +13,24 @@ import ( ) func TestAccAzureRMAutomationDscConfiguration_basic(t *testing.T) { - resourceName := "azurerm_automation_dsc_configuration.test" - ri := tf.AccRandTimeInt() - + data := acceptance.BuildTestData(t, "azurerm_automation_dsc_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAutomationDscConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationDscConfiguration_basic(ri, acceptance.Location()), + Config: testAccAzureRMAutomationDscConfiguration_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationDscConfigurationExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "location"), - resource.TestCheckResourceAttr(resourceName, "description", "test"), - resource.TestCheckResourceAttrSet(resourceName, "log_verbose"), - resource.TestCheckResourceAttrSet(resourceName, "state"), - resource.TestCheckResourceAttr(resourceName, "content_embedded", "configuration acctest {}"), + testCheckAzureRMAutomationDscConfigurationExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test"), + resource.TestCheckResourceAttrSet(data.ResourceName, "log_verbose"), + resource.TestCheckResourceAttrSet(data.ResourceName, "state"), + resource.TestCheckResourceAttr(data.ResourceName, "content_embedded", "configuration acctest {}"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -48,25 +41,19 @@ func TestAccAzureRMAutomationDscConfiguration_requiresImport(t *testing.T) { return } - resourceName := "azurerm_automation_dsc_configuration.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - + data := acceptance.BuildTestData(t, "azurerm_automation_dsc_configuration", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, CheckDestroy: testCheckAzureRMAutomationDscConfigurationDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMAutomationDscConfiguration_basic(ri, location), + Config: testAccAzureRMAutomationDscConfiguration_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMAutomationDscConfigurationExists(resourceName), + testCheckAzureRMAutomationDscConfigurationExists(data.ResourceName), ), }, - { - Config: testAccAzureRMAutomationDscConfiguration_requiresImport(ri, location), - ExpectError: acceptance.RequiresImportError("azurerm_automation_dsc_configuration"), - }, + data.RequiresImportErrorStep(testAccAzureRMAutomationDscConfiguration_requiresImport), }, }) } @@ -137,7 +124,7 @@ func testCheckAzureRMAutomationDscConfigurationExists(resourceName string) resou } } -func testAccAzureRMAutomationDscConfiguration_basic(rInt int, location string) string { +func testAccAzureRMAutomationDscConfiguration_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -162,11 +149,11 @@ resource "azurerm_automation_dsc_configuration" "test" { content_embedded = "configuration acctest {}" description = "test" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMAutomationDscConfiguration_requiresImport(rInt int, location string) string { - template := testAccAzureRMAutomationDscConfiguration_basic(rInt, location) +func testAccAzureRMAutomationDscConfiguration_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMAutomationDscConfiguration_basic(data) return fmt.Sprintf(` %s From 74f2e9ada5b2f3c7c16a05b19cb124fdfc117c8d Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 12:02:43 -0800 Subject: [PATCH 148/203] devspace: switching to the new test structure --- .../resource_arm_devspace_controller_test.go | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) rename azurerm/internal/services/devspace/{ => tests}/resource_arm_devspace_controller_test.go (82%) diff --git a/azurerm/internal/services/devspace/resource_arm_devspace_controller_test.go b/azurerm/internal/services/devspace/tests/resource_arm_devspace_controller_test.go similarity index 82% rename from azurerm/internal/services/devspace/resource_arm_devspace_controller_test.go rename to azurerm/internal/services/devspace/tests/resource_arm_devspace_controller_test.go index b10fdc6687b6..23d26e13a42f 100644 --- a/azurerm/internal/services/devspace/resource_arm_devspace_controller_test.go +++ b/azurerm/internal/services/devspace/tests/resource_arm_devspace_controller_test.go @@ -1,4 +1,4 @@ -package devspace +package tests import ( "fmt" @@ -9,16 +9,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDevSpaceController_basic(t *testing.T) { - resourceName := "azurerm_devspace_controller.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_devspace_controller", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") @@ -28,11 +25,11 @@ func TestAccAzureRMDevSpaceController_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDevSpaceControllerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevSpaceController_basic(rInt, location, clientId, clientSecret), + Config: testAccAzureRMDevSpaceController_basic(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevSpaceControllerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku.#", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), + testCheckAzureRMDevSpaceControllerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), ), }, }, @@ -45,9 +42,7 @@ func TestAccAzureRMDevSpaceController_requiresImport(t *testing.T) { return } - resourceName := "azurerm_devspace_controller.test" - rInt := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_devspace_controller", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") @@ -57,13 +52,13 @@ func TestAccAzureRMDevSpaceController_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDevSpaceControllerDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDevSpaceController_basic(rInt, location, clientId, clientSecret), + Config: testAccAzureRMDevSpaceController_basic(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDevSpaceControllerExists(resourceName), + testCheckAzureRMDevSpaceControllerExists(data.ResourceName), ), }, { - Config: testAccAzureRMDevSpaceController_requiresImport(rInt, location, clientId, clientSecret), + Config: testAccAzureRMDevSpaceController_requiresImport(data, clientId, clientSecret), ExpectError: acceptance.RequiresImportError("azurerm_devspace_controller"), }, }, @@ -128,7 +123,7 @@ func testCheckAzureRMDevSpaceControllerDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDevSpaceController_basic(rInt int, location string, clientId string, clientSecret string) string { +func testAccAzureRMDevSpaceController_basic(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -173,11 +168,11 @@ resource "azurerm_devspace_controller" "test" { tier = "Standard" } } -`, rInt, location, rInt, clientId, clientSecret, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, clientId, clientSecret, data.RandomInteger) } -func testAccAzureRMDevSpaceController_requiresImport(rInt int, location string, clientId string, clientSecret string) string { - template := testAccAzureRMDevSpaceController_basic(rInt, location, clientId, clientSecret) +func testAccAzureRMDevSpaceController_requiresImport(data acceptance.TestData, clientId string, clientSecret string) string { + template := testAccAzureRMDevSpaceController_basic(data, clientId, clientSecret) return fmt.Sprintf(` %s From 69ca31cf0315b9d24eb41b527048291e325f47e4 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 12:15:05 -0800 Subject: [PATCH 149/203] datalake: switching to the new test structure --- .../resource_arm_data_lake_store_file.go | 6 +- ...urce_arm_data_lake_store_file_migration.go | 2 +- .../data_source_data_lake_store_test.go | 36 ++--- ...ce_arm_data_lake_analytics_account_test.go | 92 +++++------ ..._data_lake_analytics_firewall_rule_test.go | 78 ++++----- ...arm_data_lake_store_file_migration_test.go | 5 +- .../resource_arm_data_lake_store_file_test.go | 68 +++----- ..._arm_data_lake_store_firewall_rule_test.go | 74 ++++----- .../resource_arm_data_lake_store_test.go | 149 ++++++++---------- 9 files changed, 206 insertions(+), 304 deletions(-) rename azurerm/internal/services/datalake/{ => tests}/data_source_data_lake_store_test.go (60%) rename azurerm/internal/services/datalake/{ => tests}/resource_arm_data_lake_analytics_account_test.go (69%) rename azurerm/internal/services/datalake/{ => tests}/resource_arm_data_lake_analytics_firewall_rule_test.go (68%) rename azurerm/internal/services/datalake/{ => tests}/resource_arm_data_lake_store_file_migration_test.go (90%) rename azurerm/internal/services/datalake/{ => tests}/resource_arm_data_lake_store_file_test.go (75%) rename azurerm/internal/services/datalake/{ => tests}/resource_arm_data_lake_store_firewall_rule_test.go (68%) rename azurerm/internal/services/datalake/{ => tests}/resource_arm_data_lake_store_test.go (60%) diff --git a/azurerm/internal/services/datalake/resource_arm_data_lake_store_file.go b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file.go index a484037b5f8c..49384023b087 100644 --- a/azurerm/internal/services/datalake/resource_arm_data_lake_store_file.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file.go @@ -26,7 +26,7 @@ func resourceArmDataLakeStoreFile() *schema.Resource { Create: resourceArmDataLakeStoreFileCreate, Read: resourceArmDataLakeStoreFileRead, Delete: resourceArmDataLakeStoreFileDelete, - MigrateState: resourceDataLakeStoreFileMigrateState, + MigrateState: ResourceDataLakeStoreFileMigrateState, SchemaVersion: 1, Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, @@ -50,7 +50,7 @@ func resourceArmDataLakeStoreFile() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateDataLakeStoreRemoteFilePath(), + ValidateFunc: ValidateDataLakeStoreRemoteFilePath(), }, "local_file_path": { @@ -198,7 +198,7 @@ func parseDataLakeStoreFileId(input string, suffix string) (*dataLakeStoreFileId return &file, nil } -func validateDataLakeStoreRemoteFilePath() schema.SchemaValidateFunc { +func ValidateDataLakeStoreRemoteFilePath() schema.SchemaValidateFunc { return func(v interface{}, k string) (warnings []string, errors []error) { val := v.(string) diff --git a/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration.go b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration.go index 465fa2c19211..8f6afdf025da 100644 --- a/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration.go +++ b/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration.go @@ -8,7 +8,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) -func resourceDataLakeStoreFileMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { +func ResourceDataLakeStoreFileMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { switch v { case 0: log.Println("[INFO] Found AzureRM Data Lake Store File State v0; migrating to v1") diff --git a/azurerm/internal/services/datalake/data_source_data_lake_store_test.go b/azurerm/internal/services/datalake/tests/data_source_data_lake_store_test.go similarity index 60% rename from azurerm/internal/services/datalake/data_source_data_lake_store_test.go rename to azurerm/internal/services/datalake/tests/data_source_data_lake_store_test.go index c97394500fac..681955502b3e 100644 --- a/azurerm/internal/services/datalake/data_source_data_lake_store_test.go +++ b/azurerm/internal/services/datalake/tests/data_source_data_lake_store_test.go @@ -1,30 +1,25 @@ -package datalake +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMDataLakeStore_basic(t *testing.T) { - dataSourceName := "data.azurerm_data_lake_store.test" - rInt := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_data_lake_store", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceDataLakeStore_basic(rInt, rs, location), + Config: testAccDataSourceDataLakeStore_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "tier", "Consumption"), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "Consumption"), ), }, }, @@ -32,28 +27,25 @@ func TestAccDataSourceAzureRMDataLakeStore_basic(t *testing.T) { } func TestAccDataSourceAzureRMDataLakeStore_tier(t *testing.T) { - dataSourceName := "data.azurerm_data_lake_store.test" - rInt := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_data_lake_store", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceDataLakeStore_tier(rInt, rs, location), + Config: testAccDataSourceDataLakeStore_tier(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "tier", "Commitment_1TB"), - resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.hello", "world"), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "Commitment_1TB"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.hello", "world"), ), }, }, }) } -func testAccDataSourceDataLakeStore_basic(rInt int, rs string, location string) string { +func testAccDataSourceDataLakeStore_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -70,10 +62,10 @@ data "azurerm_data_lake_store" "test" { name = "${azurerm_data_lake_store.test.name}" resource_group_name = "${azurerm_data_lake_store.test.resource_group_name}" } -`, rInt, location, rs, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.Locations.Primary) } -func testAccDataSourceDataLakeStore_tier(rInt int, rs string, location string) string { +func testAccDataSourceDataLakeStore_tier(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -95,5 +87,5 @@ data "azurerm_data_lake_store" "test" { name = "${azurerm_data_lake_store.test.name}" resource_group_name = "${azurerm_data_lake_store.test.resource_group_name}" } -`, rInt, location, rs, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.Locations.Primary) } diff --git a/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_account_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go similarity index 69% rename from azurerm/internal/services/datalake/resource_arm_data_lake_analytics_account_test.go rename to azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go index 1c930a25de0e..fa29a489e599 100644 --- a/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_account_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go @@ -1,4 +1,4 @@ -package datalake +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDataLakeAnalyticsAccount_basic(t *testing.T) { - resourceName := "azurerm_data_lake_analytics_account.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_analytics_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,17 +22,13 @@ func TestAccAzureRMDataLakeAnalyticsAccount_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeAnalyticsAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeAnalyticsAccount_basic(ri, acceptance.Location()), + Config: testAccAzureRMDataLakeAnalyticsAccount_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeAnalyticsAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tier", "Consumption"), + testCheckAzureRMDataLakeAnalyticsAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "Consumption"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -45,9 +39,7 @@ func TestAccAzureRMDataLakeAnalyticsAccount_requiresImport(t *testing.T) { return } - resourceName := "azurerm_data_lake_analytics_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_data_lake_analytics_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,13 +47,13 @@ func TestAccAzureRMDataLakeAnalyticsAccount_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeAnalyticsAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeAnalyticsAccount_basic(ri, location), + Config: testAccAzureRMDataLakeAnalyticsAccount_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeAnalyticsAccountExists(resourceName), + testCheckAzureRMDataLakeAnalyticsAccountExists(data.ResourceName), ), }, { - Config: testAccAzureRMDataLakeAnalyticsAccount_requiresImport(ri, location), + Config: testAccAzureRMDataLakeAnalyticsAccount_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_data_lake_analytics_account"), }, }, @@ -69,8 +61,7 @@ func TestAccAzureRMDataLakeAnalyticsAccount_requiresImport(t *testing.T) { } func TestAccAzureRMDataLakeAnalyticsAccount_tier(t *testing.T) { - resourceName := "azurerm_data_lake_analytics_account.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_analytics_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,24 +69,19 @@ func TestAccAzureRMDataLakeAnalyticsAccount_tier(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeAnalyticsAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeAnalyticsAccount_tier(ri, acceptance.Location()), + Config: testAccAzureRMDataLakeAnalyticsAccount_tier(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeAnalyticsAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tier", "Commitment_100AUHours"), + testCheckAzureRMDataLakeAnalyticsAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "Commitment_100AUHours"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataLakeAnalyticsAccount_withTags(t *testing.T) { - resourceName := "azurerm_data_lake_analytics_account.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_analytics_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -103,24 +89,20 @@ func TestAccAzureRMDataLakeAnalyticsAccount_withTags(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeAnalyticsAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeAnalyticsAccount_withTags(ri, acceptance.Location()), + Config: testAccAzureRMDataLakeAnalyticsAccount_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeAnalyticsAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDataLakeAnalyticsAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { - Config: testAccAzureRMDataLakeAnalyticsAccount_withTagsUpdate(ri, acceptance.Location()), + Config: testAccAzureRMDataLakeAnalyticsAccount_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeAnalyticsAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDataLakeAnalyticsAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -182,8 +164,8 @@ func testCheckAzureRMDataLakeAnalyticsAccountDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDataLakeAnalyticsAccount_basic(rInt int, location string) string { - template := testAccAzureRMDataLakeStore_basic(rInt, location) +func testAccAzureRMDataLakeAnalyticsAccount_basic(data acceptance.TestData) string { + template := testAccAzureRMDataLakeStore_basic(data) return fmt.Sprintf(` %s @@ -194,11 +176,11 @@ resource "azurerm_data_lake_analytics_account" "test" { default_store_account_name = "${azurerm_data_lake_store.test.name}" } -`, template, strconv.Itoa(rInt)[2:17]) +`, template, strconv.Itoa(data.RandomInteger)[2:17]) } -func testAccAzureRMDataLakeAnalyticsAccount_requiresImport(rInt int, location string) string { - template := testAccAzureRMDataLakeAnalyticsAccount_basic(rInt, location) +func testAccAzureRMDataLakeAnalyticsAccount_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDataLakeAnalyticsAccount_basic(data) return fmt.Sprintf(` %s @@ -211,8 +193,8 @@ resource "azurerm_data_lake_analytics_account" "import" { `, template) } -func testAccAzureRMDataLakeAnalyticsAccount_tier(rInt int, location string) string { - template := testAccAzureRMDataLakeStore_basic(rInt, location) +func testAccAzureRMDataLakeAnalyticsAccount_tier(data acceptance.TestData) string { + template := testAccAzureRMDataLakeStore_basic(data) return fmt.Sprintf(` %s @@ -225,11 +207,11 @@ resource "azurerm_data_lake_analytics_account" "test" { default_store_account_name = "${azurerm_data_lake_store.test.name}" } -`, template, strconv.Itoa(rInt)[2:17]) +`, template, strconv.Itoa(data.RandomInteger)[2:17]) } -func testAccAzureRMDataLakeAnalyticsAccount_withTags(rInt int, location string) string { - template := testAccAzureRMDataLakeStore_basic(rInt, location) +func testAccAzureRMDataLakeAnalyticsAccount_withTags(data acceptance.TestData) string { + template := testAccAzureRMDataLakeStore_basic(data) return fmt.Sprintf(` %s @@ -245,11 +227,11 @@ resource "azurerm_data_lake_analytics_account" "test" { cost_center = "MSFT" } } -`, template, strconv.Itoa(rInt)[2:17]) +`, template, strconv.Itoa(data.RandomInteger)[2:17]) } -func testAccAzureRMDataLakeAnalyticsAccount_withTagsUpdate(rInt int, location string) string { - template := testAccAzureRMDataLakeStore_basic(rInt, location) +func testAccAzureRMDataLakeAnalyticsAccount_withTagsUpdate(data acceptance.TestData) string { + template := testAccAzureRMDataLakeStore_basic(data) return fmt.Sprintf(` %s @@ -264,5 +246,5 @@ resource "azurerm_data_lake_analytics_account" "test" { environment = "staging" } } -`, template, strconv.Itoa(rInt)[2:17]) +`, template, strconv.Itoa(data.RandomInteger)[2:17]) } diff --git a/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_firewall_rule_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_firewall_rule_test.go similarity index 68% rename from azurerm/internal/services/datalake/resource_arm_data_lake_analytics_firewall_rule_test.go rename to azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_firewall_rule_test.go index d20e7b8bf4a4..f59b6183c00e 100644 --- a/azurerm/internal/services/datalake/resource_arm_data_lake_analytics_firewall_rule_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_firewall_rule_test.go @@ -1,4 +1,4 @@ -package datalake +package tests import ( "fmt" @@ -9,15 +9,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDataLakeAnalyticsFirewallRule_basic(t *testing.T) { - resourceName := "azurerm_data_lake_analytics_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_analytics_firewall_rule", "test") startIP := "1.1.1.1" endIP := "2.2.2.2" @@ -27,18 +25,14 @@ func TestAccAzureRMDataLakeAnalyticsFirewallRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeAnalyticsFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeAnalyticsFirewallRule_basic(ri, acceptance.Location(), startIP, endIP), + Config: testAccAzureRMDataLakeAnalyticsFirewallRule_basic(data, startIP, endIP), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeAnalyticsFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", startIP), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", endIP), + testCheckAzureRMDataLakeAnalyticsFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", startIP), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", endIP), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -49,9 +43,7 @@ func TestAccAzureRMDataLakeAnalyticsFirewallRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_data_lake_analytics_firewall_rule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_data_lake_analytics_firewall_rule", "test") startIP := "1.1.1.1" endIP := "2.2.2.2" @@ -61,15 +53,15 @@ func TestAccAzureRMDataLakeAnalyticsFirewallRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeAnalyticsFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeAnalyticsFirewallRule_basic(ri, location, startIP, endIP), + Config: testAccAzureRMDataLakeAnalyticsFirewallRule_basic(data, startIP, endIP), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeAnalyticsFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", startIP), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", endIP), + testCheckAzureRMDataLakeAnalyticsFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", startIP), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", endIP), ), }, { - Config: testAccAzureRMDataLakeAnalyticsFirewallRule_requiresImport(ri, location, startIP, endIP), + Config: testAccAzureRMDataLakeAnalyticsFirewallRule_requiresImport(data, startIP, endIP), ExpectError: acceptance.RequiresImportError("azurerm_data_lake_analytics_firewall_rule"), }, }, @@ -77,8 +69,7 @@ func TestAccAzureRMDataLakeAnalyticsFirewallRule_requiresImport(t *testing.T) { } func TestAccAzureRMDataLakeAnalyticsFirewallRule_update(t *testing.T) { - resourceName := "azurerm_data_lake_analytics_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_analytics_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,19 +77,19 @@ func TestAccAzureRMDataLakeAnalyticsFirewallRule_update(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeAnalyticsFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeAnalyticsFirewallRule_basic(ri, acceptance.Location(), "1.1.1.1", "2.2.2.2"), + Config: testAccAzureRMDataLakeAnalyticsFirewallRule_basic(data, "1.1.1.1", "2.2.2.2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeAnalyticsFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", "1.1.1.1"), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", "2.2.2.2"), + testCheckAzureRMDataLakeAnalyticsFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", "1.1.1.1"), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", "2.2.2.2"), ), }, { - Config: testAccAzureRMDataLakeAnalyticsFirewallRule_basic(ri, acceptance.Location(), "2.2.2.2", "3.3.3.3"), + Config: testAccAzureRMDataLakeAnalyticsFirewallRule_basic(data, "2.2.2.2", "3.3.3.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeAnalyticsFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", "2.2.2.2"), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", "3.3.3.3"), + testCheckAzureRMDataLakeAnalyticsFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", "2.2.2.2"), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", "3.3.3.3"), ), }, }, @@ -106,8 +97,7 @@ func TestAccAzureRMDataLakeAnalyticsFirewallRule_update(t *testing.T) { } func TestAccAzureRMDataLakeAnalyticsFirewallRule_azureServices(t *testing.T) { - resourceName := "azurerm_data_lake_analytics_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_analytics_firewall_rule", "test") azureServicesIP := "0.0.0.0" resource.ParallelTest(t, resource.TestCase{ @@ -116,18 +106,14 @@ func TestAccAzureRMDataLakeAnalyticsFirewallRule_azureServices(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeAnalyticsFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeAnalyticsFirewallRule_basic(ri, acceptance.Location(), azureServicesIP, azureServicesIP), + Config: testAccAzureRMDataLakeAnalyticsFirewallRule_basic(data, azureServicesIP, azureServicesIP), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeAnalyticsFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", azureServicesIP), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", azureServicesIP), + testCheckAzureRMDataLakeAnalyticsFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", azureServicesIP), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", azureServicesIP), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -191,7 +177,7 @@ func testCheckAzureRMDataLakeAnalyticsFirewallRuleDestroy(s *terraform.State) er return nil } -func testAccAzureRMDataLakeAnalyticsFirewallRule_basic(rInt int, location, startIP, endIP string) string { +func testAccAzureRMDataLakeAnalyticsFirewallRule_basic(data acceptance.TestData, startIP, endIP string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%[1]d" @@ -219,11 +205,11 @@ resource "azurerm_data_lake_analytics_firewall_rule" "test" { start_ip_address = "%[4]s" end_ip_address = "%[5]s" } -`, rInt, location, strconv.Itoa(rInt)[10:17], startIP, endIP) +`, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[10:17], startIP, endIP) } -func testAccAzureRMDataLakeAnalyticsFirewallRule_requiresImport(rInt int, location, startIP, endIP string) string { - template := testAccAzureRMDataLakeAnalyticsFirewallRule_basic(rInt, location, startIP, endIP) +func testAccAzureRMDataLakeAnalyticsFirewallRule_requiresImport(data acceptance.TestData, startIP, endIP string) string { + template := testAccAzureRMDataLakeAnalyticsFirewallRule_basic(data, startIP, endIP) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_migration_test.go similarity index 90% rename from azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration_test.go rename to azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_migration_test.go index 05e8d1a4d733..04691c88baf0 100644 --- a/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_migration_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_migration_test.go @@ -1,4 +1,4 @@ -package datalake +package tests import ( "context" @@ -8,6 +8,7 @@ import ( "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/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datalake" ) // NOTE: this is intentionally an acceptance test (and we're not explicitly setting the env) @@ -61,7 +62,7 @@ func TestAccAzureRMDataLakeStoreFileMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := resourceDataLakeStoreFileMigrateState(tc.StateVersion, is, client) + is, err := datalake.ResourceDataLakeStoreFileMigrateState(tc.StateVersion, is, client) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go similarity index 75% rename from azurerm/internal/services/datalake/resource_arm_data_lake_store_file_test.go rename to azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go index 0fb8f59aa36f..c7d98b967848 100644 --- a/azurerm/internal/services/datalake/resource_arm_data_lake_store_file_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go @@ -1,4 +1,4 @@ -package datalake +package tests import ( "fmt" @@ -8,13 +8,12 @@ import ( "os" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datalake` "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -34,7 +33,7 @@ func TestValidateAzureDataLakeStoreRemoteFilePath(t *testing.T) { } for _, tc := range cases { - _, errors := validateDataLakeStoreRemoteFilePath()(tc.Value, "unittest") + _, errors := datalake.ValidateDataLakeStoreRemoteFilePath()(tc.Value, "unittest") if len(errors) != tc.Errors { t.Fatalf("Expected validateDataLakeStoreRemoteFilePath to trigger '%d' errors for '%s' - got '%d'", tc.Errors, tc.Value, len(errors)) @@ -43,10 +42,7 @@ func TestValidateAzureDataLakeStoreRemoteFilePath(t *testing.T) { } func TestAccAzureRMDataLakeStoreFile_basic(t *testing.T) { - resourceName := "azurerm_data_lake_store_file.test" - - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_data_lake_store_file", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,30 +50,23 @@ func TestAccAzureRMDataLakeStoreFile_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreFileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStoreFile_basic(ri, rs, acceptance.Location()), + Config: testAccAzureRMDataLakeStoreFile_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreFileExists(resourceName), + testCheckAzureRMDataLakeStoreFileExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"local_file_path"}, - }, + data.ImportStep("local_file_path"), }, }) } func TestAccAzureRMDataLakeStoreFile_largefiles(t *testing.T) { - resourceName := "azurerm_data_lake_store_file.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) + data := acceptance.BuildTestData(t, "azurerm_data_lake_store_file", "test") //"large" in this context is anything greater than 4 megabytes largeSize := 12 * 1024 * 1024 //12 mb - data := make([]byte, largeSize) - rand.Read(data) //fill with random data + bytes := make([]byte, largeSize) + rand.Read(bytes) //fill with random data tmpfile, err := ioutil.TempFile("", "azurerm-acc-datalake-file-large") if err != nil { @@ -85,7 +74,7 @@ func TestAccAzureRMDataLakeStoreFile_largefiles(t *testing.T) { } defer os.Remove(tmpfile.Name()) - if _, err := tmpfile.Write(data); err != nil { + if _, err := tmpfile.Write(bytes); err != nil { t.Errorf("Unable to write to temporary file %q: %v", tmpfile.Name(), err) } if err := tmpfile.Close(); err != nil { @@ -98,17 +87,12 @@ func TestAccAzureRMDataLakeStoreFile_largefiles(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreFileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStoreFile_largefiles(ri, rs, acceptance.Location(), tmpfile.Name()), + Config: testAccAzureRMDataLakeStoreFile_largefiles(data, tmpfile.Name()), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreFileExists(resourceName), + testCheckAzureRMDataLakeStoreFileExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"local_file_path"}, - }, + data.ImportStep("local_file_path"), }, }) } @@ -119,11 +103,7 @@ func TestAccAzureRMDataLakeStoreFile_requiresimport(t *testing.T) { return } - resourceName := "azurerm_data_lake_store_file.test" - - ri := tf.AccRandTimeInt() - rs := acctest.RandString(4) - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store_file", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -131,13 +111,13 @@ func TestAccAzureRMDataLakeStoreFile_requiresimport(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreFileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStoreFile_basic(ri, rs, location), + Config: testAccAzureRMDataLakeStoreFile_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreFileExists(resourceName), + testCheckAzureRMDataLakeStoreFileExists(data.ResourceName), ), }, { - Config: testAccAzureRMDataLakeStoreFile_requiresImport(ri, rs, location), + Config: testAccAzureRMDataLakeStoreFile_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_data_lake_store_file"), }, }, @@ -198,7 +178,7 @@ func testCheckAzureRMDataLakeStoreFileDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDataLakeStoreFile_basic(rInt int, rString, location string) string { +func testAccAzureRMDataLakeStoreFile_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -217,10 +197,10 @@ resource "azurerm_data_lake_store_file" "test" { account_name = "${azurerm_data_lake_store.test.name}" local_file_path = "./testdata/application_gateway_test.cer" } -`, rInt, location, rString, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.Locations.Primary) } -func testAccAzureRMDataLakeStoreFile_largefiles(rInt int, rString, location, file string) string { +func testAccAzureRMDataLakeStoreFile_largefiles(data acceptance.TestData, file string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -239,11 +219,11 @@ resource "azurerm_data_lake_store_file" "test" { account_name = "${azurerm_data_lake_store.test.name}" local_file_path = "%s" } -`, rInt, location, rString, location, file) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.Locations.Primary, file) } -func testAccAzureRMDataLakeStoreFile_requiresImport(rInt int, rString, location string) string { - template := testAccAzureRMDataLakeStoreFile_basic(rInt, rString, location) +func testAccAzureRMDataLakeStoreFile_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDataLakeStoreFile_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/datalake/resource_arm_data_lake_store_firewall_rule_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_firewall_rule_test.go similarity index 68% rename from azurerm/internal/services/datalake/resource_arm_data_lake_store_firewall_rule_test.go rename to azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_firewall_rule_test.go index e1f35ac10035..3a84b024419f 100644 --- a/azurerm/internal/services/datalake/resource_arm_data_lake_store_firewall_rule_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_firewall_rule_test.go @@ -1,4 +1,4 @@ -package datalake +package tests import ( "fmt" @@ -9,15 +9,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDataLakeStoreFirewallRule_basic(t *testing.T) { - resourceName := "azurerm_data_lake_store_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store_firewall_rule", "test") startIP := "1.1.1.1" endIP := "2.2.2.2" @@ -27,18 +25,14 @@ func TestAccAzureRMDataLakeStoreFirewallRule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStoreFirewallRule_basic(ri, acceptance.Location(), startIP, endIP), + Config: testAccAzureRMDataLakeStoreFirewallRule_basic(data, startIP, endIP), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", startIP), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", endIP), + testCheckAzureRMDataLakeStoreFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", startIP), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", endIP), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -51,9 +45,7 @@ func TestAccAzureRMDataLakeStoreFirewallRule_requiresImport(t *testing.T) { return } - resourceName := "azurerm_data_lake_store_firewall_rule.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store_firewall_rule", "test") startIP := "1.1.1.1" endIP := "2.2.2.2" @@ -63,13 +55,13 @@ func TestAccAzureRMDataLakeStoreFirewallRule_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStoreFirewallRule_basic(ri, location, startIP, endIP), + Config: testAccAzureRMDataLakeStoreFirewallRule_basic(data, startIP, endIP), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreFirewallRuleExists(resourceName), + testCheckAzureRMDataLakeStoreFirewallRuleExists(data.ResourceName), ), }, { - Config: testAccAzureRMDataLakeStoreFirewallRule_requiresImport(ri, location, startIP, endIP), + Config: testAccAzureRMDataLakeStoreFirewallRule_requiresImport(data, startIP, endIP), ExpectError: acceptance.RequiresImportError("azurerm_data_lake_store_firewall_rule"), }, }, @@ -77,8 +69,7 @@ func TestAccAzureRMDataLakeStoreFirewallRule_requiresImport(t *testing.T) { } func TestAccAzureRMDataLakeStoreFirewallRule_update(t *testing.T) { - resourceName := "azurerm_data_lake_store_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store_firewall_rule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -86,19 +77,19 @@ func TestAccAzureRMDataLakeStoreFirewallRule_update(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStoreFirewallRule_basic(ri, acceptance.Location(), "1.1.1.1", "2.2.2.2"), + Config: testAccAzureRMDataLakeStoreFirewallRule_basic(data, "1.1.1.1", "2.2.2.2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", "1.1.1.1"), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", "2.2.2.2"), + testCheckAzureRMDataLakeStoreFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", "1.1.1.1"), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", "2.2.2.2"), ), }, { - Config: testAccAzureRMDataLakeStoreFirewallRule_basic(ri, acceptance.Location(), "2.2.2.2", "3.3.3.3"), + Config: testAccAzureRMDataLakeStoreFirewallRule_basic(data, "2.2.2.2", "3.3.3.3"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", "2.2.2.2"), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", "3.3.3.3"), + testCheckAzureRMDataLakeStoreFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", "2.2.2.2"), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", "3.3.3.3"), ), }, }, @@ -106,8 +97,7 @@ func TestAccAzureRMDataLakeStoreFirewallRule_update(t *testing.T) { } func TestAccAzureRMDataLakeStoreFirewallRule_azureServices(t *testing.T) { - resourceName := "azurerm_data_lake_store_firewall_rule.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store_firewall_rule", "test") azureServicesIP := "0.0.0.0" resource.ParallelTest(t, resource.TestCase{ @@ -116,18 +106,14 @@ func TestAccAzureRMDataLakeStoreFirewallRule_azureServices(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreFirewallRuleDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStoreFirewallRule_basic(ri, acceptance.Location(), azureServicesIP, azureServicesIP), + Config: testAccAzureRMDataLakeStoreFirewallRule_basic(data, azureServicesIP, azureServicesIP), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreFirewallRuleExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "start_ip_address", azureServicesIP), - resource.TestCheckResourceAttr(resourceName, "end_ip_address", azureServicesIP), + testCheckAzureRMDataLakeStoreFirewallRuleExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_ip_address", azureServicesIP), + resource.TestCheckResourceAttr(data.ResourceName, "end_ip_address", azureServicesIP), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -191,7 +177,7 @@ func testCheckAzureRMDataLakeStoreFirewallRuleDestroy(s *terraform.State) error return nil } -func testAccAzureRMDataLakeStoreFirewallRule_basic(rInt int, location, startIP, endIP string) string { +func testAccAzureRMDataLakeStoreFirewallRule_basic(data acceptance.TestData, startIP, endIP string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -211,11 +197,11 @@ resource "azurerm_data_lake_store_firewall_rule" "test" { start_ip_address = "%s" end_ip_address = "%s" } -`, rInt, location, strconv.Itoa(rInt)[2:17], startIP, endIP) +`, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[2:17], startIP, endIP) } -func testAccAzureRMDataLakeStoreFirewallRule_requiresImport(rInt int, location, startIP, endIP string) string { - template := testAccAzureRMDataLakeStoreFirewallRule_basic(rInt, location, startIP, endIP) +func testAccAzureRMDataLakeStoreFirewallRule_requiresImport(data acceptance.TestData, startIP, endIP string) string { + template := testAccAzureRMDataLakeStoreFirewallRule_basic(data, startIP, endIP) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/datalake/resource_arm_data_lake_store_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_test.go similarity index 60% rename from azurerm/internal/services/datalake/resource_arm_data_lake_store_test.go rename to azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_test.go index 5a63b9e65261..fd14ad8b150f 100644 --- a/azurerm/internal/services/datalake/resource_arm_data_lake_store_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_test.go @@ -1,4 +1,4 @@ -package datalake +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMDataLakeStore_basic(t *testing.T) { - resourceName := "azurerm_data_lake_store.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,19 +22,15 @@ func TestAccAzureRMDataLakeStore_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStore_basic(ri, acceptance.Location()), + Config: testAccAzureRMDataLakeStore_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tier", "Consumption"), - resource.TestCheckResourceAttr(resourceName, "encryption_state", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "encryption_type", "ServiceManaged"), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "Consumption"), + resource.TestCheckResourceAttr(data.ResourceName, "encryption_state", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "encryption_type", "ServiceManaged"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,9 +40,7 @@ func TestAccAzureRMDataLakeStore_requiresImport(t *testing.T) { return } - resourceName := "azurerm_data_lake_store.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,13 +48,13 @@ func TestAccAzureRMDataLakeStore_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStore_basic(ri, location), + Config: testAccAzureRMDataLakeStore_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(resourceName), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), ), }, { - Config: testAccAzureRMDataLakeStore_requiresImport(ri, location), + Config: testAccAzureRMDataLakeStore_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_data_lake_store"), }, }, @@ -70,8 +62,7 @@ func TestAccAzureRMDataLakeStore_requiresImport(t *testing.T) { } func TestAccAzureRMDataLakeStore_tier(t *testing.T) { - resourceName := "azurerm_data_lake_store.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -79,24 +70,19 @@ func TestAccAzureRMDataLakeStore_tier(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStore_tier(ri, acceptance.Location()), + Config: testAccAzureRMDataLakeStore_tier(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tier", "Commitment_1TB"), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tier", "Commitment_1TB"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataLakeStore_encryptionDisabled(t *testing.T) { - resourceName := "azurerm_data_lake_store.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,26 +90,20 @@ func TestAccAzureRMDataLakeStore_encryptionDisabled(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStore_encryptionDisabled(ri, acceptance.Location()), + Config: testAccAzureRMDataLakeStore_encryptionDisabled(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "encryption_state", "Disabled"), - resource.TestCheckResourceAttr(resourceName, "encryption_type", ""), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "encryption_state", "Disabled"), + resource.TestCheckResourceAttr(data.ResourceName, "encryption_type", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataLakeStore_firewallUpdate(t *testing.T) { - resourceName := "azurerm_data_lake_store.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -131,35 +111,35 @@ func TestAccAzureRMDataLakeStore_firewallUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStore_firewall(ri, location, "Enabled", "Enabled"), + Config: testAccAzureRMDataLakeStore_firewall(data, "Enabled", "Enabled"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "firewall_state", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "firewall_allow_azure_ips", "Enabled"), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "firewall_state", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "firewall_allow_azure_ips", "Enabled"), ), }, { - Config: testAccAzureRMDataLakeStore_firewall(ri, location, "Enabled", "Disabled"), + Config: testAccAzureRMDataLakeStore_firewall(data, "Enabled", "Disabled"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "firewall_state", "Enabled"), - resource.TestCheckResourceAttr(resourceName, "firewall_allow_azure_ips", "Disabled"), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "firewall_state", "Enabled"), + resource.TestCheckResourceAttr(data.ResourceName, "firewall_allow_azure_ips", "Disabled"), ), }, { - Config: testAccAzureRMDataLakeStore_firewall(ri, location, "Disabled", "Enabled"), + Config: testAccAzureRMDataLakeStore_firewall(data, "Disabled", "Enabled"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "firewall_state", "Disabled"), - resource.TestCheckResourceAttr(resourceName, "firewall_allow_azure_ips", "Enabled"), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "firewall_state", "Disabled"), + resource.TestCheckResourceAttr(data.ResourceName, "firewall_allow_azure_ips", "Enabled"), ), }, { - Config: testAccAzureRMDataLakeStore_firewall(ri, location, "Disabled", "Disabled"), + Config: testAccAzureRMDataLakeStore_firewall(data, "Disabled", "Disabled"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "firewall_state", "Disabled"), - resource.TestCheckResourceAttr(resourceName, "firewall_allow_azure_ips", "Disabled"), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "firewall_state", "Disabled"), + resource.TestCheckResourceAttr(data.ResourceName, "firewall_allow_azure_ips", "Disabled"), ), }, }, @@ -167,8 +147,7 @@ func TestAccAzureRMDataLakeStore_firewallUpdate(t *testing.T) { } func TestAccAzureRMDataLakeStore_withTags(t *testing.T) { - resourceName := "azurerm_data_lake_store.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_data_lake_store", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -176,24 +155,20 @@ func TestAccAzureRMDataLakeStore_withTags(t *testing.T) { CheckDestroy: testCheckAzureRMDataLakeStoreDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataLakeStore_withTags(ri, acceptance.Location()), + Config: testAccAzureRMDataLakeStore_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), ), }, { - Config: testAccAzureRMDataLakeStore_withTagsUpdate(ri, acceptance.Location()), + Config: testAccAzureRMDataLakeStore_withTagsUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataLakeStoreExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + testCheckAzureRMDataLakeStoreExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -255,7 +230,7 @@ func testCheckAzureRMDataLakeStoreDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDataLakeStore_basic(rInt int, location string) string { +func testAccAzureRMDataLakeStore_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -267,11 +242,11 @@ resource "azurerm_data_lake_store" "test" { resource_group_name = "${azurerm_resource_group.test.name}" location = "${azurerm_resource_group.test.location}" } -`, rInt, location, strconv.Itoa(rInt)[2:17]) +`, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[2:17]) } -func testAccAzureRMDataLakeStore_requiresImport(rInt int, location string) string { - template := testAccAzureRMDataLakeStore_basic(rInt, location) +func testAccAzureRMDataLakeStore_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDataLakeStore_basic(data) return fmt.Sprintf(` %s @@ -283,7 +258,7 @@ resource "azurerm_data_lake_store" "import" { `, template) } -func testAccAzureRMDataLakeStore_tier(rInt int, location string) string { +func testAccAzureRMDataLakeStore_tier(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -296,10 +271,10 @@ resource "azurerm_data_lake_store" "test" { location = "${azurerm_resource_group.test.location}" tier = "Commitment_1TB" } -`, rInt, location, strconv.Itoa(rInt)[2:17]) +`, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[2:17]) } -func testAccAzureRMDataLakeStore_encryptionDisabled(rInt int, location string) string { +func testAccAzureRMDataLakeStore_encryptionDisabled(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -312,10 +287,10 @@ resource "azurerm_data_lake_store" "test" { location = "${azurerm_resource_group.test.location}" encryption_state = "Disabled" } -`, rInt, location, strconv.Itoa(rInt)[2:17]) +`, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[2:17]) } -func testAccAzureRMDataLakeStore_firewall(rInt int, location string, firewallState string, firewallAllowAzureIPs string) string { +func testAccAzureRMDataLakeStore_firewall(data acceptance.TestData, firewallState string, firewallAllowAzureIPs string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -329,10 +304,10 @@ resource "azurerm_data_lake_store" "test" { firewall_state = "%s" firewall_allow_azure_ips = "%s" } -`, rInt, location, strconv.Itoa(rInt)[2:17], firewallState, firewallAllowAzureIPs) +`, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[2:17], firewallState, firewallAllowAzureIPs) } -func testAccAzureRMDataLakeStore_withTags(rInt int, location string) string { +func testAccAzureRMDataLakeStore_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -349,10 +324,10 @@ resource "azurerm_data_lake_store" "test" { cost_center = "MSFT" } } -`, rInt, location, strconv.Itoa(rInt)[2:17]) +`, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[2:17]) } -func testAccAzureRMDataLakeStore_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMDataLakeStore_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -368,5 +343,5 @@ resource "azurerm_data_lake_store" "test" { environment = "staging" } } -`, rInt, location, strconv.Itoa(rInt)[2:17]) +`, data.RandomInteger, data.Locations.Primary, strconv.Itoa(data.RandomInteger)[2:17]) } From 7f394b4895f41ed6fda61b2f62e0e5ff0f3a54b4 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 12:15:35 -0800 Subject: [PATCH 150/203] move datalake testdata into tests package --- .../datalake/{ => tests}/testdata/application_gateway_test.cer | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename azurerm/internal/services/datalake/{ => tests}/testdata/application_gateway_test.cer (100%) diff --git a/azurerm/internal/services/datalake/testdata/application_gateway_test.cer b/azurerm/internal/services/datalake/tests/testdata/application_gateway_test.cer similarity index 100% rename from azurerm/internal/services/datalake/testdata/application_gateway_test.cer rename to azurerm/internal/services/datalake/tests/testdata/application_gateway_test.cer From 05cce793d7c04192b18fc93bafb27c4e49c1b0da Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 12:25:42 -0800 Subject: [PATCH 151/203] datafactory: switching to the new test structure --- .../data_source_data_factory_test.go | 15 +- ...rce_arm_data_factory_dataset_mysql_test.go | 69 +++----- ...rm_data_factory_dataset_postgresql_test.go | 68 +++----- ...a_factory_dataset_sql_server_table_test.go | 68 +++----- ...actory_integration_runtime_managed_test.go | 101 ++++------- ...ked_service_data_lake_storage_gen2_test.go | 70 +++----- ..._data_factory_linked_service_mysql_test.go | 72 +++----- ..._factory_linked_service_postgresql_test.go | 72 +++----- ..._factory_linked_service_sql_server_test.go | 50 +++--- ...resource_arm_data_factory_pipeline_test.go | 64 +++---- .../resource_arm_data_factory_test.go | 159 +++++++----------- ..._arm_data_factory_trigger_schedule_test.go | 50 ++---- .../resource_arm_data_lake_store_file_test.go | 2 +- 13 files changed, 324 insertions(+), 536 deletions(-) rename azurerm/internal/services/datafactory/{ => tests}/data_source_data_factory_test.go (62%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_dataset_mysql_test.go (76%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_dataset_postgresql_test.go (76%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_dataset_sql_server_table_test.go (75%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_integration_runtime_managed_test.go (76%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go (77%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_linked_service_mysql_test.go (71%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_linked_service_postgresql_test.go (71%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_linked_service_sql_server_test.go (73%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_pipeline_test.go (72%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_test.go (61%) rename azurerm/internal/services/datafactory/{ => tests}/resource_arm_data_factory_trigger_schedule_test.go (79%) diff --git a/azurerm/internal/services/datafactory/data_source_data_factory_test.go b/azurerm/internal/services/datafactory/tests/data_source_data_factory_test.go similarity index 62% rename from azurerm/internal/services/datafactory/data_source_data_factory_test.go rename to azurerm/internal/services/datafactory/tests/data_source_data_factory_test.go index 9e0da6328bc1..293f3f96b517 100644 --- a/azurerm/internal/services/datafactory/data_source_data_factory_test.go +++ b/azurerm/internal/services/datafactory/tests/data_source_data_factory_test.go @@ -1,18 +1,15 @@ -package datafactory +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMDataFactoryDataSource_basic(t *testing.T) { - dsn := "azurerm_data_factory.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_data_factory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,17 +17,17 @@ func TestAccAzureRMDataFactoryDataSource_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataFactoryDataSource_basic(ri, location), + Config: testAccAzureRMDataFactoryDataSource_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryExists(dsn), + testCheckAzureRMDataFactoryExists(data.ResourceName), ), }, }, }) } -func testAccAzureRMDataFactoryDataSource_basic(rInt int, location string) string { - config := testAccAzureRMDataFactory_basic(rInt, location) +func testAccAzureRMDataFactoryDataSource_basic(data acceptance.TestData) string { + config := testAccAzureRMDataFactory_basic(data) return fmt.Sprintf(` %s diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_mysql_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go similarity index 76% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_mysql_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go index 973ac055ad9b..7344de1ec3ad 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_mysql_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go @@ -1,4 +1,4 @@ -package datafactory +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactoryDatasetMySQL_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryDatasetMySQL_basic(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_dataset_mysql.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_mysql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,25 +21,19 @@ func TestAccAzureRMDataFactoryDatasetMySQL_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDatasetMySQLDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryDatasetMySQL_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryDatasetMySQLExists(resourceName), + testCheckAzureRMDataFactoryDatasetMySQLExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactoryDatasetMySQL_update(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryDatasetMySQL_update1(ri, acceptance.Location()) - config2 := testAccAzureRMDataFactoryDatasetMySQL_update2(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_dataset_mysql.test" + + data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_mysql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,32 +41,28 @@ func TestAccAzureRMDataFactoryDatasetMySQL_update(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDatasetMySQLDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryDatasetMySQL_update1(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryDatasetMySQLExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "3"), - resource.TestCheckResourceAttr(resourceName, "schema_column.#", "1"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "2"), - resource.TestCheckResourceAttr(resourceName, "description", "test description"), + testCheckAzureRMDataFactoryDatasetMySQLExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "schema_column.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), ), }, { - Config: config2, + Config: testAccAzureRMDataFactoryDatasetMySQL_update2(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryDatasetMySQLExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "3"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "2"), - resource.TestCheckResourceAttr(resourceName, "schema_column.#", "2"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "1"), - resource.TestCheckResourceAttr(resourceName, "description", "test description 2"), + testCheckAzureRMDataFactoryDatasetMySQLExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "schema_column.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description 2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -138,7 +125,7 @@ func testCheckAzureRMDataFactoryDatasetMySQLDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDataFactoryDatasetMySQL_basic(rInt int, location string) string { +func testAccAzureRMDataFactoryDatasetMySQL_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -164,10 +151,10 @@ resource "azurerm_data_factory_dataset_mysql" "test" { data_factory_name = "${azurerm_data_factory.test.name}" linked_service_name = "${azurerm_data_factory_linked_service_mysql.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryDatasetMySQL_update1(rInt int, location string) string { +func testAccAzureRMDataFactoryDatasetMySQL_update1(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -214,10 +201,10 @@ resource "azurerm_data_factory_dataset_mysql" "test" { description = "description" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryDatasetMySQL_update2(rInt int, location string) string { +func testAccAzureRMDataFactoryDatasetMySQL_update2(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -270,5 +257,5 @@ resource "azurerm_data_factory_dataset_mysql" "test" { description = "description" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_postgresql_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_postgresql_test.go similarity index 76% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_postgresql_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_postgresql_test.go index f92352873672..9a89365e71ce 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_postgresql_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_postgresql_test.go @@ -1,4 +1,4 @@ -package datafactory +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactoryDatasetPostgreSQL_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryDatasetPostgreSQL_basic(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_dataset_postgresql.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_postgresql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,25 +21,18 @@ func TestAccAzureRMDataFactoryDatasetPostgreSQL_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDatasetPostgreSQLDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryDatasetPostgreSQL_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryDatasetPostgreSQLExists(resourceName), + testCheckAzureRMDataFactoryDatasetPostgreSQLExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactoryDatasetPostgreSQL_update(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryDatasetPostgreSQL_update1(ri, acceptance.Location()) - config2 := testAccAzureRMDataFactoryDatasetPostgreSQL_update2(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_dataset_postgresql.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_postgresql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,32 +40,28 @@ func TestAccAzureRMDataFactoryDatasetPostgreSQL_update(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDatasetPostgreSQLDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryDatasetPostgreSQL_update1(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryDatasetPostgreSQLExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "3"), - resource.TestCheckResourceAttr(resourceName, "schema_column.#", "1"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "2"), - resource.TestCheckResourceAttr(resourceName, "description", "test description"), + testCheckAzureRMDataFactoryDatasetPostgreSQLExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "schema_column.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), ), }, { - Config: config2, + Config: testAccAzureRMDataFactoryDatasetPostgreSQL_update2(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryDatasetPostgreSQLExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "3"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "2"), - resource.TestCheckResourceAttr(resourceName, "schema_column.#", "2"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "1"), - resource.TestCheckResourceAttr(resourceName, "description", "test description 2"), + testCheckAzureRMDataFactoryDatasetPostgreSQLExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "schema_column.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description 2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -138,7 +124,7 @@ func testCheckAzureRMDataFactoryDatasetPostgreSQLDestroy(s *terraform.State) err return nil } -func testAccAzureRMDataFactoryDatasetPostgreSQL_basic(rInt int, location string) string { +func testAccAzureRMDataFactoryDatasetPostgreSQL_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -164,10 +150,10 @@ resource "azurerm_data_factory_dataset_postgresql" "test" { data_factory_name = "${azurerm_data_factory.test.name}" linked_service_name = "${azurerm_data_factory_linked_service_postgresql.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryDatasetPostgreSQL_update1(rInt int, location string) string { +func testAccAzureRMDataFactoryDatasetPostgreSQL_update1(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -214,10 +200,10 @@ resource "azurerm_data_factory_dataset_postgresql" "test" { description = "description" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryDatasetPostgreSQL_update2(rInt int, location string) string { +func testAccAzureRMDataFactoryDatasetPostgreSQL_update2(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -270,5 +256,5 @@ resource "azurerm_data_factory_dataset_postgresql" "test" { description = "description" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_sql_server_table_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_sql_server_table_test.go similarity index 75% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_sql_server_table_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_sql_server_table_test.go index db8875e34e8b..a539da91575c 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_dataset_sql_server_table_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_sql_server_table_test.go @@ -1,4 +1,4 @@ -package datafactory +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactoryDatasetSQLServerTable_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryDatasetSQLServerTable_basic(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_dataset_sql_server_table.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_sql_server_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,25 +21,18 @@ func TestAccAzureRMDataFactoryDatasetSQLServerTable_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDatasetSQLServerTableDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryDatasetSQLServerTable_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryDatasetSQLServerTableExists(resourceName), + testCheckAzureRMDataFactoryDatasetSQLServerTableExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactoryDatasetSQLServerTable_update(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryDatasetSQLServerTable_update1(ri, acceptance.Location()) - config2 := testAccAzureRMDataFactoryDatasetSQLServerTable_update2(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_dataset_sql_server_table.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_sql_server_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,32 +40,28 @@ func TestAccAzureRMDataFactoryDatasetSQLServerTable_update(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDatasetSQLServerTableDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryDatasetSQLServerTable_update1(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryDatasetSQLServerTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "3"), - resource.TestCheckResourceAttr(resourceName, "schema_column.#", "1"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "2"), - resource.TestCheckResourceAttr(resourceName, "description", "test description"), + testCheckAzureRMDataFactoryDatasetSQLServerTableExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "schema_column.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), ), }, { - Config: config2, + Config: testAccAzureRMDataFactoryDatasetSQLServerTable_update2(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryDatasetSQLServerTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "3"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "2"), - resource.TestCheckResourceAttr(resourceName, "schema_column.#", "2"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "1"), - resource.TestCheckResourceAttr(resourceName, "description", "test description 2"), + testCheckAzureRMDataFactoryDatasetSQLServerTableExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "schema_column.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description 2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -138,7 +124,7 @@ func testCheckAzureRMDataFactoryDatasetSQLServerTableDestroy(s *terraform.State) return nil } -func testAccAzureRMDataFactoryDatasetSQLServerTable_basic(rInt int, location string) string { +func testAccAzureRMDataFactoryDatasetSQLServerTable_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -164,10 +150,10 @@ resource "azurerm_data_factory_dataset_sql_server_table" "test" { data_factory_name = "${azurerm_data_factory.test.name}" linked_service_name = "${azurerm_data_factory_linked_service_sql_server.test.name}" } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryDatasetSQLServerTable_update1(rInt int, location string) string { +func testAccAzureRMDataFactoryDatasetSQLServerTable_update1(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -214,10 +200,10 @@ resource "azurerm_data_factory_dataset_sql_server_table" "test" { description = "description" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryDatasetSQLServerTable_update2(rInt int, location string) string { +func testAccAzureRMDataFactoryDatasetSQLServerTable_update2(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -270,5 +256,5 @@ resource "azurerm_data_factory_dataset_sql_server_table" "test" { description = "description" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_integration_runtime_managed_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_integration_runtime_managed_test.go similarity index 76% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_integration_runtime_managed_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_integration_runtime_managed_test.go index d98a2838d085..c880270eeb72 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_integration_runtime_managed_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_integration_runtime_managed_test.go @@ -1,23 +1,19 @@ -package datafactory +package tests import ( "fmt" "net/http" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryIntegrationRuntimeManaged_basic(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_integration_runtime_managed.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_integration_runtime_managed", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,24 +21,18 @@ func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryIntegrationRuntimeManagedDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryIntegrationRuntimeManaged_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(resourceName), + testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_vnetIntegration(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryIntegrationRuntimeManaged_vnetIntegration(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_integration_runtime_managed.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_integration_runtime_managed", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,27 +40,21 @@ func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_vnetIntegration(t *testi CheckDestroy: testCheckAzureRMDataFactoryIntegrationRuntimeManagedDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryIntegrationRuntimeManaged_vnetIntegration(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "vnet_integration.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "vnet_integration.0.vnet_id"), - resource.TestCheckResourceAttrSet(resourceName, "vnet_integration.0.subnet_name"), + testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "vnet_integration.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "vnet_integration.0.vnet_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "vnet_integration.0.subnet_name"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_catalogInfo(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryIntegrationRuntimeManaged_catalogInfo(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_integration_runtime_managed.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_integration_runtime_managed", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -78,31 +62,23 @@ func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_catalogInfo(t *testing.T CheckDestroy: testCheckAzureRMDataFactoryIntegrationRuntimeManagedDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryIntegrationRuntimeManaged_catalogInfo(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "catalog_info.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "catalog_info.0.server_endpoint"), - resource.TestCheckResourceAttr(resourceName, "catalog_info.0.administrator_login", "ssis_catalog_admin"), - resource.TestCheckResourceAttr(resourceName, "catalog_info.0.administrator_password", "my-s3cret-p4ssword!"), - resource.TestCheckResourceAttr(resourceName, "catalog_info.0.pricing_tier", "Basic"), + testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "catalog_info.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "catalog_info.0.server_endpoint"), + resource.TestCheckResourceAttr(data.ResourceName, "catalog_info.0.administrator_login", "ssis_catalog_admin"), + resource.TestCheckResourceAttr(data.ResourceName, "catalog_info.0.administrator_password", "my-s3cret-p4ssword!"), + resource.TestCheckResourceAttr(data.ResourceName, "catalog_info.0.pricing_tier", "Basic"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"catalog_info.0.administrator_password"}, - }, + data.ImportStep("catalog_info.0.administrator_password"), }, }) } func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(t *testing.T) { - ri := tf.AccRandTimeInt() - rs := acctest.RandString(6) - config := testAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(ri, acceptance.Location(), rs) - resourceName := "azurerm_data_factory_integration_runtime_managed.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_integration_runtime_managed", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -110,25 +86,20 @@ func TestAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(t *tes CheckDestroy: testCheckAzureRMDataFactoryIntegrationRuntimeManagedDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "custom_setup_script.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "custom_setup_script.0.blob_container_uri"), - resource.TestCheckResourceAttrSet(resourceName, "custom_setup_script.0.sas_token"), + testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "custom_setup_script.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "custom_setup_script.0.blob_container_uri"), + resource.TestCheckResourceAttrSet(data.ResourceName, "custom_setup_script.0.sas_token"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"custom_setup_script.0.sas_token"}, - }, + data.ImportStep("catalog_info.0.administrator_password"), }, }) } -func testAccAzureRMDataFactoryIntegrationRuntimeManaged_basic(rInt int, location string) string { +func testAccAzureRMDataFactoryIntegrationRuntimeManaged_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -153,10 +124,10 @@ resource "azurerm_data_factory_integration_runtime_managed" "test" { edition = "Standard" license_type = "LicenseIncluded" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDataFactoryIntegrationRuntimeManaged_vnetIntegration(rInt int, location string) string { +func testAccAzureRMDataFactoryIntegrationRuntimeManaged_vnetIntegration(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -196,10 +167,10 @@ resource "azurerm_data_factory_integration_runtime_managed" "test" { subnet_name = "${azurerm_subnet.test.name}" } } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryIntegrationRuntimeManaged_catalogInfo(rInt int, location string) string { +func testAccAzureRMDataFactoryIntegrationRuntimeManaged_catalogInfo(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -236,10 +207,10 @@ resource "azurerm_data_factory_integration_runtime_managed" "test" { pricing_tier = "Basic" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(rInt int, location string, rString string) string { +func testAccAzureRMDataFactoryIntegrationRuntimeManaged_customSetupScript(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -300,7 +271,7 @@ resource "azurerm_data_factory_integration_runtime_managed" "test" { sas_token = "${data.azurerm_storage_account_blob_container_sas.test.sas}" } } -`, rInt, location, rInt, rString) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString) } func testCheckAzureRMDataFactoryIntegrationRuntimeManagedExists(name string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go similarity index 77% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go index fbe32791b560..fff00410f85f 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_data_lake_storage_gen2_test.go @@ -1,4 +1,4 @@ -package datafactory +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_basic(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_linked_service_data_lake_storage_gen2.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_data_lake_storage_gen2", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,28 +21,18 @@ func TestAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_basic(t *testing. CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceDataLakeStorageGen2Destroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServiceDataLakeStorageGen2Exists(resourceName), + testCheckAzureRMDataFactoryLinkedServiceDataLakeStorageGen2Exists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal_key", - }, - }, + data.ImportStep("service_principal_key"), }, }) } func TestAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update1(ri, acceptance.Location()) - config2 := testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update2(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_linked_service_data_lake_storage_gen2.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_data_lake_storage_gen2", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,33 +40,26 @@ func TestAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update(t *testing CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceDataLakeStorageGen2Destroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update1(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServiceDataLakeStorageGen2Exists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "3"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "2"), - resource.TestCheckResourceAttr(resourceName, "description", "test description"), + testCheckAzureRMDataFactoryLinkedServiceDataLakeStorageGen2Exists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), ), }, { - Config: config2, + Config: testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update2(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServiceDataLakeStorageGen2Exists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "3"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "2"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "1"), - resource.TestCheckResourceAttr(resourceName, "description", "test description 2"), + testCheckAzureRMDataFactoryLinkedServiceDataLakeStorageGen2Exists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description 2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal_key", - }, - }, + data.ImportStep("service_principal_key"), }, }) } @@ -142,7 +122,7 @@ func testCheckAzureRMDataFactoryLinkedServiceDataLakeStorageGen2Destroy(s *terra return nil } -func testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_basic(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -166,10 +146,10 @@ resource "azurerm_data_factory_linked_service_data_lake_storage_gen2" "test" { tenant = "11111111-1111-1111-1111-111111111111" url = "https://test.azure.com" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update1(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update1(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -205,10 +185,10 @@ resource "azurerm_data_factory_linked_service_data_lake_storage_gen2" "test" { bar = "test2" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update2(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServiceDataLakeStorageGen2_update2(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -244,5 +224,5 @@ resource "azurerm_data_factory_linked_service_data_lake_storage_gen2" "test" { foo = "test1" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_mysql_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_mysql_test.go similarity index 71% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_mysql_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_mysql_test.go index 7c1f0ec46177..0b194eb7fafa 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_mysql_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_mysql_test.go @@ -1,4 +1,4 @@ -package datafactory +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactoryLinkedServiceMySQL_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryLinkedServiceMySQL_basic(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_linked_service_mysql.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_mysql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,29 +21,18 @@ func TestAccAzureRMDataFactoryLinkedServiceMySQL_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceMySQLDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryLinkedServiceMySQL_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServiceMySQLExists(resourceName), + testCheckAzureRMDataFactoryLinkedServiceMySQLExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // returned as ***** from the api - "connection_string", - }, - }, + data.ImportStep("connection_string"), }, }) } func TestAccAzureRMDataFactoryLinkedServiceMySQL_update(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryLinkedServiceMySQL_update1(ri, acceptance.Location()) - config2 := testAccAzureRMDataFactoryLinkedServiceMySQL_update2(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_linked_service_mysql.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_mysql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,34 +40,26 @@ func TestAccAzureRMDataFactoryLinkedServiceMySQL_update(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceMySQLDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryLinkedServiceMySQL_update1(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServiceMySQLExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "3"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "2"), - resource.TestCheckResourceAttr(resourceName, "description", "test description"), + testCheckAzureRMDataFactoryLinkedServiceMySQLExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), ), }, { - Config: config2, + Config: testAccAzureRMDataFactoryLinkedServiceMySQL_update2(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServiceMySQLExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "3"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "2"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "1"), - resource.TestCheckResourceAttr(resourceName, "description", "test description 2"), + testCheckAzureRMDataFactoryLinkedServiceMySQLExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description 2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // returned as ***** from the api - "connection_string", - }, - }, + data.ImportStep("connection_string"), }, }) } @@ -144,7 +122,7 @@ func testCheckAzureRMDataFactoryLinkedServiceMySQLDestroy(s *terraform.State) er return nil } -func testAccAzureRMDataFactoryLinkedServiceMySQL_basic(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServiceMySQL_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -163,10 +141,10 @@ resource "azurerm_data_factory_linked_service_mysql" "test" { data_factory_name = "${azurerm_data_factory.test.name}" connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryLinkedServiceMySQL_update1(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServiceMySQL_update1(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -197,10 +175,10 @@ resource "azurerm_data_factory_linked_service_mysql" "test" { bar = "test2" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryLinkedServiceMySQL_update2(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServiceMySQL_update2(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -231,5 +209,5 @@ resource "azurerm_data_factory_linked_service_mysql" "test" { foo = "test1" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_postgresql_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_postgresql_test.go similarity index 71% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_postgresql_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_postgresql_test.go index a8254f1a1c7e..78f37c2b8c2e 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_postgresql_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_postgresql_test.go @@ -1,4 +1,4 @@ -package datafactory +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactoryLinkedServicePostgreSQL_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryLinkedServicePostgreSQL_basic(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_linked_service_postgresql.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_postgresql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,29 +21,18 @@ func TestAccAzureRMDataFactoryLinkedServicePostgreSQL_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryLinkedServicePostgreSQLDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryLinkedServicePostgreSQL_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServicePostgreSQLExists(resourceName), + testCheckAzureRMDataFactoryLinkedServicePostgreSQLExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // returned as ***** from the api - "connection_string", - }, - }, + data.ImportStep("connection_string"), }, }) } func TestAccAzureRMDataFactoryLinkedServicePostgreSQL_update(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryLinkedServicePostgreSQL_update1(ri, acceptance.Location()) - config2 := testAccAzureRMDataFactoryLinkedServicePostgreSQL_update2(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_linked_service_postgresql.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_postgresql", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,34 +40,26 @@ func TestAccAzureRMDataFactoryLinkedServicePostgreSQL_update(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryLinkedServicePostgreSQLDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryLinkedServicePostgreSQL_update1(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServicePostgreSQLExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "3"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "2"), - resource.TestCheckResourceAttr(resourceName, "description", "test description"), + testCheckAzureRMDataFactoryLinkedServicePostgreSQLExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), ), }, { - Config: config2, + Config: testAccAzureRMDataFactoryLinkedServicePostgreSQL_update2(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServicePostgreSQLExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "3"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "2"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "1"), - resource.TestCheckResourceAttr(resourceName, "description", "test description 2"), + testCheckAzureRMDataFactoryLinkedServicePostgreSQLExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description 2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - // returned as ***** from the api - "connection_string", - }, - }, + data.ImportStep("connection_string"), }, }) } @@ -144,7 +122,7 @@ func testCheckAzureRMDataFactoryLinkedServicePostgreSQLDestroy(s *terraform.Stat return nil } -func testAccAzureRMDataFactoryLinkedServicePostgreSQL_basic(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServicePostgreSQL_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -163,10 +141,10 @@ resource "azurerm_data_factory_linked_service_postgresql" "test" { data_factory_name = "${azurerm_data_factory.test.name}" connection_string = "Host=example;Port=5432;Database=example;UID=example;EncryptionMethod=0;Password=example" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryLinkedServicePostgreSQL_update1(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServicePostgreSQL_update1(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -197,10 +175,10 @@ resource "azurerm_data_factory_linked_service_postgresql" "test" { bar = "test2" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryLinkedServicePostgreSQL_update2(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServicePostgreSQL_update2(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -231,5 +209,5 @@ resource "azurerm_data_factory_linked_service_postgresql" "test" { foo = "test1" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_sql_server_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go similarity index 73% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_sql_server_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go index ee1688f4ca4f..18f459efa391 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_linked_service_sql_server_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go @@ -1,4 +1,4 @@ -package datafactory +package tests import ( "fmt" @@ -7,17 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactoryLinkedServiceSQLServer_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryLinkedServiceSQLServer_basic(ri, acceptance.Location()) - config2 := testAccAzureRMDataFactoryLinkedServiceSQLServer_update(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_linked_service_sql_server.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_sql_server", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,32 +21,28 @@ func TestAccAzureRMDataFactoryLinkedServiceSQLServer_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceSQLServerDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryLinkedServiceSQLServer_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServiceSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "3"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "2"), - resource.TestCheckResourceAttr(resourceName, "description", "test description"), - resource.TestCheckResourceAttrSet(resourceName, "connection_string"), + testCheckAzureRMDataFactoryLinkedServiceSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "connection_string"), ), }, { - Config: config2, + Config: testAccAzureRMDataFactoryLinkedServiceSQLServer_update(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServiceSQLServerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "3"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "2"), - resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "1"), - resource.TestCheckResourceAttr(resourceName, "description", "test description 2"), - resource.TestCheckResourceAttrSet(resourceName, "connection_string"), + testCheckAzureRMDataFactoryLinkedServiceSQLServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description 2"), + resource.TestCheckResourceAttrSet(data.ResourceName, "connection_string"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -113,7 +105,7 @@ func testCheckAzureRMDataFactoryLinkedServiceSQLServerDestroy(s *terraform.State return nil } -func testAccAzureRMDataFactoryLinkedServiceSQLServer_basic(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServiceSQLServer_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -144,10 +136,10 @@ resource "azurerm_data_factory_linked_service_sql_server" "test" { bar = "test2" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryLinkedServiceSQLServer_update(rInt int, location string) string { +func testAccAzureRMDataFactoryLinkedServiceSQLServer_update(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -178,5 +170,5 @@ resource "azurerm_data_factory_linked_service_sql_server" "test" { foo = "test1" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_pipeline_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_pipeline_test.go similarity index 72% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_pipeline_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_pipeline_test.go index 0b05c983e3de..c2ca472a77d7 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_pipeline_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_pipeline_test.go @@ -1,4 +1,4 @@ -package datafactory +package tests import ( "fmt" @@ -6,17 +6,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactoryPipeline_basic(t *testing.T) { - resourceName := "azurerm_data_factory_pipeline.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMDataFactoryPipeline_basic(ri, location) + data := acceptance.BuildTestData(t, "azurerm_data_factory_pipeline", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,26 +20,20 @@ func TestAccAzureRMDataFactoryPipeline_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryPipelineDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryPipeline_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryPipelineExists(resourceName), + testCheckAzureRMDataFactoryPipelineExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactoryPipeline_update(t *testing.T) { - resourceName := "azurerm_data_factory_pipeline.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMDataFactoryPipeline_update1(ri, location) - config2 := testAccAzureRMDataFactoryPipeline_update2(ri, location) + data := acceptance.BuildTestData(t, "azurerm_data_factory_pipeline", "test") + config := testAccAzureRMDataFactoryPipeline_update1(data) + config2 := testAccAzureRMDataFactoryPipeline_update2(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,28 +43,24 @@ func TestAccAzureRMDataFactoryPipeline_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryPipelineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "1"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "3"), - resource.TestCheckResourceAttr(resourceName, "description", "test description"), - resource.TestCheckResourceAttr(resourceName, "variables.%", "2"), + testCheckAzureRMDataFactoryPipelineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), + resource.TestCheckResourceAttr(data.ResourceName, "variables.%", "2"), ), }, { Config: config2, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryPipelineExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), - resource.TestCheckResourceAttr(resourceName, "annotations.#", "2"), - resource.TestCheckResourceAttr(resourceName, "description", "test description2"), - resource.TestCheckResourceAttr(resourceName, "variables.%", "3"), + testCheckAzureRMDataFactoryPipelineExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description2"), + resource.TestCheckResourceAttr(data.ResourceName, "variables.%", "3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -129,7 +115,7 @@ func testCheckAzureRMDataFactoryPipelineExists(resourceName string) resource.Tes } } -func testAccAzureRMDataFactoryPipeline_basic(rInt int, location string) string { +func testAccAzureRMDataFactoryPipeline_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -147,10 +133,10 @@ resource "azurerm_data_factory_pipeline" "test" { resource_group_name = "${azurerm_resource_group.test.name}" data_factory_name = "${azurerm_data_factory.test.name}" } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryPipeline_update1(rInt int, location string) string { +func testAccAzureRMDataFactoryPipeline_update1(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -179,10 +165,10 @@ resource "azurerm_data_factory_pipeline" "test" { bar = "test2" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryPipeline_update2(rInt int, location string) string { +func testAccAzureRMDataFactoryPipeline_update2(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -213,5 +199,5 @@ resource "azurerm_data_factory_pipeline" "test" { baz = "test3" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_test.go similarity index 61% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_test.go index 672f0d6b4b84..763ce7b01362 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_test.go @@ -1,4 +1,4 @@ -package datafactory +package tests import ( "fmt" @@ -7,16 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactory_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactory_basic(ri, acceptance.Location()) - resourceName := "azurerm_data_factory.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,24 +21,18 @@ func TestAccAzureRMDataFactory_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactory_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryExists(resourceName), + testCheckAzureRMDataFactoryExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactory_tags(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactory_tags(ri, acceptance.Location()) - resourceName := "azurerm_data_factory.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -49,27 +40,20 @@ func TestAccAzureRMDataFactory_tags(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactory_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), + testCheckAzureRMDataFactoryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactory_tagsUpdated(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactory_tags(ri, acceptance.Location()) - updatedConfig := testAccAzureRMDataFactory_tagsUpdated(ri, acceptance.Location()) - resourceName := "azurerm_data_factory.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -77,35 +61,29 @@ func TestAccAzureRMDataFactory_tagsUpdated(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactory_tags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), + testCheckAzureRMDataFactoryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), ), }, { - Config: updatedConfig, + Config: testAccAzureRMDataFactory_tagsUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "production"), - resource.TestCheckResourceAttr(resourceName, "tags.updated", "true"), + testCheckAzureRMDataFactoryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.updated", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactory_identity(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactory_identity(ri, acceptance.Location()) - resourceName := "azurerm_data_factory.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,28 +91,22 @@ func TestAccAzureRMDataFactory_identity(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactory_identity(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "identity.#"), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.type"), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.principal_id"), - resource.TestCheckResourceAttrSet(resourceName, "identity.0.tenant_id"), + testCheckAzureRMDataFactoryExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.#"), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.type"), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.principal_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "identity.0.tenant_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactory_disappears(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactory_basic(ri, acceptance.Location()) - resourceName := "azurerm_data_factory.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -142,10 +114,10 @@ func TestAccAzureRMDataFactory_disappears(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactory_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryExists(resourceName), - testCheckAzureRMDataFactoryDisappears(resourceName), + testCheckAzureRMDataFactoryExists(data.ResourceName), + testCheckAzureRMDataFactoryDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -154,10 +126,7 @@ func TestAccAzureRMDataFactory_disappears(t *testing.T) { } func TestAccAzureRMDataFactory_github(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactory_github(ri, acceptance.Location()) - config2 := testAccAzureRMDataFactory_githubUpdated(ri, acceptance.Location()) - resourceName := "azurerm_data_factory.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -165,32 +134,28 @@ func TestAccAzureRMDataFactory_github(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactory_github(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "github_configuration.0.account_name", fmt.Sprintf("acctestGH-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "github_configuration.0.git_url", "https://github.com/terraform-providers/"), - resource.TestCheckResourceAttr(resourceName, "github_configuration.0.repository_name", "terraform-provider-azurerm"), - resource.TestCheckResourceAttr(resourceName, "github_configuration.0.branch_name", "master"), - resource.TestCheckResourceAttr(resourceName, "github_configuration.0.root_folder", "/"), + testCheckAzureRMDataFactoryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "github_configuration.0.account_name", fmt.Sprintf("acctestGH-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "github_configuration.0.git_url", "https://github.com/terraform-providers/"), + resource.TestCheckResourceAttr(data.ResourceName, "github_configuration.0.repository_name", "terraform-provider-azurerm"), + resource.TestCheckResourceAttr(data.ResourceName, "github_configuration.0.branch_name", "master"), + resource.TestCheckResourceAttr(data.ResourceName, "github_configuration.0.root_folder", "/"), ), }, { - Config: config2, + Config: testAccAzureRMDataFactory_githubUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "github_configuration.0.account_name", fmt.Sprintf("acctestGitHub-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "github_configuration.0.git_url", "https://github.com/terraform-providers/"), - resource.TestCheckResourceAttr(resourceName, "github_configuration.0.repository_name", "terraform-provider-azuread"), - resource.TestCheckResourceAttr(resourceName, "github_configuration.0.branch_name", "stable-website"), - resource.TestCheckResourceAttr(resourceName, "github_configuration.0.root_folder", "/azuread"), + testCheckAzureRMDataFactoryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "github_configuration.0.account_name", fmt.Sprintf("acctestGitHub-%d", data.RandomInteger)), + resource.TestCheckResourceAttr(data.ResourceName, "github_configuration.0.git_url", "https://github.com/terraform-providers/"), + resource.TestCheckResourceAttr(data.ResourceName, "github_configuration.0.repository_name", "terraform-provider-azuread"), + resource.TestCheckResourceAttr(data.ResourceName, "github_configuration.0.branch_name", "stable-website"), + resource.TestCheckResourceAttr(data.ResourceName, "github_configuration.0.root_folder", "/azuread"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -279,7 +244,7 @@ func testCheckAzureRMDataFactoryDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDataFactory_basic(rInt int, location string) string { +func testAccAzureRMDataFactory_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -291,10 +256,10 @@ resource "azurerm_data_factory" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDataFactory_tags(rInt int, location string) string { +func testAccAzureRMDataFactory_tags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -310,10 +275,10 @@ resource "azurerm_data_factory" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDataFactory_tagsUpdated(rInt int, location string) string { +func testAccAzureRMDataFactory_tagsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -330,10 +295,10 @@ resource "azurerm_data_factory" "test" { updated = "true" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDataFactory_identity(rInt int, location string) string { +func testAccAzureRMDataFactory_identity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -349,10 +314,10 @@ resource "azurerm_data_factory" "test" { type = "SystemAssigned" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDataFactory_github(rInt int, location string) string { +func testAccAzureRMDataFactory_github(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -372,10 +337,10 @@ resource "azurerm_data_factory" "test" { account_name = "acctestGH-%d" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactory_githubUpdated(rInt int, location string) string { +func testAccAzureRMDataFactory_githubUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -395,5 +360,5 @@ resource "azurerm_data_factory" "test" { account_name = "acctestGitHub-%d" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } diff --git a/azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_trigger_schedule_test.go similarity index 79% rename from azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule_test.go rename to azurerm/internal/services/datafactory/tests/resource_arm_data_factory_trigger_schedule_test.go index 6adcc428442f..20748e8e94a8 100644 --- a/azurerm/internal/services/datafactory/resource_arm_data_factory_trigger_schedule_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_trigger_schedule_test.go @@ -1,4 +1,4 @@ -package datafactory +package tests import ( "fmt" @@ -8,16 +8,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMDataFactoryTriggerSchedule_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMDataFactoryTriggerSchedule_basic(ri, acceptance.Location()) - resourceName := "azurerm_data_factory_trigger_schedule.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_trigger_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,27 +22,20 @@ func TestAccAzureRMDataFactoryTriggerSchedule_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryTriggerScheduleDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryTriggerSchedule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryTriggerScheduleExists(resourceName), + testCheckAzureRMDataFactoryTriggerScheduleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMDataFactoryTriggerSchedule_complete(t *testing.T) { - ri := tf.AccRandTimeInt() loc, _ := time.LoadLocation("UTC") endTime := time.Now().UTC().Add(time.Hour * 7).In(loc).Format("2006-01-02T15:04:00Z07:00") - config := testAccAzureRMDataFactoryTriggerSchedule_basic(ri, acceptance.Location()) - config2 := testAccAzureRMDataFactoryTriggerSchedule_update(ri, acceptance.Location(), endTime) - resourceName := "azurerm_data_factory_trigger_schedule.test" + data := acceptance.BuildTestData(t, "azurerm_data_factory_trigger_schedule", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -53,27 +43,19 @@ func TestAccAzureRMDataFactoryTriggerSchedule_complete(t *testing.T) { CheckDestroy: testCheckAzureRMDataFactoryTriggerScheduleDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMDataFactoryTriggerSchedule_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryTriggerScheduleExists(resourceName), + testCheckAzureRMDataFactoryTriggerScheduleExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: config2, + Config: testAccAzureRMDataFactoryTriggerSchedule_update(data, endTime), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryTriggerScheduleExists(resourceName), + testCheckAzureRMDataFactoryTriggerScheduleExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -136,7 +118,7 @@ func testCheckAzureRMDataFactoryTriggerScheduleDestroy(s *terraform.State) error return nil } -func testAccAzureRMDataFactoryTriggerSchedule_basic(rInt int, location string) string { +func testAccAzureRMDataFactoryTriggerSchedule_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -167,10 +149,10 @@ resource "azurerm_data_factory_trigger_schedule" "test" { annotations = ["test1", "test2", "test3"] } -`, rInt, location, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDataFactoryTriggerSchedule_update(rInt int, location string, endTime string) string { +func testAccAzureRMDataFactoryTriggerSchedule_update(data acceptance.TestData, endTime string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-datafactory-%d" @@ -205,5 +187,5 @@ resource "azurerm_data_factory_trigger_schedule" "test" { interval = 5 end_time = "%s" } -`, rInt, location, rInt, rInt, rInt, endTime) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, endTime) } diff --git a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go index c7d98b967848..6aa835577e5a 100644 --- a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_store_file_test.go @@ -13,7 +13,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datalake` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datalake" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) From 310f59c29cf197b20dfe14f3d612e7d837202109 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 12:28:53 -0800 Subject: [PATCH 152/203] databricks: switching to the new test structure --- .../resource_arm_databricks_workspace.go | 4 +- .../resource_arm_databricks_workspace_test.go | 83 ++++++++----------- 2 files changed, 37 insertions(+), 50 deletions(-) rename azurerm/internal/services/databricks/{ => tests}/resource_arm_databricks_workspace_test.go (71%) diff --git a/azurerm/internal/services/databricks/resource_arm_databricks_workspace.go b/azurerm/internal/services/databricks/resource_arm_databricks_workspace.go index 22afad1ff207..23f608829f4b 100644 --- a/azurerm/internal/services/databricks/resource_arm_databricks_workspace.go +++ b/azurerm/internal/services/databricks/resource_arm_databricks_workspace.go @@ -42,7 +42,7 @@ func resourceArmDatabricksWorkspace() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateDatabricksWorkspaceName, + ValidateFunc: ValidateDatabricksWorkspaceName, }, "location": azure.SchemaLocation(), @@ -225,7 +225,7 @@ func resourceArmDatabricksWorkspaceDelete(d *schema.ResourceData, meta interface return nil } -func validateDatabricksWorkspaceName(i interface{}, k string) (warnings []string, errors []error) { +func ValidateDatabricksWorkspaceName(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(string) if !ok { errors = append(errors, fmt.Errorf("expected %q type to be string", k)) diff --git a/azurerm/internal/services/databricks/resource_arm_databricks_workspace_test.go b/azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go similarity index 71% rename from azurerm/internal/services/databricks/resource_arm_databricks_workspace_test.go rename to azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go index 5be6ac19924e..5cf579131b62 100644 --- a/azurerm/internal/services/databricks/resource_arm_databricks_workspace_test.go +++ b/azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go @@ -1,4 +1,4 @@ -package databricks +package tests import ( "fmt" @@ -7,10 +7,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks` ) func TestAzureRMDatabrickWorkspaceName(t *testing.T) { @@ -57,7 +57,7 @@ func TestAzureRMDatabrickWorkspaceName(t *testing.T) { } for _, tc := range cases { - _, errors := validateDatabricksWorkspaceName(tc.Value, "test") + _, errors := databricks.ValidateDatabricksWorkspaceName(tc.Value, "test") hasErrors := len(errors) > 0 if hasErrors && !tc.ShouldError { @@ -71,8 +71,7 @@ func TestAzureRMDatabrickWorkspaceName(t *testing.T) { } func TestAccAzureRMDatabricksWorkspace_basic(t *testing.T) { - resourceName := "azurerm_databricks_workspace.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,17 +79,13 @@ func TestAccAzureRMDatabricksWorkspace_basic(t *testing.T) { CheckDestroy: testCheckAzureRMDatabricksWorkspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDatabricksWorkspace_basic(ri, acceptance.Location()), + Config: testAccAzureRMDatabricksWorkspace_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDatabricksWorkspaceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "managed_resource_group_id"), + testCheckAzureRMDatabricksWorkspaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -101,9 +96,7 @@ func TestAccAzureRMDatabricksWorkspace_requiresImport(t *testing.T) { return } - resourceName := "azurerm_databricks_workspace.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -111,13 +104,13 @@ func TestAccAzureRMDatabricksWorkspace_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMDatabricksWorkspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDatabricksWorkspace_basic(ri, location), + Config: testAccAzureRMDatabricksWorkspace_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDatabricksWorkspaceExists(resourceName), + testCheckAzureRMDatabricksWorkspaceExists(data.ResourceName), ), }, { - Config: testAccAzureRMDatabricksWorkspace_requiresImport(ri, location), + Config: testAccAzureRMDatabricksWorkspace_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_databricks_workspace"), }, }, @@ -125,9 +118,7 @@ func TestAccAzureRMDatabricksWorkspace_requiresImport(t *testing.T) { } func TestAccAzureRMDatabricksWorkspace_complete(t *testing.T) { - resourceName := "azurerm_databricks_workspace.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -135,31 +126,27 @@ func TestAccAzureRMDatabricksWorkspace_complete(t *testing.T) { CheckDestroy: testCheckAzureRMDatabricksWorkspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDatabricksWorkspace_complete(ri, location), + Config: testAccAzureRMDatabricksWorkspace_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDatabricksWorkspaceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "managed_resource_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "managed_resource_group_name"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.Environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.Pricing", "Standard"), + testCheckAzureRMDatabricksWorkspaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Pricing", "Standard"), ), }, { - Config: testAccAzureRMDatabricksWorkspace_completeUpdate(ri, location), + Config: testAccAzureRMDatabricksWorkspace_completeUpdate(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDatabricksWorkspaceExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "managed_resource_group_id"), - resource.TestCheckResourceAttrSet(resourceName, "managed_resource_group_name"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Pricing", "Standard"), + testCheckAzureRMDatabricksWorkspaceExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Pricing", "Standard"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -217,7 +204,7 @@ func testCheckAzureRMDatabricksWorkspaceDestroy(s *terraform.State) error { return nil } -func testAccAzureRMDatabricksWorkspace_basic(rInt int, location string) string { +func testAccAzureRMDatabricksWorkspace_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -230,11 +217,11 @@ resource "azurerm_databricks_workspace" "test" { location = "${azurerm_resource_group.test.location}" sku = "standard" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDatabricksWorkspace_requiresImport(rInt int, location string) string { - template := testAccAzureRMDatabricksWorkspace_basic(rInt, location) +func testAccAzureRMDatabricksWorkspace_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMDatabricksWorkspace_basic(data) return fmt.Sprintf(` %s @@ -247,7 +234,7 @@ resource "azurerm_databricks_workspace" "import" { `, template) } -func testAccAzureRMDatabricksWorkspace_complete(rInt int, location string) string { +func testAccAzureRMDatabricksWorkspace_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -266,10 +253,10 @@ resource "azurerm_databricks_workspace" "test" { Pricing = "Standard" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMDatabricksWorkspace_completeUpdate(rInt int, location string) string { +func testAccAzureRMDatabricksWorkspace_completeUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -287,5 +274,5 @@ resource "azurerm_databricks_workspace" "test" { Pricing = "Standard" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } From 0a9df22e691e70cf886a3156b0b5d41f5da9f3eb Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 12:36:18 -0800 Subject: [PATCH 153/203] cosmos: switching to the new test structure --- .../data_source_cosmos_db_account_test.go | 147 --- .../resource_arm_cosmosdb_account_test.go | 1009 ----------------- .../data_source_cosmos_db_account_test.go | 142 +++ ...urce_arm_cosmosdb_account_failover_test.go | 69 +- .../resource_arm_cosmosdb_account_test.go | 886 +++++++++++++++ ...ce_arm_cosmosdb_cassandra_keyspace_test.go | 66 +- ...urce_arm_cosmosdb_mongo_collection_test.go | 117 +- ...source_arm_cosmosdb_mongo_database_test.go | 37 +- ...esource_arm_cosmosdb_sql_container_test.go | 68 +- ...resource_arm_cosmosdb_sql_database_test.go | 51 +- .../resource_arm_cosmosdb_table_test.go | 51 +- .../resource_arm_databricks_workspace_test.go | 2 +- 12 files changed, 1200 insertions(+), 1445 deletions(-) delete mode 100644 azurerm/internal/services/cosmos/data_source_cosmos_db_account_test.go delete mode 100644 azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_test.go create mode 100644 azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go rename azurerm/internal/services/cosmos/{ => tests}/resource_arm_cosmosdb_account_failover_test.go (78%) create mode 100644 azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_test.go rename azurerm/internal/services/cosmos/{ => tests}/resource_arm_cosmosdb_cassandra_keyspace_test.go (67%) rename azurerm/internal/services/cosmos/{ => tests}/resource_arm_cosmosdb_mongo_collection_test.go (62%) rename azurerm/internal/services/cosmos/{ => tests}/resource_arm_cosmosdb_mongo_database_test.go (77%) rename azurerm/internal/services/cosmos/{ => tests}/resource_arm_cosmosdb_sql_container_test.go (71%) rename azurerm/internal/services/cosmos/{ => tests}/resource_arm_cosmosdb_sql_database_test.go (70%) rename azurerm/internal/services/cosmos/{ => tests}/resource_arm_cosmosdb_table_test.go (71%) diff --git a/azurerm/internal/services/cosmos/data_source_cosmos_db_account_test.go b/azurerm/internal/services/cosmos/data_source_cosmos_db_account_test.go deleted file mode 100644 index e5b9b3d06d19..000000000000 --- a/azurerm/internal/services/cosmos/data_source_cosmos_db_account_test.go +++ /dev/null @@ -1,147 +0,0 @@ -package cosmos - -import ( - "fmt" - "testing" - - "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMCosmosDBAccount_boundedStaleness_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - dataSourceName := "data.azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDAtaSourceAzureRMCosmosDBAccount_boundedStaleness_complete(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(dataSourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(dataSourceName, "consistency_policy.0.max_interval_in_seconds", "10"), - resource.TestCheckResourceAttr(dataSourceName, "consistency_policy.0.max_staleness_prefix", "200"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMCosmosDBAccount_geoReplicated_customId(t *testing.T) { - ri := tf.AccRandTimeInt() - dataSourceName := "data.azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMCosmosDBAccount_geoReplicated_customId(ri, acceptance.Location(), acceptance.AltLocation()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(dataSourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 2), - resource.TestCheckResourceAttr(dataSourceName, "geo_location.0.location", acceptance.Location()), - resource.TestCheckResourceAttr(dataSourceName, "geo_location.1.location", acceptance.AltLocation()), - resource.TestCheckResourceAttr(dataSourceName, "geo_location.0.failover_priority", "0"), - resource.TestCheckResourceAttr(dataSourceName, "geo_location.1.failover_priority", "1"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMCosmosDBAccount_virtualNetworkFilter(t *testing.T) { - ri := tf.AccRandTimeInt() - dataSourceName := "data.azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMCosmosDBAccount_virtualNetworkFilter(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(dataSourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(dataSourceName, "is_virtual_network_filter_enabled", "true"), - resource.TestCheckResourceAttrSet(dataSourceName, "virtual_network_rule.0.id"), - resource.TestCheckResourceAttrSet(dataSourceName, "virtual_network_rule.1.id"), - ), - }, - }, - }) -} - -func TestAccDataSourceAzureRMCosmosDBAccount_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - dataSourceName := "data.azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMCosmosDBAccount_complete(ri, acceptance.Location(), acceptance.AltLocation()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(dataSourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 2), - resource.TestCheckResourceAttr(dataSourceName, "ip_range_filter", "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45/32,52.187.184.26,10.20.0.0/16"), - resource.TestCheckResourceAttr(dataSourceName, "enable_automatic_failover", "true"), - resource.TestCheckResourceAttr(dataSourceName, "enable_multiple_write_locations", "false"), - resource.TestCheckResourceAttr(dataSourceName, "geo_location.0.location", acceptance.Location()), - resource.TestCheckResourceAttr(dataSourceName, "geo_location.1.location", acceptance.AltLocation()), - resource.TestCheckResourceAttr(dataSourceName, "geo_location.0.failover_priority", "0"), - resource.TestCheckResourceAttr(dataSourceName, "geo_location.1.failover_priority", "1"), - ), - }, - }, - }) -} - -func testAccDAtaSourceAzureRMCosmosDBAccount_boundedStaleness_complete(rInt int, location string) string { - return fmt.Sprintf(` -%s - -data "azurerm_cosmosdb_account" "test" { - name = "${azurerm_cosmosdb_account.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, testAccAzureRMCosmosDBAccount_boundedStaleness_complete(rInt, location)) -} - -func testAccDataSourceAzureRMCosmosDBAccount_geoReplicated_customId(rInt int, location string, altLocation string) string { - return fmt.Sprintf(` -%s - -data "azurerm_cosmosdb_account" "test" { - name = "${azurerm_cosmosdb_account.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, testAccAzureRMCosmosDBAccount_geoReplicated_customId(rInt, location, altLocation)) -} - -func testAccDataSourceAzureRMCosmosDBAccount_complete(rInt int, location string, altLocation string) string { - return fmt.Sprintf(` -%s - -data "azurerm_cosmosdb_account" "test" { - name = "${azurerm_cosmosdb_account.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, testAccAzureRMCosmosDBAccount_complete(rInt, location, altLocation)) -} - -func testAccDataSourceAzureRMCosmosDBAccount_virtualNetworkFilter(rInt int, location string) string { - return fmt.Sprintf(` -%s - -data "azurerm_cosmosdb_account" "test" { - name = "${azurerm_cosmosdb_account.test.name}" - resource_group_name = "${azurerm_resource_group.test.name}" -} -`, testAccAzureRMCosmosDBAccount_virtualNetworkFilter(rInt, location)) -} diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_test.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_test.go deleted file mode 100644 index 2892c1a42f6e..000000000000 --- a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_test.go +++ /dev/null @@ -1,1009 +0,0 @@ -package cosmos - -import ( - "fmt" - "net/http" - "strconv" - "testing" - - "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" - "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/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" -) - -// TODO: refactor the test configs - -//consistency -func TestAccAzureRMCosmosDBAccount_eventualConsistency(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_basic(ri, acceptance.Location(), string(documentdb.Eventual), "", ""), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.Eventual), 1), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} -func TestAccAzureRMCosmosDBAccount_requiresImport(t *testing.T) { - if !features.ShouldResourcesBeImported() { - t.Skip("Skipping since resources aren't required to be imported") - return - } - - resourceName := "azurerm_cosmosdb_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_basic(ri, location, string(documentdb.Eventual), "", ""), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.Eventual), 1), - ), - }, - { - Config: testAccAzureRMCosmosDBAccount_requiresImport(ri, location, string(documentdb.Eventual), "", ""), - ExpectError: acceptance.RequiresImportError("azurerm_cosmosdb_account"), - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_session(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_basic(ri, acceptance.Location(), string(documentdb.Session), "", ""), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.Session), 1), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_strong(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_basic(ri, acceptance.Location(), string(documentdb.Strong), "", ""), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.Strong), 1), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_consistentPrefix(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_basic(ri, acceptance.Location(), string(documentdb.ConsistentPrefix), "", ""), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.ConsistentPrefix), 1), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_boundedStaleness(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_basic(ri, acceptance.Location(), string(documentdb.BoundedStaleness), "", ""), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_boundedStaleness_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_boundedStaleness_complete(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(resourceName, "consistency_policy.0.max_interval_in_seconds", "10"), - resource.TestCheckResourceAttr(resourceName, "consistency_policy.0.max_staleness_prefix", "200"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_consistency_change(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_basic(ri, acceptance.Location(), string(documentdb.Session), "", ""), - Check: checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.Session), 1), - }, - { - Config: testAccAzureRMCosmosDBAccount_basic(ri, acceptance.Location(), string(documentdb.BoundedStaleness), "", ""), - Check: checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -//DB kinds -func TestAccAzureRMCosmosDBAccount_mongoDB(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_mongoDB(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"), - resource.TestCheckResourceAttr(resourceName, "connection_strings.#", "4"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_capabilityGremlin(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_capabilityGremlin(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(resourceName, "kind", "GlobalDocumentDB"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_capabilityTable(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_capabilityTable(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(resourceName, "kind", "GlobalDocumentDB"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_capabilityCassandra(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_capabilityCassandra(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(resourceName, "kind", "GlobalDocumentDB"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_capabilityAggregationPipeline(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_capabilityAggregationPipeline(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(resourceName, "kind", "GlobalDocumentDB"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_capabilityMongo35(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_capabilityMongo34(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_capabilityUpdate(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"), - ), - }, - { - Config: testAccAzureRMCosmosDBAccount_capabilityMongo34(ri, acceptance.Location()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAbcAzureRMCosmosDBAccount_updatePropertiesAndLocation(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_basic(ri, acceptance.Location(), string(documentdb.Session), "", ""), - Check: checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.Session), 1), - }, - { - Config: testAccAzureRMCosmosDBAccount_geoReplicated_customId(ri, acceptance.Location(), acceptance.AltLocation()), - Check: checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 2), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -//replication -func TestAccAzureRMCosmosDBAccount_geoReplicated_customId(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_geoReplicated_customId(ri, acceptance.Location(), acceptance.AltLocation()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 2), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_geoReplicated_non_boundedStaleness_cp(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_geoReplicated_customConsistencyLevel(ri, acceptance.Location(), acceptance.AltLocation(), documentdb.Session), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.Session), 2), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_geoReplicated_add_remove(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - configBasic := testAccAzureRMCosmosDBAccount_basic(ri, acceptance.Location(), string(documentdb.BoundedStaleness), "", "") - configReplicated := testAccAzureRMCosmosDBAccount_geoReplicated_customId(ri, acceptance.Location(), acceptance.AltLocation()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: configBasic, - Check: checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - }, - { - Config: configReplicated, - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 2), - ), - }, - { - Config: configBasic, - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_geoReplicated_rename(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_geoReplicated(ri, acceptance.Location(), acceptance.AltLocation()), - Check: checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 2), - }, - { - Config: testAccAzureRMCosmosDBAccount_geoReplicated_customId(ri, acceptance.Location(), acceptance.AltLocation()), - Check: checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 2), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_virtualNetworkFilter(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_virtualNetworkFilter(ri, acceptance.Location()), - Check: checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 1), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -//basic --> complete ( -func TestAccAzureRMCosmosDBAccount_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_basic(ri, acceptance.Location(), string(documentdb.Session), "", ""), - Check: checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.Session), 1), - }, - { - Config: testAccAzureRMCosmosDBAccount_complete(ri, acceptance.Location(), acceptance.AltLocation()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 2), - resource.TestCheckResourceAttr(resourceName, "ip_range_filter", "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45/32,52.187.184.26,10.20.0.0/16"), - resource.TestCheckResourceAttr(resourceName, "enable_automatic_failover", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_emptyIpFilter(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_emptyIpFilter(ri, acceptance.Location(), acceptance.AltLocation()), - Check: resource.ComposeAggregateTestCheckFunc( - checkAccAzureRMCosmosDBAccount_basic(resourceName, acceptance.Location(), string(documentdb.BoundedStaleness), 2), - resource.TestCheckResourceAttr(resourceName, "ip_range_filter", ""), - resource.TestCheckResourceAttr(resourceName, "enable_automatic_failover", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func TestAccAzureRMCosmosDBAccount_multiMaster(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_account.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMCosmosDBAccount_multiMaster(ri, acceptance.Location(), acceptance.AltLocation()), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "geo_location.#", "2"), - resource.TestCheckResourceAttr(resourceName, "write_endpoints.#", "2"), - resource.TestCheckResourceAttr(resourceName, "enable_multiple_write_locations", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - }, - }) -} - -func testCheckAzureRMCosmosDBAccountDestroy(s *terraform.State) error { - conn := acceptance.AzureProvider.Meta().(*clients.Client).Cosmos.DatabaseClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - for _, rs := range s.RootModule().Resources { - if rs.Type != "azurerm_cosmosdb_account" { - continue - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := conn.Get(ctx, resourceGroup, name) - if err != nil { - return nil - } - - if resp.StatusCode != http.StatusNotFound { - return fmt.Errorf("CosmosDB Account still exists:\n%#v", resp) - } - } - - return nil -} - -func testCheckAzureRMCosmosDBAccountExists(resourceName string) resource.TestCheckFunc { - return func(s *terraform.State) error { - conn := acceptance.AzureProvider.Meta().(*clients.Client).Cosmos.DatabaseClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - - // Ensure we have enough information in state to look up in API - rs, ok := s.RootModule().Resources[resourceName] - if !ok { - return fmt.Errorf("Not found: %s", resourceName) - } - - name := rs.Primary.Attributes["name"] - resourceGroup := rs.Primary.Attributes["resource_group_name"] - - resp, err := conn.Get(ctx, resourceGroup, name) - if err != nil { - return fmt.Errorf("Bad: Get on cosmosAccountsClient: %+v", err) - } - - if resp.StatusCode == http.StatusNotFound { - return fmt.Errorf("Bad: CosmosDB Account '%s' (resource group: '%s') does not exist", name, resourceGroup) - } - - return nil - } -} - -func testAccAzureRMCosmosDBAccount_basic(rInt int, location string, consistency string, consistencyOptions string, additional string) string { - return fmt.Sprintf(` -resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" -} - -resource "azurerm_cosmosdb_account" "test" { - name = "acctest-%d" - location = "${azurerm_resource_group.test.location}" - resource_group_name = "${azurerm_resource_group.test.name}" - offer_type = "Standard" - - consistency_policy { - consistency_level = "%s" - - %s - } - - geo_location { - location = "${azurerm_resource_group.test.location}" - failover_priority = 0 - } - - %s -} -`, rInt, location, rInt, consistency, consistencyOptions, additional) -} - -func testAccAzureRMCosmosDBAccount_requiresImport(rInt int, location string, consistency string, consistencyOptions string, additional string) string { - template := testAccAzureRMCosmosDBAccount_basic(rInt, location, consistency, consistencyOptions, additional) - return fmt.Sprintf(` -%s - -resource "azurerm_cosmosdb_account" "import" { - name = "${azurerm_cosmosdb_account.test.name}" - location = "${azurerm_cosmosdb_account.test.location}" - resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" - offer_type = "Standard" - - consistency_policy { - consistency_level = "%s" - - %s - } - - geo_location { - location = "${azurerm_resource_group.test.location}" - failover_priority = 0 - } - - %s -} -`, template, consistency, consistencyOptions, additional) -} - -func testAccAzureRMCosmosDBAccount_boundedStaleness_complete(rInt int, location string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), ` - max_interval_in_seconds = 10 - max_staleness_prefix = 200 -`, "") -} - -func testAccAzureRMCosmosDBAccount_mongoDB(rInt int, location string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` - kind = "MongoDB" - `) -} - -func testAccAzureRMCosmosDBAccount_capabilityGremlin(rInt int, location string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` - kind = "GlobalDocumentDB" - - capabilities { - name = "EnableGremlin" - } - `) -} - -func testAccAzureRMCosmosDBAccount_capabilityTable(rInt int, location string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` - kind = "GlobalDocumentDB" - - capabilities { - name = "EnableTable" - } - `) -} - -func testAccAzureRMCosmosDBAccount_capabilityCassandra(rInt int, location string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` - kind = "GlobalDocumentDB" - - capabilities { - name = "EnableCassandra" - } - `) -} - -func testAccAzureRMCosmosDBAccount_capabilityAggregationPipeline(rInt int, location string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` - kind = "GlobalDocumentDB" - - capabilities { - name = "EnableAggregationPipeline" - } - `) -} - -func testAccAzureRMCosmosDBAccount_capabilityMongo34(rInt int, location string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` - kind = "MongoDB" - - capabilities { - name = "MongoDBv3.4" - } - `) -} - -func testAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(rInt int, location string) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` - kind = "MongoDB" - - capabilities { - name = "mongoEnableDocLevelTTL" - } - `) -} - -func testAccAzureRMCosmosDBAccount_geoReplicated(rInt int, location string, altLocation string) string { - co := ` - max_interval_in_seconds = 373 - max_staleness_prefix = 100001 -` - - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` - geo_location { - location = "%s" - failover_priority = 1 - } - - `, altLocation)) -} - -func testAccAzureRMCosmosDBAccount_multiMaster(rInt int, location string, altLocation string) string { - co := ` - max_interval_in_seconds = 373 - max_staleness_prefix = 100001 -` - - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` - enable_multiple_write_locations = true - - geo_location { - location = "%s" - failover_priority = 1 - } - - `, altLocation)) -} - -func testAccAzureRMCosmosDBAccount_geoReplicated_customId(rInt int, location string, altLocation string) string { - co := ` - max_interval_in_seconds = 373 - max_staleness_prefix = 100001 -` - - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` - geo_location { - prefix = "acctest-%d-custom-id" - location = "%s" - failover_priority = 1 - } - - `, rInt, altLocation)) -} - -func testAccAzureRMCosmosDBAccount_geoReplicated_customConsistencyLevel(rInt int, location string, altLocation string, cLevel documentdb.DefaultConsistencyLevel) string { - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(cLevel), "", fmt.Sprintf(` - geo_location { - prefix = "acctest-%d-custom-id" - location = "%s" - failover_priority = 1 - } - - `, rInt, altLocation)) -} - -func testAccAzureRMCosmosDBAccount_complete(rInt int, location string, altLocation string) string { - co := ` - max_interval_in_seconds = 373 - max_staleness_prefix = 100001 -` - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` - ip_range_filter = "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45/32,52.187.184.26,10.20.0.0/16" - enable_automatic_failover = true - - geo_location { - prefix = "acctest-%d-custom-id" - location = "%s" - failover_priority = 1 - } - `, rInt, altLocation)) -} - -func testAccAzureRMCosmosDBAccount_emptyIpFilter(rInt int, location string, altLocation string) string { - co := ` - max_interval_in_seconds = 373 - max_staleness_prefix = 100001 -` - - return testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` - ip_range_filter = "" - enable_automatic_failover = true - - geo_location { - prefix = "acctest-%d-custom-id" - location = "%s" - failover_priority = 1 - } - `, rInt, altLocation)) -} - -func testAccAzureRMCosmosDBAccount_virtualNetworkFilter(rInt int, location string) string { - vnetConfig := fmt.Sprintf(` -resource "azurerm_virtual_network" "test" { - name = "acctest-%[1]d" - resource_group_name = "${azurerm_resource_group.test.name}" - address_space = ["10.0.0.0/16"] - location = "${azurerm_resource_group.test.location}" - dns_servers = ["10.0.0.4", "10.0.0.5"] -} - -resource "azurerm_subnet" "subnet1" { - name = "acctest-%[1]d-1" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.1.0/24" - service_endpoints = ["Microsoft.AzureCosmosDB"] -} - -resource "azurerm_subnet" "subnet2" { - name = "acctest-%[1]d-2" - resource_group_name = "${azurerm_resource_group.test.name}" - virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "10.0.2.0/24" - service_endpoints = ["Microsoft.AzureCosmosDB"] -} -`, rInt) - - basic := testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.BoundedStaleness), "", ` - is_virtual_network_filter_enabled = true - - virtual_network_rule { - id = "${azurerm_subnet.subnet1.id}" - } - - virtual_network_rule { - id = "${azurerm_subnet.subnet2.id}" - } - `) - - return vnetConfig + basic -} - -func checkAccAzureRMCosmosDBAccount_basic(resourceName string, location string, consistency string, locationCount int) resource.TestCheckFunc { - return resource.ComposeTestCheckFunc( - testCheckAzureRMCosmosDBAccountExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "name"), - resource.TestCheckResourceAttrSet(resourceName, "resource_group_name"), - resource.TestCheckResourceAttr(resourceName, "location", azure.NormalizeLocation(location)), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttr(resourceName, "offer_type", string(documentdb.Standard)), - resource.TestCheckResourceAttr(resourceName, "consistency_policy.0.consistency_level", consistency), - resource.TestCheckResourceAttr(resourceName, "geo_location.#", strconv.Itoa(locationCount)), - resource.TestCheckResourceAttrSet(resourceName, "endpoint"), - resource.TestCheckResourceAttr(resourceName, "read_endpoints.#", strconv.Itoa(locationCount)), - resource.TestCheckResourceAttr(resourceName, "write_endpoints.#", "1"), - resource.TestCheckResourceAttr(resourceName, "enable_multiple_write_locations", "false"), - resource.TestCheckResourceAttrSet(resourceName, "primary_master_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_master_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_readonly_master_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_readonly_master_key"), - ) -} diff --git a/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go b/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go new file mode 100644 index 000000000000..70b3b1857ae6 --- /dev/null +++ b/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go @@ -0,0 +1,142 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMCosmosDBAccount_boundedStaleness_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDAtaSourceAzureRMCosmosDBAccount_boundedStaleness_complete(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "consistency_policy.0.max_interval_in_seconds", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "consistency_policy.0.max_staleness_prefix", "200"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMCosmosDBAccount_geoReplicated_customId(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMCosmosDBAccount_geoReplicated_customId(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 2), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.0.location", acceptance.Location()), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.1.location", acceptance.AltLocation()), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.0.failover_priority", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.1.failover_priority", "1"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMCosmosDBAccount_virtualNetworkFilter(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMCosmosDBAccount_virtualNetworkFilter(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "is_virtual_network_filter_enabled", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_rule.0.id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "virtual_network_rule.1.id"), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMCosmosDBAccount_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMCosmosDBAccount_complete(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 2), + resource.TestCheckResourceAttr(data.ResourceName, "ip_range_filter", "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45/32,52.187.184.26,10.20.0.0/16"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_automatic_failover", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_multiple_write_locations", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.0.location", acceptance.Location()), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.1.location", acceptance.AltLocation()), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.0.failover_priority", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.1.failover_priority", "1"), + ), + }, + }, + }) +} + +func testAccDAtaSourceAzureRMCosmosDBAccount_boundedStaleness_complete(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_cosmosdb_account" "test" { + name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, testAccAzureRMCosmosDBAccount_boundedStaleness_complete(data)) +} + +func testAccDataSourceAzureRMCosmosDBAccount_geoReplicated_customId(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_cosmosdb_account" "test" { + name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, testAccAzureRMCosmosDBAccount_geoReplicated_customId(data)) +} + +func testAccDataSourceAzureRMCosmosDBAccount_complete(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_cosmosdb_account" "test" { + name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, testAccAzureRMCosmosDBAccount_complete(data)) +} + +func testAccDataSourceAzureRMCosmosDBAccount_virtualNetworkFilter(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_cosmosdb_account" "test" { + name = "${azurerm_cosmosdb_account.test.name}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, testAccAzureRMCosmosDBAccount_virtualNetworkFilter(data)) +} diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_failover_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_failover_test.go similarity index 78% rename from azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_failover_test.go rename to azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_failover_test.go index 6743b1aa4f2a..344d0a79b765 100644 --- a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_account_failover_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_failover_test.go @@ -1,18 +1,16 @@ -package cosmos +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccAzureRMCosmosDBAccount_failover_boundedStaleness(t *testing.T) { - resourceName := "azurerm_cosmosdb_account.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCosmosDBAccount_failover_boundedStaleness(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + config := testAccAzureRMCosmosDBAccount_failover_boundedStaleness(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,8 +20,8 @@ func TestAccAzureRMCosmosDBAccount_failover_boundedStaleness(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCosmosDBAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "GlobalDocumentDB"), + testCheckAzureRMCosmosDBAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "GlobalDocumentDB"), ), }, }, @@ -31,8 +29,8 @@ func TestAccAzureRMCosmosDBAccount_failover_boundedStaleness(t *testing.T) { } func TestAccAzureRMCosmosDBAccount_failover_boundedStalenessComplete(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMCosmosDBAccount_failover_boundedStalenessComplete(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + config := testAccAzureRMCosmosDBAccount_failover_boundedStalenessComplete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,8 +48,8 @@ func TestAccAzureRMCosmosDBAccount_failover_boundedStalenessComplete(t *testing. } func TestAccAzureRMCosmosDBAccount_failover_eventualConsistency(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMCosmosDBAccount_failover_eventualConsistency(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + config := testAccAzureRMCosmosDBAccount_failover_eventualConsistency(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -69,9 +67,8 @@ func TestAccAzureRMCosmosDBAccount_failover_eventualConsistency(t *testing.T) { } func TestAccAzureRMCosmosDBAccount_failover_mongoDB(t *testing.T) { - resourceName := "azurerm_cosmosdb_account.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCosmosDBAccount_failover_mongoDB(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + config := testAccAzureRMCosmosDBAccount_failover_mongoDB(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,8 +78,8 @@ func TestAccAzureRMCosmosDBAccount_failover_mongoDB(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCosmosDBAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "MongoDB"), + testCheckAzureRMCosmosDBAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "MongoDB"), ), }, }, @@ -90,8 +87,8 @@ func TestAccAzureRMCosmosDBAccount_failover_mongoDB(t *testing.T) { } func TestAccAzureRMCosmosDBAccount_failover_session(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMCosmosDBAccount_failover_session(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + config := testAccAzureRMCosmosDBAccount_failover_session(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -109,8 +106,8 @@ func TestAccAzureRMCosmosDBAccount_failover_session(t *testing.T) { } func TestAccAzureRMCosmosDBAccount_failover_strong(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMCosmosDBAccount_failover_strong(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + config := testAccAzureRMCosmosDBAccount_failover_strong(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -128,8 +125,8 @@ func TestAccAzureRMCosmosDBAccount_failover_strong(t *testing.T) { } func TestAccAzureRMCosmosDBAccount_failover_geoReplicated(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMCosmosDBAccount_failover_geoReplicated(ri, acceptance.Location(), acceptance.AltLocation()) + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + config := testAccAzureRMCosmosDBAccount_failover_geoReplicated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -146,7 +143,7 @@ func TestAccAzureRMCosmosDBAccount_failover_geoReplicated(t *testing.T) { }) } -func testAccAzureRMCosmosDBAccount_failover_boundedStaleness(rInt int, location string) string { +func testAccAzureRMCosmosDBAccount_failover_boundedStaleness(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -168,10 +165,10 @@ resource "azurerm_cosmosdb_account" "test" { priority = 0 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCosmosDBAccount_failover_boundedStalenessComplete(rInt int, location string) string { +func testAccAzureRMCosmosDBAccount_failover_boundedStalenessComplete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -195,10 +192,10 @@ resource "azurerm_cosmosdb_account" "test" { priority = 0 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCosmosDBAccount_failover_eventualConsistency(rInt int, location string) string { +func testAccAzureRMCosmosDBAccount_failover_eventualConsistency(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -220,10 +217,10 @@ resource "azurerm_cosmosdb_account" "test" { priority = 0 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCosmosDBAccount_failover_session(rInt int, location string) string { +func testAccAzureRMCosmosDBAccount_failover_session(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -245,10 +242,10 @@ resource "azurerm_cosmosdb_account" "test" { priority = 0 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCosmosDBAccount_failover_mongoDB(rInt int, location string) string { +func testAccAzureRMCosmosDBAccount_failover_mongoDB(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -271,10 +268,10 @@ resource "azurerm_cosmosdb_account" "test" { priority = 0 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCosmosDBAccount_failover_strong(rInt int, location string) string { +func testAccAzureRMCosmosDBAccount_failover_strong(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -296,10 +293,10 @@ resource "azurerm_cosmosdb_account" "test" { priority = 0 } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCosmosDBAccount_failover_geoReplicated(rInt int, location string, altLocation string) string { +func testAccAzureRMCosmosDBAccount_failover_geoReplicated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -328,5 +325,5 @@ resource "azurerm_cosmosdb_account" "test" { priority = 1 } } -`, rInt, location, rInt, altLocation) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Secondary) } diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_test.go new file mode 100644 index 000000000000..1e7214442a85 --- /dev/null +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_account_test.go @@ -0,0 +1,886 @@ +package tests + +import ( + "fmt" + "net/http" + "strconv" + "testing" + + "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" + "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/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" +) + +// TODO: refactor the test configs + +//consistency +func TestAccAzureRMCosmosDBAccount_eventualConsistency(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Eventual), "", ""), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Eventual), 1), + ), + }, + data.ImportStep(), + }, + }) +} +func TestAccAzureRMCosmosDBAccount_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Eventual), "", ""), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Eventual), 1), + ), + }, + { + Config: testAccAzureRMCosmosDBAccount_requiresImport(data, string(documentdb.Eventual), "", ""), + ExpectError: acceptance.RequiresImportError("azurerm_cosmosdb_account"), + }, + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_session(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Session), "", ""), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Session), 1), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_strong(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Strong), "", ""), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Strong), 1), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_consistentPrefix(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.ConsistentPrefix), "", ""), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.ConsistentPrefix), 1), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_boundedStaleness(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", ""), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_boundedStaleness_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_boundedStaleness_complete(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "consistency_policy.0.max_interval_in_seconds", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "consistency_policy.0.max_staleness_prefix", "200"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_consistency_change(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Session), "", ""), + Check: checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Session), 1), + }, + { + Config: testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", ""), + Check: checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + }, + data.ImportStep(), + }, + }) +} + +//DB kinds +func TestAccAzureRMCosmosDBAccount_mongoDB(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_mongoDB(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "MongoDB"), + resource.TestCheckResourceAttr(data.ResourceName, "connection_strings.#", "4"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityGremlin(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityGremlin(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "GlobalDocumentDB"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityTable(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityTable(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "GlobalDocumentDB"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityCassandra(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityCassandra(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "GlobalDocumentDB"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityAggregationPipeline(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityAggregationPipeline(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "GlobalDocumentDB"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityMongo35(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityMongo34(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "MongoDB"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "MongoDB"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_capabilityUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "MongoDB"), + ), + }, + { + Config: testAccAzureRMCosmosDBAccount_capabilityMongo34(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "MongoDB"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAbcAzureRMCosmosDBAccount_updatePropertiesAndLocation(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Session), "", ""), + Check: checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Session), 1), + }, + { + Config: testAccAzureRMCosmosDBAccount_geoReplicated_customId(data), + Check: checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 2), + }, + data.ImportStep(), + }, + }) +} + +//replication +func TestAccAzureRMCosmosDBAccount_geoReplicated_customId(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_geoReplicated_customId(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 2), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_geoReplicated_non_boundedStaleness_cp(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_geoReplicated_customConsistencyLevel(data, documentdb.Session), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Session), 2), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_geoReplicated_add_remove(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + configBasic := testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", "") + configReplicated := testAccAzureRMCosmosDBAccount_geoReplicated_customId(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: configBasic, + Check: checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + }, + { + Config: configReplicated, + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 2), + ), + }, + { + Config: configBasic, + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_geoReplicated_rename(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_geoReplicated(data), + Check: checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 2), + }, + { + Config: testAccAzureRMCosmosDBAccount_geoReplicated_customId(data), + Check: checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 2), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_virtualNetworkFilter(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_virtualNetworkFilter(data), + Check: checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 1), + }, + data.ImportStep(), + }, + }) +} + +//basic --> complete ( +func TestAccAzureRMCosmosDBAccount_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Session), "", ""), + Check: checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Session), 1), + }, + { + Config: testAccAzureRMCosmosDBAccount_complete(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 2), + resource.TestCheckResourceAttr(data.ResourceName, "ip_range_filter", "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45/32,52.187.184.26,10.20.0.0/16"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_automatic_failover", "true"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_emptyIpFilter(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_emptyIpFilter(data), + Check: resource.ComposeAggregateTestCheckFunc( + checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 2), + resource.TestCheckResourceAttr(data.ResourceName, "ip_range_filter", ""), + resource.TestCheckResourceAttr(data.ResourceName, "enable_automatic_failover", "true"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosDBAccount_multiMaster(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosDBAccountDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosDBAccount_multiMaster(data), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "write_endpoints.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_multiple_write_locations", "true"), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMCosmosDBAccountDestroy(s *terraform.State) error { + conn := acceptance.AzureProvider.Meta().(*clients.Client).Cosmos.DatabaseClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_cosmosdb_account" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(ctx, resourceGroup, name) + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("CosmosDB Account still exists:\n%#v", resp) + } + } + + return nil +} + +func testCheckAzureRMCosmosDBAccountExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := acceptance.AzureProvider.Meta().(*clients.Client).Cosmos.DatabaseClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(ctx, resourceGroup, name) + if err != nil { + return fmt.Errorf("Bad: Get on cosmosAccountsClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: CosmosDB Account '%s' (resource group: '%s') does not exist", name, resourceGroup) + } + + return nil + } +} + +func testAccAzureRMCosmosDBAccount_basic(data acceptance.TestData, consistency string, consistencyOptions string, additional string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_cosmosdb_account" "test" { + name = "acctest-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + offer_type = "Standard" + + consistency_policy { + consistency_level = "%s" + + %s + } + + geo_location { + location = "${azurerm_resource_group.test.location}" + failover_priority = 0 + } + + %s +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, consistency, consistencyOptions, additional) +} + +func testAccAzureRMCosmosDBAccount_requiresImport(data acceptance.TestData, consistency string, consistencyOptions string, additional string) string { + template := testAccAzureRMCosmosDBAccount_basic(data, consistency, consistencyOptions, additional) + return fmt.Sprintf(` +%s + +resource "azurerm_cosmosdb_account" "import" { + name = "${azurerm_cosmosdb_account.test.name}" + location = "${azurerm_cosmosdb_account.test.location}" + resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" + offer_type = "Standard" + + consistency_policy { + consistency_level = "%s" + + %s + } + + geo_location { + location = "${azurerm_resource_group.test.location}" + failover_priority = 0 + } + + %s +} +`, template, consistency, consistencyOptions, additional) +} + +func testAccAzureRMCosmosDBAccount_boundedStaleness_complete(data acceptance.TestData) string { + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), ` + max_interval_in_seconds = 10 + max_staleness_prefix = 200 +`, "") +} + +func testAccAzureRMCosmosDBAccount_mongoDB(data acceptance.TestData) string { + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", ` + kind = "MongoDB" + `) +} + +func testAccAzureRMCosmosDBAccount_capabilityGremlin(data acceptance.TestData) string { + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", ` + kind = "GlobalDocumentDB" + + capabilities { + name = "EnableGremlin" + } + `) +} + +func testAccAzureRMCosmosDBAccount_capabilityTable(data acceptance.TestData) string { + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", ` + kind = "GlobalDocumentDB" + + capabilities { + name = "EnableTable" + } + `) +} + +func testAccAzureRMCosmosDBAccount_capabilityCassandra(data acceptance.TestData) string { + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", ` + kind = "GlobalDocumentDB" + + capabilities { + name = "EnableCassandra" + } + `) +} + +func testAccAzureRMCosmosDBAccount_capabilityAggregationPipeline(data acceptance.TestData) string { + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", ` + kind = "GlobalDocumentDB" + + capabilities { + name = "EnableAggregationPipeline" + } + `) +} + +func testAccAzureRMCosmosDBAccount_capabilityMongo34(data acceptance.TestData) string { + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", ` + kind = "MongoDB" + + capabilities { + name = "MongoDBv3.4" + } + `) +} + +func testAccAzureRMCosmosDBAccount_capabilityDocLevelTTL(data acceptance.TestData) string { + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", ` + kind = "MongoDB" + + capabilities { + name = "mongoEnableDocLevelTTL" + } + `) +} + +func testAccAzureRMCosmosDBAccount_geoReplicated(data acceptance.TestData) string { + co := ` + max_interval_in_seconds = 373 + max_staleness_prefix = 100001 +` + + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` + geo_location { + location = "%s" + failover_priority = 1 + } + + `, data.Locations.Secondary)) +} + +func testAccAzureRMCosmosDBAccount_multiMaster(data acceptance.TestData) string { + co := ` + max_interval_in_seconds = 373 + max_staleness_prefix = 100001 +` + + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` + enable_multiple_write_locations = true + + geo_location { + location = "%s" + failover_priority = 1 + } + + `, data.Locations.Secondary)) +} + +func testAccAzureRMCosmosDBAccount_geoReplicated_customId(data acceptance.TestData) string { + co := ` + max_interval_in_seconds = 373 + max_staleness_prefix = 100001 +` + + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` + geo_location { + prefix = "acctest-%d-custom-id" + location = "%s" + failover_priority = 1 + } + + `, data.RandomInteger, data.Locations.Secondary)) +} + +func testAccAzureRMCosmosDBAccount_geoReplicated_customConsistencyLevel(data acceptance.TestData, cLevel documentdb.DefaultConsistencyLevel) string { + return testAccAzureRMCosmosDBAccount_basic(data, string(cLevel), "", fmt.Sprintf(` + geo_location { + prefix = "acctest-%d-custom-id" + location = "%s" + failover_priority = 1 + } + + `, data.RandomInteger, data.Locations.Secondary)) +} + +func testAccAzureRMCosmosDBAccount_complete(data acceptance.TestData) string { + co := ` + max_interval_in_seconds = 373 + max_staleness_prefix = 100001 +` + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` + ip_range_filter = "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45/32,52.187.184.26,10.20.0.0/16" + enable_automatic_failover = true + + geo_location { + prefix = "acctest-%d-custom-id" + location = "%s" + failover_priority = 1 + } + `, data.RandomInteger, data.Locations.Secondary)) +} + +func testAccAzureRMCosmosDBAccount_emptyIpFilter(data acceptance.TestData) string { + co := ` + max_interval_in_seconds = 373 + max_staleness_prefix = 100001 +` + + return testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), co, fmt.Sprintf(` + ip_range_filter = "" + enable_automatic_failover = true + + geo_location { + prefix = "acctest-%d-custom-id" + location = "%s" + failover_priority = 1 + } + `, data.RandomInteger, data.Locations.Secondary)) +} + +func testAccAzureRMCosmosDBAccount_virtualNetworkFilter(data acceptance.TestData) string { + vnetConfig := fmt.Sprintf(` +resource "azurerm_virtual_network" "test" { + name = "acctest-%[1]d" + resource_group_name = "${azurerm_resource_group.test.name}" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.test.location}" + dns_servers = ["10.0.0.4", "10.0.0.5"] +} + +resource "azurerm_subnet" "subnet1" { + name = "acctest-%[1]d-1" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.1.0/24" + service_endpoints = ["Microsoft.AzureCosmosDB"] +} + +resource "azurerm_subnet" "subnet2" { + name = "acctest-%[1]d-2" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" + service_endpoints = ["Microsoft.AzureCosmosDB"] +} +`, data.RandomInteger) + + basic := testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), "", ` + is_virtual_network_filter_enabled = true + + virtual_network_rule { + id = "${azurerm_subnet.subnet1.id}" + } + + virtual_network_rule { + id = "${azurerm_subnet.subnet2.id}" + } + `) + + return vnetConfig + basic +} + +func checkAccAzureRMCosmosDBAccount_basic(data acceptance.TestData, consistency string, locationCount int) resource.TestCheckFunc { + return resource.ComposeTestCheckFunc( + testCheckAzureRMCosmosDBAccountExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttr(data.ResourceName, "location", azure.NormalizeLocation(data.Locations.Primary)), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "offer_type", string(documentdb.Standard)), + resource.TestCheckResourceAttr(data.ResourceName, "consistency_policy.0.consistency_level", consistency), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.#", strconv.Itoa(locationCount)), + resource.TestCheckResourceAttrSet(data.ResourceName, "endpoint"), + resource.TestCheckResourceAttr(data.ResourceName, "read_endpoints.#", strconv.Itoa(locationCount)), + resource.TestCheckResourceAttr(data.ResourceName, "write_endpoints.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "enable_multiple_write_locations", "false"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_master_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_master_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_readonly_master_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_readonly_master_key"), + ) +} diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_cassandra_keyspace_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_cassandra_keyspace_test.go similarity index 67% rename from azurerm/internal/services/cosmos/resource_arm_cosmosdb_cassandra_keyspace_test.go rename to azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_cassandra_keyspace_test.go index 2c2dc3dc6499..4afe84b46681 100644 --- a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_cassandra_keyspace_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_cassandra_keyspace_test.go @@ -1,4 +1,4 @@ -package cosmos +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMCosmosDbCassandraKeyspace_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_cassandra_keyspace.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_keyspace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,23 +21,18 @@ func TestAccAzureRMCosmosDbCassandraKeyspace_basic(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbCassandraKeyspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbCassandraKeyspace_basic(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbCassandraKeyspace_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbCassandraKeyspaceExists(resourceName), + testCheckAzureRMCosmosDbCassandraKeyspaceExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCosmosDbCassandraKeyspace_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_cassandra_keyspace.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_keyspace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -47,24 +40,19 @@ func TestAccAzureRMCosmosDbCassandraKeyspace_complete(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbCassandraKeyspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbCassandraKeyspace_throughput(ri, acceptance.Location(), 700), + Config: testAccAzureRMCosmosDbCassandraKeyspace_throughput(data, 700), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbCassandraKeyspaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "throughput", "700"), + testCheckAzureRMCosmosDbCassandraKeyspaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "700"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCosmosDbCassandraKeyspace_update(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_cassandra_keyspace.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_keyspace", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -72,29 +60,21 @@ func TestAccAzureRMCosmosDbCassandraKeyspace_update(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbCassandraKeyspaceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbCassandraKeyspace_throughput(ri, acceptance.Location(), 700), + Config: testAccAzureRMCosmosDbCassandraKeyspace_throughput(data, 700), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbCassandraKeyspaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "throughput", "700"), + testCheckAzureRMCosmosDbCassandraKeyspaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "700"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMCosmosDbCassandraKeyspace_throughput(ri, acceptance.Location(), 1700), + Config: testAccAzureRMCosmosDbCassandraKeyspace_throughput(data, 1700), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbCassandraKeyspaceExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "throughput", "1700"), + testCheckAzureRMCosmosDbCassandraKeyspaceExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "1700"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -155,7 +135,7 @@ func testCheckAzureRMCosmosDbCassandraKeyspaceExists(resourceName string) resour } } -func testAccAzureRMCosmosDbCassandraKeyspace_basic(rInt int, location string) string { +func testAccAzureRMCosmosDbCassandraKeyspace_basic(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -164,10 +144,10 @@ resource "azurerm_cosmosdb_cassandra_keyspace" "test" { resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" account_name = "${azurerm_cosmosdb_account.test.name}" } -`, testAccAzureRMCosmosDBAccount_capabilityCassandra(rInt, location), rInt) +`, testAccAzureRMCosmosDBAccount_capabilityCassandra(data), data.RandomInteger) } -func testAccAzureRMCosmosDbCassandraKeyspace_throughput(rInt int, location string, throughput int) string { +func testAccAzureRMCosmosDbCassandraKeyspace_throughput(data acceptance.TestData, throughput int) string { return fmt.Sprintf(` %[1]s @@ -178,5 +158,5 @@ resource "azurerm_cosmosdb_cassandra_keyspace" "test" { throughput = %[3]d } -`, testAccAzureRMCosmosDBAccount_capabilityCassandra(rInt, location), rInt, throughput) +`, testAccAzureRMCosmosDBAccount_capabilityCassandra(data), data.RandomInteger, throughput) } diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_collection_test.go similarity index 62% rename from azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection_test.go rename to azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_collection_test.go index 1b6177f57001..2e367f08ec70 100644 --- a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_collection_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_collection_test.go @@ -1,4 +1,4 @@ -package cosmos +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMCosmosDbMongoCollection_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_mongo_collection.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_mongo_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,24 +21,19 @@ func TestAccAzureRMCosmosDbMongoCollection_basic(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbMongoCollectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbMongoCollection_basic(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbMongoCollection_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbMongoCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "throughput", "400"), + testCheckAzureRMCosmosDbMongoCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "400"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCosmosDbMongoCollection_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_mongo_collection.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_mongo_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -48,25 +41,20 @@ func TestAccAzureRMCosmosDbMongoCollection_complete(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbMongoCollectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbMongoCollection_complete(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbMongoCollection_complete(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbMongoCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "shard_key", "seven"), - resource.TestCheckResourceAttr(resourceName, "default_ttl_seconds", "707"), + testCheckAzureRMCosmosDbMongoCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "shard_key", "seven"), + resource.TestCheckResourceAttr(data.ResourceName, "default_ttl_seconds", "707"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCosmosDbMongoCollection_update(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_mongo_collection.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_mongo_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,43 +62,34 @@ func TestAccAzureRMCosmosDbMongoCollection_update(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbMongoCollectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbMongoCollection_basic(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbMongoCollection_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbMongoCollectionExists(resourceName), + testCheckAzureRMCosmosDbMongoCollectionExists(data.ResourceName), ), }, { - Config: testAccAzureRMCosmosDbMongoCollection_complete(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbMongoCollection_complete(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbMongoCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "shard_key", "seven"), - resource.TestCheckResourceAttr(resourceName, "default_ttl_seconds", "707"), + testCheckAzureRMCosmosDbMongoCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "shard_key", "seven"), + resource.TestCheckResourceAttr(data.ResourceName, "default_ttl_seconds", "707"), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMCosmosDbMongoCollection_updated(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbMongoCollection_updated(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbMongoCollectionExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_ttl_seconds", "70707"), + testCheckAzureRMCosmosDbMongoCollectionExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_ttl_seconds", "70707"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCosmosDbMongoCollection_throughput(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_mongo_collection.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_mongo_collection", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -118,38 +97,26 @@ func TestAccAzureRMCosmosDbMongoCollection_throughput(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbMongoCollectionDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbMongoCollection_throughput(ri, acceptance.Location(), 700), + Config: testAccAzureRMCosmosDbMongoCollection_throughput(data, 700), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbMongoCollectionExists(resourceName), + testCheckAzureRMCosmosDbMongoCollectionExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMCosmosDbMongoCollection_throughput(ri, acceptance.Location(), 1400), + Config: testAccAzureRMCosmosDbMongoCollection_throughput(data, 1400), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbMongoCollectionExists(resourceName), + testCheckAzureRMCosmosDbMongoCollectionExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMCosmosDbMongoCollection_basic(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbMongoCollection_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbMongoCollectionExists(resourceName), + testCheckAzureRMCosmosDbMongoCollectionExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -212,7 +179,7 @@ func testCheckAzureRMCosmosDbMongoCollectionExists(resourceName string) resource } } -func testAccAzureRMCosmosDbMongoCollection_basic(rInt int, location string) string { +func testAccAzureRMCosmosDbMongoCollection_basic(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -222,10 +189,10 @@ resource "azurerm_cosmosdb_mongo_collection" "test" { account_name = "${azurerm_cosmosdb_mongo_database.test.account_name}" database_name = "${azurerm_cosmosdb_mongo_database.test.name}" } -`, testAccAzureRMCosmosDbMongoDatabase_basic(rInt, location), rInt) +`, testAccAzureRMCosmosDbMongoDatabase_basic(data), data.RandomInteger) } -func testAccAzureRMCosmosDbMongoCollection_complete(rInt int, location string) string { +func testAccAzureRMCosmosDbMongoCollection_complete(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -238,10 +205,10 @@ resource "azurerm_cosmosdb_mongo_collection" "test" { shard_key = "seven" default_ttl_seconds = 707 } -`, testAccAzureRMCosmosDbMongoDatabase_basic(rInt, location), rInt) +`, testAccAzureRMCosmosDbMongoDatabase_basic(data), data.RandomInteger) } -func testAccAzureRMCosmosDbMongoCollection_updated(rInt int, location string) string { +func testAccAzureRMCosmosDbMongoCollection_updated(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -254,10 +221,10 @@ resource "azurerm_cosmosdb_mongo_collection" "test" { shard_key = "seven" default_ttl_seconds = 70707 } -`, testAccAzureRMCosmosDbMongoDatabase_basic(rInt, location), rInt) +`, testAccAzureRMCosmosDbMongoDatabase_basic(data), data.RandomInteger) } -func testAccAzureRMCosmosDbMongoCollection_throughput(rInt int, location string, throughput int) string { +func testAccAzureRMCosmosDbMongoCollection_throughput(data acceptance.TestData, throughput int) string { return fmt.Sprintf(` %[1]s @@ -269,5 +236,5 @@ resource "azurerm_cosmosdb_mongo_collection" "test" { throughput = %[3]d } -`, testAccAzureRMCosmosDbMongoDatabase_basic(rInt, location), rInt, throughput) +`, testAccAzureRMCosmosDbMongoDatabase_basic(data), data.RandomInteger, throughput) } diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_database_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_database_test.go similarity index 77% rename from azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_database_test.go rename to azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_database_test.go index 3bfa31658f60..0a0ee730ddad 100644 --- a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_mongo_database_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_mongo_database_test.go @@ -1,4 +1,4 @@ -package cosmos +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMCosmosDbMongoDatabase_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_mongo_database.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_mongo_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,23 +21,18 @@ func TestAccAzureRMCosmosDbMongoDatabase_basic(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbMongoDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbMongoDatabase_basic(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbMongoDatabase_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbMongoDatabaseExists(resourceName), + testCheckAzureRMCosmosDbMongoDatabaseExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCosmosDbMongoDatabase_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_mongo_database.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_mongo_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -47,16 +40,12 @@ func TestAccAzureRMCosmosDbMongoDatabase_complete(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbMongoDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbMongoDatabase_complete(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbMongoDatabase_complete(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbMongoDatabaseExists(resourceName), + testCheckAzureRMCosmosDbMongoDatabaseExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -117,7 +106,7 @@ func testCheckAzureRMCosmosDbMongoDatabaseExists(resourceName string) resource.T } } -func testAccAzureRMCosmosDbMongoDatabase_basic(rInt int, location string) string { +func testAccAzureRMCosmosDbMongoDatabase_basic(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -126,10 +115,10 @@ resource "azurerm_cosmosdb_mongo_database" "test" { resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" account_name = "${azurerm_cosmosdb_account.test.name}" } -`, testAccAzureRMCosmosDBAccount_mongoDB(rInt, location), rInt) +`, testAccAzureRMCosmosDBAccount_mongoDB(data), data.RandomInteger) } -func testAccAzureRMCosmosDbMongoDatabase_complete(rInt int, location string) string { +func testAccAzureRMCosmosDbMongoDatabase_complete(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -139,5 +128,5 @@ resource "azurerm_cosmosdb_mongo_database" "test" { account_name = "${azurerm_cosmosdb_account.test.name}" throughput = 700 } -`, testAccAzureRMCosmosDBAccount_mongoDB(rInt, location), rInt) +`, testAccAzureRMCosmosDBAccount_mongoDB(data), data.RandomInteger) } diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_container_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_container_test.go similarity index 71% rename from azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_container_test.go rename to azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_container_test.go index 59b0ee621449..c9a47e65ba34 100644 --- a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_container_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_container_test.go @@ -1,4 +1,4 @@ -package cosmos +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMCosmosDbSqlContainer_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_sql_container.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_sql_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,23 +22,18 @@ func TestAccAzureRMCosmosDbSqlContainer_basic(t *testing.T) { Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbSqlContainer_basic(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbSqlContainer_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbSqlContainerExists(resourceName), + testCheckAzureRMCosmosDbSqlContainerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCosmosDbSqlContainer_complete(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_sql_container.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_sql_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -49,23 +42,18 @@ func TestAccAzureRMCosmosDbSqlContainer_complete(t *testing.T) { Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbSqlContainer_complete(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbSqlContainer_complete(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbSqlContainerExists(resourceName), + testCheckAzureRMCosmosDbSqlContainerExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCosmosDbSqlContainer_update(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_sql_container.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_sql_container", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -74,30 +62,22 @@ func TestAccAzureRMCosmosDbSqlContainer_update(t *testing.T) { Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbSqlContainer_complete(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbSqlContainer_complete(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbSqlContainerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "throughput", "600"), + testCheckAzureRMCosmosDbSqlContainerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "600"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { - Config: testAccAzureRMCosmosDbSqlContainer_update(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbSqlContainer_update(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbSqlContainerExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "throughput", "400"), + testCheckAzureRMCosmosDbSqlContainerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "400"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -160,7 +140,7 @@ func testCheckAzureRMCosmosDbSqlContainerExists(resourceName string) resource.Te } } -func testAccAzureRMCosmosDbSqlContainer_basic(rInt int, location string) string { +func testAccAzureRMCosmosDbSqlContainer_basic(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -172,10 +152,10 @@ resource "azurerm_cosmosdb_sql_container" "test" { } -`, testAccAzureRMCosmosDbSqlDatabase_basic(rInt, location), rInt) +`, testAccAzureRMCosmosDbSqlDatabase_basic(data), data.RandomInteger) } -func testAccAzureRMCosmosDbSqlContainer_complete(rInt int, location string) string { +func testAccAzureRMCosmosDbSqlContainer_complete(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -191,10 +171,10 @@ resource "azurerm_cosmosdb_sql_container" "test" { throughput = 600 } -`, testAccAzureRMCosmosDbSqlDatabase_basic(rInt, location), rInt) +`, testAccAzureRMCosmosDbSqlDatabase_basic(data), data.RandomInteger) } -func testAccAzureRMCosmosDbSqlContainer_update(rInt int, location string) string { +func testAccAzureRMCosmosDbSqlContainer_update(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -210,5 +190,5 @@ resource "azurerm_cosmosdb_sql_container" "test" { throughput = 400 } -`, testAccAzureRMCosmosDbSqlDatabase_basic(rInt, location), rInt) +`, testAccAzureRMCosmosDbSqlDatabase_basic(data), data.RandomInteger) } diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_database_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_database_test.go similarity index 70% rename from azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_database_test.go rename to azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_database_test.go index 7646fc2cf7f9..671a4b1e2c60 100644 --- a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_sql_database_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_sql_database_test.go @@ -1,4 +1,4 @@ -package cosmos +package tests import ( "fmt" @@ -8,15 +8,13 @@ import ( "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMCosmosDbSqlDatabase_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_sql_database.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_sql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,23 +22,18 @@ func TestAccAzureRMCosmosDbSqlDatabase_basic(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbSqlDatabaseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbSqlDatabase_basic(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbSqlDatabase_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbSqlDatabaseExists(resourceName), + testCheckAzureRMCosmosDbSqlDatabaseExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCosmosDbSqlDatabase_update(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_sql_database.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_sql_database", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -49,30 +42,22 @@ func TestAccAzureRMCosmosDbSqlDatabase_update(t *testing.T) { Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbSqlDatabase_throughput(ri, acceptance.Location(), 700), + Config: testAccAzureRMCosmosDbSqlDatabase_throughput(data, 700), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "throughput", "700"), + testCheckAzureRMCosmosDbSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "700"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { - Config: testAccAzureRMCosmosDbSqlDatabase_throughput(ri, acceptance.Location(), 1700), + Config: testAccAzureRMCosmosDbSqlDatabase_throughput(data, 1700), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbSqlDatabaseExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "throughput", "1700"), + testCheckAzureRMCosmosDbSqlDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "1700"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -133,7 +118,7 @@ func testCheckAzureRMCosmosDbSqlDatabaseExists(resourceName string) resource.Tes } } -func testAccAzureRMCosmosDbSqlDatabase_basic(rInt int, location string) string { +func testAccAzureRMCosmosDbSqlDatabase_basic(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -142,10 +127,10 @@ resource "azurerm_cosmosdb_sql_database" "test" { resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" account_name = "${azurerm_cosmosdb_account.test.name}" } -`, testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.Eventual), "", ""), rInt) +`, testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Eventual), "", ""), data.RandomInteger) } -func testAccAzureRMCosmosDbSqlDatabase_throughput(rInt int, location string, throughput int) string { +func testAccAzureRMCosmosDbSqlDatabase_throughput(data acceptance.TestData, throughput int) string { return fmt.Sprintf(` %[1]s @@ -155,5 +140,5 @@ resource "azurerm_cosmosdb_sql_database" "test" { account_name = "${azurerm_cosmosdb_account.test.name}" throughput = %[3]d } -`, testAccAzureRMCosmosDBAccount_basic(rInt, location, string(documentdb.Eventual), "", ""), rInt, throughput) +`, testAccAzureRMCosmosDBAccount_basic(data, string(documentdb.Eventual), "", ""), data.RandomInteger, throughput) } diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_table_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_table_test.go similarity index 71% rename from azurerm/internal/services/cosmos/resource_arm_cosmosdb_table_test.go rename to azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_table_test.go index 1a5e8f9b8aca..c3e21bb62de3 100644 --- a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_table_test.go +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_table_test.go @@ -1,4 +1,4 @@ -package cosmos +package tests import ( "fmt" @@ -7,15 +7,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMCosmosDbTable_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_table.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,23 +21,18 @@ func TestAccAzureRMCosmosDbTable_basic(t *testing.T) { CheckDestroy: testCheckAzureRMCosmosDbTableDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbTable_basic(ri, acceptance.Location()), + Config: testAccAzureRMCosmosDbTable_basic(data), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbTableExists(resourceName), + testCheckAzureRMCosmosDbTableExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCosmosDbTable_update(t *testing.T) { - ri := tf.AccRandTimeInt() - resourceName := "azurerm_cosmosdb_table.test" + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_table", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -48,30 +41,22 @@ func TestAccAzureRMCosmosDbTable_update(t *testing.T) { Steps: []resource.TestStep{ { - Config: testAccAzureRMCosmosDbTable_throughput(ri, acceptance.Location(), 700), + Config: testAccAzureRMCosmosDbTable_throughput(data, 700), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "throughput", "700"), + testCheckAzureRMCosmosDbTableExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "700"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { - Config: testAccAzureRMCosmosDbTable_throughput(ri, acceptance.Location(), 1700), + Config: testAccAzureRMCosmosDbTable_throughput(data, 1700), Check: resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMCosmosDbTableExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "throughput", "1700"), + testCheckAzureRMCosmosDbTableExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "1700"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -132,7 +117,7 @@ func testCheckAzureRMCosmosDbTableExists(resourceName string) resource.TestCheck } } -func testAccAzureRMCosmosDbTable_basic(rInt int, location string) string { +func testAccAzureRMCosmosDbTable_basic(data acceptance.TestData) string { return fmt.Sprintf(` %[1]s @@ -141,10 +126,10 @@ resource "azurerm_cosmosdb_table" "test" { resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" account_name = "${azurerm_cosmosdb_account.test.name}" } -`, testAccAzureRMCosmosDBAccount_capabilityTable(rInt, location), rInt) +`, testAccAzureRMCosmosDBAccount_capabilityTable(data), data.RandomInteger) } -func testAccAzureRMCosmosDbTable_throughput(rInt int, location string, throughput int) string { +func testAccAzureRMCosmosDbTable_throughput(data acceptance.TestData, throughput int) string { return fmt.Sprintf(` %[1]s @@ -154,5 +139,5 @@ resource "azurerm_cosmosdb_table" "test" { account_name = "${azurerm_cosmosdb_account.test.name}" throughput = %[3]d } -`, testAccAzureRMCosmosDBAccount_capabilityTable(rInt, location), rInt, throughput) +`, testAccAzureRMCosmosDBAccount_capabilityTable(data), data.RandomInteger, throughput) } diff --git a/azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go b/azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go index 5cf579131b62..c8e316e57eae 100644 --- a/azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go +++ b/azurerm/internal/services/databricks/tests/resource_arm_databricks_workspace_test.go @@ -10,7 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks" ) func TestAzureRMDatabrickWorkspaceName(t *testing.T) { From 9d649a0c721e394c167d1904fdc6a26e3756a3f9 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 13:14:46 -0800 Subject: [PATCH 154/203] containers: switching to the new test structure --- .../data_source_container_registry.go | 2 +- .../data_source_container_registry_test.go | 46 - .../data_source_kubernetes_cluster_test.go | 847 ------------------ .../resource_arm_container_registry.go | 6 +- ...resource_arm_container_registry_migrate.go | 2 +- ...resource_arm_container_registry_webhook.go | 2 +- .../resource_arm_container_service.go | 12 +- .../data_source_container_registry_test.go | 42 + .../data_source_kubernetes_cluster_test.go | 804 +++++++++++++++++ ..._source_kubernetes_service_version_test.go | 36 +- .../resource_arm_container_group_test.go | 537 +++++------ ...rce_arm_container_registry_migrate_test.go | 9 +- .../resource_arm_container_registry_test.go | 281 +++--- ...rce_arm_container_registry_webhook_test.go | 174 ++-- .../resource_arm_container_service_test.go | 55 +- ...urce_arm_kubernetes_cluster_addons_test.go | 234 ++--- ...source_arm_kubernetes_cluster_auth_test.go | 158 ++-- ...urce_arm_kubernetes_cluster_legacy_test.go | 31 +- ...rce_arm_kubernetes_cluster_network_test.go | 301 ++----- ...e_arm_kubernetes_cluster_node_pool_test.go | 367 +++----- ...ource_arm_kubernetes_cluster_other_test.go | 352 +++----- ...rce_arm_kubernetes_cluster_scaling_test.go | 122 +-- .../resource_arm_kubernetes_cluster_test.go | 2 +- 23 files changed, 1900 insertions(+), 2522 deletions(-) delete mode 100644 azurerm/internal/services/containers/data_source_container_registry_test.go delete mode 100644 azurerm/internal/services/containers/data_source_kubernetes_cluster_test.go create mode 100644 azurerm/internal/services/containers/tests/data_source_container_registry_test.go create mode 100644 azurerm/internal/services/containers/tests/data_source_kubernetes_cluster_test.go rename azurerm/internal/services/containers/{ => tests}/data_source_kubernetes_service_version_test.go (57%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_container_group_test.go (54%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_container_registry_migrate_test.go (94%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_container_registry_test.go (69%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_container_registry_webhook_test.go (71%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_container_service_test.go (83%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_kubernetes_cluster_addons_test.go (64%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_kubernetes_cluster_auth_test.go (57%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_kubernetes_cluster_legacy_test.go (72%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_kubernetes_cluster_network_test.go (70%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_kubernetes_cluster_node_pool_test.go (75%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_kubernetes_cluster_other_test.go (55%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_kubernetes_cluster_scaling_test.go (55%) rename azurerm/internal/services/containers/{ => tests}/resource_arm_kubernetes_cluster_test.go (99%) diff --git a/azurerm/internal/services/containers/data_source_container_registry.go b/azurerm/internal/services/containers/data_source_container_registry.go index d2bfdf96bc8c..50d4e9d41bf2 100644 --- a/azurerm/internal/services/containers/data_source_container_registry.go +++ b/azurerm/internal/services/containers/data_source_container_registry.go @@ -25,7 +25,7 @@ func dataSourceArmContainerRegistry() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureRMContainerRegistryName, + ValidateFunc: ValidateAzureRMContainerRegistryName, }, "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), diff --git a/azurerm/internal/services/containers/data_source_container_registry_test.go b/azurerm/internal/services/containers/data_source_container_registry_test.go deleted file mode 100644 index 3488b7f2fa57..000000000000 --- a/azurerm/internal/services/containers/data_source_container_registry_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package containers - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func TestAccDataSourceAzureRMContainerRegistry_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccDataSourceAzureRMContainerRegistry_basic(ri) - - dataSourceName := "data.azurerm_container_registry.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMContainerRegistryDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "name"), - resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"), - resource.TestCheckResourceAttrSet(dataSourceName, "location"), - resource.TestCheckResourceAttrSet(dataSourceName, "admin_enabled"), - resource.TestCheckResourceAttrSet(dataSourceName, "login_server"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMContainerRegistry_basic(rInt int) string { - return fmt.Sprintf(` -%s - -data "azurerm_container_registry" "test" { - name = "${azurerm_container_registry.test.name}" - resource_group_name = "${azurerm_container_registry.test.resource_group_name}" -} -`, testAccAzureRMContainerRegistry_basicManaged(rInt, acceptance.Location(), "Basic")) -} diff --git a/azurerm/internal/services/containers/data_source_kubernetes_cluster_test.go b/azurerm/internal/services/containers/data_source_kubernetes_cluster_test.go deleted file mode 100644 index ea3c09749d6a..000000000000 --- a/azurerm/internal/services/containers/data_source_kubernetes_cluster_test.go +++ /dev/null @@ -1,847 +0,0 @@ -package containers - -import ( - "fmt" - "os" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" -) - -func testAccDataSourceAzureRMKubernetesCluster_basic(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_basicConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "role_based_access_control.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "role_based_access_control.0.enabled", "false"), - resource.TestCheckResourceAttrSet(dataSourceName, "kube_config.0.client_key"), - resource.TestCheckResourceAttrSet(dataSourceName, "kube_config.0.client_certificate"), - resource.TestCheckResourceAttrSet(dataSourceName, "kube_config.0.cluster_ca_certificate"), - resource.TestCheckResourceAttrSet(dataSourceName, "kube_config.0.host"), - resource.TestCheckResourceAttrSet(dataSourceName, "kube_config.0.username"), - resource.TestCheckResourceAttrSet(dataSourceName, "kube_config.0.password"), - resource.TestCheckResourceAttr(dataSourceName, "kube_admin_config.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "kube_admin_config_raw", ""), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_privateLink(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - - privateIpAddressCdir := "10.0.0.0/8" - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccAzureRMKubernetesCluster_privateLinkConfig(ri, clientId, clientSecret, location, privateIpAddressCdir, true), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "private_fqdn"), - resource.TestCheckResourceAttr(resourceName, "api_server_authorized_ip_ranges.#", "1"), - resource.TestCheckResourceAttr(resourceName, "private_link_enabled", "true"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControl(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlConfig(ri, location, clientId, clientSecret), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "role_based_access_control.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "role_based_access_control.0.enabled", "true"), - resource.TestCheckResourceAttr(dataSourceName, "role_based_access_control.0.azure_active_directory.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "kube_admin_config.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "kube_admin_config_raw", ""), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlAAD(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - tenantId := os.Getenv("ARM_TENANT_ID") - location := acceptance.Location() - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(ri, location, clientId, clientSecret, tenantId), - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "role_based_access_control.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "role_based_access_control.0.enabled", "true"), - resource.TestCheckResourceAttr(dataSourceName, "role_based_access_control.0.azure_active_directory.#", "1"), - resource.TestCheckResourceAttrSet(dataSourceName, "role_based_access_control.0.azure_active_directory.0.client_app_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "role_based_access_control.0.azure_active_directory.0.server_app_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "role_based_access_control.0.azure_active_directory.0.tenant_id"), - resource.TestCheckResourceAttr(dataSourceName, "kube_admin_config.#", "1"), - resource.TestCheckResourceAttrSet(dataSourceName, "kube_admin_config_raw"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_internalNetwork(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_internalNetworkConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "agent_pool_profile.0.vnet_subnet_id"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzure(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "agent_pool_profile.0.vnet_subnet_id"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_plugin", "azure"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_plugin"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.dns_service_ip"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.docker_bridge_cidr"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.service_cidr"), - ), - }, - }, - }) -} -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicy(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "agent_pool_profile.0.vnet_subnet_id"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_plugin", "azure"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_policy", "calico"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_plugin"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_policy"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.dns_service_ip"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.docker_bridge_cidr"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.service_cidr"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicy(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "agent_pool_profile.0.vnet_subnet_id"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_plugin", "azure"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_policy", "azure"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_plugin"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_policy"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.dns_service_ip"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.docker_bridge_cidr"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.service_cidr"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureComplete(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCompleteConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "agent_pool_profile.0.vnet_subnet_id"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_plugin", "azure"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_plugin"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.dns_service_ip"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.docker_bridge_cidr"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.service_cidr"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyComplete(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyCompleteConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "agent_pool_profile.0.vnet_subnet_id"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_plugin", "azure"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_policy", "calico"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_plugin"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_policy"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.dns_service_ip"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.docker_bridge_cidr"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.service_cidr"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyComplete(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyCompleteConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "agent_pool_profile.0.vnet_subnet_id"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_plugin", "azure"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_policy", "azure"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_plugin"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_policy"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.dns_service_ip"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.docker_bridge_cidr"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.service_cidr"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenet(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "agent_pool_profile.0.vnet_subnet_id"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_plugin", "kubenet"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_plugin"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.dns_service_ip"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.docker_bridge_cidr"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.service_cidr"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetComplete(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetCompleteConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "agent_pool_profile.0.vnet_subnet_id"), - resource.TestCheckResourceAttr(dataSourceName, "network_profile.0.network_plugin", "kubenet"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.network_plugin"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.dns_service_ip"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.docker_bridge_cidr"), - resource.TestCheckResourceAttrSet(dataSourceName, "network_profile.0.service_cidr"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_addOnProfileOMS(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_addOnProfileOMSConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "addon_profile.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "addon_profile.0.oms_agent.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "addon_profile.0.oms_agent.0.enabled", "true"), - resource.TestCheckResourceAttrSet(dataSourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_addOnProfileKubeDashboard(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_addOnProfileKubeDashboardConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "addon_profile.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "addon_profile.0.kube_dashboard.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "addon_profile.0.kube_dashboard.0.enabled", "false"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_addOnProfileAzurePolicy(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - config := testAccDataSourceAzureRMKubernetesCluster_addOnProfileAzurePolicyConfig(ri, clientId, clientSecret, acceptance.Location()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.azure_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.azure_policy.0.enabled", "true"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_addOnProfileRouting(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() - config := testAccDataSourceAzureRMKubernetesCluster_addOnProfileRoutingConfig(ri, clientId, clientSecret, location) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "addon_profile.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "addon_profile.0.http_application_routing.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "addon_profile.0.http_application_routing.0.enabled", "true"), - resource.TestCheckResourceAttrSet(dataSourceName, "addon_profile.0.http_application_routing.0.http_application_routing_zone_name"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_autoscalingNoAvailabilityZones(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - - config := testAccDataSourceAzureRMKubernetesCluster_autoScalingNoAvailabilityZonesConfig(ri, clientId, clientSecret, acceptance.Location()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.min_count", "1"), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.max_count", "2"), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.type", "VirtualMachineScaleSets"), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.enable_auto_scaling", "true"), - resource.TestCheckNoResourceAttr(dataSourceName, "agent_pool_profile.0.availability_zones"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_autoscalingWithAvailabilityZones(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - - config := testAccDataSourceAzureRMKubernetesCluster_autoScalingWithAvailabilityZonesConfig(ri, clientId, clientSecret, acceptance.Location()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.min_count", "1"), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.max_count", "2"), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.type", "VirtualMachineScaleSets"), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.enable_auto_scaling", "true"), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.availability_zones.#", "2"), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.availability_zones.0", "1"), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.availability_zones.1", "2"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_nodeTaints(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - - config := testAccDataSourceAzureRMKubernetesCluster_nodeTaintsConfig(ri, clientId, clientSecret, acceptance.Location()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.1.node_taints.0", "key=value:NoSchedule"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_enableNodePublicIP(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - clientId := os.Getenv("ARM_CLIENT_ID") - clientSecret := os.Getenv("ARM_CLIENT_SECRET") - - config := testAccDataSourceAzureRMKubernetesCluster_enableNodePublicIPConfig(ri, clientId, clientSecret, acceptance.Location()) - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acceptance.PreCheck(t) }, - Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "agent_pool_profile.0.enable_node_public_ip", "true"), - ), - }, - }, - }) -} - -func testAccDataSourceAzureRMKubernetesCluster_basicConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_basicVMSSConfig(rInt, clientId, clientSecret, location) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlConfig(rInt int, location, clientId, clientSecret string) string { - resource := testAccAzureRMKubernetesCluster_roleBasedAccessControlConfig(rInt, location, clientId, clientSecret) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, resource) -} - -func testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(rInt int, location, clientId, clientSecret, tenantId string) string { - resource := testAccAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(rInt, location, clientId, clientSecret, tenantId) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, resource) -} - -func testAccDataSourceAzureRMKubernetesCluster_internalNetworkConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_internalNetworkConfig(rInt, clientId, clientSecret, location) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_advancedNetworkingConfig(rInt, clientId, clientSecret, location, "azure") - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(rInt, clientId, clientSecret, location, "azure", "calico") - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(rInt, clientId, clientSecret, location, "azure", "azure") - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCompleteConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(rInt, clientId, clientSecret, location, "azure") - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyCompleteConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(rInt, clientId, clientSecret, location, "azure", "calico") - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyCompleteConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(rInt, clientId, clientSecret, location, "azure", "azure") - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_advancedNetworkingConfig(rInt, clientId, clientSecret, location, "kubenet") - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetCompleteConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(rInt, clientId, clientSecret, location, "kubenet") - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_addOnProfileOMSConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_addonProfileOMSConfig(rInt, clientId, clientSecret, location) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_addOnProfileKubeDashboardConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_addonProfileKubeDashboardConfig(rInt, clientId, clientSecret, location) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_addOnProfileAzurePolicyConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_addonProfileAzurePolicyConfig(rInt, clientId, clientSecret, location) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_addOnProfileRoutingConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_addonProfileRoutingConfig(rInt, clientId, clientSecret, location) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_autoScalingNoAvailabilityZonesConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_autoscaleNoAvailabilityZonesConfig(rInt, clientId, clientSecret, location) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_autoScalingWithAvailabilityZonesConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_autoscaleWithAvailabilityZonesConfig(rInt, clientId, clientSecret, location) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_nodeTaintsConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_nodeTaintsConfig(rInt, clientId, clientSecret, location) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} - -func testAccDataSourceAzureRMKubernetesCluster_enableNodePublicIPConfig(rInt int, clientId string, clientSecret string, location string) string { - r := testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(rInt, clientId, clientSecret, location, true) - return fmt.Sprintf(` -%s - -data "azurerm_kubernetes_cluster" "test" { - name = "${azurerm_kubernetes_cluster.test.name}" - resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" -} -`, r) -} diff --git a/azurerm/internal/services/containers/resource_arm_container_registry.go b/azurerm/internal/services/containers/resource_arm_container_registry.go index 53b4f91d6236..d030d1a4045d 100644 --- a/azurerm/internal/services/containers/resource_arm_container_registry.go +++ b/azurerm/internal/services/containers/resource_arm_container_registry.go @@ -31,7 +31,7 @@ func resourceArmContainerRegistry() *schema.Resource { Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, - MigrateState: resourceAzureRMContainerRegistryMigrateState, + MigrateState: ResourceAzureRMContainerRegistryMigrateState, SchemaVersion: 2, Timeouts: &schema.ResourceTimeout{ @@ -46,7 +46,7 @@ func resourceArmContainerRegistry() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureRMContainerRegistryName, + ValidateFunc: ValidateAzureRMContainerRegistryName, }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -594,7 +594,7 @@ func resourceArmContainerRegistryDelete(d *schema.ResourceData, meta interface{} return nil } -func validateAzureRMContainerRegistryName(v interface{}, k string) (warnings []string, errors []error) { +func ValidateAzureRMContainerRegistryName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString(value) { errors = append(errors, fmt.Errorf( diff --git a/azurerm/internal/services/containers/resource_arm_container_registry_migrate.go b/azurerm/internal/services/containers/resource_arm_container_registry_migrate.go index 631356ac1472..e798587e2201 100644 --- a/azurerm/internal/services/containers/resource_arm_container_registry_migrate.go +++ b/azurerm/internal/services/containers/resource_arm_container_registry_migrate.go @@ -12,7 +12,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" ) -func resourceAzureRMContainerRegistryMigrateState( +func ResourceAzureRMContainerRegistryMigrateState( v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { switch v { case 0: diff --git a/azurerm/internal/services/containers/resource_arm_container_registry_webhook.go b/azurerm/internal/services/containers/resource_arm_container_registry_webhook.go index 8805b0ca8248..a2f190c602b5 100644 --- a/azurerm/internal/services/containers/resource_arm_container_registry_webhook.go +++ b/azurerm/internal/services/containers/resource_arm_container_registry_webhook.go @@ -51,7 +51,7 @@ func resourceArmContainerRegistryWebhook() *schema.Resource { Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateAzureRMContainerRegistryName, + ValidateFunc: ValidateAzureRMContainerRegistryName, }, "service_uri": { diff --git a/azurerm/internal/services/containers/resource_arm_container_service.go b/azurerm/internal/services/containers/resource_arm_container_service.go index b1a733ead174..90132090948e 100644 --- a/azurerm/internal/services/containers/resource_arm_container_service.go +++ b/azurerm/internal/services/containers/resource_arm_container_service.go @@ -59,7 +59,7 @@ More information can be found here: https://azure.microsoft.com/en-us/updates/az Type: schema.TypeString, Required: true, ForceNew: true, - ValidateFunc: validateArmContainerServiceOrchestrationPlatform, + ValidateFunc: ValidateArmContainerServiceOrchestrationPlatform, }, //lintignore:S018 @@ -73,7 +73,7 @@ More information can be found here: https://azure.microsoft.com/en-us/updates/az Type: schema.TypeInt, Optional: true, Default: 1, - ValidateFunc: validateArmContainerServiceMasterProfileCount, + ValidateFunc: ValidateArmContainerServiceMasterProfileCount, }, "dns_prefix": { @@ -136,7 +136,7 @@ More information can be found here: https://azure.microsoft.com/en-us/updates/az Type: schema.TypeInt, Optional: true, Default: 1, - ValidateFunc: validateArmContainerServiceAgentPoolProfileCount, + ValidateFunc: ValidateArmContainerServiceAgentPoolProfileCount, }, "dns_prefix": { @@ -646,7 +646,7 @@ func resourceAzureRMContainerServiceDiagnosticProfilesHash(v interface{}) int { return hashcode.String(buf.String()) } -func validateArmContainerServiceOrchestrationPlatform(v interface{}, _ string) (warnings []string, errors []error) { +func ValidateArmContainerServiceOrchestrationPlatform(v interface{}, _ string) (warnings []string, errors []error) { value := v.(string) capacities := map[string]bool{ "DCOS": true, @@ -660,7 +660,7 @@ func validateArmContainerServiceOrchestrationPlatform(v interface{}, _ string) ( return warnings, errors } -func validateArmContainerServiceMasterProfileCount(v interface{}, _ string) (warnings []string, errors []error) { +func ValidateArmContainerServiceMasterProfileCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) capacities := map[int]bool{ 1: true, @@ -674,7 +674,7 @@ func validateArmContainerServiceMasterProfileCount(v interface{}, _ string) (war return warnings, errors } -func validateArmContainerServiceAgentPoolProfileCount(v interface{}, _ string) (warnings []string, errors []error) { +func ValidateArmContainerServiceAgentPoolProfileCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) if value > 100 || 0 >= value { errors = append(errors, fmt.Errorf("The Count for an Agent Pool Profile can only be between 1 and 100.")) diff --git a/azurerm/internal/services/containers/tests/data_source_container_registry_test.go b/azurerm/internal/services/containers/tests/data_source_container_registry_test.go new file mode 100644 index 000000000000..e109f2b05aa9 --- /dev/null +++ b/azurerm/internal/services/containers/tests/data_source_container_registry_test.go @@ -0,0 +1,42 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMContainerRegistry_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_container_registry", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMContainerRegistryDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMContainerRegistry_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "location"), + resource.TestCheckResourceAttrSet(data.ResourceName, "admin_enabled"), + resource.TestCheckResourceAttrSet(data.ResourceName, "login_server"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMContainerRegistry_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_container_registry" "test" { + name = "${azurerm_container_registry.test.name}" + resource_group_name = "${azurerm_container_registry.test.resource_group_name}" +} +`, testAccAzureRMContainerRegistry_basicManaged(data, "Basic")) +} diff --git a/azurerm/internal/services/containers/tests/data_source_kubernetes_cluster_test.go b/azurerm/internal/services/containers/tests/data_source_kubernetes_cluster_test.go new file mode 100644 index 000000000000..e0b37606f69a --- /dev/null +++ b/azurerm/internal/services/containers/tests/data_source_kubernetes_cluster_test.go @@ -0,0 +1,804 @@ +package tests + +import ( + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func testAccDataSourceAzureRMKubernetesCluster_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_basicConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.enabled", "false"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.cluster_ca_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.host"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.username"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.password"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config_raw", ""), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_privateLink(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + + privateIpAddressCdir := "10.0.0.0/8" + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMKubernetesCluster_privateLinkConfig(data, clientId, clientSecret, data.Locations.Primary, privateIpAddressCdir, true), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "private_fqdn"), + resource.TestCheckResourceAttr(data.ResourceName, "api_server_authorized_ip_ranges.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "private_link_enabled", "true"), + ), + }, + data.ImportStep("service_principal.0.client_secret"), + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControl(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlConfig(data, clientId, clientSecret), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.azure_active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config_raw", ""), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlAAD(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + tenantId := os.Getenv("ARM_TENANT_ID") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(data, clientId, clientSecret, tenantId), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.azure_active_directory.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "role_based_access_control.0.azure_active_directory.0.client_app_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "role_based_access_control.0.azure_active_directory.0.server_app_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "role_based_access_control.0.azure_active_directory.0.tenant_id"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_admin_config_raw"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_internalNetwork(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_internalNetworkConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "agent_pool_profile.0.vnet_subnet_id"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzure(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "agent_pool_profile.0.vnet_subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_plugin"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.dns_service_ip"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.docker_bridge_cidr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.service_cidr"), + ), + }, + }, + }) +} +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicy(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "agent_pool_profile.0.vnet_subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_policy", "calico"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_plugin"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_policy"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.dns_service_ip"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.docker_bridge_cidr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.service_cidr"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicy(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "agent_pool_profile.0.vnet_subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_policy", "azure"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_plugin"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_policy"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.dns_service_ip"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.docker_bridge_cidr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.service_cidr"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureComplete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCompleteConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "agent_pool_profile.0.vnet_subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_plugin"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.dns_service_ip"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.docker_bridge_cidr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.service_cidr"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyComplete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyCompleteConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "agent_pool_profile.0.vnet_subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_policy", "calico"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_plugin"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_policy"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.dns_service_ip"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.docker_bridge_cidr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.service_cidr"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyComplete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyCompleteConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "agent_pool_profile.0.vnet_subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_policy", "azure"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_plugin"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_policy"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.dns_service_ip"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.docker_bridge_cidr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.service_cidr"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenet(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "agent_pool_profile.0.vnet_subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "kubenet"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_plugin"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.dns_service_ip"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.docker_bridge_cidr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.service_cidr"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetComplete(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetCompleteConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "agent_pool_profile.0.vnet_subnet_id"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "kubenet"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.network_plugin"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.dns_service_ip"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.docker_bridge_cidr"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile.0.service_cidr"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_addOnProfileOMS(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_addOnProfileOMSConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.0.enabled", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_addOnProfileKubeDashboard(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_addOnProfileKubeDashboardConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.kube_dashboard.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.kube_dashboard.0.enabled", "false"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_addOnProfileAzurePolicy(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_addOnProfileAzurePolicyConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.azure_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.azure_policy.0.enabled", "true"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_addOnProfileRouting(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + config := testAccDataSourceAzureRMKubernetesCluster_addOnProfileRoutingConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.http_application_routing.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.http_application_routing.0.enabled", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.http_application_routing.0.http_application_routing_zone_name"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_autoscalingNoAvailabilityZones(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + + config := testAccDataSourceAzureRMKubernetesCluster_autoScalingNoAvailabilityZonesConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.min_count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.max_count", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.type", "VirtualMachineScaleSets"), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.enable_auto_scaling", "true"), + resource.TestCheckNoResourceAttr(data.ResourceName, "agent_pool_profile.0.availability_zones"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_autoscalingWithAvailabilityZones(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + + config := testAccDataSourceAzureRMKubernetesCluster_autoScalingWithAvailabilityZonesConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.min_count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.max_count", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.type", "VirtualMachineScaleSets"), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.enable_auto_scaling", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.availability_zones.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.availability_zones.0", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.availability_zones.1", "2"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_nodeTaints(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + + config := testAccDataSourceAzureRMKubernetesCluster_nodeTaintsConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.1.node_taints.0", "key=value:NoSchedule"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_enableNodePublicIP(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_cluster", "test") + clientId := os.Getenv("ARM_CLIENT_ID") + clientSecret := os.Getenv("ARM_CLIENT_SECRET") + + config := testAccDataSourceAzureRMKubernetesCluster_enableNodePublicIPConfig(data, clientId, clientSecret) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.enable_node_public_ip", "true"), + ), + }, + }, + }) +} + +func testAccDataSourceAzureRMKubernetesCluster_basicConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_basicVMSSConfig(data, clientId, clientSecret) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlConfig(data acceptance.TestData, clientId, clientSecret string) string { + resource := testAccAzureRMKubernetesCluster_roleBasedAccessControlConfig(data, clientId, clientSecret) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, resource) +} + +func testAccDataSourceAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(data acceptance.TestData, clientId, clientSecret, tenantId string) string { + resource := testAccAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(data, clientId, clientSecret, tenantId) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, resource) +} + +func testAccDataSourceAzureRMKubernetesCluster_internalNetworkConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_internalNetworkConfig(data, clientId, clientSecret) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_advancedNetworkingConfig(data, clientId, clientSecret, data.Locations.Primary, "azure") + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(data, clientId, clientSecret, data.Locations.Primary, "azure", "calico") + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(data, clientId, clientSecret, data.Locations.Primary, "azure", "azure") + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCompleteConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(data, clientId, clientSecret, data.Locations.Primary, "azure") + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyCompleteConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(data, clientId, clientSecret, data.Locations.Primary, "azure", "calico") + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyCompleteConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(data, clientId, clientSecret, data.Locations.Primary, "azure", "azure") + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_advancedNetworkingConfig(data, clientId, clientSecret, data.Locations.Primary, "kubenet") + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenetCompleteConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(data, clientId, clientSecret, data.Locations.Primary, "kubenet") + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_addOnProfileOMSConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_addonProfileOMSConfig(data, clientId, clientSecret) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_addOnProfileKubeDashboardConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_addonProfileKubeDashboardConfig(data, clientId, clientSecret) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_addOnProfileAzurePolicyConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_addonProfileAzurePolicyConfig(data, clientId, clientSecret) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_addOnProfileRoutingConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_addonProfileRoutingConfig(data, clientId, clientSecret) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_autoScalingNoAvailabilityZonesConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_autoscaleNoAvailabilityZonesConfig(data, clientId, clientSecret) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_autoScalingWithAvailabilityZonesConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_autoscaleWithAvailabilityZonesConfig(data, clientId, clientSecret) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_nodeTaintsConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_nodeTaintsConfig(data, clientId, clientSecret) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} + +func testAccDataSourceAzureRMKubernetesCluster_enableNodePublicIPConfig(data acceptance.TestData, clientId string, clientSecret string) string { + r := testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(data, clientId, clientSecret, data.Locations.Primary, true) + return fmt.Sprintf(` +%s + +data "azurerm_kubernetes_cluster" "test" { + name = "${azurerm_kubernetes_cluster.test.name}" + resource_group_name = "${azurerm_kubernetes_cluster.test.resource_group_name}" +} +`, r) +} diff --git a/azurerm/internal/services/containers/data_source_kubernetes_service_version_test.go b/azurerm/internal/services/containers/tests/data_source_kubernetes_service_version_test.go similarity index 57% rename from azurerm/internal/services/containers/data_source_kubernetes_service_version_test.go rename to azurerm/internal/services/containers/tests/data_source_kubernetes_service_version_test.go index dbf0ba5741ac..3ea5c4059c21 100644 --- a/azurerm/internal/services/containers/data_source_kubernetes_service_version_test.go +++ b/azurerm/internal/services/containers/tests/data_source_kubernetes_service_version_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -12,8 +12,7 @@ import ( const k8sVersionRX = `[0-9]+\.[0-9]+\.[0-9]*` func TestAccDataSourceAzureRMKubernetesServiceVersions_basic(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_service_versions.test" - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_service_versions", "test") kvrx := regexp.MustCompile(k8sVersionRX) resource.Test(t, resource.TestCase{ @@ -21,12 +20,12 @@ func TestAccDataSourceAzureRMKubernetesServiceVersions_basic(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMKubernetesServiceVersions_basic(location), + Config: testAccDataSourceAzureRMKubernetesServiceVersions_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "versions.#"), - resource.TestMatchResourceAttr(dataSourceName, "versions.0", kvrx), - resource.TestCheckResourceAttrSet(dataSourceName, "latest_version"), - resource.TestMatchResourceAttr(dataSourceName, "latest_version", kvrx), + resource.TestCheckResourceAttrSet(data.ResourceName, "versions.#"), + resource.TestMatchResourceAttr(data.ResourceName, "versions.0", kvrx), + resource.TestCheckResourceAttrSet(data.ResourceName, "latest_version"), + resource.TestMatchResourceAttr(data.ResourceName, "latest_version", kvrx), ), }, }, @@ -34,8 +33,7 @@ func TestAccDataSourceAzureRMKubernetesServiceVersions_basic(t *testing.T) { } func TestAccDataSourceAzureRMKubernetesServiceVersions_filtered(t *testing.T) { - dataSourceName := "data.azurerm_kubernetes_service_versions.test" - location := acceptance.Location() + data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_service_versions", "test") kvrx := regexp.MustCompile(k8sVersionRX) resource.Test(t, resource.TestCase{ @@ -43,31 +41,31 @@ func TestAccDataSourceAzureRMKubernetesServiceVersions_filtered(t *testing.T) { Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceAzureRMKubernetesServiceVersions_filtered(location), + Config: testAccDataSourceAzureRMKubernetesServiceVersions_filtered(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttrSet(dataSourceName, "versions.#"), - resource.TestMatchResourceAttr(dataSourceName, "versions.0", kvrx), - resource.TestCheckResourceAttrSet(dataSourceName, "latest_version"), - resource.TestMatchResourceAttr(dataSourceName, "latest_version", kvrx), + resource.TestCheckResourceAttrSet(data.ResourceName, "versions.#"), + resource.TestMatchResourceAttr(data.ResourceName, "versions.0", kvrx), + resource.TestCheckResourceAttrSet(data.ResourceName, "latest_version"), + resource.TestMatchResourceAttr(data.ResourceName, "latest_version", kvrx), ), }, }, }) } -func testAccDataSourceAzureRMKubernetesServiceVersions_basic(location string) string { +func testAccDataSourceAzureRMKubernetesServiceVersions_basic(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_kubernetes_service_versions" "test" { location = "%s" } -`, location) +`, data.Locations.Primary) } -func testAccDataSourceAzureRMKubernetesServiceVersions_filtered(location string) string { +func testAccDataSourceAzureRMKubernetesServiceVersions_filtered(data acceptance.TestData) string { return fmt.Sprintf(` data "azurerm_kubernetes_service_versions" "test" { location = "%s" version_prefix = "1." } -`, location) +`, data.Locations.Primary) } diff --git a/azurerm/internal/services/containers/resource_arm_container_group_test.go b/azurerm/internal/services/containers/tests/resource_arm_container_group_test.go similarity index 54% rename from azurerm/internal/services/containers/resource_arm_container_group_test.go rename to azurerm/internal/services/containers/tests/resource_arm_container_group_test.go index b9953c77048f..30c8da91c81e 100644 --- a/azurerm/internal/services/containers/resource_arm_container_group_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_container_group_test.go @@ -1,10 +1,9 @@ -package containers +package tests import ( "fmt" "testing" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" @@ -12,14 +11,12 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMContainerGroup_SystemAssignedIdentity(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMContainerGroup_SystemAssignedIdentity(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") + config := testAccAzureRMContainerGroup_SystemAssignedIdentity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -28,29 +25,20 @@ func TestAccAzureRMContainerGroup_SystemAssignedIdentity(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "0"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "0"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "identity.0.principal_id", - }, - }, + data.ImportStep("identity.0.principal_id"), }, }) } func TestAccAzureRMContainerGroup_UserAssignedIdentity(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(14) - config := testAccAzureRMContainerGroup_UserAssignedIdentity(ri, acceptance.Location(), rs) + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") + config := testAccAzureRMContainerGroup_UserAssignedIdentity(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -59,26 +47,20 @@ func TestAccAzureRMContainerGroup_UserAssignedIdentity(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), - resource.TestCheckResourceAttr(resourceName, "identity.0.principal_id", ""), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.principal_id", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMContainerGroup_multipleAssignedIdentities(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() - rs := acctest.RandString(14) - config := testAccAzureRMContainerGroup_MultipleAssignedIdentities(ri, acceptance.Location(), rs) + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") + config := testAccAzureRMContainerGroup_MultipleAssignedIdentities(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -87,29 +69,21 @@ func TestAccAzureRMContainerGroup_multipleAssignedIdentities(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "identity.0.type", "SystemAssigned, UserAssigned"), - resource.TestCheckResourceAttr(resourceName, "identity.0.identity_ids.#", "1"), - resource.TestMatchResourceAttr(resourceName, "identity.0.principal_id", validate.UUIDRegExp), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.type", "SystemAssigned, UserAssigned"), + resource.TestCheckResourceAttr(data.ResourceName, "identity.0.identity_ids.#", "1"), + resource.TestMatchResourceAttr(data.ResourceName, "identity.0.principal_id", validate.UUIDRegExp), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "identity.0.principal_id", - }, - }, + data.ImportStep("identity.0.principal_id"), }, }) } func TestAccAzureRMContainerGroup_imageRegistryCredentials(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") - config := testAccAzureRMContainerGroup_imageRegistryCredentials(ri, acceptance.Location()) + config := testAccAzureRMContainerGroup_imageRegistryCredentials(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -119,35 +93,29 @@ func TestAccAzureRMContainerGroup_imageRegistryCredentials(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.#", "2"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.server", "hub.docker.com"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.username", "yourusername"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.password", "yourpassword"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.server", "mine.acr.io"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.username", "acrusername"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.password", "acrpassword"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.0.server", "hub.docker.com"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.0.username", "yourusername"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.0.password", "yourpassword"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.1.server", "mine.acr.io"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.1.username", "acrusername"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.1.password", "acrpassword"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "image_registry_credential.0.password", - "image_registry_credential.1.password", - }, - }, + data.ImportStep( + "image_registry_credential.0.password", + "image_registry_credential.1.password", + ), }, }) } func TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") - config := testAccAzureRMContainerGroup_imageRegistryCredentials(ri, acceptance.Location()) - updated := testAccAzureRMContainerGroup_imageRegistryCredentialsUpdated(ri, acceptance.Location()) + config := testAccAzureRMContainerGroup_imageRegistryCredentials(data) + updated := testAccAzureRMContainerGroup_imageRegistryCredentialsUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -157,27 +125,27 @@ func TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.#", "2"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.server", "hub.docker.com"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.username", "yourusername"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.password", "yourpassword"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.server", "mine.acr.io"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.username", "acrusername"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.password", "acrpassword"), - resource.TestCheckResourceAttr(resourceName, "container.0.port", "5443"), - resource.TestCheckResourceAttr(resourceName, "container.0.protocol", "UDP"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.0.server", "hub.docker.com"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.0.username", "yourusername"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.0.password", "yourpassword"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.1.server", "mine.acr.io"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.1.username", "acrusername"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.1.password", "acrpassword"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.port", "5443"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.protocol", "UDP"), ), }, { Config: updated, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.#", "1"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.server", "hub.docker.com"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.username", "updatedusername"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.password", "updatedpassword"), - resource.TestCheckResourceAttr(resourceName, "container.0.ports.#", "1"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.0.server", "hub.docker.com"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.0.username", "updatedusername"), + resource.TestCheckResourceAttr(data.ResourceName, "image_registry_credential.0.password", "updatedpassword"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.ports.#", "1"), ), }, }, @@ -185,9 +153,8 @@ func TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate(t *testing.T) { } func TestAccAzureRMContainerGroup_logTypeUnset(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMContainerGroup_logTypeUnset(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") + config := testAccAzureRMContainerGroup_logTypeUnset(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -196,31 +163,23 @@ func TestAccAzureRMContainerGroup_logTypeUnset(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.#", "1"), - resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.0.log_type", ""), - resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.0.metadata.%", "0"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_id"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_key"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics.0.log_analytics.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics.0.log_analytics.0.log_type", ""), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics.0.log_analytics.0.metadata.%", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics.0.log_analytics.0.workspace_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics.0.log_analytics.0.workspace_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "diagnostics.0.log_analytics.0.workspace_key", - }, - }, + data.ImportStep("diagnostics.0.log_analytics.0.workspace_key"), }, }) } func TestAccAzureRMContainerGroup_linuxBasic(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") - config := testAccAzureRMContainerGroup_linuxBasic(ri, acceptance.Location()) + config := testAccAzureRMContainerGroup_linuxBasic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -230,21 +189,16 @@ func TestAccAzureRMContainerGroup_linuxBasic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "container.#", "1"), - resource.TestCheckResourceAttr(resourceName, "os_type", "Linux"), - resource.TestCheckResourceAttr(resourceName, "container.0.port", "80"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "container.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "os_type", "Linux"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.port", "80"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "image_registry_credential.0.password", - "image_registry_credential.1.password", - }, - }, + data.ImportStep( + "image_registry_credential.0.password", + "image_registry_credential.1.password", + ), }, }) } @@ -255,9 +209,7 @@ func TestAccAzureRMContainerGroup_requiresImport(t *testing.T) { return } - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -265,13 +217,13 @@ func TestAccAzureRMContainerGroup_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMContainerGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerGroup_linuxBasic(ri, location), + Config: testAccAzureRMContainerGroup_linuxBasic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), + testCheckAzureRMContainerGroupExists(data.ResourceName), ), }, { - Config: testAccAzureRMContainerGroup_requiresImport(ri, location), + Config: testAccAzureRMContainerGroup_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_container_group"), }, }, @@ -279,11 +231,10 @@ func TestAccAzureRMContainerGroup_requiresImport(t *testing.T) { } func TestAccAzureRMContainerGroup_linuxBasicUpdate(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") - config := testAccAzureRMContainerGroup_linuxBasic(ri, acceptance.Location()) - updatedConfig := testAccAzureRMContainerGroup_linuxBasicUpdated(ri, acceptance.Location()) + config := testAccAzureRMContainerGroup_linuxBasic(data) + updatedConfig := testAccAzureRMContainerGroup_linuxBasicUpdated(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -293,16 +244,16 @@ func TestAccAzureRMContainerGroup_linuxBasicUpdate(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "container.#", "1"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "container.#", "1"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "container.#", "2"), - resource.TestCheckResourceAttr(resourceName, "container.0.ports.#", "2"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "container.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.ports.#", "2"), ), }, }, @@ -310,10 +261,9 @@ func TestAccAzureRMContainerGroup_linuxBasicUpdate(t *testing.T) { } func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") - config := testAccAzureRMContainerGroup_linuxComplete(ri, acceptance.Location()) + config := testAccAzureRMContainerGroup_linuxComplete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -323,76 +273,70 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "container.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.ports.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.command", "/bin/bash -c ls"), - resource.TestCheckResourceAttr(resourceName, "container.0.commands.#", "3"), - resource.TestCheckResourceAttr(resourceName, "container.0.commands.0", "/bin/bash"), - resource.TestCheckResourceAttr(resourceName, "container.0.commands.1", "-c"), - resource.TestCheckResourceAttr(resourceName, "container.0.commands.2", "ls"), - resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.%", "2"), - resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.foo", "bar"), - resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.foo1", "bar1"), - resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.%", "2"), - resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.secureFoo", "secureBar"), - resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.secureFoo1", "secureBar1"), - resource.TestCheckResourceAttr(resourceName, "container.0.gpu.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.gpu.0.count", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.gpu.0.sku", "K80"), - resource.TestCheckResourceAttr(resourceName, "container.0.volume.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.volume.0.mount_path", "/aci/logs"), - resource.TestCheckResourceAttr(resourceName, "container.0.volume.0.name", "logs"), - resource.TestCheckResourceAttr(resourceName, "container.0.volume.0.read_only", "false"), - resource.TestCheckResourceAttr(resourceName, "os_type", "Linux"), - resource.TestCheckResourceAttr(resourceName, "restart_policy", "OnFailure"), - resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.#", "1"), - resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.0.log_type", "ContainerInsights"), - resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.0.metadata.%", "1"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_id"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_key"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.#", "2"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.0", "cat"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.1", "/tmp/healthy"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.http_get.#", "0"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.initial_delay_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.period_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threshold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.success_threshold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.timeout_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.failure_threshold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.path", "/"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.port", "443"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.scheme", "Http"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.initial_delay_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.period_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.success_threshold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.timeout_seconds", "1"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "container.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.ports.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.command", "/bin/bash -c ls"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.0", "/bin/bash"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.1", "-c"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.2", "ls"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.environment_variables.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.environment_variables.foo", "bar"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.environment_variables.foo1", "bar1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.secure_environment_variables.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.secure_environment_variables.secureFoo", "secureBar"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.secure_environment_variables.secureFoo1", "secureBar1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.gpu.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.gpu.0.count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.gpu.0.sku", "K80"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.volume.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.volume.0.mount_path", "/aci/logs"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.volume.0.name", "logs"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.volume.0.read_only", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "os_type", "Linux"), + resource.TestCheckResourceAttr(data.ResourceName, "restart_policy", "OnFailure"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics.0.log_analytics.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics.0.log_analytics.0.log_type", "ContainerInsights"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics.0.log_analytics.0.metadata.%", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics.0.log_analytics.0.workspace_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics.0.log_analytics.0.workspace_key"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.exec.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.exec.0", "cat"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.exec.1", "/tmp/healthy"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.http_get.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.initial_delay_seconds", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.period_seconds", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.failure_threshold", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.success_threshold", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.timeout_seconds", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.failure_threshold", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.http_get.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.http_get.0.path", "/"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.http_get.0.port", "443"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.http_get.0.scheme", "Http"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.initial_delay_seconds", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.period_seconds", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.success_threshold", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.timeout_seconds", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "container.0.volume.0.storage_account_key", - "container.0.secure_environment_variables.%", - "container.0.secure_environment_variables.secureFoo", - "container.0.secure_environment_variables.secureFoo1", - "diagnostics.0.log_analytics.0.workspace_key", - }, - }, + data.ImportStep( + "container.0.volume.0.storage_account_key", + "container.0.secure_environment_variables.%", + "container.0.secure_environment_variables.secureFoo", + "container.0.secure_environment_variables.secureFoo1", + "diagnostics.0.log_analytics.0.workspace_key", + ), }, }) } func TestAccAzureRMContainerGroup_virtualNetwork(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMContainerGroup_virtualNetwork(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") + config := testAccAzureRMContainerGroup_virtualNetwork(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -402,14 +346,14 @@ func TestAccAzureRMContainerGroup_virtualNetwork(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckNoResourceAttr(resourceName, "dns_label_name"), - resource.TestCheckNoResourceAttr(resourceName, "identity"), - resource.TestCheckResourceAttr(resourceName, "container.#", "1"), - resource.TestCheckResourceAttr(resourceName, "os_type", "Linux"), - resource.TestCheckResourceAttr(resourceName, "container.0.port", "80"), - resource.TestCheckResourceAttr(resourceName, "ip_address_type", "Private"), - resource.TestCheckResourceAttrSet(resourceName, "network_profile_id"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckNoResourceAttr(data.ResourceName, "dns_label_name"), + resource.TestCheckNoResourceAttr(data.ResourceName, "identity"), + resource.TestCheckResourceAttr(data.ResourceName, "container.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "os_type", "Linux"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.port", "80"), + resource.TestCheckResourceAttr(data.ResourceName, "ip_address_type", "Private"), + resource.TestCheckResourceAttrSet(data.ResourceName, "network_profile_id"), ), }, }, @@ -417,10 +361,9 @@ func TestAccAzureRMContainerGroup_virtualNetwork(t *testing.T) { } func TestAccAzureRMContainerGroup_windowsBasic(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") - config := testAccAzureRMContainerGroup_windowsBasic(ri, acceptance.Location()) + config := testAccAzureRMContainerGroup_windowsBasic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -430,26 +373,21 @@ func TestAccAzureRMContainerGroup_windowsBasic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "container.#", "1"), - resource.TestCheckResourceAttr(resourceName, "os_type", "Windows"), - resource.TestCheckResourceAttr(resourceName, "container.0.ports.#", "2"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "container.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "os_type", "Windows"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.ports.#", "2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { - resourceName := "azurerm_container_group.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_group", "test") - config := testAccAzureRMContainerGroup_windowsComplete(ri, acceptance.Location()) + config := testAccAzureRMContainerGroup_windowsComplete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -459,65 +397,60 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "container.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.ports.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.command", "cmd.exe echo hi"), - resource.TestCheckResourceAttr(resourceName, "container.0.commands.#", "3"), - resource.TestCheckResourceAttr(resourceName, "container.0.commands.0", "cmd.exe"), - resource.TestCheckResourceAttr(resourceName, "container.0.commands.1", "echo"), - resource.TestCheckResourceAttr(resourceName, "container.0.commands.2", "hi"), - resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.%", "2"), - resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.foo", "bar"), - resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.foo1", "bar1"), - resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.%", "2"), - resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.secureFoo", "secureBar"), - resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.secureFoo1", "secureBar1"), - resource.TestCheckResourceAttr(resourceName, "os_type", "Windows"), - resource.TestCheckResourceAttr(resourceName, "restart_policy", "Never"), - resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.#", "1"), - resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.0.log_type", "ContainerInsights"), - resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.0.metadata.%", "1"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_id"), - resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_key"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.#", "2"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.0", "cat"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.1", "/tmp/healthy"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.http_get.#", "0"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.initial_delay_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.period_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threshold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.success_threshold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.timeout_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.failure_threshold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.path", "/"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.port", "443"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.scheme", "Http"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.initial_delay_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.period_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.success_threshold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.timeout_seconds", "1"), + testCheckAzureRMContainerGroupExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "container.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.ports.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.command", "cmd.exe echo hi"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.0", "cmd.exe"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.1", "echo"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.commands.2", "hi"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.environment_variables.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.environment_variables.foo", "bar"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.environment_variables.foo1", "bar1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.secure_environment_variables.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.secure_environment_variables.secureFoo", "secureBar"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.secure_environment_variables.secureFoo1", "secureBar1"), + resource.TestCheckResourceAttr(data.ResourceName, "os_type", "Windows"), + resource.TestCheckResourceAttr(data.ResourceName, "restart_policy", "Never"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics.0.log_analytics.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics.0.log_analytics.0.log_type", "ContainerInsights"), + resource.TestCheckResourceAttr(data.ResourceName, "diagnostics.0.log_analytics.0.metadata.%", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics.0.log_analytics.0.workspace_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "diagnostics.0.log_analytics.0.workspace_key"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.exec.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.exec.0", "cat"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.exec.1", "/tmp/healthy"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.http_get.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.initial_delay_seconds", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.period_seconds", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.failure_threshold", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.success_threshold", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.readiness_probe.0.timeout_seconds", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.failure_threshold", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.http_get.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.http_get.0.path", "/"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.http_get.0.port", "443"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.http_get.0.scheme", "Http"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.initial_delay_seconds", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.period_seconds", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.success_threshold", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "container.0.liveness_probe.0.timeout_seconds", "1"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "container.0.secure_environment_variables.%", - "container.0.secure_environment_variables.secureFoo", - "container.0.secure_environment_variables.secureFoo1", - "diagnostics.0.log_analytics.0.workspace_key", - }, - }, + data.ImportStep( + "container.0.secure_environment_variables.%", + "container.0.secure_environment_variables.secureFoo", + "container.0.secure_environment_variables.secureFoo1", + "diagnostics.0.log_analytics.0.workspace_key", + ), }, }) } -func testAccAzureRMContainerGroup_SystemAssignedIdentity(ri int, location string) string { +func testAccAzureRMContainerGroup_SystemAssignedIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -547,10 +480,10 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerGroup_UserAssignedIdentity(ri int, location string, rString string) string { +func testAccAzureRMContainerGroup_UserAssignedIdentity(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -588,10 +521,10 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, rString, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMContainerGroup_MultipleAssignedIdentities(ri int, location string, rString string) string { +func testAccAzureRMContainerGroup_MultipleAssignedIdentities(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -629,10 +562,10 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, rString, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) } -func testAccAzureRMContainerGroup_linuxBasic(ri int, location string) string { +func testAccAzureRMContainerGroup_linuxBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -658,11 +591,11 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerGroup_requiresImport(rInt int, location string) string { - template := testAccAzureRMContainerGroup_linuxBasic(rInt, location) +func testAccAzureRMContainerGroup_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMContainerGroup_linuxBasic(data) return fmt.Sprintf(` %s @@ -688,7 +621,7 @@ resource "azurerm_container_group" "import" { `, template) } -func testAccAzureRMContainerGroup_imageRegistryCredentials(ri int, location string) string { +func testAccAzureRMContainerGroup_imageRegistryCredentials(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -734,10 +667,10 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerGroup_imageRegistryCredentialsUpdated(ri int, location string) string { +func testAccAzureRMContainerGroup_imageRegistryCredentialsUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -779,10 +712,10 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerGroup_logTypeUnset(ri int, location string) string { +func testAccAzureRMContainerGroup_logTypeUnset(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -822,10 +755,10 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMContainerGroup_linuxBasicUpdated(ri int, location string) string { +func testAccAzureRMContainerGroup_linuxBasicUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -866,10 +799,10 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerGroup_virtualNetwork(ri int, location string) string { +func testAccAzureRMContainerGroup_virtualNetwork(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -934,10 +867,10 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerGroup_windowsBasic(ri int, location string) string { +func testAccAzureRMContainerGroup_windowsBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -972,10 +905,10 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerGroup_windowsComplete(ri int, location string) string { +func testAccAzureRMContainerGroup_windowsComplete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1074,10 +1007,10 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri, ri, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMContainerGroup_linuxComplete(ri int, location string) string { +func testAccAzureRMContainerGroup_linuxComplete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1208,7 +1141,7 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri, ri, ri, ri, ri) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMContainerGroupExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/containers/resource_arm_container_registry_migrate_test.go b/azurerm/internal/services/containers/tests/resource_arm_container_registry_migrate_test.go similarity index 94% rename from azurerm/internal/services/containers/resource_arm_container_registry_migrate_test.go rename to azurerm/internal/services/containers/tests/resource_arm_container_registry_migrate_test.go index ec24047dc9b0..155dca266f74 100644 --- a/azurerm/internal/services/containers/resource_arm_container_registry_migrate_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_container_registry_migrate_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "context" @@ -9,11 +9,12 @@ import ( "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources" "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage" - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/hashicorp/terraform/helper/acctest" "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/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers" ) func TestAccAzureRMContainerRegistryMigrateState(t *testing.T) { @@ -39,7 +40,7 @@ func TestAccAzureRMContainerRegistryMigrateState(t *testing.T) { client.StopContext = acceptance.AzureProvider.StopContext() - rs := acctest.RandString(4) + rs := acctest.RandString(7) resourceGroupName := fmt.Sprintf("acctestRG%s", rs) storageAccountName := fmt.Sprintf("acctestsa%s", rs) location := azure.NormalizeLocation(acceptance.Location()) @@ -98,7 +99,7 @@ func TestAccAzureRMContainerRegistryMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.Attributes, } - is, err := resourceAzureRMContainerRegistryMigrateState(tc.StateVersion, is, tc.Meta) + is, err := containers.ResourceAzureRMContainerRegistryMigrateState(tc.StateVersion, is, tc.Meta) if err != nil { t.Fatalf("bad: %q, err: %#v", tn, err) diff --git a/azurerm/internal/services/containers/resource_arm_container_registry_test.go b/azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go similarity index 69% rename from azurerm/internal/services/containers/resource_arm_container_registry_test.go rename to azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go index fc76dac2e989..dc4f9114755d 100644 --- a/azurerm/internal/services/containers/resource_arm_container_registry_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -9,10 +9,10 @@ import ( "github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2018-09-01/containerregistry" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -64,7 +64,7 @@ func TestAccAzureRMContainerRegistryName_validation(t *testing.T) { } for _, tc := range cases { - _, errors := validateAzureRMContainerRegistryName(tc.Value, "azurerm_container_registry") + _, errors := containers.ValidateAzureRMContainerRegistryName(tc.Value, "azurerm_container_registry") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Azure RM Container Registry Name to trigger a validation error: %v", errors) @@ -73,9 +73,7 @@ func TestAccAzureRMContainerRegistryName_validation(t *testing.T) { } func TestAccAzureRMContainerRegistry_basic_basic(t *testing.T) { - rn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() - l := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -83,16 +81,12 @@ func TestAccAzureRMContainerRegistry_basic_basic(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistry_basic_basic(ri, l), + Config: testAccAzureRMContainerRegistry_basic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), + testCheckAzureRMContainerRegistryExists(data.ResourceName), ), }, - { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -103,9 +97,7 @@ func TestAccAzureRMContainerRegistry_requiresImport(t *testing.T) { return } - rn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() - l := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,13 +105,13 @@ func TestAccAzureRMContainerRegistry_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistry_basicManaged(ri, l, "Basic"), + Config: testAccAzureRMContainerRegistry_basicManaged(data, "Basic"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), + testCheckAzureRMContainerRegistryExists(data.ResourceName), ), }, { - Config: testAccAzureRMContainerRegistry_requiresImport(ri, l, "Basic"), + Config: testAccAzureRMContainerRegistry_requiresImport(data, "Basic"), ExpectError: acceptance.RequiresImportError("azurerm_container_registry"), }, }, @@ -127,8 +119,7 @@ func TestAccAzureRMContainerRegistry_requiresImport(t *testing.T) { } func TestAccAzureRMContainerRegistry_basic_standard(t *testing.T) { - rn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -136,23 +127,18 @@ func TestAccAzureRMContainerRegistry_basic_standard(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistry_basicManaged(ri, acceptance.Location(), "Standard"), + Config: testAccAzureRMContainerRegistry_basicManaged(data, "Standard"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), + testCheckAzureRMContainerRegistryExists(data.ResourceName), ), }, - { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMContainerRegistry_basic_premium(t *testing.T) { - rn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -160,23 +146,18 @@ func TestAccAzureRMContainerRegistry_basic_premium(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistry_basicManaged(ri, acceptance.Location(), "Premium"), + Config: testAccAzureRMContainerRegistry_basicManaged(data, "Premium"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), + testCheckAzureRMContainerRegistryExists(data.ResourceName), ), }, - { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMContainerRegistry_basic_basic2Premium2basic(t *testing.T) { - rn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -184,24 +165,24 @@ func TestAccAzureRMContainerRegistry_basic_basic2Premium2basic(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistry_basic_basic(ri, acceptance.Location()), + Config: testAccAzureRMContainerRegistry_basic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), - resource.TestCheckResourceAttr(rn, "sku", "Basic"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Basic"), ), }, { - Config: testAccAzureRMContainerRegistry_basicManaged(ri, acceptance.Location(), "Premium"), + Config: testAccAzureRMContainerRegistry_basicManaged(data, "Premium"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), - resource.TestCheckResourceAttr(rn, "sku", "Premium"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Premium"), ), }, { - Config: testAccAzureRMContainerRegistry_basic_basic(ri, acceptance.Location()), + Config: testAccAzureRMContainerRegistry_basic_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), - resource.TestCheckResourceAttr(rn, "sku", "Basic"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Basic"), ), }, }, @@ -209,8 +190,7 @@ func TestAccAzureRMContainerRegistry_basic_basic2Premium2basic(t *testing.T) { } func TestAccAzureRMContainerRegistry_complete(t *testing.T) { - rn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -218,24 +198,18 @@ func TestAccAzureRMContainerRegistry_complete(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistry_complete(ri, acceptance.Location()), + Config: testAccAzureRMContainerRegistry_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), + testCheckAzureRMContainerRegistryExists(data.ResourceName), ), }, - { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMContainerRegistry_update(t *testing.T) { - rn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() - l := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -243,15 +217,15 @@ func TestAccAzureRMContainerRegistry_update(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistry_complete(ri, l), + Config: testAccAzureRMContainerRegistry_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), + testCheckAzureRMContainerRegistryExists(data.ResourceName), ), }, { - Config: testAccAzureRMContainerRegistry_completeUpdated(ri, l), + Config: testAccAzureRMContainerRegistry_completeUpdated(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), + testCheckAzureRMContainerRegistryExists(data.ResourceName), ), }, }, @@ -259,8 +233,7 @@ func TestAccAzureRMContainerRegistry_update(t *testing.T) { } func TestAccAzureRMContainerRegistry_geoReplication(t *testing.T) { - dsn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") skuPremium := "Premium" skuBasic := "Basic" @@ -273,50 +246,50 @@ func TestAccAzureRMContainerRegistry_geoReplication(t *testing.T) { // first config creates an ACR with locations { // TODO: fix this to use dynamic locations - Config: testAccAzureRMContainerRegistry_geoReplication(ri, acceptance.Location(), skuPremium, `eastus", "westus`), + Config: testAccAzureRMContainerRegistry_geoReplication(data, skuPremium, `eastus", "westus`), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dsn, "sku", skuPremium), - resource.TestCheckResourceAttr(dsn, "georeplication_locations.#", "2"), - testCheckAzureRMContainerRegistryExists(dsn), - testCheckAzureRMContainerRegistryGeoreplications(dsn, skuPremium, []string{`"eastus"`, `"westus"`}), + resource.TestCheckResourceAttr(data.ResourceName, "sku", skuPremium), + resource.TestCheckResourceAttr(data.ResourceName, "georeplication_locations.#", "2"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + testCheckAzureRMContainerRegistryGeoreplications(data.ResourceName, skuPremium, []string{`"eastus"`, `"westus"`}), ), }, // second config udpates the ACR with updated locations { - Config: testAccAzureRMContainerRegistry_geoReplication(ri, acceptance.Location(), skuPremium, `centralus", "eastus`), + Config: testAccAzureRMContainerRegistry_geoReplication(data, skuPremium, `centralus", "eastus`), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dsn, "sku", skuPremium), - resource.TestCheckResourceAttr(dsn, "georeplication_locations.#", "2"), - testCheckAzureRMContainerRegistryExists(dsn), - testCheckAzureRMContainerRegistryGeoreplications(dsn, skuPremium, []string{`"eastus"`, `"centralus"`}), + resource.TestCheckResourceAttr(data.ResourceName, "sku", skuPremium), + resource.TestCheckResourceAttr(data.ResourceName, "georeplication_locations.#", "2"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + testCheckAzureRMContainerRegistryGeoreplications(data.ResourceName, skuPremium, []string{`"eastus"`, `"centralus"`}), ), }, // third config udpates the ACR with no location { - Config: testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation(ri, acceptance.Location(), skuPremium), + Config: testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation(data, skuPremium), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dsn, "sku", skuPremium), - testCheckAzureRMContainerRegistryExists(dsn), - testCheckAzureRMContainerRegistryGeoreplications(dsn, skuPremium, nil), + resource.TestCheckResourceAttr(data.ResourceName, "sku", skuPremium), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + testCheckAzureRMContainerRegistryGeoreplications(data.ResourceName, skuPremium, nil), ), }, // fourth config updates an ACR with replicas { - Config: testAccAzureRMContainerRegistry_geoReplication(ri, acceptance.Location(), skuPremium, `eastus", "westus`), + Config: testAccAzureRMContainerRegistry_geoReplication(data, skuPremium, `eastus", "westus`), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dsn, "sku", skuPremium), - resource.TestCheckResourceAttr(dsn, "georeplication_locations.#", "2"), - testCheckAzureRMContainerRegistryExists(dsn), - testCheckAzureRMContainerRegistryGeoreplications(dsn, skuPremium, []string{`"eastus"`, `"westus"`}), + resource.TestCheckResourceAttr(data.ResourceName, "sku", skuPremium), + resource.TestCheckResourceAttr(data.ResourceName, "georeplication_locations.#", "2"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + testCheckAzureRMContainerRegistryGeoreplications(data.ResourceName, skuPremium, []string{`"eastus"`, `"westus"`}), ), }, // fifth config updates the SKU to basic and no replicas (should remove the existing replicas if any) { - Config: testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation_basic(ri, acceptance.Location()), + Config: testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation_basic(data), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dsn, "sku", skuBasic), - testCheckAzureRMContainerRegistryExists(dsn), - testCheckAzureRMContainerRegistryGeoreplications(dsn, skuBasic, nil), + resource.TestCheckResourceAttr(data.ResourceName, "sku", skuBasic), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + testCheckAzureRMContainerRegistryGeoreplications(data.ResourceName, skuBasic, nil), ), }, }, @@ -324,9 +297,7 @@ func TestAccAzureRMContainerRegistry_geoReplication(t *testing.T) { } func TestAccAzureRMContainerRegistry_networkAccessProfileIp(t *testing.T) { - rn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() - l := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -334,26 +305,20 @@ func TestAccAzureRMContainerRegistry_networkAccessProfileIp(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistry_networkAccessProfile_ip(ri, l, "Premium"), + Config: testAccAzureRMContainerRegistry_networkAccessProfile_ip(data, "Premium"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), - resource.TestCheckResourceAttr(rn, "network_rule_set.0.default_action", "Allow"), - resource.TestCheckResourceAttr(rn, "network_rule_set.0.ip_rule.#", "1"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rule_set.0.default_action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rule_set.0.ip_rule.#", "1"), ), }, - { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMContainerRegistry_networkAccessProfile_update(t *testing.T) { - rn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() - l := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -361,58 +326,44 @@ func TestAccAzureRMContainerRegistry_networkAccessProfile_update(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistry_basicManaged(ri, l, "Basic"), + Config: testAccAzureRMContainerRegistry_basicManaged(data, "Premium"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), + testCheckAzureRMContainerRegistryExists(data.ResourceName), ), }, { - Config: testAccAzureRMContainerRegistry_networkAccessProfile_ip(ri, l, "Premium"), + Config: testAccAzureRMContainerRegistry_networkAccessProfile_ip(data, "Premium"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), - resource.TestCheckResourceAttr(rn, "network_rule_set.0.default_action", "Allow"), - resource.TestCheckResourceAttr(rn, "network_rule_set.0.ip_rule.#", "2"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rule_set.0.default_action", "Allow"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rule_set.0.ip_rule.#", "2"), ), }, + data.ImportStep(), { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMContainerRegistry_networkAccessProfile_vnet(ri, l), + Config: testAccAzureRMContainerRegistry_networkAccessProfile_vnet(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), - resource.TestCheckResourceAttr(rn, "network_rule_set.0.default_action", "Deny"), - resource.TestCheckResourceAttr(rn, "network_rule_set.0.virtual_network.#", "1"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rule_set.0.default_action", "Deny"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rule_set.0.virtual_network.#", "1"), ), }, + data.ImportStep(), { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMContainerRegistry_networkAccessProfile_both(ri, l), + Config: testAccAzureRMContainerRegistry_networkAccessProfile_both(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), - resource.TestCheckResourceAttr(rn, "network_rule_set.0.default_action", "Deny"), - resource.TestCheckResourceAttr(rn, "network_rule_set.0.ip_rule.#", "1"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rule_set.0.default_action", "Deny"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rule_set.0.ip_rule.#", "1"), ), }, - { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMContainerRegistry_networkAccessProfileVnet(t *testing.T) { - rn := "azurerm_container_registry.test" - ri := tf.AccRandTimeInt() - l := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -420,18 +371,14 @@ func TestAccAzureRMContainerRegistry_networkAccessProfileVnet(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistry_networkAccessProfile_vnet(ri, l), + Config: testAccAzureRMContainerRegistry_networkAccessProfile_vnet(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryExists(rn), - resource.TestCheckResourceAttr(rn, "network_rule_set.0.default_action", "Deny"), - resource.TestCheckResourceAttr(rn, "network_rule_set.0.virtual_network.#", "1"), + testCheckAzureRMContainerRegistryExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_rule_set.0.default_action", "Deny"), + resource.TestCheckResourceAttr(data.ResourceName, "network_rule_set.0.virtual_network.#", "1"), ), }, - { - ResourceName: rn, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -531,7 +478,7 @@ func testCheckAzureRMContainerRegistryGeoreplications(resourceName string, sku s } } -func testAccAzureRMContainerRegistry_basic_basic(rInt int, location string) string { +func testAccAzureRMContainerRegistry_basic_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -548,10 +495,10 @@ resource "azurerm_container_registry" "test" { # premiuim SKU will automaticcally populate network_rule_set.default_action to allow network_rule_set = [] } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerRegistry_basicManaged(rInt int, location string, sku string) string { +func testAccAzureRMContainerRegistry_basicManaged(data acceptance.TestData, sku string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -564,11 +511,11 @@ resource "azurerm_container_registry" "test" { location = "${azurerm_resource_group.test.location}" sku = "%s" } -`, rInt, location, rInt, sku) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, sku) } -func testAccAzureRMContainerRegistry_requiresImport(rInt int, location string, sku string) string { - template := testAccAzureRMContainerRegistry_basicManaged(rInt, location, sku) +func testAccAzureRMContainerRegistry_requiresImport(data acceptance.TestData, sku string) string { + template := testAccAzureRMContainerRegistry_basicManaged(data, sku) return fmt.Sprintf(` %s @@ -582,7 +529,7 @@ resource "azurerm_container_registry" "import" { `, template) } -func testAccAzureRMContainerRegistry_complete(rInt int, location string) string { +func testAccAzureRMContainerRegistry_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -600,10 +547,10 @@ resource "azurerm_container_registry" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerRegistry_completeUpdated(rInt int, location string) string { +func testAccAzureRMContainerRegistry_completeUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -621,10 +568,10 @@ resource "azurerm_container_registry" "test" { environment = "production" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerRegistry_geoReplication(rInt int, location string, sku string, georeplicationLocations string) string { +func testAccAzureRMContainerRegistry_geoReplication(data acceptance.TestData, sku string, georeplicationLocations string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -638,10 +585,10 @@ resource "azurerm_container_registry" "test" { sku = "%s" georeplication_locations = ["%s"] } -`, rInt, location, rInt, sku, georeplicationLocations) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, sku, georeplicationLocations) } -func testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation(rInt int, location string, sku string) string { +func testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation(data acceptance.TestData, sku string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -654,10 +601,10 @@ resource "azurerm_container_registry" "test" { location = "${azurerm_resource_group.test.location}" sku = "%s" } -`, rInt, location, rInt, sku) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, sku) } -func testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation_basic(rInt int, location string) string { +func testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%d" @@ -674,10 +621,10 @@ resource "azurerm_container_registry" "test" { # premiuim SKU will automaticcally populate network_rule_set.default_action to allow network_rule_set = [] } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMContainerRegistry_networkAccessProfile_ip(rInt int, location string, sku string) string { +func testAccAzureRMContainerRegistry_networkAccessProfile_ip(data acceptance.TestData, sku string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%[1]d" @@ -705,10 +652,10 @@ resource "azurerm_container_registry" "test" { } } } -`, rInt, location, sku) +`, data.RandomInteger, data.Locations.Primary, sku) } -func testAccAzureRMContainerRegistry_networkAccessProfile_vnet(rInt int, location string) string { +func testAccAzureRMContainerRegistry_networkAccessProfile_vnet(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%[1]d" @@ -752,10 +699,10 @@ resource "azurerm_container_registry" "test" { } } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistry_networkAccessProfile_both(rInt int, location string) string { +func testAccAzureRMContainerRegistry_networkAccessProfile_both(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestrg-%[1]d" @@ -799,5 +746,5 @@ resource "azurerm_container_registry" "test" { } } } -`, rInt, location) +`, data.RandomInteger, data.Locations.Primary) } diff --git a/azurerm/internal/services/containers/resource_arm_container_registry_webhook_test.go b/azurerm/internal/services/containers/tests/resource_arm_container_registry_webhook_test.go similarity index 71% rename from azurerm/internal/services/containers/resource_arm_container_registry_webhook_test.go rename to azurerm/internal/services/containers/tests/resource_arm_container_registry_webhook_test.go index 052d82cfe94f..79e17772b16f 100644 --- a/azurerm/internal/services/containers/resource_arm_container_registry_webhook_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_container_registry_webhook_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -6,15 +6,13 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) func TestAccAzureRMContainerRegistryWebhook_basic(t *testing.T) { - resourceName := "azurerm_container_registry_webhook.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_registry_webhook", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -22,25 +20,20 @@ func TestAccAzureRMContainerRegistryWebhook_basic(t *testing.T) { CheckDestroy: testCheckAzureRMContainerRegistryWebhookDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerRegistryWebhook_basic(ri, acceptance.Location()), + Config: testAccAzureRMContainerRegistryWebhook_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMContainerRegistryWebhook_withTags(t *testing.T) { - resourceName := "azurerm_container_registry_webhook.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMContainerRegistryWebhook_withTags(ri, acceptance.Location()) - postConfig := testAccAzureRMContainerRegistryWebhook_withTagsUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_registry_webhook", "test") + preConfig := testAccAzureRMContainerRegistryWebhook_withTags(data) + postConfig := testAccAzureRMContainerRegistryWebhook_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,18 +43,18 @@ func TestAccAzureRMContainerRegistryWebhook_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.label", "test"), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.label", "test"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.label", "test1"), - resource.TestCheckResourceAttr(resourceName, "tags.ENV", "prod"), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.label", "test1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.ENV", "prod"), ), }, }, @@ -69,10 +62,9 @@ func TestAccAzureRMContainerRegistryWebhook_withTags(t *testing.T) { } func TestAccAzureRMContainerRegistryWebhook_actions(t *testing.T) { - resourceName := "azurerm_container_registry_webhook.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMContainerRegistryWebhook_actions(ri, acceptance.Location()) - postConfig := testAccAzureRMContainerRegistryWebhook_actionsUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_registry_webhook", "test") + preConfig := testAccAzureRMContainerRegistryWebhook_actions(data) + postConfig := testAccAzureRMContainerRegistryWebhook_actionsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,28 +74,19 @@ func TestAccAzureRMContainerRegistryWebhook_actions(t *testing.T) { { Config: preConfig, }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMContainerRegistryWebhook_status(t *testing.T) { - resourceName := "azurerm_container_registry_webhook.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMContainerRegistryWebhook_status(ri, acceptance.Location()) - postConfig := testAccAzureRMContainerRegistryWebhook_statusUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_registry_webhook", "test") + preConfig := testAccAzureRMContainerRegistryWebhook_status(data) + postConfig := testAccAzureRMContainerRegistryWebhook_statusUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,15 +96,15 @@ func TestAccAzureRMContainerRegistryWebhook_status(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "status", "enabled"), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "status", "enabled"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "status", "disabled"), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "status", "disabled"), ), }, }, @@ -129,10 +112,9 @@ func TestAccAzureRMContainerRegistryWebhook_status(t *testing.T) { } func TestAccAzureRMContainerRegistryWebhook_serviceUri(t *testing.T) { - resourceName := "azurerm_container_registry_webhook.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMContainerRegistryWebhook_serviceUri(ri, acceptance.Location()) - postConfig := testAccAzureRMContainerRegistryWebhook_serviceUriUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_registry_webhook", "test") + preConfig := testAccAzureRMContainerRegistryWebhook_serviceUri(data) + postConfig := testAccAzureRMContainerRegistryWebhook_serviceUriUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -142,15 +124,15 @@ func TestAccAzureRMContainerRegistryWebhook_serviceUri(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "service_uri", "https://mywebhookreceiver.example/mytag"), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "service_uri", "https://mywebhookreceiver.example/mytag"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "service_uri", "https://my.webhookreceiver.example/mytag/2"), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "service_uri", "https://my.webhookreceiver.example/mytag/2"), ), }, }, @@ -158,10 +140,9 @@ func TestAccAzureRMContainerRegistryWebhook_serviceUri(t *testing.T) { } func TestAccAzureRMContainerRegistryWebhook_scope(t *testing.T) { - resourceName := "azurerm_container_registry_webhook.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMContainerRegistryWebhook_scope(ri, acceptance.Location()) - postConfig := testAccAzureRMContainerRegistryWebhook_scopeUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_registry_webhook", "test") + preConfig := testAccAzureRMContainerRegistryWebhook_scope(data) + postConfig := testAccAzureRMContainerRegistryWebhook_scopeUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -171,15 +152,15 @@ func TestAccAzureRMContainerRegistryWebhook_scope(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "scope", "mytag:*"), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "scope", "mytag:*"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "scope", "mytag:4"), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "scope", "mytag:4"), ), }, }, @@ -187,10 +168,9 @@ func TestAccAzureRMContainerRegistryWebhook_scope(t *testing.T) { } func TestAccAzureRMContainerRegistryWebhook_customHeaders(t *testing.T) { - resourceName := "azurerm_container_registry_webhook.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMContainerRegistryWebhook_customHeaders(ri, acceptance.Location()) - postConfig := testAccAzureRMContainerRegistryWebhook_customHeadersUpdate(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_registry_webhook", "test") + preConfig := testAccAzureRMContainerRegistryWebhook_customHeaders(data) + postConfig := testAccAzureRMContainerRegistryWebhook_customHeadersUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -200,25 +180,25 @@ func TestAccAzureRMContainerRegistryWebhook_customHeaders(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "custom_headers.%", "1"), - resource.TestCheckResourceAttr(resourceName, "custom_headers.Content-Type", "application/json"), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "custom_headers.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_headers.Content-Type", "application/json"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMContainerRegistryWebhookExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "custom_headers.%", "2"), - resource.TestCheckResourceAttr(resourceName, "custom_headers.Content-Type", "application/xml"), - resource.TestCheckResourceAttr(resourceName, "custom_headers.Accept-Charset", "utf-8"), + testCheckAzureRMContainerRegistryWebhookExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "custom_headers.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_headers.Content-Type", "application/xml"), + resource.TestCheckResourceAttr(data.ResourceName, "custom_headers.Accept-Charset", "utf-8"), ), }, }, }) } -func testAccAzureRMContainerRegistryWebhook_basic(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -244,10 +224,10 @@ resource "azurerm_container_registry_webhook" "test" { "push" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_withTags(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -277,10 +257,10 @@ resource "azurerm_container_registry_webhook" "test" { label = "test" } } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -311,10 +291,10 @@ resource "azurerm_container_registry_webhook" "test" { ENV = "prod" } } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_actions(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_actions(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -340,10 +320,10 @@ resource "azurerm_container_registry_webhook" "test" { "push" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_actionsUpdate(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_actionsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -370,10 +350,10 @@ resource "azurerm_container_registry_webhook" "test" { "delete" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_status(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_status(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -401,10 +381,10 @@ resource "azurerm_container_registry_webhook" "test" { "push" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_statusUpdate(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_statusUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -432,10 +412,10 @@ resource "azurerm_container_registry_webhook" "test" { "push" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_serviceUri(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_serviceUri(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -461,10 +441,10 @@ resource "azurerm_container_registry_webhook" "test" { "push" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_serviceUriUpdate(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_serviceUriUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -492,10 +472,10 @@ resource "azurerm_container_registry_webhook" "test" { "push" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_scope(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_scope(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -523,10 +503,10 @@ resource "azurerm_container_registry_webhook" "test" { "push" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_scopeUpdate(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_scopeUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -554,10 +534,10 @@ resource "azurerm_container_registry_webhook" "test" { "push" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_customHeaders(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_customHeaders(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -587,10 +567,10 @@ resource "azurerm_container_registry_webhook" "test" { "push" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } -func testAccAzureRMContainerRegistryWebhook_customHeadersUpdate(rInt int, location string) string { +func testAccAzureRMContainerRegistryWebhook_customHeadersUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "rg" { name = "acctestRG-%d" @@ -621,7 +601,7 @@ resource "azurerm_container_registry_webhook" "test" { "push" ] } -`, rInt, location, rInt, location, rInt, location) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Locations.Primary) } func testCheckAzureRMContainerRegistryWebhookDestroy(s *terraform.State) error { diff --git a/azurerm/internal/services/containers/resource_arm_container_service_test.go b/azurerm/internal/services/containers/tests/resource_arm_container_service_test.go similarity index 83% rename from azurerm/internal/services/containers/resource_arm_container_service_test.go rename to azurerm/internal/services/containers/tests/resource_arm_container_service_test.go index c98bb5279c68..db4af84f7b8c 100644 --- a/azurerm/internal/services/containers/resource_arm_container_service_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_container_service_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -8,10 +8,10 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers" ) func TestAccAzureRMContainerService_orchestrationPlatformValidation(t *testing.T) { @@ -26,7 +26,7 @@ func TestAccAzureRMContainerService_orchestrationPlatformValidation(t *testing.T } for _, tc := range cases { - _, errors := validateArmContainerServiceOrchestrationPlatform(tc.Value, "azurerm_container_service") + _, errors := containers.ValidateArmContainerServiceOrchestrationPlatform(tc.Value, "azurerm_container_service") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Azure RM Container Service Orchestration Platform to trigger a validation error for '%s'", tc.Value) @@ -49,7 +49,7 @@ func TestAccAzureRMContainerService_masterProfileCountValidation(t *testing.T) { } for _, tc := range cases { - _, errors := validateArmContainerServiceMasterProfileCount(tc.Value, "azurerm_container_service") + _, errors := containers.ValidateArmContainerServiceMasterProfileCount(tc.Value, "azurerm_container_service") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Azure RM Container Service Master Profile Count to trigger a validation error for '%d'", tc.Value) @@ -71,7 +71,7 @@ func TestAccAzureRMContainerService_agentProfilePoolCountValidation(t *testing.T } for _, tc := range cases { - _, errors := validateArmContainerServiceAgentPoolProfileCount(tc.Value, "azurerm_container_service") + _, errors := containers.ValidateArmContainerServiceAgentPoolProfileCount(tc.Value, "azurerm_container_service") if len(errors) != tc.ErrCount { t.Fatalf("Expected the Azure RM Container Service Agent Pool Profile Count to trigger a validation error for '%d'", tc.Value) @@ -80,8 +80,8 @@ func TestAccAzureRMContainerService_agentProfilePoolCountValidation(t *testing.T } func TestAccAzureRMContainerService_dcosBasic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMContainerService_dcosBasic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_service", "test") + config := testAccAzureRMContainerService_dcosBasic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,8 +104,7 @@ func TestAccAzureRMContainerService_requiresImport(t *testing.T) { return } - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_container_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -113,13 +112,13 @@ func TestAccAzureRMContainerService_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMContainerServiceDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMContainerService_dcosBasic(ri, location), + Config: testAccAzureRMContainerService_dcosBasic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMContainerServiceExists("azurerm_container_service.test"), ), }, { - Config: testAccAzureRMContainerService_requiresImport(ri, location), + Config: testAccAzureRMContainerService_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_container_service"), }, }, @@ -127,10 +126,10 @@ func TestAccAzureRMContainerService_requiresImport(t *testing.T) { } func TestAccAzureRMContainerService_kubernetesBasic(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_service", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - config := testAccAzureRMContainerService_kubernetesBasic(ri, clientId, clientSecret, acceptance.Location()) + config := testAccAzureRMContainerService_kubernetesBasic(data, clientId, clientSecret) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -148,10 +147,10 @@ func TestAccAzureRMContainerService_kubernetesBasic(t *testing.T) { } func TestAccAzureRMContainerService_kubernetesComplete(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_container_service", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - config := testAccAzureRMContainerService_kubernetesComplete(ri, clientId, clientSecret, acceptance.Location()) + config := testAccAzureRMContainerService_kubernetesComplete(data, clientId, clientSecret) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -169,8 +168,8 @@ func TestAccAzureRMContainerService_kubernetesComplete(t *testing.T) { } func TestAccAzureRMContainerService_swarmBasic(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMContainerService_swarmBasic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_service", "test") + config := testAccAzureRMContainerService_swarmBasic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -187,7 +186,7 @@ func TestAccAzureRMContainerService_swarmBasic(t *testing.T) { }) } -func testAccAzureRMContainerService_dcosBasic(rInt int, location string) string { +func testAccAzureRMContainerService_dcosBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -224,11 +223,11 @@ resource "azurerm_container_service" "test" { enabled = false } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMContainerService_requiresImport(rInt int, location string) string { - template := testAccAzureRMContainerService_dcosBasic(rInt, location) +func testAccAzureRMContainerService_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMContainerService_dcosBasic(data) return fmt.Sprintf(` %s @@ -262,10 +261,10 @@ resource "azurerm_container_service" "import" { enabled = false } } -`, template, rInt, rInt, rInt) +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMContainerService_kubernetesBasic(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMContainerService_kubernetesBasic(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -307,10 +306,10 @@ resource "azurerm_container_service" "test" { enabled = false } } -`, rInt, location, rInt, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMContainerService_kubernetesComplete(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMContainerService_kubernetesComplete(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -356,10 +355,10 @@ resource "azurerm_container_service" "test" { you = "me" } } -`, rInt, location, rInt, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMContainerService_swarmBasic(rInt int, location string) string { +func testAccAzureRMContainerService_swarmBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -396,7 +395,7 @@ resource "azurerm_container_service" "test" { enabled = false } } -`, rInt, location, rInt, rInt, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) } func testCheckAzureRMContainerServiceExists(resourceName string) resource.TestCheckFunc { diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_addons_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_addons_test.go similarity index 64% rename from azurerm/internal/services/containers/resource_arm_kubernetes_cluster_addons_test.go rename to azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_addons_test.go index 4651b3317b0b..82217679ed99 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_addons_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_addons_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -6,16 +6,13 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinux(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,31 +20,24 @@ func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinux(t *testing.T) CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.http_application_routing.#", "0"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.aci_connector_linux.#", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.aci_connector_linux.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.aci_connector_linux.0.subnet_name", fmt.Sprintf("acctestsubnet-aci%d", ri)), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.http_application_routing.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.aci_connector_linux.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.aci_connector_linux.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.aci_connector_linux.0.subnet_name", fmt.Sprintf("acctestsubnet-aci%d", data.RandomInteger)), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxDisabled(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -55,32 +45,25 @@ func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxDisabled(t *te CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxDisabledConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxDisabledConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.http_application_routing.#", "0"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.node_count", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.aci_connector_linux.#", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.aci_connector_linux.0.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.aci_connector_linux.0.subnet_name", ""), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.http_application_routing.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.node_count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.aci_connector_linux.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.aci_connector_linux.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.aci_connector_linux.0.subnet_name", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_addonProfileAzurePolicy(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -88,29 +71,22 @@ func testAccAzureRMKubernetesCluster_addonProfileAzurePolicy(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_addonProfileAzurePolicyConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_addonProfileAzurePolicyConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.azure_policy.#", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.azure_policy.0.enabled", "true"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.azure_policy.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.azure_policy.0.enabled", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_addonProfileKubeDashboard(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -118,29 +94,22 @@ func testAccAzureRMKubernetesCluster_addonProfileKubeDashboard(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_addonProfileKubeDashboardConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_addonProfileKubeDashboardConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.kube_dashboard.#", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.kube_dashboard.0.enabled", "false"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.kube_dashboard.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.kube_dashboard.0.enabled", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_addonProfileOMS(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -148,31 +117,24 @@ func testAccAzureRMKubernetesCluster_addonProfileOMS(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_addonProfileOMSConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_addonProfileOMSConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.http_application_routing.#", "0"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.#", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.0.enabled", "true"), - resource.TestCheckResourceAttrSet(resourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.http_application_routing.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.0.enabled", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_addonProfileOMSToggle(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -180,66 +142,49 @@ func testAccAzureRMKubernetesCluster_addonProfileOMSToggle(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_addonProfileOMSConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_addonProfileOMSConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.http_application_routing.#", "0"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.node_count", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.#", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.0.enabled", "true"), - resource.TestCheckResourceAttrSet(resourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.http_application_routing.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.node_count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.0.enabled", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id"), ), }, + data.ImportStep("service_principal.0.client_secret"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, - { - Config: testAccAzureRMKubernetesCluster_addonProfileOMSDisabledConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_addonProfileOMSDisabledConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.http_application_routing.#", "0"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.node_count", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.#", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.0.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id", ""), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.http_application_routing.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.node_count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id", ""), ), }, + data.ImportStep("service_principal.0.client_secret"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, - { - Config: testAccAzureRMKubernetesCluster_addonProfileOMSScaleWithoutBlockConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_addonProfileOMSScaleWithoutBlockConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.http_application_routing.#", "0"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.node_count", "2"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.#", "1"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.0.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id", ""), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.http_application_routing.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.node_count", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.0.log_analytics_workspace_id", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_addonProfileRouting(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -247,26 +192,21 @@ func testAccAzureRMKubernetesCluster_addonProfileRouting(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_addonProfileRoutingConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_addonProfileRoutingConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.http_application_routing.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "addon_profile.0.http_application_routing.0.enabled"), - resource.TestCheckResourceAttrSet(resourceName, "addon_profile.0.http_application_routing.0.http_application_routing_zone_name"), - resource.TestCheckResourceAttr(resourceName, "addon_profile.0.oms_agent.#", "0"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.http_application_routing.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.http_application_routing.0.enabled"), + resource.TestCheckResourceAttrSet(data.ResourceName, "addon_profile.0.http_application_routing.0.http_application_routing_zone_name"), + resource.TestCheckResourceAttr(data.ResourceName, "addon_profile.0.oms_agent.#", "0"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } -func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -340,10 +280,10 @@ resource "azurerm_kubernetes_cluster" "test" { network_plugin = "azure" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxDisabledConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_addonProfileAciConnectorLinuxDisabledConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -400,10 +340,10 @@ resource "azurerm_kubernetes_cluster" "test" { network_plugin = "azure" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_addonProfileAzurePolicyConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_addonProfileAzurePolicyConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -441,10 +381,10 @@ resource "azurerm_kubernetes_cluster" "test" { } } } -`, rInt, location, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_addonProfileKubeDashboardConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_addonProfileKubeDashboardConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -482,10 +422,10 @@ resource "azurerm_kubernetes_cluster" "test" { } } } -`, rInt, location, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_addonProfileOMSConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_addonProfileOMSConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -544,10 +484,10 @@ resource "azurerm_kubernetes_cluster" "test" { } } } -`, rInt, location, rInt, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_addonProfileOMSDisabledConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_addonProfileOMSDisabledConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -585,10 +525,10 @@ resource "azurerm_kubernetes_cluster" "test" { } } } -`, rInt, location, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_addonProfileOMSScaleWithoutBlockConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_addonProfileOMSScaleWithoutBlockConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -620,10 +560,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_addonProfileRoutingConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_addonProfileRoutingConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -661,5 +601,5 @@ resource "azurerm_kubernetes_cluster" "test" { } } } -`, rInt, location, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_auth_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_auth_test.go similarity index 57% rename from azurerm/internal/services/containers/resource_arm_kubernetes_cluster_auth_test.go rename to azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_auth_test.go index 463f6149819e..10f6892b4f26 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_auth_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_auth_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -6,16 +6,13 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func testAccAzureRMKubernetesCluster_apiServerAuthorizedIPRanges(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,40 +20,33 @@ func testAccAzureRMKubernetesCluster_apiServerAuthorizedIPRanges(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_apiServerAuthorizedIPRangesConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_apiServerAuthorizedIPRangesConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.#", "1"), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.azure_active_directory.#", "0"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_key"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_certificate"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.cluster_ca_certificate"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.host"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.username"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.password"), - resource.TestCheckResourceAttr(resourceName, "kube_admin_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "kube_admin_config_raw", ""), - resource.TestCheckResourceAttrSet(resourceName, "default_node_pool.0.max_pods"), - resource.TestCheckResourceAttr(resourceName, "api_server_authorized_ip_ranges.#", "3"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.azure_active_directory.#", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.cluster_ca_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.host"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.username"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.password"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config_raw", ""), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_node_pool.0.max_pods"), + resource.TestCheckResourceAttr(data.ResourceName, "api_server_authorized_ip_ranges.#", "3"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_enablePodSecurityPolicy(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -64,26 +54,19 @@ func testAccAzureRMKubernetesCluster_enablePodSecurityPolicy(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_enablePodSecurityPolicyConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_enablePodSecurityPolicyConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "enable_pod_security_policy", "true"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "enable_pod_security_policy", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_roleBasedAccessControl(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") @@ -93,30 +76,23 @@ func testAccAzureRMKubernetesCluster_roleBasedAccessControl(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_roleBasedAccessControlConfig(ri, location, clientId, clientSecret), + Config: testAccAzureRMKubernetesCluster_roleBasedAccessControlConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.#", "1"), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.azure_active_directory.#", "0"), - resource.TestCheckResourceAttr(resourceName, "kube_admin_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "kube_admin_config_raw", ""), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.azure_active_directory.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config_raw", ""), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_roleBasedAccessControlAAD(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") tenantId := os.Getenv("ARM_TENANT_ID") @@ -127,51 +103,41 @@ func testAccAzureRMKubernetesCluster_roleBasedAccessControlAAD(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(ri, location, clientId, clientSecret, ""), + Config: testAccAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(data, clientId, clientSecret, ""), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.#", "1"), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.azure_active_directory.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "role_based_access_control.0.azure_active_directory.0.client_app_id"), - resource.TestCheckResourceAttrSet(resourceName, "role_based_access_control.0.azure_active_directory.0.server_app_id"), - resource.TestCheckResourceAttrSet(resourceName, "role_based_access_control.0.azure_active_directory.0.server_app_secret"), - resource.TestCheckResourceAttrSet(resourceName, "role_based_access_control.0.azure_active_directory.0.tenant_id"), - resource.TestCheckResourceAttr(resourceName, "kube_admin_config.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "kube_admin_config_raw"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.azure_active_directory.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "role_based_access_control.0.azure_active_directory.0.client_app_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "role_based_access_control.0.azure_active_directory.0.server_app_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "role_based_access_control.0.azure_active_directory.0.server_app_secret"), + resource.TestCheckResourceAttrSet(data.ResourceName, "role_based_access_control.0.azure_active_directory.0.tenant_id"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_admin_config_raw"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - "role_based_access_control.0.azure_active_directory.0.server_app_secret", - }, - }, + data.ImportStep( + "service_principal.0.client_secret", + "role_based_access_control.0.azure_active_directory.0.server_app_secret", + ), { // should be no changes since the default for Tenant ID comes from the Provider block - Config: testAccAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(ri, location, clientId, clientSecret, tenantId), + Config: testAccAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(data, clientId, clientSecret, tenantId), PlanOnly: true, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - "role_based_access_control.0.azure_active_directory.0.server_app_secret", - }, - }, + data.ImportStep( + "service_principal.0.client_secret", + "role_based_access_control.0.azure_active_directory.0.server_app_secret", + ), }, }) } -func testAccAzureRMKubernetesCluster_apiServerAuthorizedIPRangesConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_apiServerAuthorizedIPRangesConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -221,10 +187,10 @@ resource "azurerm_kubernetes_cluster" "test" { "8.8.2.0/24", ] } -`, rInt, location, rInt, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_enablePodSecurityPolicyConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_enablePodSecurityPolicyConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -253,10 +219,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_roleBasedAccessControlConfig(rInt int, location, clientId, clientSecret string) string { +func testAccAzureRMKubernetesCluster_roleBasedAccessControlConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -292,10 +258,10 @@ resource "azurerm_kubernetes_cluster" "test" { enabled = true } } -`, rInt, location, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(rInt int, location, clientId, clientSecret, tenantId string) string { +func testAccAzureRMKubernetesCluster_roleBasedAccessControlAADConfig(data acceptance.TestData, clientId, clientSecret, tenantId string) string { return fmt.Sprintf(` variable "tenant_id" { default = "%s" @@ -342,5 +308,5 @@ resource "azurerm_kubernetes_cluster" "test" { } } } -`, tenantId, rInt, location, rInt, rInt, rInt, clientId, clientSecret, clientId, clientSecret, clientId) +`, tenantId, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret, clientId, clientSecret, clientId) } diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_legacy_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_legacy_test.go similarity index 72% rename from azurerm/internal/services/containers/resource_arm_kubernetes_cluster_legacy_test.go rename to azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_legacy_test.go index 67e080589bef..0ab907dbfe96 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_legacy_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_legacy_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -6,18 +6,15 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) // NOTE: all of the tests in this file are for functionality which will be removed in 2.0 func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySet(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -25,10 +22,10 @@ func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySet(t *te CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySetConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySetConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "agent_pool_profile.0.type", "AvailabilitySet"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.type", "AvailabilitySet"), ), // since users are prompted to move to `default_node_pool` ExpectNonEmptyPlan: true, @@ -38,11 +35,9 @@ func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySet(t *te } func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSS(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -50,10 +45,10 @@ func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSS(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSSConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSSConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "agent_pool_profile.0.type", "VirtualMachineScaleSets"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "agent_pool_profile.0.type", "VirtualMachineScaleSets"), ), // since users are prompted to move to `default_node_pool` ExpectNonEmptyPlan: true, @@ -62,7 +57,7 @@ func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSS(t *testing.T) { }) } -func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySetConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileAvailabilitySetConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -86,10 +81,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSSConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_legacyAgentPoolProfileVMSSConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -114,5 +109,5 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_network_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_network_test.go similarity index 70% rename from azurerm/internal/services/containers/resource_arm_kubernetes_cluster_network_test.go rename to azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_network_test.go index 60d0fc1b1206..4974b6c162eb 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_network_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_network_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -6,16 +6,13 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func testAccAzureRMKubernetesCluster_advancedNetworkingKubenet(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,30 +20,21 @@ func testAccAzureRMKubernetesCluster_advancedNetworkingKubenet(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_advancedNetworkingConfig(ri, clientId, clientSecret, location, "kubenet"), + Config: testAccAzureRMKubernetesCluster_advancedNetworkingConfig(data, clientId, clientSecret, data.Locations.Primary, "kubenet"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "kubenet"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "kubenet"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_advancedNetworkingKubenetComplete(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,30 +42,21 @@ func testAccAzureRMKubernetesCluster_advancedNetworkingKubenetComplete(t *testin CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(ri, clientId, clientSecret, location, "kubenet"), + Config: testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(data, clientId, clientSecret, data.Locations.Primary, "kubenet"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "kubenet"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "kubenet"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_advancedNetworkingAzure(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -85,30 +64,21 @@ func testAccAzureRMKubernetesCluster_advancedNetworkingAzure(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_advancedNetworkingConfig(ri, clientId, clientSecret, location, "azure"), + Config: testAccAzureRMKubernetesCluster_advancedNetworkingConfig(data, clientId, clientSecret, data.Locations.Primary, "azure"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "azure"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_advancedNetworkingAzureComplete(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -116,30 +86,21 @@ func testAccAzureRMKubernetesCluster_advancedNetworkingAzureComplete(t *testing. CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(ri, clientId, clientSecret, location, "azure"), + Config: testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(data, clientId, clientSecret, data.Locations.Primary, "azure"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "azure"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicy(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -147,31 +108,22 @@ func testAccAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicy(t *test CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(ri, clientId, clientSecret, location, "azure", "calico"), + Config: testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(data, clientId, clientSecret, data.Locations.Primary, "azure", "calico"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "azure"), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_policy", "calico"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_policy", "calico"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyComplete(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -179,31 +131,22 @@ func testAccAzureRMKubernetesCluster_advancedNetworkingAzureCalicoPolicyComplete CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(ri, clientId, clientSecret, location, "azure", "calico"), + Config: testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(data, clientId, clientSecret, data.Locations.Primary, "azure", "calico"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "azure"), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_policy", "calico"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_policy", "calico"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicy(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -211,31 +154,22 @@ func testAccAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicy(t *testing CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(ri, clientId, clientSecret, location, "azure", "azure"), + Config: testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(data, clientId, clientSecret, data.Locations.Primary, "azure", "azure"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "azure"), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_policy", "azure"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_policy", "azure"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyComplete(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -243,31 +177,22 @@ func testAccAzureRMKubernetesCluster_advancedNetworkingAzureNPMPolicyComplete(t CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(ri, clientId, clientSecret, location, "azure", "azure"), + Config: testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(data, clientId, clientSecret, data.Locations.Primary, "azure", "azure"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "azure"), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_policy", "azure"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_plugin", "azure"), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.network_policy", "azure"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_enableNodePublicIP(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -276,62 +201,39 @@ func testAccAzureRMKubernetesCluster_enableNodePublicIP(t *testing.T) { Steps: []resource.TestStep{ { // Enabled - Config: testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(ri, clientId, clientSecret, location, true), + Config: testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(data, clientId, clientSecret, data.Locations.Primary, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.enable_node_public_ip", "true"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.enable_node_public_ip", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), { // Disabled - Config: testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(ri, clientId, clientSecret, location, false), + Config: testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(data, clientId, clientSecret, data.Locations.Primary, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.enable_node_public_ip", "false"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.enable_node_public_ip", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), { // Enabled - Config: testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(ri, clientId, clientSecret, location, true), + Config: testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(data, clientId, clientSecret, data.Locations.Primary, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.enable_node_public_ip", "true"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.enable_node_public_ip", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_internalNetwork(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -339,30 +241,21 @@ func testAccAzureRMKubernetesCluster_internalNetwork(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_internalNetworkConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_internalNetworkConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.max_pods", "60"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.max_pods", "60"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_standardLoadBalancer(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -370,30 +263,21 @@ func testAccAzureRMKubernetesCluster_standardLoadBalancer(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_standardLoadBalancerConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_standardLoadBalancerConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.load_balancer_sku", "Standard"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.load_balancer_sku", "Standard"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_standardLoadBalancerComplete(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -401,25 +285,18 @@ func testAccAzureRMKubernetesCluster_standardLoadBalancerComplete(t *testing.T) CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_standardLoadBalancerCompleteConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_standardLoadBalancerCompleteConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.load_balancer_sku", "Standard"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.load_balancer_sku", "Standard"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "service_principal.0.client_secret", - }, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } -func testAccAzureRMKubernetesCluster_advancedNetworkingConfig(rInt int, clientId string, clientSecret string, location string, networkPlugin string) string { +func testAccAzureRMKubernetesCluster_advancedNetworkingConfig(data acceptance.TestData, clientId string, clientSecret string, location string, networkPlugin string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -475,10 +352,10 @@ resource "azurerm_kubernetes_cluster" "test" { network_plugin = "%s" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret, networkPlugin) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret, networkPlugin) } -func testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(rInt int, clientId string, clientSecret string, location string, networkPlugin string) string { +func testAccAzureRMKubernetesCluster_advancedNetworkingCompleteConfig(data acceptance.TestData, clientId string, clientSecret string, location string, networkPlugin string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -555,10 +432,10 @@ resource "azurerm_kubernetes_cluster" "test" { service_cidr = "10.10.0.0/16" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret, networkPlugin) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret, networkPlugin) } -func testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(rInt int, clientId string, clientSecret string, location string, networkPlugin string, networkPolicy string) string { +func testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyConfig(data acceptance.TestData, clientId string, clientSecret string, location string, networkPlugin string, networkPolicy string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -610,10 +487,10 @@ resource "azurerm_kubernetes_cluster" "test" { network_policy = "%s" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret, networkPlugin, networkPolicy) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret, networkPlugin, networkPolicy) } -func testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(rInt int, clientId string, clientSecret string, location string, networkPlugin string, networkPolicy string) string { +func testAccAzureRMKubernetesCluster_advancedNetworkingWithPolicyCompleteConfig(data acceptance.TestData, clientId string, clientSecret string, location string, networkPlugin string, networkPolicy string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -687,10 +564,10 @@ resource "azurerm_kubernetes_cluster" "test" { service_cidr = "10.10.0.0/16" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret, networkPlugin, networkPolicy) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret, networkPlugin, networkPolicy) } -func testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(rInt int, clientId, clientSecret, location string, enabled bool) string { +func testAccAzureRMKubernetesCluster_enableNodePublicIPConfig(data acceptance.TestData, clientId, clientSecret, location string, enabled bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -715,10 +592,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, enabled, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, enabled, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_internalNetworkConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_internalNetworkConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -771,10 +648,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_standardLoadBalancerConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_standardLoadBalancerConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -827,10 +704,10 @@ resource "azurerm_kubernetes_cluster" "test" { load_balancer_sku = "Standard" } } -`, rInt, location, rInt, rInt, rInt, rInt, currentKubernetesVersion, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, currentKubernetesVersion, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_standardLoadBalancerCompleteConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_standardLoadBalancerCompleteConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -905,5 +782,5 @@ resource "azurerm_kubernetes_cluster" "test" { load_balancer_sku = "Standard" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, currentKubernetesVersion, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, currentKubernetesVersion, data.RandomInteger, clientId, clientSecret) } diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_node_pool_test.go similarity index 75% rename from azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool_test.go rename to azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_node_pool_test.go index 93f92f197479..d23b3b40744c 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_node_pool_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_node_pool_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -9,18 +9,16 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers" ) func testAccAzureRMKubernetesClusterNodePool_autoScale(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -29,50 +27,36 @@ func testAccAzureRMKubernetesClusterNodePool_autoScale(t *testing.T) { Steps: []resource.TestStep{ { // Enabled - Config: testAccAzureRMKubernetesClusterNodePool_autoScaleConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_autoScaleConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { // Disabled - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { // Enabled - Config: testAccAzureRMKubernetesClusterNodePool_autoScaleConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_autoScaleConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_autoScaleUpdate(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,48 +64,34 @@ func testAccAzureRMKubernetesClusterNodePool_autoScaleUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_autoScaleNodeCountConfig(ri, clientId, clientSecret, location, 1, 3), + Config: testAccAzureRMKubernetesClusterNodePool_autoScaleNodeCountConfig(data, clientId, clientSecret, data.Locations.Primary, 1, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMKubernetesClusterNodePool_autoScaleNodeCountConfig(ri, clientId, clientSecret, location, 3, 5), + Config: testAccAzureRMKubernetesClusterNodePool_autoScaleNodeCountConfig(data, clientId, clientSecret, data.Locations.Primary, 3, 5), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMKubernetesClusterNodePool_autoScaleNodeCountConfig(ri, clientId, clientSecret, location, 1, 3), + Config: testAccAzureRMKubernetesClusterNodePool_autoScaleNodeCountConfig(data, clientId, clientSecret, data.Locations.Primary, 1, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_availabilityZones(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -129,25 +99,20 @@ func testAccAzureRMKubernetesClusterNodePool_availabilityZones(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_availabilityZonesConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_availabilityZonesConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_errorForAvailabilitySet(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -155,7 +120,7 @@ func testAccAzureRMKubernetesClusterNodePool_errorForAvailabilitySet(t *testing. CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_availabilitySetConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_availabilitySetConfig(data, clientId, clientSecret), ExpectError: regexp.MustCompile("must be a VirtualMachineScaleSet to attach multiple node pools"), }, }, @@ -163,10 +128,9 @@ func testAccAzureRMKubernetesClusterNodePool_errorForAvailabilitySet(t *testing. } func testAccAzureRMKubernetesClusterNodePool_multiplePools(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,7 +138,7 @@ func testAccAzureRMKubernetesClusterNodePool_multiplePools(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_multiplePoolsConfig(ri, clientId, clientSecret, location, 3), + Config: testAccAzureRMKubernetesClusterNodePool_multiplePoolsConfig(data, clientId, clientSecret, 3), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKubernetesNodePoolExists("azurerm_kubernetes_cluster_node_pool.autoscale"), testCheckAzureRMKubernetesNodePoolExists("azurerm_kubernetes_cluster_node_pool.manual"), @@ -195,11 +159,9 @@ func testAccAzureRMKubernetesClusterNodePool_multiplePools(t *testing.T) { } func testAccAzureRMKubernetesClusterNodePool_manualScale(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -207,25 +169,20 @@ func testAccAzureRMKubernetesClusterNodePool_manualScale(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePools(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -233,7 +190,7 @@ func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePools(t *testing CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKubernetesNodePoolExists("azurerm_kubernetes_cluster_node_pool.first"), testCheckAzureRMKubernetesNodePoolExists("azurerm_kubernetes_cluster_node_pool.second"), @@ -254,10 +211,9 @@ func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePools(t *testing } func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsUpdate(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -265,7 +221,7 @@ func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsUpdate(t *t CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsNodeCountConfig(ri, clientId, clientSecret, location, 1), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsNodeCountConfig(data, clientId, clientSecret, 1), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKubernetesNodePoolExists("azurerm_kubernetes_cluster_node_pool.first"), testCheckAzureRMKubernetesNodePoolExists("azurerm_kubernetes_cluster_node_pool.second"), @@ -282,7 +238,7 @@ func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsUpdate(t *t ImportStateVerify: true, }, { - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsNodeCountConfig(ri, clientId, clientSecret, location, 2), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsNodeCountConfig(data, clientId, clientSecret, 2), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKubernetesNodePoolExists("azurerm_kubernetes_cluster_node_pool.first"), testCheckAzureRMKubernetesNodePoolExists("azurerm_kubernetes_cluster_node_pool.second"), @@ -303,11 +259,9 @@ func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsUpdate(t *t } func testAccAzureRMKubernetesClusterNodePool_manualScaleUpdate(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -315,49 +269,35 @@ func testAccAzureRMKubernetesClusterNodePool_manualScaleUpdate(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleNodeCountConfig(ri, clientId, clientSecret, location, 1), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleNodeCountConfig(data, clientId, clientSecret, 1), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { // up - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleNodeCountConfig(ri, clientId, clientSecret, location, 3), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleNodeCountConfig(data, clientId, clientSecret, 3), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), - }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + }, data.ImportStep(), { // and down - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleNodeCountConfig(ri, clientId, clientSecret, location, 1), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleNodeCountConfig(data, clientId, clientSecret, 1), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_manualScaleVMSku(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -365,37 +305,27 @@ func testAccAzureRMKubernetesClusterNodePool_manualScaleVMSku(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleVMSkuConfig(ri, clientId, clientSecret, location, "Standard_F2s_v2"), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleVMSkuConfig(data, clientId, clientSecret, "Standard_F2s_v2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, + data.ImportStep(), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, - { - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleVMSkuConfig(ri, clientId, clientSecret, location, "Standard_F4s_v2"), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleVMSkuConfig(data, clientId, clientSecret, "Standard_F4s_v2"), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_nodePublicIP(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -403,26 +333,20 @@ func testAccAzureRMKubernetesClusterNodePool_nodePublicIP(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_nodePublicIPConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_nodePublicIPConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_nodeTaints(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -430,16 +354,12 @@ func testAccAzureRMKubernetesClusterNodePool_nodeTaints(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_nodeTaintsConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_nodeTaintsConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -450,11 +370,9 @@ func testAccAzureRMKubernetesClusterNodePool_requiresImport(t *testing.T) { return } - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -462,13 +380,13 @@ func testAccAzureRMKubernetesClusterNodePool_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_manualScaleConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_manualScaleConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, { - Config: testAccAzureRMKubernetesClusterNodePool_requiresImportConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_requiresImportConfig(data, clientId, clientSecret), ExpectError: acceptance.RequiresImportError("azurerm_kubernetes_cluster_node_pool"), }, }, @@ -476,11 +394,9 @@ func testAccAzureRMKubernetesClusterNodePool_requiresImport(t *testing.T) { } func testAccAzureRMKubernetesClusterNodePool_osDiskSizeGB(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -488,26 +404,20 @@ func testAccAzureRMKubernetesClusterNodePool_osDiskSizeGB(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_osDiskSizeGBConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_osDiskSizeGBConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_virtualNetworkAutomatic(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -515,26 +425,20 @@ func testAccAzureRMKubernetesClusterNodePool_virtualNetworkAutomatic(t *testing. CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_virtualNetworkAutomaticConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_virtualNetworkAutomaticConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_virtualNetworkManual(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -542,26 +446,20 @@ func testAccAzureRMKubernetesClusterNodePool_virtualNetworkManual(t *testing.T) CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_virtualNetworkManualConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_virtualNetworkManualConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_windows(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster_node_pool.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -569,25 +467,20 @@ func testAccAzureRMKubernetesClusterNodePool_windows(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_windowsConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_windowsConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesNodePoolExists(resourceName), + testCheckAzureRMKubernetesNodePoolExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func testAccAzureRMKubernetesClusterNodePool_windowsAndLinux(t *testing.T) { - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster_node_pool", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -595,7 +488,7 @@ func testAccAzureRMKubernetesClusterNodePool_windowsAndLinux(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterNodePoolDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesClusterNodePool_windowsAndLinuxConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesClusterNodePool_windowsAndLinuxConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( testCheckAzureRMKubernetesNodePoolExists("azurerm_kubernetes_cluster_node_pool.linux"), testCheckAzureRMKubernetesNodePoolExists("azurerm_kubernetes_cluster_node_pool.windows"), @@ -623,7 +516,7 @@ func testCheckAzureRMKubernetesClusterNodePoolDestroy(s *terraform.State) error name := rs.Primary.Attributes["name"] kubernetesClusterId := rs.Primary.Attributes["kubernetes_cluster_id"] - parsedK8sId, err := ParseKubernetesClusterID(kubernetesClusterId) + parsedK8sId, err := containers.ParseKubernetesClusterID(kubernetesClusterId) if err != nil { return fmt.Errorf("Error parsing kubernetes cluster id: %+v", err) } @@ -654,7 +547,7 @@ func testCheckAzureRMKubernetesNodePoolExists(resourceName string) resource.Test name := rs.Primary.Attributes["name"] kubernetesClusterId := rs.Primary.Attributes["kubernetes_cluster_id"] - parsedK8sId, err := ParseKubernetesClusterID(kubernetesClusterId) + parsedK8sId, err := containers.ParseKubernetesClusterID(kubernetesClusterId) if err != nil { return fmt.Errorf("Error parsing kubernetes cluster id: %+v", err) } @@ -675,8 +568,8 @@ func testCheckAzureRMKubernetesNodePoolExists(resourceName string) resource.Test } } -func testAccAzureRMKubernetesClusterNodePool_autoScaleConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_autoScaleConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -691,8 +584,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_autoScaleNodeCountConfig(rInt int, clientId, clientSecret, location string, min int, max int) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_autoScaleNodeCountConfig(data acceptance.TestData, clientId, clientSecret, location string, min int, max int) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -707,7 +600,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template, min, max) } -func testAccAzureRMKubernetesClusterNodePool_availabilitySetConfig(rInt int, clientId, clientSecret, location string) string { +func testAccAzureRMKubernetesClusterNodePool_availabilitySetConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -739,10 +632,10 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { vm_size = "Standard_DS2_v2" node_count = 1 } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesClusterNodePool_availabilityZonesConfig(rInt int, clientId, clientSecret, location string) string { +func testAccAzureRMKubernetesClusterNodePool_availabilityZonesConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -796,11 +689,11 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { availability_zones = ["1"] vnet_subnet_id = azurerm_subnet.test.id } -`, rInt, location, rInt, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesClusterNodePool_manualScaleConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_manualScaleConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -813,8 +706,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -834,8 +727,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "second" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsNodeCountConfig(rInt int, clientId, clientSecret, location string, numberOfAgents int) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_manualScaleMultiplePoolsNodeCountConfig(data acceptance.TestData, clientId, clientSecret string, numberOfAgents int) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -855,8 +748,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "second" { `, template, numberOfAgents, numberOfAgents) } -func testAccAzureRMKubernetesClusterNodePool_manualScaleNodeCountConfig(rInt int, clientId, clientSecret, location string, numberOfAgents int) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_manualScaleNodeCountConfig(data acceptance.TestData, clientId, clientSecret string, numberOfAgents int) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -869,8 +762,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template, numberOfAgents) } -func testAccAzureRMKubernetesClusterNodePool_manualScaleVMSkuConfig(rInt int, clientId, clientSecret, location, sku string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_manualScaleVMSkuConfig(data acceptance.TestData, clientId, clientSecret, sku string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -883,8 +776,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template, sku) } -func testAccAzureRMKubernetesClusterNodePool_multiplePoolsConfig(rInt int, clientId, clientSecret, location string, numberOfAgents int) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_multiplePoolsConfig(data acceptance.TestData, clientId, clientSecret string, numberOfAgents int) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -906,8 +799,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "manual" { `, template, numberOfAgents) } -func testAccAzureRMKubernetesClusterNodePool_nodePublicIPConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_nodePublicIPConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -921,8 +814,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_nodeTaintsConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_nodeTaintsConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -938,8 +831,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_requiresImportConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_manualScaleConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_requiresImportConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_manualScaleConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -952,8 +845,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "import" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_osDiskSizeGBConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_osDiskSizeGBConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -967,8 +860,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_virtualNetworkAutomaticConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateVirtualNetworkConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_virtualNetworkAutomaticConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateVirtualNetworkConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -984,8 +877,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_virtualNetworkManualConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateVirtualNetworkConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_virtualNetworkManualConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateVirtualNetworkConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -999,8 +892,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_windowsConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateWindowsConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_windowsConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateWindowsConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -1014,8 +907,8 @@ resource "azurerm_kubernetes_cluster_node_pool" "test" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_windowsAndLinuxConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesClusterNodePool_templateWindowsConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesClusterNodePool_windowsAndLinuxConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesClusterNodePool_templateWindowsConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -1036,7 +929,7 @@ resource "azurerm_kubernetes_cluster_node_pool" "windows" { `, template) } -func testAccAzureRMKubernetesClusterNodePool_templateConfig(rInt int, clientId, clientSecret, location string) string { +func testAccAzureRMKubernetesClusterNodePool_templateConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1060,10 +953,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesClusterNodePool_templateVirtualNetworkConfig(rInt int, clientId, clientSecret, location string) string { +func testAccAzureRMKubernetesClusterNodePool_templateVirtualNetworkConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1125,10 +1018,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, rInt, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesClusterNodePool_templateWindowsConfig(rInt int, clientId, clientSecret, location string) string { +func testAccAzureRMKubernetesClusterNodePool_templateWindowsConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -1165,5 +1058,5 @@ resource "azurerm_kubernetes_cluster" "test" { service_cidr = "10.10.0.0/16" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_other_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_other_test.go similarity index 55% rename from azurerm/internal/services/containers/resource_arm_kubernetes_cluster_other_test.go rename to azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_other_test.go index b466b36c1532..7bb9d3e590b7 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_other_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_other_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -6,17 +6,14 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func testAccAzureRMKubernetesCluster_basicAvailabilitySet(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -24,39 +21,32 @@ func testAccAzureRMKubernetesCluster_basicAvailabilitySet(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_basicAvailabilitySetConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_basicAvailabilitySetConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.#", "1"), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.azure_active_directory.#", "0"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_key"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_certificate"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.cluster_ca_certificate"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.host"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.username"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.password"), - resource.TestCheckResourceAttr(resourceName, "kube_admin_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "kube_admin_config_raw", ""), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.load_balancer_sku", "Basic"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.azure_active_directory.#", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.cluster_ca_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.host"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.username"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.password"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config_raw", ""), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.load_balancer_sku", "Basic"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_basicVMSS(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -64,39 +54,32 @@ func testAccAzureRMKubernetesCluster_basicVMSS(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_basicVMSSConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_basicVMSSConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.#", "1"), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "role_based_access_control.0.azure_active_directory.#", "0"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_key"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_certificate"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.cluster_ca_certificate"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.host"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.username"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.password"), - resource.TestCheckResourceAttr(resourceName, "kube_admin_config.#", "0"), - resource.TestCheckResourceAttr(resourceName, "kube_admin_config_raw", ""), - resource.TestCheckResourceAttr(resourceName, "network_profile.0.load_balancer_sku", "Basic"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "role_based_access_control.0.azure_active_directory.#", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.cluster_ca_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.host"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.username"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.password"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "kube_admin_config_raw", ""), + resource.TestCheckResourceAttr(data.ResourceName, "network_profile.0.load_balancer_sku", "Basic"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_privateLinkOn(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() initialPrivateIpAddressCdir := "10.0.0.0/8" modifiedPrivateIpAddressCdir := "10.230.0.0/16" @@ -107,39 +90,32 @@ func testAccAzureRMKubernetesCluster_privateLinkOn(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_privateLinkConfig(ri, clientId, clientSecret, location, initialPrivateIpAddressCdir, true), + Config: testAccAzureRMKubernetesCluster_privateLinkConfig(data, clientId, clientSecret, data.Locations.Primary, initialPrivateIpAddressCdir, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "private_fqdn"), - resource.TestCheckResourceAttr(resourceName, "api_server_authorized_ip_ranges.#", "1"), - resource.TestCheckResourceAttr(resourceName, "private_link_enabled", "true"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "private_fqdn"), + resource.TestCheckResourceAttr(data.ResourceName, "api_server_authorized_ip_ranges.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "private_link_enabled", "true"), ), }, { - Config: testAccAzureRMKubernetesCluster_privateLinkConfig(ri, clientId, clientSecret, location, modifiedPrivateIpAddressCdir, true), + Config: testAccAzureRMKubernetesCluster_privateLinkConfig(data, clientId, clientSecret, data.Locations.Primary, modifiedPrivateIpAddressCdir, true), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "private_fqdn"), - resource.TestCheckResourceAttr(resourceName, "api_server_authorized_ip_ranges.#", "1"), - resource.TestCheckResourceAttr(resourceName, "private_link_enabled", "true"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "private_fqdn"), + resource.TestCheckResourceAttr(data.ResourceName, "api_server_authorized_ip_ranges.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "private_link_enabled", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_privateLinkOff(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() initialPrivateIpAddressCdir := "10.0.0.0/8" modifiedPrivateIpAddressCdir := "10.230.0.0/16" @@ -150,26 +126,21 @@ func testAccAzureRMKubernetesCluster_privateLinkOff(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_privateLinkConfig(ri, clientId, clientSecret, location, initialPrivateIpAddressCdir, false), + Config: testAccAzureRMKubernetesCluster_privateLinkConfig(data, clientId, clientSecret, data.Locations.Primary, initialPrivateIpAddressCdir, false), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "api_server_authorized_ip_ranges.#", "1"), - resource.TestCheckResourceAttr(resourceName, "private_link_enabled", "false"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "api_server_authorized_ip_ranges.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "private_link_enabled", "false"), ), }, { - Config: testAccAzureRMKubernetesCluster_privateLinkConfig(ri, clientId, clientSecret, location, modifiedPrivateIpAddressCdir, false), + Config: testAccAzureRMKubernetesCluster_privateLinkConfig(data, clientId, clientSecret, data.Locations.Primary, modifiedPrivateIpAddressCdir, false), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "api_server_authorized_ip_ranges.#", "1"), - resource.TestCheckResourceAttr(resourceName, "private_link_enabled", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "api_server_authorized_ip_ranges.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "private_link_enabled", "false"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } @@ -180,11 +151,9 @@ func testAccAzureRMKubernetesCluster_requiresImport(t *testing.T) { return } - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -192,13 +161,13 @@ func testAccAzureRMKubernetesCluster_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_basicVMSSConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_basicVMSSConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), ), }, { - Config: testAccAzureRMKubernetesCluster_requiresImportConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_requiresImportConfig(data, clientId, clientSecret), ExpectError: acceptance.RequiresImportError("azurerm_kubernetes_cluster"), }, }, @@ -206,11 +175,9 @@ func testAccAzureRMKubernetesCluster_requiresImport(t *testing.T) { } func testAccAzureRMKubernetesCluster_linuxProfile(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -218,34 +185,27 @@ func testAccAzureRMKubernetesCluster_linuxProfile(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_linuxProfileConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_linuxProfileConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_key"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_certificate"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.cluster_ca_certificate"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.host"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.username"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.password"), - resource.TestCheckResourceAttrSet(resourceName, "linux_profile.0.admin_username"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.cluster_ca_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.host"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.username"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.password"), + resource.TestCheckResourceAttrSet(data.ResourceName, "linux_profile.0.admin_username"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_nodeTaints(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -253,28 +213,21 @@ func testAccAzureRMKubernetesCluster_nodeTaints(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_nodeTaintsConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_nodeTaintsConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.node_taints.0", "key=value:PreferNoSchedule"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.node_taints.0", "key=value:PreferNoSchedule"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_nodeResourceGroup(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -282,25 +235,18 @@ func testAccAzureRMKubernetesCluster_nodeResourceGroup(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_nodeResourceGroupConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_nodeResourceGroupConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_upgrade(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") @@ -310,17 +256,17 @@ func testAccAzureRMKubernetesCluster_upgrade(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_upgradeConfig(ri, location, clientId, clientSecret, olderKubernetesVersion), + Config: testAccAzureRMKubernetesCluster_upgradeConfig(data, clientId, clientSecret, olderKubernetesVersion), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kubernetes_version", olderKubernetesVersion), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kubernetes_version", olderKubernetesVersion), ), }, { - Config: testAccAzureRMKubernetesCluster_upgradeConfig(ri, location, clientId, clientSecret, currentKubernetesVersion), + Config: testAccAzureRMKubernetesCluster_upgradeConfig(data, clientId, clientSecret, currentKubernetesVersion), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kubernetes_version", currentKubernetesVersion), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kubernetes_version", currentKubernetesVersion), ), }, }, @@ -328,11 +274,9 @@ func testAccAzureRMKubernetesCluster_upgrade(t *testing.T) { } func testAccAzureRMKubernetesCluster_tags(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -340,39 +284,27 @@ func testAccAzureRMKubernetesCluster_tags(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_tagsConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_tagsConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), ), }, + data.ImportStep("service_principal.0.client_secret"), { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, - { - Config: testAccAzureRMKubernetesCluster_tagsUpdatedConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_tagsUpdatedConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_windowsProfile(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -380,39 +312,32 @@ func testAccAzureRMKubernetesCluster_windowsProfile(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_windowsProfileConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_windowsProfileConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_key"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.client_certificate"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.cluster_ca_certificate"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.host"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.username"), - resource.TestCheckResourceAttrSet(resourceName, "kube_config.0.password"), - resource.TestCheckResourceAttrSet(resourceName, "default_node_pool.0.max_pods"), - resource.TestCheckResourceAttrSet(resourceName, "linux_profile.0.admin_username"), - resource.TestCheckResourceAttrSet(resourceName, "windows_profile.0.admin_username"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.client_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.cluster_ca_certificate"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.host"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.username"), + resource.TestCheckResourceAttrSet(data.ResourceName, "kube_config.0.password"), + resource.TestCheckResourceAttrSet(data.ResourceName, "default_node_pool.0.max_pods"), + resource.TestCheckResourceAttrSet(data.ResourceName, "linux_profile.0.admin_username"), + resource.TestCheckResourceAttrSet(data.ResourceName, "windows_profile.0.admin_username"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "windows_profile.0.admin_password", - "service_principal.0.client_secret", - }, - }, + data.ImportStep( + "windows_profile.0.admin_password", + "service_principal.0.client_secret", + ), }, }) } func testAccAzureRMKubernetesCluster_managedClusterIdentiy(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -420,22 +345,17 @@ func testAccAzureRMKubernetesCluster_managedClusterIdentiy(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_managedClusterIdentityConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_managedClusterIdentityConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } -func testAccAzureRMKubernetesCluster_basicAvailabilitySetConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_basicAvailabilitySetConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -460,10 +380,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_basicVMSSConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_basicVMSSConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -487,10 +407,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_privateLinkConfig(rInt int, clientId string, clientSecret string, location string, cdir string, enablePrivateLink bool) string { +func testAccAzureRMKubernetesCluster_privateLinkConfig(data acceptance.TestData, clientId string, clientSecret string, location string, cdir string, enablePrivateLink bool) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -530,11 +450,11 @@ resource "azurerm_kubernetes_cluster" "test" { api_server_authorized_ip_ranges = [ "%s"] private_link_enabled = %t } -`, rInt, location, rInt, rInt, rInt, clientId, clientSecret, cdir, enablePrivateLink) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret, cdir, enablePrivateLink) } -func testAccAzureRMKubernetesCluster_requiresImportConfig(rInt int, clientId, clientSecret, location string) string { - template := testAccAzureRMKubernetesCluster_basicVMSSConfig(rInt, clientId, clientSecret, location) +func testAccAzureRMKubernetesCluster_requiresImportConfig(data acceptance.TestData, clientId, clientSecret string) string { + template := testAccAzureRMKubernetesCluster_basicVMSSConfig(data, clientId, clientSecret) return fmt.Sprintf(` %s @@ -558,7 +478,7 @@ resource "azurerm_kubernetes_cluster" "import" { `, template, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_linuxProfileConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_linuxProfileConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -590,10 +510,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_nodeTaintsConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_nodeTaintsConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -620,10 +540,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_nodeResourceGroupConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_nodeResourceGroupConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -648,10 +568,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_tagsConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_tagsConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -679,10 +599,10 @@ resource "azurerm_kubernetes_cluster" "test" { dimension = "C-137" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_tagsUpdatedConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_tagsUpdatedConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -710,10 +630,10 @@ resource "azurerm_kubernetes_cluster" "test" { dimension = "D-99" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_upgradeConfig(rInt int, location, clientId, clientSecret, version string) string { +func testAccAzureRMKubernetesCluster_upgradeConfig(data acceptance.TestData, clientId, clientSecret, version string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -746,10 +666,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, version, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, version, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_windowsProfileConfig(rInt int, clientId, clientSecret, location string) string { +func testAccAzureRMKubernetesCluster_windowsProfileConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -795,10 +715,10 @@ resource "azurerm_kubernetes_cluster" "test" { service_cidr = "10.10.0.0/16" } } -`, rInt, location, rInt, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_managedClusterIdentityConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_managedClusterIdentityConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -827,5 +747,5 @@ resource "azurerm_kubernetes_cluster" "test" { type = "SystemAssigned" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_scaling_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_scaling_test.go similarity index 55% rename from azurerm/internal/services/containers/resource_arm_kubernetes_cluster_scaling_test.go rename to azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_scaling_test.go index b3677d07255d..eb9ea05211b9 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_scaling_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_scaling_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" @@ -6,16 +6,13 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func testAccAzureRMKubernetesCluster_addAgent(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -23,16 +20,16 @@ func testAccAzureRMKubernetesCluster_addAgent(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_addAgentConfig(ri, clientId, clientSecret, location, 1), + Config: testAccAzureRMKubernetesCluster_addAgentConfig(data, clientId, clientSecret, data.Locations.Primary, 1), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.node_count", "1"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.node_count", "1"), ), }, { - Config: testAccAzureRMKubernetesCluster_addAgentConfig(ri, clientId, clientSecret, location, 2), + Config: testAccAzureRMKubernetesCluster_addAgentConfig(data, clientId, clientSecret, data.Locations.Primary, 2), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.node_count", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.node_count", "2"), ), }, }, @@ -40,11 +37,9 @@ func testAccAzureRMKubernetesCluster_addAgent(t *testing.T) { } func testAccAzureRMKubernetesCluster_removeAgent(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,16 +47,16 @@ func testAccAzureRMKubernetesCluster_removeAgent(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_addAgentConfig(ri, clientId, clientSecret, location, 2), + Config: testAccAzureRMKubernetesCluster_addAgentConfig(data, clientId, clientSecret, data.Locations.Primary, 2), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.node_count", "2"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.node_count", "2"), ), }, { - Config: testAccAzureRMKubernetesCluster_addAgentConfig(ri, clientId, clientSecret, location, 1), + Config: testAccAzureRMKubernetesCluster_addAgentConfig(data, clientId, clientSecret, data.Locations.Primary, 1), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.node_count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.node_count", "1"), ), }, }, @@ -69,11 +64,9 @@ func testAccAzureRMKubernetesCluster_removeAgent(t *testing.T) { } func testAccAzureRMKubernetesCluster_autoScalingNodeCountUnset(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -81,30 +74,25 @@ func testAccAzureRMKubernetesCluster_autoScalingNodeCountUnset(t *testing.T) { CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_autoscaleNodeCountUnsetConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_autoscaleNodeCountUnsetConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.min_count", "2"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.max_count", "4"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.enable_auto_scaling", "true"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.min_count", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.max_count", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.enable_auto_scaling", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep( + "service_principal.0.client_secret", + ), }, }) } func testAccAzureRMKubernetesCluster_autoScalingNoAvailabilityZones(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -112,31 +100,24 @@ func testAccAzureRMKubernetesCluster_autoScalingNoAvailabilityZones(t *testing.T CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_autoscaleNoAvailabilityZonesConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_autoscaleNoAvailabilityZonesConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.type", "VirtualMachineScaleSets"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.min_count", "1"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.max_count", "2"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.enable_auto_scaling", "true"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.type", "VirtualMachineScaleSets"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.min_count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.max_count", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.enable_auto_scaling", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } func testAccAzureRMKubernetesCluster_autoScalingWithAvailabilityZones(t *testing.T) { - resourceName := "azurerm_kubernetes_cluster.test" - ri := tf.AccRandTimeInt() + data := acceptance.BuildTestData(t, "azurerm_kubernetes_cluster", "test") clientId := os.Getenv("ARM_CLIENT_ID") clientSecret := os.Getenv("ARM_CLIENT_SECRET") - location := acceptance.Location() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -144,29 +125,24 @@ func testAccAzureRMKubernetesCluster_autoScalingWithAvailabilityZones(t *testing CheckDestroy: testCheckAzureRMKubernetesClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMKubernetesCluster_autoscaleWithAvailabilityZonesConfig(ri, clientId, clientSecret, location), + Config: testAccAzureRMKubernetesCluster_autoscaleWithAvailabilityZonesConfig(data, clientId, clientSecret), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMKubernetesClusterExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.type", "VirtualMachineScaleSets"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.min_count", "1"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.max_count", "2"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.enable_auto_scaling", "true"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.availability_zones.#", "2"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.availability_zones.0", "1"), - resource.TestCheckResourceAttr(resourceName, "default_node_pool.0.availability_zones.1", "2"), + testCheckAzureRMKubernetesClusterExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.type", "VirtualMachineScaleSets"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.min_count", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.max_count", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.enable_auto_scaling", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.availability_zones.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.availability_zones.0", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "default_node_pool.0.availability_zones.1", "2"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"service_principal.0.client_secret"}, - }, + data.ImportStep("service_principal.0.client_secret"), }, }) } -func testAccAzureRMKubernetesCluster_addAgentConfig(rInt int, clientId, clientSecret, location string, numberOfAgents int) string { +func testAccAzureRMKubernetesCluster_addAgentConfig(data acceptance.TestData, clientId, clientSecret, location string, numberOfAgents int) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -190,10 +166,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, numberOfAgents, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, numberOfAgents, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_autoscaleNodeCountUnsetConfig(rInt int, clientId, clientSecret, location string) string { +func testAccAzureRMKubernetesCluster_autoscaleNodeCountUnsetConfig(data acceptance.TestData, clientId, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -219,10 +195,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_autoscaleNoAvailabilityZonesConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_autoscaleNoAvailabilityZonesConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -248,10 +224,10 @@ resource "azurerm_kubernetes_cluster" "test" { client_secret = "%s" } } -`, rInt, location, rInt, rInt, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, clientId, clientSecret) } -func testAccAzureRMKubernetesCluster_autoscaleWithAvailabilityZonesConfig(rInt int, clientId string, clientSecret string, location string) string { +func testAccAzureRMKubernetesCluster_autoscaleWithAvailabilityZonesConfig(data acceptance.TestData, clientId string, clientSecret string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -284,5 +260,5 @@ resource "azurerm_kubernetes_cluster" "test" { load_balancer_sku = "Standard" } } -`, rInt, location, rInt, rInt, olderKubernetesVersion, clientId, clientSecret) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, olderKubernetesVersion, clientId, clientSecret) } diff --git a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_test.go b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_test.go similarity index 99% rename from azurerm/internal/services/containers/resource_arm_kubernetes_cluster_test.go rename to azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_test.go index 5a8edbea85dd..5d12238db4c2 100644 --- a/azurerm/internal/services/containers/resource_arm_kubernetes_cluster_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_kubernetes_cluster_test.go @@ -1,4 +1,4 @@ -package containers +package tests import ( "fmt" From a667fb3e3fb9a2c2b6588f78ba139a501a96388f Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 13:18:24 -0800 Subject: [PATCH 155/203] cognitive: switching to the new test structure --- .../resource_arm_cognitive_account_test.go | 124 ++++++++---------- 1 file changed, 52 insertions(+), 72 deletions(-) rename azurerm/internal/services/cognitive/{ => tests}/resource_arm_cognitive_account_test.go (61%) diff --git a/azurerm/internal/services/cognitive/resource_arm_cognitive_account_test.go b/azurerm/internal/services/cognitive/tests/resource_arm_cognitive_account_test.go similarity index 61% rename from azurerm/internal/services/cognitive/resource_arm_cognitive_account_test.go rename to azurerm/internal/services/cognitive/tests/resource_arm_cognitive_account_test.go index 5820cc754295..c59adf1d8f31 100644 --- a/azurerm/internal/services/cognitive/resource_arm_cognitive_account_test.go +++ b/azurerm/internal/services/cognitive/tests/resource_arm_cognitive_account_test.go @@ -1,4 +1,4 @@ -package cognitive +package tests import ( "fmt" @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" @@ -15,9 +14,8 @@ import ( ) func TestAccAzureRMCognitiveAccount_basic(t *testing.T) { - resourceName := "azurerm_cognitive_account.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCognitiveAccount_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cognitive_account", "test") + config := testAccAzureRMCognitiveAccount_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,26 +25,21 @@ func TestAccAzureRMCognitiveAccount_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCognitiveAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "Face"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMCognitiveAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "Face"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCognitiveAccount_speechServices(t *testing.T) { - resourceName := "azurerm_cognitive_account.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCognitiveAccount_speechServices(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cognitive_account", "test") + config := testAccAzureRMCognitiveAccount_speechServices(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -56,18 +49,14 @@ func TestAccAzureRMCognitiveAccount_speechServices(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCognitiveAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "SpeechServices"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMCognitiveAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "SpeechServices"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -78,9 +67,7 @@ func TestAccAzureRMCognitiveAccount_requiresImport(t *testing.T) { return } - resourceName := "azurerm_cognitive_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_cognitive_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -88,13 +75,13 @@ func TestAccAzureRMCognitiveAccount_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMAppCognitiveAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCognitiveAccount_basic(ri, location), + Config: testAccAzureRMCognitiveAccount_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCognitiveAccountExists(resourceName), + testCheckAzureRMCognitiveAccountExists(data.ResourceName), ), }, { - Config: testAccAzureRMCognitiveAccount_requiresImport(ri, location), + Config: testAccAzureRMCognitiveAccount_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_cognitive_account"), }, }, @@ -102,9 +89,8 @@ func TestAccAzureRMCognitiveAccount_requiresImport(t *testing.T) { } func TestAccAzureRMCognitiveAccount_complete(t *testing.T) { - resourceName := "azurerm_cognitive_account.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCognitiveAccount_complete(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cognitive_account", "test") + config := testAccAzureRMCognitiveAccount_complete(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -114,27 +100,21 @@ func TestAccAzureRMCognitiveAccount_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCognitiveAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "Face"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Acceptance", "Test"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMCognitiveAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "Face"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Acceptance", "Test"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCognitiveAccount_update(t *testing.T) { - resourceName := "azurerm_cognitive_account.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_cognitive_account", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -142,24 +122,24 @@ func TestAccAzureRMCognitiveAccount_update(t *testing.T) { CheckDestroy: testCheckAzureRMAppCognitiveAccountDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCognitiveAccount_basic(ri, location), + Config: testAccAzureRMCognitiveAccount_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCognitiveAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "Face"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMCognitiveAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "Face"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "0"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, { - Config: testAccAzureRMCognitiveAccount_complete(ri, location), + Config: testAccAzureRMCognitiveAccount_complete(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCognitiveAccountExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "kind", "Face"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.Acceptance", "Test"), - resource.TestCheckResourceAttrSet(resourceName, "primary_access_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_access_key"), + testCheckAzureRMCognitiveAccountExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "kind", "Face"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.Acceptance", "Test"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_access_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_access_key"), ), }, }, @@ -218,7 +198,7 @@ func testCheckAzureRMCognitiveAccountExists(resourceName string) resource.TestCh } } -func testAccAzureRMCognitiveAccount_basic(rInt int, location string) string { +func testAccAzureRMCognitiveAccount_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -236,10 +216,10 @@ resource "azurerm_cognitive_account" "test" { tier = "Standard" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCognitiveAccount_speechServices(rInt int, location string) string { +func testAccAzureRMCognitiveAccount_speechServices(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -257,11 +237,11 @@ resource "azurerm_cognitive_account" "test" { tier = "Standard" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCognitiveAccount_requiresImport(rInt int, location string) string { - template := testAccAzureRMCognitiveAccount_basic(rInt, location) +func testAccAzureRMCognitiveAccount_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMCognitiveAccount_basic(data) return fmt.Sprintf(` %s @@ -279,7 +259,7 @@ resource "azurerm_cognitive_account" "import" { `, template) } -func testAccAzureRMCognitiveAccount_complete(rInt int, location string) string { +func testAccAzureRMCognitiveAccount_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -301,5 +281,5 @@ resource "azurerm_cognitive_account" "test" { Acceptance = "Test" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From fb33b2a8516488c2982149ff2b53d098512fcdae Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 13:22:27 -0800 Subject: [PATCH 156/203] cdn: switching to the new test structure --- .../data_source_cdn_profile_test.go | 32 ++- .../resource_arm_cdn_endpoint_test.go | 190 ++++++++---------- .../resource_arm_cdn_profile_test.go | 140 +++++-------- 3 files changed, 150 insertions(+), 212 deletions(-) rename azurerm/internal/services/cdn/{ => tests}/data_source_cdn_profile_test.go (69%) rename azurerm/internal/services/cdn/{ => tests}/resource_arm_cdn_endpoint_test.go (71%) rename azurerm/internal/services/cdn/{ => tests}/resource_arm_cdn_profile_test.go (67%) diff --git a/azurerm/internal/services/cdn/data_source_cdn_profile_test.go b/azurerm/internal/services/cdn/tests/data_source_cdn_profile_test.go similarity index 69% rename from azurerm/internal/services/cdn/data_source_cdn_profile_test.go rename to azurerm/internal/services/cdn/tests/data_source_cdn_profile_test.go index 9a1c7bab7505..be2c34336773 100644 --- a/azurerm/internal/services/cdn/data_source_cdn_profile_test.go +++ b/azurerm/internal/services/cdn/tests/data_source_cdn_profile_test.go @@ -1,18 +1,15 @@ -package cdn +package tests import ( "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) func TestAccDataSourceAzureRMCdnProfile_basic(t *testing.T) { - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccDataSourceAzureRMCdnProfile_basic(ri, location) + data := acceptance.BuildTestData(t, "data.azurerm_cdn_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -20,7 +17,7 @@ func TestAccDataSourceAzureRMCdnProfile_basic(t *testing.T) { CheckDestroy: testCheckAzureRMCdnProfileDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMCdnProfile_basic(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMCdnProfileExists("data.azurerm_cdn_profile.test"), ), @@ -30,10 +27,7 @@ func TestAccDataSourceAzureRMCdnProfile_basic(t *testing.T) { } func TestAccDataSourceAzureRMCdnProfile_withTags(t *testing.T) { - resourceName := "data.azurerm_cdn_profile.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccDataSourceAzureRMCdnProfile_withTags(ri, location) + data := acceptance.BuildTestData(t, "data.azurerm_cdn_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -41,19 +35,19 @@ func TestAccDataSourceAzureRMCdnProfile_withTags(t *testing.T) { CheckDestroy: testCheckAzureRMCdnProfileDestroy, Steps: []resource.TestStep{ { - Config: preConfig, + Config: testAccDataSourceAzureRMCdnProfile_withTags(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMCdnProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, }, }) } -func testAccDataSourceAzureRMCdnProfile_basic(rInt int, location string) string { +func testAccDataSourceAzureRMCdnProfile_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -71,10 +65,10 @@ data "azurerm_cdn_profile" "test" { name = "${azurerm_cdn_profile.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccDataSourceAzureRMCdnProfile_withTags(rInt int, location string) string { +func testAccDataSourceAzureRMCdnProfile_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -97,5 +91,5 @@ data "azurerm_cdn_profile" "test" { name = "${azurerm_cdn_profile.test.name}" resource_group_name = "${azurerm_resource_group.test.name}" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/azurerm/internal/services/cdn/resource_arm_cdn_endpoint_test.go b/azurerm/internal/services/cdn/tests/resource_arm_cdn_endpoint_test.go similarity index 71% rename from azurerm/internal/services/cdn/resource_arm_cdn_endpoint_test.go rename to azurerm/internal/services/cdn/tests/resource_arm_cdn_endpoint_test.go index 9c3b089ca613..6dd48952d657 100644 --- a/azurerm/internal/services/cdn/resource_arm_cdn_endpoint_test.go +++ b/azurerm/internal/services/cdn/tests/resource_arm_cdn_endpoint_test.go @@ -1,4 +1,4 @@ -package cdn +package tests import ( "fmt" @@ -7,16 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMCdnEndpoint_basic(t *testing.T) { - resourceName := "azurerm_cdn_endpoint.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCdnEndpoint_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cdn_endpoint", "test") + config := testAccAzureRMCdnEndpoint_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,14 +24,10 @@ func TestAccAzureRMCdnEndpoint_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), + testCheckAzureRMCdnEndpointExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,9 +38,7 @@ func TestAccAzureRMCdnEndpoint_requiresImport(t *testing.T) { return } - resourceName := "azurerm_cdn_endpoint.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_cdn_endpoint", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,13 +46,13 @@ func TestAccAzureRMCdnEndpoint_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMCdnEndpointDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCdnEndpoint_basic(ri, location), + Config: testAccAzureRMCdnEndpoint_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), + testCheckAzureRMCdnEndpointExists(data.ResourceName), ), }, { - Config: testAccAzureRMCdnEndpoint_requiresImport(ri, location), + Config: testAccAzureRMCdnEndpoint_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_cdn_endpoint"), }, }, @@ -68,9 +60,8 @@ func TestAccAzureRMCdnEndpoint_requiresImport(t *testing.T) { } func TestAccAzureRMCdnEndpoint_disappears(t *testing.T) { - resourceName := "azurerm_cdn_endpoint.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCdnEndpoint_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cdn_endpoint", "test") + config := testAccAzureRMCdnEndpoint_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -80,8 +71,8 @@ func TestAccAzureRMCdnEndpoint_disappears(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), - testCheckAzureRMCdnEndpointDisappears(resourceName), + testCheckAzureRMCdnEndpointExists(data.ResourceName), + testCheckAzureRMCdnEndpointDisappears(data.ResourceName), ), ExpectNonEmptyPlan: true, }, @@ -90,11 +81,9 @@ func TestAccAzureRMCdnEndpoint_disappears(t *testing.T) { } func TestAccAzureRMCdnEndpoint_updateHostHeader(t *testing.T) { - resourceName := "azurerm_cdn_endpoint.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMCdnEndpoint_hostHeader(ri, "www.example.com", location) - updatedConfig := testAccAzureRMCdnEndpoint_hostHeader(ri, "www.example2.com", location) + data := acceptance.BuildTestData(t, "azurerm_cdn_endpoint", "test") + config := testAccAzureRMCdnEndpoint_hostHeader(data, "www.example.com") + updatedConfig := testAccAzureRMCdnEndpoint_hostHeader(data, "www.example2.com") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -104,15 +93,15 @@ func TestAccAzureRMCdnEndpoint_updateHostHeader(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "origin_host_header", "www.example.com"), + testCheckAzureRMCdnEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "origin_host_header", "www.example.com"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "origin_host_header", "www.example2.com"), + testCheckAzureRMCdnEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "origin_host_header", "www.example2.com"), ), }, }, @@ -120,11 +109,9 @@ func TestAccAzureRMCdnEndpoint_updateHostHeader(t *testing.T) { } func TestAccAzureRMCdnEndpoint_withTags(t *testing.T) { - resourceName := "azurerm_cdn_endpoint.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMCdnEndpoint_withTags(ri, location) - postConfig := testAccAzureRMCdnEndpoint_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_cdn_endpoint", "test") + preConfig := testAccAzureRMCdnEndpoint_withTags(data) + postConfig := testAccAzureRMCdnEndpoint_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -134,37 +121,28 @@ func TestAccAzureRMCdnEndpoint_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMCdnEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMCdnEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), - }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + }, data.ImportStep(), }, }) } func TestAccAzureRMCdnEndpoint_optimized(t *testing.T) { - resourceName := "azurerm_cdn_endpoint.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCdnEndpoint_optimized(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cdn_endpoint", "test") + config := testAccAzureRMCdnEndpoint_optimized(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -174,8 +152,8 @@ func TestAccAzureRMCdnEndpoint_optimized(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "optimization_type", "GeneralWebDelivery"), + testCheckAzureRMCdnEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "optimization_type", "GeneralWebDelivery"), ), }, }, @@ -183,9 +161,8 @@ func TestAccAzureRMCdnEndpoint_optimized(t *testing.T) { } func TestAccAzureRMCdnEndpoint_withGeoFilters(t *testing.T) { - resourceName := "azurerm_cdn_endpoint.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCdnEndpoint_geoFilters(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cdn_endpoint", "test") + config := testAccAzureRMCdnEndpoint_geoFilters(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -195,17 +172,16 @@ func TestAccAzureRMCdnEndpoint_withGeoFilters(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "geo_filter.#", "2"), + testCheckAzureRMCdnEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "geo_filter.#", "2"), ), }, }, }) } func TestAccAzureRMCdnEndpoint_fullFields(t *testing.T) { - resourceName := "azurerm_cdn_endpoint.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCdnEndpoint_fullFields(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cdn_endpoint", "test") + config := testAccAzureRMCdnEndpoint_fullFields(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -215,19 +191,19 @@ func TestAccAzureRMCdnEndpoint_fullFields(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "is_http_allowed", "true"), - resource.TestCheckResourceAttr(resourceName, "is_https_allowed", "true"), - resource.TestCheckResourceAttr(resourceName, "origin_path", "/origin-path"), - resource.TestCheckResourceAttr(resourceName, "probe_path", "/origin-path/probe"), - resource.TestCheckResourceAttr(resourceName, "origin_host_header", "www.example.com"), - resource.TestCheckResourceAttr(resourceName, "optimization_type", "GeneralWebDelivery"), - resource.TestCheckResourceAttr(resourceName, "querystring_caching_behaviour", "UseQueryString"), - resource.TestCheckResourceAttr(resourceName, "content_types_to_compress.#", "1"), - resource.TestCheckResourceAttr(resourceName, "is_compression_enabled", "true"), - resource.TestCheckResourceAttr(resourceName, "geo_filter.#", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), + testCheckAzureRMCdnEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "is_http_allowed", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "is_https_allowed", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "origin_path", "/origin-path"), + resource.TestCheckResourceAttr(data.ResourceName, "probe_path", "/origin-path/probe"), + resource.TestCheckResourceAttr(data.ResourceName, "origin_host_header", "www.example.com"), + resource.TestCheckResourceAttr(data.ResourceName, "optimization_type", "GeneralWebDelivery"), + resource.TestCheckResourceAttr(data.ResourceName, "querystring_caching_behaviour", "UseQueryString"), + resource.TestCheckResourceAttr(data.ResourceName, "content_types_to_compress.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "is_compression_enabled", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "geo_filter.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), ), }, }, @@ -235,11 +211,9 @@ func TestAccAzureRMCdnEndpoint_fullFields(t *testing.T) { } func TestAccAzureRMCdnEndpoint_isHttpAndHttpsAllowedUpdate(t *testing.T) { - resourceName := "azurerm_cdn_endpoint.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - config := testAccAzureRMCdnEndpoint_isHttpAndHttpsAllowed(ri, location, "true", "false") - updatedConfig := testAccAzureRMCdnEndpoint_isHttpAndHttpsAllowed(ri, location, "false", "true") + data := acceptance.BuildTestData(t, "azurerm_cdn_endpoint", "test") + config := testAccAzureRMCdnEndpoint_isHttpAndHttpsAllowed(data, "true", "false") + updatedConfig := testAccAzureRMCdnEndpoint_isHttpAndHttpsAllowed(data, "false", "true") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -249,17 +223,17 @@ func TestAccAzureRMCdnEndpoint_isHttpAndHttpsAllowedUpdate(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "is_http_allowed", "true"), - resource.TestCheckResourceAttr(resourceName, "is_https_allowed", "false"), + testCheckAzureRMCdnEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "is_http_allowed", "true"), + resource.TestCheckResourceAttr(data.ResourceName, "is_https_allowed", "false"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnEndpointExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "is_http_allowed", "false"), - resource.TestCheckResourceAttr(resourceName, "is_https_allowed", "true"), + testCheckAzureRMCdnEndpointExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "is_http_allowed", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "is_https_allowed", "true"), ), }, }, @@ -354,7 +328,7 @@ func testCheckAzureRMCdnEndpointDestroy(s *terraform.State) error { return nil } -func testAccAzureRMCdnEndpoint_basic(rInt int, location string) string { +func testAccAzureRMCdnEndpoint_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -381,11 +355,11 @@ resource "azurerm_cdn_endpoint" "test" { http_port = 80 } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMCdnEndpoint_requiresImport(rInt int, location string) string { - template := testAccAzureRMCdnEndpoint_basic(rInt, location) +func testAccAzureRMCdnEndpoint_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMCdnEndpoint_basic(data) return fmt.Sprintf(` %s @@ -405,7 +379,7 @@ resource "azurerm_cdn_endpoint" "import" { `, template) } -func testAccAzureRMCdnEndpoint_hostHeader(rInt int, domain string, location string) string { +func testAccAzureRMCdnEndpoint_hostHeader(data acceptance.TestData, domain string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -438,10 +412,10 @@ resource "azurerm_cdn_endpoint" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt, domain) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, domain) } -func testAccAzureRMCdnEndpoint_withTags(rInt int, location string) string { +func testAccAzureRMCdnEndpoint_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -473,10 +447,10 @@ resource "azurerm_cdn_endpoint" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMCdnEndpoint_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMCdnEndpoint_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -507,10 +481,10 @@ resource "azurerm_cdn_endpoint" "test" { environment = "staging" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMCdnEndpoint_geoFilters(rInt int, location string) string { +func testAccAzureRMCdnEndpoint_geoFilters(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -553,10 +527,10 @@ resource "azurerm_cdn_endpoint" "test" { country_codes = ["US"] } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMCdnEndpoint_optimized(rInt int, location string) string { +func testAccAzureRMCdnEndpoint_optimized(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -586,10 +560,10 @@ resource "azurerm_cdn_endpoint" "test" { http_port = 80 } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMCdnEndpoint_fullFields(rInt int, location string) string { +func testAccAzureRMCdnEndpoint_fullFields(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -635,10 +609,10 @@ resource "azurerm_cdn_endpoint" "test" { environment = "Production" } } -`, rInt, location, rInt, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) } -func testAccAzureRMCdnEndpoint_isHttpAndHttpsAllowed(rInt int, location string, isHttpAllowed string, isHttpsAllowed string) string { +func testAccAzureRMCdnEndpoint_isHttpAndHttpsAllowed(data acceptance.TestData, isHttpAllowed string, isHttpsAllowed string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -667,5 +641,5 @@ resource "azurerm_cdn_endpoint" "test" { http_port = 80 } } -`, rInt, location, rInt, rInt, isHttpAllowed, isHttpsAllowed) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, isHttpAllowed, isHttpsAllowed) } diff --git a/azurerm/internal/services/cdn/resource_arm_cdn_profile_test.go b/azurerm/internal/services/cdn/tests/resource_arm_cdn_profile_test.go similarity index 67% rename from azurerm/internal/services/cdn/resource_arm_cdn_profile_test.go rename to azurerm/internal/services/cdn/tests/resource_arm_cdn_profile_test.go index ddea386b1c14..a0643fb4a960 100644 --- a/azurerm/internal/services/cdn/resource_arm_cdn_profile_test.go +++ b/azurerm/internal/services/cdn/tests/resource_arm_cdn_profile_test.go @@ -1,4 +1,4 @@ -package cdn +package tests import ( "fmt" @@ -7,16 +7,14 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" ) func TestAccAzureRMCdnProfile_basic(t *testing.T) { - resourceName := "azurerm_cdn_profile.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCdnProfile_basic(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cdn_profile", "test") + config := testAccAzureRMCdnProfile_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -26,14 +24,10 @@ func TestAccAzureRMCdnProfile_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists(resourceName), + testCheckAzureRMCdnProfileExists(data.ResourceName), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -44,9 +38,7 @@ func TestAccAzureRMCdnProfile_requiresImport(t *testing.T) { return } - resourceName := "azurerm_cdn_profile.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() + data := acceptance.BuildTestData(t, "azurerm_cdn_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,13 +46,13 @@ func TestAccAzureRMCdnProfile_requiresImport(t *testing.T) { CheckDestroy: testCheckAzureRMCdnProfileDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMCdnProfile_basic(ri, location), + Config: testAccAzureRMCdnProfile_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists(resourceName), + testCheckAzureRMCdnProfileExists(data.ResourceName), ), }, { - Config: testAccAzureRMCdnProfile_requiresImport(ri, location), + Config: testAccAzureRMCdnProfile_requiresImport(data), ExpectError: acceptance.RequiresImportError("azurerm_cdn_profile"), }, }, @@ -68,11 +60,9 @@ func TestAccAzureRMCdnProfile_requiresImport(t *testing.T) { } func TestAccAzureRMCdnProfile_withTags(t *testing.T) { - resourceName := "azurerm_cdn_profile.test" - ri := tf.AccRandTimeInt() - location := acceptance.Location() - preConfig := testAccAzureRMCdnProfile_withTags(ri, location) - postConfig := testAccAzureRMCdnProfile_withTagsUpdate(ri, location) + data := acceptance.BuildTestData(t, "azurerm_cdn_profile", "test") + preConfig := testAccAzureRMCdnProfile_withTags(data) + postConfig := testAccAzureRMCdnProfile_withTagsUpdate(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -82,37 +72,28 @@ func TestAccAzureRMCdnProfile_withTags(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "Production"), - resource.TestCheckResourceAttr(resourceName, "tags.cost_center", "MSFT"), + testCheckAzureRMCdnProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "Production"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.cost_center", "MSFT"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(resourceName, "tags.environment", "staging"), + testCheckAzureRMCdnProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "tags.environment", "staging"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCdnProfile_NonStandardCasing(t *testing.T) { - ri := tf.AccRandTimeInt() - config := testAccAzureRMCdnProfileNonStandardCasing(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cdn_profile", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -120,13 +101,13 @@ func TestAccAzureRMCdnProfile_NonStandardCasing(t *testing.T) { CheckDestroy: testCheckAzureRMCdnProfileDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMCdnProfileNonStandardCasing(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMCdnProfileExists("azurerm_cdn_profile.test"), ), }, { - Config: config, + Config: testAccAzureRMCdnProfileNonStandardCasing(data), PlanOnly: true, ExpectNonEmptyPlan: false, }, @@ -135,10 +116,9 @@ func TestAccAzureRMCdnProfile_NonStandardCasing(t *testing.T) { } func TestAccAzureRMCdnProfile_basicToStandardAkamai(t *testing.T) { - resourceName := "azurerm_cdn_profile.test" - ri := tf.AccRandTimeInt() - preConfig := testAccAzureRMCdnProfile_basic(ri, acceptance.Location()) - postConfig := testAccAzureRMCdnProfile_standardAkamai(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cdn_profile", "test") + preConfig := testAccAzureRMCdnProfile_basic(data) + postConfig := testAccAzureRMCdnProfile_standardAkamai(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -148,15 +128,15 @@ func TestAccAzureRMCdnProfile_basicToStandardAkamai(t *testing.T) { { Config: preConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Standard_Verizon"), + testCheckAzureRMCdnProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard_Verizon"), ), }, { Config: postConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Standard_Akamai"), + testCheckAzureRMCdnProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard_Akamai"), ), }, }, @@ -164,9 +144,8 @@ func TestAccAzureRMCdnProfile_basicToStandardAkamai(t *testing.T) { } func TestAccAzureRMCdnProfile_standardAkamai(t *testing.T) { - resourceName := "azurerm_cdn_profile.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCdnProfile_standardAkamai(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cdn_profile", "test") + config := testAccAzureRMCdnProfile_standardAkamai(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -176,23 +155,18 @@ func TestAccAzureRMCdnProfile_standardAkamai(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Standard_Akamai"), + testCheckAzureRMCdnProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard_Akamai"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMCdnProfile_standardMicrosoft(t *testing.T) { - resourceName := "azurerm_cdn_profile.test" - ri := tf.AccRandTimeInt() - config := testAccAzureRMCdnProfile_standardMicrosoft(ri, acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_cdn_profile", "test") + config := testAccAzureRMCdnProfile_standardMicrosoft(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -202,15 +176,11 @@ func TestAccAzureRMCdnProfile_standardMicrosoft(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMCdnProfileExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "sku", "Standard_Microsoft"), + testCheckAzureRMCdnProfileExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "sku", "Standard_Microsoft"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -271,7 +241,7 @@ func testCheckAzureRMCdnProfileDestroy(s *terraform.State) error { return nil } -func testAccAzureRMCdnProfile_basic(rInt int, location string) string { +func testAccAzureRMCdnProfile_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -284,11 +254,11 @@ resource "azurerm_cdn_profile" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard_Verizon" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCdnProfile_requiresImport(rInt int, location string) string { - template := testAccAzureRMCdnProfile_basic(rInt, location) +func testAccAzureRMCdnProfile_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMCdnProfile_basic(data) return fmt.Sprintf(` %s @@ -301,7 +271,7 @@ resource "azurerm_cdn_profile" "import" { `, template) } -func testAccAzureRMCdnProfile_withTags(rInt int, location string) string { +func testAccAzureRMCdnProfile_withTags(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -319,10 +289,10 @@ resource "azurerm_cdn_profile" "test" { cost_center = "MSFT" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCdnProfile_withTagsUpdate(rInt int, location string) string { +func testAccAzureRMCdnProfile_withTagsUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -339,10 +309,10 @@ resource "azurerm_cdn_profile" "test" { environment = "staging" } } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCdnProfileNonStandardCasing(rInt int, location string) string { +func testAccAzureRMCdnProfileNonStandardCasing(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -355,10 +325,10 @@ resource "azurerm_cdn_profile" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "standard_verizon" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCdnProfile_standardAkamai(rInt int, location string) string { +func testAccAzureRMCdnProfile_standardAkamai(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -371,10 +341,10 @@ resource "azurerm_cdn_profile" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard_Akamai" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMCdnProfile_standardMicrosoft(rInt int, location string) string { +func testAccAzureRMCdnProfile_standardMicrosoft(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -387,5 +357,5 @@ resource "azurerm_cdn_profile" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard_Microsoft" } -`, rInt, location, rInt) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From c5398a79359395a76d9f0f3580cd0699694b632a Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 13:30:08 -0800 Subject: [PATCH 157/203] graph: switching to the new test structure --- .../data_source_azuread_application_test.go | 50 ++++++------- ...a_source_azuread_service_principal_test.go | 32 ++++----- .../resource_arm_azuread_application_test.go | 72 ++++++++----------- ...azuread_service_principal_password_test.go | 26 +++---- ...urce_arm_azuread_service_principal_test.go | 20 +++--- 5 files changed, 92 insertions(+), 108 deletions(-) rename azurerm/internal/services/graph/{ => tests}/data_source_azuread_application_test.go (57%) rename azurerm/internal/services/graph/{ => tests}/data_source_azuread_service_principal_test.go (69%) rename azurerm/internal/services/graph/{ => tests}/resource_arm_azuread_application_test.go (67%) rename azurerm/internal/services/graph/{ => tests}/resource_arm_azuread_service_principal_password_test.go (88%) rename azurerm/internal/services/graph/{ => tests}/resource_arm_azuread_service_principal_test.go (87%) diff --git a/azurerm/internal/services/graph/data_source_azuread_application_test.go b/azurerm/internal/services/graph/tests/data_source_azuread_application_test.go similarity index 57% rename from azurerm/internal/services/graph/data_source_azuread_application_test.go rename to azurerm/internal/services/graph/tests/data_source_azuread_application_test.go index 765938873e02..a977b171b33d 100644 --- a/azurerm/internal/services/graph/data_source_azuread_application_test.go +++ b/azurerm/internal/services/graph/tests/data_source_azuread_application_test.go @@ -1,4 +1,4 @@ -package graph +package tests import ( "fmt" @@ -10,7 +10,7 @@ import ( ) func TestAccDataSourceAzureRMAzureADApplication_byObjectId(t *testing.T) { - dataSourceName := "data.azurerm_azuread_application.test" + data := acceptance.BuildTestData(t, "data.azurerm_azuread_application", "test") id := uuid.New().String() config := testAccDataSourceAzureRMAzureADApplication_objectId(id) @@ -25,13 +25,13 @@ func TestAccDataSourceAzureRMAzureADApplication_byObjectId(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryApplicationExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("acctest%s", id)), - resource.TestCheckResourceAttr(dataSourceName, "homepage", fmt.Sprintf("https://acctest%s", id)), - resource.TestCheckResourceAttr(dataSourceName, "identifier_uris.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "reply_urls.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "oauth2_allow_implicit_flow", "false"), - resource.TestCheckResourceAttrSet(dataSourceName, "application_id"), + testCheckAzureRMActiveDirectoryApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctest%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "homepage", fmt.Sprintf("https://acctest%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "identifier_uris.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "reply_urls.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "oauth2_allow_implicit_flow", "false"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_id"), ), }, }, @@ -39,7 +39,7 @@ func TestAccDataSourceAzureRMAzureADApplication_byObjectId(t *testing.T) { } func TestAccDataSourceAzureRMAzureADApplication_byObjectIdComplete(t *testing.T) { - dataSourceName := "data.azurerm_azuread_application.test" + data := acceptance.BuildTestData(t, "data.azurerm_azuread_application", "test") id := uuid.New().String() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -52,13 +52,13 @@ func TestAccDataSourceAzureRMAzureADApplication_byObjectIdComplete(t *testing.T) { Config: testAccDataSourceAzureRMAzureADApplication_objectIdComplete(id), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryApplicationExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("acctest%s", id)), - resource.TestCheckResourceAttr(dataSourceName, "homepage", fmt.Sprintf("https://homepage-%s", id)), - resource.TestCheckResourceAttr(dataSourceName, "identifier_uris.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "reply_urls.#", "1"), - resource.TestCheckResourceAttr(dataSourceName, "oauth2_allow_implicit_flow", "true"), - resource.TestCheckResourceAttrSet(dataSourceName, "application_id"), + testCheckAzureRMActiveDirectoryApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctest%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "homepage", fmt.Sprintf("https://homepage-%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "identifier_uris.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "reply_urls.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "oauth2_allow_implicit_flow", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_id"), ), }, }, @@ -66,7 +66,7 @@ func TestAccDataSourceAzureRMAzureADApplication_byObjectIdComplete(t *testing.T) } func TestAccDataSourceAzureRMAzureADApplication_byName(t *testing.T) { - dataSourceName := "data.azurerm_azuread_application.test" + data := acceptance.BuildTestData(t, "data.azurerm_azuread_application", "test") id := uuid.New().String() config := testAccDataSourceAzureRMAzureADApplication_name(id) @@ -81,13 +81,13 @@ func TestAccDataSourceAzureRMAzureADApplication_byName(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryApplicationExists(dataSourceName), - resource.TestCheckResourceAttr(dataSourceName, "name", fmt.Sprintf("acctest%s", id)), - resource.TestCheckResourceAttr(dataSourceName, "homepage", fmt.Sprintf("https://acctest%s", id)), - resource.TestCheckResourceAttr(dataSourceName, "identifier_uris.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "reply_urls.#", "0"), - resource.TestCheckResourceAttr(dataSourceName, "oauth2_allow_implicit_flow", "false"), - resource.TestCheckResourceAttrSet(dataSourceName, "application_id"), + testCheckAzureRMActiveDirectoryApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctest%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "homepage", fmt.Sprintf("https://acctest%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "identifier_uris.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "reply_urls.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "oauth2_allow_implicit_flow", "false"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_id"), ), }, }, diff --git a/azurerm/internal/services/graph/data_source_azuread_service_principal_test.go b/azurerm/internal/services/graph/tests/data_source_azuread_service_principal_test.go similarity index 69% rename from azurerm/internal/services/graph/data_source_azuread_service_principal_test.go rename to azurerm/internal/services/graph/tests/data_source_azuread_service_principal_test.go index 704c58185617..3289059154dd 100644 --- a/azurerm/internal/services/graph/data_source_azuread_service_principal_test.go +++ b/azurerm/internal/services/graph/tests/data_source_azuread_service_principal_test.go @@ -1,4 +1,4 @@ -package graph +package tests import ( "fmt" @@ -10,7 +10,7 @@ import ( ) func TestAccDataSourceAzureRMAzureADServicePrincipal_byApplicationId(t *testing.T) { - dataSourceName := "data.azurerm_azuread_service_principal.test" + data := acceptance.BuildTestData(t, "data.azurerm_azuread_service_principal", "test") id := uuid.New().String() config := testAccDataSourceAzureRMAzureADServicePrincipal_byApplicationId(id) @@ -22,10 +22,10 @@ func TestAccDataSourceAzureRMAzureADServicePrincipal_byApplicationId(t *testing. { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryServicePrincipalExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "application_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "object_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "display_name"), + testCheckAzureRMActiveDirectoryServicePrincipalExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "object_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "display_name"), ), }, }, @@ -33,7 +33,7 @@ func TestAccDataSourceAzureRMAzureADServicePrincipal_byApplicationId(t *testing. } func TestAccDataSourceAzureRMAzureADServicePrincipal_byDisplayName(t *testing.T) { - dataSourceName := "data.azurerm_azuread_service_principal.test" + data := acceptance.BuildTestData(t, "data.azurerm_azuread_service_principal", "test") id := uuid.New().String() config := testAccDataSourceAzureRMAzureADServicePrincipal_byDisplayName(id) @@ -45,10 +45,10 @@ func TestAccDataSourceAzureRMAzureADServicePrincipal_byDisplayName(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryServicePrincipalExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "application_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "object_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "display_name"), + testCheckAzureRMActiveDirectoryServicePrincipalExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "object_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "display_name"), ), }, }, @@ -56,7 +56,7 @@ func TestAccDataSourceAzureRMAzureADServicePrincipal_byDisplayName(t *testing.T) } func TestAccDataSourceAzureRMAzureADServicePrincipal_byObjectId(t *testing.T) { - dataSourceName := "data.azurerm_azuread_service_principal.test" + data := acceptance.BuildTestData(t, "data.azurerm_azuread_service_principal", "test") id := uuid.New().String() config := testAccDataSourceAzureRMAzureADServicePrincipal_byObjectId(id) @@ -68,10 +68,10 @@ func TestAccDataSourceAzureRMAzureADServicePrincipal_byObjectId(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryServicePrincipalExists(dataSourceName), - resource.TestCheckResourceAttrSet(dataSourceName, "application_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "object_id"), - resource.TestCheckResourceAttrSet(dataSourceName, "display_name"), + testCheckAzureRMActiveDirectoryServicePrincipalExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "object_id"), + resource.TestCheckResourceAttrSet(data.ResourceName, "display_name"), ), }, }, diff --git a/azurerm/internal/services/graph/resource_arm_azuread_application_test.go b/azurerm/internal/services/graph/tests/resource_arm_azuread_application_test.go similarity index 67% rename from azurerm/internal/services/graph/resource_arm_azuread_application_test.go rename to azurerm/internal/services/graph/tests/resource_arm_azuread_application_test.go index 53e7ff1356bd..c770a613acc8 100644 --- a/azurerm/internal/services/graph/resource_arm_azuread_application_test.go +++ b/azurerm/internal/services/graph/tests/resource_arm_azuread_application_test.go @@ -1,4 +1,4 @@ -package graph +package tests import ( "fmt" @@ -13,7 +13,7 @@ import ( ) func TestAccAzureRMActiveDirectoryApplication_basic(t *testing.T) { - resourceName := "azurerm_azuread_application.test" + data := acceptance.BuildTestData(t, "azurerm_azuread_application", "test") id := uuid.New().String() config := testAccAzureRMActiveDirectoryApplication_basic(id) @@ -25,23 +25,19 @@ func TestAccAzureRMActiveDirectoryApplication_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryApplicationExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", id)), - resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("https://acctest%s", id)), - resource.TestCheckResourceAttrSet(resourceName, "application_id"), + testCheckAzureRMActiveDirectoryApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctest%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "homepage", fmt.Sprintf("https://acctest%s", id)), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMActiveDirectoryApplication_availableToOtherTenants(t *testing.T) { - resourceName := "azurerm_azuread_application.test" + data := acceptance.BuildTestData(t, "azurerm_azuread_application", "test") id := uuid.New().String() config := testAccAzureRMActiveDirectoryApplication_availableToOtherTenants(id) @@ -53,21 +49,17 @@ func TestAccAzureRMActiveDirectoryApplication_availableToOtherTenants(t *testing { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryApplicationExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "available_to_other_tenants", "true"), + testCheckAzureRMActiveDirectoryApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "available_to_other_tenants", "true"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMActiveDirectoryApplication_complete(t *testing.T) { - resourceName := "azurerm_azuread_application.test" + data := acceptance.BuildTestData(t, "azurerm_azuread_application", "test") id := uuid.New().String() config := testAccAzureRMActiveDirectoryApplication_complete(id) @@ -79,25 +71,21 @@ func TestAccAzureRMActiveDirectoryApplication_complete(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryApplicationExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", id)), - resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("https://homepage-%s", id)), - resource.TestCheckResourceAttr(resourceName, "identifier_uris.#", "1"), - resource.TestCheckResourceAttr(resourceName, "reply_urls.#", "1"), - resource.TestCheckResourceAttrSet(resourceName, "application_id"), + testCheckAzureRMActiveDirectoryApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctest%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "homepage", fmt.Sprintf("https://homepage-%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "identifier_uris.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "reply_urls.#", "1"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } func TestAccAzureRMActiveDirectoryApplication_update(t *testing.T) { - resourceName := "azurerm_azuread_application.test" + data := acceptance.BuildTestData(t, "azurerm_azuread_application", "test") id := uuid.New().String() config := testAccAzureRMActiveDirectoryApplication_basic(id) @@ -112,21 +100,21 @@ func TestAccAzureRMActiveDirectoryApplication_update(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryApplicationExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", id)), - resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("https://acctest%s", id)), - resource.TestCheckResourceAttr(resourceName, "identifier_uris.#", "0"), - resource.TestCheckResourceAttr(resourceName, "reply_urls.#", "0"), + testCheckAzureRMActiveDirectoryApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctest%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "homepage", fmt.Sprintf("https://acctest%s", id)), + resource.TestCheckResourceAttr(data.ResourceName, "identifier_uris.#", "0"), + resource.TestCheckResourceAttr(data.ResourceName, "reply_urls.#", "0"), ), }, { Config: updatedConfig, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryApplicationExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest%s", updatedId)), - resource.TestCheckResourceAttr(resourceName, "homepage", fmt.Sprintf("https://homepage-%s", updatedId)), - resource.TestCheckResourceAttr(resourceName, "identifier_uris.#", "1"), - resource.TestCheckResourceAttr(resourceName, "reply_urls.#", "1"), + testCheckAzureRMActiveDirectoryApplicationExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", fmt.Sprintf("acctest%s", updatedId)), + resource.TestCheckResourceAttr(data.ResourceName, "homepage", fmt.Sprintf("https://homepage-%s", updatedId)), + resource.TestCheckResourceAttr(data.ResourceName, "identifier_uris.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "reply_urls.#", "1"), ), }, }, diff --git a/azurerm/internal/services/graph/resource_arm_azuread_service_principal_password_test.go b/azurerm/internal/services/graph/tests/resource_arm_azuread_service_principal_password_test.go similarity index 88% rename from azurerm/internal/services/graph/resource_arm_azuread_service_principal_password_test.go rename to azurerm/internal/services/graph/tests/resource_arm_azuread_service_principal_password_test.go index 743b73adeca6..db89b722a817 100644 --- a/azurerm/internal/services/graph/resource_arm_azuread_service_principal_password_test.go +++ b/azurerm/internal/services/graph/tests/resource_arm_azuread_service_principal_password_test.go @@ -1,4 +1,4 @@ -package graph +package tests import ( "fmt" @@ -15,7 +15,7 @@ import ( ) func TestAccAzureRMActiveDirectoryServicePrincipalPassword_basic(t *testing.T) { - resourceName := "azurerm_azuread_service_principal_password.test" + data := acceptance.BuildTestData(t, "azurerm_azuread_service_principal_password", "test") applicationId, err := uuid.GenerateUUID() if err != nil { t.Fatal(err) @@ -36,10 +36,10 @@ func TestAccAzureRMActiveDirectoryServicePrincipalPassword_basic(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( // can't assert on Value since it's not returned - testCheckAzureRMActiveDirectoryServicePrincipalPasswordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "start_date"), - resource.TestCheckResourceAttrSet(resourceName, "key_id"), - resource.TestCheckResourceAttr(resourceName, "end_date", "2020-01-01T01:02:03Z"), + testCheckAzureRMActiveDirectoryServicePrincipalPasswordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "start_date"), + resource.TestCheckResourceAttrSet(data.ResourceName, "key_id"), + resource.TestCheckResourceAttr(data.ResourceName, "end_date", "2020-01-01T01:02:03Z"), ), }, }, @@ -52,7 +52,7 @@ func TestAccAzureRMActiveDirectoryServicePrincipalPassword_requiresImport(t *tes return } - resourceName := "azurerm_azuread_service_principal_password.test" + data := acceptance.BuildTestData(t, "azurerm_azuread_service_principal_password", "test") applicationId, err := uuid.GenerateUUID() if err != nil { t.Fatal(err) @@ -70,7 +70,7 @@ func TestAccAzureRMActiveDirectoryServicePrincipalPassword_requiresImport(t *tes { Config: testAccAzureRMActiveDirectoryServicePrincipalPassword_basic(applicationId, value), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryServicePrincipalPasswordExists(resourceName), + testCheckAzureRMActiveDirectoryServicePrincipalPasswordExists(data.ResourceName), ), }, { @@ -82,7 +82,7 @@ func TestAccAzureRMActiveDirectoryServicePrincipalPassword_requiresImport(t *tes } func TestAccAzureRMActiveDirectoryServicePrincipalPassword_customKeyId(t *testing.T) { - resourceName := "azurerm_azuread_service_principal_password.test" + data := acceptance.BuildTestData(t, "azurerm_azuread_service_principal_password", "test") applicationId, err := uuid.GenerateUUID() if err != nil { t.Fatal(err) @@ -106,10 +106,10 @@ func TestAccAzureRMActiveDirectoryServicePrincipalPassword_customKeyId(t *testin Config: config, Check: resource.ComposeTestCheckFunc( // can't assert on Value since it's not returned - testCheckAzureRMActiveDirectoryServicePrincipalPasswordExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "start_date"), - resource.TestCheckResourceAttr(resourceName, "key_id", keyId), - resource.TestCheckResourceAttr(resourceName, "end_date", "2020-01-01T01:02:03Z"), + testCheckAzureRMActiveDirectoryServicePrincipalPasswordExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "start_date"), + resource.TestCheckResourceAttr(data.ResourceName, "key_id", keyId), + resource.TestCheckResourceAttr(data.ResourceName, "end_date", "2020-01-01T01:02:03Z"), ), }, }, diff --git a/azurerm/internal/services/graph/resource_arm_azuread_service_principal_test.go b/azurerm/internal/services/graph/tests/resource_arm_azuread_service_principal_test.go similarity index 87% rename from azurerm/internal/services/graph/resource_arm_azuread_service_principal_test.go rename to azurerm/internal/services/graph/tests/resource_arm_azuread_service_principal_test.go index af4a88e10c82..de6baf6b0137 100644 --- a/azurerm/internal/services/graph/resource_arm_azuread_service_principal_test.go +++ b/azurerm/internal/services/graph/tests/resource_arm_azuread_service_principal_test.go @@ -1,4 +1,4 @@ -package graph +package tests import ( "fmt" @@ -14,7 +14,7 @@ import ( ) func TestAccAzureRMActiveDirectoryServicePrincipal_basic(t *testing.T) { - resourceName := "azurerm_azuread_service_principal.test" + data := acceptance.BuildTestData(t, "azurerm_azuread_service_principal", "test") id := uuid.New().String() config := testAccAzureRMActiveDirectoryServicePrincipal_basic(id) @@ -26,16 +26,12 @@ func TestAccAzureRMActiveDirectoryServicePrincipal_basic(t *testing.T) { { Config: config, Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryServicePrincipalExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "display_name"), - resource.TestCheckResourceAttrSet(resourceName, "application_id"), + testCheckAzureRMActiveDirectoryServicePrincipalExists(data.ResourceName), + resource.TestCheckResourceAttrSet(data.ResourceName, "display_name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "application_id"), ), }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -46,7 +42,7 @@ func TestAccAzureRMActiveDirectoryServicePrincipal_requiresImport(t *testing.T) return } - resourceName := "azurerm_azuread_service_principal.test" + data := acceptance.BuildTestData(t, "azurerm_azuread_service_principal", "test") id := uuid.New().String() resource.ParallelTest(t, resource.TestCase{ @@ -57,7 +53,7 @@ func TestAccAzureRMActiveDirectoryServicePrincipal_requiresImport(t *testing.T) { Config: testAccAzureRMActiveDirectoryServicePrincipal_basic(id), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMActiveDirectoryServicePrincipalExists(resourceName), + testCheckAzureRMActiveDirectoryServicePrincipalExists(data.ResourceName), ), }, { From de8a708934d83ef38fee54e31d73f7482ab08354 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 13:39:18 -0800 Subject: [PATCH 158/203] fix error in resource_arm_batch_pool_test.go --- .../services/batch/tests/resource_arm_batch_pool_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/batch/tests/resource_arm_batch_pool_test.go b/azurerm/internal/services/batch/tests/resource_arm_batch_pool_test.go index cf3efecce0de..673b6d4276b0 100644 --- a/azurerm/internal/services/batch/tests/resource_arm_batch_pool_test.go +++ b/azurerm/internal/services/batch/tests/resource_arm_batch_pool_test.go @@ -29,7 +29,7 @@ func TestAccAzureRMBatchPool_basic(t *testing.T) { testCheckAzureRMBatchPoolExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "vm_size", "STANDARD_A1"), resource.TestCheckResourceAttr(data.ResourceName, "node_agent_sku_id", "batch.node.ubuntu 16.04"), - resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", rs)), + resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.#", "1"), resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.publisher", "Canonical"), resource.TestCheckResourceAttr(data.ResourceName, "storage_image_reference.0.sku", "16.04.0-LTS"), From 69bcc115bb5f1907cd3f49f9bf16667b1951daa2 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 13:41:29 -0800 Subject: [PATCH 159/203] storage migrations: switching to the new test structure --- .../services/storage/resource_arm_storage_table.go | 8 ++++---- .../storage/resource_arm_storage_table_migration.go | 6 +++--- .../resource_arm_storage_account_migration_test.go | 5 +++-- .../resource_arm_storage_blob_migration_test.go | 5 +++-- .../resource_arm_storage_container_migration_test.go | 5 +++-- .../resource_arm_storage_queue_migration_test.go | 5 +++-- .../resource_arm_storage_share_migration_test.go | 7 ++++--- .../resource_arm_storage_table_migration_test.go | 7 ++++--- 8 files changed, 27 insertions(+), 21 deletions(-) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_account_migration_test.go (88%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_blob_migration_test.go (91%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_container_migration_test.go (91%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_queue_migration_test.go (91%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_share_migration_test.go (90%) rename azurerm/internal/services/storage/{ => tests}/resource_arm_storage_table_migration_test.go (89%) diff --git a/azurerm/internal/services/storage/resource_arm_storage_table.go b/azurerm/internal/services/storage/resource_arm_storage_table.go index 08da3d6d23e1..5a7b2466707f 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table.go @@ -31,13 +31,13 @@ func resourceArmStorageTable() *schema.Resource { StateUpgraders: []schema.StateUpgrader{ { // this should have been applied from pre-0.12 migration system; backporting just in-case - Type: resourceStorageTableStateResourceV0V1().CoreConfigSchema().ImpliedType(), - Upgrade: resourceStorageTableStateUpgradeV0ToV1, + Type: ResourceStorageTableStateResourceV0V1().CoreConfigSchema().ImpliedType(), + Upgrade: ResourceStorageTableStateUpgradeV0ToV1, Version: 0, }, { - Type: resourceStorageTableStateResourceV0V1().CoreConfigSchema().ImpliedType(), - Upgrade: resourceStorageTableStateUpgradeV1ToV2, + Type: ResourceStorageTableStateResourceV0V1().CoreConfigSchema().ImpliedType(), + Upgrade: ResourceStorageTableStateUpgradeV1ToV2, Version: 1, }, }, diff --git a/azurerm/internal/services/storage/resource_arm_storage_table_migration.go b/azurerm/internal/services/storage/resource_arm_storage_table_migration.go index fea99ca0ad74..12b1ced79c86 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table_migration.go +++ b/azurerm/internal/services/storage/resource_arm_storage_table_migration.go @@ -12,7 +12,7 @@ import ( ) // the schema schema was used for both V0 and V1 -func resourceStorageTableStateResourceV0V1() *schema.Resource { +func ResourceStorageTableStateResourceV0V1() *schema.Resource { return &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { @@ -68,7 +68,7 @@ func resourceStorageTableStateResourceV0V1() *schema.Resource { } } -func resourceStorageTableStateUpgradeV0ToV1(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { +func ResourceStorageTableStateUpgradeV0ToV1(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { tableName := rawState["name"].(string) accountName := rawState["storage_account_name"].(string) environment := meta.(*clients.Client).Account.Environment @@ -81,7 +81,7 @@ func resourceStorageTableStateUpgradeV0ToV1(rawState map[string]interface{}, met return rawState, nil } -func resourceStorageTableStateUpgradeV1ToV2(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { +func ResourceStorageTableStateUpgradeV1ToV2(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { tableName := rawState["name"].(string) accountName := rawState["storage_account_name"].(string) environment := meta.(*clients.Client).Account.Environment diff --git a/azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go similarity index 88% rename from azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go index 78370892d34a..eb86ad7190f0 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go @@ -1,9 +1,10 @@ -package storage +package tests import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` ) func TestAzureRMStorageAccountMigrateState(t *testing.T) { @@ -51,7 +52,7 @@ func TestAzureRMStorageAccountMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := ResourceStorageAccountMigrateState(tc.StateVersion, is, tc.Meta) + is, err := storage.ResourceStorageAccountMigrateState(tc.StateVersion, is, tc.Meta) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go similarity index 91% rename from azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go index 18bf52c93b28..40e46d12caae 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_blob_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go @@ -1,4 +1,4 @@ -package storage +package tests import ( "context" @@ -8,6 +8,7 @@ import ( "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/clients" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` ) // NOTE: this is intentionally an acceptance test (and we're not explicitly setting the env) @@ -62,7 +63,7 @@ func TestAccAzureRMStorageBlobMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := ResourceStorageBlobMigrateState(tc.StateVersion, is, client) + is, err := storage.ResourceStorageBlobMigrateState(tc.StateVersion, is, client) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go similarity index 91% rename from azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go index 46d074082087..9eb50075022d 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_container_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go @@ -1,4 +1,4 @@ -package storage +package tests import ( "context" @@ -8,6 +8,7 @@ import ( "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/clients" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` ) // NOTE: this is intentionally an acceptance test (and we're not explicitly setting the env) @@ -61,7 +62,7 @@ func TestAccAzureRMStorageContainerMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := ResourceStorageContainerMigrateState(tc.StateVersion, is, client) + is, err := storage.ResourceStorageContainerMigrateState(tc.StateVersion, is, client) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go similarity index 91% rename from azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go index 76bae71a7c59..d85fe1e28cf1 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_queue_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go @@ -1,4 +1,4 @@ -package storage +package tests import ( "context" @@ -8,6 +8,7 @@ import ( "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/clients" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` ) // NOTE: this is intentionally an acceptance test (and we're not explicitly setting the env) @@ -61,7 +62,7 @@ func TestAccAzureRMStorageQueueMigrateState(t *testing.T) { ID: tc.ID, Attributes: tc.InputAttributes, } - is, err := ResourceStorageQueueMigrateState(tc.StateVersion, is, client) + is, err := storage.ResourceStorageQueueMigrateState(tc.StateVersion, is, client) if err != nil { t.Fatalf("bad: %s, err: %#v", tn, err) diff --git a/azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go similarity index 90% rename from azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go index c16ae17734f4..15aeb26e782a 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_share_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go @@ -1,4 +1,4 @@ -package storage +package tests import ( "fmt" @@ -7,6 +7,7 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` ) func TestAzureRMStorageShareMigrateStateV0ToV1(t *testing.T) { @@ -40,7 +41,7 @@ func TestAzureRMStorageShareMigrateStateV0ToV1(t *testing.T) { "quota": 5120, } - actual, err := ResourceStorageShareStateUpgradeV0ToV1(input, meta) + actual, err := storage.ResourceStorageShareStateUpgradeV0ToV1(input, meta) if err != nil { t.Fatalf("Expected no error but got: %s", err) } @@ -84,7 +85,7 @@ func TestAzureRMStorageShareMigrateStateV1ToV2(t *testing.T) { "quota": 5120, } - actual, err := ResourceStorageShareStateUpgradeV1ToV2(input, meta) + actual, err := storage.ResourceStorageShareStateUpgradeV1ToV2(input, meta) if err != nil { t.Fatalf("Expected no error but got: %s", err) } diff --git a/azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go similarity index 89% rename from azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go rename to azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go index f24b171aa7f9..7731f96ef090 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_table_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go @@ -1,4 +1,4 @@ -package storage +package tests import ( "fmt" @@ -7,6 +7,7 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` ) func TestAzureRMStorageTableMigrateStateV0ToV1(t *testing.T) { @@ -38,7 +39,7 @@ func TestAzureRMStorageTableMigrateStateV0ToV1(t *testing.T) { "storage_account_name": "account1", } - actual, err := resourceStorageTableStateUpgradeV0ToV1(input, meta) + actual, err := storage.ResourceStorageTableStateUpgradeV0ToV1(input, meta) if err != nil { t.Fatalf("Expected no error but got: %s", err) } @@ -80,7 +81,7 @@ func TestAzureRMStorageTableMigrateStateV1ToV2(t *testing.T) { "storage_account_name": "account1", } - actual, err := resourceStorageTableStateUpgradeV1ToV2(input, meta) + actual, err := storage.ResourceStorageTableStateUpgradeV1ToV2(input, meta) if err != nil { t.Fatalf("Expected no error but got: %s", err) } From 619b42c4e6f7a990991f97b848a1bff083f2d244 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 13:44:48 -0800 Subject: [PATCH 160/203] fix goimport and whitespace errors --- .../services/apimanagement/tests/diff_suppress_test.go | 3 ++- .../tests/resource_arm_app_configuration_test.go | 3 ++- .../resource_arm_application_insights_analytics_item_test.go | 3 ++- .../services/automation/tests/automation_variable_test.go | 3 ++- .../services/batch/tests/resource_arm_batch_account_test.go | 3 ++- .../tests/resource_arm_data_factory_dataset_mysql_test.go | 1 - azurerm/internal/services/keyvault/resource_arm_key_vault.go | 3 ++- azurerm/internal/services/redis/resource_arm_redis_cache.go | 3 ++- .../resource_arm_servicebus_namespace_migration_test.go | 3 ++- .../sql/tests/resource_arm_sql_virtual_network_rule_test.go | 3 ++- .../services/storage/resource_arm_storage_account.go | 5 +++-- .../data_source_storage_account_blob_container_sas_test.go | 3 ++- .../storage/tests/data_source_storage_account_sas_test.go | 3 ++- azurerm/internal/services/storage/tests/metadata_test.go | 3 ++- .../tests/resource_arm_storage_account_migration_test.go | 2 +- .../storage/tests/resource_arm_storage_account_test.go | 3 ++- .../tests/resource_arm_storage_blob_migration_test.go | 2 +- .../tests/resource_arm_storage_container_migration_test.go | 2 +- .../tests/resource_arm_storage_queue_migration_test.go | 2 +- .../storage/tests/resource_arm_storage_queue_test.go | 3 ++- .../tests/resource_arm_storage_share_migration_test.go | 2 +- .../tests/resource_arm_storage_table_migration_test.go | 2 +- .../storage/tests/resource_arm_storage_table_test.go | 3 ++- azurerm/internal/services/storage/tests/validation_test.go | 3 ++- .../resource_arm_app_service_virtual_network_association.go | 3 ++- .../services/web/tests/resource_arm_app_service_test.go | 3 --- 26 files changed, 43 insertions(+), 29 deletions(-) diff --git a/azurerm/internal/services/apimanagement/tests/diff_suppress_test.go b/azurerm/internal/services/apimanagement/tests/diff_suppress_test.go index 48a784724def..93c25aaafa4e 100644 --- a/azurerm/internal/services/apimanagement/tests/diff_suppress_test.go +++ b/azurerm/internal/services/apimanagement/tests/diff_suppress_test.go @@ -1,9 +1,10 @@ package tests import ( - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement" "log" "testing" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement" ) func TestXmlWithDotNetInterpolationsDiffSuppress(t *testing.T) { diff --git a/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go b/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go index 49ac2ccbe5d1..8bda1879cd2a 100644 --- a/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go +++ b/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go @@ -2,10 +2,11 @@ package tests import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appconfiguration" "net/http" "testing" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/appconfiguration" + "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" diff --git a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go index 5836c3be158e..49a8d00a82ac 100644 --- a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_analytics_item_test.go @@ -2,9 +2,10 @@ package tests import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/applicationinsights" "testing" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/applicationinsights" + "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" diff --git a/azurerm/internal/services/automation/tests/automation_variable_test.go b/azurerm/internal/services/automation/tests/automation_variable_test.go index 3e4eae607d73..d666302d5ea2 100644 --- a/azurerm/internal/services/automation/tests/automation_variable_test.go +++ b/azurerm/internal/services/automation/tests/automation_variable_test.go @@ -2,11 +2,12 @@ package tests import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/automation" "strings" "testing" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/automation" + "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" diff --git a/azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go b/azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go index 810a449b738c..bd46fb789d65 100644 --- a/azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go +++ b/azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go @@ -2,11 +2,12 @@ package tests import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/batch" "net/http" "os" "testing" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/batch" + "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" diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go index 7344de1ec3ad..e6e2456c31ed 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_dataset_mysql_test.go @@ -32,7 +32,6 @@ func TestAccAzureRMDataFactoryDatasetMySQL_basic(t *testing.T) { } func TestAccAzureRMDataFactoryDatasetMySQL_update(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_mysql", "test") resource.ParallelTest(t, resource.TestCase{ diff --git a/azurerm/internal/services/keyvault/resource_arm_key_vault.go b/azurerm/internal/services/keyvault/resource_arm_key_vault.go index d2b8d3055d17..a8dee0b0b0fa 100644 --- a/azurerm/internal/services/keyvault/resource_arm_key_vault.go +++ b/azurerm/internal/services/keyvault/resource_arm_key_vault.go @@ -2,12 +2,13 @@ package keyvault import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "log" "net/http" "regexp" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" + "github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2018-02-14/keyvault" "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" diff --git a/azurerm/internal/services/redis/resource_arm_redis_cache.go b/azurerm/internal/services/redis/resource_arm_redis_cache.go index f4eb7061d047..9e2ed80a57a4 100644 --- a/azurerm/internal/services/redis/resource_arm_redis_cache.go +++ b/azurerm/internal/services/redis/resource_arm_redis_cache.go @@ -3,13 +3,14 @@ package redis import ( "context" "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "log" "net/http" "strconv" "strings" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" + "github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis" "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" diff --git a/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_migration_test.go b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_migration_test.go index a654b230f8bc..ea4e95b31672 100644 --- a/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_migration_test.go +++ b/azurerm/internal/services/servicebus/tests/resource_arm_servicebus_namespace_migration_test.go @@ -1,10 +1,11 @@ package tests import ( - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/servicebus" "reflect" "testing" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/servicebus" + "github.com/hashicorp/terraform-plugin-sdk/terraform" ) diff --git a/azurerm/internal/services/sql/tests/resource_arm_sql_virtual_network_rule_test.go b/azurerm/internal/services/sql/tests/resource_arm_sql_virtual_network_rule_test.go index 7a9fbbb0efd1..6909a59f50b2 100644 --- a/azurerm/internal/services/sql/tests/resource_arm_sql_virtual_network_rule_test.go +++ b/azurerm/internal/services/sql/tests/resource_arm_sql_virtual_network_rule_test.go @@ -2,10 +2,11 @@ package tests import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/sql" "regexp" "testing" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/sql" + "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" diff --git a/azurerm/internal/services/storage/resource_arm_storage_account.go b/azurerm/internal/services/storage/resource_arm_storage_account.go index 56008fadf933..26965313008d 100644 --- a/azurerm/internal/services/storage/resource_arm_storage_account.go +++ b/azurerm/internal/services/storage/resource_arm_storage_account.go @@ -2,14 +2,15 @@ package storage import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "log" "net/http" "regexp" "strings" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/iothub" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" + "github.com/Azure/azure-sdk-for-go/services/preview/security/mgmt/v1.0/security" "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage" azautorest "github.com/Azure/go-autorest/autorest" diff --git a/azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go b/azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go index 337e45cfe28e..6b719546e072 100644 --- a/azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go +++ b/azurerm/internal/services/storage/tests/data_source_storage_account_blob_container_sas_test.go @@ -2,10 +2,11 @@ package tests import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) diff --git a/azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go b/azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go index 7039fc31128d..c788115bb7ec 100644 --- a/azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go +++ b/azurerm/internal/services/storage/tests/data_source_storage_account_sas_test.go @@ -2,10 +2,11 @@ package tests import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" ) diff --git a/azurerm/internal/services/storage/tests/metadata_test.go b/azurerm/internal/services/storage/tests/metadata_test.go index e5f598a67e98..2cefa1cfa591 100644 --- a/azurerm/internal/services/storage/tests/metadata_test.go +++ b/azurerm/internal/services/storage/tests/metadata_test.go @@ -1,8 +1,9 @@ package tests import ( - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" ) func TestValidateMetaDataKeys(t *testing.T) { diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go index eb86ad7190f0..c2993c108e05 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_account_migration_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/terraform" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" ) func TestAzureRMStorageAccountMigrateState(t *testing.T) { diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go index 0dd87841e693..1e00104a8db6 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_account_test.go @@ -2,12 +2,13 @@ package tests import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "net/http" "os" "regexp" "testing" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go index 40e46d12caae..d4f537812722 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_blob_migration_test.go @@ -8,7 +8,7 @@ import ( "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/clients" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" ) // NOTE: this is intentionally an acceptance test (and we're not explicitly setting the env) diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go index 9eb50075022d..3a08346eab8e 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_container_migration_test.go @@ -8,7 +8,7 @@ import ( "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/clients" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" ) // NOTE: this is intentionally an acceptance test (and we're not explicitly setting the env) diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go index d85fe1e28cf1..56f3763403dd 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_migration_test.go @@ -8,7 +8,7 @@ import ( "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/clients" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" ) // NOTE: this is intentionally an acceptance test (and we're not explicitly setting the env) diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go index dc85b980ca6f..e80662188014 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_queue_test.go @@ -2,9 +2,10 @@ package tests import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "testing" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/terraform" diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go index 15aeb26e782a..01974ce78743 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_share_migration_test.go @@ -7,7 +7,7 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" ) func TestAzureRMStorageShareMigrateStateV0ToV1(t *testing.T) { diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go index 7731f96ef090..7694b6d93726 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_table_migration_test.go @@ -7,7 +7,7 @@ import ( "github.com/Azure/go-autorest/autorest/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" - `github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage` + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" ) func TestAzureRMStorageTableMigrateStateV0ToV1(t *testing.T) { diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go index 79ce2e3fec54..80228e8a0097 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_table_test.go @@ -2,10 +2,11 @@ package tests import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "strings" "testing" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" + "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" diff --git a/azurerm/internal/services/storage/tests/validation_test.go b/azurerm/internal/services/storage/tests/validation_test.go index 66f2de217d7b..67bb3754f1a1 100644 --- a/azurerm/internal/services/storage/tests/validation_test.go +++ b/azurerm/internal/services/storage/tests/validation_test.go @@ -1,9 +1,10 @@ package tests import ( - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" "strings" "testing" + + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage" ) func TestValidateArmStorageShareName(t *testing.T) { diff --git a/azurerm/internal/services/web/resource_arm_app_service_virtual_network_association.go b/azurerm/internal/services/web/resource_arm_app_service_virtual_network_association.go index cd0a27de0ecb..015aafc93d4c 100644 --- a/azurerm/internal/services/web/resource_arm_app_service_virtual_network_association.go +++ b/azurerm/internal/services/web/resource_arm_app_service_virtual_network_association.go @@ -2,9 +2,10 @@ package web import ( "fmt" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" "time" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" + "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" diff --git a/azurerm/internal/services/web/tests/resource_arm_app_service_test.go b/azurerm/internal/services/web/tests/resource_arm_app_service_test.go index 4ab0f784f546..ab82cdf0f6fe 100644 --- a/azurerm/internal/services/web/tests/resource_arm_app_service_test.go +++ b/azurerm/internal/services/web/tests/resource_arm_app_service_test.go @@ -487,7 +487,6 @@ func TestAccAzureRMAppService_clientAffinityUpdate(t *testing.T) { } func TestAccAzureRMAppService_connectionStrings(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -524,7 +523,6 @@ func TestAccAzureRMAppService_connectionStrings(t *testing.T) { } func TestAccAzureRMAppService_storageAccounts(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_app_service", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -1598,7 +1596,6 @@ func TestAccAzureRMAppService_twitterAuthSettings(t *testing.T) { } func TestAccAzureRMAppService_multiAuthSettings(t *testing.T) { - tenantID := os.Getenv("ARM_TENANT_ID") data := acceptance.BuildTestData(t, "azurerm_app_service", "test") From c58e28db4e9002fae489cb83e5d869447cf481d1 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 13:47:50 -0800 Subject: [PATCH 161/203] fix linting errors --- azurerm/internal/provider/provider.go | 4 ++-- .../tests/resource_arm_application_insights_api_key_test.go | 2 +- .../services/batch/tests/resource_arm_batch_account_test.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/provider/provider.go b/azurerm/internal/provider/provider.go index f7906b3ee9e8..8763fe8ec189 100644 --- a/azurerm/internal/provider/provider.go +++ b/azurerm/internal/provider/provider.go @@ -25,8 +25,8 @@ func AzureProvider() terraform.ResourceProvider { log.Printf(f, v...) } - dataSources := make(map[string]*schema.Resource, 0) - resources := make(map[string]*schema.Resource, 0) + dataSources := make(map[string]*schema.Resource) + resources := make(map[string]*schema.Resource) for _, service := range SupportedServices() { debugLog("[DEBUG] Registering Data Sources for %q..", service.Name()) for k, v := range service.SupportedDataSources() { diff --git a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go index 7843baee0456..1ebcc75cf0d4 100644 --- a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_api_key_test.go @@ -52,7 +52,7 @@ func TestAccAzureRMApplicationInsightsAPIKey_requiresImport(t *testing.T) { ), }, { - Config: testAccAzureRMApplicationInsights_requiresImport(data, "web"), + Config: testAccAzureRMApplicationInsightsAPIKey_requiresImport(data, "[]", "[]"), ExpectError: acceptance.RequiresImportError("azurerm_application_insights"), }, }, diff --git a/azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go b/azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go index bd46fb789d65..069205d40060 100644 --- a/azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go +++ b/azurerm/internal/services/batch/tests/resource_arm_batch_account_test.go @@ -282,7 +282,7 @@ resource "azurerm_batch_account" "test" { version = "2" } } -`, data.RandomString, data.Locations.Primary, data.RandomString, data.RandomString) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString) } func testAccAzureRMBatchAccount_userSubscription(data acceptance.TestData, tenantID string) string { From 4f27962f162a5d76b3713b0b1f2a81139ba7c106 Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 21 Dec 2019 14:23:23 -0800 Subject: [PATCH 162/203] GOGC=5 for linting --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d3d69814762b..065043f11800 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ matrix: - name: "make lintstatic" script: GOGC=15 make lintstatic - name: "make linttravis" - script: GOGC=15 make lintrest + script: GOGC=5 make lintrest - name: "make tflint" script: make tflint - name: "make test" From 9d638de53ad51b218cc881326d2e1b28c8fd380a Mon Sep 17 00:00:00 2001 From: kt Date: Sun, 22 Dec 2019 11:51:53 -0800 Subject: [PATCH 163/203] try and fix travis OOM error --- ...i-travisrest.yml => .golangci-travis-1.yml | 8 ------- .golangci-travis-2.yml | 22 +++++++++++++++++++ .golangci-travis-3.yml | 22 +++++++++++++++++++ .travis.yml | 8 +++++-- GNUmakefile | 14 ++++++++++-- 5 files changed, 62 insertions(+), 12 deletions(-) rename .golangci-travisrest.yml => .golangci-travis-1.yml (79%) create mode 100644 .golangci-travis-2.yml create mode 100644 .golangci-travis-3.yml diff --git a/.golangci-travisrest.yml b/.golangci-travis-1.yml similarity index 79% rename from .golangci-travisrest.yml rename to .golangci-travis-1.yml index 7e9dae76b5b8..f7111e28bea4 100644 --- a/.golangci-travisrest.yml +++ b/.golangci-travis-1.yml @@ -19,14 +19,6 @@ linters: - interfacer - nakedret - misspell - - structcheck - - typecheck - - unused - - unconvert - - varcheck - - vet - - vetshadow - - whitespace linters-settings: errcheck: diff --git a/.golangci-travis-2.yml b/.golangci-travis-2.yml new file mode 100644 index 000000000000..cf8f407bdee4 --- /dev/null +++ b/.golangci-travis-2.yml @@ -0,0 +1,22 @@ +run: + deadline: 30m10s + modules-download-mode: vendor + +issues: + max-per-linter: 0 + max-same-issues: 0 + +linters: + disable-all: true + enable: + - structcheck + - typecheck + - unused + - unconvert + +linters-settings: + errcheck: + ignore: github.com/hashicorp/terraform-plugin-sdk/helper/schema:ForceNew|Set,fmt:.*,io:Close + misspell: + ignore-words: + - hdinsight diff --git a/.golangci-travis-3.yml b/.golangci-travis-3.yml new file mode 100644 index 000000000000..a4b929008ff9 --- /dev/null +++ b/.golangci-travis-3.yml @@ -0,0 +1,22 @@ +run: + deadline: 30m10s + modules-download-mode: vendor + +issues: + max-per-linter: 0 + max-same-issues: 0 + +linters: + disable-all: true + enable: + - varcheck + - vet + - vetshadow + - whitespace + +linters-settings: + errcheck: + ignore: github.com/hashicorp/terraform-plugin-sdk/helper/schema:ForceNew|Set,fmt:.*,io:Close + misspell: + ignore-words: + - hdinsight diff --git a/.travis.yml b/.travis.yml index 065043f11800..4f6e0675bd8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,8 +29,12 @@ matrix: include: - name: "make lintstatic" script: GOGC=15 make lintstatic - - name: "make linttravis" - script: GOGC=5 make lintrest + - name: "make linttravis1" + script: GOGC=5 make lintrest1 + - name: "make linttravis2" + script: GOGC=5 make lintrest2 + - name: "make linttravis3" + script: GOGC=5 make lintrest3 - name: "make tflint" script: make tflint - name: "make test" diff --git a/GNUmakefile b/GNUmakefile index cdac65f0e1aa..3e35cfac1f61 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -47,10 +47,20 @@ lintstatic: (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ golangci-lint run ./... -v --no-config --concurrency 1 --deadline=30m10s --disable-all --enable=staticcheck; ES=$$?; kill -9 $$PID; exit $$ES -lintrest: +lintrest1: @echo "==> Checking source code against linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ - golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travisrest.yml ; ES=$$?; kill -9 $$PID; exit $$ES + golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis-1.yml ; ES=$$?; kill -9 $$PID; exit $$ES + +lintrest2: + @echo "==> Checking source code against linters..." + (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ + golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis-2.yml ; ES=$$?; kill -9 $$PID; exit $$ES + +lintrest3: + @echo "==> Checking source code against linters..." + (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ + golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis-2.yml ; ES=$$?; kill -9 $$PID; exit $$ES tflint: @echo "==> Checking source code against terraform provider linters..." From 660c8658137955741a8aa5c24a063fe0220bc978 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 23 Dec 2019 08:01:17 +0100 Subject: [PATCH 164/203] travis: temporarily disabling travis2 and travis3 Since this is an enhancement and not a blocking change - we can instead do this in a separate PR post-merging this one; which is blocking other things. --- .travis.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4f6e0675bd8c..c150d55d785c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,10 +31,11 @@ matrix: script: GOGC=15 make lintstatic - name: "make linttravis1" script: GOGC=5 make lintrest1 - - name: "make linttravis2" - script: GOGC=5 make lintrest2 - - name: "make linttravis3" - script: GOGC=5 make lintrest3 + # TODO: fix/re-enable in a separate PR + #- name: "make linttravis2" + # script: GOGC=5 make lintrest2 + #- name: "make linttravis3" + # script: GOGC=5 make lintrest3 - name: "make tflint" script: make tflint - name: "make test" From feb3fef8ad4a763446c0fd1ba70a79dfe5ac44d8 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 23 Dec 2019 08:42:08 +0100 Subject: [PATCH 165/203] refactor: sorting the keys in the registration structs --- .../internal/services/common/service_registration.go | 3 --- azurerm/internal/services/compute/registration.go | 4 ++-- azurerm/internal/services/loganalytics/registration.go | 2 +- .../internal/services/recoveryservices/registration.go | 10 +++++----- azurerm/internal/services/resource/registration.go | 2 +- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/azurerm/internal/services/common/service_registration.go b/azurerm/internal/services/common/service_registration.go index 33447ae69b16..f4d433676498 100644 --- a/azurerm/internal/services/common/service_registration.go +++ b/azurerm/internal/services/common/service_registration.go @@ -2,9 +2,6 @@ package common import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" -// NOTE: unfortunately this has to live in it's own package to avoid a circular reference -// since the Services will need to access ArmClient which is moving to `internal/common` - type ServiceRegistration interface { // Name is the name of this Service Name() string diff --git a/azurerm/internal/services/compute/registration.go b/azurerm/internal/services/compute/registration.go index 8ac9a25433ff..bddae3dec966 100644 --- a/azurerm/internal/services/compute/registration.go +++ b/azurerm/internal/services/compute/registration.go @@ -31,10 +31,10 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { func (r Registration) SupportedResources() map[string]*schema.Resource { resources := map[string]*schema.Resource{ "azurerm_availability_set": resourceArmAvailabilitySet(), - "azurerm_managed_disk": resourceArmManagedDisk(), "azurerm_image": resourceArmImage(), - "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), + "azurerm_managed_disk": resourceArmManagedDisk(), "azurerm_marketplace_agreement": resourceArmMarketplaceAgreement(), + "azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(), "azurerm_shared_image_gallery": resourceArmSharedImageGallery(), "azurerm_shared_image_version": resourceArmSharedImageVersion(), "azurerm_shared_image": resourceArmSharedImage(), diff --git a/azurerm/internal/services/loganalytics/registration.go b/azurerm/internal/services/loganalytics/registration.go index b9f4a802cb32..05d3b41202f2 100644 --- a/azurerm/internal/services/loganalytics/registration.go +++ b/azurerm/internal/services/loganalytics/registration.go @@ -20,8 +20,8 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), "azurerm_log_analytics_linked_service": resourceArmLogAnalyticsLinkedService(), + "azurerm_log_analytics_solution": resourceArmLogAnalyticsSolution(), "azurerm_log_analytics_workspace_linked_service": resourceArmLogAnalyticsWorkspaceLinkedService(), "azurerm_log_analytics_workspace": resourceArmLogAnalyticsWorkspace()} } diff --git a/azurerm/internal/services/recoveryservices/registration.go b/azurerm/internal/services/recoveryservices/registration.go index a650aca1df6a..c2c497c38216 100644 --- a/azurerm/internal/services/recoveryservices/registration.go +++ b/azurerm/internal/services/recoveryservices/registration.go @@ -22,6 +22,11 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ + "azurerm_backup_container_storage_account": resourceArmBackupProtectionContainerStorageAccount(), + "azurerm_backup_policy_file_share": resourceArmBackupProtectionPolicyFileShare(), + "azurerm_backup_protected_file_share": resourceArmBackupProtectedFileShare(), + "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), + "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), "azurerm_recovery_network_mapping": resourceArmRecoveryServicesNetworkMapping(), "azurerm_recovery_replicated_vm": resourceArmRecoveryServicesReplicatedVm(), "azurerm_recovery_services_fabric": resourceArmRecoveryServicesFabric(), @@ -37,10 +42,5 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_site_recovery_protection_container_mapping": resourceArmSiteRecoveryProtectionContainerMapping(), "azurerm_site_recovery_replicated_vm": resourceArmSiteRecoveryReplicatedVM(), "azurerm_site_recovery_replication_policy": resourceArmSiteRecoveryReplicationPolicy(), - "azurerm_backup_container_storage_account": resourceArmBackupProtectionContainerStorageAccount(), - "azurerm_backup_policy_file_share": resourceArmBackupProtectionPolicyFileShare(), - "azurerm_backup_protected_file_share": resourceArmBackupProtectedFileShare(), - "azurerm_backup_protected_vm": resourceArmRecoveryServicesBackupProtectedVM(), - "azurerm_backup_policy_vm": resourceArmBackupProtectionPolicyVM(), } } diff --git a/azurerm/internal/services/resource/registration.go b/azurerm/internal/services/resource/registration.go index 08ad4bd5b533..156f7b6514a8 100644 --- a/azurerm/internal/services/resource/registration.go +++ b/azurerm/internal/services/resource/registration.go @@ -22,8 +22,8 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_resource_group": resourceArmResourceGroup(), "azurerm_management_lock": resourceArmManagementLock(), + "azurerm_resource_group": resourceArmResourceGroup(), "azurerm_template_deployment": resourceArmTemplateDeployment(), } } From e70fbb5bb84efad81f510926a84cb86fd1fd0b5f Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 23 Dec 2019 09:00:57 +0100 Subject: [PATCH 166/203] timeouts: fixing the timeouts script to handle the refactor --- scripts/timeouts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/timeouts.sh b/scripts/timeouts.sh index f74be3d011e6..52b0a12f15b9 100755 --- a/scripts/timeouts.sh +++ b/scripts/timeouts.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -files=$(ls ./azurerm/*.go) +files=$(find ./azurerm -type f -name "*.go") error=false echo "==> Checking that Custom Timeouts are used..." From 7ab6787040edf3bfe5f90e75bc58917f980ff9fd Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 23 Dec 2019 09:03:05 +0100 Subject: [PATCH 167/203] registry: adding a check for an empty category --- scripts/website-registrycheck.sh | 4 ++++ 1 file changed, 4 insertions(+) mode change 100644 => 100755 scripts/website-registrycheck.sh diff --git a/scripts/website-registrycheck.sh b/scripts/website-registrycheck.sh old mode 100644 new mode 100755 index 01032d1ea55a..33faa8e79466 --- a/scripts/website-registrycheck.sh +++ b/scripts/website-registrycheck.sh @@ -21,6 +21,10 @@ for doc in $docs; do if ! grep "^subcategory: " "$doc" > /dev/null; then echo "Website documentation file is missing a 'subcategory' line at the top: $doc" error=true + # cannot be empty + elif grep "^subcategory: \"\"" "$doc" > /dev/null; then + echo "Website documentation file cannot have an empty 'subcategory' line at the top: $doc" + error=true fi ;; From cedaf8521394d8f678ac6dd9c3896ffdf31c8837 Mon Sep 17 00:00:00 2001 From: BHoggs <40219783+BHoggs@users.noreply.github.com> Date: Fri, 20 Dec 2019 10:56:08 +1300 Subject: [PATCH 168/203] Fix mistakes and add additional example --- website/docs/d/resources.html.markdown | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/website/docs/d/resources.html.markdown b/website/docs/d/resources.html.markdown index 821655b2e329..e59e284ea4d5 100644 --- a/website/docs/d/resources.html.markdown +++ b/website/docs/d/resources.html.markdown @@ -23,11 +23,30 @@ data "azurerm_resources" "example" { data "azurerm_resources" "example" { resource_group_name = "example-resources" - required_tags { + required_tags = { environment = "production" role = "webserver" } } + +# Get resources by type, create spoke vNet peerings +data "azurerm_resources" "spokes" { + type = "Microsoft.Network/virtualNetworks" + + required_tags = { + environment = "production" + role = "spokeNetwork" + } +} + +resource "azurerm_virtual_network_peering" "spoke_peers" { + count = length(data.azurerm_resources.spokes.resources) + + name = "hub2${data.azurerm_resources.spokes.resources[count.index].name}" + resource_group_name = azurerm_resource_group.hub.name + virtual_network_name = azurerm_virtual_network.hub.name + remote_virtual_network_id = data.azurerm_resources.spokes.resources[count.index].id +} ``` ## Argument Reference @@ -54,8 +73,8 @@ The `resource` block contains: * `id` - The Resource ID of this resource. -* `type` - The type of this resoource. +* `type` - The type of this resource. (e.g. `Microsoft.Network/virtualNetworks`) * `location` - The location of this resource. -* `tags` - The type of resource that this is, such as `Microsoft.Network/virtualNetworks`. +* `tags` - Map of tags that are applied to this resource From 92cf359c31fa332729b7ebfb19b0950470c38210 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 11:58:46 -0800 Subject: [PATCH 169/203] tests: misc cleanup after test reorg (#5239) --- ...ource_arm_analysis_services_server_test.go | 24 ++--------- ...e_arm_api_management_api_operation_test.go | 42 ++++--------------- ...urce_arm_api_management_api_schema_test.go | 6 +-- .../resource_arm_api_management_api_test.go | 38 ++++------------- ...arm_api_management_api_version_set_test.go | 24 ++--------- ...pi_management_authorization_server_test.go | 12 +----- ...esource_arm_api_management_backend_test.go | 24 ++--------- ...urce_arm_api_management_diagnostic_test.go | 6 +-- .../resource_arm_api_management_group_test.go | 12 +----- ...urce_arm_api_management_group_user_test.go | 6 +-- ...management_openid_connect_provider_test.go | 12 +----- ...rce_arm_api_management_product_api_test.go | 6 +-- ...e_arm_api_management_product_group_test.go | 6 +-- ...esource_arm_api_management_product_test.go | 30 +++---------- ...source_arm_api_management_property_test.go | 12 +----- ...ce_arm_api_management_subscription_test.go | 12 +----- .../tests/resource_arm_api_management_test.go | 36 +++------------- .../resource_arm_api_management_user_test.go | 6 +-- .../resource_arm_app_configuration_test.go | 28 ++++--------- ...source_arm_automation_job_schedule_test.go | 18 ++------ .../data_source_batch_certificate_test.go | 3 +- .../resource_arm_bot_channel_email_test.go | 15 +++---- ...rm_linux_virtual_machine_scale_set_test.go | 2 +- ...irtual_machine_scale_set_extension_test.go | 4 +- ..._windows_virtual_machine_scale_set_test.go | 2 +- .../resource_arm_container_registry_test.go | 20 ++++----- ..._factory_linked_service_sql_server_test.go | 6 +-- ...ce_arm_data_lake_analytics_account_test.go | 5 +-- ...resource_arm_dev_test_lab_schedule_test.go | 10 ++--- .../tests/resource_arm_front_door_test.go | 6 +-- ..._arm_express_route_circuit_peering_test.go | 5 +-- ...urce_arm_point_to_site_vpn_gateway_test.go | 2 +- .../tests/resource_arm_virtual_hub_test.go | 2 +- .../tests/resource_arm_vpn_gateway_test.go | 2 +- ...ource_arm_vpn_server_configuration_test.go | 2 +- ...source_arm_storage_share_directory_test.go | 2 +- .../resource_arm_storage_table_entity_test.go | 2 +- .../services/web/resource_arm_app_service.go | 1 + ..._virtual_network_association.html.markdown | 2 +- 39 files changed, 106 insertions(+), 347 deletions(-) diff --git a/azurerm/internal/services/analysisservices/tests/resource_arm_analysis_services_server_test.go b/azurerm/internal/services/analysisservices/tests/resource_arm_analysis_services_server_test.go index 4e315297bb4c..512db8070273 100644 --- a/azurerm/internal/services/analysisservices/tests/resource_arm_analysis_services_server_test.go +++ b/azurerm/internal/services/analysisservices/tests/resource_arm_analysis_services_server_test.go @@ -27,11 +27,7 @@ func TestAccAzureRMAnalysisServicesServer_basic(t *testing.T) { testCheckAzureRMAnalysisServicesServerExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -170,19 +166,11 @@ func TestAccAzureRMAnalysisServicesServer_adminUsers(t *testing.T) { { Config: preConfig, }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: postConfig, }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -202,11 +190,7 @@ func TestAccAzureRMAnalysisServicesServer_serverFullName(t *testing.T) { resource.TestCheckResourceAttrSet(data.ResourceName, "server_full_name"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go index ae44c431f0d8..34a3db939949 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_operation_test.go @@ -26,11 +26,7 @@ func TestAccAzureRMApiManagementApiOperation_basic(t *testing.T) { testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -73,11 +69,7 @@ func TestAccAzureRMApiManagementApiOperation_customMethod(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "method", "HAMMERTIME"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -96,11 +88,7 @@ func TestAccAzureRMApiManagementApiOperation_headers(t *testing.T) { testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -119,22 +107,14 @@ func TestAccAzureRMApiManagementApiOperation_requestRepresentations(t *testing.T testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: testAccAzureRMApiManagementApiOperation_requestRepresentationUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -154,22 +134,14 @@ func TestAccAzureRMApiManagementApiOperation_representations(t *testing.T) { testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: testAccAzureRMApiManagementApiOperation_representationUpdated(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMApiManagementApiOperationExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go index 45b30785bd3e..44e2d6f01a41 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_schema_test.go @@ -26,11 +26,7 @@ func TestAccAzureRMApiManagementApiSchema_basic(t *testing.T) { testCheckAzureRMApiManagementApiSchemaExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go index 3f524561b005..1aa95caf9c72 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_test.go @@ -29,11 +29,7 @@ func TestAccAzureRMApiManagementApi_basic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -56,11 +52,7 @@ func TestAccAzureRMApiManagementApi_basicClassic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -80,11 +72,7 @@ func TestAccAzureRMApiManagementApi_wordRevision(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "revision", "one-point-oh"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -104,11 +92,7 @@ func TestAccAzureRMApiManagementApi_version(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "version", "v1"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -150,11 +134,7 @@ func TestAccAzureRMApiManagementApi_soapPassthrough(t *testing.T) { testCheckAzureRMApiManagementApiExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -269,11 +249,7 @@ func TestAccAzureRMApiManagementApi_complete(t *testing.T) { testCheckAzureRMApiManagementApiExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -548,7 +524,7 @@ resource "azurerm_api_management" "test" { func testAccAzureRMApiManagementApi_templateClassic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go index 3f434ea59eb2..7f507e129e85 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_api_version_set_test.go @@ -26,11 +26,7 @@ func TestAccAzureRMApiManagementApiVersionSet_basic(t *testing.T) { testCheckAzureRMApiManagementApiVersionSetExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -72,11 +68,7 @@ func TestAccAzureRMApiManagementApiVersionSet_header(t *testing.T) { testCheckAzureRMApiManagementApiVersionSetExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -95,11 +87,7 @@ func TestAccAzureRMApiManagementApiVersionSet_query(t *testing.T) { testCheckAzureRMApiManagementApiVersionSetExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -128,11 +116,7 @@ func TestAccAzureRMApiManagementApiVersionSet_update(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "display_name", fmt.Sprintf("TestApiVersionSet2%d", data.RandomInteger)), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go index 45a444c02cfe..e5e1f452c009 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_authorization_server_test.go @@ -26,11 +26,7 @@ func TestAccAzureRMAPIManagementAuthorizationServer_basic(t *testing.T) { testCheckAzureRMAPIManagementAuthorizationServerExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -72,11 +68,7 @@ func TestAccAzureRMAPIManagementAuthorizationServer_complete(t *testing.T) { testCheckAzureRMAPIManagementAuthorizationServerExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go index aa3ccb482946..01a4f454847f 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_backend_test.go @@ -28,11 +28,7 @@ func TestAccAzureRMApiManagementBackend_basic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "url", "https://acctest"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -71,11 +67,7 @@ func TestAccAzureRMApiManagementBackend_allProperties(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "tls.0.validate_certificate_name", "true"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -94,11 +86,7 @@ func TestAccAzureRMApiManagementBackend_credentialsNoCertificate(t *testing.T) { testCheckAzureRMApiManagementBackendExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -173,11 +161,7 @@ func TestAccAzureRMApiManagementBackend_serviceFabric(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "service_fabric_cluster.0.server_certificate_thumbprints.#", "2"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go index f219e1f6204b..a70d65aa3270 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_diagnostic_test.go @@ -27,11 +27,7 @@ func TestAccAzureRMApiManagementDiagnostic_basic(t *testing.T) { testCheckAzureRMApiManagementDiagnosticExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go index 93a9da21050e..3fb9f6be3e8b 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_test.go @@ -29,11 +29,7 @@ func TestAccAzureRMAPIManagementGroup_basic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "type", "custom"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -82,11 +78,7 @@ func TestAccAzureRMAPIManagementGroup_complete(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "type", "external"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go index f620c37e57da..f38cc9e4e68e 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_group_user_test.go @@ -26,11 +26,7 @@ func TestAccAzureRMAPIManagementGroupUser_basic(t *testing.T) { testCheckAzureRMAPIManagementGroupUserExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go index 06920a5e3b30..306e4a839aab 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_openid_connect_provider_test.go @@ -26,11 +26,7 @@ func TestAccAzureRMApiManagementOpenIDConnectProvider_basic(t *testing.T) { testCheckAzureRMApiManagementOpenIDConnectProviderExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -78,11 +74,7 @@ func TestAccAzureRMApiManagementOpenIDConnectProvider_update(t *testing.T) { testCheckAzureRMApiManagementOpenIDConnectProviderExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go index 1b861f128a11..6d9f027355d8 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_api_test.go @@ -26,11 +26,7 @@ func TestAccAzureRMAPIManagementProductApi_basic(t *testing.T) { testCheckAzureRMAPIManagementProductApiExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go index 400ef7ad8e0b..e6b1c5a5f806 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_group_test.go @@ -26,11 +26,7 @@ func TestAccAzureRMAPIManagementProductGroup_basic(t *testing.T) { testCheckAzureRMAPIManagementProductGroupExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go index 2b630eccb52f..acb42c5c182f 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_product_test.go @@ -34,11 +34,7 @@ func TestAccAzureRMApiManagementProduct_basic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "terms", ""), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -114,11 +110,7 @@ func TestAccAzureRMApiManagementProduct_update(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "terms", ""), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: testAccAzureRMApiManagementProduct_updated(data), Check: resource.ComposeTestCheckFunc( @@ -132,11 +124,7 @@ func TestAccAzureRMApiManagementProduct_update(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "terms", ""), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: testAccAzureRMApiManagementProduct_basic(data), Check: resource.ComposeTestCheckFunc( @@ -170,11 +158,7 @@ func TestAccAzureRMApiManagementProduct_subscriptionsLimit(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "subscriptions_limit", "2"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -201,11 +185,7 @@ func TestAccAzureRMApiManagementProduct_complete(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "terms", "These are some example terms and conditions"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go index bb330151d7d7..9fd43131abfc 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_property_test.go @@ -30,11 +30,7 @@ func TestAccAzureRMAPIManagementProperty_basic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "tags.1", "tag2"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -70,11 +66,7 @@ func TestAccAzureRMAPIManagementProperty_update(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "tags.1", "tag4"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go index 1bbd2a2f9255..b8190f3625ae 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_subscription_test.go @@ -29,11 +29,7 @@ func TestAccAzureRMAPIManagementSubscription_basic(t *testing.T) { resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -125,11 +121,7 @@ func TestAccAzureRMAPIManagementSubscription_complete(t *testing.T) { resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go index e24401e12e3e..b4dd75350b13 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_test.go @@ -28,11 +28,7 @@ func TestAccAzureRMApiManagement_basic(t *testing.T) { testCheckAzureRMApiManagementExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -53,11 +49,7 @@ func TestAccAzureRMApiManagement_basicClassic(t *testing.T) { testCheckAzureRMApiManagementExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -119,11 +111,7 @@ func TestAccAzureRMApiManagement_customProps(t *testing.T) { testCheckAzureRMApiManagementExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -177,11 +165,7 @@ func TestAccAzureRMApiManagement_signInSignUpSettings(t *testing.T) { testCheckAzureRMApiManagementExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -200,11 +184,7 @@ func TestAccAzureRMApiManagement_policy(t *testing.T) { testCheckAzureRMApiManagementExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), { Config: testAccAzureRMApiManagement_policyXmlLink(data), Check: resource.ComposeTestCheckFunc( @@ -225,11 +205,7 @@ func TestAccAzureRMApiManagement_policy(t *testing.T) { testCheckAzureRMApiManagementExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go index 956ad2c83ab7..7b419a093945 100644 --- a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_user_test.go @@ -28,11 +28,7 @@ func TestAccAzureRMApiManagementUser_basic(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "last_name", "Test"), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go b/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go index 8bda1879cd2a..785b7daa0de1 100644 --- a/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go +++ b/azurerm/internal/services/appconfiguration/tests/resource_arm_app_configuration_test.go @@ -85,11 +85,7 @@ func TestAccAzureAppConfiguration_free(t *testing.T) { testCheckAzureAppConfigurationExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -108,11 +104,7 @@ func TestAccAzureAppConfiguration_standard(t *testing.T) { testCheckAzureAppConfigurationExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -154,11 +146,7 @@ func TestAccAzureAppConfiguration_complete(t *testing.T) { testCheckAzureAppConfigurationExists(data.ResourceName), ), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -245,12 +233,12 @@ func testCheckAzureAppConfigurationExists(resourceName string) resource.TestChec func testAccAzureAppConfiguration_free(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } resource "azurerm_app_configuration" "test" { - name = "testaccappconf%d" + name = "testacc-appconf%d" resource_group_name = "${azurerm_resource_group.test.name}" location = "${azurerm_resource_group.test.location}" sku = "free" @@ -261,7 +249,7 @@ resource "azurerm_app_configuration" "test" { func testAccAzureAppConfiguration_standard(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -292,7 +280,7 @@ resource "azurerm_app_configuration" "import" { func testAccAzureAppConfiguration_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -312,7 +300,7 @@ resource "azurerm_app_configuration" "test" { func testAccAzureAppConfiguration_completeUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/automation/tests/resource_arm_automation_job_schedule_test.go b/azurerm/internal/services/automation/tests/resource_arm_automation_job_schedule_test.go index b80e23057658..ff9788215b96 100644 --- a/azurerm/internal/services/automation/tests/resource_arm_automation_job_schedule_test.go +++ b/azurerm/internal/services/automation/tests/resource_arm_automation_job_schedule_test.go @@ -26,11 +26,7 @@ func TestAccAzureRMAutomationJobSchedule_basic(t *testing.T) { Config: testAccAzureRMAutomationJobSchedule_basic(data), Check: checkAccAzureRMAutomationJobSchedule_basic(data.ResourceName), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -47,11 +43,7 @@ func TestAccAzureRMAutomationJobSchedule_complete(t *testing.T) { Config: testAccAzureRMAutomationJobSchedule_complete(data), Check: checkAccAzureRMAutomationJobSchedule_complete(data.ResourceName), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } @@ -76,11 +68,7 @@ func TestAccAzureRMAutomationJobSchedule_update(t *testing.T) { Config: testAccAzureRMAutomationJobSchedule_basic(data), Check: checkAccAzureRMAutomationJobSchedule_basic(data.ResourceName), }, - { - ResourceName: data.ResourceName, - ImportState: true, - ImportStateVerify: true, - }, + data.ImportStep(), }, }) } diff --git a/azurerm/internal/services/batch/tests/data_source_batch_certificate_test.go b/azurerm/internal/services/batch/tests/data_source_batch_certificate_test.go index 460b8ed455e9..7fb6091bf801 100644 --- a/azurerm/internal/services/batch/tests/data_source_batch_certificate_test.go +++ b/azurerm/internal/services/batch/tests/data_source_batch_certificate_test.go @@ -10,14 +10,13 @@ import ( func TestAccDataSourceAzureRMBatchCertificate_basic(t *testing.T) { data := acceptance.BuildTestData(t, "data.azurerm_batch_certificate", "test") - config := testAccDataSourceAzureRMBatchCertificate_basic(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, Steps: []resource.TestStep{ { - Config: config, + Config: testAccDataSourceAzureRMBatchCertificate_basic(data), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(data.ResourceName, "name", "sha1-42c107874fd0e4a9583292a2f1098e8fe4b2edda"), resource.TestCheckResourceAttr(data.ResourceName, "account_name", fmt.Sprintf("testaccbatch%s", data.RandomString)), diff --git a/azurerm/internal/services/bot/tests/resource_arm_bot_channel_email_test.go b/azurerm/internal/services/bot/tests/resource_arm_bot_channel_email_test.go index a65e7baa30b0..8316ad0db9d2 100644 --- a/azurerm/internal/services/bot/tests/resource_arm_bot_channel_email_test.go +++ b/azurerm/internal/services/bot/tests/resource_arm_bot_channel_email_test.go @@ -19,7 +19,6 @@ func TestAccAzureRMBotChannelEmail_basic(t *testing.T) { t.Skip("Skipping as one of `ARM_TEST_EMAIL`, AND `ARM_TEST_EMAIL_PASSWORD` was not specified") } data := acceptance.BuildTestData(t, "azurerm_bot_channel_email", "test") - config := testAccAzureRMBotChannelEmail_basicConfig(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -27,7 +26,7 @@ func TestAccAzureRMBotChannelEmail_basic(t *testing.T) { CheckDestroy: testCheckAzureRMBotChannelEmailDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMBotChannelEmail_basicConfig(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMBotChannelEmailExists(data.ResourceName), ), @@ -45,8 +44,6 @@ func TestAccAzureRMBotChannelEmail_update(t *testing.T) { t.Skip("Skipping as one of `ARM_TEST_SLACK_CLIENT_ID`, `ARM_TEST_SLACK_CLIENT_SECRET`, or `ARM_TEST_SLACK_VERIFICATION_TOKEN` was not specified") } data := acceptance.BuildTestData(t, "azurerm_bot_channel_email", "test") - config := testAccAzureRMBotChannelEmail_basicConfig(data) - config2 := testAccAzureRMBotChannelEmail_basicUpdate(data) resource.Test(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -54,14 +51,14 @@ func TestAccAzureRMBotChannelEmail_update(t *testing.T) { CheckDestroy: testCheckAzureRMBotChannelEmailDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMBotChannelEmail_basicConfig(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMBotChannelEmailExists(data.ResourceName), ), }, data.ImportStep("email_password"), { - Config: config2, + Config: testAccAzureRMBotChannelEmail_basicUpdate(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMBotChannelEmailExists(data.ResourceName), ), @@ -73,6 +70,9 @@ func TestAccAzureRMBotChannelEmail_update(t *testing.T) { func testCheckAzureRMBotChannelEmailExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Bot.ChannelClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + // Ensure we have enough information in state to look up in API rs, ok := s.RootModule().Resources[name] if !ok { @@ -85,9 +85,6 @@ func testCheckAzureRMBotChannelEmailExists(name string) resource.TestCheckFunc { return fmt.Errorf("Bad: no resource group found in state for Bot Channel Email") } - client := acceptance.AzureProvider.Meta().(*clients.Client).Bot.ChannelClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - resp, err := client.Get(ctx, resourceGroup, botName, string(botservice.ChannelNameEmailChannel)) if err != nil { return fmt.Errorf("Bad: Get on botChannelClient: %+v", err) diff --git a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_test.go index 64ab33d491d9..8c07fcb387b7 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_test.go @@ -70,7 +70,7 @@ locals { } resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_extension_test.go b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_extension_test.go index 0cf8e90d9715..9f41ca183490 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_extension_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_virtual_machine_scale_set_extension_test.go @@ -444,7 +444,7 @@ resource "azurerm_virtual_machine_scale_set_extension" "import" { func testAccAzureRMVirtualMachineScaleSetExtension_templateLinux(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -505,7 +505,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { func testAccAzureRMVirtualMachineScaleSetExtension_templateWindows(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_test.go b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_test.go index 66953cb2669c..8e500021c4b1 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_windows_virtual_machine_scale_set_test.go @@ -74,7 +74,7 @@ locals { } resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go b/azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go index dc4f9114755d..c80d452f78aa 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_container_registry_test.go @@ -481,7 +481,7 @@ func testCheckAzureRMContainerRegistryGeoreplications(resourceName string, sku s func testAccAzureRMContainerRegistry_basic_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -501,7 +501,7 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_basicManaged(data acceptance.TestData, sku string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -532,7 +532,7 @@ resource "azurerm_container_registry" "import" { func testAccAzureRMContainerRegistry_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -553,7 +553,7 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_completeUpdated(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -574,7 +574,7 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_geoReplication(data acceptance.TestData, sku string, georeplicationLocations string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -591,7 +591,7 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation(data acceptance.TestData, sku string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -607,7 +607,7 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_geoReplicationUpdateWithNoLocation_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -627,7 +627,7 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_networkAccessProfile_ip(data acceptance.TestData, sku string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%[1]d" + name = "acctestRG-%[1]d" location = "%[2]s" } @@ -658,7 +658,7 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_networkAccessProfile_vnet(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%[1]d" + name = "acctestRG-%[1]d" location = "%[2]s" } @@ -705,7 +705,7 @@ resource "azurerm_container_registry" "test" { func testAccAzureRMContainerRegistry_networkAccessProfile_both(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%[1]d" + name = "acctestRG-%[1]d" location = "%[2]s" } diff --git a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go index 18f459efa391..c6719a36a963 100644 --- a/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go +++ b/azurerm/internal/services/datafactory/tests/resource_arm_data_factory_linked_service_sql_server_test.go @@ -49,6 +49,9 @@ func TestAccAzureRMDataFactoryLinkedServiceSQLServer_basic(t *testing.T) { func testCheckAzureRMDataFactoryLinkedServiceSQLServerExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).DataFactory.LinkedServiceClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + // Ensure we have enough information in state to look up in API rs, ok := s.RootModule().Resources[name] if !ok { @@ -62,9 +65,6 @@ func testCheckAzureRMDataFactoryLinkedServiceSQLServerExists(name string) resour return fmt.Errorf("Bad: no resource group found in state for Data Factory: %s", name) } - client := acceptance.AzureProvider.Meta().(*clients.Client).DataFactory.LinkedServiceClient - ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") if err != nil { return fmt.Errorf("Bad: Get on dataFactoryLinkedServiceClient: %+v", err) diff --git a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go index fa29a489e599..06ed3d3caf0f 100644 --- a/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go +++ b/azurerm/internal/services/datalake/tests/resource_arm_data_lake_analytics_account_test.go @@ -52,10 +52,7 @@ func TestAccAzureRMDataLakeAnalyticsAccount_requiresImport(t *testing.T) { testCheckAzureRMDataLakeAnalyticsAccountExists(data.ResourceName), ), }, - { - Config: testAccAzureRMDataLakeAnalyticsAccount_requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_data_lake_analytics_account"), - }, + data.RequiresImportErrorStep(testAccAzureRMDataLakeAnalyticsAccount_requiresImport), }, }) } diff --git a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go index 7893e29f7815..504db94aa5af 100644 --- a/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go +++ b/azurerm/internal/services/devtestlabs/tests/resource_arm_dev_test_lab_schedule_test.go @@ -162,7 +162,7 @@ func testCheckAzureRMDevTestLabScheduleDestroy(s *terraform.State) error { func testAccAzureRMDevTestLabSchedule_autoShutdownBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -197,7 +197,7 @@ resource "azurerm_dev_test_schedule" "test" { func testAccAzureRMDevTestLabSchedule_autoShutdownBasicUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -235,7 +235,7 @@ resource "azurerm_dev_test_schedule" "test" { func testAccAzureRMDevTestLabSchedule_autoStartupBasic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -273,7 +273,7 @@ resource "azurerm_dev_test_schedule" "test" { func testAccAzureRMDevTestLabSchedule_autoStartupBasicUpdate(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -314,7 +314,7 @@ resource "azurerm_dev_test_schedule" "test" { func testAccAzureRMDevTestLabSchedule_concurrent(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go index a197a9acad7f..8a7683698003 100644 --- a/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go +++ b/azurerm/internal/services/frontdoor/tests/resource_arm_front_door_test.go @@ -172,7 +172,7 @@ func testCheckAzureRMFrontDoorDestroy(s *terraform.State) error { func testAccAzureRMFrontDoor_basic(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -285,7 +285,7 @@ resource "azurerm_frontdoor" "import" { func testAccAzureRMFrontDoor_complete(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } @@ -346,7 +346,7 @@ resource "azurerm_frontdoor" "test" { func testAccAzureRMFrontDoor_waf(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go index c09255fafbdd..16e9bd7ecd5e 100644 --- a/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_express_route_circuit_peering_test.go @@ -53,10 +53,7 @@ func testAccAzureRMExpressRouteCircuitPeering_requiresImport(t *testing.T) { testCheckAzureRMExpressRouteCircuitPeeringExists(data.ResourceName), ), }, - { - Config: testAccAzureRMExpressRouteCircuitPeering_requiresImportConfig(data), - ExpectError: acceptance.RequiresImportError("azurerm_express_route_circuit_peering"), - }, + data.RequiresImportErrorStep(testAccAzureRMExpressRouteCircuitPeering_requiresImportConfig), }, }) } diff --git a/azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go index b63f080d2a45..7c8bb3bf83b0 100644 --- a/azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_point_to_site_vpn_gateway_test.go @@ -250,7 +250,7 @@ resource "azurerm_point_to_site_vpn_gateway" "test" { func testAccAzureRMAzureRMPointToSiteVPNGateway_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go b/azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go index 28edba603616..77b22318bffe 100644 --- a/azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_virtual_hub_test.go @@ -283,7 +283,7 @@ resource "azurerm_virtual_hub" "test" { func testAccAzureRMVirtualHub_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go b/azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go index bb3fcbf71b67..42bb9cd4fbfa 100644 --- a/azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_vpn_gateway_test.go @@ -288,7 +288,7 @@ resource "azurerm_vpn_gateway" "test" { func testAccAzureRMVPNGateway_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go b/azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go index 3d38a19d0711..54bb7ea7dd89 100644 --- a/azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go +++ b/azurerm/internal/services/network/tests/resource_arm_vpn_server_configuration_test.go @@ -441,7 +441,7 @@ EOF func testAccAzureRMAzureRMVPNServerConfiguration_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go index e4a61f2cc5e2..71f3e4f522ca 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_share_directory_test.go @@ -316,7 +316,7 @@ resource "azurerm_storage_share_directory" "child" { func testAccAzureRMStorageShareDirectory_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go b/azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go index 5b1911f4142d..13aea750d856 100644 --- a/azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go +++ b/azurerm/internal/services/storage/tests/resource_arm_storage_table_entity_test.go @@ -235,7 +235,7 @@ resource "azurerm_storage_table_entity" "test" { func testAccAzureRMTableEntity_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestrg-%d" + name = "acctestRG-%d" location = "%s" } diff --git a/azurerm/internal/services/web/resource_arm_app_service.go b/azurerm/internal/services/web/resource_arm_app_service.go index 9ea6454b7a03..b2b68dd38e6c 100644 --- a/azurerm/internal/services/web/resource_arm_app_service.go +++ b/azurerm/internal/services/web/resource_arm_app_service.go @@ -26,6 +26,7 @@ func resourceArmAppService() *schema.Resource { Read: resourceArmAppServiceRead, Update: resourceArmAppServiceUpdate, Delete: resourceArmAppServiceDelete, + Importer: azSchema.ValidateResourceIDPriorToImport(func(id string) error { _, err := ParseAppServiceID(id) return err diff --git a/website/docs/r/app_service_virtual_network_association.html.markdown b/website/docs/r/app_service_virtual_network_association.html.markdown index 97f7972e2f96..3946b1fb1bbd 100644 --- a/website/docs/r/app_service_virtual_network_association.html.markdown +++ b/website/docs/r/app_service_virtual_network_association.html.markdown @@ -16,7 +16,7 @@ Manages an App Service Virtual Network Association (this is for the [Regional VN ```hcl resource "azurerm_resource_group" "test" { - name = "acctestrg" + name = "acctestRG" location = "uksouth" } From fe8218a600518e23a20da00b7e221d95ca19636a Mon Sep 17 00:00:00 2001 From: aqche <39076898+aqche@users.noreply.github.com> Date: Wed, 25 Dec 2019 19:17:53 -0600 Subject: [PATCH 170/203] azurerm_logic_app_trigger_recurrence - support for start_time (#5244) Partially Addresses: #4316 --- ...source_arm_logic_app_trigger_recurrence.go | 15 +++++++ ...e_arm_logic_app_trigger_recurrence_test.go | 43 +++++++++++++++++++ ...logic_app_trigger_recurrence.html.markdown | 2 + 3 files changed, 60 insertions(+) diff --git a/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go index 673852349632..c9ad22c308b3 100644 --- a/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go +++ b/azurerm/internal/services/logic/resource_arm_logic_app_trigger_recurrence.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" ) func resourceArmLogicAppTriggerRecurrence() *schema.Resource { @@ -59,6 +60,12 @@ func resourceArmLogicAppTriggerRecurrence() *schema.Resource { Type: schema.TypeInt, Required: true, }, + + "start_time": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.RFC3339Time, + }, }, } } @@ -72,6 +79,10 @@ func resourceArmLogicAppTriggerRecurrenceCreateUpdate(d *schema.ResourceData, me "type": "Recurrence", } + if v, ok := d.GetOk("start_time"); ok { + trigger["recurrence"].(map[string]interface{})["startTime"] = v.(string) + } + logicAppId := d.Get("logic_app_id").(string) name := d.Get("name").(string) if err := resourceLogicAppTriggerUpdate(d, meta, logicAppId, name, trigger, "azurerm_logic_app_trigger_recurrence"); err != nil { @@ -125,6 +136,10 @@ func resourceArmLogicAppTriggerRecurrenceRead(d *schema.ResourceData, meta inter d.Set("interval", int(interval.(float64))) } + if startTime := recurrence["startTime"]; startTime != nil { + d.Set("start_time", startTime.(string)) + } + return nil } diff --git a/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_recurrence_test.go b/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_recurrence_test.go index 249124e6e372..8de5a70128ea 100644 --- a/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_recurrence_test.go +++ b/azurerm/internal/services/logic/tests/resource_arm_logic_app_trigger_recurrence_test.go @@ -192,6 +192,26 @@ func TestAccAzureRMLogicAppTriggerRecurrence_update(t *testing.T) { }) } +func TestAccAzureRMLogicAppTriggerRecurrence_startTime(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_logic_app_trigger_recurrence", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMLogicAppWorkflowDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMLogicAppTriggerRecurrence_startTime(data, "2020-01-01T01:02:03Z"), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMLogicAppTriggerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "start_time", "2020-01-01T01:02:03Z"), + ), + }, + data.ImportStep(), + }, + }) +} + func testAccAzureRMLogicAppTriggerRecurrence_basic(data acceptance.TestData, frequency string, interval int) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -214,6 +234,29 @@ resource "azurerm_logic_app_trigger_recurrence" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, frequency, interval) } +func testAccAzureRMLogicAppTriggerRecurrence_startTime(data acceptance.TestData, startTime string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_logic_app_workflow" "test" { + name = "acctestlaw-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_logic_app_trigger_recurrence" "test" { + name = "frequency-trigger" + logic_app_id = "${azurerm_logic_app_workflow.test.id}" + frequency = "Month" + interval = 1 + start_time = "%s" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, startTime) +} + func testAccAzureRMLogicAppTriggerRecurrence_requiresImport(data acceptance.TestData, frequency string, interval int) string { template := testAccAzureRMLogicAppTriggerRecurrence_basic(data, frequency, interval) return fmt.Sprintf(` diff --git a/website/docs/r/logic_app_trigger_recurrence.html.markdown b/website/docs/r/logic_app_trigger_recurrence.html.markdown index 2452ca634383..91ec38648f4f 100644 --- a/website/docs/r/logic_app_trigger_recurrence.html.markdown +++ b/website/docs/r/logic_app_trigger_recurrence.html.markdown @@ -47,6 +47,8 @@ The following arguments are supported: * `interval` - (Required) Specifies interval used for the Frequency, for example a value of `4` for `interval` and `hour` for `frequency` would run the Trigger every 4 hours. +* `start_time` - (Optional) Specifies the start date and time for this trigger in RFC3339 format: `2000-01-02T03:04:05Z`. + ## Attributes Reference The following attributes are exported: From eef847289389ab9a450dc644342c18a34bfb4462 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 17:18:49 -0800 Subject: [PATCH 171/203] Update CHANGELOG.md to include #5244 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e85f3735a307..e23bebee7252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ IMPROVEMENTS: * `azurerm_key_vault`: the `network_acls` property is now computed [GH-5207] * `azurerm_kubernetes_cluster` - support for the `managed_cluster_identity` property [GH-5168] * `azurerm_kubernetes_cluster` - support for private link [GH-5161] +* `azurerm_logic_app_trigger_recurrence` - support for the `start_time` property [GH-5244] * `azurerm_private_link_service` - support for the `enable_proxy_protocol` property [GH-5178] * `azurerm_recovery_services_fabric` - has been deprecated and renamed to ` azurerm_site_recovery_fabric` [GH-5170] * `azurerm_recovery_network_mapping` - has been deprecated and renamed to ` azurerm_site_recovery_network_mapping` [GH-5170] From 7d58850a9fe80ff1521b46b5242f7d5ca7c88504 Mon Sep 17 00:00:00 2001 From: Neil Ye Date: Thu, 26 Dec 2019 09:23:32 +0800 Subject: [PATCH 172/203] Add new resource & data source: azurerm_netapp_snapshot (#5215) fixes #5216 --- .../internal/services/netapp/client/client.go | 17 +- .../netapp/data_source_netapp_snapshot.go | 89 +++++ .../internal/services/netapp/registration.go | 14 +- .../netapp/resource_arm_netapp_snapshot.go | 189 +++++++++++ .../tests/data_source_netapp_snapshot_test.go | 41 +++ .../resource_arm_netapp_snapshot_test.go | 314 ++++++++++++++++++ .../internal/services/netapp/validation.go | 10 + .../services/netapp/validation_test.go | 68 ++++ examples/netapp/snapshot/main.tf | 63 ++++ examples/netapp/snapshot/variables.tf | 7 + website/azurerm.erb | 8 + website/docs/d/netapp_snapshot.html.markdown | 48 +++ website/docs/r/netapp_snapshot.html.markdown | 112 +++++++ 13 files changed, 968 insertions(+), 12 deletions(-) create mode 100644 azurerm/internal/services/netapp/data_source_netapp_snapshot.go create mode 100644 azurerm/internal/services/netapp/resource_arm_netapp_snapshot.go create mode 100644 azurerm/internal/services/netapp/tests/data_source_netapp_snapshot_test.go create mode 100644 azurerm/internal/services/netapp/tests/resource_arm_netapp_snapshot_test.go create mode 100644 examples/netapp/snapshot/main.tf create mode 100644 examples/netapp/snapshot/variables.tf create mode 100644 website/docs/d/netapp_snapshot.html.markdown create mode 100644 website/docs/r/netapp_snapshot.html.markdown diff --git a/azurerm/internal/services/netapp/client/client.go b/azurerm/internal/services/netapp/client/client.go index f2141ff1d023..cc0127c118bb 100644 --- a/azurerm/internal/services/netapp/client/client.go +++ b/azurerm/internal/services/netapp/client/client.go @@ -6,9 +6,10 @@ import ( ) type Client struct { - AccountClient *netapp.AccountsClient - PoolClient *netapp.PoolsClient - VolumeClient *netapp.VolumesClient + AccountClient *netapp.AccountsClient + PoolClient *netapp.PoolsClient + VolumeClient *netapp.VolumesClient + SnapshotClient *netapp.SnapshotsClient } func NewClient(o *common.ClientOptions) *Client { @@ -21,9 +22,13 @@ func NewClient(o *common.ClientOptions) *Client { volumeClient := netapp.NewVolumesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&volumeClient.Client, o.ResourceManagerAuthorizer) + snapshotClient := netapp.NewSnapshotsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&snapshotClient.Client, o.ResourceManagerAuthorizer) + return &Client{ - AccountClient: &accountClient, - PoolClient: &poolClient, - VolumeClient: &volumeClient, + AccountClient: &accountClient, + PoolClient: &poolClient, + VolumeClient: &volumeClient, + SnapshotClient: &snapshotClient, } } diff --git a/azurerm/internal/services/netapp/data_source_netapp_snapshot.go b/azurerm/internal/services/netapp/data_source_netapp_snapshot.go new file mode 100644 index 000000000000..42e8e258572f --- /dev/null +++ b/azurerm/internal/services/netapp/data_source_netapp_snapshot.go @@ -0,0 +1,89 @@ +package netapp + +import ( + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func dataSourceArmNetAppSnapshot() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmNetAppSnapshotRead, + + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: ValidateNetAppSnapshotName, + }, + + "location": azure.SchemaLocationForDataSource(), + + "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + + "account_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: ValidateNetAppAccountName, + }, + + "pool_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: ValidateNetAppPoolName, + }, + + "volume_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: ValidateNetAppVolumeName, + }, + }, + } +} + +func dataSourceArmNetAppSnapshotRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).NetApp.SnapshotClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + accountName := d.Get("account_name").(string) + poolName := d.Get("pool_name").(string) + volumeName := d.Get("volume_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + resp, err := client.Get(ctx, resourceGroup, accountName, poolName, volumeName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error: NetApp Snapshot %q (Resource Group %q) was not found", name, resourceGroup) + } + return fmt.Errorf("Error reading NetApp Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("Error retrieving NetApp Snapshot %q (Resource Group %q): ID was nil or empty", name, resourceGroup) + } + + d.SetId(*resp.ID) + + d.Set("name", name) + d.Set("resource_group_name", resourceGroup) + d.Set("account_name", accountName) + d.Set("pool_name", poolName) + d.Set("volume_name", volumeName) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + return nil +} diff --git a/azurerm/internal/services/netapp/registration.go b/azurerm/internal/services/netapp/registration.go index e432adbd1453..c1bb265794bb 100644 --- a/azurerm/internal/services/netapp/registration.go +++ b/azurerm/internal/services/netapp/registration.go @@ -14,15 +14,17 @@ func (r Registration) Name() string { // SupportedDataSources returns the supported Data Sources supported by this Service func (r Registration) SupportedDataSources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_netapp_account": dataSourceArmNetAppAccount(), - "azurerm_netapp_pool": dataSourceArmNetAppPool(), - "azurerm_netapp_volume": dataSourceArmNetAppVolume()} + "azurerm_netapp_account": dataSourceArmNetAppAccount(), + "azurerm_netapp_pool": dataSourceArmNetAppPool(), + "azurerm_netapp_volume": dataSourceArmNetAppVolume(), + "azurerm_netapp_snapshot": dataSourceArmNetAppSnapshot()} } // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ - "azurerm_netapp_account": resourceArmNetAppAccount(), - "azurerm_netapp_pool": resourceArmNetAppPool(), - "azurerm_netapp_volume": resourceArmNetAppVolume()} + "azurerm_netapp_account": resourceArmNetAppAccount(), + "azurerm_netapp_pool": resourceArmNetAppPool(), + "azurerm_netapp_volume": resourceArmNetAppVolume(), + "azurerm_netapp_snapshot": resourceArmNetAppSnapshot()} } diff --git a/azurerm/internal/services/netapp/resource_arm_netapp_snapshot.go b/azurerm/internal/services/netapp/resource_arm_netapp_snapshot.go new file mode 100644 index 000000000000..a8599b9e1e9a --- /dev/null +++ b/azurerm/internal/services/netapp/resource_arm_netapp_snapshot.go @@ -0,0 +1,189 @@ +package netapp + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp" + "github.com/hashicorp/go-azure-helpers/response" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmNetAppSnapshot() *schema.Resource { + return &schema.Resource{ + Create: resourceArmNetAppSnapshotCreate, + Read: resourceArmNetAppSnapshotRead, + Update: nil, + Delete: resourceArmNetAppSnapshotDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: ValidateNetAppSnapshotName, + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "location": azure.SchemaLocation(), + + "account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: ValidateNetAppAccountName, + }, + + "pool_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: ValidateNetAppPoolName, + }, + + "volume_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: ValidateNetAppVolumeName, + }, + }, + } +} + +func resourceArmNetAppSnapshotCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).NetApp.SnapshotClient + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + accountName := d.Get("account_name").(string) + poolName := d.Get("pool_name").(string) + volumeName := d.Get("volume_name").(string) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + resp, err := client.Get(ctx, resourceGroup, accountName, poolName, volumeName, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for present of existing NetApp Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + } + } + if !utils.ResponseWasNotFound(resp.Response) { + return tf.ImportAsExistsError("azurerm_netapp_snapshot", *resp.ID) + } + } + + location := azure.NormalizeLocation(d.Get("location").(string)) + + parameters := netapp.Snapshot{ + Location: utils.String(location), + } + + future, err := client.Create(ctx, parameters, resourceGroup, accountName, poolName, volumeName, name) + if err != nil { + return fmt.Errorf("Error creating NetApp Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + } + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting for creation of NetApp Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, accountName, poolName, volumeName, name) + if err != nil { + return fmt.Errorf("Error retrieving NetApp Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + } + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("Cannot read NetApp Snapshot %q (Resource Group %q) ID", name, resourceGroup) + } + d.SetId(*resp.ID) + + return resourceArmNetAppSnapshotRead(d, meta) +} + +func resourceArmNetAppSnapshotRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).NetApp.SnapshotClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["netAppAccounts"] + poolName := id.Path["capacityPools"] + volumeName := id.Path["volumes"] + name := id.Path["snapshots"] + + resp, err := client.Get(ctx, resourceGroup, accountName, poolName, volumeName, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] NetApp Snapshots %q does not exist - removing from state", d.Id()) + d.SetId("") + return nil + } + return fmt.Errorf("Error reading NetApp Snapshots %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.Set("name", name) + d.Set("resource_group_name", resourceGroup) + d.Set("account_name", accountName) + d.Set("pool_name", poolName) + d.Set("volume_name", volumeName) + if location := resp.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + return nil +} + +func resourceArmNetAppSnapshotDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).NetApp.SnapshotClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + accountName := id.Path["netAppAccounts"] + poolName := id.Path["capacityPools"] + volumeName := id.Path["volumes"] + name := id.Path["snapshots"] + + future, err := client.Delete(ctx, resourceGroup, accountName, poolName, volumeName, name) + if err != nil { + if response.WasNotFound(future.Response()) { + return nil + } + return fmt.Errorf("Error deleting NetApp Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("Error waiting for deleting NetApp Snapshot %q (Resource Group %q): %+v", name, resourceGroup, err) + } + } + + return nil +} diff --git a/azurerm/internal/services/netapp/tests/data_source_netapp_snapshot_test.go b/azurerm/internal/services/netapp/tests/data_source_netapp_snapshot_test.go new file mode 100644 index 000000000000..272ff9cd055f --- /dev/null +++ b/azurerm/internal/services/netapp/tests/data_source_netapp_snapshot_test.go @@ -0,0 +1,41 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceAzureRMNetAppSnapshot_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_netapp_snapshot", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceNetAppSnapshot_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + ), + }, + }, + }) +} + +func testAccDataSourceNetAppSnapshot_basic(data acceptance.TestData) string { + config := testAccAzureRMNetAppSnapshot_basic(data) + return fmt.Sprintf(` +%s + +data "azurerm_netapp_snapshot" "test" { + resource_group_name = "${azurerm_netapp_snapshot.test.resource_group_name}" + account_name = "${azurerm_netapp_snapshot.test.account_name}" + pool_name = "${azurerm_netapp_snapshot.test.pool_name}" + volume_name = "${azurerm_netapp_snapshot.test.volume_name}" + name = "${azurerm_netapp_snapshot.test.name}" +} +`, config) +} diff --git a/azurerm/internal/services/netapp/tests/resource_arm_netapp_snapshot_test.go b/azurerm/internal/services/netapp/tests/resource_arm_netapp_snapshot_test.go new file mode 100644 index 000000000000..ea0ba259496a --- /dev/null +++ b/azurerm/internal/services/netapp/tests/resource_arm_netapp_snapshot_test.go @@ -0,0 +1,314 @@ +package tests + +import ( + "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/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMNetAppSnapshot_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_netapp_snapshot", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetAppSnapshotDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetAppSnapshot_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetAppSnapshotExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMNetAppSnapshot_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + data := acceptance.BuildTestData(t, "azurerm_netapp_snapshot", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetAppSnapshotDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetAppSnapshot_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetAppSnapshotExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMNetAppSnapshot_requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_netapp_snapshot"), + }, + }, + }) +} + +func TestAccAzureRMNetAppSnapshot_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_netapp_snapshot", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetAppSnapshotDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetAppSnapshot_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetAppSnapshotExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMNetAppSnapshot_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_netapp_snapshot", "test") + oldVolumeName := fmt.Sprintf("acctest-NetAppVolume-%d", data.RandomInteger) + newVolumeName := fmt.Sprintf("acctest-updated-NetAppVolume-%d", data.RandomInteger) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMNetAppSnapshotDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMNetAppSnapshot_complete(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetAppSnapshotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "volume_name", oldVolumeName), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMNetAppSnapshot_update(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMNetAppSnapshotExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "volume_name", newVolumeName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMNetAppSnapshotExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("NetApp Snapshot not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + accountName := rs.Primary.Attributes["account_name"] + poolName := rs.Primary.Attributes["pool_name"] + volumeName := rs.Primary.Attributes["volume_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + client := acceptance.AzureProvider.Meta().(*clients.Client).NetApp.SnapshotClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + if resp, err := client.Get(ctx, resourceGroup, accountName, poolName, volumeName, name); err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: NetApp Snapshot %q (Resource Group %q) does not exist", name, resourceGroup) + } + return fmt.Errorf("Bad: Get on netapp.SnapshotClient: %+v", err) + } + + return nil + } +} + +func testCheckAzureRMNetAppSnapshotDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).NetApp.SnapshotClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_netapp_snapshot" { + continue + } + + name := rs.Primary.Attributes["name"] + accountName := rs.Primary.Attributes["account_name"] + poolName := rs.Primary.Attributes["pool_name"] + volumeName := rs.Primary.Attributes["volume_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + if resp, err := client.Get(ctx, resourceGroup, accountName, poolName, volumeName, name); err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Get on netapp.SnapshotClient: %+v", err) + } + } + + return nil + } + + return nil +} + +func testAccAzureRMNetAppSnapshot_basic(data acceptance.TestData) string { + template := testAccAzureRMNetAppSnapshot_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_netapp_snapshot" "test" { + name = "acctest-NetAppSnapshot-%d" + account_name = "${azurerm_netapp_account.test.name}" + pool_name = "${azurerm_netapp_pool.test.name}" + volume_name = "${azurerm_netapp_volume.test.name}" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetAppSnapshot_requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_netapp_snapshot" "import" { + name = "${azurerm_netapp_snapshot.test.name}" + location = "${azurerm_netapp_snapshot.test.location}" + resource_group_name = "${azurerm_netapp_snapshot.test.name}" +} +`, testAccAzureRMNetAppSnapshot_basic(data)) +} + +func testAccAzureRMNetAppSnapshot_complete(data acceptance.TestData) string { + template := testAccAzureRMNetAppSnapshot_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_netapp_snapshot" "test" { + name = "acctest-NetAppSnapshot-%d" + account_name = "${azurerm_netapp_account.test.name}" + pool_name = "${azurerm_netapp_pool.test.name}" + volume_name = "${azurerm_netapp_volume.test.name}" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template, data.RandomInteger) +} + +func testAccAzureRMNetAppSnapshot_update(data acceptance.TestData) string { + template := testAccAzureRMNetAppSnapshot_template(data) + return fmt.Sprintf(` +%s + +resource "azurerm_virtual_network" "update" { + name = "acctest-updated-VirtualNetwork-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + address_space = ["10.0.0.0/16"] +} + +resource "azurerm_subnet" "update" { + name = "acctest-updated-Subnet-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.update.name}" + address_prefix = "10.0.2.0/24" + delegation { + name = "netapp" + service_delegation { + name = "Microsoft.Netapp/volumes" + actions = ["Microsoft.Network/networkinterfaces/*", "Microsoft.Network/virtualNetworks/subnets/join/action"] + } + } +} + +resource "azurerm_netapp_volume" "update" { + name = "acctest-updated-NetAppVolume-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + account_name = "${azurerm_netapp_account.test.name}" + pool_name = "${azurerm_netapp_pool.test.name}" + volume_path = "my-updated-unique-file-path-%d" + service_level = "Premium" + subnet_id = "${azurerm_subnet.update.id}" + storage_quota_in_gb = 100 +} + +resource "azurerm_netapp_snapshot" "test" { + name = "acctest-NetAppSnapshot-%d" + account_name = "${azurerm_netapp_account.test.name}" + pool_name = "${azurerm_netapp_pool.test.name}" + volume_name = "${azurerm_netapp_volume.update.name}" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, template, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMNetAppSnapshot_template(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-netapp-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctest-VirtualNetwork-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + address_space = ["10.0.0.0/16"] +} + +resource "azurerm_subnet" "test" { + name = "acctest-Subnet-%d" + resource_group_name = "${azurerm_resource_group.test.name}" + virtual_network_name = "${azurerm_virtual_network.test.name}" + address_prefix = "10.0.2.0/24" + + delegation { + name = "netapp" + + service_delegation { + name = "Microsoft.Netapp/volumes" + actions = ["Microsoft.Network/networkinterfaces/*", "Microsoft.Network/virtualNetworks/subnets/join/action"] + } + } +} + +resource "azurerm_netapp_account" "test" { + name = "acctest-NetAppAccount-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" +} + +resource "azurerm_netapp_pool" "test" { + name = "acctest-NetAppPool-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + account_name = "${azurerm_netapp_account.test.name}" + service_level = "Premium" + size_in_tb = 4 +} + +resource "azurerm_netapp_volume" "test" { + name = "acctest-NetAppVolume-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + account_name = "${azurerm_netapp_account.test.name}" + pool_name = "${azurerm_netapp_pool.test.name}" + volume_path = "my-unique-file-path-%d" + service_level = "Premium" + subnet_id = "${azurerm_subnet.test.id}" + storage_quota_in_gb = 100 +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +} diff --git a/azurerm/internal/services/netapp/validation.go b/azurerm/internal/services/netapp/validation.go index 24c7f3d78167..0f845c9165d0 100644 --- a/azurerm/internal/services/netapp/validation.go +++ b/azurerm/internal/services/netapp/validation.go @@ -44,3 +44,13 @@ func ValidateNetAppVolumeVolumePath(v interface{}, k string) (warnings []string, return warnings, errors } + +func ValidateNetAppSnapshotName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + + if !regexp.MustCompile(`^[\da-zA-Z][-_\da-zA-Z]{3,63}$`).MatchString(value) { + errors = append(errors, fmt.Errorf("%q must be between 4 and 64 characters in length and start with letters or numbers and contains only letters, numbers, underscore or hyphens.", k)) + } + + return warnings, errors +} diff --git a/azurerm/internal/services/netapp/validation_test.go b/azurerm/internal/services/netapp/validation_test.go index 7b72f66062f6..4359a04a159b 100644 --- a/azurerm/internal/services/netapp/validation_test.go +++ b/azurerm/internal/services/netapp/validation_test.go @@ -137,3 +137,71 @@ func TestValidateNetAppVolumeVolumePath(t *testing.T) { } } } + +func TestValidateNetAppSnapshotName(t *testing.T) { + testData := []struct { + input string + expected bool + }{ + { + // empty + input: "", + expected: false, + }, + { + // basic example + input: "hello", + expected: true, + }, + { + // can't start with an underscore + input: "_hello", + expected: false, + }, + { + // can't end with a dash + input: "hello-", + expected: true, + }, + { + // can't contain an exclamation mark + input: "hello!", + expected: false, + }, + { + // dash in the middle + input: "malcolm-in-the-middle", + expected: true, + }, + { + // can't end with a period + input: "hello.", + expected: false, + }, + { + // 63 chars + input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk", + expected: true, + }, + { + // 64 chars + input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkj", + expected: true, + }, + { + // 65 chars + input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkja", + expected: false, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q..", v.input) + + _, errors := ValidateNetAppSnapshotName(v.input, "name") + actual := len(errors) == 0 + if v.expected != actual { + t.Fatalf("Expected %t but got %t", v.expected, actual) + } + } +} diff --git a/examples/netapp/snapshot/main.tf b/examples/netapp/snapshot/main.tf new file mode 100644 index 000000000000..ba881d4a697c --- /dev/null +++ b/examples/netapp/snapshot/main.tf @@ -0,0 +1,63 @@ +resource "azurerm_resource_group" "example" { + name = "${var.prefix}-resources" + location = "${var.location}" +} + +resource "azurerm_virtual_network" "example" { + name = "${var.prefix}-virtualnetwork" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + address_space = ["10.0.0.0/16"] +} + +resource "azurerm_subnet" "example" { + name = "${var.prefix}-subnet" + resource_group_name = "${azurerm_resource_group.example.name}" + virtual_network_name = "${azurerm_virtual_network.example.name}" + address_prefix = "10.0.2.0/24" + + delegation { + name = "netapp" + + service_delegation { + name = "Microsoft.Netapp/volumes" + actions = ["Microsoft.Network/networkinterfaces/*", "Microsoft.Network/virtualNetworks/subnets/join/action"] + } + } +} + +resource "azurerm_netapp_account" "example" { + name = "${var.prefix}-netappaccount" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" +} + +resource "azurerm_netapp_pool" "example" { + name = "${var.prefix}-netapppool" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + account_name = "${azurerm_netapp_account.example.name}" + service_level = "Premium" + size_in_tb = 4 +} + +resource "azurerm_netapp_volume" "example" { + name = "${var.prefix}-netappvolume" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + account_name = "${azurerm_netapp_account.example.name}" + pool_name = "${azurerm_netapp_pool.example.name}" + volume_path = "my-unique-file-path" + service_level = "Premium" + subnet_id = "${azurerm_subnet.example.id}" + storage_quota_in_gb = 100 +} + +resource "azurerm_netapp_snapshot" "example" { + name = "${var.prefix}-netappsnapshot" + account_name = "${azurerm_netapp_account.example.name}" + pool_name = "${azurerm_netapp_pool.example.name}" + volume_name = "${azurerm_netapp_volume.example.name}" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" +} diff --git a/examples/netapp/snapshot/variables.tf b/examples/netapp/snapshot/variables.tf new file mode 100644 index 000000000000..f6ace0ff7d0a --- /dev/null +++ b/examples/netapp/snapshot/variables.tf @@ -0,0 +1,7 @@ +variable "location" { + description = "The Azure location where all resources in this example should be created." +} + +variable "prefix" { + description = "The prefix used for all resources used by this NetApp Snapshot" +} diff --git a/website/azurerm.erb b/website/azurerm.erb index 42c01b5ff468..ad6b83f0c2e8 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -310,6 +310,10 @@ azurerm_netapp_volume +
  • + azurerm_netapp_snapshot +
  • +
  • azurerm_platform_image
  • @@ -1804,6 +1808,10 @@
  • azurerm_netapp_volume
  • + +
  • + azurerm_netapp_snapshot +
  • diff --git a/website/docs/d/netapp_snapshot.html.markdown b/website/docs/d/netapp_snapshot.html.markdown new file mode 100644 index 000000000000..6ccb7984e9de --- /dev/null +++ b/website/docs/d/netapp_snapshot.html.markdown @@ -0,0 +1,48 @@ +--- +subcategory: "NetApp" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_netapp_snapshot" +sidebar_current: "docs-azurerm-datasource-netapp-snapshot" +description: |- +Gets information about an existing NetApp Snapshot +--- + +# Data Source: azurerm_netapp_snapshot + +Uses this data source to access information about an existing NetApp Snapshot. + +## NetApp Snapshot Usage + +```hcl +data "azurerm_netapp_snapshot" "test" { + resource_group_name = "acctestRG" + name = "acctestnetappsnapshot" + account_name = "acctestnetappaccount" + pool_name = "acctestnetapppool" + volume_name = "acctestnetappvolume" +} + +output "netapp_snapshot_id" { + value = "${data.azurerm_netapp_snapshot.example.id}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the NetApp Snapshot. + +* `account_name` - (Required) The name of the NetApp Account where the NetApp Pool exists. + +* `pool_name` - (Required) The name of the NetApp Pool where the NetApp Volume exists. + +* `volume_name` - (Required) The name of the NetApp Volume where the NetApp Snapshot exists. + +* `resource_group_name` - (Required) The Name of the Resource Group where the NetApp Snapshot exists. + +## Attributes Reference + +The following attributes are exported: + +* `location` - The Azure Region where the NetApp Snapshot exists. diff --git a/website/docs/r/netapp_snapshot.html.markdown b/website/docs/r/netapp_snapshot.html.markdown new file mode 100644 index 000000000000..08c3cf8c0829 --- /dev/null +++ b/website/docs/r/netapp_snapshot.html.markdown @@ -0,0 +1,112 @@ +--- +subcategory: "NetApp" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_netapp_snapshot" +sidebar_current: "docs-azurerm-resource-netapp-snapshot" +description: |- + Manages a NetApp Snapshot. +--- + +# azurerm_netapp_snapshot + +Manages a NetApp Snapshot. + +## NetApp Snapshot Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_virtual_network" "example" { + name = "example-virtualnetwork" + address_space = ["10.0.0.0/16"] + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" +} + +resource "azurerm_subnet" "example" { + name = "example-subnet" + resource_group_name = "${azurerm_resource_group.example.name}" + virtual_network_name = "${azurerm_virtual_network.example.name}" + address_prefix = "10.0.2.0/24" + + delegation { + name = "netapp" + + service_delegation { + name = "Microsoft.Netapp/volumes" + actions = ["Microsoft.Network/networkinterfaces/*", "Microsoft.Network/virtualNetworks/subnets/join/action"] + } + } +} + +resource "azurerm_netapp_account" "example" { + name = "example-netappaccount" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" +} + +resource "azurerm_netapp_pool" "example" { + name = "example-netapppool" + account_name = "${azurerm_netapp_account.example.name}" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + service_level = "Premium" + size_in_tb = "4" +} + +resource "azurerm_netapp_volume" "example" { + name = "example-netappvolume" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + account_name = "${azurerm_netapp_account.example.name}" + pool_name = "${azurerm_netapp_pool.example.name}" + volume_path = "my-unique-file-path" + service_level = "Premium" + subnet_id = "${azurerm_subnet.test.id}" + storage_quota_in_gb = "100" +} + +resource "azurerm_netapp_snapshot" "example" { + name = "example-netappsnapshot" + account_name = "${azurerm_netapp_account.example.name}" + pool_name = "${azurerm_netapp_pool.example.name}" + volume_name = "${azurerm_netapp_volume.example.name}" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the NetApp Snapshot. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group where the NetApp Snapshot should be created. Changing this forces a new resource to be created. + +* `account_name` - (Required) The name of the NetApp account in which the NetApp Pool should be created. Changing this forces a new resource to be created. + +* `pool_name` - (Required) The name of the NetApp pool in which the NetApp Volume should be created. Changing this forces a new resource to be created. + +* `volume_name` - (Required) The name of the NetApp volume in which the NetApp Snapshot should be created. Changing this forces a new resource to be created. + +* `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. + +--- + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the NetApp Snapshot. + +## Import + +NetApp Snapshot can be imported using the `resource id`, e.g. + +```shell +$ terraform import azurerm_netapp_snapshot.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.NetApp/netAppAccounts/account1/capacityPools/pool1/volumes/volume1/snapshots/snapshot1 +``` \ No newline at end of file From 4425ac056588d08da7579f4e21282a6e7f6ab466 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 17:24:14 -0800 Subject: [PATCH 173/203] Update CHANGELOG.md to include #5215 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e23bebee7252..bdaee4d873b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 1.40.0 (Unreleased) * **New Data Source:** `azurerm_netapp_volume` [GH-4933] +* **New Data Source:** `azurerm_netapp_snapshot` [GH-5215] * **New Resource:** `azurerm_advanced_threat_protection` [GH-4848] * **New Resource:** `azurerm_api_management_diagnostic ` [GH-4836] * **New Resource:** `azurerm_automation_certificate` [GH-4785] @@ -10,6 +11,7 @@ * **New Resource:** `azurerm_iothub_dps_shared_access_policy` [GH-5171] * **New Resource:** `azurerm_network_watcher_flow_log` [GH-5059] * **New Resource:** `azurerm_netapp_volume` [GH-4933] +* **New Resource:** `azurerm_netapp_snapshot` [GH-5215] * **New Resource:** `azurerm_stream_analytics_reference_input_blob` [GH-3633] * **New Resource:** `azurerm_app_service_virtual_network_swift_connection` [GH-5214] From 3da46fadd102cc47e539b936493c8d53f737032f Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Wed, 25 Dec 2019 17:51:50 -0800 Subject: [PATCH 174/203] New Resource: `azurerm_kusto_database_principal` (#5242) Addresses #4414 --- .../internal/services/kusto/registration.go | 1 + .../resource_arm_kusto_database_principal.go | 324 ++++++++++++++++++ ...ource_arm_kusto_database_principal_test.go | 168 +++++++++ website/azurerm.erb | 3 + .../r/kusto_database_principal.html.markdown | 97 ++++++ 5 files changed, 593 insertions(+) create mode 100644 azurerm/internal/services/kusto/resource_arm_kusto_database_principal.go create mode 100644 azurerm/internal/services/kusto/tests/resource_arm_kusto_database_principal_test.go create mode 100644 website/docs/r/kusto_database_principal.html.markdown diff --git a/azurerm/internal/services/kusto/registration.go b/azurerm/internal/services/kusto/registration.go index 805981e53a7a..7c6688bda6e9 100644 --- a/azurerm/internal/services/kusto/registration.go +++ b/azurerm/internal/services/kusto/registration.go @@ -21,6 +21,7 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ "azurerm_kusto_cluster": resourceArmKustoCluster(), "azurerm_kusto_database": resourceArmKustoDatabase(), + "azurerm_kusto_database_principal": resourceArmKustoDatabasePrincipal(), "azurerm_kusto_eventhub_data_connection": resourceArmKustoEventHubDataConnection(), } } diff --git a/azurerm/internal/services/kusto/resource_arm_kusto_database_principal.go b/azurerm/internal/services/kusto/resource_arm_kusto_database_principal.go new file mode 100644 index 000000000000..157745a9dcfe --- /dev/null +++ b/azurerm/internal/services/kusto/resource_arm_kusto_database_principal.go @@ -0,0 +1,324 @@ +package kusto + +import ( + "fmt" + "log" + "strings" + "time" + + "github.com/Azure/azure-sdk-for-go/services/kusto/mgmt/2019-05-15/kusto" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmKustoDatabasePrincipal() *schema.Resource { + return &schema.Resource{ + Create: resourceArmKustoDatabasePrincipalCreate, + Read: resourceArmKustoDatabasePrincipalRead, + Delete: resourceArmKustoDatabasePrincipalDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(60 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(60 * time.Minute), + Delete: schema.DefaultTimeout(60 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "resource_group_name": azure.SchemaResourceGroupName(), + + "cluster_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateAzureRMKustoClusterName, + }, + + "database_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateAzureRMKustoDatabaseName, + }, + + "role": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(kusto.Admin), + string(kusto.Ingestor), + string(kusto.Monitor), + string(kusto.User), + string(kusto.UnrestrictedViewers), + string(kusto.Viewer), + }, false), + }, + + "type": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(kusto.DatabasePrincipalTypeApp), + string(kusto.DatabasePrincipalTypeGroup), + string(kusto.DatabasePrincipalTypeUser), + }, false), + }, + + "client_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "object_id": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "fully_qualified_name": { + Type: schema.TypeString, + Computed: true, + }, + + // These must be computed as the values passed in are overwritten by what the `fqn` returns. + // For more info: https://github.com/Azure/azure-sdk-for-go/issues/6547 + "name": { + Type: schema.TypeString, + Computed: true, + }, + + "email": { + Type: schema.TypeString, + Computed: true, + }, + + "app_id": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceArmKustoDatabasePrincipalCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Kusto.DatabasesClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + log.Printf("[INFO] preparing arguments for Azure Kusto Database Principal creation.") + + resourceGroup := d.Get("resource_group_name").(string) + clusterName := d.Get("cluster_name").(string) + databaseName := d.Get("database_name").(string) + role := d.Get("role").(string) + principalType := d.Get("type").(string) + + clientID := d.Get("client_id").(string) + objectID := d.Get("object_id").(string) + fqn := "" + if principalType == "User" { + fqn = fmt.Sprintf("aaduser=%s;%s", objectID, clientID) + } else if principalType == "Group" { + fqn = fmt.Sprintf("aadgroup=%s;%s", objectID, clientID) + } else if principalType == "App" { + fqn = fmt.Sprintf("aadapp=%s;%s", objectID, clientID) + } + + database, err := client.Get(ctx, resourceGroup, clusterName, databaseName) + if err != nil { + if utils.ResponseWasNotFound(database.Response) { + return fmt.Errorf("Kusto Database %q (Resource Group %q) was not found", databaseName, resourceGroup) + } + + return fmt.Errorf("Error loading Kusto Database %q (Resource Group %q): %+v", databaseName, resourceGroup, err) + } + resourceId := fmt.Sprintf("%s/Role/%s/FQN/%s", *database.ID, role, fqn) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + resp, err := client.ListPrincipals(ctx, resourceGroup, clusterName, databaseName) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for presence of existing Kusto Database Principals (Resource Group %q, Cluster %q): %s", resourceGroup, clusterName, err) + } + } + + if principals := resp.Value; principals != nil { + for _, principal := range *principals { + // kusto database principals are unique when looked at with name and role + if string(principal.Role) == role && principal.Fqn != nil && *principal.Fqn == fqn { + return tf.ImportAsExistsError("azurerm_kusto_database_principal", resourceId) + } + } + } + } + + kustoPrincipal := kusto.DatabasePrincipal{ + Type: kusto.DatabasePrincipalType(principalType), + Role: kusto.DatabasePrincipalRole(role), + Fqn: utils.String(fqn), + // These three must be specified or the api returns `The request is invalid.` + // For more info: https://github.com/Azure/azure-sdk-for-go/issues/6547 + Email: utils.String(""), + AppID: utils.String(""), + Name: utils.String(""), + } + + principals := []kusto.DatabasePrincipal{kustoPrincipal} + request := kusto.DatabasePrincipalListRequest{ + Value: &principals, + } + + if _, err = client.AddPrincipals(ctx, resourceGroup, clusterName, databaseName, request); err != nil { + return fmt.Errorf("Error creating Kusto Database Principal (Resource Group %q, Cluster %q): %+v", resourceGroup, clusterName, err) + } + + resp, err := client.ListPrincipals(ctx, resourceGroup, clusterName, databaseName) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for presence of existing Kusto Database Principals (Resource Group %q, Cluster %q): %s", resourceGroup, clusterName, err) + } + } + + d.SetId(resourceId) + + return resourceArmKustoDatabasePrincipalRead(d, meta) +} + +func resourceArmKustoDatabasePrincipalRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Kusto.DatabasesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup := id.ResourceGroup + clusterName := id.Path["Clusters"] + databaseName := id.Path["Databases"] + role := id.Path["Role"] + fqn := id.Path["FQN"] + + databaseResponse, err := client.Get(ctx, resourceGroup, clusterName, databaseName) + if err != nil { + if utils.ResponseWasNotFound(databaseResponse.Response) { + d.SetId("") + return nil + } + return fmt.Errorf("Error retrieving Kusto Database %q (Resource Group %q, Cluster %q): %+v", databaseName, resourceGroup, clusterName, err) + } + + resp, err := client.ListPrincipals(ctx, resourceGroup, clusterName, databaseName) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Error checking for presence of existing Kusto Database Principals %q (Resource Group %q, Cluster %q): %s", id, resourceGroup, clusterName, err) + } + } + + principal := kusto.DatabasePrincipal{} + found := false + if principals := resp.Value; principals != nil { + for _, currPrincipal := range *principals { + // kusto database principals are unique when looked at with fqn and role + if string(currPrincipal.Role) == role && currPrincipal.Fqn != nil && *currPrincipal.Fqn == fqn { + principal = currPrincipal + found = true + break + } + } + } + + if !found { + log.Printf("[DEBUG] Kusto Database Principal %q was not found - removing from state", id) + d.SetId("") + return nil + } + + d.Set("resource_group_name", resourceGroup) + d.Set("cluster_name", clusterName) + d.Set("database_name", databaseName) + + d.Set("role", string(principal.Role)) + d.Set("type", string(principal.Type)) + if fqn := principal.Fqn; fqn != nil { + d.Set("fully_qualified_name", fqn) + } + if email := principal.Email; email != nil { + d.Set("email", email) + } + if appID := principal.AppID; appID != nil { + d.Set("app_id", appID) + } + if name := principal.Name; name != nil { + d.Set("name", principal.Name) + } + + splitFQN := strings.Split(fqn, "=") + if len(splitFQN) != 2 { + return fmt.Errorf("Expected `fqn` to be in the format aadtype=objectid:clientid but got: %q", fqn) + } + splitIDs := strings.Split(splitFQN[1], ";") + if len(splitIDs) != 2 { + return fmt.Errorf("Expected `fqn` to be in the format aadtype=objectid:clientid but got: %q", fqn) + } + d.Set("object_id", splitIDs[0]) + d.Set("client_id", splitIDs[1]) + + return nil +} + +func resourceArmKustoDatabasePrincipalDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Kusto.DatabasesClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resGroup := id.ResourceGroup + clusterName := id.Path["Clusters"] + databaseName := id.Path["Databases"] + role := id.Path["Role"] + fqn := id.Path["FQN"] + + kustoPrincipal := kusto.DatabasePrincipal{ + Role: kusto.DatabasePrincipalRole(role), + Fqn: utils.String(fqn), + Type: kusto.DatabasePrincipalType(d.Get("type").(string)), + // These three must be specified or the api returns `The request is invalid.` + // For more info: https://github.com/Azure/azure-sdk-for-go/issues/6547 + Name: utils.String(""), + Email: utils.String(""), + AppID: utils.String(""), + } + + principals := []kusto.DatabasePrincipal{kustoPrincipal} + request := kusto.DatabasePrincipalListRequest{ + Value: &principals, + } + + if _, err = client.RemovePrincipals(ctx, resGroup, clusterName, databaseName, request); err != nil { + return fmt.Errorf("Error deleting Kusto Database Principal %q (Resource Group %q, Cluster %q, Database %q): %+v", id, resGroup, clusterName, databaseName, err) + } + + return nil +} diff --git a/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_principal_test.go b/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_principal_test.go new file mode 100644 index 000000000000..99941605fd79 --- /dev/null +++ b/azurerm/internal/services/kusto/tests/resource_arm_kusto_database_principal_test.go @@ -0,0 +1,168 @@ +package tests + +import ( + "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/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMKustoDatabasePrincipal_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kusto_database_principal", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMKustoDatabasePrincipalDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMKustoDatabasePrincipal_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMKustoDatabasePrincipalExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMKustoDatabasePrincipalDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Kusto.DatabasesClient + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_kusto_database_principal" { + continue + } + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + clusterName := rs.Primary.Attributes["cluster_name"] + databaseName := rs.Primary.Attributes["database_name"] + role := rs.Primary.Attributes["role"] + fqn := rs.Primary.Attributes["fully_qualified_name"] + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + resp, err := client.ListPrincipals(ctx, resourceGroup, clusterName, databaseName) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return nil + } + return err + } + + found := false + if principals := resp.Value; principals != nil { + for _, currPrincipal := range *principals { + // kusto database principals are unique when looked at with fqn and role + if string(currPrincipal.Role) == role && currPrincipal.Fqn != nil && *currPrincipal.Fqn == fqn { + found = true + break + } + } + } + if found { + return fmt.Errorf("Kusto Database Principal %q still exists", fqn) + } + + return nil + } + + return nil +} + +func testCheckAzureRMKustoDatabasePrincipalExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + role := rs.Primary.Attributes["role"] + fqn := rs.Primary.Attributes["fully_qualified_name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Kusto Database Principal: %s", fqn) + } + + clusterName, hasClusterName := rs.Primary.Attributes["cluster_name"] + if !hasClusterName { + return fmt.Errorf("Bad: no cluster name found in state for Kusto Database Principal: %s", fqn) + } + + databaseName, hasDatabaseName := rs.Primary.Attributes["database_name"] + if !hasDatabaseName { + return fmt.Errorf("Bad: no database name found in state for Kusto Database Principal: %s", fqn) + } + + client := acceptance.AzureProvider.Meta().(*clients.Client).Kusto.DatabasesClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + resp, err := client.ListPrincipals(ctx, resourceGroup, clusterName, databaseName) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Kusto Database %q (resource group: %q, cluster: %q) does not exist", fqn, resourceGroup, clusterName) + } + + return fmt.Errorf("Bad: Get on DatabasesClient: %+v", err) + } + + found := false + if principals := resp.Value; principals != nil { + for _, currPrincipal := range *principals { + // kusto database principals are unique when looked at with fqn and role + if string(currPrincipal.Role) == role && currPrincipal.Fqn != nil && *currPrincipal.Fqn == fqn { + found = true + break + } + } + } + if !found { + return fmt.Errorf("Unable to find Kusto Database Principal %q", fqn) + } + + return nil + } +} + +func testAccAzureRMKustoDatabasePrincipal_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +data "azurerm_client_config" "current" {} + + +resource "azurerm_resource_group" "rg" { + name = "acctestRG-kusto-%d" + location = "%s" +} + +resource "azurerm_kusto_cluster" "cluster" { + name = "acctestkc%s" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + + sku { + name = "Dev(No SLA)_Standard_D11_v2" + capacity = 1 + } +} + +resource "azurerm_kusto_database" "test" { + name = "acctestkd-%d" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + cluster_name = azurerm_kusto_cluster.cluster.name +} + +resource "azurerm_kusto_database_principal" "test" { + resource_group_name = azurerm_resource_group.rg.name + cluster_name = azurerm_kusto_cluster.cluster.name + database_name = azurerm_kusto_database.test.name + + role = "Viewer" + type = "App" + client_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.client_id +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomInteger) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index ad6b83f0c2e8..f3506a70cbc4 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -1061,6 +1061,9 @@
  • azurerm_kusto_database
  • +
  • + azurerm_kusto_database_principal +
  • azurerm_kusto_eventhub_data_connection
  • diff --git a/website/docs/r/kusto_database_principal.html.markdown b/website/docs/r/kusto_database_principal.html.markdown new file mode 100644 index 000000000000..4d012b5a839c --- /dev/null +++ b/website/docs/r/kusto_database_principal.html.markdown @@ -0,0 +1,97 @@ +--- +subcategory: "Data Explorer" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_kusto_database_principal" +sidebar_current: "docs-azurerm-resource-kusto-database-principal" +description: |- + Manages Kusto / Data Explorer Database Principal +--- + +# azurerm_kusto_database_principal + +Manages a Kusto (also known as Azure Data Explorer) Database Principal + +## Example Usage + +```hcl +data "azurerm_client_config" "current" {} + +resource "azurerm_resource_group" "rg" { + name = "my-kusto-rg" + location = "East US" +} + +resource "azurerm_kusto_cluster" "cluster" { + name = "kustocluster" + location = "${azurerm_resource_group.rg.location}" + resource_group_name = "${azurerm_resource_group.rg.name}" + + sku { + name = "Standard_D13_v2" + capacity = 2 + } +} + +resource "azurerm_kusto_database" "database" { + name = "my-kusto-database" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + cluster_name = azurerm_kusto_cluster.cluster.name + + hot_cache_period = "P7D" + soft_delete_period = "P31D" +} + +resource "azurerm_kusto_database_principal" "principal" { + resource_group_name = azurerm_resource_group.rg.name + cluster_name = azurerm_kusto_cluster.cluster.name + database_name = azurerm_kusto_database.test.name + + role = "Viewer" + type = "User" + client_id = data.azurerm_client_config.current.tenant_id + object_id = data.azurerm_client_config.current.client_id +} +``` + +## Argument Reference + +The following arguments are supported: + +* `resource_group_name` - (Required) Specifies the Resource Group where the Kusto Database Principal should exist. Changing this forces a new resource to be created. + +* `cluster_name` - (Required) Specifies the name of the Kusto Cluster this database principal will be added to. Changing this forces a new resource to be created. + +* `database_name` - (Required) Specified the name of the Kusto Database this principal will be added to. Changing this forces a new resource to be created. + +* `role` - (Required) Specifies the permissions the Principal will have. Valid values include `Admin`, `Ingestor`, `Monitor`, `UnrestrictedViewers`, `User`, `Viewer`. Changing this forces a new resource to be created. + +* `type` - (Required) Specifies the type of object the principal is. Valid values include `App`, `Group`, `User`. Changing this forces a new resource to be created. + +* `object_id` - (Required) An Object ID of a User, Group, or App. Changing this forces a new resource to be created. + +* `client_id` - (Required) The Client ID that owns the specified `object_id`. Changing this forces a new resource to be created. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The Kusto Database Principal ID. + +* `app_id` - The app id, if not empty, of the principal. + +* `email` - The email, if not empty, of the principal. + +* `fully_qualified_name` - The fully qualified name of the principal. + +* `name` - The name of the Kusto Database Principal. + +--- + +## Import + +Kusto Database Principals can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_kusto_database_principal.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Kusto/Clusters/cluster1/Databases/database1/Role/role1/FQN/some-guid +``` From 622b6e8935c99ffb76d5fa17f6cdfd9393812434 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 17:52:41 -0800 Subject: [PATCH 175/203] Update CHANGELOG.md to include #5242 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdaee4d873b3..21cfb006c091 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * **New Resource:** `azurerm_backup_policy_file_share` [GH-5213] * **New Resource:** `azurerm_backup_protected_file_share` [GH-5213] * **New Resource:** `azurerm_iothub_dps_shared_access_policy` [GH-5171] +* **New Resource:** `azurerm_kusto_database_principal` [GH-5242] * **New Resource:** `azurerm_network_watcher_flow_log` [GH-5059] * **New Resource:** `azurerm_netapp_volume` [GH-4933] * **New Resource:** `azurerm_netapp_snapshot` [GH-5215] From 637d5e0619495ee46433ca1583073a92f58d07ed Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Thu, 26 Dec 2019 07:44:54 +0100 Subject: [PATCH 176/203] provider: omiting logging during acctests (#5241) --- azurerm/internal/provider/provider.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/azurerm/internal/provider/provider.go b/azurerm/internal/provider/provider.go index 8763fe8ec189..6b3f8e263a1f 100644 --- a/azurerm/internal/provider/provider.go +++ b/azurerm/internal/provider/provider.go @@ -22,6 +22,10 @@ func AzureProvider() terraform.ResourceProvider { return } + if os.Getenv("TF_ACC") != "" { + return + } + log.Printf(f, v...) } From 5f07128c56a185bf7cf3bd6f4e96078ad71eb47f Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 23 Dec 2019 11:15:53 -0800 Subject: [PATCH 177/203] attempt to fix travis 1 --- .golangci-travis-1.yml | 1 + .golangci-travis-2.yml | 1 - .travis.yml | 9 ++++----- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.golangci-travis-1.yml b/.golangci-travis-1.yml index f7111e28bea4..35a975914bc4 100644 --- a/.golangci-travis-1.yml +++ b/.golangci-travis-1.yml @@ -19,6 +19,7 @@ linters: - interfacer - nakedret - misspell + - structcheck linters-settings: errcheck: diff --git a/.golangci-travis-2.yml b/.golangci-travis-2.yml index cf8f407bdee4..b3a0f7bf1140 100644 --- a/.golangci-travis-2.yml +++ b/.golangci-travis-2.yml @@ -9,7 +9,6 @@ issues: linters: disable-all: true enable: - - structcheck - typecheck - unused - unconvert diff --git a/.travis.yml b/.travis.yml index c150d55d785c..4f6e0675bd8c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,11 +31,10 @@ matrix: script: GOGC=15 make lintstatic - name: "make linttravis1" script: GOGC=5 make lintrest1 - # TODO: fix/re-enable in a separate PR - #- name: "make linttravis2" - # script: GOGC=5 make lintrest2 - #- name: "make linttravis3" - # script: GOGC=5 make lintrest3 + - name: "make linttravis2" + script: GOGC=5 make lintrest2 + - name: "make linttravis3" + script: GOGC=5 make lintrest3 - name: "make tflint" script: make tflint - name: "make test" From cc33a3290def3fee38d54d3328216622345f884a Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 23 Dec 2019 12:05:14 -0800 Subject: [PATCH 178/203] attempt 2 --- .golangci-travis-1.yml | 1 + .golangci-travis-2.yml | 2 +- .golangci-travis-3.yml | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.golangci-travis-1.yml b/.golangci-travis-1.yml index 35a975914bc4..50c6f4d1e5bf 100644 --- a/.golangci-travis-1.yml +++ b/.golangci-travis-1.yml @@ -20,6 +20,7 @@ linters: - nakedret - misspell - structcheck + - typecheck linters-settings: errcheck: diff --git a/.golangci-travis-2.yml b/.golangci-travis-2.yml index b3a0f7bf1140..1d62d33a7cbe 100644 --- a/.golangci-travis-2.yml +++ b/.golangci-travis-2.yml @@ -9,9 +9,9 @@ issues: linters: disable-all: true enable: - - typecheck - unused - unconvert + - varcheck linters-settings: errcheck: diff --git a/.golangci-travis-3.yml b/.golangci-travis-3.yml index a4b929008ff9..4be75689bdf6 100644 --- a/.golangci-travis-3.yml +++ b/.golangci-travis-3.yml @@ -9,7 +9,6 @@ issues: linters: disable-all: true enable: - - varcheck - vet - vetshadow - whitespace From 650f3c63030e1abcca0deeec8f3f37157c8a5fda Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 23 Dec 2019 21:04:06 -0800 Subject: [PATCH 179/203] try 3 --- .golangci-travis-1.yml | 1 + .golangci-travis-2.yml | 2 +- .golangci-travis-3.yml | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.golangci-travis-1.yml b/.golangci-travis-1.yml index 50c6f4d1e5bf..52af1da4b130 100644 --- a/.golangci-travis-1.yml +++ b/.golangci-travis-1.yml @@ -21,6 +21,7 @@ linters: - misspell - structcheck - typecheck + - unused linters-settings: errcheck: diff --git a/.golangci-travis-2.yml b/.golangci-travis-2.yml index 1d62d33a7cbe..751dea9a15b7 100644 --- a/.golangci-travis-2.yml +++ b/.golangci-travis-2.yml @@ -9,9 +9,9 @@ issues: linters: disable-all: true enable: - - unused - unconvert - varcheck + - vet linters-settings: errcheck: diff --git a/.golangci-travis-3.yml b/.golangci-travis-3.yml index 4be75689bdf6..aaafab29c01f 100644 --- a/.golangci-travis-3.yml +++ b/.golangci-travis-3.yml @@ -9,7 +9,6 @@ issues: linters: disable-all: true enable: - - vet - vetshadow - whitespace From a391ec97924c7b69f03440fb81fda66fdca9382b Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 24 Dec 2019 08:25:31 -0800 Subject: [PATCH 180/203] try 4 --- .golangci-travis-1.yml | 5 ----- .golangci-travis-2.yml | 8 +++++--- .golangci-travis-3.yml | 5 +++-- .golangci-travis-4.yml | 20 ++++++++++++++++++++ .travis.yml | 8 +++++--- GNUmakefile | 6 +++--- 6 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 .golangci-travis-4.yml diff --git a/.golangci-travis-1.yml b/.golangci-travis-1.yml index 52af1da4b130..1949dc88fad4 100644 --- a/.golangci-travis-1.yml +++ b/.golangci-travis-1.yml @@ -17,11 +17,6 @@ linters: - govet - ineffassign - interfacer - - nakedret - - misspell - - structcheck - - typecheck - - unused linters-settings: errcheck: diff --git a/.golangci-travis-2.yml b/.golangci-travis-2.yml index 751dea9a15b7..1d42ad11ad06 100644 --- a/.golangci-travis-2.yml +++ b/.golangci-travis-2.yml @@ -9,9 +9,11 @@ issues: linters: disable-all: true enable: - - unconvert - - varcheck - - vet + - nakedret + - misspell + - structcheck + - typecheck + - unused linters-settings: errcheck: diff --git a/.golangci-travis-3.yml b/.golangci-travis-3.yml index aaafab29c01f..751dea9a15b7 100644 --- a/.golangci-travis-3.yml +++ b/.golangci-travis-3.yml @@ -9,8 +9,9 @@ issues: linters: disable-all: true enable: - - vetshadow - - whitespace + - unconvert + - varcheck + - vet linters-settings: errcheck: diff --git a/.golangci-travis-4.yml b/.golangci-travis-4.yml new file mode 100644 index 000000000000..aaafab29c01f --- /dev/null +++ b/.golangci-travis-4.yml @@ -0,0 +1,20 @@ +run: + deadline: 30m10s + modules-download-mode: vendor + +issues: + max-per-linter: 0 + max-same-issues: 0 + +linters: + disable-all: true + enable: + - vetshadow + - whitespace + +linters-settings: + errcheck: + ignore: github.com/hashicorp/terraform-plugin-sdk/helper/schema:ForceNew|Set,fmt:.*,io:Close + misspell: + ignore-words: + - hdinsight diff --git a/.travis.yml b/.travis.yml index 4f6e0675bd8c..cdcb5f53b27b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,11 +30,13 @@ matrix: - name: "make lintstatic" script: GOGC=15 make lintstatic - name: "make linttravis1" - script: GOGC=5 make lintrest1 + script: GOGC=5 make linttravis1 - name: "make linttravis2" - script: GOGC=5 make lintrest2 + script: GOGC=5 make linttravis2 - name: "make linttravis3" - script: GOGC=5 make lintrest3 + script: GOGC=5 make linttravis3 + - name: "make linttravis4" + script: GOGC=5 make linttravis4 - name: "make tflint" script: make tflint - name: "make test" diff --git a/GNUmakefile b/GNUmakefile index 3e35cfac1f61..a5fc8fe87377 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -47,17 +47,17 @@ lintstatic: (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ golangci-lint run ./... -v --no-config --concurrency 1 --deadline=30m10s --disable-all --enable=staticcheck; ES=$$?; kill -9 $$PID; exit $$ES -lintrest1: +linttravis1: @echo "==> Checking source code against linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis-1.yml ; ES=$$?; kill -9 $$PID; exit $$ES -lintrest2: +linttravis2: @echo "==> Checking source code against linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis-2.yml ; ES=$$?; kill -9 $$PID; exit $$ES -lintrest3: +linttravis3: @echo "==> Checking source code against linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis-2.yml ; ES=$$?; kill -9 $$PID; exit $$ES From 2ced912013c97f4243a7d32d89fed3564fbdba59 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 24 Dec 2019 08:56:39 -0800 Subject: [PATCH 181/203] try again --- .travis.yml | 2 -- .golangci-travis-1.yml => .travis/.golangci-travis-1.yml | 4 ++++ .golangci-travis-2.yml => .travis/.golangci-travis-2.yml | 6 ++---- .golangci-travis-3.yml => .travis/.golangci-travis-3.yml | 4 ++-- .golangci-travis-4.yml => .travis/.golangci-travis-4.yml | 3 +-- GNUmakefile | 7 ++++--- 6 files changed, 13 insertions(+), 13 deletions(-) rename .golangci-travis-1.yml => .travis/.golangci-travis-1.yml (87%) rename .golangci-travis-2.yml => .travis/.golangci-travis-2.yml (83%) rename .golangci-travis-3.yml => .travis/.golangci-travis-3.yml (90%) rename .golangci-travis-4.yml => .travis/.golangci-travis-4.yml (90%) diff --git a/.travis.yml b/.travis.yml index cdcb5f53b27b..fb9e3b3fdcf1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,8 +35,6 @@ matrix: script: GOGC=5 make linttravis2 - name: "make linttravis3" script: GOGC=5 make linttravis3 - - name: "make linttravis4" - script: GOGC=5 make linttravis4 - name: "make tflint" script: make tflint - name: "make test" diff --git a/.golangci-travis-1.yml b/.travis/.golangci-travis-1.yml similarity index 87% rename from .golangci-travis-1.yml rename to .travis/.golangci-travis-1.yml index 1949dc88fad4..50c6f4d1e5bf 100644 --- a/.golangci-travis-1.yml +++ b/.travis/.golangci-travis-1.yml @@ -17,6 +17,10 @@ linters: - govet - ineffassign - interfacer + - nakedret + - misspell + - structcheck + - typecheck linters-settings: errcheck: diff --git a/.golangci-travis-2.yml b/.travis/.golangci-travis-2.yml similarity index 83% rename from .golangci-travis-2.yml rename to .travis/.golangci-travis-2.yml index 1d42ad11ad06..1d62d33a7cbe 100644 --- a/.golangci-travis-2.yml +++ b/.travis/.golangci-travis-2.yml @@ -9,11 +9,9 @@ issues: linters: disable-all: true enable: - - nakedret - - misspell - - structcheck - - typecheck - unused + - unconvert + - varcheck linters-settings: errcheck: diff --git a/.golangci-travis-3.yml b/.travis/.golangci-travis-3.yml similarity index 90% rename from .golangci-travis-3.yml rename to .travis/.golangci-travis-3.yml index 751dea9a15b7..4be75689bdf6 100644 --- a/.golangci-travis-3.yml +++ b/.travis/.golangci-travis-3.yml @@ -9,9 +9,9 @@ issues: linters: disable-all: true enable: - - unconvert - - varcheck - vet + - vetshadow + - whitespace linters-settings: errcheck: diff --git a/.golangci-travis-4.yml b/.travis/.golangci-travis-4.yml similarity index 90% rename from .golangci-travis-4.yml rename to .travis/.golangci-travis-4.yml index aaafab29c01f..4fd20a85bb66 100644 --- a/.golangci-travis-4.yml +++ b/.travis/.golangci-travis-4.yml @@ -9,8 +9,7 @@ issues: linters: disable-all: true enable: - - vetshadow - - whitespace + linters-settings: errcheck: diff --git a/GNUmakefile b/GNUmakefile index a5fc8fe87377..628113ac31cf 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -50,17 +50,18 @@ lintstatic: linttravis1: @echo "==> Checking source code against linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ - golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis-1.yml ; ES=$$?; kill -9 $$PID; exit $$ES + golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .travis/.golangci-travis-1.yml ; ES=$$?; kill -9 $$PID; exit $$ES linttravis2: @echo "==> Checking source code against linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ - golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis-2.yml ; ES=$$?; kill -9 $$PID; exit $$ES + golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .travis/.golangci-travis-2.yml ; ES=$$?; kill -9 $$PID; exit $$ES linttravis3: @echo "==> Checking source code against linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ - golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis-2.yml ; ES=$$?; kill -9 $$PID; exit $$ES + golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .travis/.golangci-travis-3.yml ; ES=$$?; kill -9 $$PID; exit $$ES + tflint: @echo "==> Checking source code against terraform provider linters..." From 61934e625ab7a92e598912ac7493fe42c001fd67 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 24 Dec 2019 09:28:24 -0800 Subject: [PATCH 182/203] try again --- .travis/.golangci-travis-2.yml | 1 - .travis/.golangci-travis-3.yml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/.golangci-travis-2.yml b/.travis/.golangci-travis-2.yml index 1d62d33a7cbe..9a97ced993f3 100644 --- a/.travis/.golangci-travis-2.yml +++ b/.travis/.golangci-travis-2.yml @@ -11,7 +11,6 @@ linters: enable: - unused - unconvert - - varcheck linters-settings: errcheck: diff --git a/.travis/.golangci-travis-3.yml b/.travis/.golangci-travis-3.yml index 4be75689bdf6..a4b929008ff9 100644 --- a/.travis/.golangci-travis-3.yml +++ b/.travis/.golangci-travis-3.yml @@ -9,6 +9,7 @@ issues: linters: disable-all: true enable: + - varcheck - vet - vetshadow - whitespace From 71e0b55719f0d8fd3baaffee5d36ad929c65e210 Mon Sep 17 00:00:00 2001 From: kt Date: Tue, 24 Dec 2019 23:04:59 -0800 Subject: [PATCH 183/203] try again --- .travis/.golangci-travis-2.yml | 1 - .travis/.golangci-travis-3.yml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis/.golangci-travis-2.yml b/.travis/.golangci-travis-2.yml index 9a97ced993f3..5327dd671109 100644 --- a/.travis/.golangci-travis-2.yml +++ b/.travis/.golangci-travis-2.yml @@ -10,7 +10,6 @@ linters: disable-all: true enable: - unused - - unconvert linters-settings: errcheck: diff --git a/.travis/.golangci-travis-3.yml b/.travis/.golangci-travis-3.yml index a4b929008ff9..b27c50189ed3 100644 --- a/.travis/.golangci-travis-3.yml +++ b/.travis/.golangci-travis-3.yml @@ -9,6 +9,7 @@ issues: linters: disable-all: true enable: + - unconvert - varcheck - vet - vetshadow From dbc83cbd30df678d51bb1e25cf4ba11620514d41 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 05:52:23 -0800 Subject: [PATCH 184/203] try again --- .travis/.golangci-travis-1.yml | 5 +++++ .travis/.golangci-travis-3.yml | 6 +----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.travis/.golangci-travis-1.yml b/.travis/.golangci-travis-1.yml index 50c6f4d1e5bf..464ac388ebb5 100644 --- a/.travis/.golangci-travis-1.yml +++ b/.travis/.golangci-travis-1.yml @@ -21,6 +21,11 @@ linters: - misspell - structcheck - typecheck + - unconvert + - varcheck + - vet + - vetshadow + - whitespace linters-settings: errcheck: diff --git a/.travis/.golangci-travis-3.yml b/.travis/.golangci-travis-3.yml index b27c50189ed3..4fd20a85bb66 100644 --- a/.travis/.golangci-travis-3.yml +++ b/.travis/.golangci-travis-3.yml @@ -9,11 +9,7 @@ issues: linters: disable-all: true enable: - - unconvert - - varcheck - - vet - - vetshadow - - whitespace + linters-settings: errcheck: From c6e146ecb1cc86c19ab0c1ea8d6e804045dceec4 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 11:52:42 -0800 Subject: [PATCH 185/203] try try try again --- ...angci-travis-1.yml => .golangci-travis.yml | 0 .travis.yml | 8 +++----- .travis/.golangci-travis-2.yml | 19 ------------------- .travis/.golangci-travis-3.yml | 19 ------------------- .travis/.golangci-travis-4.yml | 19 ------------------- GNUmakefile | 16 +++++----------- 6 files changed, 8 insertions(+), 73 deletions(-) rename .travis/.golangci-travis-1.yml => .golangci-travis.yml (100%) delete mode 100644 .travis/.golangci-travis-2.yml delete mode 100644 .travis/.golangci-travis-3.yml delete mode 100644 .travis/.golangci-travis-4.yml diff --git a/.travis/.golangci-travis-1.yml b/.golangci-travis.yml similarity index 100% rename from .travis/.golangci-travis-1.yml rename to .golangci-travis.yml diff --git a/.travis.yml b/.travis.yml index fb9e3b3fdcf1..67a737f6ebcd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,12 +29,10 @@ matrix: include: - name: "make lintstatic" script: GOGC=15 make lintstatic - - name: "make linttravis1" - script: GOGC=5 make linttravis1 - - name: "make linttravis2" + - name: "make lintunused" + script: GOGC=2 make unused + - name: "make lintrest" script: GOGC=5 make linttravis2 - - name: "make linttravis3" - script: GOGC=5 make linttravis3 - name: "make tflint" script: make tflint - name: "make test" diff --git a/.travis/.golangci-travis-2.yml b/.travis/.golangci-travis-2.yml deleted file mode 100644 index 5327dd671109..000000000000 --- a/.travis/.golangci-travis-2.yml +++ /dev/null @@ -1,19 +0,0 @@ -run: - deadline: 30m10s - modules-download-mode: vendor - -issues: - max-per-linter: 0 - max-same-issues: 0 - -linters: - disable-all: true - enable: - - unused - -linters-settings: - errcheck: - ignore: github.com/hashicorp/terraform-plugin-sdk/helper/schema:ForceNew|Set,fmt:.*,io:Close - misspell: - ignore-words: - - hdinsight diff --git a/.travis/.golangci-travis-3.yml b/.travis/.golangci-travis-3.yml deleted file mode 100644 index 4fd20a85bb66..000000000000 --- a/.travis/.golangci-travis-3.yml +++ /dev/null @@ -1,19 +0,0 @@ -run: - deadline: 30m10s - modules-download-mode: vendor - -issues: - max-per-linter: 0 - max-same-issues: 0 - -linters: - disable-all: true - enable: - - -linters-settings: - errcheck: - ignore: github.com/hashicorp/terraform-plugin-sdk/helper/schema:ForceNew|Set,fmt:.*,io:Close - misspell: - ignore-words: - - hdinsight diff --git a/.travis/.golangci-travis-4.yml b/.travis/.golangci-travis-4.yml deleted file mode 100644 index 4fd20a85bb66..000000000000 --- a/.travis/.golangci-travis-4.yml +++ /dev/null @@ -1,19 +0,0 @@ -run: - deadline: 30m10s - modules-download-mode: vendor - -issues: - max-per-linter: 0 - max-same-issues: 0 - -linters: - disable-all: true - enable: - - -linters-settings: - errcheck: - ignore: github.com/hashicorp/terraform-plugin-sdk/helper/schema:ForceNew|Set,fmt:.*,io:Close - misspell: - ignore-words: - - hdinsight diff --git a/GNUmakefile b/GNUmakefile index 628113ac31cf..312ee23a3ba2 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -47,21 +47,15 @@ lintstatic: (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ golangci-lint run ./... -v --no-config --concurrency 1 --deadline=30m10s --disable-all --enable=staticcheck; ES=$$?; kill -9 $$PID; exit $$ES -linttravis1: - @echo "==> Checking source code against linters..." - (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ - golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .travis/.golangci-travis-1.yml ; ES=$$?; kill -9 $$PID; exit $$ES - -linttravis2: - @echo "==> Checking source code against linters..." +lintunused: + @echo "==> Checking source code against static check linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ - golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .travis/.golangci-travis-2.yml ; ES=$$?; kill -9 $$PID; exit $$ES + golangci-lint run ./... -v --no-config --concurrency 1 --deadline=30m10s --disable-all --enable=unused; ES=$$?; kill -9 $$PID; exit $$ES -linttravis3: +lintrest: @echo "==> Checking source code against linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ - golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .travis/.golangci-travis-3.yml ; ES=$$?; kill -9 $$PID; exit $$ES - + golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .travis/.golangci-rest.yml ; ES=$$?; kill -9 $$PID; exit $$ES tflint: @echo "==> Checking source code against terraform provider linters..." From f06504e42a4f392fba87be5b6c2b5ef91abf0e91 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 14:13:24 -0800 Subject: [PATCH 186/203] removed unused linter --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 67a737f6ebcd..bd032b074c37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,10 +29,8 @@ matrix: include: - name: "make lintstatic" script: GOGC=15 make lintstatic - - name: "make lintunused" - script: GOGC=2 make unused - name: "make lintrest" - script: GOGC=5 make linttravis2 + script: GOGC=5 make lintrest - name: "make tflint" script: make tflint - name: "make test" From f161e21f14445239275005f0c26560ea76baf8fe Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 15:11:09 -0800 Subject: [PATCH 187/203] fix cfg file path --- GNUmakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index 312ee23a3ba2..02a5ffa48623 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -55,7 +55,7 @@ lintunused: lintrest: @echo "==> Checking source code against linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ - golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .travis/.golangci-rest.yml ; ES=$$?; kill -9 $$PID; exit $$ES + golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis.yml ; ES=$$?; kill -9 $$PID; exit $$ES tflint: @echo "==> Checking source code against terraform provider linters..." From c744074cf77848f2617c0144e3cc4b0599720faa Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 15:39:12 -0800 Subject: [PATCH 188/203] fail build for info to open issue with --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index bd032b074c37..f04705c1e2eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,8 @@ matrix: script: GOGC=15 make lintstatic - name: "make lintrest" script: GOGC=5 make lintrest + - name: "make lintrest" + script: GOGC=5 make lintunused - name: "make tflint" script: make tflint - name: "make test" From 4c3beb50f2b403cf3a41d173aa78677b320993c6 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 16:31:42 -0800 Subject: [PATCH 189/203] try including static check --- .golangci-travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci-travis.yml b/.golangci-travis.yml index 464ac388ebb5..874f1285756b 100644 --- a/.golangci-travis.yml +++ b/.golangci-travis.yml @@ -19,6 +19,7 @@ linters: - interfacer - nakedret - misspell + - staticcheck - structcheck - typecheck - unconvert From 294c6f63ff677288cd9ee456ff99b1680d5dc241 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 25 Dec 2019 17:06:51 -0800 Subject: [PATCH 190/203] remove seperate staticcheck linting --- .travis.yml | 7 +++---- GNUmakefile | 5 ----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index f04705c1e2eb..58760513e733 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,12 +27,11 @@ matrix: allow_failures: - go: tip include: - - name: "make lintstatic" - script: GOGC=15 make lintstatic - name: "make lintrest" script: GOGC=5 make lintrest - - name: "make lintrest" - script: GOGC=5 make lintunused + # results in a OOM error + #- name: "make lintunused" + # script: GOGC=5 make lintunused - name: "make tflint" script: make tflint - name: "make test" diff --git a/GNUmakefile b/GNUmakefile index 02a5ffa48623..c891ef37646a 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -42,11 +42,6 @@ lint: golangci-lint run ./... # we have split off static check because it causes travis to fail with an OOM error -lintstatic: - @echo "==> Checking source code against static check linters..." - (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ - golangci-lint run ./... -v --no-config --concurrency 1 --deadline=30m10s --disable-all --enable=staticcheck; ES=$$?; kill -9 $$PID; exit $$ES - lintunused: @echo "==> Checking source code against static check linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ From 76df86d3913f4b30e27680328b088662151f7d79 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 26 Dec 2019 09:42:24 -0800 Subject: [PATCH 191/203] increase golang-ci deadling to 60m --- .golangci-travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci-travis.yml b/.golangci-travis.yml index 874f1285756b..dafa580b4b5a 100644 --- a/.golangci-travis.yml +++ b/.golangci-travis.yml @@ -1,5 +1,5 @@ run: - deadline: 30m10s + deadline: 60m10s modules-download-mode: vendor issues: From b7e57b8b246599e9ae3f9ace5bfb55f65cbab92d Mon Sep 17 00:00:00 2001 From: SebRosander <32144528+SebRosander@users.noreply.github.com> Date: Fri, 27 Dec 2019 07:29:52 +0800 Subject: [PATCH 192/203] New Resource `azurerm_cosmosdb_gremlin_database` (#5248) Fixes some parts of #3692 and #4970 --- .../internal/services/cosmos/registration.go | 1 + .../resource_arm_cosmosdb_gremlin_database.go | 249 ++++++++++++++++++ ...urce_arm_cosmosdb_gremlin_database_test.go | 181 +++++++++++++ .../r/cosmosdb_gremlin_database.html.markdown | 55 ++++ 4 files changed, 486 insertions(+) create mode 100644 azurerm/internal/services/cosmos/resource_arm_cosmosdb_gremlin_database.go create mode 100644 azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_database_test.go create mode 100644 website/docs/r/cosmosdb_gremlin_database.html.markdown diff --git a/azurerm/internal/services/cosmos/registration.go b/azurerm/internal/services/cosmos/registration.go index ee333431573f..f6579c305d90 100644 --- a/azurerm/internal/services/cosmos/registration.go +++ b/azurerm/internal/services/cosmos/registration.go @@ -23,6 +23,7 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { return map[string]*schema.Resource{ "azurerm_cosmosdb_account": resourceArmCosmosDbAccount(), "azurerm_cosmosdb_cassandra_keyspace": resourceArmCosmosDbCassandraKeyspace(), + "azurerm_cosmosdb_gremlin_database": resourceArmCosmosGremlinDatabase(), "azurerm_cosmosdb_mongo_collection": resourceArmCosmosDbMongoCollection(), "azurerm_cosmosdb_mongo_database": resourceArmCosmosDbMongoDatabase(), "azurerm_cosmosdb_sql_container": resourceArmCosmosDbSQLContainer(), diff --git a/azurerm/internal/services/cosmos/resource_arm_cosmosdb_gremlin_database.go b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_gremlin_database.go new file mode 100644 index 000000000000..bdabcaf2bb14 --- /dev/null +++ b/azurerm/internal/services/cosmos/resource_arm_cosmosdb_gremlin_database.go @@ -0,0 +1,249 @@ +package cosmos + +import ( + "fmt" + "log" + "strconv" + "time" + + "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb" + "github.com/hashicorp/go-azure-helpers/response" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmCosmosGremlinDatabase() *schema.Resource { + return &schema.Resource{ + Create: resourceArmCosmosGremlinDatabaseCreate, + Update: resourceArmCosmosGremlinDatabaseUpdate, + Read: resourceArmCosmosGremlinDatabaseRead, + Delete: resourceArmCosmosGremlinDatabaseDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CosmosEntityName, + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "account_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.CosmosAccountName, + }, + + "throughput": { + Type: schema.TypeInt, + Optional: true, + Computed: true, + ValidateFunc: validate.CosmosThroughput, + }, + }, + } +} + +func resourceArmCosmosGremlinDatabaseCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Cosmos.DatabaseClient + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + account := d.Get("account_name").(string) + + if features.ShouldResourcesBeImported() { + existing, err := client.GetGremlinDatabase(ctx, resourceGroup, account, name) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of creating Gremlin Database %s (Account %s): %+v", name, account, err) + } + } else { + id, err := azure.CosmosGetIDFromResponse(existing.Response) + if err != nil { + return fmt.Errorf("Error generating import ID for Cosmos Gremlin Database '%s' (Account %s)", name, account) + } + + return tf.ImportAsExistsError("azurerm_cosmosdb_gremlin_database", id) + } + } + + db := documentdb.GremlinDatabaseCreateUpdateParameters{ + GremlinDatabaseCreateUpdateProperties: &documentdb.GremlinDatabaseCreateUpdateProperties{ + Resource: &documentdb.GremlinDatabaseResource{ + ID: &name, + }, + Options: map[string]*string{}, + }, + } + + if throughput, hasThroughput := d.GetOk("throughput"); hasThroughput { + db.GremlinDatabaseCreateUpdateProperties.Options = map[string]*string{ + "throughput": utils.String(strconv.Itoa(throughput.(int))), + } + } + + future, err := client.CreateUpdateGremlinDatabase(ctx, resourceGroup, account, name, db) + if err != nil { + return fmt.Errorf("Error issuing create/update request for Gremlin Database %s (Account %s): %+v", name, account, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting on create/update future for Cosmos Gremlin Database %s (Account %s): %+v", name, account, err) + } + + resp, err := client.GetGremlinDatabase(ctx, resourceGroup, account, name) + if err != nil { + return fmt.Errorf("Error making get request for Cosmos Gremlin Database %s (Account %s) ID: %v", name, account, err) + } + + id, err := azure.CosmosGetIDFromResponse(resp.Response) + if err != nil { + return fmt.Errorf("Error retrieving the ID for Cosmos Gremlin Database '%s' (Account %s) ID: %v", name, account, err) + } + d.SetId(id) + + return resourceArmCosmosGremlinDatabaseRead(d, meta) +} + +func resourceArmCosmosGremlinDatabaseUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Cosmos.DatabaseClient + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseCosmosDatabaseID(d.Id()) + if err != nil { + return err + } + + db := documentdb.GremlinDatabaseCreateUpdateParameters{ + GremlinDatabaseCreateUpdateProperties: &documentdb.GremlinDatabaseCreateUpdateProperties{ + Resource: &documentdb.GremlinDatabaseResource{ + ID: &id.Database, + }, + Options: map[string]*string{}, + }, + } + + future, err := client.CreateUpdateGremlinDatabase(ctx, id.ResourceGroup, id.Account, id.Database, db) + if err != nil { + return fmt.Errorf("Error issuing create/update request for Cosmos Gremlin Database %s (Account %s): %+v", id.Database, id.Account, err) + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting on create/update future for Cosmos Gremlin Database %s (Account %s): %+v", id.Database, id.Account, err) + } + + if d.HasChange("throughput") { + throughputParameters := documentdb.ThroughputUpdateParameters{ + ThroughputUpdateProperties: &documentdb.ThroughputUpdateProperties{ + Resource: &documentdb.ThroughputResource{ + Throughput: utils.Int32(int32(d.Get("throughput").(int))), + }, + }, + } + + throughputFuture, err := client.UpdateGremlinDatabaseThroughput(ctx, id.ResourceGroup, id.Account, id.Database, throughputParameters) + if err != nil { + if response.WasNotFound(throughputFuture.Response()) { + return fmt.Errorf("Error setting Throughput for Cosmos Gremlin Database %s (Account %s): %+v - "+ + "If the collection has not been created with and initial throughput, you cannot configure it later.", id.Database, id.Account, err) + } + } + + if err = throughputFuture.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting on ThroughputUpdate future for Cosmos Gremlin Database %s (Account %s, Database %s): %+v", id.Database, id.Account, id.Database, err) + } + } + + if _, err = client.GetGremlinDatabase(ctx, id.ResourceGroup, id.Account, id.Database); err != nil { + return fmt.Errorf("Error making get request for Cosmos Gremlin Database %s (Account %s): %+v", id.Database, id.Account, err) + } + + return resourceArmCosmosGremlinDatabaseRead(d, meta) +} + +func resourceArmCosmosGremlinDatabaseRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Cosmos.DatabaseClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseCosmosDatabaseID(d.Id()) + if err != nil { + return err + } + + resp, err := client.GetGremlinDatabase(ctx, id.ResourceGroup, id.Account, id.Database) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[INFO] Error reading Cosmos Gremlin Database %s (Account %s) - removing from state", id.Database, id.Account) + d.SetId("") + return nil + } + + return fmt.Errorf("Error reading Cosmos Gremlin Database %s (Account %s): %+v", id.Database, id.Account, err) + } + + d.Set("resource_group_name", id.ResourceGroup) + d.Set("account_name", id.Account) + if props := resp.GremlinDatabaseProperties; props != nil { + d.Set("name", props.ID) + } + + throughputResp, err := client.GetGremlinDatabaseThroughput(ctx, id.ResourceGroup, id.Account, id.Database) + if err != nil { + if !utils.ResponseWasNotFound(throughputResp.Response) { + return fmt.Errorf("Error reading Throughput on Cosmos Gremlin Database %s (Account %s): %+v", id.Database, id.Account, err) + } else { + d.Set("throughput", nil) + } + } else { + d.Set("throughput", throughputResp.Throughput) + } + + return nil +} + +func resourceArmCosmosGremlinDatabaseDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Cosmos.DatabaseClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseCosmosDatabaseID(d.Id()) + if err != nil { + return err + } + + future, err := client.DeleteGremlinDatabase(ctx, id.ResourceGroup, id.Account, id.Database) + if err != nil { + if !response.WasNotFound(future.Response()) { + return fmt.Errorf("Error deleting Cosmos Gremlin Database %s (Account %s): %+v", id.Database, id.Account, err) + } + } + + if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { + return fmt.Errorf("Error waiting on delete future for Cosmos Gremlin Database %s (Account %s): %+v", id.Database, id.Account, err) + } + + return nil +} diff --git a/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_database_test.go b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_database_test.go new file mode 100644 index 000000000000..65fd940b64af --- /dev/null +++ b/azurerm/internal/services/cosmos/tests/resource_arm_cosmosdb_gremlin_database_test.go @@ -0,0 +1,181 @@ +package tests + +import ( + "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/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMCosmosGremlinDatabase_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_gremlin_database", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosGremlinDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosGremlinDatabase_basic(data), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMCosmosGremlinDatabaseExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMCosmosGremlinDatabase_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_gremlin_database", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosGremlinDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosGremlinDatabase_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMCosmosGremlinDatabaseExists(data.ResourceName), + ), + }, + { + Config: testAccAzureRMCosmosDatabase_requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_cosmosdb_gremlin_database"), + }, + }, + }) +} + +func TestAccAzureRMCosmosGremlinDatabase_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_gremlin_database", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMCosmosGremlinDatabaseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMCosmosGremlinDatabase_complete(data, 700), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMCosmosGremlinDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "700"), + ), + }, + data.ImportStep(), + { + Config: testAccAzureRMCosmosGremlinDatabase_complete(data, 1700), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMCosmosGremlinDatabaseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "throughput", "1700"), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMCosmosGremlinDatabaseDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Cosmos.DatabaseClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_cosmosdb_gremlin_database" { + continue + } + + name := rs.Primary.Attributes["name"] + account := rs.Primary.Attributes["account_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetGremlinDatabase(ctx, resourceGroup, account, name) + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Error checking destroy for Cosmos Gremlin Database %s (Account %s) still exists:\n%v", name, account, err) + } + } + + if !utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Cosmos Gremlin Database %s (Account %s): still exist:\n%#v", name, account, resp) + } + } + + return nil +} + +func testCheckAzureRMCosmosGremlinDatabaseExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).Cosmos.DatabaseClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + name := rs.Primary.Attributes["name"] + account := rs.Primary.Attributes["account_name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := client.GetGremlinDatabase(ctx, resourceGroup, account, name) + if err != nil { + return fmt.Errorf("Bad: Get on cosmosAccountsClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Cosmos database '%s' (Account: '%s') does not exist", name, account) + } + + return nil + } +} + +func testAccAzureRMCosmosGremlinDatabase_basic(data acceptance.TestData) string { + return fmt.Sprintf(` + %[1]s + + resource "azurerm_cosmosdb_gremlin_database" "test" { + name = "acctest-%[2]d" + resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" + account_name = "${azurerm_cosmosdb_account.test.name}" + } + `, testAccAzureRMCosmosDBAccount_capabilityGremlin(data), data.RandomInteger) +} + +func testAccAzureRMCosmosDatabase_requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` + %s + + resource "azurerm_cosmosdb_gremlin_database" "import" { + name = "${azurerm_cosmosdb_database.test.name}" + resource_group_name = "${azurerm_cosmosdb_database.test.name" + account_name = "${azurerm_cosmosdb_database.test.name}" + } + `, testAccAzureRMCosmosGremlinDatabase_basic(data)) +} + +func testAccAzureRMCosmosGremlinDatabase_complete(data acceptance.TestData, throughput int) string { + return fmt.Sprintf(` + %[1]s + + resource "azurerm_cosmosdb_gremlin_database" "test" { + name = "acctest-%[2]d" + resource_group_name = "${azurerm_cosmosdb_account.test.resource_group_name}" + account_name = "${azurerm_cosmosdb_account.test.name}" + throughput = %[3]d + } + `, testAccAzureRMCosmosDBAccount_capabilityGremlin(data), data.RandomInteger, throughput) +} diff --git a/website/docs/r/cosmosdb_gremlin_database.html.markdown b/website/docs/r/cosmosdb_gremlin_database.html.markdown new file mode 100644 index 000000000000..8141c720b3b1 --- /dev/null +++ b/website/docs/r/cosmosdb_gremlin_database.html.markdown @@ -0,0 +1,55 @@ +--- +subcategory: "CosmosDB (DocumentDB)" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_cosmosdb_gremlin_database" +sidebar_current: "docs-azurerm-resource-cosmosdb-gremlin-database" +description: |- + Manages a Gremlin Database within a Cosmos DB Account. +--- + +# azurerm_cosmosdb_gremlin_database + +Manages a Gremlin Database within a Cosmos DB Account. + +## Example Usage + +```hcl +data "azurerm_cosmosdb_account" "example" { + name = "tfex-cosmosdb-account" + resource_group_name = "tfex-cosmosdb-account-rg" +} + +resource "azurerm_cosmosdb_gremlin_database" "example" { + name = "tfex-cosmos-gremlin-db" + resource_group_name = "${data.azurerm_cosmosdb_account.example.resource_group_name}" + account_name = "${data.azurerm_cosmosdb_account.example.name}" + throughput = 400 +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Cosmos DB Gremlin Database. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the resource group in which the Cosmos DB Gremlin Database is created. Changing this forces a new resource to be created. + +* `account_name` - (Required) The name of the CosmosDB Account to create the Gremlin Database within. Changing this forces a new resource to be created. + +* `throughput` - (Optional) The throughput of the Gremlin database (RU/s). Must be set in increments of `100`. The minimum value is `400`. This must be set upon database creation otherwise it cannot be updated without a manual terraform destroy-apply. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - the Cosmos DB Gremlin Database ID. + +## Import + +Cosmos Mongo Database can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_cosmosdb_gremlin_database.db1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg1/providers/Microsoft.DocumentDB/databaseAccounts/account1/apis/gremlin/databases/db1 +``` From d0e21a95314bc568798e06895ce1417826cf9908 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 26 Dec 2019 15:30:28 -0800 Subject: [PATCH 193/203] Update CHANGELOG.md to include #5248 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21cfb006c091..41044dae27ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * **New Resource:** `azurerm_backup_container_storage_account` [GH-5213] * **New Resource:** `azurerm_backup_policy_file_share` [GH-5213] * **New Resource:** `azurerm_backup_protected_file_share` [GH-5213] +* **New Resource:** `azurerm_cosmosdb_gremlin_database` [GH-5248] * **New Resource:** `azurerm_iothub_dps_shared_access_policy` [GH-5171] * **New Resource:** `azurerm_kusto_database_principal` [GH-5242] * **New Resource:** `azurerm_network_watcher_flow_log` [GH-5059] From 16c2a2a9df120194099a6d04cffe4c11adae03ae Mon Sep 17 00:00:00 2001 From: arcturusZhang Date: Fri, 27 Dec 2019 14:18:43 +0800 Subject: [PATCH 194/203] Fix wrong doc items for nat-gateway --- website/docs/d/nat_gateway.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/nat_gateway.html.markdown b/website/docs/d/nat_gateway.html.markdown index 06d9d2d927d8..f231508b5381 100644 --- a/website/docs/d/nat_gateway.html.markdown +++ b/website/docs/d/nat_gateway.html.markdown @@ -17,7 +17,7 @@ Use this data source to access information about an existing NAT Gateway. The following arguments are supported: -* `name` - (Required) The Name of the Resource Group where the NAT Gateway exists. +* `name` - (Required) Specifies the Name of the NAT Gateway. * `resource_group_name` - (Required) Specifies the name of the Resource Group where the NAT Gateway exists. From 5f9cfbb977d4edca0724e3f002433a68e82fe37c Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 27 Dec 2019 09:51:32 -0800 Subject: [PATCH 195/203] remove concurancy argument from travis linting command so config file is used --- GNUmakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GNUmakefile b/GNUmakefile index c891ef37646a..29595cf0df6e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -50,7 +50,7 @@ lintunused: lintrest: @echo "==> Checking source code against linters..." (while true; do sleep 300; echo "(I'm still alive and linting!)"; done) & PID=$$!; echo $$PID; \ - golangci-lint run ./... -v --concurrency 1 --deadline=30m10s --config .golangci-travis.yml ; ES=$$?; kill -9 $$PID; exit $$ES + golangci-lint run ./... -v --concurrency 1 --config .golangci-travis.yml ; ES=$$?; kill -9 $$PID; exit $$ES tflint: @echo "==> Checking source code against terraform provider linters..." From ea1b1ef62058bddf24b3140585c9c5d7f801b7cf Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Sat, 28 Dec 2019 21:16:17 +0000 Subject: [PATCH 196/203] post-refactor: fixing a couple of test failures (#5267) * r/eventgrid_event_subscription: fixing TestAccAzureRMEventGridEventSubscription_basic * r/backup_policy_vm: fixing broken assertions * refactor: removing Location(), LocationAlt() and LocationAlt2() --- azurerm/internal/acceptance/data.go | 7 +- azurerm/internal/acceptance/deprecated.go | 18 -- ...rce_arm_container_registry_migrate_test.go | 9 +- .../data_source_cosmos_db_account_test.go | 8 +- ...e_arm_eventgrid_event_subscription_test.go | 7 - .../resource_arm_backup_policy_vm_test.go | 214 +++++++++--------- 6 files changed, 117 insertions(+), 146 deletions(-) delete mode 100644 azurerm/internal/acceptance/deprecated.go diff --git a/azurerm/internal/acceptance/data.go b/azurerm/internal/acceptance/data.go index c0b9df10df51..f46222fbe887 100644 --- a/azurerm/internal/acceptance/data.go +++ b/azurerm/internal/acceptance/data.go @@ -2,6 +2,7 @@ package acceptance import ( "fmt" + "os" "testing" "github.com/Azure/go-autorest/autorest/azure" @@ -73,9 +74,9 @@ func BuildTestData(t *testing.T, resourceType string, resourceLabel string) Test testData.Locations = availableLocations() } else { testData.Locations = Regions{ - Primary: Location(), - Secondary: AltLocation(), - Ternary: AltLocation2(), + Primary: os.Getenv("ARM_TEST_LOCATION"), + Secondary: os.Getenv("ARM_TEST_LOCATION_ALT"), + Ternary: os.Getenv("ARM_TEST_LOCATION_ALT2"), } } diff --git a/azurerm/internal/acceptance/deprecated.go b/azurerm/internal/acceptance/deprecated.go deleted file mode 100644 index 0028f206dc6d..000000000000 --- a/azurerm/internal/acceptance/deprecated.go +++ /dev/null @@ -1,18 +0,0 @@ -package acceptance - -import "os" - -// Functions in this file are provided for compatibility purposes - but will eventually be deprecated -// Developers should instead switch to using the `BuildTestData` method to obtain Test/Client Data - -func Location() string { - return os.Getenv("ARM_TEST_LOCATION") -} - -func AltLocation() string { - return os.Getenv("ARM_TEST_LOCATION_ALT") -} - -func AltLocation2() string { - return os.Getenv("ARM_TEST_LOCATION_ALT2") -} diff --git a/azurerm/internal/services/containers/tests/resource_arm_container_registry_migrate_test.go b/azurerm/internal/services/containers/tests/resource_arm_container_registry_migrate_test.go index 155dca266f74..bbb1d9945bf4 100644 --- a/azurerm/internal/services/containers/tests/resource_arm_container_registry_migrate_test.go +++ b/azurerm/internal/services/containers/tests/resource_arm_container_registry_migrate_test.go @@ -10,7 +10,6 @@ import ( "github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources" "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage" "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/hashicorp/terraform/helper/acctest" "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/clients" @@ -40,10 +39,10 @@ func TestAccAzureRMContainerRegistryMigrateState(t *testing.T) { client.StopContext = acceptance.AzureProvider.StopContext() - rs := acctest.RandString(7) - resourceGroupName := fmt.Sprintf("acctestRG%s", rs) - storageAccountName := fmt.Sprintf("acctestsa%s", rs) - location := azure.NormalizeLocation(acceptance.Location()) + data := acceptance.BuildTestData(t, "azurerm_container_registry", "test") + resourceGroupName := fmt.Sprintf("acctestRG%s", data.RandomString) + storageAccountName := fmt.Sprintf("acctestsa%s", data.RandomString) + location := azure.NormalizeLocation(data.Locations.Primary) ctx := client.StopContext err = createResourceGroup(ctx, client, resourceGroupName, location) diff --git a/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go b/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go index 70b3b1857ae6..e3194139bf92 100644 --- a/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go +++ b/azurerm/internal/services/cosmos/tests/data_source_cosmos_db_account_test.go @@ -41,8 +41,8 @@ func TestAccDataSourceAzureRMCosmosDBAccount_geoReplicated_customId(t *testing.T Config: testAccDataSourceAzureRMCosmosDBAccount_geoReplicated_customId(data), Check: resource.ComposeAggregateTestCheckFunc( checkAccAzureRMCosmosDBAccount_basic(data, string(documentdb.BoundedStaleness), 2), - resource.TestCheckResourceAttr(data.ResourceName, "geo_location.0.location", acceptance.Location()), - resource.TestCheckResourceAttr(data.ResourceName, "geo_location.1.location", acceptance.AltLocation()), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.0.location", data.Locations.Primary), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.1.location", data.Locations.Secondary), resource.TestCheckResourceAttr(data.ResourceName, "geo_location.0.failover_priority", "0"), resource.TestCheckResourceAttr(data.ResourceName, "geo_location.1.failover_priority", "1"), ), @@ -87,8 +87,8 @@ func TestAccDataSourceAzureRMCosmosDBAccount_complete(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "ip_range_filter", "104.42.195.92,40.76.54.131,52.176.6.30,52.169.50.45/32,52.187.184.26,10.20.0.0/16"), resource.TestCheckResourceAttr(data.ResourceName, "enable_automatic_failover", "true"), resource.TestCheckResourceAttr(data.ResourceName, "enable_multiple_write_locations", "false"), - resource.TestCheckResourceAttr(data.ResourceName, "geo_location.0.location", acceptance.Location()), - resource.TestCheckResourceAttr(data.ResourceName, "geo_location.1.location", acceptance.AltLocation()), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.0.location", data.Locations.Primary), + resource.TestCheckResourceAttr(data.ResourceName, "geo_location.1.location", data.Locations.Secondary), resource.TestCheckResourceAttr(data.ResourceName, "geo_location.0.failover_priority", "0"), resource.TestCheckResourceAttr(data.ResourceName, "geo_location.1.failover_priority", "1"), ), diff --git a/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go index 9b1aa9c282a6..b612011ad31d 100644 --- a/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go +++ b/azurerm/internal/services/eventgrid/tests/resource_arm_eventgrid_event_subscription_test.go @@ -25,13 +25,6 @@ func TestAccAzureRMEventGridEventSubscription_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMEventGridEventSubscriptionExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "event_delivery_schema", "EventGridSchema"), - resource.TestCheckResourceAttr(data.ResourceName, "storage_queue_endpoint.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "storage_blob_dead_letter_destination.#", "1"), - resource.TestCheckResourceAttr(data.ResourceName, "included_event_types.0", "All"), - resource.TestCheckResourceAttr(data.ResourceName, "retry_policy.0.max_delivery_attempts", "11"), - resource.TestCheckResourceAttr(data.ResourceName, "retry_policy.0.event_time_to_live", "11"), - resource.TestCheckResourceAttr(data.ResourceName, "labels.0", "test"), - resource.TestCheckResourceAttr(data.ResourceName, "labels.2", "test2"), ), }, data.ImportStep(), diff --git a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go index 00f32459ed68..58b1bc205bd0 100644 --- a/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go +++ b/azurerm/internal/services/recoveryservices/tests/resource_arm_backup_policy_vm_test.go @@ -22,7 +22,12 @@ func TestAccAzureRMBackupProtectionPolicyVM_basicDaily(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.frequency", "Daily"), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.time", "23:00"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_daily.0.count", "10"), + ), }, data.ImportStep(), }, @@ -44,7 +49,9 @@ func TestAccAzureRMBackupProtectionPolicyVM_requiresImport(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + ), }, data.RequiresImportErrorStep(testAccAzureRMBackupProtectionPolicyVM_requiresImport), }, @@ -61,7 +68,9 @@ func TestAccAzureRMBackupProtectionPolicyVM_basicWeekly(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + ), }, data.ImportStep(), }, @@ -78,7 +87,9 @@ func TestAccAzureRMBackupProtectionPolicyVM_completeDaily(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAzureRMBackupProtectionPolicyVM_completeDaily(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeDaily(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + ), }, data.ImportStep(), }, @@ -95,7 +106,21 @@ func TestAccAzureRMBackupProtectionPolicyVM_completeWeekly(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAzureRMBackupProtectionPolicyVM_completeWeekly(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.frequency", "Weekly"), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.time", "23:00"), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.weekdays.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_weekly.0.count", "42"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_weekly.0.weekdays.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.count", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.weekdays.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.weeks.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.count", "77"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.weekdays.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.weeks.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.months.#", "2"), + ), }, data.ImportStep(), }, @@ -112,11 +137,27 @@ func TestAccAzureRMBackupProtectionPolicyVM_updateDaily(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + ), }, { Config: testAccAzureRMBackupProtectionPolicyVM_completeDaily(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeDaily(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.frequency", "Daily"), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.time", "23:00"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_daily.0.count", "10"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_weekly.0.count", "42"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_weekly.0.weekdays.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.count", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.weekdays.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.weeks.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.count", "77"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.weekdays.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.weeks.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.months.#", "2"), + ), }, data.ImportStep(), }, @@ -133,11 +174,27 @@ func TestAccAzureRMBackupProtectionPolicyVM_updateWeekly(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + ), }, { Config: testAccAzureRMBackupProtectionPolicyVM_completeWeekly(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.frequency", "Weekly"), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.time", "23:00"), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.weekdays.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_weekly.0.count", "42"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_weekly.0.weekdays.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.count", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.weekdays.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.weeks.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.count", "77"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.weekdays.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.weeks.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.months.#", "2"), + ), }, data.ImportStep(), }, @@ -154,11 +211,16 @@ func TestAccAzureRMBackupProtectionPolicyVM_updateDailyToWeekly(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + ), }, + data.ImportStep(), { Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + ), }, data.ImportStep(), }, @@ -175,11 +237,16 @@ func TestAccAzureRMBackupProtectionPolicyVM_updateWeeklyToDaily(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + ), }, + data.ImportStep(), { Config: testAccAzureRMBackupProtectionPolicyVM_basicDaily(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_basicDaily(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + ), }, data.ImportStep(), }, @@ -196,11 +263,28 @@ func TestAccAzureRMBackupProtectionPolicyVM_updateWeeklyToPartial(t *testing.T) Steps: []resource.TestStep{ { Config: testAccAzureRMBackupProtectionPolicyVM_completeWeekly(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + ), }, + data.ImportStep(), { Config: testAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(data), - Check: checkAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(data.ResourceName, data.RandomInteger), + Check: resource.ComposeAggregateTestCheckFunc( + testCheckAzureRMBackupProtectionPolicyVmExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.frequency", "Weekly"), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.time", "23:00"), + resource.TestCheckResourceAttr(data.ResourceName, "backup.0.weekdays.#", "4"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_weekly.0.count", "42"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_weekly.0.weekdays.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.count", "7"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.weekdays.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_monthly.0.weeks.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.count", "77"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.weekdays.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.weeks.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_yearly.0.months.#", "1"), + ), }, data.ImportStep(), }, @@ -266,7 +350,7 @@ func testCheckAzureRMBackupProtectionPolicyVmExists(resourceName string) resourc } } -func testAccAzureRMBackupProtectionPolicyVM_base(data acceptance.TestData) string { +func testAccAzureRMBackupProtectionPolicyVM_template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-%d" @@ -283,7 +367,7 @@ resource "azurerm_recovery_services_vault" "test" { } func testAccAzureRMBackupProtectionPolicyVM_basicDaily(data acceptance.TestData) string { - template := testAccAzureRMBackupProtectionPolicyVM_base(data) + template := testAccAzureRMBackupProtectionPolicyVM_template(data) return fmt.Sprintf(` %s @@ -326,20 +410,8 @@ resource "azurerm_backup_policy_vm" "import" { `, template) } -func checkAccAzureRMBackupProtectionPolicyVM_basicDaily(resourceName string, ri int) resource.TestCheckFunc { - return resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMBackupProtectionPolicyVmExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "resource_group_name", fmt.Sprintf("acctestRG-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "recovery_vault_name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "backup.0.frequency", "Daily"), - resource.TestCheckResourceAttr(resourceName, "backup.0.time", "23:00"), - resource.TestCheckResourceAttr(resourceName, "retention_daily.0.count", "10"), - ) -} - func testAccAzureRMBackupProtectionPolicyVM_basicWeekly(data acceptance.TestData) string { - template := testAccAzureRMBackupProtectionPolicyVM_base(data) + template := testAccAzureRMBackupProtectionPolicyVM_template(data) return fmt.Sprintf(` %s @@ -362,21 +434,8 @@ resource "azurerm_backup_policy_vm" "test" { `, template, data.RandomInteger) } -func checkAccAzureRMBackupProtectionPolicyVM_basicWeekly(resourceName string, ri int) resource.TestCheckFunc { - return resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMBackupProtectionPolicyVmExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "resource_group_name", fmt.Sprintf("acctestRG-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "recovery_vault_name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "backup.0.frequency", "Weekly"), - resource.TestCheckResourceAttr(resourceName, "backup.0.time", "23:00"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.count", "42"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.weekdays.#", "2"), - ) -} - func testAccAzureRMBackupProtectionPolicyVM_completeDaily(data acceptance.TestData) string { - template := testAccAzureRMBackupProtectionPolicyVM_base(data) + template := testAccAzureRMBackupProtectionPolicyVM_template(data) return fmt.Sprintf(` %s @@ -415,29 +474,8 @@ resource "azurerm_backup_policy_vm" "test" { `, template, data.RandomInteger) } -func checkAccAzureRMBackupProtectionPolicyVM_completeDaily(resourceName string, ri int) resource.TestCheckFunc { - return resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMBackupProtectionPolicyVmExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "resource_group_name", fmt.Sprintf("acctestRG-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "recovery_vault_name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "backup.0.frequency", "Daily"), - resource.TestCheckResourceAttr(resourceName, "backup.0.time", "23:00"), - resource.TestCheckResourceAttr(resourceName, "retention_daily.0.count", "10"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.count", "42"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.weekdays.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.count", "7"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weekdays.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weeks.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.count", "77"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weekdays.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weeks.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.months.#", "2"), - ) -} - func testAccAzureRMBackupProtectionPolicyVM_completeWeekly(data acceptance.TestData) string { - template := testAccAzureRMBackupProtectionPolicyVM_base(data) + template := testAccAzureRMBackupProtectionPolicyVM_template(data) return fmt.Sprintf(` %s @@ -473,29 +511,8 @@ resource "azurerm_backup_policy_vm" "test" { `, template, data.RandomInteger) } -func checkAccAzureRMBackupProtectionPolicyVM_completeWeekly(resourceName string, ri int) resource.TestCheckFunc { - return resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMBackupProtectionPolicyVmExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "resource_group_name", fmt.Sprintf("acctestRG-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "recovery_vault_name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "backup.0.frequency", "Weekly"), - resource.TestCheckResourceAttr(resourceName, "backup.0.time", "23:00"), - resource.TestCheckResourceAttr(resourceName, "backup.0.weekdays.#", "4"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.count", "42"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.weekdays.#", "4"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.count", "7"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weekdays.#", "4"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weeks.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.count", "77"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weekdays.#", "4"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weeks.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.months.#", "2"), - ) -} - func testAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(data acceptance.TestData) string { - template := testAccAzureRMBackupProtectionPolicyVM_base(data) + template := testAccAzureRMBackupProtectionPolicyVM_template(data) return fmt.Sprintf(` %s @@ -530,24 +547,3 @@ resource "azurerm_backup_policy_vm" "test" { } `, template, data.RandomInteger) } - -func checkAccAzureRMBackupProtectionPolicyVM_completeWeeklyPartial(resourceName string, ri int) resource.TestCheckFunc { - return resource.ComposeAggregateTestCheckFunc( - testCheckAzureRMBackupProtectionPolicyVmExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "resource_group_name", fmt.Sprintf("acctestRG-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "recovery_vault_name", fmt.Sprintf("acctest-%d", ri)), - resource.TestCheckResourceAttr(resourceName, "backup.0.frequency", "Weekly"), - resource.TestCheckResourceAttr(resourceName, "backup.0.time", "23:00"), - resource.TestCheckResourceAttr(resourceName, "backup.0.weekdays.#", "4"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.count", "42"), - resource.TestCheckResourceAttr(resourceName, "retention_weekly.0.weekdays.#", "3"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.count", "7"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weekdays.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_monthly.0.weeks.#", "2"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.count", "77"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weekdays.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.weeks.#", "1"), - resource.TestCheckResourceAttr(resourceName, "retention_yearly.0.months.#", "1"), - ) -} From 4c0b594a17374204ca669b2e2391415b8f04682d Mon Sep 17 00:00:00 2001 From: kt Date: Sat, 28 Dec 2019 14:09:28 -0800 Subject: [PATCH 197/203] provider - fix various test failures from the refactoring (#5262) --- azurerm/internal/provider/services.go | 2 + ...x_virtual_machine_scale_set_images_test.go | 2 +- ...namespace_disaster_recovery_config_test.go | 8 ++-- .../resource_arm_healthcare_service_test.go | 7 +++- .../resource_arm_metric_alertrule_test.go | 42 ++++++++++++++----- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/azurerm/internal/provider/services.go b/azurerm/internal/provider/services.go index 70d8913b5c2f..4a052e204d13 100644 --- a/azurerm/internal/provider/services.go +++ b/azurerm/internal/provider/services.go @@ -51,6 +51,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redis" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/relay" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/scheduler" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/search" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/securitycenter" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/servicebus" @@ -115,6 +116,7 @@ func SupportedServices() []common.ServiceRegistration { redis.Registration{}, relay.Registration{}, resource.Registration{}, + scheduler.Registration{}, search.Registration{}, securitycenter.Registration{}, servicebus.Registration{}, diff --git a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_images_test.go b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_images_test.go index 15866e697880..fe954ed6bc0a 100644 --- a/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_images_test.go +++ b/azurerm/internal/services/compute/tests/resource_arm_linux_virtual_machine_scale_set_images_test.go @@ -721,7 +721,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "test" { publisher = "cloudbees" } - depends_on = ["azurerm_marketplace_agreement", "test")] + depends_on = ["azurerm_marketplace_agreement", "test"] } `, template, data.RandomInteger) } diff --git a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go index b8a4b5b91f6f..29dfffc7657a 100644 --- a/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go +++ b/azurerm/internal/services/eventhub/tests/resource_arm_eventhub_namespace_disaster_recovery_config_test.go @@ -161,7 +161,7 @@ resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { partner_namespace_id = "${azurerm_eventhub_namespace.testb.id}" } -`, data.RandomInteger, data.Locations.Primary, data.Locations.Primary) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) } func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_complete(data acceptance.TestData) string { @@ -186,7 +186,7 @@ resource "azurerm_eventhub_namespace" "testb" { } resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { - name = "${azurerm_eventhub_namespace.testa.name}" + name = "${azurerm_eventhub_namespace.testa.name}-111" resource_group_name = "${azurerm_resource_group.test.name}" namespace_name = "${azurerm_eventhub_namespace.testa.name}" partner_namespace_id = "${azurerm_eventhub_namespace.testb.id}" @@ -231,7 +231,7 @@ resource "azurerm_eventhub_namespace_disaster_recovery_config" "test" { partner_namespace_id = "${azurerm_eventhub_namespace.testc.id}" } -`, data.RandomInteger, data.Locations.Primary, data.Locations.Primary) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) } func testAccAzureRMEventHubNamespaceDisasterRecoveryConfig_updated_removed(data acceptance.TestData) string { @@ -261,5 +261,5 @@ resource "azurerm_eventhub_namespace" "testc" { resource_group_name = "${azurerm_resource_group.test.name}" sku = "Standard" } -`, data.RandomInteger, data.Locations.Primary, data.Locations.Primary) +`, data.RandomInteger, data.Locations.Primary, data.Locations.Secondary) } diff --git a/azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go b/azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go index d0cf65dc5e64..bc87e249ba54 100644 --- a/azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go +++ b/azurerm/internal/services/healthcare/tests/resource_arm_healthcare_service_test.go @@ -14,6 +14,7 @@ import ( func TestAccAzureRMHealthCareService_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_healthcare_service", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -37,6 +38,7 @@ func TestAccAzureRMHealthCareService_requiresImport(t *testing.T) { } data := acceptance.BuildTestData(t, "azurerm_healthcare_service", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -55,6 +57,7 @@ func TestAccAzureRMHealthCareService_requiresImport(t *testing.T) { func TestAccAzureRMHealthCareService_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_healthcare_service", "test") + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, @@ -146,7 +149,7 @@ resource "azurerm_healthcare_service" "test" { "${data.azurerm_client_config.current.service_principal_object_id}", ] } -`, data.RandomInteger, location, data.RandomInteger) +`, data.RandomInteger, location, data.RandomInteger/10) //name can only be 24 chars long } func testAccAzureRMHealthCareService_requiresImport(data acceptance.TestData) string { @@ -206,5 +209,5 @@ resource "azurerm_healthcare_service" "test" { allow_credentials = true } } -`, data.RandomInteger, location, data.RandomInteger) +`, data.RandomInteger, location, data.RandomInteger/10) //name can only be 24 chars long } diff --git a/azurerm/internal/services/monitor/tests/resource_arm_metric_alertrule_test.go b/azurerm/internal/services/monitor/tests/resource_arm_metric_alertrule_test.go index 988f678a6fa0..75d180d1f47f 100644 --- a/azurerm/internal/services/monitor/tests/resource_arm_metric_alertrule_test.go +++ b/azurerm/internal/services/monitor/tests/resource_arm_metric_alertrule_test.go @@ -135,7 +135,6 @@ func TestAccAzureRMMetricAlertRule_requiresImport(t *testing.T) { func TestAccAzureRMMetricAlertRule_sqlDatabaseStorage(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_metric_alertrule", "test") - config := testAccAzureRMMetricAlertRule_sqlDatabaseStorage(data) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, @@ -143,7 +142,7 @@ func TestAccAzureRMMetricAlertRule_sqlDatabaseStorage(t *testing.T) { CheckDestroy: testCheckAzureRMMetricAlertRuleDestroy, Steps: []resource.TestStep{ { - Config: config, + Config: testAccAzureRMMetricAlertRule_sqlDatabaseStorage(data), Check: resource.ComposeTestCheckFunc( testCheckAzureRMMetricAlertRuleExists(data.ResourceName), resource.TestCheckNoResourceAttr(data.ResourceName, "tags.$type"), @@ -360,26 +359,47 @@ resource "azurerm_metric_alertrule" "import" { func testAccAzureRMMetricAlertRule_sqlDatabaseStorage(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { - name = "acctestRG-%d" - location = "%s" + name = "acctestRG-%[1]d" + location = "%[2]s" +} + + +resource "azurerm_sql_server" "test" { + name = "acctestsqlserver%[1]d" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + version = "12.0" + administrator_login = "mradministrator" + administrator_login_password = "thisIsDog11" +} + +resource "azurerm_sql_database" "test" { + name = "acctestdb%[1]d" + resource_group_name = "${azurerm_resource_group.test.name}" + server_name = "${azurerm_sql_server.test.name}" + location = "${azurerm_resource_group.test.location}" + edition = "Standard" + collation = "SQL_Latin1_General_CP1_CI_AS" + max_size_bytes = "1073741824" + requested_service_objective_name = "S0" } resource "azurerm_virtual_network" "test" { - name = "acctvn-%d" + name = "acctvn-%[1]d" address_space = ["10.0.0.0/16"] location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" } resource "azurerm_subnet" "test" { - name = "acctsub-%d" + name = "acctsub-%[1]d" resource_group_name = "${azurerm_resource_group.test.name}" virtual_network_name = "${azurerm_virtual_network.test.name}" address_prefix = "10.0.2.0/24" } resource "azurerm_network_interface" "test" { - name = "acctni-%d" + name = "acctni-%[1]d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" @@ -391,7 +411,7 @@ resource "azurerm_network_interface" "test" { } resource "azurerm_virtual_machine" "test" { - name = "acctvm-%d" + name = "acctvm-%[1]d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" network_interface_ids = ["${azurerm_network_interface.test.id}"] @@ -405,7 +425,7 @@ resource "azurerm_virtual_machine" "test" { } storage_os_disk { - name = "osd-%d" + name = "osd-%[1]d" caching = "ReadWrite" create_option = "FromImage" disk_size_gb = "50" @@ -413,7 +433,7 @@ resource "azurerm_virtual_machine" "test" { } os_profile { - computer_name = "hn%d" + computer_name = "hn%[1]d" admin_username = "testadmin" admin_password = "Password1234!" } @@ -461,5 +481,5 @@ resource "azurerm_metric_alertrule" "test" { } } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary) } From c9feb608b7f862ae5da19551854d470152e1cea8 Mon Sep 17 00:00:00 2001 From: aqche <39076898+aqche@users.noreply.github.com> Date: Sun, 29 Dec 2019 18:04:45 -0600 Subject: [PATCH 198/203] New Resource: `azurerm_api_management_identity_provider_aad` (#5268) Partially addresses: #5044 Adds the azurerm_api_management_identity_provider_aad resource. --- .../services/apimanagement/client/client.go | 5 + .../services/apimanagement/registration.go | 1 + ...rm_api_management_identity_provider_aad.go | 171 ++++++++++++++ ...i_management_identity_provider_aad_test.go | 208 ++++++++++++++++++ website/azurerm.erb | 4 + ...gement_identity_provider_aad.html.markdown | 68 ++++++ 6 files changed, 457 insertions(+) create mode 100644 azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_aad.go create mode 100644 azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_aad_test.go create mode 100644 website/docs/r/api_management_identity_provider_aad.html.markdown diff --git a/azurerm/internal/services/apimanagement/client/client.go b/azurerm/internal/services/apimanagement/client/client.go index 41ad41b3b116..500d7f31f6f7 100644 --- a/azurerm/internal/services/apimanagement/client/client.go +++ b/azurerm/internal/services/apimanagement/client/client.go @@ -18,6 +18,7 @@ type Client struct { DiagnosticClient *apimanagement.DiagnosticClient GroupClient *apimanagement.GroupClient GroupUsersClient *apimanagement.GroupUserClient + IdentityProviderClient *apimanagement.IdentityProviderClient LoggerClient *apimanagement.LoggerClient OpenIdConnectClient *apimanagement.OpenIDConnectProviderClient PolicyClient *apimanagement.PolicyClient @@ -70,6 +71,9 @@ func NewClient(o *common.ClientOptions) *Client { groupUsersClient := apimanagement.NewGroupUserClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&groupUsersClient.Client, o.ResourceManagerAuthorizer) + identityProviderClient := apimanagement.NewIdentityProviderClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + o.ConfigureClient(&identityProviderClient.Client, o.ResourceManagerAuthorizer) + loggerClient := apimanagement.NewLoggerClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&loggerClient.Client, o.ResourceManagerAuthorizer) @@ -122,6 +126,7 @@ func NewClient(o *common.ClientOptions) *Client { DiagnosticClient: &diagnosticClient, GroupClient: &groupClient, GroupUsersClient: &groupUsersClient, + IdentityProviderClient: &identityProviderClient, LoggerClient: &loggerClient, OpenIdConnectClient: &openIdConnectClient, PolicyClient: &policyClient, diff --git a/azurerm/internal/services/apimanagement/registration.go b/azurerm/internal/services/apimanagement/registration.go index e14db112f0ab..03232eec7fdd 100644 --- a/azurerm/internal/services/apimanagement/registration.go +++ b/azurerm/internal/services/apimanagement/registration.go @@ -38,6 +38,7 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_api_management_diagnostic": resourceArmApiManagementDiagnostic(), "azurerm_api_management_group": resourceArmApiManagementGroup(), "azurerm_api_management_group_user": resourceArmApiManagementGroupUser(), + "azurerm_api_management_identity_provider_aad": resourceArmApiManagementIdentityProviderAAD(), "azurerm_api_management_logger": resourceArmApiManagementLogger(), "azurerm_api_management_openid_connect_provider": resourceArmApiManagementOpenIDConnectProvider(), "azurerm_api_management_product": resourceArmApiManagementProduct(), diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_aad.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_aad.go new file mode 100644 index 000000000000..ca25fb914586 --- /dev/null +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_identity_provider_aad.go @@ -0,0 +1,171 @@ +package apimanagement + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmApiManagementIdentityProviderAAD() *schema.Resource { + return &schema.Resource{ + Create: resourceArmApiManagementIdentityProviderAADCreateUpdate, + Read: resourceArmApiManagementIdentityProviderAADRead, + Update: resourceArmApiManagementIdentityProviderAADCreateUpdate, + Delete: resourceArmApiManagementIdentityProviderAADDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "resource_group_name": azure.SchemaResourceGroupName(), + + "api_management_name": azure.SchemaApiManagementName(), + + "client_id": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.GUID, + }, + + "client_secret": { + Type: schema.TypeString, + Required: true, + Sensitive: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "allowed_tenants": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validate.GUID, + }, + }, + }, + } +} + +func resourceArmApiManagementIdentityProviderAADCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).ApiManagement.IdentityProviderClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + resourceGroup := d.Get("resource_group_name").(string) + serviceName := d.Get("api_management_name").(string) + clientID := d.Get("client_id").(string) + clientSecret := d.Get("client_secret").(string) + allowedTenants := d.Get("allowed_tenants").([]interface{}) + + if features.ShouldResourcesBeImported() && d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, serviceName, apimanagement.Aad) + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing Identity Provider %q (API Management Service %q / Resource Group %q): %s", apimanagement.Aad, serviceName, resourceGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_api_management_identity_provider_aad", *existing.ID) + } + } + + parameters := apimanagement.IdentityProviderContract{ + IdentityProviderContractProperties: &apimanagement.IdentityProviderContractProperties{ + ClientID: utils.String(clientID), + ClientSecret: utils.String(clientSecret), + Type: apimanagement.Aad, + AllowedTenants: utils.ExpandStringSlice(allowedTenants), + }, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, serviceName, apimanagement.Aad, parameters, ""); err != nil { + return fmt.Errorf("Error creating or updating Identity Provider %q (Resource Group %q / API Management Service %q): %+v", apimanagement.Aad, resourceGroup, serviceName, err) + } + + resp, err := client.Get(ctx, resourceGroup, serviceName, apimanagement.Aad) + if err != nil { + return fmt.Errorf("Error retrieving Identity Provider %q (Resource Group %q / API Management Service %q): %+v", apimanagement.Aad, resourceGroup, serviceName, err) + } + if resp.ID == nil { + return fmt.Errorf("Cannot read ID for Identity Provider %q (Resource Group %q / API Management Service %q)", apimanagement.Aad, resourceGroup, serviceName) + } + d.SetId(*resp.ID) + + return resourceArmApiManagementIdentityProviderAADRead(d, meta) +} + +func resourceArmApiManagementIdentityProviderAADRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).ApiManagement.IdentityProviderClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + serviceName := id.Path["service"] + identityProviderName := id.Path["identityProviders"] + + resp, err := client.Get(ctx, resourceGroup, serviceName, apimanagement.IdentityProviderType(identityProviderName)) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + log.Printf("[DEBUG] Identity Provider %q (Resource Group %q / API Management Service %q) was not found - removing from state!", identityProviderName, resourceGroup, serviceName) + d.SetId("") + return nil + } + + return fmt.Errorf("Error making Read request for Identity Provider %q (Resource Group %q / API Management Service %q): %+v", identityProviderName, resourceGroup, serviceName, err) + } + + d.Set("resource_group_name", resourceGroup) + d.Set("api_management_name", serviceName) + + if props := resp.IdentityProviderContractProperties; props != nil { + d.Set("client_id", props.ClientID) + d.Set("client_secret", props.ClientSecret) + d.Set("allowed_tenants", props.AllowedTenants) + } + + return nil +} + +func resourceArmApiManagementIdentityProviderAADDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).ApiManagement.IdentityProviderClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + serviceName := id.Path["service"] + identityProviderName := id.Path["identityProviders"] + + if resp, err := client.Delete(ctx, resourceGroup, serviceName, apimanagement.IdentityProviderType(identityProviderName), ""); err != nil { + if !utils.ResponseWasNotFound(resp) { + return fmt.Errorf("Error deleting Identity Provider %q (Resource Group %q / API Management Service %q): %+v", identityProviderName, resourceGroup, serviceName, err) + } + } + + return nil +} diff --git a/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_aad_test.go b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_aad_test.go new file mode 100644 index 000000000000..4085fbe096ce --- /dev/null +++ b/azurerm/internal/services/apimanagement/tests/resource_arm_api_management_identity_provider_aad_test.go @@ -0,0 +1,208 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement" + "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/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMApiManagementIdentityProviderAAD_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_identity_provider_aad", "test") + config := testAccAzureRMApiManagementIdentityProviderAAD_basic(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMApiManagementIdentityProviderAADDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementIdentityProviderAADExists(data.ResourceName), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMApiManagementIdentityProviderAAD_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_identity_provider_aad", "test") + config := testAccAzureRMApiManagementIdentityProviderAAD_basic(data) + updateConfig := testAccAzureRMApiManagementIdentityProviderAAD_update(data) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMApiManagementIdentityProviderAADDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementIdentityProviderAADExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_id", "00000000-0000-0000-0000-000000000000"), + resource.TestCheckResourceAttr(data.ResourceName, "client_secret", "00000000000000000000000000000000"), + resource.TestCheckResourceAttr(data.ResourceName, "allowed_tenants.#", "1"), + resource.TestCheckResourceAttr(data.ResourceName, "allowed_tenants.0", data.Client().TenantID), + ), + }, + { + Config: updateConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementIdentityProviderAADExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "client_id", "11111111-1111-1111-1111-111111111111"), + resource.TestCheckResourceAttr(data.ResourceName, "client_secret", "11111111111111111111111111111111"), + resource.TestCheckResourceAttr(data.ResourceName, "allowed_tenants.#", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "allowed_tenants.0", data.Client().TenantID), + resource.TestCheckResourceAttr(data.ResourceName, "allowed_tenants.1", data.Client().TenantID), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMApiManagementIdentityProviderAAD_requiresImport(t *testing.T) { + if !features.ShouldResourcesBeImported() { + t.Skip("Skipping since resources aren't required to be imported") + return + } + data := acceptance.BuildTestData(t, "azurerm_api_management_identity_provider_aad", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMApiManagementIdentityProviderAADDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMApiManagementIdentityProviderAAD_basic(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApiManagementIdentityProviderAADExists(data.ResourceName), + ), + }, + data.RequiresImportErrorStep(testAccAzureRMApiManagementIdentityProviderAAD_requiresImport), + }, + }) +} + +func testCheckAzureRMApiManagementIdentityProviderAADDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).ApiManagement.IdentityProviderClient + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_api_management_identity_provider_aad" { + continue + } + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + serviceName := rs.Primary.Attributes["api_management_name"] + + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + resp, err := client.Get(ctx, resourceGroup, serviceName, apimanagement.Aad) + + if err != nil { + if !utils.ResponseWasNotFound(resp.Response) { + return err + } + } + + return nil + } + return nil +} + +func testCheckAzureRMApiManagementIdentityProviderAADExists(resourceName string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[resourceName] + if !ok { + return fmt.Errorf("Not found: %s", resourceName) + } + + resourceGroup := rs.Primary.Attributes["resource_group_name"] + serviceName := rs.Primary.Attributes["api_management_name"] + + client := acceptance.AzureProvider.Meta().(*clients.Client).ApiManagement.IdentityProviderClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + resp, err := client.Get(ctx, resourceGroup, serviceName, apimanagement.Aad) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: API Management Identity Provider %q (Resource Group %q / API Management Service %q) does not exist", apimanagement.Aad, resourceGroup, serviceName) + } + return fmt.Errorf("Bad: Get on apiManagementIdentityProviderClient: %+v", err) + } + + return nil + } +} + +func testAccAzureRMApiManagementIdentityProviderAAD_basic(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-api-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Developer_1" +} + +resource "azurerm_api_management_identity_provider_aad" "test" { + resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = "${azurerm_api_management.test.name}" + client_id = "00000000-0000-0000-0000-000000000000" + client_secret = "00000000000000000000000000000000" + allowed_tenants = ["%s"] +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Client().TenantID) +} + +func testAccAzureRMApiManagementIdentityProviderAAD_update(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-api-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + publisher_name = "pub1" + publisher_email = "pub1@email.com" + sku_name = "Developer_1" +} + +resource "azurerm_api_management_identity_provider_aad" "test" { + resource_group_name = "${azurerm_resource_group.test.name}" + api_management_name = "${azurerm_api_management.test.name}" + client_id = "11111111-1111-1111-1111-111111111111" + client_secret = "11111111111111111111111111111111" + allowed_tenants = ["%s", "%s"] +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.Client().TenantID, data.Client().TenantID) +} + +func testAccAzureRMApiManagementIdentityProviderAAD_requiresImport(data acceptance.TestData) string { + template := testAccAzureRMApiManagementIdentityProviderAAD_basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_identity_provider_aad" "import" { + resource_group_name = "${azurerm_api_management_identity_provider_aad.test.resource_group_name}" + api_management_name = "${azurerm_api_management_identity_provider_aad.test.api_management_name}" + client_id = "${azurerm_api_management_identity_provider_aad.test.client_id}" + client_secret = "${azurerm_api_management_identity_provider_aad.test.client_secret}" + allowed_tenants = "${azurerm_api_management_identity_provider_aad.test.allowed_tenants}" +} +`, template) +} diff --git a/website/azurerm.erb b/website/azurerm.erb index f3506a70cbc4..5c618bfc3cb6 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -561,6 +561,10 @@ azurerm_api_management_group_user +
  • + azurerm_api_management_identity_provider_aad +
  • +
  • azurerm_api_management_logger
  • diff --git a/website/docs/r/api_management_identity_provider_aad.html.markdown b/website/docs/r/api_management_identity_provider_aad.html.markdown new file mode 100644 index 000000000000..4f2e1cb764f6 --- /dev/null +++ b/website/docs/r/api_management_identity_provider_aad.html.markdown @@ -0,0 +1,68 @@ +--- +subcategory: "API Management" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_api_management_identity_provider_aad" +sidebar_current: "docs-azurerm-resource-api-management-identity-provider-aad" +description: |- + Manages an API Management AAD Identity Provider. +--- + +# azurerm_api_management_identity_provider_aad + +Manages an API Management AAD Identity Provider. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_api_management" "example" { + name = "example-apim" + location = "${azurerm_resource_group.example.location}" + resource_group_name = "${azurerm_resource_group.example.name}" + publisher_name = "My Company" + publisher_email = "company@terraform.io" + sku_name = "Developer_1" +} + +resource "azurerm_api_management_identity_provider_aad" "example" { + resource_group_name = "${azurerm_resource_group.example.name}" + api_management_name = "${azurerm_api_management.example.name}" + client_id = "00000000-0000-0000-0000-000000000000" + client_secret = "00000000000000000000000000000000" + allowed_tenants = ["00000000-0000-0000-0000-000000000000"] +} +``` + +## Argument Reference + +The following arguments are supported: + +* `api_management_name` - (Required) The Name of the API Management Service where this AAD Identity Provider should be created. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The Name of the Resource Group where the API Management Service exists. Changing this forces a new resource to be created. + +* `client_id` - (Required) Client Id of the Application in the AAD Identity Provider. + +* `client_secret` - (Required) Client secret of the Application in the AAD Identity Provider. + +* `allowed_tenants` - (Required) List of allowed AAD Tenants. + +--- + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The ID of the API Management AAD Identity Provider. + +## Import + +API Management AAD Identity Provider can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_api_management_identity_provider_aad.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.ApiManagement/service/instance1/identityProviders/aad +``` From b2fdea168009396228f30ff4606e4372798b1b8d Mon Sep 17 00:00:00 2001 From: kt Date: Sun, 29 Dec 2019 16:05:32 -0800 Subject: [PATCH 199/203] Update CHANGELOG.md to include #5268 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41044dae27ee..a3a099b3dae8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * **New Data Source:** `azurerm_netapp_snapshot` [GH-5215] * **New Resource:** `azurerm_advanced_threat_protection` [GH-4848] * **New Resource:** `azurerm_api_management_diagnostic ` [GH-4836] +* **New Resource:** `azurerm_api_management_identity_provider_aad` [GH-5268] * **New Resource:** `azurerm_automation_certificate` [GH-4785] * **New Resource:** `azurerm_backup_container_storage_account` [GH-5213] * **New Resource:** `azurerm_backup_policy_file_share` [GH-5213] From c6386d1242b9bd6faca73b69f27452e8b8e65cf0 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 30 Dec 2019 17:29:19 -0600 Subject: [PATCH 200/203] Fix panic in 'azurerm_api_management_operation' (#5273) Fix panic in 'azurerm_api_management_operation' Recreatd #5243 after the changes to the provider organization. --- .../resource_arm_api_management_api_operation.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go index 38e7bbd2daaf..da9c713c8d58 100644 --- a/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go +++ b/azurerm/internal/services/apimanagement/resource_arm_api_management_api_operation.go @@ -250,15 +250,27 @@ func expandApiManagementOperationRequestContract(input []interface{}) (*apimanag } vs := input[0].(map[string]interface{}) + if vs == nil { + return nil, nil + } description := vs["description"].(string) headersRaw := vs["header"].([]interface{}) + if headersRaw == nil { + headersRaw = []interface{}{} + } headers := azure.ExpandApiManagementOperationParameterContract(headersRaw) queryParametersRaw := vs["query_parameter"].([]interface{}) + if queryParametersRaw == nil { + queryParametersRaw = []interface{}{} + } queryParameters := azure.ExpandApiManagementOperationParameterContract(queryParametersRaw) representationsRaw := vs["representation"].([]interface{}) + if representationsRaw == nil { + representationsRaw = []interface{}{} + } representations, err := azure.ExpandApiManagementOperationRepresentation(representationsRaw) if err != nil { return nil, err From 1a6f97369d32d4397a13f372fae16ea0adbe5e49 Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 30 Dec 2019 15:30:19 -0800 Subject: [PATCH 201/203] Update CHANGELOG.md to include #5273 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3a099b3dae8..c89c5c849a64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ IMPROVEMENTS: * Data Source: `azurerm_private_link_service` - exposing the `enable_proxy_protocol` property [GH-5178] * Data Source: `azurerm_virtual_network_gateway` - exposing the `generation` property [GH-5198] * `azurerm_application_gateway` - support for the `trusted_root_certificate_names` property [GH-5204] +* `azurerm_api_management_operation` - will no longer panic when `response` is missing values [GH-5273] * `azurerm_cosmosdb_cassandra_keyspace` - support for the `throughput` property [GH-5203] * `azurerm_cosmosdb_sql_container` - support for the `throughput` property [GH-5203] * `azurerm_cosmosdb_sql_database` - support for the `throughput` property [GH-5203] From 0978968b207b9ded7ed2d2bc38b662da85fb7e19 Mon Sep 17 00:00:00 2001 From: Jack Batzner Date: Mon, 30 Dec 2019 21:24:28 -0600 Subject: [PATCH 202/203] Fix reference to 'resourceName' --- ...rm_iothub_dps_shared_access_policy_test.go | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go index 43d3ef00c83f..2c820ce2e8f1 100644 --- a/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go +++ b/azurerm/internal/services/iothub/tests/resource_arm_iothub_dps_shared_access_policy_test.go @@ -24,17 +24,17 @@ func TestAccAzureRMIotHubDpsSharedAccessPolicy_basic(t *testing.T) { { Config: testAccAzureRMIotHubDpsSharedAccessPolicy_basic(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMIotHubDpsSharedAccessPolicyExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "name", "acctest"), - resource.TestCheckResourceAttr(resourceName, "enrollment_read", "false"), - resource.TestCheckResourceAttr(resourceName, "enrollment_write", "false"), - resource.TestCheckResourceAttr(resourceName, "registration_read", "false"), - resource.TestCheckResourceAttr(resourceName, "registration_write", "false"), - resource.TestCheckResourceAttr(resourceName, "service_config", "true"), - resource.TestCheckResourceAttrSet(resourceName, "primary_key"), - resource.TestCheckResourceAttrSet(resourceName, "primary_connection_string"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_key"), - resource.TestCheckResourceAttrSet(resourceName, "secondary_connection_string"), + testCheckAzureRMIotHubDpsSharedAccessPolicyExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "name", "acctest"), + resource.TestCheckResourceAttr(data.ResourceName, "enrollment_read", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "enrollment_write", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "registration_read", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "registration_write", "false"), + resource.TestCheckResourceAttr(data.ResourceName, "service_config", "true"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "primary_connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"), + resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_connection_string"), ), }, }, From f557dc43a6e7e557f4b88b899f74a8fe88be0bd0 Mon Sep 17 00:00:00 2001 From: Jack Batzner Date: Tue, 31 Dec 2019 08:38:30 -0600 Subject: [PATCH 203/203] fmt file --- .../iothub/resource_arm_iothub_dps_shared_access_policy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy.go b/azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy.go index 5071c975d3d5..324e3421e3a0 100644 --- a/azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy.go +++ b/azurerm/internal/services/iothub/resource_arm_iothub_dps_shared_access_policy.go @@ -103,7 +103,7 @@ func resourceArmIotHubDPSSharedAccessPolicy() *schema.Resource { Sensitive: true, Computed: true, }, - + "secondary_connection_string": { Type: schema.TypeString, Sensitive: true,