From 7d286a56c56b7259b22006b8d43b747f34ff54fb Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Wed, 24 Nov 2021 11:52:49 +0800 Subject: [PATCH 1/4] Add support for new properties of azurerm_cosmosdb_account --- .../cosmos/cosmosdb_account_resource.go | 152 ++++++++++++++++++ .../cosmos/cosmosdb_account_resource_test.go | 39 ++++- website/docs/r/cosmosdb_account.html.markdown | 21 +++ 3 files changed, 204 insertions(+), 8 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index 5a90d15c347d..1b949b14f90b 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -110,6 +110,53 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { }, true), }, + "analytical_storage_configuration": { + Type: pluginsdk.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "schema_type": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice([]string{ + string(documentdb.AnalyticalStorageSchemaTypeWellDefined), + string(documentdb.AnalyticalStorageSchemaTypeFullFidelity), + }, false), + }, + }, + }, + }, + + "capacity": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "total_throughput_limit": { + Type: pluginsdk.TypeInt, + Required: true, + ValidateFunc: validation.IntAtLeast(-1), + }, + }, + }, + }, + + "default_identity": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "FirstPartyIdentity", + ValidateFunc: validation.Any( + validation.StringMatch(regexp.MustCompile(`^UserAssignedIdentity(.)+$`), "It may start with `UserAssignedIdentity`"), + validation.StringInSlice([]string{ + "FirstPartyIdentity", + "SystemAssignedIdentity", + }, false), + ), + }, + "kind": { Type: pluginsdk.TypeString, Optional: true, @@ -371,6 +418,17 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { Computed: true, ValidateFunc: validation.IntBetween(8, 720), }, + + "storage_redundancy": { + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{ + string(documentdb.BackupStorageRedundancyGeo), + string(documentdb.BackupStorageRedundancyLocal), + string(documentdb.BackupStorageRedundancyZone), + }, false), + }, }, }, }, @@ -576,10 +634,19 @@ 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").(string)), }, Tags: tags.Expand(t), } + if v, ok := d.GetOk("analytical_storage_configuration"); ok { + account.DatabaseAccountCreateUpdateProperties.AnalyticalStorageConfiguration = expandCosmosDBAccountAnalyticalStorageConfiguration(v.([]interface{})) + } + + if v, ok := d.GetOk("capacity"); ok { + account.DatabaseAccountCreateUpdateProperties.Capacity = expandCosmosDBAccountCapacity(v.([]interface{})) + } + if v, ok := d.GetOk("mongo_server_version"); ok { account.DatabaseAccountCreateUpdateProperties.APIProperties = &documentdb.APIProperties{ ServerVersion: documentdb.ServerVersion(v.(string)), @@ -710,10 +777,19 @@ 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").(string)), }, Tags: tags.Expand(t), } + if v, ok := d.GetOk("analytical_storage_configuration"); ok { + account.DatabaseAccountCreateUpdateProperties.AnalyticalStorageConfiguration = expandCosmosDBAccountAnalyticalStorageConfiguration(v.([]interface{})) + } + + if v, ok := d.GetOk("capacity"); ok { + account.DatabaseAccountCreateUpdateProperties.Capacity = expandCosmosDBAccountCapacity(v.([]interface{})) + } + if keyVaultKeyIDRaw, ok := d.GetOk("key_vault_key_id"); ok { keyVaultKey, err := keyVaultParse.ParseOptionallyVersionedNestedItemID(keyVaultKeyIDRaw.(string)) if err != nil { @@ -832,6 +908,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) + d.Set("default_identity", props.DefaultIdentity) if v := resp.IsVirtualNetworkFilterEnabled; v != nil { d.Set("is_virtual_network_filter_enabled", props.IsVirtualNetworkFilterEnabled) @@ -849,6 +926,14 @@ func resourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{}) er d.Set("enable_multiple_write_locations", props.EnableMultipleWriteLocations) } + if err := d.Set("analytical_storage_configuration", flattenCosmosDBAccountAnalyticalStorageConfiguration(props.AnalyticalStorageConfiguration)); err != nil { + return fmt.Errorf("setting `analytical_storage_configuration`: %+v", err) + } + + if err := d.Set("capacity", flattenCosmosDBAccountCapacity(props.Capacity)); err != nil { + return fmt.Errorf("setting `capacity`: %+v", err) + } + if err = d.Set("consistency_policy", flattenAzureRmCosmosDBAccountConsistencyPolicy(props.ConsistencyPolicy)); err != nil { return fmt.Errorf("setting CosmosDB Account %q `consistency_policy` (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) } @@ -1317,6 +1402,9 @@ func expandCosmosdbAccountBackup(input []interface{}, backupHasChange bool) (doc if v := attr["retention_in_hours"].(int); v != 0 && !backupHasChange { return nil, fmt.Errorf("`retention_in_hours` can not be set when `type` in `backup` is `Continuous`") } + if v := attr["storage_redundancy"].(string); v != "" && !backupHasChange { + return nil, fmt.Errorf("`storage_redundancy` can not be set when `type` in `backup` is `Continuous`") + } return documentdb.ContinuousModeBackupPolicy{ Type: documentdb.TypeContinuous, }, nil @@ -1327,6 +1415,7 @@ func expandCosmosdbAccountBackup(input []interface{}, backupHasChange bool) (doc PeriodicModeProperties: &documentdb.PeriodicModeProperties{ BackupIntervalInMinutes: utils.Int32(int32(attr["interval_in_minutes"].(int))), BackupRetentionIntervalInHours: utils.Int32(int32(attr["retention_in_hours"].(int))), + BackupStorageRedundancy: documentdb.BackupStorageRedundancy(attr["storage_redundancy"].(string)), }, }, nil @@ -1360,11 +1449,16 @@ func flattenCosmosdbAccountBackup(input documentdb.BasicBackupPolicy) ([]interfa if v := policy.PeriodicModeProperties.BackupRetentionIntervalInHours; v != nil { retention = int(*v) } + var storageRedundancy documentdb.BackupStorageRedundancy + if policy.PeriodicModeProperties.BackupStorageRedundancy != "" { + storageRedundancy = policy.PeriodicModeProperties.BackupStorageRedundancy + } return []interface{}{ map[string]interface{}{ "type": string(documentdb.TypePeriodic), "interval_in_minutes": interval, "retention_in_hours": retention, + "storage_redundancy": storageRedundancy, }, }, nil @@ -1408,3 +1502,61 @@ func flattenAzureRmdocumentdbMachineIdentity(identity *documentdb.ManagedService }, } } + +func expandCosmosDBAccountAnalyticalStorageConfiguration(input []interface{}) *documentdb.AnalyticalStorageConfiguration { + if len(input) == 0 { + return nil + } + + v := input[0].(map[string]interface{}) + + return &documentdb.AnalyticalStorageConfiguration{ + SchemaType: documentdb.AnalyticalStorageSchemaType(v["schema_type"].(string)), + } +} + +func expandCosmosDBAccountCapacity(input []interface{}) *documentdb.Capacity { + if len(input) == 0 { + return nil + } + + v := input[0].(map[string]interface{}) + + return &documentdb.Capacity{ + TotalThroughputLimit: utils.Int32(int32(v["total_throughput_limit"].(int))), + } +} + +func flattenCosmosDBAccountAnalyticalStorageConfiguration(input *documentdb.AnalyticalStorageConfiguration) []interface{} { + if input == nil { + return make([]interface{}, 0) + } + + var schemaType documentdb.AnalyticalStorageSchemaType + if input.SchemaType != "" { + schemaType = input.SchemaType + } + + return []interface{}{ + map[string]interface{}{ + "schema_type": schemaType, + }, + } +} + +func flattenCosmosDBAccountCapacity(input *documentdb.Capacity) []interface{} { + if input == nil { + return make([]interface{}, 0) + } + + var totalThroughputLimit int32 + if input.TotalThroughputLimit != nil { + totalThroughputLimit = *input.TotalThroughputLimit + } + + return []interface{}{ + map[string]interface{}{ + "total_throughput_limit": totalThroughputLimit, + }, + } +} diff --git a/internal/services/cosmos/cosmosdb_account_resource_test.go b/internal/services/cosmos/cosmosdb_account_resource_test.go index d774b018a676..5b46927c0830 100644 --- a/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -109,7 +109,7 @@ func TestAccCosmosDBAccount_keyVaultUri(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelStrong), + Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelStrong, "FirstPartyIdentity"), Check: acceptance.ComposeAggregateTestCheckFunc( checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelStrong, 1), ), @@ -124,14 +124,14 @@ func TestAccCosmosDBAccount_keyVaultUriUpdateConsistancy(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelStrong), + Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelStrong, "FirstPartyIdentity"), Check: acceptance.ComposeAggregateTestCheckFunc( checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelStrong, 1), ), }, data.ImportStep(), { - Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelSession), + Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelSession, "SystemAssignedIdentity"), Check: acceptance.ComposeAggregateTestCheckFunc( checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelSession, 1), ), @@ -607,7 +607,15 @@ func TestAccCosmosDBAccount_analyticalStorage(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual), + Config: r.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual, documentdb.AnalyticalStorageSchemaTypeWellDefined), + Check: acceptance.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + check.That(data.ResourceName).Key("analytical_storage_enabled").HasValue("true"), + ), + }, + data.ImportStep(), + { + Config: r.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual,documentdb.AnalyticalStorageSchemaTypeFullFidelity), Check: acceptance.ComposeAggregateTestCheckFunc( checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), check.That(data.ResourceName).Key("analytical_storage_enabled").HasValue("true"), @@ -1093,6 +1101,10 @@ resource "azurerm_cosmosdb_account" "test" { is_virtual_network_filter_enabled = true + capacity { + total_throughput_limit = -1 + } + virtual_network_rule { id = azurerm_subnet.subnet1.id } @@ -1297,6 +1309,10 @@ resource "azurerm_cosmosdb_account" "test" { is_virtual_network_filter_enabled = true + capacity { + total_throughput_limit = 200 + } + virtual_network_rule { id = azurerm_subnet.subnet2.id } @@ -1683,7 +1699,7 @@ resource "azurerm_cosmosdb_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) } -func (CosmosDBAccountResource) analyticalStorage(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string { +func (CosmosDBAccountResource) analyticalStorage(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel, schemaType documentdb.AnalyticalStorageSchemaType) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -1703,6 +1719,10 @@ resource "azurerm_cosmosdb_account" "test" { analytical_storage_enabled = true + analytical_storage_configuration { + schema_type = "%s" + } + consistency_policy { consistency_level = "%s" } @@ -1712,7 +1732,7 @@ resource "azurerm_cosmosdb_account" "test" { failover_priority = 0 } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(schemaType), string(consistency)) } func (CosmosDBAccountResource) mongoAnalyticalStorage(data acceptance.TestData, consistency documentdb.DefaultConsistencyLevel) string { @@ -1804,7 +1824,7 @@ resource "azurerm_cosmosdb_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) } -func (CosmosDBAccountResource) key_vault_uri(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string { +func (CosmosDBAccountResource) key_vault_uri(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel, defaultIdentity string) string { return fmt.Sprintf(` provider "azurerm" { features { @@ -1903,6 +1923,7 @@ resource "azurerm_cosmosdb_account" "test" { offer_type = "Standard" kind = "%s" key_vault_key_id = azurerm_key_vault_key.test.versionless_id + default_identity = "%s" capabilities { name = "EnableMongo" @@ -1917,7 +1938,7 @@ resource "azurerm_cosmosdb_account" "test" { failover_priority = 0 } } -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, string(kind), string(consistency)) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, string(kind), string(consistency), defaultIdentity) } func (CosmosDBAccountResource) systemAssignedIdentity(data acceptance.TestData, consistency documentdb.DefaultConsistencyLevel) string { @@ -1989,6 +2010,7 @@ resource "azurerm_cosmosdb_account" "test" { type = "Periodic" interval_in_minutes = 120 retention_in_hours = 10 + storage_redundancy = "Geo" } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) @@ -2025,6 +2047,7 @@ resource "azurerm_cosmosdb_account" "test" { type = "Periodic" interval_in_minutes = 60 retention_in_hours = 8 + storage_redundancy = "Local" } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index 06402018a111..77958862d58f 100644 --- a/website/docs/r/cosmosdb_account.html.markdown +++ b/website/docs/r/cosmosdb_account.html.markdown @@ -80,6 +80,12 @@ The following arguments are supported: * `offer_type` - (Required) Specifies the Offer Type to use for this CosmosDB Account - currently this can only be set to `Standard`. +* `analytical_storage_configuration` - (Optional) An `analytical_storage_configuration` block as defined below. + +* `capacity` - (Optional) A `capacity` block as defined below. + +* `default_identity` - (Optional) The default identity for accessing Key Vault. Possible values are `FirstPartyIdentity`, `SystemAssignedIdentity` or start with `UserAssignedIdentity`. Defaults to `FirstPartyIdentity`. + * `kind` - (Optional) Specifies the Kind of CosmosDB to create - possible values are `GlobalDocumentDB` and `MongoDB`. Defaults to `GlobalDocumentDB`. Changing this forces a new resource to be created. * `consistency_policy` - (Required) Specifies a `consistency_policy` resource, used to define the consistency policy for this CosmosDB account. @@ -164,6 +170,19 @@ The following arguments are supported: --- +A `analytical_storage_configuration` block supports the following: + +* `schema_type` - (Required) The schema type of the Analytical Storage for this Cosmos DB account. Possible values are `FullFidelity` and `WellDefined`. + +--- + + +A `capacity` block supports the following: + +* `total_throughput_limit` - (Required) The total throughput limit imposed on this Cosmos DB account. Possible values are at least `-1`. + +--- + A `backup` block supports the following: * `type` - (Required) The type of the `backup`. Possible values are `Continuous` and `Periodic`. Defaults to `Periodic`. Migration of `Periodic` to `Continuous` is one-way, changing `Continuous` to `Periodic` forces a new resource to be created. @@ -172,6 +191,8 @@ A `backup` block supports the following: * `retention_in_hours` - (Optional) The time in hours that each backup is retained. This is configurable only when `type` is `Periodic`. Possible values are between 8 and 720. +* `storage_redundancy` - (Optional) The storage redundancy which is used to indicate type of backup residency. This is configurable only when `type` is `Periodic`. Possible values are `Geo`, `Local` and `Zone`. + --- A `cors_rule` block supports the following: From 821d14a41f2e9764eb7bad7fcc0a41e48df8638f Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 25 Nov 2021 20:48:24 +0800 Subject: [PATCH 2/4] update code --- .../cosmos/cosmosdb_account_resource_test.go | 270 ++++++++++++++++-- .../validate/cassandra_cluster_id_test.go | 76 +++++ .../validate/cassandra_datacenter_id.go | 23 ++ .../validate/cassandra_datacenter_id_test.go | 88 ++++++ 4 files changed, 434 insertions(+), 23 deletions(-) create mode 100644 internal/services/cosmos/validate/cassandra_cluster_id_test.go create mode 100644 internal/services/cosmos/validate/cassandra_datacenter_id.go create mode 100644 internal/services/cosmos/validate/cassandra_datacenter_id_test.go diff --git a/internal/services/cosmos/cosmosdb_account_resource_test.go b/internal/services/cosmos/cosmosdb_account_resource_test.go index 5b46927c0830..e09e66866ea4 100644 --- a/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -109,7 +109,7 @@ func TestAccCosmosDBAccount_keyVaultUri(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelStrong, "FirstPartyIdentity"), + Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelStrong), Check: acceptance.ComposeAggregateTestCheckFunc( checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelStrong, 1), ), @@ -124,14 +124,14 @@ func TestAccCosmosDBAccount_keyVaultUriUpdateConsistancy(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelStrong, "FirstPartyIdentity"), + Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelStrong), Check: acceptance.ComposeAggregateTestCheckFunc( checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelStrong, 1), ), }, data.ImportStep(), { - Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelSession, "SystemAssignedIdentity"), + Config: r.key_vault_uri(data, documentdb.DatabaseAccountKindMongoDB, documentdb.DefaultConsistencyLevelSession), Check: acceptance.ComposeAggregateTestCheckFunc( checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelSession, 1), ), @@ -140,6 +140,42 @@ func TestAccCosmosDBAccount_keyVaultUriUpdateConsistancy(t *testing.T) { }) } +func TestAccCosmosDBAccount_updateDefaultIdentity(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( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + { + Config: r.defaultIdentity(data, documentdb.DatabaseAccountKindGlobalDocumentDB, "FirstPartyIdentity", documentdb.DefaultConsistencyLevelEventual), + Check: acceptance.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + { + Config: r.updateDefaultIdentity(data, documentdb.DatabaseAccountKindGlobalDocumentDB, "SystemAssignedIdentity", documentdb.DefaultConsistencyLevelEventual), + Check: acceptance.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + { + Config: r.basic(data, documentdb.DatabaseAccountKindGlobalDocumentDB, documentdb.DefaultConsistencyLevelEventual), + Check: acceptance.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + }) +} + func testAccCosmosDBAccount_basicWith(t *testing.T, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) { data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") r := CosmosDBAccountResource{} @@ -607,18 +643,82 @@ func TestAccCosmosDBAccount_analyticalStorage(t *testing.T) { data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual, documentdb.AnalyticalStorageSchemaTypeWellDefined), + Config: r.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual), Check: acceptance.ComposeAggregateTestCheckFunc( checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), check.That(data.ResourceName).Key("analytical_storage_enabled").HasValue("true"), ), }, data.ImportStep(), + }) +} + +func TestAccCosmosDBAccount_updateAnalyticalStorage(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") + r := CosmosDBAccountResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.analyticalStorage(data, "GlobalDocumentDB", documentdb.DefaultConsistencyLevelEventual,documentdb.AnalyticalStorageSchemaTypeFullFidelity), + Config: r.basic(data, documentdb.DatabaseAccountKindGlobalDocumentDB, documentdb.DefaultConsistencyLevelEventual), + Check: acceptance.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + { + Config: r.updateAnalyticalStorage(data, documentdb.DatabaseAccountKindGlobalDocumentDB, documentdb.AnalyticalStorageSchemaTypeWellDefined, documentdb.DefaultConsistencyLevelEventual), + Check: acceptance.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + { + Config: r.updateAnalyticalStorage(data, documentdb.DatabaseAccountKindGlobalDocumentDB, documentdb.AnalyticalStorageSchemaTypeFullFidelity, documentdb.DefaultConsistencyLevelEventual), + Check: acceptance.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + { + Config: r.basic(data, documentdb.DatabaseAccountKindGlobalDocumentDB, documentdb.DefaultConsistencyLevelEventual), + Check: acceptance.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + }) +} + +func TestAccCosmosDBAccount_updateCapacity(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( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + { + Config: r.updateCapacity(data, documentdb.DatabaseAccountKindGlobalDocumentDB, -1, documentdb.DefaultConsistencyLevelEventual), + Check: acceptance.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + { + Config: r.updateCapacity(data, documentdb.DatabaseAccountKindGlobalDocumentDB, 200, documentdb.DefaultConsistencyLevelEventual), + Check: acceptance.ComposeAggregateTestCheckFunc( + checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), + ), + }, + data.ImportStep(), + { + Config: r.basic(data, documentdb.DatabaseAccountKindGlobalDocumentDB, documentdb.DefaultConsistencyLevelEventual), Check: acceptance.ComposeAggregateTestCheckFunc( checkAccCosmosDBAccount_basic(data, documentdb.DefaultConsistencyLevelEventual, 1), - check.That(data.ResourceName).Key("analytical_storage_enabled").HasValue("true"), ), }, data.ImportStep(), @@ -685,6 +785,7 @@ func TestAccCosmosDBAccount_backup(t *testing.T) { check.That(data.ResourceName).Key("backup.0.type").HasValue("Periodic"), check.That(data.ResourceName).Key("backup.0.interval_in_minutes").HasValue("240"), check.That(data.ResourceName).Key("backup.0.retention_in_hours").HasValue("8"), + check.That(data.ResourceName).Key("backup.0.storage_redundancy").HasValue("Geo"), ), }, data.ImportStep(), @@ -1101,10 +1202,6 @@ resource "azurerm_cosmosdb_account" "test" { is_virtual_network_filter_enabled = true - capacity { - total_throughput_limit = -1 - } - virtual_network_rule { id = azurerm_subnet.subnet1.id } @@ -1309,10 +1406,6 @@ resource "azurerm_cosmosdb_account" "test" { is_virtual_network_filter_enabled = true - capacity { - total_throughput_limit = 200 - } - virtual_network_rule { id = azurerm_subnet.subnet2.id } @@ -1699,7 +1792,7 @@ resource "azurerm_cosmosdb_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) } -func (CosmosDBAccountResource) analyticalStorage(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel, schemaType documentdb.AnalyticalStorageSchemaType) string { +func (CosmosDBAccountResource) analyticalStorage(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -1719,10 +1812,6 @@ resource "azurerm_cosmosdb_account" "test" { analytical_storage_enabled = true - analytical_storage_configuration { - schema_type = "%s" - } - consistency_policy { consistency_level = "%s" } @@ -1732,7 +1821,7 @@ resource "azurerm_cosmosdb_account" "test" { failover_priority = 0 } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(schemaType), string(consistency)) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) } func (CosmosDBAccountResource) mongoAnalyticalStorage(data acceptance.TestData, consistency documentdb.DefaultConsistencyLevel) string { @@ -1824,7 +1913,7 @@ resource "azurerm_cosmosdb_account" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) } -func (CosmosDBAccountResource) key_vault_uri(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel, defaultIdentity string) string { +func (CosmosDBAccountResource) key_vault_uri(data acceptance.TestData, kind documentdb.DatabaseAccountKind, consistency documentdb.DefaultConsistencyLevel) string { return fmt.Sprintf(` provider "azurerm" { features { @@ -1923,7 +2012,6 @@ resource "azurerm_cosmosdb_account" "test" { offer_type = "Standard" kind = "%s" key_vault_key_id = azurerm_key_vault_key.test.versionless_id - default_identity = "%s" capabilities { name = "EnableMongo" @@ -1938,7 +2026,7 @@ resource "azurerm_cosmosdb_account" "test" { failover_priority = 0 } } -`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, string(kind), string(consistency), defaultIdentity) +`, data.RandomInteger, data.Locations.Primary, data.RandomString, data.RandomString, data.RandomInteger, string(kind), string(consistency)) } func (CosmosDBAccountResource) systemAssignedIdentity(data acceptance.TestData, consistency documentdb.DefaultConsistencyLevel) string { @@ -2320,3 +2408,139 @@ resource "azurerm_cosmosdb_account" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) } + +func (CosmosDBAccountResource) updateAnalyticalStorage(data acceptance.TestData, kind documentdb.DatabaseAccountKind, schemaType documentdb.AnalyticalStorageSchemaType, 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" + analytical_storage_enabled = false + + analytical_storage_configuration { + schema_type = "%s" + } + + consistency_policy { + consistency_level = "%s" + } + + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(schemaType), string(consistency)) +} + +func (CosmosDBAccountResource) updateCapacity(data acceptance.TestData, kind documentdb.DatabaseAccountKind, totalThroughputLimit int, 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" + analytical_storage_enabled = false + + capacity { + total_throughput_limit = %d + } + + consistency_policy { + consistency_level = "%s" + } + + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), totalThroughputLimit, string(consistency)) +} + +func (CosmosDBAccountResource) defaultIdentity(data acceptance.TestData, kind documentdb.DatabaseAccountKind, defaultIdentity string, 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" + default_identity = "%s" + + consistency_policy { + consistency_level = "%s" + } + + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), defaultIdentity, string(consistency)) +} + +func (CosmosDBAccountResource) updateDefaultIdentity(data acceptance.TestData, kind documentdb.DatabaseAccountKind, defaultIdentity string, 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" + default_identity = "%s" + + identity { + type = "SystemAssigned" + } + + consistency_policy { + consistency_level = "%s" + } + + geo_location { + location = azurerm_resource_group.test.location + failover_priority = 0 + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), defaultIdentity, string(consistency)) +} diff --git a/internal/services/cosmos/validate/cassandra_cluster_id_test.go b/internal/services/cosmos/validate/cassandra_cluster_id_test.go new file mode 100644 index 000000000000..d9e1dbb53974 --- /dev/null +++ b/internal/services/cosmos/validate/cassandra_cluster_id_test.go @@ -0,0 +1,76 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestCassandraClusterID(t *testing.T) { + cases := []struct { + Input string + Valid bool + }{ + + { + // empty + Input: "", + Valid: false, + }, + + { + // missing SubscriptionId + Input: "/", + Valid: false, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Valid: false, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Valid: false, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Valid: false, + }, + + { + // missing Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/", + Valid: false, + }, + + { + // missing value for Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/cluster1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.DOCUMENTDB/CASSANDRACLUSTERS/CLUSTER1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := CassandraClusterID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/internal/services/cosmos/validate/cassandra_datacenter_id.go b/internal/services/cosmos/validate/cassandra_datacenter_id.go new file mode 100644 index 000000000000..d491b5754c54 --- /dev/null +++ b/internal/services/cosmos/validate/cassandra_datacenter_id.go @@ -0,0 +1,23 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "fmt" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/parse" +) + +func CassandraDatacenterID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := parse.CassandraDatacenterID(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/cosmos/validate/cassandra_datacenter_id_test.go b/internal/services/cosmos/validate/cassandra_datacenter_id_test.go new file mode 100644 index 000000000000..2a9324eb15bc --- /dev/null +++ b/internal/services/cosmos/validate/cassandra_datacenter_id_test.go @@ -0,0 +1,88 @@ +package validate + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import "testing" + +func TestCassandraDatacenterID(t *testing.T) { + cases := []struct { + Input string + Valid bool + }{ + + { + // empty + Input: "", + Valid: false, + }, + + { + // missing SubscriptionId + Input: "/", + Valid: false, + }, + + { + // missing value for SubscriptionId + Input: "/subscriptions/", + Valid: false, + }, + + { + // missing ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", + Valid: false, + }, + + { + // missing value for ResourceGroup + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", + Valid: false, + }, + + { + // missing CassandraClusterName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/", + Valid: false, + }, + + { + // missing value for CassandraClusterName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/", + Valid: false, + }, + + { + // missing DataCenterName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/cluster1/", + Valid: false, + }, + + { + // missing value for DataCenterName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/cluster1/dataCenters/", + Valid: false, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/cluster1/dataCenters/dc1", + Valid: true, + }, + + { + // upper-cased + Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.DOCUMENTDB/CASSANDRACLUSTERS/CLUSTER1/DATACENTERS/DC1", + Valid: false, + }, + } + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := CassandraDatacenterID(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} From 9e27e31dc837713e35fe8b943bd27b1e7a6f444b Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Thu, 25 Nov 2021 20:52:01 +0800 Subject: [PATCH 3/4] update code --- .../validate/cassandra_cluster_id_test.go | 76 ---------------- .../validate/cassandra_datacenter_id.go | 23 ----- .../validate/cassandra_datacenter_id_test.go | 88 ------------------- 3 files changed, 187 deletions(-) delete mode 100644 internal/services/cosmos/validate/cassandra_cluster_id_test.go delete mode 100644 internal/services/cosmos/validate/cassandra_datacenter_id.go delete mode 100644 internal/services/cosmos/validate/cassandra_datacenter_id_test.go diff --git a/internal/services/cosmos/validate/cassandra_cluster_id_test.go b/internal/services/cosmos/validate/cassandra_cluster_id_test.go deleted file mode 100644 index d9e1dbb53974..000000000000 --- a/internal/services/cosmos/validate/cassandra_cluster_id_test.go +++ /dev/null @@ -1,76 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestCassandraClusterID(t *testing.T) { - cases := []struct { - Input string - Valid bool - }{ - - { - // empty - Input: "", - Valid: false, - }, - - { - // missing SubscriptionId - Input: "/", - Valid: false, - }, - - { - // missing value for SubscriptionId - Input: "/subscriptions/", - Valid: false, - }, - - { - // missing ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", - Valid: false, - }, - - { - // missing value for ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", - Valid: false, - }, - - { - // missing Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/", - Valid: false, - }, - - { - // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/cluster1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.DOCUMENTDB/CASSANDRACLUSTERS/CLUSTER1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := CassandraClusterID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} diff --git a/internal/services/cosmos/validate/cassandra_datacenter_id.go b/internal/services/cosmos/validate/cassandra_datacenter_id.go deleted file mode 100644 index d491b5754c54..000000000000 --- a/internal/services/cosmos/validate/cassandra_datacenter_id.go +++ /dev/null @@ -1,23 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import ( - "fmt" - - "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/parse" -) - -func CassandraDatacenterID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := parse.CassandraDatacenterID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/internal/services/cosmos/validate/cassandra_datacenter_id_test.go b/internal/services/cosmos/validate/cassandra_datacenter_id_test.go deleted file mode 100644 index 2a9324eb15bc..000000000000 --- a/internal/services/cosmos/validate/cassandra_datacenter_id_test.go +++ /dev/null @@ -1,88 +0,0 @@ -package validate - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import "testing" - -func TestCassandraDatacenterID(t *testing.T) { - cases := []struct { - Input string - Valid bool - }{ - - { - // empty - Input: "", - Valid: false, - }, - - { - // missing SubscriptionId - Input: "/", - Valid: false, - }, - - { - // missing value for SubscriptionId - Input: "/subscriptions/", - Valid: false, - }, - - { - // missing ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", - Valid: false, - }, - - { - // missing value for ResourceGroup - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", - Valid: false, - }, - - { - // missing CassandraClusterName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/", - Valid: false, - }, - - { - // missing value for CassandraClusterName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/", - Valid: false, - }, - - { - // missing DataCenterName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/cluster1/", - Valid: false, - }, - - { - // missing value for DataCenterName - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/cluster1/dataCenters/", - Valid: false, - }, - - { - // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DocumentDB/cassandraClusters/cluster1/dataCenters/dc1", - Valid: true, - }, - - { - // upper-cased - Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.DOCUMENTDB/CASSANDRACLUSTERS/CLUSTER1/DATACENTERS/DC1", - Valid: false, - }, - } - for _, tc := range cases { - t.Logf("[DEBUG] Testing Value %s", tc.Input) - _, errors := CassandraDatacenterID(tc.Input, "test") - valid := len(errors) == 0 - - if tc.Valid != valid { - t.Fatalf("Expected %t but got %t", tc.Valid, valid) - } - } -} From 647940ff538a03eaa5d08eac4d7cd653cb643d55 Mon Sep 17 00:00:00 2001 From: neil-yechenwei Date: Fri, 26 Nov 2021 08:15:12 +0800 Subject: [PATCH 4/4] update code --- .../cosmos/cosmosdb_account_resource.go | 18 ++++++------- .../cosmos/cosmosdb_account_resource_test.go | 26 +++++++++---------- website/docs/r/cosmosdb_account.html.markdown | 9 +++---- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_account_resource.go b/internal/services/cosmos/cosmosdb_account_resource.go index 1b949b14f90b..48ed257e2af4 100644 --- a/internal/services/cosmos/cosmosdb_account_resource.go +++ b/internal/services/cosmos/cosmosdb_account_resource.go @@ -110,7 +110,7 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { }, true), }, - "analytical_storage_configuration": { + "analytical_storage": { Type: pluginsdk.TypeList, Optional: true, Computed: true, @@ -144,7 +144,7 @@ func resourceCosmosDbAccount() *pluginsdk.Resource { }, }, - "default_identity": { + "default_identity_type": { Type: pluginsdk.TypeString, Optional: true, Default: "FirstPartyIdentity", @@ -634,12 +634,12 @@ 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").(string)), + DefaultIdentity: utils.String(d.Get("default_identity_type").(string)), }, Tags: tags.Expand(t), } - if v, ok := d.GetOk("analytical_storage_configuration"); ok { + if v, ok := d.GetOk("analytical_storage"); ok { account.DatabaseAccountCreateUpdateProperties.AnalyticalStorageConfiguration = expandCosmosDBAccountAnalyticalStorageConfiguration(v.([]interface{})) } @@ -777,12 +777,12 @@ 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").(string)), + DefaultIdentity: utils.String(d.Get("default_identity_type").(string)), }, Tags: tags.Expand(t), } - if v, ok := d.GetOk("analytical_storage_configuration"); ok { + if v, ok := d.GetOk("analytical_storage"); ok { account.DatabaseAccountCreateUpdateProperties.AnalyticalStorageConfiguration = expandCosmosDBAccountAnalyticalStorageConfiguration(v.([]interface{})) } @@ -908,7 +908,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) - d.Set("default_identity", props.DefaultIdentity) + d.Set("default_identity_type", props.DefaultIdentity) if v := resp.IsVirtualNetworkFilterEnabled; v != nil { d.Set("is_virtual_network_filter_enabled", props.IsVirtualNetworkFilterEnabled) @@ -926,8 +926,8 @@ func resourceCosmosDbAccountRead(d *pluginsdk.ResourceData, meta interface{}) er d.Set("enable_multiple_write_locations", props.EnableMultipleWriteLocations) } - if err := d.Set("analytical_storage_configuration", flattenCosmosDBAccountAnalyticalStorageConfiguration(props.AnalyticalStorageConfiguration)); err != nil { - return fmt.Errorf("setting `analytical_storage_configuration`: %+v", err) + if err := d.Set("analytical_storage", flattenCosmosDBAccountAnalyticalStorageConfiguration(props.AnalyticalStorageConfiguration)); err != nil { + return fmt.Errorf("setting `analytical_storage`: %+v", err) } if err := d.Set("capacity", flattenCosmosDBAccountCapacity(props.Capacity)); err != nil { diff --git a/internal/services/cosmos/cosmosdb_account_resource_test.go b/internal/services/cosmos/cosmosdb_account_resource_test.go index e09e66866ea4..82c2119a7922 100644 --- a/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -2428,7 +2428,7 @@ resource "azurerm_cosmosdb_account" "test" { kind = "%s" analytical_storage_enabled = false - analytical_storage_configuration { + analytical_storage { schema_type = "%s" } @@ -2491,12 +2491,12 @@ resource "azurerm_resource_group" "test" { } 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" - default_identity = "%s" + name = "acctest-ca-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + offer_type = "Standard" + kind = "%s" + default_identity_type = "%s" consistency_policy { consistency_level = "%s" @@ -2522,12 +2522,12 @@ resource "azurerm_resource_group" "test" { } 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" - default_identity = "%s" + name = "acctest-ca-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + offer_type = "Standard" + kind = "%s" + default_identity_type = "%s" identity { type = "SystemAssigned" diff --git a/website/docs/r/cosmosdb_account.html.markdown b/website/docs/r/cosmosdb_account.html.markdown index 77958862d58f..c9ff64c61900 100644 --- a/website/docs/r/cosmosdb_account.html.markdown +++ b/website/docs/r/cosmosdb_account.html.markdown @@ -80,11 +80,11 @@ The following arguments are supported: * `offer_type` - (Required) Specifies the Offer Type to use for this CosmosDB Account - currently this can only be set to `Standard`. -* `analytical_storage_configuration` - (Optional) An `analytical_storage_configuration` block as defined below. +* `analytical_storage` - (Optional) An `analytical_storage` block as defined below. * `capacity` - (Optional) A `capacity` block as defined below. -* `default_identity` - (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`. Defaults to `FirstPartyIdentity`. * `kind` - (Optional) Specifies the Kind of CosmosDB to create - possible values are `GlobalDocumentDB` and `MongoDB`. Defaults to `GlobalDocumentDB`. Changing this forces a new resource to be created. @@ -170,16 +170,15 @@ The following arguments are supported: --- -A `analytical_storage_configuration` block supports the following: +A `analytical_storage` block supports the following: * `schema_type` - (Required) The schema type of the Analytical Storage for this Cosmos DB account. Possible values are `FullFidelity` and `WellDefined`. --- - A `capacity` block supports the following: -* `total_throughput_limit` - (Required) The total throughput limit imposed on this Cosmos DB account. Possible values are at least `-1`. +* `total_throughput_limit` - (Required) The total throughput limit imposed on this Cosmos DB account (RU/s). Possible values are at least `-1`. `-1` means no limit. ---