Skip to content

Commit 2a1b1ab

Browse files
Added missing KMS fields to instance_template resources (#13241) (#22503)
[upstream:923b7b9dde0b7085fcccf3c7dc1e2542aad4a068] Signed-off-by: Modular Magician <[email protected]>
1 parent 1d46236 commit 2a1b1ab

7 files changed

+748
-30
lines changed

.changelog/13241.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: Added fields like `raw_key`, `rsa_encrypted_key`, `kms_key_service_account` to all relevant resources on `google_compute_instance_template` and `google_compute_region_instance_template`
3+
```

google/services/compute/resource_compute_instance_template.go

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,20 @@ images are encrypted with your own keys.`,
215215
MaxItems: 1,
216216
Elem: &schema.Resource{
217217
Schema: map[string]*schema.Schema{
218+
"raw_key": {
219+
Type: schema.TypeString,
220+
Optional: true,
221+
ForceNew: true,
222+
Description: `Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource. Only one of kms_key_self_link, rsa_encrypted_key and raw_key may be set.`,
223+
Sensitive: true,
224+
},
225+
"rsa_encrypted_key": {
226+
Type: schema.TypeString,
227+
Optional: true,
228+
ForceNew: true,
229+
Description: `Specifies an RFC 4648 base64 encoded, RSA-wrapped 2048-bit customer-supplied encryption key to either encrypt or decrypt this resource. Only one of kms_key_self_link, rsa_encrypted_key and raw_key may be set.`,
230+
Sensitive: true,
231+
},
218232
"kms_key_service_account": {
219233
Type: schema.TypeString,
220234
Optional: true,
@@ -225,10 +239,10 @@ Engine default service account is used.`,
225239
},
226240
"kms_key_self_link": {
227241
Type: schema.TypeString,
228-
Required: true,
242+
Optional: true,
229243
ForceNew: true,
230244
Description: `The self link of the encryption key that is stored in
231-
Google Cloud KMS.`,
245+
Google Cloud KMS. Only one of kms_key_self_link, rsa_encrypted_key and raw_key may be set.`,
232246
},
233247
},
234248
},
@@ -250,6 +264,21 @@ required except for local SSD.`,
250264
MaxItems: 1,
251265
Elem: &schema.Resource{
252266
Schema: map[string]*schema.Schema{
267+
"raw_key": {
268+
Type: schema.TypeString,
269+
Optional: true,
270+
ForceNew: true,
271+
Description: `Specifies a 256-bit customer-supplied encryption key, encoded in RFC 4648 base64 to either encrypt or decrypt this resource. Only one of kms_key_self_link, rsa_encrypted_key and raw_key may be set.`,
272+
Sensitive: true,
273+
},
274+
275+
"rsa_encrypted_key": {
276+
Type: schema.TypeString,
277+
Optional: true,
278+
ForceNew: true,
279+
Description: `Specifies an RFC 4648 base64 encoded, RSA-wrapped 2048-bit customer-supplied encryption key to either encrypt or decrypt this resource. Only one of kms_key_self_link, rsa_encrypted_key and raw_key may be set.`,
280+
Sensitive: true,
281+
},
253282
"kms_key_service_account": {
254283
Type: schema.TypeString,
255284
Optional: true,
@@ -260,10 +289,10 @@ Engine default service account is used.`,
260289
},
261290
"kms_key_self_link": {
262291
Type: schema.TypeString,
263-
Required: true,
292+
Optional: true,
264293
ForceNew: true,
265294
Description: `The self link of the encryption key that is stored in
266-
Google Cloud KMS.`,
295+
Google Cloud KMS. Only one of kms_key_self_link, rsa_encrypted_key and raw_key may be set.`,
267296
},
268297
},
269298
},
@@ -308,9 +337,15 @@ Google Cloud KMS.`,
308337
Description: `Encrypts or decrypts a disk using a customer-supplied encryption key.`,
309338
Elem: &schema.Resource{
310339
Schema: map[string]*schema.Schema{
340+
"kms_key_service_account": {
341+
Type: schema.TypeString,
342+
Optional: true,
343+
ForceNew: true,
344+
Description: `The service account being used for the encryption request for the given KMS key. If absent, the Compute Engine default service account is used.`,
345+
},
311346
"kms_key_self_link": {
312347
Type: schema.TypeString,
313-
Required: true,
348+
Optional: true,
314349
ForceNew: true,
315350
DiffSuppressFunc: tpgresource.CompareSelfLinkRelativePaths,
316351
Description: `The self link of the encryption key that is stored in Google Cloud KMS.`,
@@ -1234,6 +1269,9 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
12341269
if v, ok := d.GetOk(prefix + ".disk_encryption_key.0.kms_key_self_link"); ok {
12351270
disk.DiskEncryptionKey.KmsKeyName = v.(string)
12361271
}
1272+
if v, ok := d.GetOk(prefix + ".disk_encryption_key.0.kms_key_service_account"); ok {
1273+
disk.DiskEncryptionKey.KmsKeyServiceAccount = v.(string)
1274+
}
12371275
}
12381276
// Assign disk.DiskSizeGb and disk.InitializeParams.DiskSizeGb the same value
12391277
if v, ok := d.GetOk(prefix + ".disk_size_gb"); ok {
@@ -1285,6 +1323,12 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
12851323

12861324
if _, ok := d.GetOk(prefix + ".source_image_encryption_key"); ok {
12871325
disk.InitializeParams.SourceImageEncryptionKey = &compute.CustomerEncryptionKey{}
1326+
if v, ok := d.GetOk(prefix + ".source_image_encryption_key.0.raw_key"); ok {
1327+
disk.InitializeParams.SourceImageEncryptionKey.RawKey = v.(string)
1328+
}
1329+
if v, ok := d.GetOk(prefix + ".source_image_encryption_key.0.rsa_encrypted_key"); ok {
1330+
disk.InitializeParams.SourceImageEncryptionKey.RsaEncryptedKey = v.(string)
1331+
}
12881332
if v, ok := d.GetOk(prefix + ".source_image_encryption_key.0.kms_key_self_link"); ok {
12891333
disk.InitializeParams.SourceImageEncryptionKey.KmsKeyName = v.(string)
12901334
}
@@ -1299,6 +1343,12 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput
12991343

13001344
if _, ok := d.GetOk(prefix + ".source_snapshot_encryption_key"); ok {
13011345
disk.InitializeParams.SourceSnapshotEncryptionKey = &compute.CustomerEncryptionKey{}
1346+
if v, ok := d.GetOk(prefix + ".source_snapshot_encryption_key.0.raw_key"); ok {
1347+
disk.InitializeParams.SourceSnapshotEncryptionKey.RawKey = v.(string)
1348+
}
1349+
if v, ok := d.GetOk(prefix + ".source_snapshot_encryption_key.0.rsa_encrypted_key"); ok {
1350+
disk.InitializeParams.SourceSnapshotEncryptionKey.RsaEncryptedKey = v.(string)
1351+
}
13021352
if v, ok := d.GetOk(prefix + ".source_snapshot_encryption_key.0.kms_key_self_link"); ok {
13031353
disk.InitializeParams.SourceSnapshotEncryptionKey.KmsKeyName = v.(string)
13041354
}
@@ -1572,6 +1622,13 @@ func flattenDisk(disk *compute.AttachedDisk, configDisk map[string]any, defaultP
15721622
encryption := make([]map[string]interface{}, 1)
15731623
encryption[0] = make(map[string]interface{})
15741624
encryption[0]["kms_key_self_link"] = disk.DiskEncryptionKey.KmsKeyName
1625+
if diskEncryptionKey, ok := configDisk["disk_encryption_key"].([]interface{}); ok && len(diskEncryptionKey) > 0 {
1626+
if encryptionKeyMap, ok := diskEncryptionKey[0].(map[string]interface{}); ok {
1627+
if kmsSa, ok := encryptionKeyMap["kms_key_service_account"].(string); ok && kmsSa != "" {
1628+
encryption[0]["kms_key_service_account"] = kmsSa
1629+
}
1630+
}
1631+
}
15751632
diskMap["disk_encryption_key"] = encryption
15761633
}
15771634

0 commit comments

Comments
 (0)