Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_cosmosdb_account - deprecate connection_strings and rename enable_* properties #25510

Merged
merged 7 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading