Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_mariadb_server: deprecate sku in favour of sku_name #5378

Merged
merged 4 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 80 additions & 14 deletions azurerm/internal/services/mariadb/resource_arm_mariadb_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 number of 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{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -303,6 +325,34 @@ 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}"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions website/docs/guides/2.0-upgrade-guide.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 replaced by the `sku_name` field 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.
Expand Down
7 changes: 1 addition & 6 deletions website/docs/r/mariadb_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions website/docs/r/mariadb_database.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading