From 9e7f5bbe0ae9a7bad2c619412567d9350322f431 Mon Sep 17 00:00:00 2001 From: Richard Jennings Date: Wed, 26 May 2021 16:47:03 +0100 Subject: [PATCH 1/6] Init support for outpost_arn. --- aws/resource_aws_ec2_capacity_reservation.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/aws/resource_aws_ec2_capacity_reservation.go b/aws/resource_aws_ec2_capacity_reservation.go index 57e491bebf6..d368bb77e3e 100644 --- a/aws/resource_aws_ec2_capacity_reservation.go +++ b/aws/resource_aws_ec2_capacity_reservation.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "regexp" "time" "github.com/aws/aws-sdk-go/aws" @@ -98,6 +99,16 @@ func resourceAwsEc2CapacityReservation() *schema.Resource { Required: true, ForceNew: true, }, + "outpost_arn": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.All( + validation.StringMatch( + regexp.MustCompile(`^arn:aws([a-z-]+)?:outposts:[a-z\d-]+:\d{12}:outpost/op-[a-f0-9]{17}$`), + "must match ^arn:aws([a-z-]+)?:outposts:[a-z\\d-]+:\\d{12}:outpost/op-[a-f0-9]{17}$", + ), + ), + }, "owner_id": { Type: schema.TypeString, Computed: true, @@ -156,6 +167,10 @@ func resourceAwsEc2CapacityReservationCreate(d *schema.ResourceData, meta interf opts.InstanceMatchCriteria = aws.String(v.(string)) } + if v, ok := d.GetOk("outpost_arn"); ok { + opts.OutpostArn = aws.String(v.(string)) + } + if v, ok := d.GetOk("tenancy"); ok { opts.Tenancy = aws.String(v.(string)) } @@ -214,6 +229,7 @@ func resourceAwsEc2CapacityReservationRead(d *schema.ResourceData, meta interfac d.Set("instance_match_criteria", reservation.InstanceMatchCriteria) d.Set("instance_platform", reservation.InstancePlatform) d.Set("instance_type", reservation.InstanceType) + d.Set("outpost_arn", reservation.OutpostArn) d.Set("owner_id", reservation.OwnerId) tags := keyvaluetags.Ec2KeyValueTags(reservation.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig) From b6aceba4d8f4b493534ac278968e1aad014e6c84 Mon Sep 17 00:00:00 2001 From: Richard Jennings Date: Wed, 26 May 2021 17:04:09 +0100 Subject: [PATCH 2/6] add changelog release-note:enhancement resource/aws_ec2_capacity_reservation: Add support for outpost_arn attribute --- .changelog/19535.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/19535.txt diff --git a/.changelog/19535.txt b/.changelog/19535.txt new file mode 100644 index 00000000000..4ee30055411 --- /dev/null +++ b/.changelog/19535.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_ec2_capacity_reservation: Add support for outpost_arn attribute +``` \ No newline at end of file From 3f118725dbf3d0c5e484b692c93d4bb1e83e0c33 Mon Sep 17 00:00:00 2001 From: Richard Jennings Date: Wed, 26 May 2021 18:20:22 +0100 Subject: [PATCH 3/6] use validateArn instead of regex pattern --- aws/resource_aws_ec2_capacity_reservation.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/aws/resource_aws_ec2_capacity_reservation.go b/aws/resource_aws_ec2_capacity_reservation.go index d368bb77e3e..9d20620db3f 100644 --- a/aws/resource_aws_ec2_capacity_reservation.go +++ b/aws/resource_aws_ec2_capacity_reservation.go @@ -3,7 +3,6 @@ package aws import ( "fmt" "log" - "regexp" "time" "github.com/aws/aws-sdk-go/aws" @@ -100,14 +99,9 @@ func resourceAwsEc2CapacityReservation() *schema.Resource { ForceNew: true, }, "outpost_arn": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.All( - validation.StringMatch( - regexp.MustCompile(`^arn:aws([a-z-]+)?:outposts:[a-z\d-]+:\d{12}:outpost/op-[a-f0-9]{17}$`), - "must match ^arn:aws([a-z-]+)?:outposts:[a-z\\d-]+:\\d{12}:outpost/op-[a-f0-9]{17}$", - ), - ), + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateArn, }, "owner_id": { Type: schema.TypeString, From 1e5be7a74a4692aa504f8b0817b7469ce8b9d423 Mon Sep 17 00:00:00 2001 From: Richard Jennings Date: Wed, 26 May 2021 18:21:26 +0100 Subject: [PATCH 4/6] add check that outpost_arn is empty string --- aws/resource_aws_ec2_capacity_reservation_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/aws/resource_aws_ec2_capacity_reservation_test.go b/aws/resource_aws_ec2_capacity_reservation_test.go index 099a5840796..54b4e7e348d 100644 --- a/aws/resource_aws_ec2_capacity_reservation_test.go +++ b/aws/resource_aws_ec2_capacity_reservation_test.go @@ -89,6 +89,7 @@ func TestAccAWSEc2CapacityReservation_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "instance_match_criteria", "open"), resource.TestCheckResourceAttr(resourceName, "instance_platform", "Linux/UNIX"), resource.TestCheckResourceAttr(resourceName, "instance_type", "t2.micro"), + resource.TestCheckResourceAttr(resourceName, "outpost_arn", ""), testAccCheckResourceAttrAccountID(resourceName, "owner_id"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), resource.TestCheckResourceAttr(resourceName, "tenancy", "default"), From cbb68fb91a2640dac47ef5a1c4495668e55cd359 Mon Sep 17 00:00:00 2001 From: Richard Jennings Date: Wed, 26 May 2021 18:25:04 +0100 Subject: [PATCH 5/6] add outpost_arn attribute to website documentation --- website/docs/r/ec2_capacity_reservation.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/ec2_capacity_reservation.html.markdown b/website/docs/r/ec2_capacity_reservation.html.markdown index fa70669e024..3d61d70f24d 100644 --- a/website/docs/r/ec2_capacity_reservation.html.markdown +++ b/website/docs/r/ec2_capacity_reservation.html.markdown @@ -34,6 +34,7 @@ The following arguments are supported: * `instance_match_criteria` - (Optional) Indicates the type of instance launches that the Capacity Reservation accepts. Specify either `open` or `targeted`. * `instance_platform` - (Required) The type of operating system for which to reserve capacity. Valid options are `Linux/UNIX`, `Red Hat Enterprise Linux`, `SUSE Linux`, `Windows`, `Windows with SQL Server`, `Windows with SQL Server Enterprise`, `Windows with SQL Server Standard` or `Windows with SQL Server Web`. * `instance_type` - (Required) The instance type for which to reserve capacity. +* `outpost_arn` - (Optional) The Amazon Resource Name (ARN) of the Outpost on which to create the Capacity Reservation. * `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://www.terraform.io/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. * `tenancy` - (Optional) Indicates the tenancy of the Capacity Reservation. Specify either `default` or `dedicated`. From f135b689cf706e54e6e0c05e0e4b559c9bd65b94 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 26 May 2021 16:55:53 -0400 Subject: [PATCH 6/6] Update 19535.txt --- .changelog/19535.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changelog/19535.txt b/.changelog/19535.txt index 4ee30055411..50c62e684b8 100644 --- a/.changelog/19535.txt +++ b/.changelog/19535.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/aws_ec2_capacity_reservation: Add support for outpost_arn attribute -``` \ No newline at end of file +resource/aws_ec2_capacity_reservation: Add `outpost_arn` argument +```