From 4f39e63b52623082125a3d0de62ccb9406475695 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 4 Sep 2024 12:25:50 +0200 Subject: [PATCH 1/6] add state migration for ip_range_filter type change --- .../cosmos/cosmosdb_account_resource.go | 7 + .../cosmos/migration/cosmosdb_account.go | 528 ++++++++++++++++++ 2 files changed, 535 insertions(+) create mode 100644 internal/services/cosmos/migration/cosmosdb_account.go diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index 5144d2d6d946..42d77935438b 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -27,6 +27,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/common" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/validate" keyVaultParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse" @@ -183,6 +184,12 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { Delete: pluginsdk.DefaultTimeout(180 * time.Minute), }, + SchemaVersion: 1, + + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.CosmosDBAccountV0toV1{}, + }), + Schema: map[string]*pluginsdk.Schema{ "name": { Type: pluginsdk.TypeString, diff --git a/internal/services/cosmos/migration/cosmosdb_account.go b/internal/services/cosmos/migration/cosmosdb_account.go new file mode 100644 index 000000000000..fed9c898ec61 --- /dev/null +++ b/internal/services/cosmos/migration/cosmosdb_account.go @@ -0,0 +1,528 @@ +package migration + +import ( + "context" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2024-05-15/cosmosdb" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/common" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +var _ pluginsdk.StateUpgrade = CosmosDBAccountV0toV1{} + +type CosmosDBAccountV0toV1 struct{} + +func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "location": commonschema.Location(), + + "resource_group_name": commonschema.ResourceGroupName(), + + "offer_type": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "analytical_storage": { + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "schema_type": { + Type: pluginsdk.TypeString, + Required: true, + }, + }, + }, + }, + + "capacity": { + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "total_throughput_limit": { + Type: pluginsdk.TypeInt, + Required: true, + }, + }, + }, + }, + + // per Microsoft's documentation, as of April 1 2023 the default minimal TLS version for all new accounts is 1.2 + "minimal_tls_version": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + + "create_mode": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, + + // Per Documentation: "The default identity needs to be explicitly set by the users." This should not be optional without a default anymore. + // DOC: https://learn.microsoft.com/en-us/java/api/com.azure.resourcemanager.cosmos.models.databaseaccountupdateparameters?view=azure-java-stable#method-details + "default_identity_type": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "FirstPartyIdentity", + }, + + "kind": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + Default: string(cosmosdb.DatabaseAccountKindGlobalDocumentDB), + }, + + "ip_range_filter": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "free_tier_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + }, + + "analytical_storage_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "public_network_access_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + }, + + "automatic_failover_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Computed: !features.FourPointOhBeta(), + }, + + "key_vault_key_id": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + }, + + "consistency_policy": { + Type: pluginsdk.TypeList, + Required: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "consistency_level": { + Type: pluginsdk.TypeString, + Required: true, + }, + + // This value can only change if the 'consistency_level' is set to 'BoundedStaleness' + "max_interval_in_seconds": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 5, + }, + + // This value can only change if the 'consistency_level' is set to 'BoundedStaleness' + "max_staleness_prefix": { + Type: pluginsdk.TypeInt, + Optional: true, + Default: 100, + }, + }, + }, + }, + + "geo_location": { + Type: pluginsdk.TypeSet, + Required: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "id": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "location": commonschema.LocationWithoutForceNew(), + + "failover_priority": { + Type: pluginsdk.TypeInt, + Required: true, + }, + + "zone_redundant": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + }, + }, + }, + + "capabilities": { + Type: pluginsdk.TypeSet, + Optional: true, + Computed: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + }, + }, + }, + }, + + "is_virtual_network_filter_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "virtual_network_rule": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "id": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: azure.ValidateResourceID, + }, + "ignore_missing_vnet_service_endpoint": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + }, + }, + }, + + "access_key_metadata_writes_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + }, + + "local_authentication_disabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "mongo_server_version": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + + "multiple_write_locations_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Computed: true, + }, + + "network_acl_bypass_for_azure_services": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "network_acl_bypass_ids": { + Type: pluginsdk.TypeList, + Optional: true, Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "partition_merge_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "burst_capacity_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "backup": { + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "type": { + Type: pluginsdk.TypeString, + Required: true, + }, + + // Though `tier` has the default value `Continuous30Days` but `tier` is only for the backup type `Continuous`. So the default value isn't added in the property schema. + "tier": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + + "interval_in_minutes": { + Type: pluginsdk.TypeInt, + Optional: true, + Computed: true, + }, + + "retention_in_hours": { + Type: pluginsdk.TypeInt, + Optional: true, + Computed: true, + }, + + "storage_redundancy": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + }, + }, + }, + }, + + "identity": commonschema.SystemAssignedUserAssignedIdentityOptional(), + + "cors_rule": common.SchemaCorsRule(), + + "connection_strings": { + Type: pluginsdk.TypeList, + Computed: true, + Sensitive: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Sensitive: true, + }, + }, + + "enable_multiple_write_locations": { + Type: pluginsdk.TypeBool, + Optional: true, + Computed: true, + }, + + "enable_free_tier": { + Type: pluginsdk.TypeBool, + Optional: true, + Computed: true, + }, + + "enable_automatic_failover": { + Type: pluginsdk.TypeBool, + Optional: true, + Computed: true, + }, + + "restore": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "source_cosmosdb_account_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "restore_timestamp_in_utc": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "database": { + Type: pluginsdk.TypeSet, + Optional: true, + ForceNew: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "collection_names": { + Type: pluginsdk.TypeSet, + Optional: true, + ForceNew: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + }, + }, + }, + + "gremlin_database": { + Type: pluginsdk.TypeList, + Optional: true, + ForceNew: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "graph_names": { + Type: pluginsdk.TypeList, + Optional: true, + ForceNew: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + }, + }, + }, + + "tables_to_restore": { + Type: pluginsdk.TypeList, + Optional: true, + ForceNew: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + }, + }, + }, + + "endpoint": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "read_endpoints": { + Type: pluginsdk.TypeList, + Computed: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "write_endpoints": { + Type: pluginsdk.TypeList, + Computed: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "primary_key": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_key": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "primary_readonly_key": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_readonly_key": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "primary_sql_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_sql_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "primary_readonly_sql_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_readonly_sql_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "primary_mongodb_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_mongodb_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "primary_readonly_mongodb_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "secondary_readonly_mongodb_connection_string": { + Type: pluginsdk.TypeString, + Computed: true, + Sensitive: true, + }, + + "tags": commonschema.Tags(), + } +} + +func (c CosmosDBAccountV0toV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + ipfString := rawState["ip_range_filter"].(string) + ipfSet := make([]string, 0) + if ipfString != "" { + ipfSet = strings.Split(ipfString, ",") + } + rawState["ip_range_filter"] = ipfSet + + return rawState, nil + } +} From 95fff2d87f551c355d8e2824a154b1f30535d3d2 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 4 Sep 2024 12:55:18 +0200 Subject: [PATCH 2/6] remove pre4.0 flagged code --- internal/services/cosmos/common/ip_rules.go | 4 +- .../cosmos/cosmosdb_account_data_source.go | 42 +--- .../cosmos/cosmosdb_account_resource.go | 210 ++---------------- 3 files changed, 22 insertions(+), 234 deletions(-) diff --git a/internal/services/cosmos/common/ip_rules.go b/internal/services/cosmos/common/ip_rules.go index d66e66731cb9..540e436c3541 100644 --- a/internal/services/cosmos/common/ip_rules.go +++ b/internal/services/cosmos/common/ip_rules.go @@ -10,8 +10,8 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/utils" ) -// CosmosDBIpRulesToIpRangeFilterThreePointOh todo Remove for 4.0 -func CosmosDBIpRulesToIpRangeFilterThreePointOh(ipRules *[]cosmosdb.IPAddressOrRange) string { +// CosmosDBIpRulesToIpRangeFilterDataSource todo Remove for 4.0 +func CosmosDBIpRulesToIpRangeFilterDataSource(ipRules *[]cosmosdb.IPAddressOrRange) string { ipRangeFilter := make([]string, 0) if ipRules != nil { for _, ipRule := range *ipRules { diff --git a/internal/services/cosmos/cosmosdb_account_data_source.go b/internal/services/cosmos/cosmosdb_account_data_source.go index 872d1c54fcf1..d6078ec64a10 100644 --- a/internal/services/cosmos/cosmosdb_account_data_source.go +++ b/internal/services/cosmos/cosmosdb_account_data_source.go @@ -16,7 +16,6 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2024-05-15/cosmosdb" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/common" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -249,35 +248,6 @@ func dataSourceCosmosDbAccount() *pluginsdk.Resource { }, } - if !features.FourPointOhBeta() { - dataSource.Schema["connection_strings"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Computed: true, - Sensitive: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - Sensitive: true, - }, - Deprecated: "This property has been superseded by the primary and secondary connection strings for sql, mongodb and readonly and will be removed in v4.0 of the AzureRM provider", - } - dataSource.Schema["enable_free_tier"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeBool, - Computed: true, - Deprecated: "This property has been renamed to `free_tier_enabled` and will be removed in v4.0 of the AzureRM provider", - } - dataSource.Schema["enable_automatic_failover"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeBool, - Computed: true, - Deprecated: "This property has been renamed to `automatic_failover_enabled` and will be removed in v4.0 of the AzureRM provider", - } - dataSource.Schema["enable_multiple_write_locations"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeBool, - Computed: true, - Deprecated: "This property has been renamed to `multiple_write_locations_enabled` and will be removed in v4.0 of the AzureRM provider", - } - - } - return dataSource } @@ -309,15 +279,9 @@ func dataSourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{}) if props := model.Properties; props != nil { d.Set("offer_type", string(pointer.From(props.DatabaseAccountOfferType))) - d.Set("ip_range_filter", common.CosmosDBIpRulesToIpRangeFilterThreePointOh(props.IPRules)) + d.Set("ip_range_filter", common.CosmosDBIpRulesToIpRangeFilterDataSource(props.IPRules)) d.Set("endpoint", props.DocumentEndpoint) d.Set("is_virtual_network_filter_enabled", props.IsVirtualNetworkFilterEnabled) - if !features.FourPointOhBeta() { - d.Set("enable_free_tier", props.EnableFreeTier) - d.Set("enable_automatic_failover", props.EnableAutomaticFailover) - d.Set("enable_multiple_write_locations", props.EnableMultipleWriteLocations) - } - d.Set("free_tier_enabled", props.EnableFreeTier) d.Set("automatic_failover_enabled", props.EnableAutomaticFailover) d.Set("multiple_write_locations_enabled", props.EnableMultipleWriteLocations) @@ -440,10 +404,6 @@ func dataSourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{}) } } } - - if !features.FourPointOhBeta() { - d.Set("connection_strings", connStrings) - } } } return nil diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index 42d77935438b..107ebf99635a 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -25,7 +25,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/common" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/parse" @@ -125,7 +124,7 @@ func suppressConsistencyPolicyStalenessConfiguration(_, _, _ string, d *pluginsd } func resourceCosmosDbAccount() *pluginsdk.Resource { - resource := &pluginsdk.Resource{ + return &pluginsdk.Resource{ Create: resourceCosmosDbAccountCreate, Read: resourceCosmosDbAccountRead, Update: resourceCosmosDbAccountUpdate, @@ -251,15 +250,9 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { // per Microsoft's documentation, as of April 1 2023 the default minimal TLS version for all new accounts is 1.2 "minimal_tls_version": { - Type: pluginsdk.TypeString, - Optional: true, - Computed: !features.FourPointOhBeta(), - Default: func() interface{} { - if !features.FourPointOhBeta() { - return nil - } - return string(cosmosdb.MinimalTlsVersionTlsOneTwo) - }(), + Type: pluginsdk.TypeString, + Optional: true, + Default: string(cosmosdb.MinimalTlsVersionTlsOneTwo), ValidateFunc: validation.StringInSlice(cosmosdb.PossibleValuesForMinimalTlsVersion(), false), }, @@ -301,44 +294,20 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { }, false), }, - "ip_range_filter": func() *schema.Schema { - if features.FourPointOhBeta() { - return &schema.Schema{ - Type: pluginsdk.TypeSet, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.Any(validation.IsCIDR, validation.IsIPv4Address), - }, - } - } - return &schema.Schema{ - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringMatch( - regexp.MustCompile(`^(\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/([1-2][0-9]|3[0-2]|[3-9]))?\b[,]?)*$`), - "Cosmos DB ip_range_filter must be a set of CIDR IP addresses separated by commas with no spaces: '10.0.0.1,10.0.0.2,10.20.0.0/16'", - ), - } - }(), + "ip_range_filter": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + ValidateFunc: validation.Any(validation.IsCIDR, validation.IsIPv4Address), + }, + }, "free_tier_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: func() interface{} { - if !features.FourPointOhBeta() { - return nil - } - return false - }(), - ForceNew: features.FourPointOhBeta(), - Computed: !features.FourPointOhBeta(), - ConflictsWith: func() []string { - if !features.FourPointOhBeta() { - return []string{"enable_free_tier"} - } - return []string{} - }(), + Default: false, + ForceNew: true, }, "analytical_storage_enabled": { @@ -356,19 +325,7 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { "automatic_failover_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: func() interface{} { - if !features.FourPointOhBeta() { - return nil - } - return false - }(), - Computed: !features.FourPointOhBeta(), - ConflictsWith: func() []string { - if !features.FourPointOhBeta() { - return []string{"enable_automatic_failover"} - } - return []string{} - }(), + Default: false, }, "key_vault_key_id": { @@ -532,19 +489,7 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { "multiple_write_locations_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: func() interface{} { - if !features.FourPointOhBeta() { - return nil - } - return false - }(), - Computed: !features.FourPointOhBeta(), - ConflictsWith: func() []string { - if !features.FourPointOhBeta() { - return []string{"enable_multiple_write_locations"} - } - return []string{} - }(), + Default: false, }, "network_acl_bypass_for_azure_services": { @@ -811,57 +756,6 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { "tags": commonschema.Tags(), }, } - - if !features.FourPointOhBeta() { - resource.Schema["connection_strings"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Computed: true, - Sensitive: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - Sensitive: true, - }, - Deprecated: "This property has been superseded by the primary and secondary connection strings for sql, mongodb and readonly and will be removed in v4.0 of the AzureRM provider", - } - resource.Schema["enable_multiple_write_locations"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeBool, - Optional: true, - Computed: true, - ConflictsWith: func() []string { - if !features.FourPointOhBeta() { - return []string{"multiple_write_locations_enabled"} - } - return []string{} - }(), - Deprecated: "This property has been superseded by `multiple_write_locations_enabled` and will be removed in v4.0 of the AzureRM Provider", - } - resource.Schema["enable_free_tier"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeBool, - Optional: true, - Computed: true, - ConflictsWith: func() []string { - if !features.FourPointOhBeta() { - return []string{"free_tier_enabled"} - } - return []string{} - }(), - Deprecated: "This property has been superseded by `free_tier_enabled` and will be removed in v4.0 of the AzureRM Provider", - } - resource.Schema["enable_automatic_failover"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeBool, - Optional: true, - Computed: true, - ConflictsWith: func() []string { - if !features.FourPointOhBeta() { - return []string{"automatic_failover_enabled"} - } - return []string{} - }(), - Deprecated: "This property has been superseded by `automatic_failover_enabled` and will be removed in v4.0 of the AzureRM Provider", - } - } - - return resource } func resourceCosmosDbAccountCreate(d *pluginsdk.ResourceData, meta interface{}) error { @@ -893,33 +787,13 @@ func resourceCosmosDbAccountCreate(d *pluginsdk.ResourceData, meta interface{}) offerType := d.Get("offer_type").(string) var ipRangeFilter *[]cosmosdb.IPAddressOrRange - if features.FourPointOhBeta() { - ipRangeFilter = common.CosmosDBIpRangeFilterToIpRules(*utils.ExpandStringSlice(d.Get("ip_range_filter").(*pluginsdk.Set).List())) - } else { - ipRangeFilter = common.CosmosDBIpRangeFilterToIpRulesThreePointOh(d.Get("ip_range_filter").(string)) - } - + ipRangeFilter = common.CosmosDBIpRangeFilterToIpRules(*utils.ExpandStringSlice(d.Get("ip_range_filter").(*pluginsdk.Set).List())) isVirtualNetworkFilterEnabled := d.Get("is_virtual_network_filter_enabled").(bool) enableFreeTier := d.Get("free_tier_enabled").(bool) enableAutomaticFailover := d.Get("automatic_failover_enabled").(bool) enableMultipleWriteLocations := d.Get("multiple_write_locations_enabled").(bool) - if !features.FourPointOhBeta() { - // nolint : staticcheck - if v, ok := d.GetOkExists("enable_automatic_failover"); ok { - enableAutomaticFailover = v.(bool) - } - // nolint : staticcheck - if v, ok := d.GetOkExists("enable_multiple_write_locations"); ok { - enableMultipleWriteLocations = v.(bool) - } - // nolint : staticcheck - if v, ok := d.GetOkExists("enable_free_tier"); ok { - enableFreeTier = v.(bool) - } - } - partitionMergeEnabled := d.Get("partition_merge_enabled").(bool) burstCapacityEnabled := d.Get("burst_capacity_enabled").(bool) enableAnalyticalStorage := d.Get("analytical_storage_enabled").(bool) @@ -1153,12 +1027,6 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) enableAnalyticalStorage := pointer.To(d.Get("analytical_storage_enabled").(bool)) disableLocalAuthentication := pointer.To(d.Get("local_authentication_disabled").(bool)) enableAutomaticFailover := pointer.To(d.Get("automatic_failover_enabled").(bool)) - if !features.FourPointOhBeta() { - // nolint : staticcheck - if v, ok := d.GetOkExists("enable_automatic_failover"); ok && v.(bool) { - enableAutomaticFailover = pointer.To(v.(bool)) - } - } networkByPass := cosmosdb.NetworkAclBypassNone if d.Get("network_acl_bypass_for_azure_services").(bool) { @@ -1166,11 +1034,7 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) } var ipRangeFilter *[]cosmosdb.IPAddressOrRange - if features.FourPointOhBeta() { - ipRangeFilter = common.CosmosDBIpRangeFilterToIpRules(*utils.ExpandStringSlice(d.Get("ip_range_filter").(*pluginsdk.Set).List())) - } else { - ipRangeFilter = common.CosmosDBIpRangeFilterToIpRulesThreePointOh(d.Get("ip_range_filter").(string)) - } + ipRangeFilter = common.CosmosDBIpRangeFilterToIpRules(*utils.ExpandStringSlice(d.Get("ip_range_filter").(*pluginsdk.Set).List())) publicNetworkAccess := cosmosdb.PublicNetworkAccessEnabled if enabled := d.Get("public_network_access_enabled").(bool); !enabled { @@ -1301,24 +1165,6 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) } // Update the following properties independently after the initial CreateOrUpdate... - if !features.FourPointOhBeta() { - if d.HasChange("enable_multiple_write_locations") { - log.Printf("[INFO] Updating AzureRM Cosmos DB Account: Updating 'EnableMultipleWriteLocations'") - - enableMultipleWriteLocations := pointer.To(d.Get("enable_multiple_write_locations").(bool)) - if props.EnableMultipleWriteLocations != enableMultipleWriteLocations { - account.Properties.EnableMultipleWriteLocations = enableMultipleWriteLocations - - // Update the database... - if err = resourceCosmosDbAccountApiCreateOrUpdate(client, ctx, *id, account, d); err != nil { - return fmt.Errorf("updating %q EnableMultipleWriteLocations: %+v", id, err) - } - } - } else { - log.Printf("[INFO] [SKIP] AzureRM Cosmos DB Account: Updating 'EnableMultipleWriteLocations' [NO CHANGE]") - } - } - if d.HasChange("multiple_write_locations_enabled") { log.Printf("[INFO] Updating AzureRM Cosmos DB Account: Updating 'EnableMultipleWriteLocations'") @@ -1526,24 +1372,10 @@ func resourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{}) er if props := existing.Model.Properties; props != nil { d.Set("offer_type", pointer.From(props.DatabaseAccountOfferType)) - if features.FourPointOhBeta() { - d.Set("ip_range_filter", common.CosmosDBIpRulesToIpRangeFilter(props.IPRules)) - } else { - d.Set("ip_range_filter", common.CosmosDBIpRulesToIpRangeFilterThreePointOh(props.IPRules)) - } + d.Set("ip_range_filter", common.CosmosDBIpRulesToIpRangeFilter(props.IPRules)) d.Set("endpoint", props.DocumentEndpoint) - if !features.FourPointOhBeta() { - d.Set("enable_free_tier", props.EnableFreeTier) - if v := existing.Model.Properties.EnableMultipleWriteLocations; v != nil { - d.Set("enable_multiple_write_locations", props.EnableMultipleWriteLocations) - } - if v := existing.Model.Properties.EnableAutomaticFailover; v != nil { - d.Set("enable_automatic_failover", props.EnableAutomaticFailover) - } - } - d.Set("free_tier_enabled", props.EnableFreeTier) d.Set("analytical_storage_enabled", props.EnableAnalyticalStorage) d.Set("public_network_access_enabled", pointer.From(props.PublicNetworkAccess) == cosmosdb.PublicNetworkAccessEnabled) @@ -1702,10 +1534,6 @@ func resourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{}) er } } - if !features.FourPointOhBeta() { - d.Set("connection_strings", connStrings) - } - return tags.FlattenAndSet(d, existing.Model.Tags) } From bc06b117b07350ffe782f76a464239fe626954ba Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 4 Sep 2024 13:17:11 +0200 Subject: [PATCH 3/6] use static schema instead of func refs for future stability --- .../cosmos/migration/cosmosdb_account.go | 122 +++++++++++++++--- 1 file changed, 106 insertions(+), 16 deletions(-) diff --git a/internal/services/cosmos/migration/cosmosdb_account.go b/internal/services/cosmos/migration/cosmosdb_account.go index fed9c898ec61..9c8ecfe9734b 100644 --- a/internal/services/cosmos/migration/cosmosdb_account.go +++ b/internal/services/cosmos/migration/cosmosdb_account.go @@ -4,11 +4,9 @@ import ( "context" "strings" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2024-05-15/cosmosdb" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/common" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) @@ -23,9 +21,20 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { Required: true, }, - "location": commonschema.Location(), + "location": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: location.EnhancedValidate, + StateFunc: location.StateFunc, + DiffSuppressFunc: location.DiffSuppressFunc, + }, - "resource_group_name": commonschema.ResourceGroupName(), + "resource_group_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, "offer_type": { Type: pluginsdk.TypeString, @@ -62,7 +71,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { }, }, - // per Microsoft's documentation, as of April 1 2023 the default minimal TLS version for all new accounts is 1.2 "minimal_tls_version": { Type: pluginsdk.TypeString, Optional: true, @@ -76,8 +84,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { ForceNew: true, }, - // Per Documentation: "The default identity needs to be explicitly set by the users." This should not be optional without a default anymore. - // DOC: https://learn.microsoft.com/en-us/java/api/com.azure.resourcemanager.cosmos.models.databaseaccountupdateparameters?view=azure-java-stable#method-details "default_identity_type": { Type: pluginsdk.TypeString, Optional: true, @@ -116,7 +122,7 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "automatic_failover_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Computed: !features.FourPointOhBeta(), + Computed: true, }, "key_vault_key_id": { @@ -136,14 +142,12 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { Required: true, }, - // This value can only change if the 'consistency_level' is set to 'BoundedStaleness' "max_interval_in_seconds": { Type: pluginsdk.TypeInt, Optional: true, Default: 5, }, - // This value can only change if the 'consistency_level' is set to 'BoundedStaleness' "max_staleness_prefix": { Type: pluginsdk.TypeInt, Optional: true, @@ -163,7 +167,13 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { Computed: true, }, - "location": commonschema.LocationWithoutForceNew(), + "location": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: location.EnhancedValidate, + StateFunc: location.StateFunc, + DiffSuppressFunc: location.DiffSuppressFunc, + }, "failover_priority": { Type: pluginsdk.TypeInt, @@ -279,7 +289,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { Required: true, }, - // Though `tier` has the default value `Continuous30Days` but `tier` is only for the backup type `Continuous`. So the default value isn't added in the property schema. "tier": { Type: pluginsdk.TypeString, Optional: true, @@ -307,9 +316,84 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { }, }, - "identity": commonschema.SystemAssignedUserAssignedIdentityOptional(), + "identity": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "type": { + Type: pluginsdk.TypeString, + Required: true, + }, + "identity_ids": { + Type: pluginsdk.TypeSet, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + "principal_id": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "tenant_id": { + Type: pluginsdk.TypeString, + Computed: true, + }, + }, + }, + }, - "cors_rule": common.SchemaCorsRule(), + "cors_rule": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "allowed_origins": { + Type: pluginsdk.TypeList, + Required: true, + MaxItems: 64, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "exposed_headers": { + Type: pluginsdk.TypeList, + Required: true, + MaxItems: 64, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "allowed_headers": { + Type: pluginsdk.TypeList, + Required: true, + MaxItems: 64, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "allowed_methods": { + Type: pluginsdk.TypeList, + Required: true, + MaxItems: 64, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "max_age_in_seconds": { + Type: pluginsdk.TypeInt, + Optional: true, + }, + }, + }, + }, "connection_strings": { Type: pluginsdk.TypeList, @@ -510,7 +594,13 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { Sensitive: true, }, - "tags": commonschema.Tags(), + "tags": { + Type: pluginsdk.TypeMap, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, } } From 75002aa2c4be3459f3a8d9919cd2272b211d70ed Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 4 Sep 2024 13:31:14 +0200 Subject: [PATCH 4/6] remove extraneous schema attribs from state migration --- .../cosmos/migration/cosmosdb_account.go | 61 ++----------------- 1 file changed, 6 insertions(+), 55 deletions(-) diff --git a/internal/services/cosmos/migration/cosmosdb_account.go b/internal/services/cosmos/migration/cosmosdb_account.go index 9c8ecfe9734b..cbc6cb1ad0e9 100644 --- a/internal/services/cosmos/migration/cosmosdb_account.go +++ b/internal/services/cosmos/migration/cosmosdb_account.go @@ -4,9 +4,6 @@ import ( "context" "strings" - "github.com/hashicorp/go-azure-helpers/resourcemanager/location" - "github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2024-05-15/cosmosdb" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) @@ -22,18 +19,13 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { }, "location": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: location.EnhancedValidate, - StateFunc: location.StateFunc, - DiffSuppressFunc: location.DiffSuppressFunc, + Type: pluginsdk.TypeString, + Required: true, }, "resource_group_name": { Type: pluginsdk.TypeString, Required: true, - ForceNew: true, }, "offer_type": { @@ -44,8 +36,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "analytical_storage": { Type: pluginsdk.TypeList, Optional: true, - Computed: true, - MaxItems: 1, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "schema_type": { @@ -60,7 +50,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { Type: pluginsdk.TypeList, Optional: true, Computed: true, - MaxItems: 1, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "total_throughput_limit": { @@ -81,20 +70,16 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { Type: pluginsdk.TypeString, Optional: true, Computed: true, - ForceNew: true, }, "default_identity_type": { Type: pluginsdk.TypeString, Optional: true, - Default: "FirstPartyIdentity", }, "kind": { Type: pluginsdk.TypeString, Optional: true, - ForceNew: true, - Default: string(cosmosdb.DatabaseAccountKindGlobalDocumentDB), }, "ip_range_filter": { @@ -110,13 +95,11 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "analytical_storage_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: false, }, "public_network_access_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: true, }, "automatic_failover_enabled": { @@ -128,13 +111,11 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "key_vault_key_id": { Type: pluginsdk.TypeString, Optional: true, - ForceNew: true, }, "consistency_policy": { Type: pluginsdk.TypeList, Required: true, - MaxItems: 1, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "consistency_level": { @@ -145,13 +126,11 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "max_interval_in_seconds": { Type: pluginsdk.TypeInt, Optional: true, - Default: 5, }, "max_staleness_prefix": { Type: pluginsdk.TypeInt, Optional: true, - Default: 100, }, }, }, @@ -168,11 +147,8 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { }, "location": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: location.EnhancedValidate, - StateFunc: location.StateFunc, - DiffSuppressFunc: location.DiffSuppressFunc, + Type: pluginsdk.TypeString, + Required: true, }, "failover_priority": { @@ -183,7 +159,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "zone_redundant": { Type: pluginsdk.TypeBool, Optional: true, - Default: false, }, }, }, @@ -206,7 +181,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "is_virtual_network_filter_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: false, }, "virtual_network_rule": { @@ -215,14 +189,12 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "id": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: azure.ValidateResourceID, + Type: pluginsdk.TypeString, + Required: true, }, "ignore_missing_vnet_service_endpoint": { Type: pluginsdk.TypeBool, Optional: true, - Default: false, }, }, }, @@ -231,13 +203,11 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "access_key_metadata_writes_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: true, }, "local_authentication_disabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: false, }, "mongo_server_version": { @@ -255,7 +225,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "network_acl_bypass_for_azure_services": { Type: pluginsdk.TypeBool, Optional: true, - Default: false, }, "network_acl_bypass_ids": { @@ -268,20 +237,17 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "partition_merge_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: false, }, "burst_capacity_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Default: false, }, "backup": { Type: pluginsdk.TypeList, Optional: true, Computed: true, - MaxItems: 1, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "type": { @@ -319,7 +285,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "identity": { Type: pluginsdk.TypeList, Optional: true, - MaxItems: 1, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "type": { @@ -348,13 +313,11 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "cors_rule": { Type: pluginsdk.TypeList, Optional: true, - MaxItems: 1, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "allowed_origins": { Type: pluginsdk.TypeList, Required: true, - MaxItems: 64, Elem: &pluginsdk.Schema{ Type: pluginsdk.TypeString, }, @@ -363,7 +326,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "exposed_headers": { Type: pluginsdk.TypeList, Required: true, - MaxItems: 64, Elem: &pluginsdk.Schema{ Type: pluginsdk.TypeString, }, @@ -372,7 +334,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "allowed_headers": { Type: pluginsdk.TypeList, Required: true, - MaxItems: 64, Elem: &pluginsdk.Schema{ Type: pluginsdk.TypeString, }, @@ -381,7 +342,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "allowed_methods": { Type: pluginsdk.TypeList, Required: true, - MaxItems: 64, Elem: &pluginsdk.Schema{ Type: pluginsdk.TypeString, }, @@ -426,7 +386,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "restore": { Type: pluginsdk.TypeList, Optional: true, - MaxItems: 1, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "source_cosmosdb_account_id": { @@ -438,25 +397,21 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "restore_timestamp_in_utc": { Type: pluginsdk.TypeString, Required: true, - ForceNew: true, }, "database": { Type: pluginsdk.TypeSet, Optional: true, - ForceNew: true, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "name": { Type: pluginsdk.TypeString, Required: true, - ForceNew: true, }, "collection_names": { Type: pluginsdk.TypeSet, Optional: true, - ForceNew: true, Elem: &pluginsdk.Schema{ Type: pluginsdk.TypeString, }, @@ -468,19 +423,16 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "gremlin_database": { Type: pluginsdk.TypeList, Optional: true, - ForceNew: true, Elem: &pluginsdk.Resource{ Schema: map[string]*pluginsdk.Schema{ "name": { Type: pluginsdk.TypeString, Required: true, - ForceNew: true, }, "graph_names": { Type: pluginsdk.TypeList, Optional: true, - ForceNew: true, Elem: &pluginsdk.Schema{ Type: pluginsdk.TypeString, }, @@ -492,7 +444,6 @@ func (c CosmosDBAccountV0toV1) Schema() map[string]*pluginsdk.Schema { "tables_to_restore": { Type: pluginsdk.TypeList, Optional: true, - ForceNew: true, Elem: &pluginsdk.Schema{ Type: pluginsdk.TypeString, }, From dab922105d94c8af1be2aab85024bb809792695a Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 4 Sep 2024 14:55:09 +0200 Subject: [PATCH 5/6] linting gosimple --- internal/services/cosmos/cosmosdb_account_resource.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index 107ebf99635a..cf320f74fd58 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -786,8 +786,7 @@ func resourceCosmosDbAccountCreate(d *pluginsdk.ResourceData, meta interface{}) kind := d.Get("kind").(string) offerType := d.Get("offer_type").(string) - var ipRangeFilter *[]cosmosdb.IPAddressOrRange - ipRangeFilter = common.CosmosDBIpRangeFilterToIpRules(*utils.ExpandStringSlice(d.Get("ip_range_filter").(*pluginsdk.Set).List())) + ipRangeFilter := common.CosmosDBIpRangeFilterToIpRules(*utils.ExpandStringSlice(d.Get("ip_range_filter").(*pluginsdk.Set).List())) isVirtualNetworkFilterEnabled := d.Get("is_virtual_network_filter_enabled").(bool) enableFreeTier := d.Get("free_tier_enabled").(bool) From aff9affe5064c6b49ad0dd83382971423f362bc6 Mon Sep 17 00:00:00 2001 From: jackofallops Date: Wed, 4 Sep 2024 15:01:57 +0200 Subject: [PATCH 6/6] linting gosimple 2 --- internal/services/cosmos/cosmosdb_account_resource.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index cf320f74fd58..fded86af195c 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -1032,8 +1032,7 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) networkByPass = cosmosdb.NetworkAclBypassAzureServices } - var ipRangeFilter *[]cosmosdb.IPAddressOrRange - ipRangeFilter = common.CosmosDBIpRangeFilterToIpRules(*utils.ExpandStringSlice(d.Get("ip_range_filter").(*pluginsdk.Set).List())) + ipRangeFilter := common.CosmosDBIpRangeFilterToIpRules(*utils.ExpandStringSlice(d.Get("ip_range_filter").(*pluginsdk.Set).List())) publicNetworkAccess := cosmosdb.PublicNetworkAccessEnabled if enabled := d.Get("public_network_access_enabled").(bool); !enabled {