From 0fe8df0aee1a7768c3fe698b162a17186f7441af Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 22 Nov 2018 13:54:16 -0800 Subject: [PATCH 1/2] Moved properties in to the top level --- azurerm/resource_arm_mssql_elasticpool.go | 102 ++++++++++++------ .../resource_arm_mssql_elasticpool_test.go | 8 ++ 2 files changed, 79 insertions(+), 31 deletions(-) diff --git a/azurerm/resource_arm_mssql_elasticpool.go b/azurerm/resource_arm_mssql_elasticpool.go index b502629b17e6..ef59028af600 100644 --- a/azurerm/resource_arm_mssql_elasticpool.go +++ b/azurerm/resource_arm_mssql_elasticpool.go @@ -5,6 +5,7 @@ import ( "log" "math" "strings" + "time" "github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2017-10-01-preview/sql" "github.com/hashicorp/terraform/helper/schema" @@ -119,39 +120,70 @@ 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", }, }, }, }, + "state": { + Type: schema.TypeString, + Computed: true, + }, + + "creation_date": { + Type: schema.TypeString, + Computed: true, + }, + + "max_size_bytes": { + Type: schema.TypeInt, + Computed: true, + }, + + "zone_redundant": { + Type: schema.TypeBool, + Computed: true, + }, + + "license_type": { + Type: schema.TypeString, + Computed: true, + }, + "tags": tagsSchema(), }, @@ -208,7 +240,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)) { @@ -249,15 +281,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) @@ -313,12 +346,21 @@ 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("creation_date", properties.CreationDate.Format(time.RFC3339)) + d.Set("license_type", string(properties.LicenseType)) + d.Set("max_size_bytes", properties.MaxSizeBytes) + d.Set("state", string(properties.State)) + d.Set("zone_redundant", properties.ZoneRedundant) + + //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(resp.ElasticPoolProperties.PerDatabaseSettings)); err != nil { - return fmt.Errorf("Error setting `per_database_settings`: %+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) @@ -348,18 +390,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), } } diff --git a/azurerm/resource_arm_mssql_elasticpool_test.go b/azurerm/resource_arm_mssql_elasticpool_test.go index 934fd8d15243..61cdb56e066c 100644 --- a/azurerm/resource_arm_mssql_elasticpool_test.go +++ b/azurerm/resource_arm_mssql_elasticpool_test.go @@ -29,6 +29,10 @@ 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, "creation_date"), + resource.TestCheckResourceAttrSet(resourceName, "max_size_bytes"), + resource.TestCheckResourceAttrSet(resourceName, "state"), + resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"), ), }, { @@ -60,6 +64,10 @@ 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, "creation_date"), + resource.TestCheckResourceAttrSet(resourceName, "max_size_bytes"), + resource.TestCheckResourceAttrSet(resourceName, "state"), + resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"), ), }, { From f99feb5a7c7cb7c9c01582611b8a7152cbcde862 Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 22 Nov 2018 15:12:15 -0800 Subject: [PATCH 2/2] updates requested in pr #2378 --- azurerm/resource_arm_mssql_elasticpool.go | 19 ------------------- .../resource_arm_mssql_elasticpool_test.go | 4 ---- .../docs/r/mssql_elasticpool.html.markdown | 4 +++- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/azurerm/resource_arm_mssql_elasticpool.go b/azurerm/resource_arm_mssql_elasticpool.go index ef59028af600..69ce65171f1a 100644 --- a/azurerm/resource_arm_mssql_elasticpool.go +++ b/azurerm/resource_arm_mssql_elasticpool.go @@ -5,7 +5,6 @@ import ( "log" "math" "strings" - "time" "github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/2017-10-01-preview/sql" "github.com/hashicorp/terraform/helper/schema" @@ -159,16 +158,6 @@ func resourceArmMsSqlElasticPool() *schema.Resource { }, }, - "state": { - Type: schema.TypeString, - Computed: true, - }, - - "creation_date": { - Type: schema.TypeString, - Computed: true, - }, - "max_size_bytes": { Type: schema.TypeInt, Computed: true, @@ -179,11 +168,6 @@ func resourceArmMsSqlElasticPool() *schema.Resource { Computed: true, }, - "license_type": { - Type: schema.TypeString, - Computed: true, - }, - "tags": tagsSchema(), }, @@ -347,10 +331,7 @@ func resourceArmMsSqlElasticPoolRead(d *schema.ResourceData, meta interface{}) e } if properties := resp.ElasticPoolProperties; properties != nil { - d.Set("creation_date", properties.CreationDate.Format(time.RFC3339)) - d.Set("license_type", string(properties.LicenseType)) d.Set("max_size_bytes", properties.MaxSizeBytes) - d.Set("state", string(properties.State)) d.Set("zone_redundant", properties.ZoneRedundant) //todo remove in 2.0 diff --git a/azurerm/resource_arm_mssql_elasticpool_test.go b/azurerm/resource_arm_mssql_elasticpool_test.go index 61cdb56e066c..aa7fbb026c5a 100644 --- a/azurerm/resource_arm_mssql_elasticpool_test.go +++ b/azurerm/resource_arm_mssql_elasticpool_test.go @@ -29,9 +29,7 @@ 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, "creation_date"), resource.TestCheckResourceAttrSet(resourceName, "max_size_bytes"), - resource.TestCheckResourceAttrSet(resourceName, "state"), resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"), ), }, @@ -64,9 +62,7 @@ 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, "creation_date"), resource.TestCheckResourceAttrSet(resourceName, "max_size_bytes"), - resource.TestCheckResourceAttrSet(resourceName, "state"), resource.TestCheckResourceAttrSet(resourceName, "zone_redundant"), ), }, diff --git a/website/docs/r/mssql_elasticpool.html.markdown b/website/docs/r/mssql_elasticpool.html.markdown index 0559157baa36..1d2fe0088435 100644 --- a/website/docs/r/mssql_elasticpool.html.markdown +++ b/website/docs/r/mssql_elasticpool.html.markdown @@ -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