Skip to content

Commit

Permalink
Merge pull request #19 from modular-magician/codegen-pr-569
Browse files Browse the repository at this point in the history
Magic Modules changes.
  • Loading branch information
chrisst authored Oct 20, 2018
2 parents 7fea703 + c3baaf1 commit 9b068f3
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 14 deletions.
84 changes: 84 additions & 0 deletions google-beta/resource_compute_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ func resourceComputeDisk() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kms_key_self_link": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkRelativePaths,
},
"raw_key": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -310,6 +316,12 @@ func resourceComputeDisk() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kms_key_self_link": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkRelativePaths,
},
"raw_key": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -329,6 +341,12 @@ func resourceComputeDisk() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"kms_key_self_link": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: compareSelfLinkRelativePaths,
},
"raw_key": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -918,6 +936,8 @@ func flattenComputeDiskSourceImageEncryptionKey(v interface{}) interface{} {
flattenComputeDiskSourceImageEncryptionKeyRawKey(original["rawKey"])
transformed["sha256"] =
flattenComputeDiskSourceImageEncryptionKeySha256(original["sha256"])
transformed["kms_key_self_link"] =
flattenComputeDiskSourceImageEncryptionKeyKmsKeySelfLink(original["kmsKeyName"])
return []interface{}{transformed}
}
func flattenComputeDiskSourceImageEncryptionKeyRawKey(v interface{}) interface{} {
Expand All @@ -928,6 +948,10 @@ func flattenComputeDiskSourceImageEncryptionKeySha256(v interface{}) interface{}
return v
}

func flattenComputeDiskSourceImageEncryptionKeyKmsKeySelfLink(v interface{}) interface{} {
return v
}

func flattenComputeDiskSourceImageId(v interface{}) interface{} {
return v
}
Expand All @@ -942,6 +966,8 @@ func flattenComputeDiskDiskEncryptionKey(v interface{}) interface{} {
flattenComputeDiskDiskEncryptionKeyRawKey(original["rawKey"])
transformed["sha256"] =
flattenComputeDiskDiskEncryptionKeySha256(original["sha256"])
transformed["kms_key_self_link"] =
flattenComputeDiskDiskEncryptionKeyKmsKeySelfLink(original["kmsKeyName"])
return []interface{}{transformed}
}
func flattenComputeDiskDiskEncryptionKeyRawKey(v interface{}) interface{} {
Expand All @@ -952,6 +978,10 @@ func flattenComputeDiskDiskEncryptionKeySha256(v interface{}) interface{} {
return v
}

func flattenComputeDiskDiskEncryptionKeyKmsKeySelfLink(v interface{}) interface{} {
return v
}

func flattenComputeDiskSnapshot(v interface{}) interface{} {
if v == nil {
return v
Expand All @@ -967,6 +997,8 @@ func flattenComputeDiskSourceSnapshotEncryptionKey(v interface{}) interface{} {
transformed := make(map[string]interface{})
transformed["raw_key"] =
flattenComputeDiskSourceSnapshotEncryptionKeyRawKey(original["rawKey"])
transformed["kms_key_self_link"] =
flattenComputeDiskSourceSnapshotEncryptionKeyKmsKeySelfLink(original["kmsKeyName"])
transformed["sha256"] =
flattenComputeDiskSourceSnapshotEncryptionKeySha256(original["sha256"])
return []interface{}{transformed}
Expand All @@ -975,6 +1007,10 @@ func flattenComputeDiskSourceSnapshotEncryptionKeyRawKey(v interface{}) interfac
return v
}

func flattenComputeDiskSourceSnapshotEncryptionKeyKmsKeySelfLink(v interface{}) interface{} {
return v
}

func flattenComputeDiskSourceSnapshotEncryptionKeySha256(v interface{}) interface{} {
return v
}
Expand Down Expand Up @@ -1053,6 +1089,13 @@ func expandComputeDiskSourceImageEncryptionKey(v interface{}, d *schema.Resource
transformed["sha256"] = transformedSha256
}

transformedKmsKeySelfLink, err := expandComputeDiskSourceImageEncryptionKeyKmsKeySelfLink(original["kms_key_self_link"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedKmsKeySelfLink); val.IsValid() && !isEmptyValue(val) {
transformed["kmsKeyName"] = transformedKmsKeySelfLink
}

return transformed, nil
}

Expand All @@ -1064,6 +1107,10 @@ func expandComputeDiskSourceImageEncryptionKeySha256(v interface{}, d *schema.Re
return v, nil
}

func expandComputeDiskSourceImageEncryptionKeyKmsKeySelfLink(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeDiskDiskEncryptionKey(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand All @@ -1087,6 +1134,13 @@ func expandComputeDiskDiskEncryptionKey(v interface{}, d *schema.ResourceData, c
transformed["sha256"] = transformedSha256
}

transformedKmsKeySelfLink, err := expandComputeDiskDiskEncryptionKeyKmsKeySelfLink(original["kms_key_self_link"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedKmsKeySelfLink); val.IsValid() && !isEmptyValue(val) {
transformed["kmsKeyName"] = transformedKmsKeySelfLink
}

return transformed, nil
}

Expand All @@ -1098,6 +1152,10 @@ func expandComputeDiskDiskEncryptionKeySha256(v interface{}, d *schema.ResourceD
return v, nil
}

func expandComputeDiskDiskEncryptionKeyKmsKeySelfLink(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeDiskSnapshot(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("snapshots", v.(string), "project", d, config, true)
if err != nil {
Expand All @@ -1122,6 +1180,13 @@ func expandComputeDiskSourceSnapshotEncryptionKey(v interface{}, d *schema.Resou
transformed["rawKey"] = transformedRawKey
}

transformedKmsKeySelfLink, err := expandComputeDiskSourceSnapshotEncryptionKeyKmsKeySelfLink(original["kms_key_self_link"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedKmsKeySelfLink); val.IsValid() && !isEmptyValue(val) {
transformed["kmsKeyName"] = transformedKmsKeySelfLink
}

transformedSha256, err := expandComputeDiskSourceSnapshotEncryptionKeySha256(original["sha256"], d, config)
if err != nil {
return nil, err
Expand All @@ -1136,6 +1201,10 @@ func expandComputeDiskSourceSnapshotEncryptionKeyRawKey(v interface{}, d *schema
return v, nil
}

func expandComputeDiskSourceSnapshotEncryptionKeyKmsKeySelfLink(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeDiskSourceSnapshotEncryptionKeySha256(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -1211,6 +1280,11 @@ func resourceComputeDiskDecoder(d *schema.ResourceData, meta interface{}, res ma
// The raw key won't be returned, so we need to use the original.
transformed["rawKey"] = d.Get("disk_encryption_key.0.raw_key")
transformed["sha256"] = original["sha256"]

// The response for crypto keys often includes the version of the key which needs to be removed
// format: projects/<project>/locations/<region>/keyRings/<keyring>/cryptoKeys/<key>/cryptoKeyVersions/1
transformed["kmsKeyName"] = strings.Split(original["kmsKeyName"].(string), "/cryptoKeyVersions")[0]

res["diskEncryptionKey"] = transformed
}

Expand All @@ -1220,6 +1294,11 @@ func resourceComputeDiskDecoder(d *schema.ResourceData, meta interface{}, res ma
// The raw key won't be returned, so we need to use the original.
transformed["rawKey"] = d.Get("source_image_encryption_key.0.raw_key")
transformed["sha256"] = original["sha256"]

// The response for crypto keys often includes the version of the key which needs to be removed
// format: projects/<project>/locations/<region>/keyRings/<keyring>/cryptoKeys/<key>/cryptoKeyVersions/1
transformed["kmsKeyName"] = strings.Split(original["kmsKeyName"].(string), "/cryptoKeyVersions")[0]

res["sourceImageEncryptionKey"] = transformed
}

Expand All @@ -1229,6 +1308,11 @@ func resourceComputeDiskDecoder(d *schema.ResourceData, meta interface{}, res ma
// The raw key won't be returned, so we need to use the original.
transformed["rawKey"] = d.Get("source_snapshot_encryption_key.0.raw_key")
transformed["sha256"] = original["sha256"]

// The response for crypto keys often includes the version of the key which needs to be removed
// format: projects/<project>/locations/<region>/keyRings/<keyring>/cryptoKeys/<key>/cryptoKeyVersions/1
transformed["kmsKeyName"] = strings.Split(original["kmsKeyName"].(string), "/cryptoKeyVersions")[0]

res["sourceSnapshotEncryptionKey"] = transformed
}

Expand Down
Loading

0 comments on commit 9b068f3

Please sign in to comment.