From c151157b7bd2e10cf4975cefa0295b007a46413c Mon Sep 17 00:00:00 2001 From: kt Date: Sun, 12 Jan 2020 13:44:10 -0800 Subject: [PATCH 1/4] azurerm_mariadb_server: deprecate sku in favour of sku_name --- .../mariadb/resource_arm_mariadb_server.go | 94 ++++++++++++--- .../resource_arm_mariadb_database_test.go | 7 +- .../tests/resource_arm_mariadb_server_test.go | 110 ++++++++++-------- .../guides/2.0-upgrade-guide.html.markdown | 4 + .../r/mariadb_configuration.html.markdown | 7 +- website/docs/r/mariadb_database.html.markdown | 7 +- website/docs/r/mariadb_server.html.markdown | 21 +--- ...mariadb_virtual_network_rule.html.markdown | 7 +- 8 files changed, 150 insertions(+), 107 deletions(-) diff --git a/azurerm/internal/services/mariadb/resource_arm_mariadb_server.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_server.go index 684c43f8818b..2c3e0a532496 100644 --- a/azurerm/internal/services/mariadb/resource_arm_mariadb_server.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_server.go @@ -54,10 +54,34 @@ func resourceArmMariaDbServer() *schema.Resource { "resource_group_name": azure.SchemaResourceGroupName(), + "sku_name": { + Type: schema.TypeString, + Optional: true, // required in 2.0 + Computed: true, // remove in 2.0 + ConflictsWith: []string{"sku"}, + ValidateFunc: validation.StringInSlice([]string{ + "B_Gen5_1", + "B_Gen5_2", + "GP_Gen5_2", + "GP_Gen5_4", + "GP_Gen5_8", + "GP_Gen5_16", + "GP_Gen5_32", + "MO_Gen5_2", + "MO_Gen5_4", + "MO_Gen5_8", + "MO_Gen5_16", + }, false), + }, + + // remove in 2.0 "sku": { - Type: schema.TypeList, - Required: true, - MaxItems: 1, + Type: schema.TypeList, + Optional: true, + Computed: true, + ConflictsWith: []string{"sku_name"}, + Deprecated: "This property has been deprecated in favour of the 'sku_name' property and will be removed in version 2.0 of the provider", + MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { @@ -219,15 +243,22 @@ func resourceArmMariaDbServerCreateUpdate(d *schema.ResourceData, meta interface } location := azure.NormalizeLocation(d.Get("location").(string)) - adminLogin := d.Get("administrator_login").(string) - adminLoginPassword := d.Get("administrator_login_password").(string) - sslEnforcement := d.Get("ssl_enforcement").(string) - version := d.Get("version").(string) - t := d.Get("tags").(map[string]interface{}) - sku := expandAzureRmMariaDbServerSku(d) storageProfile := expandAzureRmMariaDbStorageProfile(d) + var sku *mariadb.Sku + if b, ok := d.GetOk("sku_name"); ok { + var err error + sku, err = expandServerSkuName(b.(string)) + if err != nil { + return fmt.Errorf("error expanding sku_name for PostgreSQL Server %q (Resource Group %q): %v", name, resourceGroup, err) + } + } else if _, ok := d.GetOk("sku"); ok { + sku = expandAzureRmMariaDbServerSku(d) + } else { + return fmt.Errorf("One of `sku` or `sku_name` must be set for PostgreSQL Server %q (Resource Group %q)", name, resourceGroup) + } + skuName := sku.Name capacity := sku.Capacity tier := string(sku.Tier) @@ -283,15 +314,15 @@ func resourceArmMariaDbServerCreateUpdate(d *schema.ResourceData, meta interface properties := mariadb.ServerForCreate{ Location: &location, Properties: &mariadb.ServerPropertiesForDefaultCreate{ - AdministratorLogin: utils.String(adminLogin), - AdministratorLoginPassword: utils.String(adminLoginPassword), - Version: mariadb.ServerVersion(version), - SslEnforcement: mariadb.SslEnforcementEnum(sslEnforcement), + AdministratorLogin: utils.String(d.Get("administrator_login").(string)), + AdministratorLoginPassword: utils.String(d.Get("administrator_login_password").(string)), + Version: mariadb.ServerVersion(d.Get("version").(string)), + SslEnforcement: mariadb.SslEnforcementEnum(d.Get("ssl_enforcement").(string)), StorageProfile: storageProfile, CreateMode: mariadb.CreateModeDefault, }, Sku: sku, - Tags: tags.Expand(t), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } future, err := client.Create(ctx, resourceGroup, name, properties) @@ -347,6 +378,10 @@ func resourceArmMariaDbServerRead(d *schema.ResourceData, meta interface{}) erro d.Set("location", azure.NormalizeLocation(*location)) } + if sku := resp.Sku; sku != nil { + d.Set("sku_name", sku.Name) + } + if properties := resp.ServerProperties; properties != nil { d.Set("administrator_login", properties.AdministratorLogin) d.Set("version", string(properties.Version)) @@ -398,6 +433,37 @@ func resourceArmMariaDbServerDelete(d *schema.ResourceData, meta interface{}) er return nil } +func expandServerSkuName(skuName string) (*mariadb.Sku, error) { + parts := strings.Split(skuName, "_") + if len(parts) != 3 { + return nil, fmt.Errorf("sku_name (%s) has the worng numberof parts (%d) after splitting on _", skuName, len(parts)) + } + + var tier mariadb.SkuTier + switch parts[0] { + case "B": + tier = mariadb.Basic + case "GP": + tier = mariadb.GeneralPurpose + case "MO": + tier = mariadb.MemoryOptimized + default: + return nil, fmt.Errorf("sku_name %s has unknown sku tier %s", skuName, parts[0]) + } + + capacity, err := strconv.Atoi(parts[2]) + if err != nil { + return nil, fmt.Errorf("cannot convert skuname %s capcity %s to int", skuName, parts[2]) + } + + return &mariadb.Sku{ + Name: utils.String(skuName), + Tier: tier, + Capacity: utils.Int32(int32(capacity)), + Family: utils.String(parts[1]), + }, nil +} + func expandAzureRmMariaDbServerSku(d *schema.ResourceData) *mariadb.Sku { skus := d.Get("sku").([]interface{}) sku := skus[0].(map[string]interface{}) diff --git a/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_database_test.go b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_database_test.go index a9cf1fd56960..15a92fa916f7 100644 --- a/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_database_test.go +++ b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_database_test.go @@ -128,12 +128,7 @@ resource "azurerm_mariadb_server" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku { - name = "B_Gen5_2" - capacity = 2 - tier = "Basic" - family = "Gen5" - } + sku_name = "B_Gen5_2" storage_profile { storage_mb = 51200 diff --git a/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go index 561376bb1575..78665b570227 100644 --- a/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go +++ b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go @@ -34,6 +34,28 @@ func TestAccAzureRMMariaDbServer_basic(t *testing.T) { }) } +func TestAccAzureRMMariaDbServer_basicOldSku(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_mariadb_server", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMMariaDbServerDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMMariaDbServer_basicOldSku(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMMariaDbServerExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "administrator_login", "acctestun"), + resource.TestCheckResourceAttr(data.ResourceName, "version", "10.2"), + resource.TestCheckResourceAttr(data.ResourceName, "ssl_enforcement", "Enabled"), + ), + }, + data.ImportStep("administrator_login_password"), // not returned as sensitive + }, + }) +} + func TestAccAzureRMMariaDbServer_requiresImport(t *testing.T) { if !features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -303,13 +325,41 @@ resource "azurerm_resource_group" "test" { location = "%s" } +resource "azurerm_mariadb_server" "test" { + name = "acctestmariadbsvr-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + + sku_name = "B_Gen5_2" + + storage_profile { + storage_mb = 51200 + backup_retention_days = 7 + geo_redundant_backup = "Disabled" + } + + administrator_login = "acctestun" + administrator_login_password = "H@Sh1CoR3!" + version = "10.2" + ssl_enforcement = "Enabled" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} + +func testAccAzureRMMariaDbServer_basicOldSku(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + resource "azurerm_mariadb_server" "test" { name = "acctestmariadbsvr-%d" location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" sku { - name = "B_Gen5_2" + name = "B_Gen5_21" capacity = 2 tier = "Basic" family = "Gen5" @@ -339,12 +389,7 @@ resource "azurerm_mariadb_server" "import" { location = "${azurerm_mariadb_server.test.location}" resource_group_name = "${azurerm_mariadb_server.test.resource_group_name}" - sku { - name = "B_Gen5_2" - capacity = 2 - tier = "Basic" - family = "Gen5" - } + sku_name = "B_Gen5_2" storage_profile { storage_mb = 51200 @@ -372,12 +417,7 @@ resource "azurerm_mariadb_server" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku { - name = "B_Gen5_2" - capacity = 2 - tier = "Basic" - family = "Gen5" - } + sku_name = "B_Gen5_2" storage_profile { storage_mb = 51200 @@ -405,12 +445,7 @@ resource "azurerm_mariadb_server" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku { - name = "B_Gen5_1" - capacity = 1 - tier = "Basic" - family = "Gen5" - } + sku_name = "B_Gen5_1" storage_profile { storage_mb = 640000 @@ -438,12 +473,7 @@ resource "azurerm_mariadb_server" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku { - name = "B_Gen5_2" - capacity = 2 - tier = "Basic" - family = "Gen5" - } + sku_name = "B_Gen5_2" storage_profile { storage_mb = 947200 @@ -471,12 +501,7 @@ resource "azurerm_mariadb_server" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku { - name = "GP_Gen5_32" - capacity = 32 - tier = "GeneralPurpose" - family = "Gen5" - } + sku_name = "GP_Gen5_32" storage_profile { storage_mb = 640000 @@ -504,12 +529,7 @@ resource "azurerm_mariadb_server" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku { - name = "MO_Gen5_16" - capacity = 16 - tier = "MemoryOptimized" - family = "Gen5" - } + sku_name = "MO_Gen5_16" storage_profile { storage_mb = 4096000 @@ -537,13 +557,8 @@ resource "azurerm_mariadb_server" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku { - name = "MO_Gen5_16" - capacity = 16 - tier = "MemoryOptimized" - family = "Gen5" - } - + sku_name = "MO_Gen5_16" + storage_profile { storage_mb = 4096000 backup_retention_days = 7 @@ -570,12 +585,7 @@ resource "azurerm_mariadb_server" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" - sku { - name = "B_Gen5_2" - capacity = 2 - tier = "Basic" - family = "Gen5" - } + sku_name = "B_Gen5_2" storage_profile { storage_mb = 51200 diff --git a/website/docs/guides/2.0-upgrade-guide.html.markdown b/website/docs/guides/2.0-upgrade-guide.html.markdown index a3b41e341ecf..b9518ad56094 100644 --- a/website/docs/guides/2.0-upgrade-guide.html.markdown +++ b/website/docs/guides/2.0-upgrade-guide.html.markdown @@ -339,6 +339,10 @@ This resource has been renamed to `azurerm_log_analytics_linked_service` which i The deprecated field `linked_service_properties` will be removed. This has been replaced by the `resource_id` resource. +### Resource: `azurerm_mariadb_server` + +The deprecated `sku` block has been simplified and replaced by the `sku_name` block and will be removed. + ### Resource: `azurerm_mssql_elasticpool` The deprecated `elastic_pool_properties` block will be removed. The fields inside this block have been moved to the top-level. diff --git a/website/docs/r/mariadb_configuration.html.markdown b/website/docs/r/mariadb_configuration.html.markdown index d42ddf57efe3..10091b78c961 100644 --- a/website/docs/r/mariadb_configuration.html.markdown +++ b/website/docs/r/mariadb_configuration.html.markdown @@ -23,12 +23,7 @@ resource "azurerm_mariadb_server" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku { - name = "B_Gen5_2" - capacity = 2 - tier = "Basic" - family = "Gen5" - } + sku_name = "B_Gen5_2" storage_profile { storage_mb = 5120 diff --git a/website/docs/r/mariadb_database.html.markdown b/website/docs/r/mariadb_database.html.markdown index f624281bf1d7..98e20808e0c3 100644 --- a/website/docs/r/mariadb_database.html.markdown +++ b/website/docs/r/mariadb_database.html.markdown @@ -23,12 +23,7 @@ resource "azurerm_mariadb_server" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku { - name = "B_Gen5_2" - capacity = 2 - tier = "Basic" - family = "Gen5" - } + sku_name = "B_Gen5_2" storage_profile { storage_mb = 51200 diff --git a/website/docs/r/mariadb_server.html.markdown b/website/docs/r/mariadb_server.html.markdown index 0e518a81e276..d555dd480008 100644 --- a/website/docs/r/mariadb_server.html.markdown +++ b/website/docs/r/mariadb_server.html.markdown @@ -23,12 +23,7 @@ resource "azurerm_mariadb_server" "example" { location = "${azurerm_resource_group.example.location}" resource_group_name = "${azurerm_resource_group.example.name}" - sku { - name = "B_Gen5_2" - capacity = 2 - tier = "Basic" - family = "Gen5" - } + sku_name = "B_Gen5_2" storage_profile { storage_mb = 5120 @@ -54,7 +49,7 @@ The following arguments are supported: * `location` - (Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. -* `sku` - (Required) A `sku` block as defined below. +* `sku_name` - (Required) Specifies the SKU Name for this MariaDB Server. The name of the SKU, follows the `tier` + `family` + `cores` pattern (e.g. `B_Gen4_1`, `GP_Gen5_8`). For more information see the [product documentation](https://docs.microsoft.com/en-us/rest/api/mariadb/servers/create#sku). * `storage_profile` - (Required) A `storage_profile` block as defined below. @@ -70,18 +65,6 @@ The following arguments are supported: --- -A `sku` block supports the following: - -* `name` - (Required) Specifies the SKU Name for this MariaDB Server. The name of the SKU, follows the `tier` + `family` + `cores` pattern (e.g. `B_Gen5_1`, `GP_Gen5_8`). For more information see the [product documentation](https://docs.microsoft.com/en-us/rest/api/mariadb/servers/create#sku). - -* `capacity` - (Required) The scale up/out capacity, representing server's compute units. - -* `tier` - (Required) The tier of the particular SKU. Possible values are `Basic`, `GeneralPurpose`, and `MemoryOptimized`. For more information see the [product documentation](https://docs.microsoft.com/en-us/azure/mariadb/concepts-pricing-tiers). - -* `family` - (Required) The `family` of the hardware (e.g. `Gen5`), before selecting your `family` check the [product documentation](https://docs.microsoft.com/en-us/azure/mariadb/concepts-pricing-tiers#compute-generations-vcores-and-memory) for availability in your region. - ---- - A `storage_profile` block supports the following: * `storage_mb` - (Required) Max storage allowed for a server. Possible values are between `5120` MB (5GB) and `1024000`MB (1TB) for the Basic SKU and between `5120` MB (5GB) and `4096000` MB (4TB) for General Purpose/Memory Optimized SKUs. For more information see the [product documentation](https://docs.microsoft.com/en-us/rest/api/mariadb/servers/create#storageprofile). diff --git a/website/docs/r/mariadb_virtual_network_rule.html.markdown b/website/docs/r/mariadb_virtual_network_rule.html.markdown index 1ed39d3ff7ad..4d6e9287107d 100644 --- a/website/docs/r/mariadb_virtual_network_rule.html.markdown +++ b/website/docs/r/mariadb_virtual_network_rule.html.markdown @@ -44,12 +44,7 @@ resource "azurerm_mariadb_server" "example" { version = "5.7" ssl_enforcement = "Enabled" - sku { - name = "GP_Gen5_2" - capacity = 2 - tier = "GeneralPurpose" - family = "Gen5" - } + sku_name = "GP_Gen5_2" storage_profile { storage_mb = 5120 From 06169d2e7299af459090d8c0172d0bd78818b535 Mon Sep 17 00:00:00 2001 From: kt Date: Sun, 12 Jan 2020 14:47:50 -0800 Subject: [PATCH 2/4] tidy up guide wording --- website/docs/guides/2.0-upgrade-guide.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/guides/2.0-upgrade-guide.html.markdown b/website/docs/guides/2.0-upgrade-guide.html.markdown index b9518ad56094..9a274cab7a0d 100644 --- a/website/docs/guides/2.0-upgrade-guide.html.markdown +++ b/website/docs/guides/2.0-upgrade-guide.html.markdown @@ -341,7 +341,7 @@ The deprecated field `linked_service_properties` will be removed. This has been ### Resource: `azurerm_mariadb_server` -The deprecated `sku` block has been simplified and replaced by the `sku_name` block and will be removed. +The deprecated `sku` block has been simplified and replaced by the `sku_name` property and will be removed. ### Resource: `azurerm_mssql_elasticpool` From e40eec9d8e8673cec99405463e4360be77610533 Mon Sep 17 00:00:00 2001 From: kt Date: Sun, 12 Jan 2020 14:52:25 -0800 Subject: [PATCH 3/4] fix test --- .../services/mariadb/tests/resource_arm_mariadb_server_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go index 78665b570227..1a95fed0b1a7 100644 --- a/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go +++ b/azurerm/internal/services/mariadb/tests/resource_arm_mariadb_server_test.go @@ -359,7 +359,7 @@ resource "azurerm_mariadb_server" "test" { resource_group_name = "${azurerm_resource_group.test.name}" sku { - name = "B_Gen5_21" + name = "B_Gen5_2" capacity = 2 tier = "Basic" family = "Gen5" From a18efdaeccfa6997e5d5fc766a131bc31680ec01 Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 13 Jan 2020 18:48:01 -0800 Subject: [PATCH 4/4] fix guide wording --- .../internal/services/mariadb/resource_arm_mariadb_server.go | 2 +- website/docs/guides/2.0-upgrade-guide.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/mariadb/resource_arm_mariadb_server.go b/azurerm/internal/services/mariadb/resource_arm_mariadb_server.go index 2c3e0a532496..88f6a58c66c5 100644 --- a/azurerm/internal/services/mariadb/resource_arm_mariadb_server.go +++ b/azurerm/internal/services/mariadb/resource_arm_mariadb_server.go @@ -436,7 +436,7 @@ func resourceArmMariaDbServerDelete(d *schema.ResourceData, meta interface{}) er func expandServerSkuName(skuName string) (*mariadb.Sku, error) { parts := strings.Split(skuName, "_") if len(parts) != 3 { - return nil, fmt.Errorf("sku_name (%s) has the worng numberof parts (%d) after splitting on _", skuName, len(parts)) + return nil, fmt.Errorf("sku_name (%s) has the worng number of parts (%d) after splitting on _", skuName, len(parts)) } var tier mariadb.SkuTier diff --git a/website/docs/guides/2.0-upgrade-guide.html.markdown b/website/docs/guides/2.0-upgrade-guide.html.markdown index 9a274cab7a0d..4ff685fe81a5 100644 --- a/website/docs/guides/2.0-upgrade-guide.html.markdown +++ b/website/docs/guides/2.0-upgrade-guide.html.markdown @@ -341,7 +341,7 @@ The deprecated field `linked_service_properties` will be removed. This has been ### Resource: `azurerm_mariadb_server` -The deprecated `sku` block has been simplified and replaced by the `sku_name` property and will be removed. +The deprecated `sku` block has been replaced by the `sku_name` field and will be removed. ### Resource: `azurerm_mssql_elasticpool`