Skip to content

Commit bb4697d

Browse files
modular-magicianchrisst
authored andcommitted
Make Disk KMS features GA (#2884)
<!-- This change is generated by MagicModules. --> /cc @chrisst
1 parent 411bf08 commit bb4697d

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

google/resource_compute_disk.go

+69
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ func resourceComputeDisk() *schema.Resource {
270270
MaxItems: 1,
271271
Elem: &schema.Resource{
272272
Schema: map[string]*schema.Schema{
273+
"kms_key_self_link": {
274+
Type: schema.TypeString,
275+
Optional: true,
276+
ForceNew: true,
277+
DiffSuppressFunc: compareSelfLinkRelativePaths,
278+
},
273279
"raw_key": {
274280
Type: schema.TypeString,
275281
Optional: true,
@@ -311,6 +317,12 @@ func resourceComputeDisk() *schema.Resource {
311317
MaxItems: 1,
312318
Elem: &schema.Resource{
313319
Schema: map[string]*schema.Schema{
320+
"kms_key_self_link": {
321+
Type: schema.TypeString,
322+
Optional: true,
323+
ForceNew: true,
324+
DiffSuppressFunc: compareSelfLinkRelativePaths,
325+
},
314326
"raw_key": {
315327
Type: schema.TypeString,
316328
Optional: true,
@@ -330,6 +342,12 @@ func resourceComputeDisk() *schema.Resource {
330342
MaxItems: 1,
331343
Elem: &schema.Resource{
332344
Schema: map[string]*schema.Schema{
345+
"kms_key_self_link": {
346+
Type: schema.TypeString,
347+
Optional: true,
348+
ForceNew: true,
349+
DiffSuppressFunc: compareSelfLinkRelativePaths,
350+
},
333351
"raw_key": {
334352
Type: schema.TypeString,
335353
Optional: true,
@@ -899,6 +917,8 @@ func flattenComputeDiskSourceImageEncryptionKey(v interface{}, d *schema.Resourc
899917
flattenComputeDiskSourceImageEncryptionKeyRawKey(original["rawKey"], d)
900918
transformed["sha256"] =
901919
flattenComputeDiskSourceImageEncryptionKeySha256(original["sha256"], d)
920+
transformed["kms_key_self_link"] =
921+
flattenComputeDiskSourceImageEncryptionKeyKmsKeySelfLink(original["kmsKeyName"], d)
902922
return []interface{}{transformed}
903923
}
904924
func flattenComputeDiskSourceImageEncryptionKeyRawKey(v interface{}, d *schema.ResourceData) interface{} {
@@ -909,6 +929,10 @@ func flattenComputeDiskSourceImageEncryptionKeySha256(v interface{}, d *schema.R
909929
return v
910930
}
911931

932+
func flattenComputeDiskSourceImageEncryptionKeyKmsKeySelfLink(v interface{}, d *schema.ResourceData) interface{} {
933+
return v
934+
}
935+
912936
func flattenComputeDiskSourceImageId(v interface{}, d *schema.ResourceData) interface{} {
913937
return v
914938
}
@@ -926,6 +950,8 @@ func flattenComputeDiskDiskEncryptionKey(v interface{}, d *schema.ResourceData)
926950
flattenComputeDiskDiskEncryptionKeyRawKey(original["rawKey"], d)
927951
transformed["sha256"] =
928952
flattenComputeDiskDiskEncryptionKeySha256(original["sha256"], d)
953+
transformed["kms_key_self_link"] =
954+
flattenComputeDiskDiskEncryptionKeyKmsKeySelfLink(original["kmsKeyName"], d)
929955
return []interface{}{transformed}
930956
}
931957
func flattenComputeDiskDiskEncryptionKeyRawKey(v interface{}, d *schema.ResourceData) interface{} {
@@ -936,6 +962,10 @@ func flattenComputeDiskDiskEncryptionKeySha256(v interface{}, d *schema.Resource
936962
return v
937963
}
938964

965+
func flattenComputeDiskDiskEncryptionKeyKmsKeySelfLink(v interface{}, d *schema.ResourceData) interface{} {
966+
return v
967+
}
968+
939969
func flattenComputeDiskSnapshot(v interface{}, d *schema.ResourceData) interface{} {
940970
if v == nil {
941971
return v
@@ -954,6 +984,8 @@ func flattenComputeDiskSourceSnapshotEncryptionKey(v interface{}, d *schema.Reso
954984
transformed := make(map[string]interface{})
955985
transformed["raw_key"] =
956986
flattenComputeDiskSourceSnapshotEncryptionKeyRawKey(original["rawKey"], d)
987+
transformed["kms_key_self_link"] =
988+
flattenComputeDiskSourceSnapshotEncryptionKeyKmsKeySelfLink(original["kmsKeyName"], d)
957989
transformed["sha256"] =
958990
flattenComputeDiskSourceSnapshotEncryptionKeySha256(original["sha256"], d)
959991
return []interface{}{transformed}
@@ -962,6 +994,10 @@ func flattenComputeDiskSourceSnapshotEncryptionKeyRawKey(v interface{}, d *schem
962994
return v
963995
}
964996

997+
func flattenComputeDiskSourceSnapshotEncryptionKeyKmsKeySelfLink(v interface{}, d *schema.ResourceData) interface{} {
998+
return v
999+
}
1000+
9651001
func flattenComputeDiskSourceSnapshotEncryptionKeySha256(v interface{}, d *schema.ResourceData) interface{} {
9661002
return v
9671003
}
@@ -1040,6 +1076,13 @@ func expandComputeDiskSourceImageEncryptionKey(v interface{}, d *schema.Resource
10401076
transformed["sha256"] = transformedSha256
10411077
}
10421078

1079+
transformedKmsKeySelfLink, err := expandComputeDiskSourceImageEncryptionKeyKmsKeySelfLink(original["kms_key_self_link"], d, config)
1080+
if err != nil {
1081+
return nil, err
1082+
} else if val := reflect.ValueOf(transformedKmsKeySelfLink); val.IsValid() && !isEmptyValue(val) {
1083+
transformed["kmsKeyName"] = transformedKmsKeySelfLink
1084+
}
1085+
10431086
return transformed, nil
10441087
}
10451088

@@ -1051,6 +1094,10 @@ func expandComputeDiskSourceImageEncryptionKeySha256(v interface{}, d *schema.Re
10511094
return v, nil
10521095
}
10531096

1097+
func expandComputeDiskSourceImageEncryptionKeyKmsKeySelfLink(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
1098+
return v, nil
1099+
}
1100+
10541101
func expandComputeDiskDiskEncryptionKey(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
10551102
l := v.([]interface{})
10561103
if len(l) == 0 || l[0] == nil {
@@ -1074,6 +1121,13 @@ func expandComputeDiskDiskEncryptionKey(v interface{}, d *schema.ResourceData, c
10741121
transformed["sha256"] = transformedSha256
10751122
}
10761123

1124+
transformedKmsKeySelfLink, err := expandComputeDiskDiskEncryptionKeyKmsKeySelfLink(original["kms_key_self_link"], d, config)
1125+
if err != nil {
1126+
return nil, err
1127+
} else if val := reflect.ValueOf(transformedKmsKeySelfLink); val.IsValid() && !isEmptyValue(val) {
1128+
transformed["kmsKeyName"] = transformedKmsKeySelfLink
1129+
}
1130+
10771131
return transformed, nil
10781132
}
10791133

@@ -1085,6 +1139,10 @@ func expandComputeDiskDiskEncryptionKeySha256(v interface{}, d *schema.ResourceD
10851139
return v, nil
10861140
}
10871141

1142+
func expandComputeDiskDiskEncryptionKeyKmsKeySelfLink(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
1143+
return v, nil
1144+
}
1145+
10881146
func expandComputeDiskSnapshot(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
10891147
f, err := parseGlobalFieldValue("snapshots", v.(string), "project", d, config, true)
10901148
if err != nil {
@@ -1109,6 +1167,13 @@ func expandComputeDiskSourceSnapshotEncryptionKey(v interface{}, d *schema.Resou
11091167
transformed["rawKey"] = transformedRawKey
11101168
}
11111169

1170+
transformedKmsKeySelfLink, err := expandComputeDiskSourceSnapshotEncryptionKeyKmsKeySelfLink(original["kms_key_self_link"], d, config)
1171+
if err != nil {
1172+
return nil, err
1173+
} else if val := reflect.ValueOf(transformedKmsKeySelfLink); val.IsValid() && !isEmptyValue(val) {
1174+
transformed["kmsKeyName"] = transformedKmsKeySelfLink
1175+
}
1176+
11121177
transformedSha256, err := expandComputeDiskSourceSnapshotEncryptionKeySha256(original["sha256"], d, config)
11131178
if err != nil {
11141179
return nil, err
@@ -1123,6 +1188,10 @@ func expandComputeDiskSourceSnapshotEncryptionKeyRawKey(v interface{}, d *schema
11231188
return v, nil
11241189
}
11251190

1191+
func expandComputeDiskSourceSnapshotEncryptionKeyKmsKeySelfLink(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
1192+
return v, nil
1193+
}
1194+
11261195
func expandComputeDiskSourceSnapshotEncryptionKeySha256(v interface{}, d *schema.ResourceData, config *Config) (interface{}, error) {
11271196
return v, nil
11281197
}

website/docs/r/compute_disk.html.markdown

+21
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ The `source_image_encryption_key` block supports:
175175
The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied
176176
encryption key that protects this resource.
177177

178+
* `kms_key_self_link` -
179+
(Optional)
180+
The self link of the encryption key used to encrypt the disk. Also called KmsKeyName
181+
in the cloud console. In order to use this additional
182+
IAM permissions need to be set on the Compute Engine Service Agent. See
183+
https://cloud.google.com/compute/docs/disks/customer-managed-encryption#encrypt_a_new_persistent_disk_with_your_own_keys
184+
178185
The `disk_encryption_key` block supports:
179186

180187
* `raw_key` -
@@ -186,13 +193,27 @@ The `disk_encryption_key` block supports:
186193
The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied
187194
encryption key that protects this resource.
188195

196+
* `kms_key_self_link` -
197+
(Optional)
198+
The self link of the encryption key used to encrypt the disk. Also called KmsKeyName
199+
in the cloud console. In order to use this additional
200+
IAM permissions need to be set on the Compute Engine Service Agent. See
201+
https://cloud.google.com/compute/docs/disks/customer-managed-encryption#encrypt_a_new_persistent_disk_with_your_own_keys
202+
189203
The `source_snapshot_encryption_key` block supports:
190204

191205
* `raw_key` -
192206
(Optional)
193207
Specifies a 256-bit customer-supplied encryption key, encoded in
194208
RFC 4648 base64 to either encrypt or decrypt this resource.
195209

210+
* `kms_key_self_link` -
211+
(Optional)
212+
The self link of the encryption key used to encrypt the disk. Also called KmsKeyName
213+
in the cloud console. In order to use this additional
214+
IAM permissions need to be set on the Compute Engine Service Agent. See
215+
https://cloud.google.com/compute/docs/disks/customer-managed-encryption#encrypt_a_new_persistent_disk_with_your_own_keys
216+
196217
* `sha256` -
197218
The RFC 4648 base64 encoded SHA-256 hash of the customer-supplied
198219
encryption key that protects this resource.

0 commit comments

Comments
 (0)