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

2.0 mariadb #5777

Merged
merged 3 commits into from
Feb 17, 2020
Merged
Changes from 2 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
127 changes: 5 additions & 122 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,8 @@ 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"},
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"B_Gen5_1",
"B_Gen5_2",
Expand All @@ -73,68 +71,6 @@ func resourceArmMariaDbServer() *schema.Resource {
}, false),
},

// remove in 2.0
"sku": {
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": {
Type: schema.TypeString,
Required: true,
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),
},

"capacity": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntInSlice([]int{
1,
2,
4,
8,
16,
32,
}),
},

"tier": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(mariadb.Basic),
string(mariadb.GeneralPurpose),
string(mariadb.MemoryOptimized),
}, false),
},

"family": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"Gen5",
}, false),
},
},
},
},

"administrator_login": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -248,17 +184,9 @@ func resourceArmMariaDbServerCreateUpdate(d *schema.ResourceData, meta interface

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)
sku, err := expandServerSkuName(d.Get("sku_name").(string))
if err != nil {
return fmt.Errorf("error expanding sku_name for PostgreSQL Server %q (Resource Group %q): %v", name, resourceGroup, err)
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
}

skuName := sku.Name
Expand Down Expand Up @@ -396,10 +324,6 @@ func resourceArmMariaDbServerRead(d *schema.ResourceData, meta interface{}) erro
}
}

if err := d.Set("sku", flattenMariaDbServerSku(resp.Sku)); err != nil {
return fmt.Errorf("Error setting `sku`: %+v", err)
}

return tags.FlattenAndSet(d, resp.Tags)
}

Expand Down Expand Up @@ -466,23 +390,6 @@ func expandServerSkuName(skuName string) (*mariadb.Sku, error) {
}, nil
}

func expandAzureRmMariaDbServerSku(d *schema.ResourceData) *mariadb.Sku {
skus := d.Get("sku").([]interface{})
sku := skus[0].(map[string]interface{})

name := sku["name"].(string)
capacity := sku["capacity"].(int)
tier := sku["tier"].(string)
family := sku["family"].(string)

return &mariadb.Sku{
Name: utils.String(name),
Tier: mariadb.SkuTier(tier),
Capacity: utils.Int32(int32(capacity)),
Family: utils.String(family),
}
}

func expandAzureRmMariaDbStorageProfile(d *schema.ResourceData) *mariadb.StorageProfile {
storageprofiles := d.Get("storage_profile").([]interface{})
storageprofile := storageprofiles[0].(map[string]interface{})
Expand All @@ -500,30 +407,6 @@ func expandAzureRmMariaDbStorageProfile(d *schema.ResourceData) *mariadb.Storage
}
}

func flattenMariaDbServerSku(sku *mariadb.Sku) []interface{} {
values := map[string]interface{}{}

if sku == nil {
return []interface{}{}
}

if name := sku.Name; name != nil {
values["name"] = *name
}

if capacity := sku.Capacity; capacity != nil {
values["capacity"] = *capacity
}

values["tier"] = string(sku.Tier)

if family := sku.Family; family != nil {
values["family"] = *family
}

return []interface{}{values}
}

func flattenMariaDbStorageProfile(storage *mariadb.StorageProfile) []interface{} {
values := map[string]interface{}{}

Expand Down