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

r/aws_backup_plan: Correctly handle changes to recovery_point_tags #10641

Merged
merged 4 commits into from
Oct 29, 2019

Conversation

ewbankkit
Copy link
Contributor

@ewbankkit ewbankkit commented Oct 25, 2019

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Closes #8431,
Closes #9502.
Closes #8193.
Closes #8737.

Release note for CHANGELOG:

resource/aws_backup_plan: Correctly handle changes to recovery_point_tags

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAwsBackupPlan_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAwsBackupPlan_ -timeout 120m
=== RUN   TestAccAwsBackupPlan_basic
=== PAUSE TestAccAwsBackupPlan_basic
=== RUN   TestAccAwsBackupPlan_withTags
=== PAUSE TestAccAwsBackupPlan_withTags
=== RUN   TestAccAwsBackupPlan_withRules
=== PAUSE TestAccAwsBackupPlan_withRules
=== RUN   TestAccAwsBackupPlan_withLifecycle
=== PAUSE TestAccAwsBackupPlan_withLifecycle
=== RUN   TestAccAwsBackupPlan_withRecoveryPointTags
=== PAUSE TestAccAwsBackupPlan_withRecoveryPointTags
=== RUN   TestAccAwsBackupPlan_disappears
=== PAUSE TestAccAwsBackupPlan_disappears
=== CONT  TestAccAwsBackupPlan_basic
=== CONT  TestAccAwsBackupPlan_withRecoveryPointTags
=== CONT  TestAccAwsBackupPlan_withLifecycle
=== CONT  TestAccAwsBackupPlan_disappears
=== CONT  TestAccAwsBackupPlan_withRules
=== CONT  TestAccAwsBackupPlan_withTags
--- PASS: TestAccAwsBackupPlan_disappears (19.47s)
--- PASS: TestAccAwsBackupPlan_basic (21.03s)
--- PASS: TestAccAwsBackupPlan_withRecoveryPointTags (47.45s)
--- PASS: TestAccAwsBackupPlan_withTags (47.99s)
--- PASS: TestAccAwsBackupPlan_withRules (51.20s)
--- PASS: TestAccAwsBackupPlan_withLifecycle (61.37s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	61.428s

… before testing 'recovery_point_tags' attribute.
$ make testacc TEST=./aws TESTARGS='-run=TestAccAwsBackupPlan_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAwsBackupPlan_ -timeout 120m
=== RUN   TestAccAwsBackupPlan_basic
=== PAUSE TestAccAwsBackupPlan_basic
=== RUN   TestAccAwsBackupPlan_withTags
=== PAUSE TestAccAwsBackupPlan_withTags
=== RUN   TestAccAwsBackupPlan_withRules
=== PAUSE TestAccAwsBackupPlan_withRules
=== RUN   TestAccAwsBackupPlan_withLifecycle
=== PAUSE TestAccAwsBackupPlan_withLifecycle
=== RUN   TestAccAwsBackupPlan_withRecoveryPointTags
=== PAUSE TestAccAwsBackupPlan_withRecoveryPointTags
=== RUN   TestAccAwsBackupPlan_disappears
=== PAUSE TestAccAwsBackupPlan_disappears
=== CONT  TestAccAwsBackupPlan_basic
=== CONT  TestAccAwsBackupPlan_withRecoveryPointTags
=== CONT  TestAccAwsBackupPlan_disappears
=== CONT  TestAccAwsBackupPlan_withRules
=== CONT  TestAccAwsBackupPlan_withLifecycle
=== CONT  TestAccAwsBackupPlan_withTags
--- PASS: TestAccAwsBackupPlan_disappears (19.33s)
--- PASS: TestAccAwsBackupPlan_basic (20.82s)
--- FAIL: TestAccAwsBackupPlan_withRecoveryPointTags (26.61s)
    testing.go:569: Step 1 error: errors during apply:

        Error: error updating Backup Plan (1104fa3b-5714-4c2e-9776-78660300ee6b): InvalidParameter: 2 validation error(s) found.
        - missing required field, UpdateBackupPlanInput.BackupPlan.Rules[0].RuleName.
        - missing required field, UpdateBackupPlanInput.BackupPlan.Rules[0].TargetBackupVaultName.

          on /tmp/tf-test417192270/main.tf line 6:
          (source code not available)

--- PASS: TestAccAwsBackupPlan_withRules (47.10s)
--- PASS: TestAccAwsBackupPlan_withTags (47.82s)
--- PASS: TestAccAwsBackupPlan_withLifecycle (60.07s)
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	60.128s
FAIL
GNUmakefile:24: recipe for target 'testacc' failed
make: *** [testacc] Error 1
@ewbankkit ewbankkit requested a review from a team October 25, 2019 22:20
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. service/backup Issues and PRs that pertain to the backup service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Oct 25, 2019
BackupPlanName: aws.String(d.Get("name").(string)),
Rules: expandBackupPlanRules(d.Get("rule").(*schema.Set)),
},
BackupPlanTags: keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().BackupTags(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use keyvaluetags.

}

rule := &schema.Set{F: resourceAwsPlanRuleHash}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactor to flattenBackupPlanRules().

return fmt.Errorf("error setting rule: %s", err)
}

tagsOutput, err := conn.ListTags(&backup.ListTagsInput{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use keyvaluetags.

BackupPlanId: aws.String(d.Id()),
BackupPlan: plan,
}
if d.HasChange("rule") {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only update if there's actually a change...

}

if d.HasChange("tags") {
resourceArn := d.Get("arn").(string)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use keyvaluetags.

if vRuleName, ok := mRule["rule_name"].(string); ok && vRuleName != "" {
rule.RuleName = aws.String(vRuleName)
} else {
continue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if v, ok := m["start_window"]; ok {
buf.WriteString(fmt.Sprintf("%d-", v.(interface{})))
if vRecoveryPointTags, ok := mRule["recovery_point_tags"].(map[string]interface{}); ok && len(vRecoveryPointTags) > 0 {
buf.WriteString(fmt.Sprintf("%d-", tagsMapToHash(vRecoveryPointTags)))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stable has value (not strictly necessary after Go 1.12).

@bflad bflad added the bug Addresses a defect in current functionality. label Oct 29, 2019
@bflad bflad added this to the v2.34.0 milestone Oct 29, 2019
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Nice work, @ewbankkit, LGTM

--- PASS: TestAccAwsBackupPlan_disappears (9.31s)
--- PASS: TestAccAwsBackupPlan_basic (9.48s)
--- PASS: TestAccAwsBackupPlan_withRules (19.28s)
--- PASS: TestAccAwsBackupPlan_withRecoveryPointTags (19.40s)
--- PASS: TestAccAwsBackupPlan_withTags (19.97s)
--- PASS: TestAccAwsBackupPlan_withLifecycle (24.67s)

@bflad bflad merged commit 0b14ec8 into hashicorp:master Oct 29, 2019
bflad added a commit that referenced this pull request Oct 29, 2019
@ewbankkit ewbankkit deleted the issue-8431 branch October 29, 2019 10:33
@bflad
Copy link
Contributor

bflad commented Oct 31, 2019

This has been released in version 2.34.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/backup Issues and PRs that pertain to the backup service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
2 participants