Skip to content

Commit

Permalink
Merge branch 'fix_ec2_capacity_reservation_arn' of ssh://github.com/s…
Browse files Browse the repository at this point in the history
…huheiktgw/terraform-provider-aws into shuheiktgw-fix_ec2_capacity_reservation_arn
  • Loading branch information
bflad committed Feb 11, 2021
2 parents 5a31b00 + 027aad0 commit 29e16ed
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
17 changes: 6 additions & 11 deletions aws/resource_aws_ec2_capacity_reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -97,6 +96,10 @@ func resourceAwsEc2CapacityReservation() *schema.Resource {
Required: true,
ForceNew: true,
},
"owner_id": {
Type: schema.TypeString,
Computed: true,
},
"tags": tagsSchema(),
"tenancy": {
Type: schema.TypeString,
Expand Down Expand Up @@ -205,22 +208,14 @@ 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("owner_id", reservation.OwnerId)

if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(reservation.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

d.Set("tenancy", reservation.Tenancy)

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "ec2",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("capacity-reservation/%s", d.Id()),
}.String()

d.Set("arn", arn)
d.Set("arn", reservation.CapacityReservationArn)

return nil
}
Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_ec2_capacity_reservation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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"),
testAccCheckResourceAttrAccountID(resourceName, "owner_id"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "tenancy", "default"),
),
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ec2_capacity_reservation.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `id` - The Capacity Reservation ID.
* `owner_id` - The ID of the AWS account that owns the Capacity Reservation.
* `arn` - The ARN of the Capacity Reservation.

## Import
Expand Down

0 comments on commit 29e16ed

Please sign in to comment.