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

Add opt_in_to_archive_for_supported_resources attribute to AWS Backup Plan resource #34994

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/34994.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_backup_plan: Add `rule.lifecycle.opt_in_to_archive_for_supported_resources` and `rule.copy_action.lifecycle.opt_in_to_archive_for_supported_resources` and arguments
```
14 changes: 14 additions & 0 deletions internal/service/backup/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ func ResourcePlan() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"opt_in_to_archive_for_supported_resources": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
},
},
Expand All @@ -122,6 +127,11 @@ func ResourcePlan() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"opt_in_to_archive_for_supported_resources": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -395,6 +405,9 @@ func expandPlanLifecycle(l []interface{}) *backup.Lifecycle {
if vMoveToColdStorageAfterDays, ok := lc["cold_storage_after"]; ok && vMoveToColdStorageAfterDays.(int) > 0 {
lifecycle.MoveToColdStorageAfterDays = aws.Int64(int64(vMoveToColdStorageAfterDays.(int)))
}
if optInToArchiveForSupportedResources, ok := lc["opt_in_to_archive_for_supported_resources"]; ok {
lifecycle.OptInToArchiveForSupportedResources = aws.Bool(optInToArchiveForSupportedResources.(bool))
}
}

return lifecycle
Expand Down Expand Up @@ -475,6 +488,7 @@ func flattenPlanCopyActionLifecycle(copyActionLifecycle *backup.Lifecycle) []int
m := map[string]interface{}{
"delete_after": aws.Int64Value(copyActionLifecycle.DeleteAfterDays),
"cold_storage_after": aws.Int64Value(copyActionLifecycle.MoveToColdStorageAfterDays),
"opt_in_to_archive_for_supported_resources": aws.BoolValue(copyActionLifecycle.OptInToArchiveForSupportedResources),
}

return []interface{}{m}
Expand Down
38 changes: 38 additions & 0 deletions internal/service/backup/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@ func TestAccBackupPlan_withLifecycle(t *testing.T) {
}),
),
},
{
Config: testAccPlanConfig_optInToArchiveForSupportedResources(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckPlanExists(ctx, resourceName, &plan),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "rule.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "rule.*", map[string]string{
"rule_name": rName,
"lifecycle.#": "1",
"lifecycle.0.cold_storage_after": "30",
"lifecycle.0.delete_after": "180",
"lifecycle.0.opt_in_to_archive_for_supported_resources": "true",
}),
),
},
{
Config: testAccPlanConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -727,6 +742,29 @@ resource "aws_backup_plan" "test" {
`, rName)
}

func testAccPlanConfig_optInToArchiveForSupportedResources(rName string) string {
return fmt.Sprintf(`
resource "aws_backup_vault" "test" {
name = %[1]q
}

resource "aws_backup_plan" "test" {
name = %[1]q

rule {
rule_name = %[1]q
target_vault_name = aws_backup_vault.test.name
schedule = "cron(0 10 ? * 6L *)"
lifecycle {
cold_storage_after = 30
delete_after = 180
opt_in_to_archive_for_supported_resources = true
}
}
}
`, rName)
}

func testAccPlanConfig_tags(rName string) string {
return fmt.Sprintf(`
resource "aws_backup_vault" "test" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/backup_plan.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ This resource supports the following arguments:

* `cold_storage_after` - (Optional) Specifies the number of days after creation that a recovery point is moved to cold storage.
* `delete_after` - (Optional) Specifies the number of days after creation that a recovery point is deleted. Must be 90 days greater than `cold_storage_after`.
* `opt_in_to_archive_for_supported_resources` - (Optional) This setting will instruct your backup plan to transition supported resources to archive (cold) storage tier in accordance with your lifecycle settings.

### Copy Action Arguments

Expand Down
Loading