-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added data source aws_kms_custom_key_store
- Loading branch information
Paul Harrington
committed
May 16, 2022
1 parent
3ea2d0b
commit 4a6c834
Showing
3 changed files
with
132 additions
and
6 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
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,92 @@ | ||
package kms | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/kms" | ||
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-aws/internal/conns" | ||
"github.com/hashicorp/terraform-provider-aws/internal/tfresource" | ||
) | ||
|
||
func DataSourceCustomKeyStore() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceCustomKeyStoreRead, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"cloudhsm_cluster_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"connection_state": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"creation_date": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"trust_anchor_certificate": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceCustomKeyStoreRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*conns.AWSClient).KMSConn | ||
|
||
input := &kms.DescribeCustomKeyStoresInput{} | ||
|
||
if v, ok := d.GetOk("id"); ok { | ||
input.CustomKeyStoreId = aws.String(v.(string)) | ||
} | ||
if v, ok := d.GetOk("name"); ok { | ||
input.CustomKeyStoreName = aws.String(v.(string)) | ||
} | ||
|
||
output, err := conn.DescribeCustomKeyStores(input) | ||
|
||
if tfawserr.ErrCodeEquals(err, kms.ErrCodeCustomKeyStoreNotFoundException) { | ||
return &resource.NotFoundError{ | ||
LastError: err, | ||
LastRequest: input, | ||
} | ||
} | ||
|
||
if err != nil { | ||
return fmt.Errorf("error reading KMS Custom Key Store: %w", err) | ||
} | ||
|
||
if output == nil || len(output.CustomKeyStores) == 0 || output.CustomKeyStores[0] == nil { | ||
return tfresource.NewEmptyResultError(input) | ||
} | ||
|
||
if count := len(output.CustomKeyStores); count > 1 { | ||
return tfresource.NewTooManyResultsError(count, input) | ||
} | ||
|
||
keyStore := output.CustomKeyStores[0] | ||
d.SetId(aws.StringValue(keyStore.CustomKeyStoreId)) | ||
d.Set("name", keyStore.CustomKeyStoreName) | ||
d.Set("cloudhsm_cluster_id", keyStore.CloudHsmClusterId) | ||
d.Set("connection_state", keyStore.ConnectionState) | ||
d.Set("creation_date", keyStore.CreationDate.Format(time.RFC3339)) | ||
d.Set("trust_anchor_certificate", keyStore.TrustAnchorCertificate) | ||
|
||
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,33 @@ | ||
--- | ||
subcategory: "KMS (Key Management)" | ||
layout: "aws" | ||
page_title: "AWS: aws_kms_custom_key_store" | ||
description: |- | ||
Get information on a AWS Key Management Service (KMS) Custom Key Store | ||
--- | ||
|
||
# Data Source: aws_kms_custom_key_store | ||
|
||
Use this data source to get the metadata KMS custom key store. | ||
By using this data source, you can reference KMS custom key store | ||
without having to hard code the ID as input. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "aws_kms_custom_key_store" "keystore" { | ||
name = "my_cloudhsm" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Optional) The user-specified friendly name for the custom key store. | ||
* `id` - (Optional) The ID for the custom key store. | ||
|
||
## Attributes Reference | ||
|
||
* `cloudhsm_cluster_id` - ID for the CloudHSM cluster that is associated with the custom key store. | ||
* `connection_state` - Indicates whether the custom key store is connected to its CloudHSM cluster. | ||
* `creation_date` - The date and time when the custom key store was created. | ||
* `trust_anchor_certificate` - The trust anchor certificate of the associated CloudHSM cluster. |