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_mssql_elasticpool: moved elastic_pool_properties properties to the top level #2378

Merged
merged 2 commits into from
Nov 22, 2018
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
83 changes: 52 additions & 31 deletions azurerm/resource_arm_mssql_elasticpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,39 +119,55 @@ func resourceArmMsSqlElasticPool() *schema.Resource {
},

"elastic_pool_properties": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Deprecated: "All properties herein have been move to the top level",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"state": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Deprecated: "This property has been moved to the top level",
},

"creation_date": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Deprecated: "This property has been moved to the top level",
},

"max_size_bytes": {
Type: schema.TypeInt,
Computed: true,
Type: schema.TypeInt,
Computed: true,
Deprecated: "This property has been moved to the top level",
},

"zone_redundant": {
Type: schema.TypeBool,
Computed: true,
Type: schema.TypeBool,
Computed: true,
Deprecated: "This property has been moved to the top level",
},

"license_type": {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
Computed: true,
Deprecated: "This property has been moved to the top level",
},
},
},
},

katbyte marked this conversation as resolved.
Show resolved Hide resolved
"max_size_bytes": {
Type: schema.TypeInt,
Computed: true,
},

"zone_redundant": {
Type: schema.TypeBool,
Computed: true,
},

"tags": tagsSchema(),
},

Expand Down Expand Up @@ -208,7 +224,7 @@ func resourceArmMsSqlElasticPool() *schema.Resource {
}
}

// Addutional checks based of SKU type...
// Additional checks based of SKU type...
if strings.HasPrefix(strings.ToLower(name.(string)), "gp_") || strings.HasPrefix(strings.ToLower(name.(string)), "bc_") {
// vCore based
if maxCapacity.(float64) > float64(capacity.(int)) {
Expand Down Expand Up @@ -249,15 +265,16 @@ func resourceArmMsSqlElasticPoolCreate(d *schema.ResourceData, meta interface{})
location := azureRMNormalizeLocation(d.Get("location").(string))
resGroup := d.Get("resource_group_name").(string)
sku := expandAzureRmMsSqlElasticPoolSku(d)
properties := expandAzureRmMsSqlElasticPoolProperties(d)
tags := d.Get("tags").(map[string]interface{})

elasticPool := sql.ElasticPool{
Sku: sku,
ElasticPoolProperties: properties,
Location: &location,
Tags: expandTags(tags),
Name: &elasticPoolName,
Name: &elasticPoolName,
Location: &location,
Sku: sku,
Tags: expandTags(tags),
ElasticPoolProperties: &sql.ElasticPoolProperties{
PerDatabaseSettings: expandAzureRmMsSqlElasticPoolPerDatabaseSettings(d),
},
}

future, err := client.CreateOrUpdate(ctx, resGroup, serverName, elasticPoolName, elasticPool)
Expand Down Expand Up @@ -313,12 +330,18 @@ func resourceArmMsSqlElasticPoolRead(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("Error setting `sku`: %+v", err)
}

if err := d.Set("elastic_pool_properties", flattenAzureRmMsSqlElasticPoolProperties(resp.ElasticPoolProperties)); err != nil {
return fmt.Errorf("Error setting `elastic_pool_properties`: %+v", err)
}
if properties := resp.ElasticPoolProperties; properties != nil {
d.Set("max_size_bytes", properties.MaxSizeBytes)
d.Set("zone_redundant", properties.ZoneRedundant)

if err := d.Set("per_database_settings", flattenAzureRmMsSqlElasticPoolPerDatabaseSettings(resp.ElasticPoolProperties.PerDatabaseSettings)); err != nil {
return fmt.Errorf("Error setting `per_database_settings`: %+v", err)
//todo remove in 2.0
if err := d.Set("elastic_pool_properties", flattenAzureRmMsSqlElasticPoolProperties(resp.ElasticPoolProperties)); err != nil {
return fmt.Errorf("Error setting `elastic_pool_properties`: %+v", err)
}

if err := d.Set("per_database_settings", flattenAzureRmMsSqlElasticPoolPerDatabaseSettings(properties.PerDatabaseSettings)); err != nil {
return fmt.Errorf("Error setting `per_database_settings`: %+v", err)
}
}

flattenAndSetTags(d, resp.Tags)
Expand Down Expand Up @@ -348,18 +371,16 @@ func parseArmMsSqlElasticPoolId(sqlElasticPoolId string) (string, string, string
return id.ResourceGroup, id.Path["servers"], id.Path["elasticPools"], nil
}

func expandAzureRmMsSqlElasticPoolProperties(d *schema.ResourceData) *sql.ElasticPoolProperties {
func expandAzureRmMsSqlElasticPoolPerDatabaseSettings(d *schema.ResourceData) *sql.ElasticPoolPerDatabaseSettings {
perDatabaseSettings := d.Get("per_database_settings").([]interface{})
perDatabaseSetting := perDatabaseSettings[0].(map[string]interface{})

minCapacity := perDatabaseSetting["min_capacity"].(float64)
maxCapacity := perDatabaseSetting["max_capacity"].(float64)

return &sql.ElasticPoolProperties{
PerDatabaseSettings: &sql.ElasticPoolPerDatabaseSettings{
MinCapacity: utils.Float(minCapacity),
MaxCapacity: utils.Float(maxCapacity),
},
return &sql.ElasticPoolPerDatabaseSettings{
MinCapacity: utils.Float(minCapacity),
MaxCapacity: utils.Float(maxCapacity),
}
}

Expand Down
4 changes: 4 additions & 0 deletions azurerm/resource_arm_mssql_elasticpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestAccAzureRMMsSqlElasticPool_basic_DTU(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "sku.0.capacity", "50"),
resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0"),
resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "50"),
resource.TestCheckResourceAttrSet(resourceName, "max_size_bytes"),
resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"),
),
},
{
Expand Down Expand Up @@ -60,6 +62,8 @@ func TestAccAzureRMMsSqlElasticPool_basic_vCore(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "sku.0.family", "Gen5"),
resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.min_capacity", "0.25"),
resource.TestCheckResourceAttr(resourceName, "per_database_settings.0.max_capacity", "4"),
resource.TestCheckResourceAttrSet(resourceName, "max_size_bytes"),
resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"),
),
},
{
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/mssql_elasticpool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ The following attributes are exported:

* `id` - The MsSQL Elastic Pool ID.

* `creation_date` - The creation date of the MsSQL Elastic Pool.
* `max_size_bytes` - The storage limit for the database elastic pool in bytes.

* `zone_redundant` - Whether or not this elastic pool is zone redundant.

## Import

Expand Down