Skip to content

Commit

Permalink
azurerm_cosmosdb_account - remove default value for `default_identi…
Browse files Browse the repository at this point in the history
…ty_type` per new API behavior (#19956)
  • Loading branch information
neil-yechenwei authored Jan 12, 2023
1 parent 97cab67 commit 6a4518b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func resourceCosmosDbAccount() *pluginsdk.Resource {
"default_identity_type": {
Type: pluginsdk.TypeString,
Optional: true,
Default: "FirstPartyIdentity",
Computed: true,
ValidateFunc: validation.Any(
validation.StringMatch(regexp.MustCompile(`^UserAssignedIdentity(.)+$`), "It may start with `UserAssignedIdentity`"),
validation.StringInSlice([]string{
Expand Down Expand Up @@ -750,11 +750,14 @@ func resourceCosmosDbAccountCreate(d *pluginsdk.ResourceData, meta interface{})
NetworkACLBypass: networkByPass,
NetworkACLBypassResourceIds: utils.ExpandStringSlice(d.Get("network_acl_bypass_ids").([]interface{})),
DisableLocalAuth: utils.Bool(disableLocalAuthentication),
DefaultIdentity: utils.String(d.Get("default_identity_type").(string)),
},
Tags: tags.Expand(t),
}

if v, ok := d.GetOk("default_identity_type"); ok {
account.DatabaseAccountCreateUpdateProperties.DefaultIdentity = utils.String(v.(string))
}

if v, ok := d.GetOk("analytical_storage"); ok {
account.DatabaseAccountCreateUpdateProperties.AnalyticalStorageConfiguration = expandCosmosDBAccountAnalyticalStorageConfiguration(v.([]interface{}))
}
Expand Down Expand Up @@ -948,11 +951,15 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
NetworkACLBypass: networkByPass,
NetworkACLBypassResourceIds: utils.ExpandStringSlice(d.Get("network_acl_bypass_ids").([]interface{})),
DisableLocalAuth: utils.Bool(disableLocalAuthentication),
DefaultIdentity: utils.String(d.Get("default_identity_type").(string)),
},
Tags: tags.Expand(t),
}

// d.GetOk cannot identify whether user sets the property that is added Optional and Computed when the property isn't set in TF config file. Because d.GetOk always gets the property value from the last apply when the property isn't set in TF config file. So it has to identify it using `d.GetRawConfig()`
if v := d.GetRawConfig().AsValueMap()["default_identity_type"]; !v.IsNull() {
account.DatabaseAccountCreateUpdateProperties.DefaultIdentity = utils.String(v.AsString())
}

if v, ok := d.GetOk("analytical_storage"); ok {
account.DatabaseAccountCreateUpdateProperties.AnalyticalStorageConfiguration = expandCosmosDBAccountAnalyticalStorageConfiguration(v.([]interface{}))
}
Expand Down Expand Up @@ -1089,11 +1096,7 @@ func resourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{}) er
d.Set("enable_free_tier", props.EnableFreeTier)
d.Set("analytical_storage_enabled", props.EnableAnalyticalStorage)
d.Set("public_network_access_enabled", props.PublicNetworkAccess == documentdb.PublicNetworkAccessEnabled)
defaultIdentity := props.DefaultIdentity
if defaultIdentity == nil || *defaultIdentity == "" {
defaultIdentity = utils.String("FirstPartyIdentity")
}
d.Set("default_identity_type", defaultIdentity)
d.Set("default_identity_type", props.DefaultIdentity)
d.Set("create_mode", props.CreateMode)

if v := resp.IsVirtualNetworkFilterEnabled; v != nil {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/cosmosdb_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The following arguments are supported:

~> **NOTE:** `create_mode` only works when `backup.type` is `Continuous`.

* `default_identity_type` - (Optional) The default identity for accessing Key Vault. Possible values are `FirstPartyIdentity`, `SystemAssignedIdentity` or start with `UserAssignedIdentity`. Defaults to `FirstPartyIdentity`.
* `default_identity_type` - (Optional) The default identity for accessing Key Vault. Possible values are `FirstPartyIdentity`, `SystemAssignedIdentity` or start with `UserAssignedIdentity`.

* `kind` - (Optional) Specifies the Kind of CosmosDB to create - possible values are `GlobalDocumentDB`, `MongoDB` and `Parse`. Defaults to `GlobalDocumentDB`. Changing this forces a new resource to be created.

Expand Down

0 comments on commit 6a4518b

Please sign in to comment.