Skip to content

Commit

Permalink
Add name to google_kms_crypto_key_version datasource (#5065) (#3500)
Browse files Browse the repository at this point in the history
Co-authored-by: upodroid <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: upodroid <[email protected]>
  • Loading branch information
modular-magician and upodroid authored Aug 10, 2021
1 parent e87da38 commit aaceb3b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/5065.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
kms: added `name` field to `google_kms_crypto_key_version` datasource
```
11 changes: 11 additions & 0 deletions google-beta/data_source_google_kms_crypto_key_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func dataSourceGoogleKmsCryptoKeyVersion() *schema.Resource {
Required: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -81,6 +85,9 @@ func dataSourceGoogleKmsCryptoKeyVersionRead(d *schema.ResourceData, meta interf
if err := d.Set("version", flattenKmsCryptoKeyVersionVersion(res["name"], d)); err != nil {
return fmt.Errorf("Error setting CryptoKeyVersion: %s", err)
}
if err := d.Set("name", flattenKmsCryptoKeyVersionName(res["name"], d)); err != nil {
return fmt.Errorf("Error setting CryptoKeyVersion: %s", err)
}
if err := d.Set("state", flattenKmsCryptoKeyVersionState(res["state"], d)); err != nil {
return fmt.Errorf("Error setting CryptoKeyVersion: %s", err)
}
Expand Down Expand Up @@ -135,6 +142,10 @@ func flattenKmsCryptoKeyVersionVersion(v interface{}, d *schema.ResourceData) in
return v
}

func flattenKmsCryptoKeyVersionName(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenKmsCryptoKeyVersionState(v interface{}, d *schema.ResourceData) interface{} {
return v
}
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_gke_hub_feature_membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
"github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
gkehub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down
9 changes: 6 additions & 3 deletions website/docs/d/kms_crypto_key_version.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ data "google_kms_key_ring" "my_key_ring" {
data "google_kms_crypto_key" "my_crypto_key" {
name = "my-crypto-key"
key_ring = data.google_kms_key_ring.my_key_ring.self_link
key_ring = data.google_kms_key_ring.my_key_ring.id
}
data "google_kms_crypto_key_version" "my_crypto_key_version" {
crypto_key = data.google_kms_key.my_key.self_link
crypto_key = data.google_kms_key.my_key.id
}
```

## Argument Reference

The following arguments are supported:

* `crypto_key` - (Required) The `self_link` of the Google Cloud Platform CryptoKey to which the key version belongs.
* `crypto_key` - (Required) The `self_link` of the Google Cloud Platform CryptoKey to which the key version belongs. This is also the `id` field of the
`google_kms_crypto_key` resource/datasource.

* `version` - (Optional) The version number for this CryptoKeyVersion. Defaults to `1`.

Expand All @@ -49,6 +50,8 @@ exported:

* `id` - an identifier for the resource with format `//cloudkms.googleapis.com/v1/{{crypto_key}}/cryptoKeyVersions/{{version}}`

* `name` - The resource name for this CryptoKeyVersion in the format `projects/*/locations/*/keyRings/*/cryptoKeys/*/cryptoKeyVersions/*`

* `state` - The current state of the CryptoKeyVersion. See the [state reference](https://cloud.google.com/kms/docs/reference/rest/v1/projects.locations.keyRings.cryptoKeys.cryptoKeyVersions#CryptoKeyVersion.CryptoKeyVersionState) for possible outputs.

* `protection_level` - The ProtectionLevel describing how crypto operations are performed with this CryptoKeyVersion. See the [protection_level reference](https://cloud.google.com/kms/docs/reference/rest/v1/ProtectionLevel) for possible outputs.
Expand Down

0 comments on commit aaceb3b

Please sign in to comment.