terraform-provider-google/google/data_source_google_kms_crypto_key.go
The Magician 30fe927df6 Data Sources for KMS Key Ring and Key (#2891)
<!-- This change is generated by MagicModules. -->
/cc @kierachell
2019-01-17 16:12:22 -08:00

36 lines
803 B
Go

package google
import (
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceGoogleKmsCryptoKey() *schema.Resource {
dsSchema := datasourceSchemaFromResourceSchema(resourceKmsCryptoKey().Schema)
addRequiredFieldsToSchema(dsSchema, "name")
addRequiredFieldsToSchema(dsSchema, "key_ring")
return &schema.Resource{
Read: dataSourceGoogleKmsCryptoKeyRead,
Schema: dsSchema,
}
}
func dataSourceGoogleKmsCryptoKeyRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
keyRingId, err := parseKmsKeyRingId(d.Get("key_ring").(string), config)
if err != nil {
return err
}
cryptoKeyId := kmsCryptoKeyId{
KeyRingId: *keyRingId,
Name: d.Get("name").(string),
}
d.SetId(cryptoKeyId.cryptoKeyId())
return resourceKmsCryptoKeyRead(d, meta)
}