From 7dfc47ce587ea264168b0648aff7906fe8f30228 Mon Sep 17 00:00:00 2001 From: Chris Greatbanks Date: Tue, 13 Nov 2018 14:04:33 +0000 Subject: [PATCH 1/2] Add copy_tags option to the resource_aws_dlm_lifecycle_policy --- aws/resource_aws_dlm_lifecycle_policy.go | 10 ++++++++++ aws/resource_aws_dlm_lifecycle_policy_test.go | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/aws/resource_aws_dlm_lifecycle_policy.go b/aws/resource_aws_dlm_lifecycle_policy.go index c3da953064a..7211e3bfd9e 100644 --- a/aws/resource_aws_dlm_lifecycle_policy.go +++ b/aws/resource_aws_dlm_lifecycle_policy.go @@ -50,6 +50,12 @@ func resourceAwsDlmLifecyclePolicy() *schema.Resource { Required: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ + "copy_tags": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + ForceNew: true, + }, "create_rule": { Type: schema.TypeList, Required: true, @@ -257,6 +263,9 @@ func expandDlmSchedules(cfg []interface{}) []*dlm.Schedule { for i, c := range cfg { schedule := &dlm.Schedule{} m := c.(map[string]interface{}) + if v, ok := m["copy_tags"]; ok { + schedule.CopyTags = aws.Bool(v.(bool)) + } if v, ok := m["create_rule"]; ok { schedule.CreateRule = expandDlmCreateRule(v.([]interface{})) } @@ -279,6 +288,7 @@ func flattenDlmSchedules(schedules []*dlm.Schedule) []map[string]interface{} { result := make([]map[string]interface{}, len(schedules)) for i, s := range schedules { m := make(map[string]interface{}) + m["copy_tags"] = aws.BoolValue(s.CopyTags) m["create_rule"] = flattenDlmCreateRule(s.CreateRule) m["name"] = aws.StringValue(s.Name) m["retain_rule"] = flattenDlmRetainRule(s.RetainRule) diff --git a/aws/resource_aws_dlm_lifecycle_policy_test.go b/aws/resource_aws_dlm_lifecycle_policy_test.go index 9a1b337f9fb..e5f2bbd17e7 100644 --- a/aws/resource_aws_dlm_lifecycle_policy_test.go +++ b/aws/resource_aws_dlm_lifecycle_policy_test.go @@ -68,6 +68,7 @@ func TestAccAWSDlmLifecyclePolicy_Full(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.create_rule.0.times.0", "21:42"), resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.retain_rule.0.count", "10"), resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.tags_to_add.tf-acc-test-added", "full"), + resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.copy_tags", "true"), resource.TestCheckResourceAttr(resourceName, "policy_details.0.target_tags.tf-acc-test", "full"), ), }, @@ -85,6 +86,7 @@ func TestAccAWSDlmLifecyclePolicy_Full(t *testing.T) { 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.count", "100"), resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.tags_to_add.tf-acc-test-added", "full-updated"), + resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.copy_tags", "true"), resource.TestCheckResourceAttr(resourceName, "policy_details.0.target_tags.tf-acc-test", "full-updated"), ), }, @@ -240,6 +242,8 @@ resource "aws_dlm_lifecycle_policy" "full" { tags_to_add { tf-acc-test-added = "full" } + + copy_tags = true } target_tags { @@ -296,6 +300,7 @@ resource "aws_dlm_lifecycle_policy" "full" { tags_to_add { tf-acc-test-added = "full-updated" } + copy_tags = true } target_tags { From a1437ca218cabc0001dab7855937706014b39f33 Mon Sep 17 00:00:00 2001 From: Chris Greatbanks Date: Tue, 13 Nov 2018 16:01:49 +0000 Subject: [PATCH 2/2] Include testing copy_tag false and true Update documention to include copy_tag option --- aws/resource_aws_dlm_lifecycle_policy_test.go | 5 +++-- website/docs/r/dlm_lifecycle_policy.markdown | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_dlm_lifecycle_policy_test.go b/aws/resource_aws_dlm_lifecycle_policy_test.go index e5f2bbd17e7..120165ae4da 100644 --- a/aws/resource_aws_dlm_lifecycle_policy_test.go +++ b/aws/resource_aws_dlm_lifecycle_policy_test.go @@ -68,7 +68,7 @@ func TestAccAWSDlmLifecyclePolicy_Full(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.create_rule.0.times.0", "21:42"), resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.retain_rule.0.count", "10"), resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.tags_to_add.tf-acc-test-added", "full"), - resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.copy_tags", "true"), + resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.copy_tags", "false"), resource.TestCheckResourceAttr(resourceName, "policy_details.0.target_tags.tf-acc-test", "full"), ), }, @@ -243,7 +243,7 @@ resource "aws_dlm_lifecycle_policy" "full" { tf-acc-test-added = "full" } - copy_tags = true + copy_tags = false } target_tags { @@ -300,6 +300,7 @@ resource "aws_dlm_lifecycle_policy" "full" { tags_to_add { tf-acc-test-added = "full-updated" } + copy_tags = true } diff --git a/website/docs/r/dlm_lifecycle_policy.markdown b/website/docs/r/dlm_lifecycle_policy.markdown index c056709e8f1..2ca8017cc71 100644 --- a/website/docs/r/dlm_lifecycle_policy.markdown +++ b/website/docs/r/dlm_lifecycle_policy.markdown @@ -57,6 +57,8 @@ resource "aws_dlm_lifecycle_policy" "example" { tags_to_add { SnapshotCreator = "DLM" } + + copy_tags = false } target_tags { @@ -85,6 +87,7 @@ The following arguments are supported: #### Schedule arguments +* `copy_tags` - (Optional) Copy all user-defined tags on a source volume to snapshots of the volume created by this policy. * `create_rule` - (Required) See the [`create_rule`](#create-rule-arguments) block. Max of 1 per schedule. * `name` - (Required) A name for the schedule. * `retain_rule` - (Required) See the [`create_rule`](#create-rule-arguments) block. Max of 1 per schedule.