diff --git a/.changelog/17735.txt b/.changelog/17735.txt new file mode 100644 index 000000000000..ed697b895426 --- /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 diff --git a/aws/resource_aws_ami_copy.go b/aws/resource_aws_ami_copy.go index 1dd9f74b6734..d314fd818a9f 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 48a2b8bf3cd3..ae7bf4582e18 100644 --- a/aws/resource_aws_ami_copy_test.go +++ b/aws/resource_aws_ami_copy_test.go @@ -91,6 +91,29 @@ 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) }, + ErrorCheck: testAccErrorCheck(t, ec2.EndpointsID), + 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 +390,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 3f1261ba52a3..43f302342773 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.