From a88b25cfcf654ca7529913dced9bd11cc46f94c2 Mon Sep 17 00:00:00 2001 From: Ninir Date: Sun, 23 Oct 2016 15:08:41 +0200 Subject: [PATCH] Exposed AWS API GW REST Api created_date attribute --- .../aws/resource_aws_api_gateway_rest_api.go | 22 ++++++++++++++----- .../resource_aws_api_gateway_rest_api_test.go | 8 +++++-- .../aws/r/api_gateway_rest_api.html.markdown | 1 + 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/builtin/providers/aws/resource_aws_api_gateway_rest_api.go b/builtin/providers/aws/resource_aws_api_gateway_rest_api.go index 2d6f6dc26..2500ba3fa 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_rest_api.go +++ b/builtin/providers/aws/resource_aws_api_gateway_rest_api.go @@ -20,17 +20,22 @@ func resourceAwsApiGatewayRestApi() *schema.Resource { Delete: resourceAwsApiGatewayRestApiDelete, Schema: map[string]*schema.Schema{ - "name": &schema.Schema{ + "name": { Type: schema.TypeString, Required: true, }, - "description": &schema.Schema{ + "description": { Type: schema.TypeString, Optional: true, }, - "root_resource_id": &schema.Schema{ + "root_resource_id": { + Type: schema.TypeString, + Computed: true, + }, + + "created_date": { Type: schema.TypeString, Computed: true, }, @@ -56,7 +61,11 @@ func resourceAwsApiGatewayRestApiCreate(d *schema.ResourceData, meta interface{} d.SetId(*gateway.Id) - return resourceAwsApiGatewayRestApiRefreshResources(d, meta) + if err = resourceAwsApiGatewayRestApiRefreshResources(d, meta); err != nil { + return err + } + + return resourceAwsApiGatewayRestApiRead(d, meta) } func resourceAwsApiGatewayRestApiRefreshResources(d *schema.ResourceData, meta interface{}) error { @@ -94,10 +103,13 @@ func resourceAwsApiGatewayRestApiRead(d *schema.ResourceData, meta interface{}) return err } - d.SetId(*api.Id) d.Set("name", api.Name) d.Set("description", api.Description) + if err := d.Set("created_date", api.CreatedDate.Format(time.RFC3339)); err != nil { + log.Printf("[DEBUG] Error setting created_date: %s", err) + } + return nil } diff --git a/builtin/providers/aws/resource_aws_api_gateway_rest_api_test.go b/builtin/providers/aws/resource_aws_api_gateway_rest_api_test.go index 0cac93f04..e534c6cfc 100644 --- a/builtin/providers/aws/resource_aws_api_gateway_rest_api_test.go +++ b/builtin/providers/aws/resource_aws_api_gateway_rest_api_test.go @@ -18,7 +18,7 @@ func TestAccAWSAPIGatewayRestApi_basic(t *testing.T) { Providers: testAccProviders, CheckDestroy: testAccCheckAWSAPIGatewayRestAPIDestroy, Steps: []resource.TestStep{ - resource.TestStep{ + { Config: testAccAWSAPIGatewayRestAPIConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayRestAPIExists("aws_api_gateway_rest_api.test", &conf), @@ -27,10 +27,12 @@ func TestAccAWSAPIGatewayRestApi_basic(t *testing.T) { "aws_api_gateway_rest_api.test", "name", "bar"), resource.TestCheckResourceAttr( "aws_api_gateway_rest_api.test", "description", ""), + resource.TestCheckResourceAttrSet( + "aws_api_gateway_rest_api.test", "created_date"), ), }, - resource.TestStep{ + { Config: testAccAWSAPIGatewayRestAPIUpdateConfig, Check: resource.ComposeTestCheckFunc( testAccCheckAWSAPIGatewayRestAPIExists("aws_api_gateway_rest_api.test", &conf), @@ -40,6 +42,8 @@ func TestAccAWSAPIGatewayRestApi_basic(t *testing.T) { "aws_api_gateway_rest_api.test", "name", "test"), resource.TestCheckResourceAttr( "aws_api_gateway_rest_api.test", "description", "test"), + resource.TestCheckResourceAttrSet( + "aws_api_gateway_rest_api.test", "created_date"), ), }, }, diff --git a/website/source/docs/providers/aws/r/api_gateway_rest_api.html.markdown b/website/source/docs/providers/aws/r/api_gateway_rest_api.html.markdown index 5d376df74..21bccd8ff 100644 --- a/website/source/docs/providers/aws/r/api_gateway_rest_api.html.markdown +++ b/website/source/docs/providers/aws/r/api_gateway_rest_api.html.markdown @@ -32,3 +32,4 @@ The following attributes are exported: * `id` - The ID of the REST API * `root_resource_id` - The resource ID of the REST API's root +* `created_date` - The creation date of the REST API