From c313f4f9fea43bb04bdde93a4f70cedd7e3f1ab6 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 18 Feb 2022 09:13:09 +0100 Subject: [PATCH 1/7] refactor: removing azure.LocationOptional() --- helpers/azure/location.go | 4 ---- internal/location/schema.go | 4 ---- internal/services/policy/assignment_base_resource.go | 2 +- internal/services/policy/policy_assignment_resource.go | 3 ++- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/helpers/azure/location.go b/helpers/azure/location.go index dfd6054b4a44..77d10b7d5393 100644 --- a/helpers/azure/location.go +++ b/helpers/azure/location.go @@ -9,10 +9,6 @@ func SchemaLocation() *pluginsdk.Schema { return location.Schema() } -func SchemaLocationOptional() *pluginsdk.Schema { - return location.SchemaOptional() -} - func SchemaLocationForDataSource() *pluginsdk.Schema { return location.SchemaComputed() } diff --git a/internal/location/schema.go b/internal/location/schema.go index 55977edb8ac3..5939ab7181d9 100644 --- a/internal/location/schema.go +++ b/internal/location/schema.go @@ -10,10 +10,6 @@ func Schema() *pluginsdk.Schema { return commonschema.Location() } -func SchemaOptional() *pluginsdk.Schema { - return commonschema.LocationOptional() -} - func SchemaComputed() *pluginsdk.Schema { return commonschema.LocationComputed() } diff --git a/internal/services/policy/assignment_base_resource.go b/internal/services/policy/assignment_base_resource.go index 2f8d8e501560..0682714e3e31 100644 --- a/internal/services/policy/assignment_base_resource.go +++ b/internal/services/policy/assignment_base_resource.go @@ -315,7 +315,7 @@ func (br assignmentBaseResource) arguments(fields map[string]*pluginsdk.Schema) Optional: true, }, - "location": azure.SchemaLocationOptional(), + "location": commonschema.LocationOptional(), "identity": commonschema.SystemAssignedIdentityOptional(), diff --git a/internal/services/policy/policy_assignment_resource.go b/internal/services/policy/policy_assignment_resource.go index f073ceb4fd7a..5eb719bcd359 100644 --- a/internal/services/policy/policy_assignment_resource.go +++ b/internal/services/policy/policy_assignment_resource.go @@ -7,6 +7,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2021-06-01-preview/policy" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -84,7 +85,7 @@ resources and will be removed in version 3.0 of the Azure Provider. Optional: true, }, - "location": azure.SchemaLocationOptional(), + "location": commonschema.LocationOptional(), //lintignore:XS003 "identity": { From 5923f3bf1777a012621d355583e6c3cd024530f4 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 18 Feb 2022 09:14:52 +0100 Subject: [PATCH 2/7] refactor: removing `location.SchemaWithoutForceNew()` --- internal/location/schema.go | 4 ---- internal/services/apimanagement/api_management_resource.go | 2 +- .../services/bot/bot_channel_direct_line_speech_resource.go | 3 ++- internal/services/containers/container_registry_resource.go | 6 +++--- internal/services/cosmos/cosmosdb_account_resource.go | 2 +- .../cosmosdb_restorable_database_accounts_data_source.go | 4 ++-- internal/services/firewall/firewall_policy_resource.go | 2 +- 7 files changed, 10 insertions(+), 13 deletions(-) diff --git a/internal/location/schema.go b/internal/location/schema.go index 5939ab7181d9..6a1d35187926 100644 --- a/internal/location/schema.go +++ b/internal/location/schema.go @@ -14,10 +14,6 @@ func SchemaComputed() *pluginsdk.Schema { return commonschema.LocationComputed() } -func SchemaWithoutForceNew() *pluginsdk.Schema { - return commonschema.LocationWithoutForceNew() -} - func DiffSuppressFunc(v, old, new string, d *pluginsdk.ResourceData) bool { return location.DiffSuppressFunc(v, old, new, d) } diff --git a/internal/services/apimanagement/api_management_resource.go b/internal/services/apimanagement/api_management_resource.go index 57753def8b84..fd55b9f7bc99 100644 --- a/internal/services/apimanagement/api_management_resource.go +++ b/internal/services/apimanagement/api_management_resource.go @@ -170,7 +170,7 @@ func resourceApiManagementSchema() map[string]*pluginsdk.Schema { Optional: true, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ - "location": location.SchemaWithoutForceNew(), + "location": commonschema.LocationWithoutForceNew(), "virtual_network_configuration": { Type: pluginsdk.TypeList, diff --git a/internal/services/bot/bot_channel_direct_line_speech_resource.go b/internal/services/bot/bot_channel_direct_line_speech_resource.go index d33e8d998149..0d3400c7b954 100644 --- a/internal/services/bot/bot_channel_direct_line_speech_resource.go +++ b/internal/services/bot/bot_channel_direct_line_speech_resource.go @@ -7,6 +7,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/botservice/mgmt/2021-03-01/botservice" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" @@ -58,7 +59,7 @@ func resourceBotChannelDirectLineSpeech() *pluginsdk.Resource { ValidateFunc: validation.StringIsNotEmpty, }, - "cognitive_service_location": location.SchemaWithoutForceNew(), + "cognitive_service_location": commonschema.LocationWithoutForceNew(), "custom_speech_model_id": { Type: schema.TypeString, diff --git a/internal/services/containers/container_registry_resource.go b/internal/services/containers/container_registry_resource.go index f9a71dce86b3..62624add3874 100644 --- a/internal/services/containers/container_registry_resource.go +++ b/internal/services/containers/container_registry_resource.go @@ -19,7 +19,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/parse" - validate2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/validate" + containerValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/validate" keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -857,7 +857,7 @@ func resourceContainerRegistrySchema() map[string]*pluginsdk.Schema { Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateFunc: validate2.ContainerRegistryName, + ValidateFunc: containerValidate.ContainerRegistryName, }, "resource_group_name": azure.SchemaResourceGroupName(), @@ -903,7 +903,7 @@ func resourceContainerRegistrySchema() map[string]*pluginsdk.Schema { }(), Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ - "location": location.SchemaWithoutForceNew(), + "location": commonschema.LocationWithoutForceNew(), "zone_redundancy_enabled": { Type: pluginsdk.TypeBool, diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index 8bf50684c7e4..087dcdb35d9c 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -292,7 +292,7 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { Computed: true, }, - "location": location.SchemaWithoutForceNew(), + "location": commonschema.LocationWithoutForceNew(), "failover_priority": { Type: pluginsdk.TypeInt, diff --git a/internal/services/cosmos/cosmosdb_restorable_database_accounts_data_source.go b/internal/services/cosmos/cosmosdb_restorable_database_accounts_data_source.go index 07d6c5371b35..2d0277feb898 100644 --- a/internal/services/cosmos/cosmosdb_restorable_database_accounts_data_source.go +++ b/internal/services/cosmos/cosmosdb_restorable_database_accounts_data_source.go @@ -5,8 +5,8 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-10-15/documentdb" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -29,7 +29,7 @@ func dataSourceCosmosDbRestorableDatabaseAccounts() *pluginsdk.Resource { ValidateFunc: validate.CosmosAccountName, }, - "location": location.SchemaWithoutForceNew(), + "location": commonschema.LocationWithoutForceNew(), "accounts": { Type: pluginsdk.TypeList, diff --git a/internal/services/firewall/firewall_policy_resource.go b/internal/services/firewall/firewall_policy_resource.go index 80b98f99b18c..e97cedeb6354 100644 --- a/internal/services/firewall/firewall_policy_resource.go +++ b/internal/services/firewall/firewall_policy_resource.go @@ -941,7 +941,7 @@ func resourceFirewallPolicySchema() map[string]*pluginsdk.Schema { Required: true, ValidateFunc: logAnalytiscValidate.LogAnalyticsWorkspaceID, }, - "firewall_location": location.SchemaWithoutForceNew(), + "firewall_location": commonschema.LocationWithoutForceNew(), }, }, }, From 12aedca9cee2b85ff35697e833807641def48b5a Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 18 Feb 2022 09:18:18 +0100 Subject: [PATCH 3/7] refactor: removing `azure.SchemaResourceGroupNameDeprecatedComputed` --- helpers/azure/resource_group.go | 19 ------------------- .../backend_address_pool_resource.go | 4 ++-- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/helpers/azure/resource_group.go b/helpers/azure/resource_group.go index 1847b2967a85..e3f927774abf 100644 --- a/helpers/azure/resource_group.go +++ b/helpers/azure/resource_group.go @@ -18,25 +18,6 @@ func SchemaResourceGroupName() *pluginsdk.Schema { } } -func SchemaResourceGroupNameDeprecated() *pluginsdk.Schema { - return &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: ValidateResourceGroupName, - Deprecated: "This field is no longer used and will be removed in the next major version of the Azure Provider", - } -} - -func SchemaResourceGroupNameDeprecatedComputed() *pluginsdk.Schema { - return &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - Optional: true, - Computed: true, - ValidateFunc: ValidateResourceGroupName, - Deprecated: "This field is no longer used and will be removed in the next major version of the Azure Provider", - } -} - func SchemaResourceGroupNameDiffSuppress() *pluginsdk.Schema { return &pluginsdk.Schema{ Type: pluginsdk.TypeString, diff --git a/internal/services/loadbalancer/backend_address_pool_resource.go b/internal/services/loadbalancer/backend_address_pool_resource.go index 204f63483581..b7fcbd0c4949 100644 --- a/internal/services/loadbalancer/backend_address_pool_resource.go +++ b/internal/services/loadbalancer/backend_address_pool_resource.go @@ -6,7 +6,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-05-01/network" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" @@ -131,7 +131,7 @@ func resourceArmLoadBalancerBackendAddressPool() *pluginsdk.Resource { } if !features.ThreePointOhBeta() { - s["resource_group_name"] = azure.SchemaResourceGroupNameDeprecatedComputed() + s["resource_group_name"] = commonschema.ResourceGroupNameDeprecatedComputed() s["backend_address"] = &pluginsdk.Schema{ Type: pluginsdk.TypeSet, Optional: true, From 2ad5b06cb1a452d15b03b77f4ccada73a4630f6b Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 18 Feb 2022 09:20:05 +0100 Subject: [PATCH 4/7] refactor: removing `azure.SchemaResourceGroupNameOptional()` --- helpers/azure/resource_group.go | 8 -------- internal/services/iothub/iothub_resource.go | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/helpers/azure/resource_group.go b/helpers/azure/resource_group.go index e3f927774abf..e0be0db34e26 100644 --- a/helpers/azure/resource_group.go +++ b/helpers/azure/resource_group.go @@ -46,14 +46,6 @@ func SchemaResourceGroupNameOptionalComputed() *pluginsdk.Schema { } } -func SchemaResourceGroupNameOptional() *pluginsdk.Schema { - return &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: ValidateResourceGroupName, - } -} - func SchemaResourceGroupNameSetOptional() *pluginsdk.Schema { return &pluginsdk.Schema{ Type: pluginsdk.TypeSet, diff --git a/internal/services/iothub/iothub_resource.go b/internal/services/iothub/iothub_resource.go index e707fba322a5..65108acf8c38 100644 --- a/internal/services/iothub/iothub_resource.go +++ b/internal/services/iothub/iothub_resource.go @@ -337,7 +337,7 @@ func resourceIotHub() *pluginsdk.Resource { ValidateFunc: iothubValidate.FileNameFormat, }, - "resource_group_name": azure.SchemaResourceGroupNameOptional(), + "resource_group_name": commonschema.ResourceGroupNameOptional(), }, }, }, From 2ac238877b27ad6a79119e0e5fd2415d43c50617 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 18 Feb 2022 09:21:47 +0100 Subject: [PATCH 5/7] refactor: removing `azure.SchemaResourceGroupNameSetOptional()` --- helpers/azure/resource_group.go | 11 ----------- .../advisor/advisor_recommendations_data_source.go | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/helpers/azure/resource_group.go b/helpers/azure/resource_group.go index e0be0db34e26..c8533e7f4f38 100644 --- a/helpers/azure/resource_group.go +++ b/helpers/azure/resource_group.go @@ -46,17 +46,6 @@ func SchemaResourceGroupNameOptionalComputed() *pluginsdk.Schema { } } -func SchemaResourceGroupNameSetOptional() *pluginsdk.Schema { - return &pluginsdk.Schema{ - Type: pluginsdk.TypeSet, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: ValidateResourceGroupName, - }, - } -} - func ValidateResourceGroupName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) diff --git a/internal/services/advisor/advisor_recommendations_data_source.go b/internal/services/advisor/advisor_recommendations_data_source.go index 9fa406017a5e..31cab74650c3 100644 --- a/internal/services/advisor/advisor_recommendations_data_source.go +++ b/internal/services/advisor/advisor_recommendations_data_source.go @@ -7,7 +7,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/advisor/mgmt/2020-01-01/advisor" "github.com/gofrs/uuid" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -41,7 +41,7 @@ func dataSourceAdvisorRecommendations() *pluginsdk.Resource { }, }, - "filter_by_resource_groups": azure.SchemaResourceGroupNameSetOptional(), + "filter_by_resource_groups": commonschema.ResourceGroupNameSetOptional(), "recommendations": { Type: pluginsdk.TypeList, From 04925facef879a6b3b67175352c35562754946b7 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 18 Feb 2022 09:27:27 +0100 Subject: [PATCH 6/7] refactor: removing `azure.SchemaResourceGroupNameOptionalComputed()` --- helpers/azure/resource_group.go | 10 ---------- .../services/synapse/synapse_workspace_resource.go | 2 +- .../services/web/app_service_environment_resource.go | 6 ++++-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/helpers/azure/resource_group.go b/helpers/azure/resource_group.go index c8533e7f4f38..0947fa24c26f 100644 --- a/helpers/azure/resource_group.go +++ b/helpers/azure/resource_group.go @@ -36,16 +36,6 @@ func SchemaResourceGroupNameForDataSource() *pluginsdk.Schema { } } -func SchemaResourceGroupNameOptionalComputed() *pluginsdk.Schema { - return &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ForceNew: true, - Optional: true, - Computed: true, - ValidateFunc: ValidateResourceGroupName, - } -} - func ValidateResourceGroupName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) diff --git a/internal/services/synapse/synapse_workspace_resource.go b/internal/services/synapse/synapse_workspace_resource.go index 984910fe9a1d..675669e37395 100644 --- a/internal/services/synapse/synapse_workspace_resource.go +++ b/internal/services/synapse/synapse_workspace_resource.go @@ -187,7 +187,7 @@ func resourceSynapseWorkspace() *pluginsdk.Resource { return commonschema.SystemAssignedIdentityComputed() }(), - "managed_resource_group_name": azure.SchemaResourceGroupNameOptionalComputed(), + "managed_resource_group_name": commonschema.ResourceGroupNameOptionalComputed(), "azure_devops_repo": { Type: pluginsdk.TypeList, diff --git a/internal/services/web/app_service_environment_resource.go b/internal/services/web/app_service_environment_resource.go index e52fb031b0fd..ae52a46e9864 100644 --- a/internal/services/web/app_service_environment_resource.go +++ b/internal/services/web/app_service_environment_resource.go @@ -7,6 +7,8 @@ import ( "strings" "time" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/Azure/azure-sdk-for-go/services/web/mgmt/2021-02-01/web" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" @@ -504,9 +506,9 @@ func resourceAppServiceEnvironmentSchema() map[string]*pluginsdk.Schema { "resource_group_name": func() *pluginsdk.Schema { if !features.ThreePointOhBeta() { - return azure.SchemaResourceGroupNameOptionalComputed() + return commonschema.ResourceGroupNameOptionalComputed() } - return azure.SchemaResourceGroupName() + return commonschema.ResourceGroupName() }(), "tags": tags.ForceNewSchema(), From 6dce739463a50dfd8b02271aeffa108b8ee9e1bb Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 18 Feb 2022 09:44:52 +0100 Subject: [PATCH 7/7] refactor: updating the azure methods to call commonschema --- helpers/azure/location.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/helpers/azure/location.go b/helpers/azure/location.go index 77d10b7d5393..68e3606cc465 100644 --- a/helpers/azure/location.go +++ b/helpers/azure/location.go @@ -1,19 +1,20 @@ package azure import ( - "github.com/hashicorp/terraform-provider-azurerm/internal/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) func SchemaLocation() *pluginsdk.Schema { - return location.Schema() + return commonschema.Location() } func SchemaLocationForDataSource() *pluginsdk.Schema { - return location.SchemaComputed() + return commonschema.LocationComputed() } -// azure.NormalizeLocation is a function which normalises human-readable region/location +// NormalizeLocation is a function which normalises human-readable region/location // names (e.g. "West US") to the values used and returned by the Azure API (e.g. "westus"). // In state we track the API internal version as it is easier to go from the human form // to the canonical form than the other way around.