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

mssql_elasticpool - support license_type #6631

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -61,6 +61,11 @@ func dataSourceArmMsSqlElasticpool() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},

"license_type": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -99,6 +104,7 @@ func dataSourceArmMsSqlElasticpoolRead(d *schema.ResourceData, meta interface{})
d.Set("max_size_bytes", props.MaxSizeBytes)

d.Set("zone_redundant", props.ZoneRedundant)
d.Set("license_type", props.LicenseType)

if perDbSettings := props.PerDatabaseSettings; perDbSettings != nil {
d.Set("per_db_min_capacity", perDbSettings.MinCapacity)
Expand Down
12 changes: 12 additions & 0 deletions azurerm/internal/services/mssql/resource_arm_mssql_elasticpool.go
Expand Up @@ -151,6 +151,16 @@ func resourceArmMsSqlElasticPool() *schema.Resource {
Optional: true,
},

"license_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
string(sql.BasePrice),
string(sql.LicenseIncluded),
}, false),
},
pearcec marked this conversation as resolved.
Show resolved Hide resolved

"tags": tags.Schema(),
},

Expand Down Expand Up @@ -199,6 +209,7 @@ func resourceArmMsSqlElasticPoolCreateUpdate(d *schema.ResourceData, meta interf
Tags: tags.Expand(t),
ElasticPoolProperties: &sql.ElasticPoolProperties{
PerDatabaseSettings: expandAzureRmMsSqlElasticPoolPerDatabaseSettings(d),
LicenseType: sql.ElasticPoolLicenseType(d.Get("license_type").(string)),
pearcec marked this conversation as resolved.
Show resolved Hide resolved
},
}

Expand Down Expand Up @@ -279,6 +290,7 @@ func resourceArmMsSqlElasticPoolRead(d *schema.ResourceData, meta interface{}) e
}
}
d.Set("zone_redundant", properties.ZoneRedundant)
d.Set("license_type", string(properties.LicenseType))

if err := d.Set("per_database_settings", flattenAzureRmMsSqlElasticPoolPerDatabaseSettings(properties.PerDatabaseSettings)); err != nil {
return fmt.Errorf("Error setting `per_database_settings`: %+v", err)
Expand Down
Expand Up @@ -35,6 +35,25 @@ func TestAccDataSourceAzureRMMsSqlElasticPool_basic(t *testing.T) {
})
}

func TestAccDataSourceAzureRMMsSqlElasticPool_licenseType(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_mssql_elasticpool", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMMsSqlElasticPoolDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureRMMsSqlElasticPool_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "license_type", "LicenseIncluded"),
),
},
},
})
}

func testAccDataSourceAzureRMMsSqlElasticPool_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
Expand Up @@ -242,6 +242,32 @@ func TestAccAzureRMMsSqlElasticPool_resize_vCore(t *testing.T) {
})
}

func TestAccAzureRMMsSqlElasticPool_licenseType(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mssql_elasticpool", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMMsSqlElasticPoolDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMMsSqlElasticPool_licenseTypeLicenseIncluded(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "license_type", "LicenseIncluded"),
),
},
pearcec marked this conversation as resolved.
Show resolved Hide resolved
{
Config: testAccAzureRMMsSqlElasticPool_licenseTypeBasePrice(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMMsSqlElasticPoolExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "license_type", "BasePrice"),
),
},
pearcec marked this conversation as resolved.
Show resolved Hide resolved
},
})
}

func testCheckAzureRMMsSqlElasticPoolExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).MSSQL.ElasticPoolsClient
Expand Down Expand Up @@ -497,3 +523,56 @@ resource "azurerm_mssql_elasticpool" "test" {
}
`, data.RandomInteger, data.Locations.Primary, skuName, skuTier, skuCapacity, maxSizeGB, databaseSettingsMin, databaseSettingsMax, zoneRedundant)
}

func testAccAzureRMMsSqlElasticPool_licenseTypeBasePrice(data acceptance.TestData) string {
return testAccAzureRMMsSqlElasticPool_licenseType_Template(data, "BasePrice")
}

func testAccAzureRMMsSqlElasticPool_licenseTypeLicenseIncluded(data acceptance.TestData) string {
return testAccAzureRMMsSqlElasticPool_licenseType_Template(data, "LicenseIncluded")
}
pearcec marked this conversation as resolved.
Show resolved Hide resolved

func testAccAzureRMMsSqlElasticPool_licenseType_Template(data acceptance.TestData, licenseType string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%s"
}

resource "azurerm_sql_server" "test" {
name = "acctest%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
version = "12.0"
administrator_login = "4dm1n157r470r"
administrator_login_password = "4-v3ry-53cr37-p455w0rd"
}

resource "azurerm_mssql_elasticpool" "test" {
name = "acctest-pool-dtu-%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
server_name = azurerm_sql_server.test.name
max_size_gb = 50
zone_redundant = false
license_type = "%[3]s"

sku {
name = "GP_Gen5"
tier = "GeneralPurpose"
capacity = 4
family = "Gen5"
}

per_database_settings {
min_capacity = 0
max_capacity = 4
}

}
`, data.RandomInteger, data.Locations.Primary, licenseType)
}
2 changes: 2 additions & 0 deletions website/docs/d/mssql_elasticpool.html.markdown
Expand Up @@ -34,6 +34,8 @@ output "elasticpool_id" {

## Attributes Reference

* `license_type` - The license type to apply for this database.

* `location` - Specifies the supported Azure location where the resource exists.

* `max_size_gb` - The max data size of the elastic pool in gigabytes.
Expand Down
5 changes: 4 additions & 1 deletion website/docs/r/mssql_elasticpool.html.markdown
Expand Up @@ -8,7 +8,7 @@ description: |-

# azurerm_mssql_elasticpool

Allows you to manage an Azure SQL Elastic Pool via the `2017-10-01-preview` API which allows for `vCore` and `DTU` based configurations.
Allows you to manage an Azure SQL Elastic Pool via the `v3.0` API which allows for `vCore` and `DTU` based configurations.

## Example Usage

Expand All @@ -32,6 +32,7 @@ resource "azurerm_mssql_elasticpool" "example" {
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
server_name = azurerm_sql_server.example.name
license_type = "LicenseIncluded"
max_size_gb = 756

sku {
Expand Down Expand Up @@ -72,6 +73,8 @@ The following arguments are supported:

* `zone_redundant` - (Optional) Whether or not this elastic pool is zone redundant. `tier` needs to be `Premium` for `DTU` based or `BusinessCritical` for `vCore` based `sku`. Defaults to `false`.

* `license_type` - (Optional) Specifies the license type applied to this database. Possible values are `LicenseIncluded` and `BasePrice`.

---

`sku` supports the following:
Expand Down