Skip to content

Commit

Permalink
azurerm_cosmosdb_account - deprecate connection_strings and renam…
Browse files Browse the repository at this point in the history
…e `enable_*` properties (#25510)

* deprecate connection_strings and rename enable_* properties to *_enabled in data source

* rename enable_ to _enabled

* update create, update and read for new properties

* imports and lint

* fix property name in create for enable_multiple_write_locations

* update tests and docs

* update deprecated property enable_automatic_failover only when set to true
  • Loading branch information
stephybun committed Apr 8, 2024
1 parent 96507b9 commit 0ebb8ca
Show file tree
Hide file tree
Showing 5 changed files with 401 additions and 104 deletions.
70 changes: 48 additions & 22 deletions internal/services/cosmos/cosmosdb_account_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2023-04-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"
)

func dataSourceCosmosDbAccount() *pluginsdk.Resource {
return &pluginsdk.Resource{
dataSource := &pluginsdk.Resource{
Read: dataSourceCosmosDbAccountRead,

Timeouts: &pluginsdk.ResourceTimeout{
Expand Down Expand Up @@ -56,14 +57,12 @@ func dataSourceCosmosDbAccount() *pluginsdk.Resource {
Computed: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_free_tier": {
"free_tier_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_automatic_failover": {
"automatic_failover_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},
Expand Down Expand Up @@ -150,8 +149,7 @@ func dataSourceCosmosDbAccount() *pluginsdk.Resource {
Computed: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_multiple_write_locations": {
"multiple_write_locations_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},
Expand Down Expand Up @@ -201,16 +199,6 @@ func dataSourceCosmosDbAccount() *pluginsdk.Resource {
Sensitive: true,
},

"connection_strings": {
Type: pluginsdk.TypeList,
Computed: true,
Sensitive: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Sensitive: true,
},
},

"primary_sql_connection_string": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -260,6 +248,37 @@ 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
}

func dataSourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -293,8 +312,15 @@ func dataSourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{})
d.Set("ip_range_filter", common.CosmosDBIpRulesToIpRangeFilterThreePointOh(props.IPRules))
d.Set("endpoint", props.DocumentEndpoint)
d.Set("is_virtual_network_filter_enabled", props.IsVirtualNetworkFilterEnabled)
d.Set("enable_free_tier", props.EnableFreeTier)
d.Set("enable_automatic_failover", props.EnableAutomaticFailover)
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)

if v := props.KeyVaultKeyUri; v != nil {
d.Set("key_vault_key_id", v)
Expand Down Expand Up @@ -368,8 +394,6 @@ func dataSourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{})
if err := d.Set("write_endpoints", writeEndpoints); err != nil {
return fmt.Errorf("setting `write_endpoints`: %s", err)
}

d.Set("enable_multiple_write_locations", props.EnableMultipleWriteLocations)
}

if err := tags.FlattenAndSet(d, model.Tags); err != nil {
Expand Down Expand Up @@ -417,7 +441,9 @@ func dataSourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{})
}
}

d.Set("connection_strings", connStrings)
if !features.FourPointOhBeta() {
d.Set("connection_strings", connStrings)
}
}
}
return nil
Expand Down
Loading

0 comments on commit 0ebb8ca

Please sign in to comment.