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

azurerm_mssql_managed_instance_failover_group: add property secondary_type #28633

Merged
merged 19 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type MsSqlManagedInstanceFailoverGroupModel struct {
ManagedInstanceId string `tfschema:"managed_instance_id"`
PartnerManagedInstanceId string `tfschema:"partner_managed_instance_id"`
ReadOnlyEndpointFailoverPolicyEnabled bool `tfschema:"readonly_endpoint_failover_policy_enabled"`
SecondaryType string `tfschema:"secondary_type"`

ReadWriteEndpointFailurePolicy []MsSqlManagedInstanceReadWriteEndpointFailurePolicyModel `tfschema:"read_write_endpoint_failover_policy"`

Expand Down Expand Up @@ -118,6 +119,16 @@ func (r MsSqlManagedInstanceFailoverGroupResource) Arguments() map[string]*plugi
},
},
},

"secondary_type": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(instancefailovergroups.SecondaryInstanceTypeGeo),
ValidateFunc: validation.StringInSlice([]string{
string(instancefailovergroups.SecondaryInstanceTypeGeo),
string(instancefailovergroups.SecondaryInstanceTypeStandby),
}, false),
wyattfry marked this conversation as resolved.
Show resolved Hide resolved
},
}
}

Expand Down Expand Up @@ -207,6 +218,7 @@ func (r MsSqlManagedInstanceFailoverGroupResource) Create() sdk.ResourceFunc {
PartnerManagedInstanceId: utils.String(partnerId.ID()),
},
},
SecondaryType: pointer.To(instancefailovergroups.SecondaryInstanceType(model.SecondaryType)),
},
}

Expand Down Expand Up @@ -286,6 +298,7 @@ func (r MsSqlManagedInstanceFailoverGroupResource) Update() sdk.ResourceFunc {
PartnerManagedInstanceId: utils.String(partnerId.ID()),
},
},
SecondaryType: pointer.To(instancefailovergroups.SecondaryInstanceType(state.SecondaryType)),
},
}

Expand Down Expand Up @@ -380,6 +393,10 @@ func (r MsSqlManagedInstanceFailoverGroupResource) Read() sdk.ResourceFunc {
}
}

if secondaryType := props.SecondaryType; secondaryType != nil {
model.SecondaryType = string(pointer.From(props.SecondaryType))
}
wyattfry marked this conversation as resolved.
Show resolved Hide resolved

model.ReadWriteEndpointFailurePolicy = []MsSqlManagedInstanceReadWriteEndpointFailurePolicyModel{
{
Mode: string(props.ReadWriteEndpoint.FailoverPolicy),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type MsSqlManagedInstanceFailoverGroupResource struct{}
func TestAccMsSqlManagedInstanceFailoverGroup_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mssql_managed_instance_failover_group", "test")
r := MsSqlManagedInstanceFailoverGroupResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Expand Down Expand Up @@ -62,9 +61,11 @@ func (r MsSqlManagedInstanceFailoverGroupResource) basic(data acceptance.TestDat
return fmt.Sprintf(`
%[1]s

resource "random_pet" "this" {}
wyattfry marked this conversation as resolved.
Show resolved Hide resolved

resource "azurerm_mssql_managed_instance_failover_group" "test" {
name = "acctest-fog-%[2]d"
location = "%[3]s"
name = "acctest-fog-${random_pet.this.id}"
location = "%[2]s"
managed_instance_id = azurerm_mssql_managed_instance.test.id
partner_managed_instance_id = azurerm_mssql_managed_instance.secondary.id

Expand All @@ -77,18 +78,21 @@ resource "azurerm_mssql_managed_instance_failover_group" "test" {
azurerm_virtual_network_gateway_connection.secondary,
]
}
`, r.template(data), data.RandomInteger, data.Locations.Primary)
`, r.template(data), data.Locations.Primary)
}

func (r MsSqlManagedInstanceFailoverGroupResource) update(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s

resource "random_pet" "this" {}

resource "azurerm_mssql_managed_instance_failover_group" "test" {
name = "acctest-fog-%[2]d"
location = "%[3]s"
name = "acctest-fog-${random_pet.this.id}"
location = "%[2]s"
managed_instance_id = azurerm_mssql_managed_instance.test.id
partner_managed_instance_id = azurerm_mssql_managed_instance.secondary.id
secondary_type = "Standby"

readonly_endpoint_failover_policy_enabled = true

Expand All @@ -102,7 +106,7 @@ resource "azurerm_mssql_managed_instance_failover_group" "test" {
azurerm_virtual_network_gateway_connection.secondary,
]
}
`, r.template(data), data.RandomInteger, data.Locations.Primary)
`, r.template(data), data.Locations.Primary)
}

func (r MsSqlManagedInstanceFailoverGroupResource) template(data acceptance.TestData) string {
Expand All @@ -121,15 +125,15 @@ resource "azurerm_subnet" "gateway_snet_test" {
}

resource "azurerm_public_ip" "test" {
name = "acctest-pip-%[2]d"
name = "acctest-pip-${random_pet.this.id}"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
allocation_method = "Dynamic"
sku = "Basic"
}

resource "azurerm_virtual_network_gateway" "test" {
name = "acctest-vnetgway-%[2]d"
name = "acctest-vnetgway-${random_pet.this.id}"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

Expand All @@ -146,7 +150,7 @@ resource "azurerm_virtual_network_gateway" "test" {
}

resource "azurerm_virtual_network_gateway_connection" "test" {
name = "acctest-gwc-%[2]d"
name = "acctest-gwc-${random_pet.this.id}"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name

Expand All @@ -165,15 +169,15 @@ resource "azurerm_subnet" "gateway_snet_secondary" {
}

resource "azurerm_public_ip" "secondary" {
name = "acctest-pip2-%[2]d"
name = "acctest-pip2-${random_pet.this.id}"
location = azurerm_resource_group.secondary.location
resource_group_name = azurerm_resource_group.secondary.name
allocation_method = "Dynamic"
sku = "Basic"
}

resource "azurerm_virtual_network_gateway" "secondary" {
name = "acctest-vnetgway2-%[2]d"
name = "acctest-vnetgway2-${random_pet.this.id}"
location = azurerm_resource_group.secondary.location
resource_group_name = azurerm_resource_group.secondary.name

Expand All @@ -190,7 +194,7 @@ resource "azurerm_virtual_network_gateway" "secondary" {
}

resource "azurerm_virtual_network_gateway_connection" "secondary" {
name = "acctest-gwc2-%[2]d"
name = "acctest-gwc2-${random_pet.this.id}"
location = azurerm_resource_group.secondary.location
resource_group_name = azurerm_resource_group.secondary.name

Expand All @@ -200,5 +204,5 @@ resource "azurerm_virtual_network_gateway_connection" "secondary" {

shared_key = var.shared_key
}
`, MsSqlManagedInstanceResource{}.dnsZonePartner(data), data.RandomInteger)
`, MsSqlManagedInstanceResource{}.dnsZonePartner(data))
}
Loading
Loading