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

F/destination_outpost_arn support in aws_ami_copy #17735

Merged
merged 4 commits into from
May 11, 2021
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/17735.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_ami_copy: Add `destination_outpost_arn` argument
```
9 changes: 9 additions & 0 deletions aws/resource_aws_ami_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
52 changes: 52 additions & 0 deletions aws/resource_aws_ami_copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions website/docs/r/ami_copy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down