-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6449 from gthole/data-apig-api-key
Add API Gateway API Key data source
- Loading branch information
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/apigateway" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceAwsApiGatewayApiKey() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsApiGatewayApiKeyRead, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"value": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Sensitive: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsApiGatewayApiKeyRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).apigateway | ||
apiKey, err := conn.GetApiKey(&apigateway.GetApiKeyInput{ | ||
ApiKey: aws.String(d.Get("id").(string)), | ||
IncludeValue: aws.Bool(true), | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(aws.StringValue(apiKey.Id)) | ||
d.Set("name", apiKey.Name) | ||
d.Set("value", apiKey.Value) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsApiGatewayApiKey(t *testing.T) { | ||
rName := acctest.RandString(8) | ||
resourceName1 := "aws_api_gateway_api_key.example_key" | ||
dataSourceName1 := "data.aws_api_gateway_api_key.test_key" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsApiGatewayApiKeyConfig(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(resourceName1, "id", dataSourceName1, "id"), | ||
resource.TestCheckResourceAttrPair(resourceName1, "name", dataSourceName1, "name"), | ||
resource.TestCheckResourceAttrPair(resourceName1, "value", dataSourceName1, "value"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsApiGatewayApiKeyConfig(r string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_api_gateway_api_key" "example_key" { | ||
name = "%s" | ||
} | ||
data "aws_api_gateway_api_key" "test_key" { | ||
id = "${aws_api_gateway_api_key.example_key.id}" | ||
} | ||
`, r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_api_gateway_api_key" | ||
sidebar_current: "docs-aws_api_gateway_api_key" | ||
description: |- | ||
Get information on an API Gateway API Key | ||
--- | ||
|
||
# Data Source: aws_api_gateway_api_key | ||
|
||
Use this data source to get the name and value of a pre-existing API Key, for | ||
example to supply credentials for a dependency microservice. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_api_gateway_api_key" "my_api_key" { | ||
id = "ru3mpjgse6" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `id` - (Required) The ID of the API Key to look up. | ||
|
||
## Attributes Reference | ||
|
||
* `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. |