diff --git a/.changelog/45113.txt b/.changelog/45113.txt new file mode 100644 index 000000000000..ba1dd9ab12e4 --- /dev/null +++ b/.changelog/45113.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_dlm_lifecycle_policy: Add `exclude_data_volume_tags` attributes to `policy_details` parameters configuration block +``` diff --git a/internal/service/dlm/lifecycle_policy.go b/internal/service/dlm/lifecycle_policy.go index 7371a2a9fc8d..569dea80899c 100644 --- a/internal/service/dlm/lifecycle_policy.go +++ b/internal/service/dlm/lifecycle_policy.go @@ -246,6 +246,11 @@ func resourceLifecyclePolicy() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + "exclude_data_volume_tags": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, "no_reboot": { Type: schema.TypeBool, Optional: true, @@ -1506,6 +1511,10 @@ func expandParameters(tfList []any, policyType awstypes.PolicyTypeValues) *awsty apiObject.ExcludeBootVolume = aws.Bool(v) } + if v, ok := tfMap["exclude_data_volume_tags"].(map[string]any); ok && policyType == awstypes.PolicyTypeValuesEbsSnapshotManagement { + apiObject.ExcludeDataVolumeTags = expandTags(v) + } + if v, ok := tfMap["no_reboot"].(bool); ok && policyType == awstypes.PolicyTypeValuesImageManagement { apiObject.NoReboot = aws.Bool(v) } @@ -1518,6 +1527,9 @@ func flattenParameters(apiObject *awstypes.Parameters) []any { if apiObject.ExcludeBootVolume != nil { tfMap["exclude_boot_volume"] = aws.ToBool(apiObject.ExcludeBootVolume) } + if apiObject.ExcludeDataVolumeTags != nil { + tfMap["exclude_data_volume_tags"] = flattenTags(apiObject.ExcludeDataVolumeTags) + } if apiObject.NoReboot != nil { tfMap["no_reboot"] = aws.ToBool(apiObject.NoReboot) } diff --git a/internal/service/dlm/lifecycle_policy_test.go b/internal/service/dlm/lifecycle_policy_test.go index 6e2b347820f1..3343e3476e6a 100644 --- a/internal/service/dlm/lifecycle_policy_test.go +++ b/internal/service/dlm/lifecycle_policy_test.go @@ -500,6 +500,7 @@ func TestAccDLMLifecyclePolicy_parameters_volume(t *testing.T) { checkLifecyclePolicyExists(ctx, t, resourceName), resource.TestCheckResourceAttr(resourceName, "policy_details.0.parameters.#", "1"), resource.TestCheckResourceAttr(resourceName, "policy_details.0.parameters.0.exclude_boot_volume", acctest.CtTrue), + resource.TestCheckResourceAttr(resourceName, "policy_details.0.parameters.0.exclude_data_volume_tags.test", "exclude"), resource.TestCheckResourceAttr(resourceName, "policy_details.0.parameters.0.no_reboot", acctest.CtFalse), ), }, @@ -1380,6 +1381,9 @@ resource "aws_dlm_lifecycle_policy" "test" { parameters { exclude_boot_volume = true + exclude_data_volume_tags = { + test = "exclude" + } } schedule { diff --git a/website/docs/r/dlm_lifecycle_policy.html.markdown b/website/docs/r/dlm_lifecycle_policy.html.markdown index 378c445731d0..e59e2aea85ca 100644 --- a/website/docs/r/dlm_lifecycle_policy.html.markdown +++ b/website/docs/r/dlm_lifecycle_policy.html.markdown @@ -95,6 +95,47 @@ resource "aws_dlm_lifecycle_policy" "example" { } } } + +# ...example policy to exclude data volumes through tags... +resource "aws_dlm_lifecycle_policy" "example" { + description = "example DLM lifecycle policy" + execution_role_arn = aws_iam_role.dlm_lifecycle_role.arn + state = "ENABLED" + + policy_details { + resource_types = ["INSTANCE"] + parameters { + exclude_data_volume_tags = { + test = "exclude" + } + + } + + schedule { + name = "2 weeks of daily snapshots" + + create_rule { + interval = 24 + interval_unit = "HOURS" + times = ["23:45"] + } + + retain_rule { + count = 14 + } + + tags_to_add = { + SnapshotCreator = "DLM" + } + + copy_tags = false + } + + target_tags = { + Snapshot = "true" + } + } +} ``` ### Example Default Policy @@ -351,6 +392,7 @@ This resource supports the following arguments: #### Parameters arguments * `exclude_boot_volume` - (Optional) Indicates whether to exclude the root volume from snapshots created using CreateSnapshots. The default is `false`. +* `exclude_data_volume_tags` - (Optional) Map specifies whether to exclude volumes that have specific tags. * `no_reboot` - (Optional) Applies to AMI lifecycle policies only. Indicates whether targeted instances are rebooted when the lifecycle policy runs. `true` indicates that targeted instances are not rebooted when the policy runs. `false` indicates that target instances are rebooted when the policy runs. The default is `true` (instances are not rebooted). #### Schedule arguments