Skip to content

Commit

Permalink
hashicorp#2009: fixed per @bflad review
Browse files Browse the repository at this point in the history
  • Loading branch information
trung committed Feb 26, 2018
1 parent 656d814 commit e28ea81
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
9 changes: 2 additions & 7 deletions aws/data_source_aws_kms_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,10 @@ func dataSourceAwsKmsKey() *schema.Resource {

func dataSourceAwsKmsKeyRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).kmsconn
keyId, keyIdOk := d.GetOk("key_id")
if !keyIdOk {
return fmt.Errorf("key_id value is missing")
}
keyId := d.Get("key_id")
var grantTokens []*string
if v, ok := d.GetOk("grant_tokens"); ok {
for _, token := range v.([]interface{}) {
grantTokens = append(grantTokens, aws.String(token.(string)))
}
grantTokens = aws.StringSlice(v.([]string))
}
input := &kms.DescribeKeyInput{
KeyId: aws.String(keyId.(string)),
Expand Down
17 changes: 15 additions & 2 deletions aws/data_source_aws_kms_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,30 @@ import (

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"regexp"
)

func TestAccDataSourceAwsKmsKey(t *testing.T) {
func TestAccDataSourceAwsKmsKey_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccDataSourceAwsKmsKeyConfig,
Check: resource.ComposeTestCheckFunc(
testAccDataSourceAwsKmsKeyCheck("data.aws_kms_key.arbitrary"),
resource.TestMatchResourceAttr("data.aws_kms_key.arbitrary", "arn", regexp.MustCompile("^arn:[^:]+:kms:[^:]+:[^:]+:key/.+")),
resource.TestCheckResourceAttrSet("data.aws_kms_key.arbitrary", "aws_account_id"),
resource.TestCheckResourceAttrSet("data.aws_kms_key.arbitrary", "creation_date"),
resource.TestCheckResourceAttrSet("data.aws_kms_key.arbitrary", "deletion_date"),
resource.TestCheckResourceAttr("data.aws_kms_key.arbitrary", "description", "Terraform acc test"),
resource.TestCheckResourceAttr("data.aws_kms_key.arbitrary", "enabled", "true"),
resource.TestCheckResourceAttrSet("data.aws_kms_key.arbitrary", "expiration_model"),
resource.TestCheckResourceAttrSet("data.aws_kms_key.arbitrary", "key_manager"),
resource.TestCheckResourceAttrSet("data.aws_kms_key.arbitrary", "key_state"),
resource.TestCheckResourceAttrSet("data.aws_kms_key.arbitrary", "key_usage"),
resource.TestCheckResourceAttrSet("data.aws_kms_key.arbitrary", "origin"),
resource.TestCheckResourceAttrSet("data.aws_kms_key.arbitrary", "valid_to"),
),
},
},
Expand Down
2 changes: 1 addition & 1 deletion aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -2146,7 +2146,7 @@ func validateDxConnectionBandWidth(v interface{}, k string) (ws []string, errors

func validateKmsKey(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
arnPrefixPattern := `arn:[\w-]+:([a-zA-Z0-9\-])+:([a-z]{2}-(gov-)?[a-z]+-\d{1})?:(\d{12})?:`
arnPrefixPattern := `arn:[^:]+:kms:[^:]+:[^:]+:`
keyIdPattern := "[A-Za-z0-9-]+"
keyArnPattern := arnPrefixPattern + "key/" + keyIdPattern
aliasNamePattern := "alias/[a-zA-Z0-9:/_-]+"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/kms_key.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: |-
Get information on a AWS Key Management Service (KMS) Key
---

# aws\_kms\_key
# aws_kms_key

Use this data source to get detailed information about
the specified KMS Key with flexible key id input.
Expand Down

0 comments on commit e28ea81

Please sign in to comment.