From eb68d1489d1af35d898fc0417f85c3b47d771448 Mon Sep 17 00:00:00 2001 From: nikhil Date: Sun, 21 Feb 2021 01:27:52 +0530 Subject: [PATCH 1/4] outpost_arn support in aws_ami_copy --- aws/resource_aws_ami_copy.go | 9 +++++ aws/resource_aws_ami_copy_test.go | 51 +++++++++++++++++++++++++++ website/docs/r/ami_copy.html.markdown | 2 ++ 3 files changed, 62 insertions(+) diff --git a/aws/resource_aws_ami_copy.go b/aws/resource_aws_ami_copy.go index 1dd9f74b673..d314fd818a9 100644 --- a/aws/resource_aws_ami_copy.go +++ b/aws/resource_aws_ami_copy.go @@ -209,6 +209,11 @@ func resourceAwsAmiCopy() *schema.Resource { Required: true, ForceNew: true, }, + "destination_outpost_arn": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateArn, + }, "sriov_net_support": { Type: schema.TypeString, Computed: true, @@ -252,6 +257,10 @@ func resourceAwsAmiCopyCreate(d *schema.ResourceData, meta interface{}) error { req.KmsKeyId = aws.String(v.(string)) } + if v, ok := d.GetOk("destination_outpost_arn"); ok { + req.DestinationOutpostArn = aws.String(v.(string)) + } + res, err := client.CopyImage(req) if err != nil { return err diff --git a/aws/resource_aws_ami_copy_test.go b/aws/resource_aws_ami_copy_test.go index 48a2b8bf3cd..6e6bc578639 100644 --- a/aws/resource_aws_ami_copy_test.go +++ b/aws/resource_aws_ami_copy_test.go @@ -91,6 +91,28 @@ func TestAccAWSAMICopy_EnaSupport(t *testing.T) { }) } +func TestAccAWSAMICopy_DestinationOutpost(t *testing.T) { + var image ec2.Image + rName := acctest.RandomWithPrefix("tf-acc-test") + outpostDataSourceName := "data.aws_outposts_outpost.test" + resourceName := "aws_ami_copy.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAMICopyDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSAMICopyConfigDestOutpost(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSAMICopyExists(resourceName, &image), + resource.TestCheckResourceAttrPair(resourceName, "destination_outpost_arn", outpostDataSourceName, "arn"), + ), + }, + }, + }) +} + func TestAccAWSAMICopy_tags(t *testing.T) { var ami ec2.Image resourceName := "aws_ami_copy.test" @@ -367,3 +389,32 @@ resource "aws_ami_copy" "test" { } `, rName, rName) } + +func testAccAWSAMICopyConfigDestOutpost(rName string) string { + return testAccAWSAMICopyConfigBase(rName) + fmt.Sprintf(` +data "aws_outposts_outposts" "test" {} + +data "aws_outposts_outpost" "test" { + id = tolist(data.aws_outposts_outposts.test.ids)[0] +} + +resource "aws_ami" "test" { + ena_support = true + name = "%s-source" + virtualization_type = "hvm" + root_device_name = "/dev/sda1" + + ebs_block_device { + device_name = "/dev/sda1" + snapshot_id = aws_ebs_snapshot.test.id + } +} + +resource "aws_ami_copy" "test" { + name = "%s-copy" + source_ami_id = aws_ami.test.id + source_ami_region = data.aws_region.current.name + destination_outpost_arn = data.aws_outposts_outpost.test.arn +} +`, rName, rName) +} diff --git a/website/docs/r/ami_copy.html.markdown b/website/docs/r/ami_copy.html.markdown index 3f1261ba52a..a89a03fcd7c 100644 --- a/website/docs/r/ami_copy.html.markdown +++ b/website/docs/r/ami_copy.html.markdown @@ -44,6 +44,8 @@ The following arguments are supported: given by `source_ami_region`. * `source_ami_region` - (Required) The region from which the AMI will be copied. This may be the same as the AWS provider region in order to create a copy within the same region. +* `destination_outpost_arn` - (Optional) The ARN of the Outpost to which to copy the AMI. + Only specify this parameter when copying an AMI from an AWS Region to an Outpost. The AMI must be in the Region of the destination Outpost. * `encrypted` - (Optional) Specifies whether the destination snapshots of the copied image should be encrypted. Defaults to `false` * `kms_key_id` - (Optional) The full ARN of the KMS Key to use when encrypting the snapshots of an image during a copy operation. If not specified, then the default AWS KMS Key will be used * `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. From e7600284d4f4bd1b7734ff7ae15eb92189620b5c Mon Sep 17 00:00:00 2001 From: nikhil Date: Sun, 21 Feb 2021 01:38:53 +0530 Subject: [PATCH 2/4] outpost_arn support in aws_ami_copy --- aws/resource_aws_ami_copy_test.go | 6 +++--- website/docs/r/ami_copy.html.markdown | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/aws/resource_aws_ami_copy_test.go b/aws/resource_aws_ami_copy_test.go index 6e6bc578639..948a0d40f5c 100644 --- a/aws/resource_aws_ami_copy_test.go +++ b/aws/resource_aws_ami_copy_test.go @@ -411,9 +411,9 @@ resource "aws_ami" "test" { } resource "aws_ami_copy" "test" { - name = "%s-copy" - source_ami_id = aws_ami.test.id - source_ami_region = data.aws_region.current.name + name = "%s-copy" + source_ami_id = aws_ami.test.id + source_ami_region = data.aws_region.current.name destination_outpost_arn = data.aws_outposts_outpost.test.arn } `, rName, rName) diff --git a/website/docs/r/ami_copy.html.markdown b/website/docs/r/ami_copy.html.markdown index a89a03fcd7c..43f30234277 100644 --- a/website/docs/r/ami_copy.html.markdown +++ b/website/docs/r/ami_copy.html.markdown @@ -44,7 +44,7 @@ The following arguments are supported: given by `source_ami_region`. * `source_ami_region` - (Required) The region from which the AMI will be copied. This may be the same as the AWS provider region in order to create a copy within the same region. -* `destination_outpost_arn` - (Optional) The ARN of the Outpost to which to copy the AMI. +* `destination_outpost_arn` - (Optional) The ARN of the Outpost to which to copy the AMI. Only specify this parameter when copying an AMI from an AWS Region to an Outpost. The AMI must be in the Region of the destination Outpost. * `encrypted` - (Optional) Specifies whether the destination snapshots of the copied image should be encrypted. Defaults to `false` * `kms_key_id` - (Optional) The full ARN of the KMS Key to use when encrypting the snapshots of an image during a copy operation. If not specified, then the default AWS KMS Key will be used From 7a69af2b0d517272be50b2a607b03e66e8e8032a Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 May 2021 17:08:16 -0400 Subject: [PATCH 3/4] Add CHANGELOG entry. --- .changelog/17735.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/17735.txt diff --git a/.changelog/17735.txt b/.changelog/17735.txt new file mode 100644 index 00000000000..ed697b89542 --- /dev/null +++ b/.changelog/17735.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_ami_copy: Add `destination_outpost_arn` argument +``` \ No newline at end of file From 08d8dca7c30894ff09cf953254fe17ed3ae71c6d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 11 May 2021 17:21:19 -0400 Subject: [PATCH 4/4] Fix awsproviderlint error 'XAT001: missing ErrorCheck'. --- aws/resource_aws_ami_copy_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_ami_copy_test.go b/aws/resource_aws_ami_copy_test.go index 948a0d40f5c..ae7bf4582e1 100644 --- a/aws/resource_aws_ami_copy_test.go +++ b/aws/resource_aws_ami_copy_test.go @@ -99,6 +99,7 @@ func TestAccAWSAMICopy_DestinationOutpost(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSOutpostsOutposts(t) }, + ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSAMICopyDestroy, Steps: []resource.TestStep{