Fix GCP HCL image_encryption_key fields and use the same casing in JSON and HCL2

this closes #9997
This commit is contained in:
Adrien Delorme 2020-10-27 15:46:45 +01:00
parent c4866504e1
commit ef32147a4a
4 changed files with 27 additions and 8 deletions

View File

@ -87,13 +87,19 @@ type Config struct {
// * kmsKeyName - The name of the encryption key that is stored in Google Cloud KMS.
// * RawKey: - A 256-bit customer-supplied encryption key, encodes in RFC 4648 base64.
//
// example:
// examples:
//
// ```json
// {
// "kmsKeyName": "projects/${project}/locations/${region}/keyRings/computeEngine/cryptoKeys/computeEngine/cryptoKeyVersions/4"
// }
// ```
//
// ```hcl
// image_encryption_key {
// kmsKeyName = "projects/${var.project}/locations/${var.region}/keyRings/computeEngine/cryptoKeys/computeEngine/cryptoKeyVersions/4"
// }
// ```
ImageEncryptionKey *CustomerEncryptionKey `mapstructure:"image_encryption_key" required:"false"`
// The name of the image family to which the resulting image belongs. You
// can create disks by specifying an image family instead of a specific
@ -539,11 +545,11 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
type CustomerEncryptionKey struct {
// KmsKeyName: The name of the encryption key that is stored in Google
// Cloud KMS.
KmsKeyName string `json:"kmsKeyName,omitempty"`
KmsKeyName string `mapstructure:"kmsKeyName" json:"kmsKeyName,omitempty"`
// RawKey: Specifies a 256-bit customer-supplied encryption key, encoded
// in RFC 4648 base64 to either encrypt or decrypt this resource.
RawKey string `json:"rawKey,omitempty"`
RawKey string `mapstructure:"rawKey" json:"rawKey,omitempty"`
}
func (k *CustomerEncryptionKey) ComputeType() *compute.CustomerEncryptionKey {

View File

@ -242,8 +242,8 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
// FlatCustomerEncryptionKey is an auto-generated flat version of CustomerEncryptionKey.
// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up.
type FlatCustomerEncryptionKey struct {
KmsKeyName *string `json:"kmsKeyName,omitempty" cty:"kms_key_name" hcl:"kms_key_name"`
RawKey *string `json:"rawKey,omitempty" cty:"raw_key" hcl:"raw_key"`
KmsKeyName *string `mapstructure:"kmsKeyName" json:"kmsKeyName,omitempty" cty:"kmsKeyName" hcl:"kmsKeyName"`
RawKey *string `mapstructure:"rawKey" json:"rawKey,omitempty" cty:"rawKey" hcl:"rawKey"`
}
// FlatMapstructure returns a new FlatCustomerEncryptionKey.
@ -258,8 +258,8 @@ func (*CustomerEncryptionKey) FlatMapstructure() interface{ HCL2Spec() map[strin
// The decoded values from this spec will then be applied to a FlatCustomerEncryptionKey.
func (*FlatCustomerEncryptionKey) HCL2Spec() map[string]hcldec.Spec {
s := map[string]hcldec.Spec{
"kms_key_name": &hcldec.AttrSpec{Name: "kms_key_name", Type: cty.String, Required: false},
"raw_key": &hcldec.AttrSpec{Name: "raw_key", Type: cty.String, Required: false},
"kmsKeyName": &hcldec.AttrSpec{Name: "kmsKeyName", Type: cty.String, Required: false},
"rawKey": &hcldec.AttrSpec{Name: "rawKey", Type: cty.String, Required: false},
}
return s
}

View File

@ -53,7 +53,7 @@
* kmsKeyName - The name of the encryption key that is stored in Google Cloud KMS.
* RawKey: - A 256-bit customer-supplied encryption key, encodes in RFC 4648 base64.
example:
examples:
```json
{
@ -61,6 +61,12 @@
}
```
```hcl
image_encryption_key {
kmsKeyName = "projects/${var.project}/locations/${var.region}/keyRings/computeEngine/cryptoKeys/computeEngine/cryptoKeyVersions/4"
}
```
- `image_family` (string) - The name of the image family to which the resulting image belongs. You
can create disks by specifying an image family instead of a specific
image name. The image family always returns its latest image that is not

View File

@ -0,0 +1,7 @@
<!-- Code generated from the comments of the CustomerEncryptionKey struct in builder/googlecompute/config.go; DO NOT EDIT MANUALLY -->
- `kmsKeyName` (string) - KmsKeyName: The name of the encryption key that is stored in Google
Cloud KMS.
- `rawKey` (string) - RawKey: Specifies a 256-bit customer-supplied encryption key, encoded
in RFC 4648 base64 to either encrypt or decrypt this resource.