Skip to content

Commit

Permalink
azurerm_sql_managed_instance - support for the zone_redundant_enabled…
Browse files Browse the repository at this point in the history
… property (#25089)
  • Loading branch information
katbyte authored Feb 29, 2024
1 parent c79f4ce commit 8dc5142
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/v5.0/sql" // nolint: staticcheck
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
Expand Down Expand Up @@ -47,9 +48,10 @@ type MsSqlManagedInstanceModel struct {
StorageAccountType string `tfschema:"storage_account_type"`
StorageSizeInGb int `tfschema:"storage_size_in_gb"`
SubnetId string `tfschema:"subnet_id"`
Tags map[string]string `tfschema:"tags"`
TimezoneId string `tfschema:"timezone_id"`
VCores int `tfschema:"vcores"`
ZoneRedundantEnabled bool `tfschema:"zone_redundant_enabled"`
Tags map[string]string `tfschema:"tags"`
}

var _ sdk.Resource = MsSqlManagedInstanceResource{}
Expand Down Expand Up @@ -225,15 +227,21 @@ func (r MsSqlManagedInstanceResource) Arguments() map[string]*pluginsdk.Schema {
}, false),
},

"tags": tags.Schema(),

"timezone_id": {
Type: schema.TypeString,
Optional: true,
Default: "UTC",
ValidateFunc: validation.StringIsNotEmpty,
ForceNew: true,
},

"zone_redundant_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},

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

Expand Down Expand Up @@ -309,29 +317,30 @@ func (r MsSqlManagedInstanceResource) Create() sdk.ResourceFunc {
parameters := sql.ManagedInstance{
Sku: sku,
Identity: r.expandIdentity(model.Identity),
Location: utils.String(location.Normalize(model.Location)),
Location: pointer.To(location.Normalize(model.Location)),
ManagedInstanceProperties: &sql.ManagedInstanceProperties{
AdministratorLogin: utils.String(model.AdministratorLogin),
AdministratorLoginPassword: utils.String(model.AdministratorLoginPassword),
Collation: utils.String(model.Collation),
DNSZonePartner: utils.String(model.DnsZonePartnerId),
AdministratorLogin: pointer.To(model.AdministratorLogin),
AdministratorLoginPassword: pointer.To(model.AdministratorLoginPassword),
Collation: pointer.To(model.Collation),
DNSZonePartner: pointer.To(model.DnsZonePartnerId),
LicenseType: sql.ManagedInstanceLicenseType(model.LicenseType),
MaintenanceConfigurationID: utils.String(maintenanceConfigId.ID()),
MinimalTLSVersion: utils.String(model.MinimumTlsVersion),
MaintenanceConfigurationID: pointer.To(maintenanceConfigId.ID()),
MinimalTLSVersion: pointer.To(model.MinimumTlsVersion),
ProxyOverride: sql.ManagedInstanceProxyOverride(model.ProxyOverride),
PublicDataEndpointEnabled: utils.Bool(model.PublicDataEndpointEnabled),
PublicDataEndpointEnabled: pointer.To(model.PublicDataEndpointEnabled),
StorageAccountType: sql.StorageAccountType(model.StorageAccountType),
StorageSizeInGB: utils.Int32(int32(model.StorageSizeInGb)),
SubnetID: utils.String(model.SubnetId),
TimezoneID: utils.String(model.TimezoneId),
VCores: utils.Int32(int32(model.VCores)),
StorageSizeInGB: pointer.To(int32(model.StorageSizeInGb)),
SubnetID: pointer.To(model.SubnetId),
TimezoneID: pointer.To(model.TimezoneId),
VCores: pointer.To(int32(model.VCores)),
ZoneRedundant: pointer.To(model.ZoneRedundantEnabled),
},
Tags: tags.FromTypedObject(model.Tags),
}

if parameters.Identity != nil && len(parameters.Identity.UserAssignedIdentities) > 0 {
for k := range parameters.Identity.UserAssignedIdentities {
parameters.ManagedInstanceProperties.PrimaryUserAssignedIdentityID = utils.String(k)
parameters.ManagedInstanceProperties.PrimaryUserAssignedIdentityID = pointer.To(k)
break
}
}
Expand Down Expand Up @@ -384,33 +393,34 @@ func (r MsSqlManagedInstanceResource) Update() sdk.ResourceFunc {
properties := sql.ManagedInstance{
Sku: sku,
Identity: r.expandIdentity(state.Identity),
Location: utils.String(location.Normalize(state.Location)),
Location: pointer.To(location.Normalize(state.Location)),
ManagedInstanceProperties: &sql.ManagedInstanceProperties{
DNSZonePartner: utils.String(state.DnsZonePartnerId),
DNSZonePartner: pointer.To(state.DnsZonePartnerId),
LicenseType: sql.ManagedInstanceLicenseType(state.LicenseType),
MinimalTLSVersion: utils.String(state.MinimumTlsVersion),
MinimalTLSVersion: pointer.To(state.MinimumTlsVersion),
ProxyOverride: sql.ManagedInstanceProxyOverride(state.ProxyOverride),
PublicDataEndpointEnabled: utils.Bool(state.PublicDataEndpointEnabled),
StorageSizeInGB: utils.Int32(int32(state.StorageSizeInGb)),
VCores: utils.Int32(int32(state.VCores)),
PublicDataEndpointEnabled: pointer.To(state.PublicDataEndpointEnabled),
StorageSizeInGB: pointer.To(int32(state.StorageSizeInGb)),
VCores: pointer.To(int32(state.VCores)),
ZoneRedundant: pointer.To(state.ZoneRedundantEnabled),
},
Tags: tags.FromTypedObject(state.Tags),
}

if properties.Identity != nil && len(properties.Identity.UserAssignedIdentities) > 0 {
for k := range properties.Identity.UserAssignedIdentities {
properties.ManagedInstanceProperties.PrimaryUserAssignedIdentityID = utils.String(k)
properties.ManagedInstanceProperties.PrimaryUserAssignedIdentityID = pointer.To(k)
break
}
}

if metadata.ResourceData.HasChange("maintenance_configuration_name") {
maintenanceConfigId := publicmaintenanceconfigurations.NewPublicMaintenanceConfigurationID(id.SubscriptionId, state.MaintenanceConfigurationName)
properties.MaintenanceConfigurationID = utils.String(maintenanceConfigId.ID())
properties.MaintenanceConfigurationID = pointer.To(maintenanceConfigId.ID())
}

if metadata.ResourceData.HasChange("administrator_login_password") {
properties.AdministratorLoginPassword = utils.String(state.AdministratorLoginPassword)
properties.AdministratorLoginPassword = pointer.To(state.AdministratorLoginPassword)
}

metadata.Logger.Infof("Updating %s", id)
Expand Down Expand Up @@ -513,6 +523,10 @@ func (r MsSqlManagedInstanceResource) Read() sdk.ResourceFunc {
if props.VCores != nil {
model.VCores = int(*props.VCores)
}

if props.ZoneRedundant != nil {
model.ZoneRedundantEnabled = *props.ZoneRedundant
}
}

return metadata.Encode(&model)
Expand Down Expand Up @@ -618,9 +632,9 @@ func (r MsSqlManagedInstanceResource) expandSkuName(skuName string) (*sql.Sku, e
}

return &sql.Sku{
Name: utils.String(skuName),
Tier: utils.String(tier),
Family: utils.String(parts[1]),
Name: pointer.To(skuName),
Tier: pointer.To(tier),
Family: pointer.To(parts[1]),
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,7 @@ resource "azurerm_mssql_managed_instance" "test" {
subnet_id = azurerm_subnet.test.id
timezone_id = "Pacific Standard Time"
vcores = 8
zone_redundant_enabled = true
administrator_login = "missadministrator"
administrator_login_password = "NCC-1701-D"
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 @@ -243,6 +243,8 @@ The following arguments are supported:

* `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`. Defaults to `GRS`.

* `zone_redundant_enabled` - (Optional) Specifies whether or not the SQL Managed Instance is zone redundant. Defaults to `false`.

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

---
Expand Down

0 comments on commit 8dc5142

Please sign in to comment.