-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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_dlm_lifecycle_policy: retain rule #11503
Closed
thatderek
wants to merge
2
commits into
hashicorp:main
from
thatderek:r-aws_dlm_lifecycle_policy-retainrule
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,44 @@ func TestAccAWSDlmLifecyclePolicy_Full(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestAccAWSDlmLifecyclePolicy_Retain(t *testing.T) { | ||
resourceName := "aws_dlm_lifecycle_policy.full" | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDlm(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: dlmLifecyclePolicyDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: dlmLifecyclePolicyFullUpdateConfigWithAgeBasedRetain(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDlmLifecyclePolicyExists(resourceName), | ||
resource.TestCheckResourceAttr(resourceName, "description", "tf-acc-full-updated-age"), | ||
resource.TestCheckResourceAttrSet(resourceName, "execution_role_arn"), | ||
resource.TestCheckResourceAttr(resourceName, "state", "DISABLED"), | ||
resource.TestCheckResourceAttr(resourceName, "policy_details.0.resource_types.0", "VOLUME"), | ||
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.name", "tf-acc-full-updated-age"), | ||
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.create_rule.0.interval", "24"), | ||
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.create_rule.0.interval_unit", "HOURS"), | ||
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.create_rule.0.times.0", "09:42"), | ||
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.retain_rule.0.interval", "15"), | ||
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.retain_rule.0.interval_unit", "DAYS"), | ||
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.tags_to_add.tf-acc-test-added", "full-updated-age"), | ||
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.copy_tags", "true"), | ||
resource.TestCheckResourceAttr(resourceName, "policy_details.0.target_tags.tf-acc-test", "full-updated-age"), | ||
), | ||
}, | ||
{ | ||
Config: dlmLifecyclePolicyFullUpdateConfigWithAgeBasedRetainless(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDlmLifecyclePolicyExists(resourceName), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccAWSDlmLifecyclePolicy_Tags(t *testing.T) { | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
resourceName := "aws_dlm_lifecycle_policy.test" | ||
|
@@ -246,7 +284,7 @@ resource "aws_dlm_lifecycle_policy" "basic" { | |
} | ||
|
||
retain_rule { | ||
count = 10 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an odd diff here. Is this accidental? |
||
count = 10 | ||
} | ||
} | ||
|
||
|
@@ -374,6 +412,123 @@ resource "aws_dlm_lifecycle_policy" "full" { | |
`, rName) | ||
} | ||
|
||
func dlmLifecyclePolicyFullUpdateConfigWithAgeBasedRetain(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_iam_role" "dlm_lifecycle_role" { | ||
name = %q | ||
|
||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "dlm.amazonaws.com" | ||
}, | ||
"Effect": "Allow", | ||
"Sid": "" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_dlm_lifecycle_policy" "full" { | ||
description = "tf-acc-full-updated-age" | ||
execution_role_arn = "${aws_iam_role.dlm_lifecycle_role.arn}-doesnt-exist" | ||
state = "DISABLED" | ||
|
||
policy_details { | ||
resource_types = ["VOLUME"] | ||
|
||
schedule { | ||
name = "tf-acc-full-updated-age" | ||
|
||
create_rule { | ||
interval = 24 | ||
interval_unit = "HOURS" | ||
times = ["09:42"] | ||
} | ||
|
||
retain_rule { | ||
interval = 15 | ||
interval_unit = "DAYS" | ||
} | ||
|
||
tags_to_add = { | ||
tf-acc-test-added = "full-updated-age" | ||
} | ||
|
||
copy_tags = true | ||
} | ||
|
||
target_tags = { | ||
tf-acc-test = "full-updated-age" | ||
} | ||
} | ||
} | ||
`, rName) | ||
} | ||
|
||
func dlmLifecyclePolicyFullUpdateConfigWithAgeBasedRetainless(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_iam_role" "dlm_lifecycle_role" { | ||
name = %q | ||
|
||
assume_role_policy = <<EOF | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Principal": { | ||
"Service": "dlm.amazonaws.com" | ||
}, | ||
"Effect": "Allow", | ||
"Sid": "" | ||
} | ||
] | ||
} | ||
EOF | ||
} | ||
|
||
resource "aws_dlm_lifecycle_policy" "full" { | ||
description = "tf-acc-full-updated-age" | ||
execution_role_arn = "${aws_iam_role.dlm_lifecycle_role.arn}-doesnt-exist" | ||
state = "DISABLED" | ||
|
||
policy_details { | ||
resource_types = ["VOLUME"] | ||
|
||
schedule { | ||
name = "tf-acc-full-updated-age" | ||
|
||
create_rule { | ||
interval = 24 | ||
interval_unit = "HOURS" | ||
times = ["09:42"] | ||
} | ||
|
||
retain_rule { | ||
count = 5 | ||
} | ||
|
||
tags_to_add = { | ||
tf-acc-test-added = "full-updated-age" | ||
} | ||
|
||
copy_tags = true | ||
} | ||
|
||
target_tags = { | ||
tf-acc-test = "full-updated-age" | ||
} | ||
} | ||
} | ||
`, rName) | ||
} | ||
|
||
func dlmLifecyclePolicyConfigTags1(rName, tagKey1, tagValue1 string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_iam_role" "test" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably have
ConflictsWith: []string{"policy_details.0.schedule.0.retain_rule.0.interval", "policy_details.0.schedule.0.retain_rule.0.interval_unit"},
and thenConflictsWith: []string{"policy_details.0.schedule.0.retain_rule.0.count"},
on theinterval
andinterval_unit
blocks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw your comment above but in this case nearly all of the parameters in the DLM API that is a list is also required to be 1 element in the list (AWS sure do like future proofing things at the expense of more complex APIs) so you can just hardcode the list element as 0 as in my comment here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realised that that's not currently true because
schedule
is missing aMaxItems: 1
despite that being required by the API which I think I missed in my initial pull request that added this resource.We should add that in this pull request I think. It then makes the
ConflictsWith
robust as well as giving plan time validation in the event someone adds multipleschedule
blocks to apolicy_details
block.