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_site_recovery_replication_recovery_plan: fix update for boot_recovery_group,failover_recovery_group and shutdown_recovery_group #22687

Merged
merged 4 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this below the new code and remove the duplicate extra error return code in the if-else structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code updated, thanks

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