Skip to content

Commit

Permalink
data-source/aws_api_gateway_api_key: Add created_date, description, e…
Browse files Browse the repository at this point in the history
…nabled, last_updated_date, and tags attributes (#10821)

Output from acceptance testing:

```
--- PASS: TestAccDataSourceAwsApiGatewayApiKey (8.38s)
```
  • Loading branch information
DrFaust92 authored and bflad committed Jan 18, 2020
1 parent 60b139c commit 4244937
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
29 changes: 29 additions & 0 deletions aws/data_source_aws_api_gateway_api_key.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package aws

import (
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func dataSourceAwsApiGatewayApiKey() *schema.Resource {
Expand All @@ -18,11 +22,28 @@ func dataSourceAwsApiGatewayApiKey() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"created_date": {
Type: schema.TypeString,
Computed: true,
},
"last_updated_date": {
Type: schema.TypeString,
Computed: true,
},
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"value": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"tags": tagsSchemaComputed(),
},
}
}
Expand All @@ -41,5 +62,13 @@ func dataSourceAwsApiGatewayApiKeyRead(d *schema.ResourceData, meta interface{})
d.SetId(aws.StringValue(apiKey.Id))
d.Set("name", apiKey.Name)
d.Set("value", apiKey.Value)
d.Set("created_date", aws.TimeValue(apiKey.CreatedDate).Format(time.RFC3339))
d.Set("description", apiKey.Description)
d.Set("enabled", apiKey.Enabled)
d.Set("last_updated_date", aws.TimeValue(apiKey.LastUpdatedDate).Format(time.RFC3339))

if err := d.Set("tags", keyvaluetags.ApigatewayKeyValueTags(apiKey.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}
return nil
}
5 changes: 5 additions & 0 deletions aws/data_source_aws_api_gateway_api_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func TestAccDataSourceAwsApiGatewayApiKey(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName1, "id", dataSourceName1, "id"),
resource.TestCheckResourceAttrPair(resourceName1, "name", dataSourceName1, "name"),
resource.TestCheckResourceAttrPair(resourceName1, "value", dataSourceName1, "value"),
resource.TestCheckResourceAttrPair(resourceName1, "enabled", dataSourceName1, "enabled"),
resource.TestCheckResourceAttrPair(resourceName1, "description", dataSourceName1, "description"),
resource.TestCheckResourceAttrSet(dataSourceName1, "last_updated_date"),
resource.TestCheckResourceAttrSet(dataSourceName1, "created_date"),
resource.TestCheckResourceAttr(dataSourceName1, "tags.%", "0"),
),
},
},
Expand Down
5 changes: 5 additions & 0 deletions website/docs/d/api_gateway_api_key.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,8 @@ data "aws_api_gateway_api_key" "my_api_key" {
* `id` - Set to the ID of the API Key.
* `name` - Set to the name of the API Key.
* `value` - Set to the value of the API Key.
* `created_date` - The date and time when the API Key was created.
* `last_updated_date` - The date and time when the API Key was last updated.
* `description` - The description of the API Key.
* `enabled` - Specifies whether the API Key is enabled.
* `tags` - A mapping of tags for the resource.

0 comments on commit 4244937

Please sign in to comment.