Skip to content

Commit

Permalink
azurerm_sql_managed_instance: Support for storage_account_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Aris van Ommeren committed Nov 12, 2021
1 parent 8053272 commit e647406
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/services/sql/sql_managed_instance_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ func resourceArmSqlMiServer() *schema.Resource {

"identity": managedInstanceIdentity{}.Schema(),

"storage_account_type": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
Default: string(sql.StorageAccountTypeGRS),
ValidateFunc: validation.StringInSlice([]string{
string(sql.StorageAccountTypeGRS),
string(sql.StorageAccountTypeLRS),
string(sql.StorageAccountTypeZRS),
}, false),
},

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

Expand Down Expand Up @@ -232,6 +244,7 @@ func resourceArmSqlMiServerCreateUpdate(d *schema.ResourceData, meta interface{}
ProxyOverride: sql.ManagedInstanceProxyOverride(d.Get("proxy_override").(string)),
TimezoneID: utils.String(d.Get("timezone_id").(string)),
DNSZonePartner: utils.String(d.Get("dns_zone_partner_id").(string)),
StorageAccountType: sql.StorageAccountType(d.Get("storage_account_type").(string)),
},
}

Expand Down Expand Up @@ -307,6 +320,7 @@ func resourceArmSqlMiServerRead(d *schema.ResourceData, meta interface{}) error
d.Set("minimum_tls_version", props.MinimalTLSVersion)
d.Set("proxy_override", props.ProxyOverride)
d.Set("timezone_id", props.TimezoneID)
d.Set("storage_account_type", props.StorageAccountType)
// This value is not returned from the api so we'll just set whatever is in the config
d.Set("administrator_login_password", d.Get("administrator_login_password").(string))
}
Expand Down
45 changes: 45 additions & 0 deletions internal/services/sql/sql_managed_instance_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ func TestAccAzureRMSqlMiServer_basic(t *testing.T) {
})
}

func TestAccAzureRMSqlMiServer_backupRedundancyLRS(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_sql_managed_instance", "test")
r := SqlManagedInstanceResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.storageType(data, "LRS"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
})
}

func TestAccAzureRMSqlMiServer_identity(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_sql_managed_instance", "test")
r := SqlManagedInstanceResource{}
Expand Down Expand Up @@ -197,6 +212,36 @@ resource "azurerm_sql_managed_instance" "test" {
`, r.template(data), data.RandomInteger)
}

func (r SqlManagedInstanceResource) storageType(data acceptance.TestData, storageAccountType string) string {
return fmt.Sprintf(`
%s
resource "azurerm_sql_managed_instance" "test" {
name = "acctestsqlserver%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
administrator_login = "mradministrator"
administrator_login_password = "thisIsDog11"
license_type = "BasePrice"
subnet_id = azurerm_subnet.test.id
sku_name = "GP_Gen5"
vcores = 4
storage_size_in_gb = 32
storage_account_type = "%s"
depends_on = [
azurerm_subnet_network_security_group_association.test,
azurerm_subnet_route_table_association.test,
]
tags = {
environment = "staging"
database = "test"
}
}
`, r.template(data), data.RandomInteger, storageAccountType)
}

func (r SqlManagedInstanceResource) identity(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/sql_managed_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ The following arguments are supported:

* `identity` - (Optional) An `identity` block as defined below.

* `storage_account_type` - (Optional) Specifies the storage account type used to store backups for this database. Changing this forces a new resource to be created. Possible values are `GRS`, `LRS` and `ZRS`. The default value is `GRS`.

* `tags` - (Optional) A mapping of tags to assign to the resource.

---
Expand Down

0 comments on commit e647406

Please sign in to comment.