From 4b4cbf990310d8d71811516ff78553ebe6bab848 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Thu, 4 Jun 2020 11:02:30 +0300 Subject: [PATCH 1/3] add arn attribute + support for linux sql server `instance_platform` --- aws/resource_aws_ec2_capacity_reservation.go | 18 +++++++++++++++ ...ource_aws_ec2_capacity_reservation_test.go | 23 +++++++++++++++++++ .../docs/r/ec2_capacity_reservation.markdown | 1 + 3 files changed, 42 insertions(+) diff --git a/aws/resource_aws_ec2_capacity_reservation.go b/aws/resource_aws_ec2_capacity_reservation.go index 19d2a30ee4ab..b54912a234b2 100644 --- a/aws/resource_aws_ec2_capacity_reservation.go +++ b/aws/resource_aws_ec2_capacity_reservation.go @@ -6,6 +6,7 @@ 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/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/helper/validation" @@ -86,6 +87,9 @@ func resourceAwsEc2CapacityReservation() *schema.Resource { ec2.CapacityReservationInstancePlatformWindowswithSqlserverEnterprise, ec2.CapacityReservationInstancePlatformWindowswithSqlserverStandard, ec2.CapacityReservationInstancePlatformWindowswithSqlserverWeb, + ec2.CapacityReservationInstancePlatformLinuxwithSqlserverStandard, + ec2.CapacityReservationInstancePlatformLinuxwithSqlserverWeb, + ec2.CapacityReservationInstancePlatformLinuxwithSqlserverEnterprise, }, false), }, "instance_type": { @@ -104,6 +108,10 @@ func resourceAwsEc2CapacityReservation() *schema.Resource { ec2.CapacityReservationTenancyDedicated, }, false), }, + "arn": { + Type: schema.TypeString, + Computed: true, + }, }, } } @@ -204,6 +212,16 @@ func resourceAwsEc2CapacityReservationRead(d *schema.ResourceData, meta interfac 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) + return nil } diff --git a/aws/resource_aws_ec2_capacity_reservation_test.go b/aws/resource_aws_ec2_capacity_reservation_test.go index 7473731107c0..fbc15f7458f3 100644 --- a/aws/resource_aws_ec2_capacity_reservation_test.go +++ b/aws/resource_aws_ec2_capacity_reservation_test.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "regexp" "testing" "time" @@ -77,6 +78,7 @@ func TestAccAWSEc2CapacityReservation_basic(t *testing.T) { Config: testAccEc2CapacityReservationConfig, Check: resource.ComposeTestCheckFunc( testAccCheckEc2CapacityReservationExists(resourceName, &cr), + testAccMatchResourceAttrRegionalARN(resourceName, "arn", "ec2", regexp.MustCompile(`capacity-reservation/cr-.+`)), resource.TestCheckResourceAttrPair(resourceName, "availability_zone", availabilityZonesDataSourceName, "names.0"), resource.TestCheckResourceAttr(resourceName, "ebs_optimized", "false"), resource.TestCheckResourceAttr(resourceName, "end_date", ""), @@ -358,6 +360,27 @@ func TestAccAWSEc2CapacityReservation_tags(t *testing.T) { }) } +func TestAccAWSEc2CapacityReservation_disappears(t *testing.T) { + var cr ec2.CapacityReservation + resourceName := "aws_ec2_capacity_reservation.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSEc2CapacityReservation(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckEc2CapacityReservationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccEc2CapacityReservationConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckEc2CapacityReservationExists(resourceName, &cr), + testAccCheckResourceDisappears(testAccProvider, resourceAwsEc2CapacityReservation(), resourceName), + ), + ExpectNonEmptyPlan: true, + }, + }, + }) +} + func TestAccAWSEc2CapacityReservation_tenancy(t *testing.T) { // Error creating EC2 Capacity Reservation: Unsupported: The requested configuration is currently not supported. Please check the documentation for supported configurations. t.Skip("EC2 Capacity Reservations do not currently support dedicated tenancy.") diff --git a/website/docs/r/ec2_capacity_reservation.markdown b/website/docs/r/ec2_capacity_reservation.markdown index 10df8da9fa65..085442978a17 100644 --- a/website/docs/r/ec2_capacity_reservation.markdown +++ b/website/docs/r/ec2_capacity_reservation.markdown @@ -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. +* `arn` - The ARN of the Capacity Reservation. ## Import From 1289676807330bf77678c82c2f5c8d99b384046c Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Thu, 4 Jun 2020 17:22:43 +0300 Subject: [PATCH 2/3] add to docs --- website/docs/index.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index 8f5b0b928bd8..df48dad389e5 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -246,6 +246,7 @@ for more information about connecting to alternate AWS endpoints or AWS compatib - [`aws_dx_public_virtual_interface` resource](/docs/providers/aws/r/dx_public_virtual_interface.html) - [`aws_dx_transit_virtual_interface` resource](/docs/providers/aws/r/dx_transit_virtual_interface.html) - [`aws_ebs_volume` data source](/docs/providers/aws/d/ebs_volume.html) + - [`aws_ec2_capacity_reservation` resource (import)](/docs/providers/aws/r/ec2_capacity_reservation.html) - [`aws_ecs_capacity_provider` resource (import)](/docs/providers/aws/r/ecs_capacity_provider.html) - [`aws_ecs_cluster` resource (import)](/docs/providers/aws/r/ecs_cluster.html) - [`aws_ecs_service` resource (import)](/docs/providers/aws/r/ecs_service.html) From ea360da25dd62c47d8b76562300d8ae432d45a46 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Thu, 4 Jun 2020 18:34:39 +0300 Subject: [PATCH 3/3] docs --- website/docs/index.html.markdown | 2 +- ...ervation.markdown => ec2_capacity_reservation.html.markdown} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename website/docs/r/{ec2_capacity_reservation.markdown => ec2_capacity_reservation.html.markdown} (100%) diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index df48dad389e5..63cce6ffac12 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -246,7 +246,7 @@ for more information about connecting to alternate AWS endpoints or AWS compatib - [`aws_dx_public_virtual_interface` resource](/docs/providers/aws/r/dx_public_virtual_interface.html) - [`aws_dx_transit_virtual_interface` resource](/docs/providers/aws/r/dx_transit_virtual_interface.html) - [`aws_ebs_volume` data source](/docs/providers/aws/d/ebs_volume.html) - - [`aws_ec2_capacity_reservation` resource (import)](/docs/providers/aws/r/ec2_capacity_reservation.html) + - [`aws_ec2_capacity_reservation` resource](/docs/providers/aws/r/ec2_capacity_reservation.html) - [`aws_ecs_capacity_provider` resource (import)](/docs/providers/aws/r/ecs_capacity_provider.html) - [`aws_ecs_cluster` resource (import)](/docs/providers/aws/r/ecs_cluster.html) - [`aws_ecs_service` resource (import)](/docs/providers/aws/r/ecs_service.html) diff --git a/website/docs/r/ec2_capacity_reservation.markdown b/website/docs/r/ec2_capacity_reservation.html.markdown similarity index 100% rename from website/docs/r/ec2_capacity_reservation.markdown rename to website/docs/r/ec2_capacity_reservation.html.markdown