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

New Resource: aws_ebs_snapshot_copy #3086

Merged
merged 5 commits into from
Oct 9, 2018

Conversation

jwieringa
Copy link
Contributor

@jwieringa jwieringa commented Jan 22, 2018

Purpose: Add aws_ebs_snapshot_copy resource

The bulk of the code is taken from resource_aws_ebs_snapshot. Tests are demonstrating the happy path is working.

Example Workflow:

  • Create and configure EBS volumes with Packer
  • Utilize Terraform to copy and encrypt snapshots to multiple regions and accounts
provider "aws" {
  region = "us-west-2"
  alias  = "uswest2"
}

provider "aws" {
  region = "us-east-1"
  alias  = "useast1"
}

resource "aws_ebs_volume" "region_test" {
  provider          = "aws.uswest2"
  availability_zone = "us-west-2a"
  size              = 1

  tags {
    Name = "testAccAwsCopySnapshotConfigWithRegions"
  }
}

resource "aws_ebs_snapshot" "region_test" {
  provider  = "aws.uswest2"
  volume_id = "${aws_ebs_volume.region_test.id}"

  tags {
    Name = "testAccAwsCopySnapshotConfigWithRegions"
  }
}

resource "aws_ebs_snapshot_copy" "region_test" {
  provider           = "aws.useast1"
  source_snapshot_id = "${aws_ebs_snapshot.region_test.id}"
  source_region      = "us-west-2"

  tags {
    Name = "testAccAwsCopySnapshotConfigWithRegions"
  }
}

Todos:

  • Verify acceptance tests
  • Test copying snapshots across regions
  • Test with KMS encryption
  • Add Documentation

@radeksimko radeksimko changed the title Added resource_aws_copy_snapshot New Resource: aws_copy_snapshot Jan 22, 2018
@radeksimko radeksimko added new-resource Introduces a new resource. service/ec2 Issues and PRs that pertain to the ec2 service. labels Jan 22, 2018
@jwieringa jwieringa force-pushed the f-add-aws-copy-snapshot branch from 74bc52e to db64c72 Compare January 22, 2018 20:05
@jwieringa
Copy link
Contributor Author

Rebased on master and added a commit to fix acceptance tests:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSCopySnapshot'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSCopySnapshot -timeout 120m
=== RUN   TestAccAWSCopySnapshot_basic
--- PASS: TestAccAWSCopySnapshot_basic (69.44s)
=== RUN   TestAccAWSCopySnapshot_withDescription
--- PASS: TestAccAWSCopySnapshot_withDescription (68.02s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	137.815s

req := &ec2.DescribeSnapshotsInput{
SnapshotIds: []*string{aws.String(id)},
}
err := conn.WaitUntilSnapshotCompleted(req)
Copy link
Contributor Author

@jwieringa jwieringa Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function call can result in an loop if incorrect configurations set. Consider a source_snapshot_id which is in us-west-2 and a config which sets source_region to us-east-1. In this scenario, the snapshot shows as pending via the AWS API for a few minutes (2m40s was observed) at which point the following is returned (I assume until the max retries is reached).

2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws: <DescribeSnapshotsResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:     <requestId>d6c4ece6-eded-4a90-a5dd-204191d8bdc5</requestId>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:     <snapshotSet>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:         <item>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:             <snapshotId>snap-0fb4b3336bc1b1493</snapshotId>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:             <volumeId>vol-ffffffff</volumeId>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:             <status>error</status>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:             <statusMessage>Source snapshot is not found</statusMessage>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:             <startTime>2018-01-23T00:05:06.000Z</startTime>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:             <progress>0%</progress>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:             <ownerId>721355555739</ownerId>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:             <volumeSize>0</volumeSize>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:             <description/>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:             <encrypted>false</encrypted>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:         </item>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws:     </snapshotSet>
2018-01-22T16:14:56.506-0800 [DEBUG] plugin.terraform-provider-aws: </DescribeSnapshotsResponse>

I suspect this could use some more work. At the ten minute mark:

Error: Error applying plan:

1 error(s) occurred:

* aws_copy_snapshot.region_test: 1 error(s) occurred:

* aws_copy_snapshot.region_test: ResourceNotReady: exceeded wait attempts

@jwieringa jwieringa force-pushed the f-add-aws-copy-snapshot branch 2 times, most recently from 8d5caba to f252278 Compare January 26, 2018 02:50
@jwieringa
Copy link
Contributor Author

Added documentation and rebased on master.

@jwieringa jwieringa force-pushed the f-add-aws-copy-snapshot branch from f252278 to 8397cc3 Compare January 30, 2018 21:26
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jan 30, 2018
@jwieringa
Copy link
Contributor Author

Rebased on master to bring up to date with 1.8 release.

@jwieringa jwieringa force-pushed the f-add-aws-copy-snapshot branch from 8397cc3 to c0307e6 Compare February 10, 2018 16:05
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Feb 10, 2018
@jwieringa
Copy link
Contributor Author

Rebased on master to bring up to date with 1.9 release.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSCopySnapshot'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSCopySnapshot -timeout 120m
=== RUN   TestAccAWSCopySnapshot_basic
--- PASS: TestAccAWSCopySnapshot_basic (104.07s)
=== RUN   TestAccAWSCopySnapshot_withDescription
--- PASS: TestAccAWSCopySnapshot_withDescription (72.90s)
=== RUN   TestAccAWSCopySnapshot_withRegions
--- PASS: TestAccAWSCopySnapshot_withRegions (122.94s)
=== RUN   TestAccAWSCopySnapshot_withKms
--- PASS: TestAccAWSCopySnapshot_withKms (94.29s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	394.522s

@jwieringa jwieringa force-pushed the f-add-aws-copy-snapshot branch from c0307e6 to 937dc96 Compare February 27, 2018 18:40
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Feb 27, 2018
@jwieringa
Copy link
Contributor Author

Rebased on master to bring up to date with 1.10 release.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSCopySnapshot'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSCopySnapshot -timeout 120m
=== RUN   TestAccAWSCopySnapshot_basic
--- PASS: TestAccAWSCopySnapshot_basic (85.71s)
=== RUN   TestAccAWSCopySnapshot_withDescription
--- PASS: TestAccAWSCopySnapshot_withDescription (106.32s)
=== RUN   TestAccAWSCopySnapshot_withRegions
--- PASS: TestAccAWSCopySnapshot_withRegions (89.16s)
=== RUN   TestAccAWSCopySnapshot_withKms
--- PASS: TestAccAWSCopySnapshot_withKms (118.07s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	399.612s

@jantman
Copy link

jantman commented Mar 25, 2018

Thanks so much for working on this! I've been using a custom AMI for ECS with a non-standard Block Device Mapping. I can create the AMI itself through Terraform, but I've been having to manually copy the root device snapshot of the official ECS Optimized AMI, and then pass that snapshot ID to terraform. This will make the process much easier for me!

@jwieringa jwieringa force-pushed the f-add-aws-copy-snapshot branch from 937dc96 to a98c717 Compare March 25, 2018 16:12
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Mar 25, 2018
@jwieringa
Copy link
Contributor Author

@jantman Glad it is helpful!

Rebased on master to bring up to date with 1.12.0 release.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSCopySnapshot'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSCopySnapshot -timeout 120m
=== RUN   TestAccAWSCopySnapshot_basic
--- PASS: TestAccAWSCopySnapshot_basic (75.40s)
=== RUN   TestAccAWSCopySnapshot_withDescription
--- PASS: TestAccAWSCopySnapshot_withDescription (88.13s)
=== RUN   TestAccAWSCopySnapshot_withRegions
--- PASS: TestAccAWSCopySnapshot_withRegions (77.39s)
=== RUN   TestAccAWSCopySnapshot_withKms
--- PASS: TestAccAWSCopySnapshot_withKms (79.17s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	320.490s

@jwieringa
Copy link
Contributor Author

Hi all, it would be great to see if the new resource aws_copy_snapshot is a good candidate for the AWS provider as it would help us out a lot. Please let me know if there is anything I can do.

@radeksimko because you've helped label the PR, are you also able to help schedule a review of this addition?

@jwieringa jwieringa changed the title New Resource: aws_copy_snapshot New Resource: aws_ebs_snapshot_copy Jul 10, 2018
@jwieringa jwieringa force-pushed the f-add-aws-copy-snapshot branch from a98c717 to 8250874 Compare July 10, 2018 18:27
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jul 10, 2018
@jwieringa
Copy link
Contributor Author

jwieringa commented Jul 10, 2018

I took another look at the original naming, aws_copy_snapshot, and I've reasoned that it was not consistent with resources like aws_ami_copy. Thus, I've modified the resource to be aws_ebs_snapshot_copy to conform to aws_<resource>_<action> which I thought matched existing resources better.

@jantman In case you've been using aws_copy_snapshot, 7e7dc07 changes the naming scheme.

I've also rebased on the master branch to resolve conflicts and updated tests so that they are passing again.

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSEbsSnapshotCopy'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSEbsSnapshotCopy -timeout 120m
=== RUN   TestAccAWSEbsSnapshotCopy_basic
--- PASS: TestAccAWSEbsSnapshotCopy_basic (206.51s)
=== RUN   TestAccAWSEbsSnapshotCopy_withDescription
--- PASS: TestAccAWSEbsSnapshotCopy_withDescription (160.51s)
=== RUN   TestAccAWSEbsSnapshotCopy_withRegions
--- PASS: TestAccAWSEbsSnapshotCopy_withRegions (132.78s)
=== RUN   TestAccAWSEbsSnapshotCopy_withKms
--- PASS: TestAccAWSEbsSnapshotCopy_withKms (104.15s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	604.414s

I took another look at the original naming, aws_copy_snapshot, and I've
reasoned that it was not consistent with resources like aws_ami_copy.
Thus, I've modified the resource to be aws_ebs_snapshot_copy to conform
to aws_<resource>_<action> which I thought matched existing resources better.
@jwieringa jwieringa force-pushed the f-add-aws-copy-snapshot branch from 8250874 to 7e7dc07 Compare July 10, 2018 18:37
@ghost ghost added the size/XL Managed by automation to categorize the size of a PR. label Jul 10, 2018
@bflad bflad added this to the v1.40.0 milestone Oct 9, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, @jwieringa! 🚀 Sorry this wasn't reviewed and merged sooner. 😅

--- PASS: TestAccAWSEbsSnapshotCopy_withRegions (66.01s)
--- PASS: TestAccAWSEbsSnapshotCopy_withDescription (135.70s)
--- PASS: TestAccAWSEbsSnapshotCopy_basic (150.72s)
--- PASS: TestAccAWSEbsSnapshotCopy_withKms (199.33s)

---
layout: "aws"
page_title: "AWS: aws_ebs_snapshot_copy"
sidebar_current: "docs-aws-resource-ebs-snapshot-copy"
Copy link
Contributor

@bflad bflad Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing missing was a link in website/aws.erb 😄 Will fix on merge

@bflad bflad merged commit 7c65edf into hashicorp:master Oct 9, 2018
bflad added a commit that referenced this pull request Oct 9, 2018
@jwieringa jwieringa deleted the f-add-aws-copy-snapshot branch October 9, 2018 17:28
@jwieringa
Copy link
Contributor Author

@bflad Thank you for the merge and handling the missing link. 🎆

@bflad
Copy link
Contributor

bflad commented Oct 10, 2018

This has been released in version 1.40.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 2, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-resource Introduces a new resource. service/ec2 Issues and PRs that pertain to the ec2 service. size/XL Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants