Exposed aws_api_gateway_api_key created_date & last_updated_date (#9530)

This commit is contained in:
Ninir 2016-11-14 11:03:56 +01:00 committed by Paul Stack
parent ab03a50d92
commit 932c92e4c6
3 changed files with 32 additions and 8 deletions

View File

@ -23,41 +23,51 @@ func resourceAwsApiGatewayApiKey() *schema.Resource {
},
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"description": &schema.Schema{
"description": {
Type: schema.TypeString,
Optional: true,
Default: "Managed by Terraform",
},
"enabled": &schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"stage_key": &schema.Schema{
"stage_key": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"rest_api_id": &schema.Schema{
"rest_api_id": {
Type: schema.TypeString,
Required: true,
},
"stage_name": &schema.Schema{
"stage_name": {
Type: schema.TypeString,
Required: true,
},
},
},
},
"created_date": {
Type: schema.TypeString,
Computed: true,
},
"last_updated_date": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
@ -102,6 +112,14 @@ func resourceAwsApiGatewayApiKeyRead(d *schema.ResourceData, meta interface{}) e
d.Set("enabled", apiKey.Enabled)
d.Set("stage_key", flattenApiGatewayStageKeys(apiKey.StageKeys))
if err := d.Set("created_date", apiKey.CreatedDate.Format(time.RFC3339)); err != nil {
log.Printf("[DEBUG] Error setting created_date: %s", err)
}
if err := d.Set("last_updated_date", apiKey.LastUpdatedDate.Format(time.RFC3339)); err != nil {
log.Printf("[DEBUG] Error setting last_updated_date: %s", err)
}
return nil
}

View File

@ -20,7 +20,7 @@ func TestAccAWSAPIGatewayApiKey_basic(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGatewayApiKeyDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccAWSAPIGatewayApiKeyConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayApiKeyExists("aws_api_gateway_api_key.test", &conf),
@ -29,6 +29,10 @@ func TestAccAWSAPIGatewayApiKey_basic(t *testing.T) {
"aws_api_gateway_api_key.test", "name", "foo"),
resource.TestCheckResourceAttr(
"aws_api_gateway_api_key.test", "description", "Managed by Terraform"),
resource.TestCheckResourceAttrSet(
"aws_api_gateway_api_key.test", "created_date"),
resource.TestCheckResourceAttrSet(
"aws_api_gateway_api_key.test", "last_updated_date"),
),
},
},

View File

@ -51,6 +51,8 @@ The following arguments are supported:
The following attributes are exported:
* `id` - The ID of the API key
* `created_date` - The creation date of the API key
* `last_updated_date` - The last update date of the API key
## Import
@ -59,4 +61,4 @@ API Gateway Keys can be imported using the `id`, e.g.
```
$ terraform import aws_api_gateway_api_key.my_demo_key 8bklk8bl1k3sB38D9B3l0enyWT8c09B30lkq0blk
```
```