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

Support for local_authentication_disabled in azurerm_cosmosdb_account #13237

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions internal/services/cosmos/cosmosdb_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ func resourceCosmosDbAccount() *pluginsdk.Resource {
Default: true,
},

"local_authentication_disabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"mongo_server_version": {
Type: pluginsdk.TypeString,
Optional: true,
Expand Down Expand Up @@ -493,6 +499,7 @@ func resourceCosmosDbAccountCreate(d *pluginsdk.ResourceData, meta interface{})
enableAutomaticFailover := d.Get("enable_automatic_failover").(bool)
enableMultipleWriteLocations := d.Get("enable_multiple_write_locations").(bool)
enableAnalyticalStorage := d.Get("analytical_storage_enabled").(bool)
localAuthenticationDisabled := d.Get("local_authentication_disabled").(bool)

r, err := client.CheckNameExists(ctx, name)
if err != nil {
Expand Down Expand Up @@ -541,6 +548,7 @@ func resourceCosmosDbAccountCreate(d *pluginsdk.ResourceData, meta interface{})
DisableKeyBasedMetadataWriteAccess: utils.Bool(!d.Get("access_key_metadata_writes_enabled").(bool)),
NetworkACLBypass: networkByPass,
NetworkACLBypassResourceIds: utils.ExpandStringSlice(d.Get("network_acl_bypass_ids").([]interface{})),
DisableLocalAuth: utils.Bool(localAuthenticationDisabled),
},
Tags: tags.Expand(t),
}
Expand Down Expand Up @@ -613,6 +621,7 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
enableAutomaticFailover := d.Get("enable_automatic_failover").(bool)
enableMultipleWriteLocations := d.Get("enable_multiple_write_locations").(bool)
enableAnalyticalStorage := d.Get("analytical_storage_enabled").(bool)
localAuthenticationDisabled := d.Get("local_authentication_disabled").(bool)
shibayan marked this conversation as resolved.
Show resolved Hide resolved

newLocations, err := expandAzureRmCosmosDBAccountGeoLocations(d)
if err != nil {
Expand Down Expand Up @@ -673,6 +682,7 @@ func resourceCosmosDbAccountUpdate(d *pluginsdk.ResourceData, meta interface{})
DisableKeyBasedMetadataWriteAccess: utils.Bool(!d.Get("access_key_metadata_writes_enabled").(bool)),
NetworkACLBypass: networkByPass,
NetworkACLBypassResourceIds: utils.ExpandStringSlice(d.Get("network_acl_bypass_ids").([]interface{})),
DisableLocalAuth: utils.Bool(localAuthenticationDisabled),
},
Tags: tags.Expand(t),
}
Expand Down Expand Up @@ -828,6 +838,7 @@ func resourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{}) er
}
d.Set("network_acl_bypass_for_azure_services", props.NetworkACLBypass == documentdb.NetworkACLBypassAzureServices)
d.Set("network_acl_bypass_ids", utils.FlattenStringSlice(props.NetworkACLBypassResourceIds))
d.Set("local_authentication_disabled", props.DisableLocalAuth)

policy, err := flattenCosmosdbAccountBackup(props.BackupPolicy)
if err != nil {
Expand Down
56 changes: 56 additions & 0 deletions internal/services/cosmos/cosmosdb_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,30 @@ func TestAccCosmosDBAccount_mongoVersion40(t *testing.T) {
})
}

func TestAccCosmosDBAccount_localAuthenticationDisabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test")
r := CosmosDBAccountResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data, documentdb.DatabaseAccountKindGlobalDocumentDB, documentdb.DefaultConsistencyLevelEventual),
Check: acceptance.ComposeAggregateTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("local_authentication_disabled").HasValue("false"),
),
},
data.ImportStep(),
{
Config: r.basicWithLocalAuthenticationDisabled(data, documentdb.DatabaseAccountKindGlobalDocumentDB, documentdb.DefaultConsistencyLevelEventual),
Check: acceptance.ComposeAggregateTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("local_authentication_disabled").HasValue("true"),
),
},
data.ImportStep(),
})
}

func (t CosmosDBAccountResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.DatabaseAccountID(state.ID)
if err != nil {
Expand Down Expand Up @@ -2102,3 +2126,35 @@ resource "azurerm_cosmosdb_account" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(consistency))
}

func (CosmosDBAccountResource) basicWithLocalAuthenticationDisabled(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-cosmos-%d"
location = "%s"
}

resource "azurerm_cosmosdb_account" "test" {
name = "acctest-ca-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
offer_type = "Standard"
kind = "%s"

consistency_policy {
consistency_level = "%s"
}

geo_location {
location = azurerm_resource_group.test.location
failover_priority = 0
}

local_authentication_disabled = true
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency))
}
2 changes: 2 additions & 0 deletions website/docs/r/cosmosdb_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ The following arguments are supported:

* `network_acl_bypass_ids` - (Optional) The list of resource Ids for Network Acl Bypass for this Cosmos DB account.

* `local_authentication_disabled` - (Optional) Disable local authentication and ensure only MSI and AAD can be used exclusively for authentication. Defaults to `false`. Can be set only when using the SQL API.

* `backup` - (Optional) A `backup` block as defined below.

* `cors_rule` - (Optional) A `cors_rule` block as defined below.
Expand Down