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

[Enhancement]: r/ebs_snapshot_copy new completion_duration_minutes argument. Time-based Copy for EBS Snapshots #40336

Merged
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/40336.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ebs_snapshot_copy: Add `completion_duration_minutes` argument
```
25 changes: 17 additions & 8 deletions internal/service/ec2/ebs_snapshot_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func resourceEBSSnapshotCopy() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"completion_duration_minutes": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
ValidateFunc: validation.All(validation.IntDivisibleBy(15), validation.IntAtMost(2880)),
},
"data_encryption_key_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -123,6 +129,10 @@ func resourceEBSSnapshotCopyCreate(ctx context.Context, d *schema.ResourceData,
TagSpecifications: getTagSpecificationsIn(ctx, awstypes.ResourceTypeSnapshot),
}

if v, ok := d.GetOk("completion_duration_minutes"); ok {
input.CompletionDurationMinutes = aws.Int32(int32(v.(int)))
}

if v, ok := d.GetOk(names.AttrDescription); ok {
input.Description = aws.String(v.(string))
}
Expand All @@ -145,8 +155,7 @@ func resourceEBSSnapshotCopyCreate(ctx context.Context, d *schema.ResourceData,

_, err = tfresource.RetryWhenAWSErrCodeEquals(ctx, d.Timeout(schema.TimeoutCreate),
func() (interface{}, error) {
waiter := ec2.NewSnapshotCompletedWaiter(conn)
return waiter.WaitForOutput(ctx, &ec2.DescribeSnapshotsInput{
return ec2.NewSnapshotCompletedWaiter(conn).WaitForOutput(ctx, &ec2.DescribeSnapshotsInput{
SnapshotIds: []string{d.Id()},
}, d.Timeout(schema.TimeoutCreate))
},
Expand All @@ -156,19 +165,19 @@ func resourceEBSSnapshotCopyCreate(ctx context.Context, d *schema.ResourceData,
return sdkdiag.AppendErrorf(diags, "waiting for EBS Snapshot Copy (%s) create: %s", d.Id(), err)
}

if v, ok := d.GetOk("storage_tier"); ok && v.(string) == string(awstypes.TargetStorageTierArchive) {
_, err = conn.ModifySnapshotTier(ctx, &ec2.ModifySnapshotTierInput{
if v, ok := d.GetOk("storage_tier"); ok && awstypes.TargetStorageTier(v.(string)) == awstypes.TargetStorageTierArchive {
input := &ec2.ModifySnapshotTierInput{
SnapshotId: aws.String(d.Id()),
StorageTier: awstypes.TargetStorageTier(v.(string)),
})
}

_, err := conn.ModifySnapshotTier(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "setting EBS Snapshot Copy (%s) Storage Tier: %s", d.Id(), err)
}

_, err = waitEBSSnapshotTierArchive(ctx, conn, d.Id(), ebsSnapshotArchivedTimeout)

if err != nil {
if _, err := waitEBSSnapshotTierArchive(ctx, conn, d.Id(), ebsSnapshotArchivedTimeout); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for EBS Snapshot Copy (%s) Storage Tier archive: %s", d.Id(), err)
}
}
Expand Down
37 changes: 37 additions & 0 deletions internal/service/ec2/ebs_snapshot_copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,29 @@ func TestAccEC2EBSSnapshotCopy_storageTier(t *testing.T) {
})
}

func TestAccEC2EBSSnapshotCopy_withCompletionDurationMinutes(t *testing.T) {
ctx := acctest.Context(t)
var snapshot awstypes.Snapshot
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_ebs_snapshot_copy.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.EC2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckEBSSnapshotDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccEBSSnapshotCopyConfig_completionDurationMinutes(rName, 15),
Check: resource.ComposeTestCheckFunc(
testAccCheckSnapshotExists(ctx, resourceName, &snapshot),
resource.TestCheckResourceAttr(resourceName, "completion_duration_minutes", "15"),
),
},
},
})
}

func testAccEBSSnapshotCopyBaseConfig(rName string) string {
return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(`
data "aws_region" "current" {}
Expand Down Expand Up @@ -349,3 +372,17 @@ resource "aws_ebs_snapshot_copy" "test" {
}
`, rName))
}

func testAccEBSSnapshotCopyConfig_completionDurationMinutes(rName string, durantionMinutes int) string {
return acctest.ConfigCompose(testAccEBSSnapshotCopyBaseConfig(rName), fmt.Sprintf(`
resource "aws_ebs_snapshot_copy" "test" {
source_snapshot_id = aws_ebs_snapshot.test.id
source_region = data.aws_region.current.name
completion_duration_minutes = %[2]d

tags = {
Name = %[1]q
}
}
`, rName, durantionMinutes))
}
1 change: 1 addition & 0 deletions website/docs/r/ebs_snapshot_copy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ This resource supports the following arguments:
* `storage_tier` - (Optional) The name of the storage tier. Valid values are `archive` and `standard`. Default value is `standard`.
* `permanent_restore` - (Optional) Indicates whether to permanently restore an archived snapshot.
* `temporary_restore_days` - (Optional) Specifies the number of days for which to temporarily restore an archived snapshot. Required for temporary restores only. The snapshot will be automatically re-archived after this period.
* `completion_duration_minutes` - (Optional) Specifies a completion duration to initiate a time-based snapshot copy. Time-based snapshot copy operations complete within the specified duration. Value must be between 15 and 2880 minutes, in 15 minute increments only.
* `tags` - A map of tags for the snapshot. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.

## Attribute Reference
Expand Down
Loading