Skip to content

Commit

Permalink
Optimization on delete by removing ForceNew
Browse files Browse the repository at this point in the history
  • Loading branch information
Aris van Ommeren committed Oct 31, 2021
1 parent e2c091d commit 97f3b36
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
7 changes: 6 additions & 1 deletion internal/services/sql/sql_managed_instance_resource.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sql

import (
"context"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -166,11 +167,15 @@ func resourceArmSqlMiServer() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ValidateFunc: azure.ValidateResourceID,
ForceNew: true,
},

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

CustomizeDiff: pluginsdk.ForceNewIfChange("dns_zone_partner_id", func(ctx context.Context, old, new, _ interface{}) bool {
// dns_zone_partner_id can only be set on init
return old.(string) == "" && new.(string) != ""
}),
}
}

Expand Down
39 changes: 39 additions & 0 deletions internal/services/sql/sql_managed_instance_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ func TestAccAzureRMSqlMiServer_dnsZonePartner(t *testing.T) {
),
},
data.ImportStep("administrator_login_password", "dns_zone_partner_id"),
{
// DNS Zone Partner empty makes delete faster as MI can be destroyed simultaniously
Config: r.emptyDnsZonePartner(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
})
}

Expand Down Expand Up @@ -280,6 +288,37 @@ resource "azurerm_sql_managed_instance" "test1" {
`, r.basic(data), r.templateSecondary(data), data.RandomInteger)
}

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

func (SqlManagedInstanceResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/sql_managed_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ The following arguments are supported:

* `timezone_id` - (Optional) The TimeZone ID that the SQL Managed Instance will be operating in. Default value is `UTC`. Changing this forces a new resource to be created.

* `dns_zone_partner_id` - (Optional) The ID of the Managed Instance which will share the DNS zone. This is a prerequisite for creating a failover group, although creation of a failover group is not yet possible in `azurerm`. Changing this forces a new resource to be created.
* `dns_zone_partner_id` - (Optional) The ID of the Managed Instance which will share the DNS zone. This is a prerequisite for creating a failover group, although creation of a failover group is not yet possible in `azurerm`. Setting this after creation forces a new resource to be created.

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

Expand Down

0 comments on commit 97f3b36

Please sign in to comment.