Skip to content

Commit 2249c48

Browse files
authored
Merge pull request #33796 from crisbal/f-dlm_cross_region_copy_rule_target_region
feat: dlm: Add support for target_region parameter in cross_region_copy_rule
2 parents 147b347 + c0ac3d3 commit 2249c48

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

.changelog/33796.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
resource/aws_dlm_lifecycle_policy: Add `policy_details.schedule.cross_region_copy_rule.target_region` argument
3+
```
4+
5+
```release-note:enhancement
6+
resource/aws_dlm_lifecycle_policy: Make `policy_details.schedule.cross_region_copy_rule.target` optional
7+
```

internal/service/dlm/lifecycle_policy.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,14 @@ func resourceLifecyclePolicy() *schema.Resource {
513513
},
514514
names.AttrTarget: {
515515
Type: schema.TypeString,
516-
Required: true,
516+
Optional: true,
517517
ValidateFunc: validation.StringMatch(regexache.MustCompile(`^[\w:\-\/\*]+$`), ""),
518518
},
519+
"target_region": {
520+
Type: schema.TypeString,
521+
Optional: true,
522+
ValidateFunc: verify.ValidRegionName,
523+
},
519524
},
520525
},
521526
},
@@ -1180,6 +1185,9 @@ func expandCrossRegionCopyRules(tfList []any) []awstypes.CrossRegionCopyRule {
11801185
if v, ok := tfMap[names.AttrTarget].(string); ok && v != "" {
11811186
apiObject.Target = aws.String(v)
11821187
}
1188+
if v, ok := tfMap["target_region"].(string); ok && v != "" {
1189+
apiObject.TargetRegion = aws.String(v)
1190+
}
11831191

11841192
apiObjects = append(apiObjects, apiObject)
11851193
}
@@ -1202,6 +1210,7 @@ func flattenCrossRegionCopyRules(apiObjects []awstypes.CrossRegionCopyRule) []an
12021210
names.AttrEncrypted: aws.ToBool(apiObject.Encrypted),
12031211
"retain_rule": flattenCrossRegionCopyRuleRetainRule(apiObject.RetainRule),
12041212
names.AttrTarget: aws.ToString(apiObject.Target),
1213+
"target_region": aws.ToString(apiObject.TargetRegion),
12051214
}
12061215

12071216
tfList = append(tfList, tfMap)

internal/service/dlm/lifecycle_policy_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,42 @@ func TestAccDLMLifecyclePolicy_crossRegionCopyRule(t *testing.T) {
657657
})
658658
}
659659

660+
func TestAccDLMLifecyclePolicy_crossRegionCopyRuleImageManagement(t *testing.T) {
661+
ctx := acctest.Context(t)
662+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
663+
resourceName := "aws_dlm_lifecycle_policy.test"
664+
665+
resource.ParallelTest(t, resource.TestCase{
666+
PreCheck: func() {
667+
acctest.PreCheck(ctx, t)
668+
acctest.PreCheckMultipleRegion(t, 2)
669+
testAccPreCheck(ctx, t)
670+
},
671+
ErrorCheck: acctest.ErrorCheck(t, names.DLMServiceID),
672+
ProtoV5ProviderFactories: acctest.ProtoV5FactoriesAlternate(ctx, t),
673+
CheckDestroy: testAccCheckLifecyclePolicyDestroy(ctx),
674+
Steps: []resource.TestStep{
675+
{
676+
Config: testAccLifecyclePolicyConfig_crossRegionCopyRuleImageManagement(rName),
677+
Check: resource.ComposeTestCheckFunc(
678+
checkLifecyclePolicyExists(ctx, resourceName),
679+
resource.TestCheckResourceAttr(resourceName, "policy_details.0.policy_type", "IMAGE_MANAGEMENT"),
680+
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.cross_region_copy_rule.#", "1"),
681+
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.cross_region_copy_rule.0.encrypted", acctest.CtFalse),
682+
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.cross_region_copy_rule.0.retain_rule.0.interval", "15"),
683+
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.cross_region_copy_rule.0.retain_rule.0.interval_unit", "DAYS"),
684+
resource.TestCheckResourceAttr(resourceName, "policy_details.0.schedule.0.cross_region_copy_rule.0.target_region", acctest.AlternateRegion()),
685+
),
686+
},
687+
{
688+
ResourceName: resourceName,
689+
ImportState: true,
690+
ImportStateVerify: true,
691+
},
692+
},
693+
})
694+
}
695+
660696
func TestAccDLMLifecyclePolicy_tags(t *testing.T) {
661697
ctx := acctest.Context(t)
662698
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
@@ -1518,6 +1554,47 @@ resource "aws_dlm_lifecycle_policy" "test" {
15181554
`, rName, acctest.AlternateRegion()))
15191555
}
15201556

1557+
func testAccLifecyclePolicyConfig_crossRegionCopyRuleImageManagement(rName string) string {
1558+
return acctest.ConfigCompose(
1559+
lifecyclePolicyBaseConfig(rName),
1560+
fmt.Sprintf(`
1561+
resource "aws_dlm_lifecycle_policy" "test" {
1562+
description = %[1]q
1563+
execution_role_arn = aws_iam_role.test.arn
1564+
1565+
policy_details {
1566+
policy_type = "IMAGE_MANAGEMENT"
1567+
resource_types = ["INSTANCE"]
1568+
1569+
schedule {
1570+
name = %[1]q
1571+
1572+
create_rule {
1573+
interval = 12
1574+
}
1575+
1576+
retain_rule {
1577+
count = 10
1578+
}
1579+
1580+
cross_region_copy_rule {
1581+
target_region = %[2]q
1582+
encrypted = false
1583+
retain_rule {
1584+
interval = 15
1585+
interval_unit = "DAYS"
1586+
}
1587+
}
1588+
}
1589+
1590+
target_tags = {
1591+
Name = %[1]q
1592+
}
1593+
}
1594+
}
1595+
`, rName, acctest.AlternateRegion()))
1596+
}
1597+
15211598
func testAccLifecyclePolicyConfig_updateCrossRegionCopyRule(rName string) string {
15221599
return acctest.ConfigCompose(
15231600
acctest.ConfigMultipleRegionProvider(2),

website/docs/r/dlm_lifecycle_policy.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ This resource supports the following arguments:
416416
* `deprecate_rule` - (Optional) The AMI deprecation rule for cross-Region AMI copies created by the rule. See the [`deprecate_rule`](#cross-region-copy-rule-deprecate-rule-arguments) block.
417417
* `encrypted` - (Required) To encrypt a copy of an unencrypted snapshot if encryption by default is not enabled, enable encryption using this parameter. Copies of encrypted snapshots are encrypted, even if this parameter is false or if encryption by default is not enabled.
418418
* `retain_rule` - (Required) The retention rule that indicates how long snapshot copies are to be retained in the destination Region. See the [`retain_rule`](#cross-region-copy-rule-retain-rule-arguments) block. Max of 1 per schedule.
419-
* `target` - (Required) The target Region or the Amazon Resource Name (ARN) of the target Outpost for the snapshot copies.
419+
* `target` - Use only for DLM policies of `policy_type=EBS_SNAPSHOT_MANAGEMENT`. The target Region or the Amazon Resource Name (ARN) of the target Outpost for the snapshot copies.
420+
* `target_region` - Use only for DLM policies of `policy_type=IMAGE_MANAGEMENT`. The target Region or the Amazon Resource Name (ARN) of the target Outpost for the snapshot copies.
420421

421422
#### Cross Region Copy Rule Deprecate Rule arguments
422423

0 commit comments

Comments
 (0)