Skip to content

Commit

Permalink
azurerm_site_recovery_replication_recovery_plan: fix update for `bo…
Browse files Browse the repository at this point in the history
…ot_recovery_group`,`failover_recovery_group` and `shutdown_recovery_group` (#22687)

* fix #22649

Signed-off-by: ziyeqf <[email protected]>

* update code

Signed-off-by: ziyeqf <[email protected]>

* update per comments

Signed-off-by: ziyeqf <[email protected]>

* update code

Signed-off-by: ziyeqf <[email protected]>

---------

Signed-off-by: ziyeqf <[email protected]>
  • Loading branch information
ziyeqf authored Jul 28, 2023
1 parent f49c4de commit 26fdc34
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,43 @@ func (r SiteRecoveryReplicationRecoveryPlanResource) Update() sdk.ResourceFunc {
return fmt.Errorf("parse Site reocvery replication plan id: %+v", err)
}

recoveryPlanGroup, err := expandRecoveryGroup(model.RecoveryGroup)
resp, err := client.Get(ctx, *id)
if err != nil {
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

var groupValue []replicationrecoveryplans.RecoveryPlanGroup
if resp.Model == nil {
return fmt.Errorf("retrieving %s: model is nil", *id)
}

if resp.Model.Properties == nil {
return fmt.Errorf("retrieving %s: properties is nil", *id)
}

if resp.Model.Properties.Groups == nil {
return fmt.Errorf("retrieving %s: groups is nil", *id)
}

groupValue = *resp.Model.Properties.Groups

if metadata.ResourceData.HasChange("recovery_group") {
groupValue, err = expandRecoveryGroup(model.RecoveryGroup)
}

if metadata.ResourceData.HasChange("boot_recovery_group") ||
metadata.ResourceData.HasChange("failover_recovery_group") ||
metadata.ResourceData.HasChange("shutdown_recovery_group") {
groupValue, err = expandRecoveryGroupNew(model.ShutdownRecoveryGroup, model.FailoverRecoveryGroup, model.BootRecoveryGroup)
}

if err != nil {
return fmt.Errorf("when expanding recovery group: %s", err)
return fmt.Errorf("expanding recovery group: %+v", err)
}

parameters := replicationrecoveryplans.UpdateRecoveryPlanInput{
Properties: &replicationrecoveryplans.UpdateRecoveryPlanInputProperties{
Groups: &recoveryPlanGroup,
Groups: &groupValue,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,38 @@ func TestAccSiteRecoveryReplicationRecoveryPlan_withMultiActions(t *testing.T) {
})
}

func TestAccSiteRecoveryReplicationRecoveryPlan_updateWithmultiActions(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_site_recovery_replication_recovery_plan", "test")
r := SiteRecoveryReplicationRecoveryPlan{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.withMultiActions(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
// to check the actions are in the correct order
check.That(data.ResourceName).Key("boot_recovery_group.0.pre_action.0.name").HasValue("testPreAction1"),
check.That(data.ResourceName).Key("boot_recovery_group.0.pre_action.1.name").HasValue("testPreAction2"),
check.That(data.ResourceName).Key("boot_recovery_group.0.post_action.0.name").HasValue("testPostAction1"),
check.That(data.ResourceName).Key("boot_recovery_group.0.post_action.1.name").HasValue("testPostAction2"),
),
},
data.ImportStep(),
{
Config: r.updateWithMultiActions(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
// to check the actions are in the correct order
check.That(data.ResourceName).Key("boot_recovery_group.0.pre_action.0.name").HasValue("testPreAction1-new"),
check.That(data.ResourceName).Key("boot_recovery_group.0.pre_action.1.name").HasValue("testPreAction2-new"),
check.That(data.ResourceName).Key("boot_recovery_group.0.post_action.0.name").HasValue("testPostAction1-new"),
check.That(data.ResourceName).Key("boot_recovery_group.0.post_action.1.name").HasValue("testPostAction2-new"),
),
},
data.ImportStep(),
})
}

func TestAccSiteRecoveryReplicationRecoveryPlan_withZones(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_site_recovery_replication_recovery_plan", "test")
r := SiteRecoveryReplicationRecoveryPlan{}
Expand Down Expand Up @@ -513,6 +545,59 @@ resource "azurerm_site_recovery_replication_recovery_plan" "test" {
`, r.template(data), data.RandomInteger)
}

func (r SiteRecoveryReplicationRecoveryPlan) updateWithMultiActions(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_site_recovery_replication_recovery_plan" "test" {
name = "acctest-%[2]d"
recovery_vault_id = azurerm_recovery_services_vault.test.id
source_recovery_fabric_id = azurerm_site_recovery_fabric.test1.id
target_recovery_fabric_id = azurerm_site_recovery_fabric.test2.id
shutdown_recovery_group {}
failover_recovery_group {}
boot_recovery_group {
replicated_protected_items = [azurerm_site_recovery_replicated_vm.test.id]
pre_action {
name = "testPreAction1-new"
type = "ManualActionDetails"
fail_over_directions = ["PrimaryToRecovery"]
fail_over_types = ["TestFailover"]
manual_action_instruction = "test instruction"
}
pre_action {
name = "testPreAction2-new"
type = "ManualActionDetails"
fail_over_directions = ["PrimaryToRecovery"]
fail_over_types = ["TestFailover"]
manual_action_instruction = "test instruction"
}
post_action {
name = "testPostAction1-new"
type = "ManualActionDetails"
fail_over_directions = ["PrimaryToRecovery"]
fail_over_types = ["TestFailover"]
manual_action_instruction = "test instruction"
}
post_action {
name = "testPostAction2-new"
type = "ManualActionDetails"
fail_over_directions = ["PrimaryToRecovery"]
fail_over_types = ["TestFailover"]
manual_action_instruction = "test instruction"
}
}
}
`, r.template(data), data.RandomInteger)
}

func (r SiteRecoveryReplicationRecoveryPlan) withZones(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down

0 comments on commit 26fdc34

Please sign in to comment.