From ccf824c2f94f8fee2efcf3da7514a09334f95926 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 28 Sep 2023 13:21:51 -0600 Subject: [PATCH 1/5] Initial Check-in... --- .../cosmosdb_cassandra_datacenter_resource.go | 24 +++++---- ...osdb_cassandra_datacenter_resource_test.go | 53 ++++++++++++++++++- .../cosmosdb_cassandra_keyspace_resource.go | 2 +- .../cosmosdb_cassandra_resource_test.go | 5 +- .../cosmosdb_gremlin_database_resource.go | 2 +- .../cosmos/cosmosdb_gremlin_graph_resource.go | 2 +- .../cosmosdb_mongo_database_resource.go | 2 +- .../cosmos/cosmosdb_sql_database_resource.go | 2 +- .../cosmos/cosmosdb_table_resource.go | 2 +- ...osmosdb_cassandra_datacenter.html.markdown | 2 +- 10 files changed, 75 insertions(+), 21 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go index 9d84be0f23e3..603284529a4d 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go @@ -99,9 +99,12 @@ func resourceCassandraDatacenter() *pluginsdk.Resource { ValidateFunc: validation.IntAtLeast(3), Default: 3, }, + // NOTE: The API does not expose a constant + // for the Sku so I had to hardcode it here... "sku_name": { Type: pluginsdk.TypeString, Optional: true, + Default: "Standard_DS14_v2", ValidateFunc: validation.StringIsNotEmpty, }, "disk_count": { @@ -139,7 +142,7 @@ func resourceCassandraDatacenterCreate(d *pluginsdk.ResourceData, meta interface return tf.ImportAsExistsError("azurerm_cosmosdb_cassandra_datacenter", id.ID()) } - body := managedcassandras.DataCenterResource{ + payload := managedcassandras.DataCenterResource{ Properties: &managedcassandras.DataCenterResourceProperties{ DelegatedSubnetId: utils.String(d.Get("delegated_management_subnet_id").(string)), NodeCount: utils.Int64(int64(d.Get("node_count").(int))), @@ -152,18 +155,18 @@ func resourceCassandraDatacenterCreate(d *pluginsdk.ResourceData, meta interface } if v, ok := d.GetOk("backup_storage_customer_key_uri"); ok { - body.Properties.BackupStorageCustomerKeyUri = utils.String(v.(string)) + payload.Properties.BackupStorageCustomerKeyUri = utils.String(v.(string)) } if v, ok := d.GetOk("base64_encoded_yaml_fragment"); ok { - body.Properties.Base64EncodedCassandraYamlFragment = utils.String(v.(string)) + payload.Properties.Base64EncodedCassandraYamlFragment = utils.String(v.(string)) } if v, ok := d.GetOk("managed_disk_customer_key_uri"); ok { - body.Properties.ManagedDiskCustomerKeyUri = utils.String(v.(string)) + payload.Properties.ManagedDiskCustomerKeyUri = utils.String(v.(string)) } - if err = client.CassandraDataCentersCreateUpdateThenPoll(ctx, id, body); err != nil { + if err = client.CassandraDataCentersCreateUpdateThenPoll(ctx, id, payload); err != nil { return fmt.Errorf("creating %q: %+v", id, err) } @@ -222,28 +225,29 @@ func resourceCassandraDatacenterUpdate(d *pluginsdk.ResourceData, meta interface return err } - body := managedcassandras.DataCenterResource{ + payload := managedcassandras.DataCenterResource{ Properties: &managedcassandras.DataCenterResourceProperties{ DelegatedSubnetId: utils.String(d.Get("delegated_management_subnet_id").(string)), NodeCount: utils.Int64(int64(d.Get("node_count").(int))), + Sku: utils.String(d.Get("sku_name").(string)), DataCenterLocation: utils.String(azure.NormalizeLocation(d.Get("location").(string))), DiskSku: utils.String(d.Get("disk_sku").(string)), }, } if v, ok := d.GetOk("backup_storage_customer_key_uri"); ok { - body.Properties.BackupStorageCustomerKeyUri = utils.String(v.(string)) + payload.Properties.BackupStorageCustomerKeyUri = utils.String(v.(string)) } if v, ok := d.GetOk("base64_encoded_yaml_fragment"); ok { - body.Properties.Base64EncodedCassandraYamlFragment = utils.String(v.(string)) + payload.Properties.Base64EncodedCassandraYamlFragment = utils.String(v.(string)) } if v, ok := d.GetOk("managed_disk_customer_key_uri"); ok { - body.Properties.ManagedDiskCustomerKeyUri = utils.String(v.(string)) + payload.Properties.ManagedDiskCustomerKeyUri = utils.String(v.(string)) } - if err := client.CassandraDataCentersCreateUpdateThenPoll(ctx, *id, body); err != nil { + if err := client.CassandraDataCentersCreateUpdateThenPoll(ctx, *id, payload); err != nil { return fmt.Errorf("updating %q: %+v", id, err) } diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go index 4e1f10b31cb3..10b99b90448a 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go @@ -55,6 +55,39 @@ func testAccCassandraDatacenter_update(t *testing.T) { }) } +func testAccCassandraDatacenter_updateSku(t *testing.T) { + // Regression test case for MS IcM issue + data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_datacenter", "test") + r := CassandraDatacenterResource{} + + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data, 3), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), + ), + }, + data.ImportStep(), + { + Config: r.updateSku(data, "Standard_DS13_v2"), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS13_v2"), + ), + }, + data.ImportStep(), + { + Config: r.basic(data, 3), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), + ), + }, + data.ImportStep(), + }) +} + func (t CassandraDatacenterResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := managedcassandras.ParseDataCenterID(state.ID) if err != nil { @@ -80,7 +113,6 @@ resource "azurerm_cosmosdb_cassandra_datacenter" "test" { delegated_management_subnet_id = azurerm_subnet.test.id node_count = %d disk_count = 4 - sku_name = "Standard_DS14_v2" availability_zones_enabled = false } `, r.template(data), data.RandomInteger, nodeCount) @@ -308,7 +340,7 @@ provider "azurerm" { } resource "azurerm_resource_group" "test" { - name = "acctestRG-ca-%d" + name = "acctestRG-cassandra-%d" location = "%s" } @@ -351,3 +383,20 @@ resource "azurerm_cosmosdb_cassandra_cluster" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } + +func (r CassandraDatacenterResource) updateSku(data acceptance.TestData, skuName string) string { + return fmt.Sprintf(` +%s + +resource "azurerm_cosmosdb_cassandra_datacenter" "test" { + name = "acctca-mi-dc-%d" + cassandra_cluster_id = azurerm_cosmosdb_cassandra_cluster.test.id + location = azurerm_cosmosdb_cassandra_cluster.test.location + delegated_management_subnet_id = azurerm_subnet.test.id + node_count = 3 + disk_count = 4 + sku_name = "%s" + availability_zones_enabled = false +} +`, r.template(data), data.RandomInteger, skuName) +} diff --git a/internal/services/cosmos/cosmosdb_cassandra_keyspace_resource.go b/internal/services/cosmos/cosmosdb_cassandra_keyspace_resource.go index 774057101287..43604f9e3046 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_keyspace_resource.go +++ b/internal/services/cosmos/cosmosdb_cassandra_keyspace_resource.go @@ -168,7 +168,7 @@ func resourceCosmosDbCassandraKeyspaceUpdate(d *pluginsdk.ResourceData, meta int if err != nil { if response.WasNotFound(throughputFuture.Response()) { return fmt.Errorf("setting Throughput for Cosmos Cassandra Keyspace %q (Account: %q): %+v - "+ - "If the collection has not been created with an initial throughput, you cannot configure it later.", id.Name, id.DatabaseAccountName, err) + "If the collection has not been created with an initial throughput, you cannot configure it later", id.Name, id.DatabaseAccountName, err) } } diff --git a/internal/services/cosmos/cosmosdb_cassandra_resource_test.go b/internal/services/cosmos/cosmosdb_cassandra_resource_test.go index 5b7f33f71766..f0e61171212b 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_resource_test.go +++ b/internal/services/cosmos/cosmosdb_cassandra_resource_test.go @@ -19,8 +19,9 @@ func TestAccCassandraSequential(t *testing.T) { "requiresImport": testAccCassandraCluster_requiresImport, }, "dataCenter": { - "basic": testAccCassandraDatacenter_basic, - "update": testAccCassandraDatacenter_update, + "basic": testAccCassandraDatacenter_basic, + "update": testAccCassandraDatacenter_update, + "updateSku": testAccCassandraDatacenter_updateSku, }, }) } diff --git a/internal/services/cosmos/cosmosdb_gremlin_database_resource.go b/internal/services/cosmos/cosmosdb_gremlin_database_resource.go index 818a611fa9e7..f3805076b42e 100644 --- a/internal/services/cosmos/cosmosdb_gremlin_database_resource.go +++ b/internal/services/cosmos/cosmosdb_gremlin_database_resource.go @@ -156,7 +156,7 @@ func resourceCosmosGremlinDatabaseUpdate(d *pluginsdk.ResourceData, meta interfa if err != nil { if response.WasNotFound(throughputFuture.HttpResponse) { return fmt.Errorf("setting Throughput for Cosmos Gremlin Database %q (Account: %q): %+v - "+ - "If the collection has not been created with and initial throughput, you cannot configure it later.", id.GremlinDatabaseName, id.DatabaseAccountName, err) + "If the collection has not been created with and initial throughput, you cannot configure it later", id.GremlinDatabaseName, id.DatabaseAccountName, err) } } diff --git a/internal/services/cosmos/cosmosdb_gremlin_graph_resource.go b/internal/services/cosmos/cosmosdb_gremlin_graph_resource.go index 9398a102ab11..4fa921dbd3a6 100644 --- a/internal/services/cosmos/cosmosdb_gremlin_graph_resource.go +++ b/internal/services/cosmos/cosmosdb_gremlin_graph_resource.go @@ -336,7 +336,7 @@ func resourceCosmosDbGremlinGraphUpdate(d *pluginsdk.ResourceData, meta interfac if err != nil { if response.WasNotFound(throughputFuture.HttpResponse) { return fmt.Errorf("setting Throughput for Cosmos Gremlin Graph %q (Account: %q, Database: %q): %+v - "+ - "If the graph has not been created with an initial throughput, you cannot configure it later.", id.GraphName, id.DatabaseAccountName, id.GremlinDatabaseName, err) + "If the graph has not been created with an initial throughput, you cannot configure it later", id.GraphName, id.DatabaseAccountName, id.GremlinDatabaseName, err) } } diff --git a/internal/services/cosmos/cosmosdb_mongo_database_resource.go b/internal/services/cosmos/cosmosdb_mongo_database_resource.go index b88d3f9297bb..4a4c1e401e30 100644 --- a/internal/services/cosmos/cosmosdb_mongo_database_resource.go +++ b/internal/services/cosmos/cosmosdb_mongo_database_resource.go @@ -168,7 +168,7 @@ func resourceCosmosDbMongoDatabaseUpdate(d *pluginsdk.ResourceData, meta interfa if err != nil { if response.WasNotFound(throughputFuture.Response()) { return fmt.Errorf("setting Throughput for Cosmos MongoDB Database %q (Account: %q): %+v - "+ - "If the collection has not been created with an initial throughput, you cannot configure it later.", id.Name, id.DatabaseAccountName, err) + "If the collection has not been created with an initial throughput, you cannot configure it later", id.Name, id.DatabaseAccountName, err) } } diff --git a/internal/services/cosmos/cosmosdb_sql_database_resource.go b/internal/services/cosmos/cosmosdb_sql_database_resource.go index 9ff0ca40528d..1e98971de0fd 100644 --- a/internal/services/cosmos/cosmosdb_sql_database_resource.go +++ b/internal/services/cosmos/cosmosdb_sql_database_resource.go @@ -168,7 +168,7 @@ func resourceCosmosDbSQLDatabaseUpdate(d *pluginsdk.ResourceData, meta interface if err != nil { if response.WasNotFound(throughputFuture.Response()) { return fmt.Errorf("setting Throughput for Cosmos SQL Database %q (Account: %q) %+v - "+ - "If the collection has not been created with an initial throughput, you cannot configure it later.", id.Name, id.DatabaseAccountName, err) + "If the collection has not been created with an initial throughput, you cannot configure it later", id.Name, id.DatabaseAccountName, err) } } diff --git a/internal/services/cosmos/cosmosdb_table_resource.go b/internal/services/cosmos/cosmosdb_table_resource.go index 78c40813f5dd..0b2d4f726fda 100644 --- a/internal/services/cosmos/cosmosdb_table_resource.go +++ b/internal/services/cosmos/cosmosdb_table_resource.go @@ -168,7 +168,7 @@ func resourceCosmosDbTableUpdate(d *pluginsdk.ResourceData, meta interface{}) er if err != nil { if response.WasNotFound(throughputFuture.Response()) { return fmt.Errorf("setting Throughput for Cosmos Table %q (Account: %q): %+v - "+ - "If the collection has not been created with an initial throughput, you cannot configure it later.", id.Name, id.DatabaseAccountName, err) + "If the collection has not been created with an initial throughput, you cannot configure it later", id.Name, id.DatabaseAccountName, err) } } diff --git a/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown b/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown index a00b48e65aea..8d3ebadd852a 100644 --- a/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown +++ b/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown @@ -98,7 +98,7 @@ The following arguments are supported: * `managed_disk_customer_key_uri` - (Optional) The key URI of the customer key to use for the encryption of the Managed Disk. -* `sku_name` - (Optional) Determines the selected sku. +* `sku_name` - (Optional) Determines the selected sku. Defaults to `Standard_DS14_v2`. * `disk_count` - (Optional) Determines the number of p30 disks that are attached to each node. From e59e0c373293a63836d108cb91da74c178e2610f Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:07:17 -0600 Subject: [PATCH 2/5] Change default sku_name value for 4.0... --- .../cosmosdb_cassandra_datacenter_resource.go | 32 ++++++-- ...osdb_cassandra_datacenter_resource_test.go | 82 +++++++++++++------ ...osmosdb_cassandra_datacenter.html.markdown | 2 + 3 files changed, 81 insertions(+), 35 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go index 603284529a4d..f6bc90afa013 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go @@ -17,6 +17,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "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/validate" keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -26,7 +27,7 @@ import ( ) func resourceCassandraDatacenter() *pluginsdk.Resource { - return &pluginsdk.Resource{ + resource := &pluginsdk.Resource{ Create: resourceCassandraDatacenterCreate, Read: resourceCassandraDatacenterRead, Update: resourceCassandraDatacenterUpdate, @@ -99,14 +100,6 @@ func resourceCassandraDatacenter() *pluginsdk.Resource { ValidateFunc: validation.IntAtLeast(3), Default: 3, }, - // NOTE: The API does not expose a constant - // for the Sku so I had to hardcode it here... - "sku_name": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Standard_DS14_v2", - ValidateFunc: validation.StringIsNotEmpty, - }, "disk_count": { Type: pluginsdk.TypeInt, Optional: true, @@ -119,6 +112,27 @@ func resourceCassandraDatacenter() *pluginsdk.Resource { }, }, } + + if !features.FourPointOhBeta() { + // NOTE: The API does not expose a constant for the Sku so I had to hardcode it here... + // Per the service team, the current default Sku is 'Standard_DS14_v2' but moving forward + // the new default value should be 'Standard_E16s_v5'. + resource.Schema["sku_name"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Default: "Standard_DS14_v2", + ValidateFunc: validation.StringIsNotEmpty, + } + } else { + resource.Schema["sku_name"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Default: "Standard_E16s_v5", + ValidateFunc: validation.StringIsNotEmpty, + } + } + + return resource } func resourceCassandraDatacenterCreate(d *pluginsdk.ResourceData, meta interface{}) error { diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go index 10b99b90448a..def38f73f282 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -60,32 +61,61 @@ func testAccCassandraDatacenter_updateSku(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_datacenter", "test") r := CassandraDatacenterResource{} - data.ResourceSequentialTest(t, r, []acceptance.TestStep{ - { - Config: r.basic(data, 3), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), - ), - }, - data.ImportStep(), - { - Config: r.updateSku(data, "Standard_DS13_v2"), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS13_v2"), - ), - }, - data.ImportStep(), - { - Config: r.basic(data, 3), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), - ), - }, - data.ImportStep(), - }) + if !features.FourPointOhBeta() { + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data, 3), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), + ), + }, + data.ImportStep(), + { + Config: r.updateSku(data, "Standard_DS13_v2"), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS13_v2"), + ), + }, + data.ImportStep(), + { + Config: r.basic(data, 3), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), + ), + }, + data.ImportStep(), + }) + } else { + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data, 3), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E16s_v5"), + ), + }, + data.ImportStep(), + { + Config: r.updateSku(data, "Standard_E2_v5"), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E2_v5"), + ), + }, + data.ImportStep(), + { + Config: r.basic(data, 3), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E16s_v5"), + ), + }, + data.ImportStep(), + }) + } } func (t CassandraDatacenterResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { diff --git a/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown b/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown index 8d3ebadd852a..e648138a55c0 100644 --- a/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown +++ b/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown @@ -100,6 +100,8 @@ The following arguments are supported: * `sku_name` - (Optional) Determines the selected sku. Defaults to `Standard_DS14_v2`. +-> **NOTE:** In v4.0 of the provider the default value for the `sku_name` field will be changed to `Standard_E16s_v5`. + * `disk_count` - (Optional) Determines the number of p30 disks that are attached to each node. * `availability_zones_enabled` - (Optional) Determines whether availability zones are enabled. Defaults to `true`. From 3446b5a6ecacec07da2d817232c40269f199c0ed Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 28 Sep 2023 14:41:49 -0600 Subject: [PATCH 3/5] Fix lint error... --- ...osmosdb_cassandra_datacenter_resource_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go index def38f73f282..dcbe11bb83dc 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go @@ -25,7 +25,7 @@ func testAccCassandraDatacenter_basic(t *testing.T) { data.ResourceSequentialTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data, 3), + Config: r.basic(data), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -64,7 +64,7 @@ func testAccCassandraDatacenter_updateSku(t *testing.T) { if !features.FourPointOhBeta() { data.ResourceSequentialTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data, 3), + Config: r.basic(data), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), @@ -80,7 +80,7 @@ func testAccCassandraDatacenter_updateSku(t *testing.T) { }, data.ImportStep(), { - Config: r.basic(data, 3), + Config: r.basic(data), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), @@ -91,7 +91,7 @@ func testAccCassandraDatacenter_updateSku(t *testing.T) { } else { data.ResourceSequentialTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data, 3), + Config: r.basic(data), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E16s_v5"), @@ -107,7 +107,7 @@ func testAccCassandraDatacenter_updateSku(t *testing.T) { }, data.ImportStep(), { - Config: r.basic(data, 3), + Config: r.basic(data), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E16s_v5"), @@ -132,7 +132,7 @@ func (t CassandraDatacenterResource) Exists(ctx context.Context, clients *client return utils.Bool(resp.Model != nil), nil } -func (r CassandraDatacenterResource) basic(data acceptance.TestData, nodeCount int) string { +func (r CassandraDatacenterResource) basic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -141,11 +141,11 @@ resource "azurerm_cosmosdb_cassandra_datacenter" "test" { cassandra_cluster_id = azurerm_cosmosdb_cassandra_cluster.test.id location = azurerm_cosmosdb_cassandra_cluster.test.location delegated_management_subnet_id = azurerm_subnet.test.id - node_count = %d + node_count = 3 disk_count = 4 availability_zones_enabled = false } -`, r.template(data), data.RandomInteger, nodeCount) +`, r.template(data), data.RandomInteger) } func (r CassandraDatacenterResource) complete(data acceptance.TestData, nodeCount int) string { From 793c3c011ff62d4cd722d8e09be85b763eb59eb0 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:48:12 -0600 Subject: [PATCH 4/5] Update 3.x to be computed... --- .../cosmosdb_cassandra_datacenter_resource.go | 3 +- ...osdb_cassandra_datacenter_resource_test.go | 45 ++++++++++--------- ...osmosdb_cassandra_datacenter.html.markdown | 4 +- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go index f6bc90afa013..8c2eb48dcd4e 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go @@ -93,7 +93,6 @@ func resourceCassandraDatacenter() *pluginsdk.Resource { Optional: true, ValidateFunc: keyVaultValidate.NestedItemId, }, - "node_count": { Type: pluginsdk.TypeInt, Optional: true, @@ -120,7 +119,7 @@ func resourceCassandraDatacenter() *pluginsdk.Resource { resource.Schema["sku_name"] = &pluginsdk.Schema{ Type: pluginsdk.TypeString, Optional: true, - Default: "Standard_DS14_v2", + Computed: true, ValidateFunc: validation.StringIsNotEmpty, } } else { diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go index dcbe11bb83dc..c23b0597b5e9 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go @@ -28,6 +28,7 @@ func testAccCassandraDatacenter_basic(t *testing.T) { Config: r.basic(data), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").IsNotEmpty(), ), }, data.ImportStep(), @@ -57,14 +58,14 @@ func testAccCassandraDatacenter_update(t *testing.T) { } func testAccCassandraDatacenter_updateSku(t *testing.T) { - // Regression test case for MS IcM issue + // Regression test case for MS IcM data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_datacenter", "test") r := CassandraDatacenterResource{} if !features.FourPointOhBeta() { data.ResourceSequentialTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data), + Config: r.basicSku(data, "Standard_DS14_v2"), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), @@ -72,7 +73,7 @@ func testAccCassandraDatacenter_updateSku(t *testing.T) { }, data.ImportStep(), { - Config: r.updateSku(data, "Standard_DS13_v2"), + Config: r.basicSku(data, "Standard_DS13_v2"), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS13_v2"), @@ -80,7 +81,7 @@ func testAccCassandraDatacenter_updateSku(t *testing.T) { }, data.ImportStep(), { - Config: r.basic(data), + Config: r.basicSku(data, "Standard_DS14_v2"), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), @@ -99,7 +100,7 @@ func testAccCassandraDatacenter_updateSku(t *testing.T) { }, data.ImportStep(), { - Config: r.updateSku(data, "Standard_E2_v5"), + Config: r.basicSku(data, "Standard_E2_v5"), Check: acceptance.ComposeAggregateTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E2_v5"), @@ -148,6 +149,23 @@ resource "azurerm_cosmosdb_cassandra_datacenter" "test" { `, r.template(data), data.RandomInteger) } +func (r CassandraDatacenterResource) basicSku(data acceptance.TestData, skuName string) string { + return fmt.Sprintf(` +%s + +resource "azurerm_cosmosdb_cassandra_datacenter" "test" { + name = "acctca-mi-dc-%d" + cassandra_cluster_id = azurerm_cosmosdb_cassandra_cluster.test.id + location = azurerm_cosmosdb_cassandra_cluster.test.location + delegated_management_subnet_id = azurerm_subnet.test.id + node_count = 3 + disk_count = 4 + sku_name = "%s" + availability_zones_enabled = false +} +`, r.template(data), data.RandomInteger, skuName) +} + func (r CassandraDatacenterResource) complete(data acceptance.TestData, nodeCount int) string { return fmt.Sprintf(` %s @@ -413,20 +431,3 @@ resource "azurerm_cosmosdb_cassandra_cluster" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger) } - -func (r CassandraDatacenterResource) updateSku(data acceptance.TestData, skuName string) string { - return fmt.Sprintf(` -%s - -resource "azurerm_cosmosdb_cassandra_datacenter" "test" { - name = "acctca-mi-dc-%d" - cassandra_cluster_id = azurerm_cosmosdb_cassandra_cluster.test.id - location = azurerm_cosmosdb_cassandra_cluster.test.location - delegated_management_subnet_id = azurerm_subnet.test.id - node_count = 3 - disk_count = 4 - sku_name = "%s" - availability_zones_enabled = false -} -`, r.template(data), data.RandomInteger, skuName) -} diff --git a/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown b/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown index e648138a55c0..e2549b332d90 100644 --- a/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown +++ b/website/docs/r/cosmosdb_cassandra_datacenter.html.markdown @@ -98,9 +98,9 @@ The following arguments are supported: * `managed_disk_customer_key_uri` - (Optional) The key URI of the customer key to use for the encryption of the Managed Disk. -* `sku_name` - (Optional) Determines the selected sku. Defaults to `Standard_DS14_v2`. +* `sku_name` - (Optional) Determines the selected sku. --> **NOTE:** In v4.0 of the provider the default value for the `sku_name` field will be changed to `Standard_E16s_v5`. +-> **NOTE:** In v4.0 of the provider the `sku_name` will have a default value of `Standard_E16s_v5`. * `disk_count` - (Optional) Determines the number of p30 disks that are attached to each node. From 4edcea5fd9bfafddb5f6a7b493377f5e191e502a Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:53:09 -0600 Subject: [PATCH 5/5] Make Sku conditional in Create function... --- .../cosmos/cosmosdb_cassandra_datacenter_resource.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go index 8c2eb48dcd4e..2eeacd8682b5 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go @@ -159,7 +159,6 @@ func resourceCassandraDatacenterCreate(d *pluginsdk.ResourceData, meta interface Properties: &managedcassandras.DataCenterResourceProperties{ DelegatedSubnetId: utils.String(d.Get("delegated_management_subnet_id").(string)), NodeCount: utils.Int64(int64(d.Get("node_count").(int))), - Sku: utils.String(d.Get("sku_name").(string)), AvailabilityZone: utils.Bool(d.Get("availability_zones_enabled").(bool)), DiskCapacity: utils.Int64(int64(d.Get("disk_count").(int))), DiskSku: utils.String(d.Get("disk_sku").(string)), @@ -179,6 +178,10 @@ func resourceCassandraDatacenterCreate(d *pluginsdk.ResourceData, meta interface payload.Properties.ManagedDiskCustomerKeyUri = utils.String(v.(string)) } + if v, ok := d.GetOk("sku_name"); ok { + payload.Properties.Sku = utils.String(v.(string)) + } + if err = client.CassandraDataCentersCreateUpdateThenPoll(ctx, id, payload); err != nil { return fmt.Errorf("creating %q: %+v", id, err) }