Skip to content

Commit ec2eda3

Browse files
Add KMS fields to google_compute_image (#13259) (#9730)
[upstream:2e4efd5ebf20bc025f5d213484773e6f61b1458c] Signed-off-by: Modular Magician <[email protected]>
1 parent 81a7911 commit ec2eda3

9 files changed

+834
-5
lines changed

.changelog/13259.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
compute: added `source_disk_encryption_key`, `source_image_encryption_key` and `source_snapshot_encryption_key` to `google_compute_image`
3+
```
4+
5+
```release-note:enhancement
6+
compute: added `source_disk_encryption_key.kms_key_self_link` and `source_disk_encryption_key.rsa_encrypted_key` to `google_compute_snapshot`
7+
```

google-beta/services/compute/resource_compute_image.go

+330
Large diffs are not rendered by default.

google-beta/services/compute/resource_compute_image_generated_meta.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,23 @@ fields:
3535
- field: 'shielded_instance_initial_state.pk.content'
3636
- field: 'shielded_instance_initial_state.pk.file_type'
3737
- field: 'source_disk'
38+
- field: 'source_disk_encryption_key.kms_key_self_link'
39+
api_field: 'source_disk_encryption_key.kms_key_name'
40+
- field: 'source_disk_encryption_key.kms_key_service_account'
41+
- field: 'source_disk_encryption_key.raw_key'
42+
- field: 'source_disk_encryption_key.rsa_encrypted_key'
3843
- field: 'source_image'
44+
- field: 'source_image_encryption_key.kms_key_self_link'
45+
api_field: 'source_image_encryption_key.kms_key_name'
46+
- field: 'source_image_encryption_key.kms_key_service_account'
47+
- field: 'source_image_encryption_key.raw_key'
48+
- field: 'source_image_encryption_key.rsa_encrypted_key'
3949
- field: 'source_snapshot'
50+
- field: 'source_snapshot_encryption_key.kms_key_self_link'
51+
api_field: 'source_snapshot_encryption_key.kms_key_name'
52+
- field: 'source_snapshot_encryption_key.kms_key_service_account'
53+
- field: 'source_snapshot_encryption_key.raw_key'
54+
- field: 'source_snapshot_encryption_key.rsa_encrypted_key'
4055
- field: 'storage_locations'
4156
- field: 'terraform_labels'
4257
provider_only: true

google-beta/services/compute/resource_compute_image_generated_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestAccComputeImage_imageBasicExample(t *testing.T) {
4949
ResourceName: "google_compute_image.example",
5050
ImportState: true,
5151
ImportStateVerify: true,
52-
ImportStateVerifyIgnore: []string{"image_encryption_key.0.raw_key", "image_encryption_key.0.rsa_encrypted_key", "labels", "raw_disk", "source_disk", "source_image", "source_snapshot", "terraform_labels"},
52+
ImportStateVerifyIgnore: []string{"image_encryption_key.0.raw_key", "image_encryption_key.0.rsa_encrypted_key", "labels", "raw_disk", "source_disk", "source_disk_encryption_key", "source_image", "source_image_encryption_key", "source_snapshot", "source_snapshot_encryption_key", "terraform_labels"},
5353
},
5454
},
5555
})
@@ -97,7 +97,7 @@ func TestAccComputeImage_imageGuestOsExample(t *testing.T) {
9797
ResourceName: "google_compute_image.example",
9898
ImportState: true,
9999
ImportStateVerify: true,
100-
ImportStateVerifyIgnore: []string{"image_encryption_key.0.raw_key", "image_encryption_key.0.rsa_encrypted_key", "labels", "raw_disk", "source_disk", "source_image", "source_snapshot", "terraform_labels"},
100+
ImportStateVerifyIgnore: []string{"image_encryption_key.0.raw_key", "image_encryption_key.0.rsa_encrypted_key", "labels", "raw_disk", "source_disk", "source_disk_encryption_key", "source_image", "source_image_encryption_key", "source_snapshot", "source_snapshot_encryption_key", "terraform_labels"},
101101
},
102102
},
103103
})
@@ -165,7 +165,7 @@ func TestAccComputeImage_imageBasicStorageLocationExample(t *testing.T) {
165165
ResourceName: "google_compute_image.example",
166166
ImportState: true,
167167
ImportStateVerify: true,
168-
ImportStateVerifyIgnore: []string{"image_encryption_key.0.raw_key", "image_encryption_key.0.rsa_encrypted_key", "labels", "raw_disk", "source_disk", "source_image", "source_snapshot", "terraform_labels"},
168+
ImportStateVerifyIgnore: []string{"image_encryption_key.0.raw_key", "image_encryption_key.0.rsa_encrypted_key", "labels", "raw_disk", "source_disk", "source_disk_encryption_key", "source_image", "source_image_encryption_key", "source_snapshot", "source_snapshot_encryption_key", "terraform_labels"},
169169
},
170170
},
171171
})

google-beta/services/compute/resource_compute_image_test.go

+323
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,72 @@ func TestAccComputeImage_imageEncryptionKey(t *testing.T) {
316316
})
317317
}
318318

319+
func TestAccComputeImage_sourceImageEncryptionKey(t *testing.T) {
320+
t.Parallel()
321+
322+
context := map[string]interface{}{
323+
"random_suffix": acctest.RandString(t, 10),
324+
"kms_key_self_link": acctest.BootstrapKMSKeyInLocation(t, "us-central1").CryptoKey.Name,
325+
"raw_key": "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=",
326+
"rsa_encrypted_key": "fB6BS8tJGhGVDZDjGt1pwUo2wyNbkzNxgH1avfOtiwB9X6oPG94gWgenygitnsYJyKjdOJ7DyXLmxwQOSmnCYCUBWdKCSssyLV5907HL2mb5TfqmgHk5JcArI/t6QADZWiuGtR+XVXqiLa5B9usxFT2BTmbHvSKfkpJ7McCNc/3U0PQR8euFRZ9i75o/w+pLHFMJ05IX3JB0zHbXMV173PjObiV3ItSJm2j3mp5XKabRGSA5rmfMnHIAMz6stGhcuom6+bMri2u/axmPsdxmC6MeWkCkCmPjaKsVz1+uQUNCJkAnzesluhoD+R6VjFDm4WI7yYabu4MOOAOTaQXdEg==",
327+
}
328+
329+
acctest.VcrTest(t, resource.TestCase{
330+
PreCheck: func() { acctest.AccTestPreCheck(t) },
331+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
332+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
333+
Steps: []resource.TestStep{
334+
{
335+
Config: testAccComputeImage_sourceImageEncryptionKey(context),
336+
},
337+
},
338+
})
339+
}
340+
341+
func TestAccComputeImage_sourceSnapshotEncryptionKey(t *testing.T) {
342+
t.Parallel()
343+
344+
context := map[string]interface{}{
345+
"random_suffix": acctest.RandString(t, 10),
346+
"kms_key_self_link": acctest.BootstrapKMSKeyInLocation(t, "us-central1").CryptoKey.Name,
347+
"raw_key": "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=",
348+
"rsa_encrypted_key": "fB6BS8tJGhGVDZDjGt1pwUo2wyNbkzNxgH1avfOtiwB9X6oPG94gWgenygitnsYJyKjdOJ7DyXLmxwQOSmnCYCUBWdKCSssyLV5907HL2mb5TfqmgHk5JcArI/t6QADZWiuGtR+XVXqiLa5B9usxFT2BTmbHvSKfkpJ7McCNc/3U0PQR8euFRZ9i75o/w+pLHFMJ05IX3JB0zHbXMV173PjObiV3ItSJm2j3mp5XKabRGSA5rmfMnHIAMz6stGhcuom6+bMri2u/axmPsdxmC6MeWkCkCmPjaKsVz1+uQUNCJkAnzesluhoD+R6VjFDm4WI7yYabu4MOOAOTaQXdEg==",
349+
}
350+
351+
acctest.VcrTest(t, resource.TestCase{
352+
PreCheck: func() { acctest.AccTestPreCheck(t) },
353+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
354+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
355+
Steps: []resource.TestStep{
356+
{
357+
Config: testAccComputeImage_sourceSnapshotEncryptionKey(context),
358+
},
359+
},
360+
})
361+
}
362+
363+
func TestAccComputeImage_sourceDiskEncryptionKey(t *testing.T) {
364+
t.Parallel()
365+
366+
context := map[string]interface{}{
367+
"random_suffix": acctest.RandString(t, 10),
368+
"kms_key_self_link": acctest.BootstrapKMSKeyInLocation(t, "us-central1").CryptoKey.Name,
369+
"raw_key": "SGVsbG8gZnJvbSBHb29nbGUgQ2xvdWQgUGxhdGZvcm0=",
370+
"rsa_encrypted_key": "fB6BS8tJGhGVDZDjGt1pwUo2wyNbkzNxgH1avfOtiwB9X6oPG94gWgenygitnsYJyKjdOJ7DyXLmxwQOSmnCYCUBWdKCSssyLV5907HL2mb5TfqmgHk5JcArI/t6QADZWiuGtR+XVXqiLa5B9usxFT2BTmbHvSKfkpJ7McCNc/3U0PQR8euFRZ9i75o/w+pLHFMJ05IX3JB0zHbXMV173PjObiV3ItSJm2j3mp5XKabRGSA5rmfMnHIAMz6stGhcuom6+bMri2u/axmPsdxmC6MeWkCkCmPjaKsVz1+uQUNCJkAnzesluhoD+R6VjFDm4WI7yYabu4MOOAOTaQXdEg==",
371+
}
372+
373+
acctest.VcrTest(t, resource.TestCase{
374+
PreCheck: func() { acctest.AccTestPreCheck(t) },
375+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
376+
CheckDestroy: testAccCheckComputeInstanceTemplateDestroyProducer(t),
377+
Steps: []resource.TestStep{
378+
{
379+
Config: testAccComputeImage_sourceDiskEncryptionKey(context),
380+
},
381+
},
382+
})
383+
}
384+
319385
func testAccCheckComputeImageResolution(t *testing.T, n string) resource.TestCheckFunc {
320386
return func(s *terraform.State) error {
321387
config := acctest.GoogleProviderConfig(t)
@@ -719,6 +785,263 @@ resource "google_compute_image" "foobar" {
719785
`, diskName, snapshotName, imageName)
720786
}
721787

788+
func testAccComputeImage_sourceDiskEncryptionKey(context map[string]interface{}) string {
789+
return acctest.Nprintf(`
790+
data "google_compute_image" "debian" {
791+
family = "debian-11"
792+
project = "debian-cloud"
793+
}
794+
795+
resource "google_compute_disk" "src-disk-kms" {
796+
name = "tf-test-src-disk-kms-%{random_suffix}"
797+
image = data.google_compute_image.debian.self_link
798+
size = 10
799+
type = "pd-ssd"
800+
zone = "us-central1-a"
801+
802+
disk_encryption_key {
803+
kms_key_self_link = "%{kms_key_self_link}"
804+
}
805+
}
806+
807+
resource "google_compute_disk" "src-disk-raw" {
808+
name = "tf-test-src-disk-raw-%{random_suffix}"
809+
image = data.google_compute_image.debian.self_link
810+
size = 10
811+
type = "pd-ssd"
812+
zone = "us-central1-a"
813+
814+
disk_encryption_key {
815+
raw_key = "%{raw_key}"
816+
}
817+
}
818+
819+
resource "google_compute_disk" "src-disk-rsa" {
820+
name = "tf-test-src-disk-rsa-%{random_suffix}"
821+
image = data.google_compute_image.debian.self_link
822+
size = 10
823+
type = "pd-ssd"
824+
zone = "us-central1-a"
825+
826+
disk_encryption_key {
827+
rsa_encrypted_key = "%{rsa_encrypted_key}"
828+
}
829+
}
830+
831+
resource "google_compute_image" "foobar-kms" {
832+
name = "tf-test-image-kms-%{random_suffix}"
833+
source_disk = google_compute_disk.src-disk-kms.self_link
834+
source_disk_encryption_key {
835+
kms_key_self_link = "%{kms_key_self_link}"
836+
}
837+
}
838+
839+
resource "google_compute_image" "foobar-raw" {
840+
name = "tf-test-image-raw-%{random_suffix}"
841+
source_disk = google_compute_disk.src-disk-raw.self_link
842+
source_disk_encryption_key {
843+
raw_key = "%{raw_key}"
844+
}
845+
}
846+
847+
resource "google_compute_image" "foobar-rsa" {
848+
name = "tf-test-image-rsa-%{random_suffix}"
849+
source_disk = google_compute_disk.src-disk-rsa.self_link
850+
source_disk_encryption_key {
851+
rsa_encrypted_key = "%{rsa_encrypted_key}"
852+
kms_key_service_account = data.google_compute_default_service_account.default.email
853+
}
854+
}
855+
856+
data "google_compute_default_service_account" "default" {
857+
}
858+
`, context)
859+
}
860+
861+
func testAccComputeImage_sourceImageEncryptionKey(context map[string]interface{}) string {
862+
return acctest.Nprintf(`
863+
data "google_compute_image" "debian" {
864+
family = "debian-11"
865+
project = "debian-cloud"
866+
}
867+
868+
resource "google_compute_disk" "src_disk" {
869+
name = "tf-test-src-disk-%{random_suffix}"
870+
image = data.google_compute_image.debian.self_link
871+
size = 10
872+
type = "pd-ssd"
873+
zone = "us-central1-a"
874+
875+
disk_encryption_key {
876+
kms_key_self_link = "%{kms_key_self_link}"
877+
}
878+
}
879+
880+
resource "google_compute_image" "src-image-kms" {
881+
name = "tf-test-src-kms-%{random_suffix}"
882+
source_disk = google_compute_disk.src_disk.self_link
883+
image_encryption_key {
884+
kms_key_self_link = "%{kms_key_self_link}"
885+
}
886+
}
887+
888+
resource "google_compute_image" "src-image-raw" {
889+
name = "tf-test-src-raw-%{random_suffix}"
890+
source_disk = google_compute_disk.src_disk.self_link
891+
image_encryption_key {
892+
raw_key = "%{raw_key}"
893+
}
894+
}
895+
896+
resource "google_compute_image" "src-image-rsa" {
897+
name = "tf-test-src-rsa-%{random_suffix}"
898+
source_disk = google_compute_disk.src_disk.self_link
899+
image_encryption_key {
900+
rsa_encrypted_key = "%{rsa_encrypted_key}"
901+
}
902+
}
903+
904+
resource "google_compute_image" "foobar-kms" {
905+
name = "tf-test-image-kms-%{random_suffix}"
906+
source_image = google_compute_image.src-image-kms.self_link
907+
source_image_encryption_key {
908+
kms_key_self_link = "%{kms_key_self_link}"
909+
}
910+
}
911+
912+
resource "google_compute_image" "foobar-raw" {
913+
name = "tf-test-image-raw-%{random_suffix}"
914+
source_image = google_compute_image.src-image-raw.self_link
915+
source_image_encryption_key {
916+
raw_key = "%{raw_key}"
917+
}
918+
}
919+
920+
resource "google_compute_image" "foobar-rsa" {
921+
name = "tf-test-image-rsa-%{random_suffix}"
922+
source_image = google_compute_image.src-image-rsa.self_link
923+
source_image_encryption_key {
924+
rsa_encrypted_key = "%{rsa_encrypted_key}"
925+
kms_key_service_account = data.google_compute_default_service_account.default.email
926+
}
927+
}
928+
929+
data "google_compute_default_service_account" "default" {
930+
}
931+
`, context)
932+
}
933+
934+
func testAccComputeImage_sourceSnapshotEncryptionKey(context map[string]interface{}) string {
935+
return acctest.Nprintf(`
936+
data "google_compute_image" "debian" {
937+
family = "debian-11"
938+
project = "debian-cloud"
939+
}
940+
941+
resource "google_compute_disk" "src_disk-kms" {
942+
name = "tf-test-src-disk-kms-%{random_suffix}"
943+
image = data.google_compute_image.debian.self_link
944+
size = 10
945+
type = "pd-ssd"
946+
zone = "us-central1-a"
947+
948+
disk_encryption_key {
949+
kms_key_self_link = "%{kms_key_self_link}"
950+
}
951+
}
952+
953+
resource "google_compute_disk" "src_disk-raw" {
954+
name = "tf-test-src-disk-raw-%{random_suffix}"
955+
image = data.google_compute_image.debian.self_link
956+
size = 10
957+
type = "pd-ssd"
958+
zone = "us-central1-a"
959+
960+
disk_encryption_key {
961+
raw_key = "%{raw_key}"
962+
}
963+
}
964+
965+
resource "google_compute_disk" "src_disk-rsa" {
966+
name = "tf-test-src-disk-rsa-%{random_suffix}"
967+
image = data.google_compute_image.debian.self_link
968+
size = 10
969+
type = "pd-ssd"
970+
zone = "us-central1-a"
971+
972+
disk_encryption_key {
973+
rsa_encrypted_key = "%{rsa_encrypted_key}"
974+
}
975+
}
976+
977+
resource "google_compute_snapshot" "src-snapshot-kms" {
978+
name = "tf-test-src-snapshot-kms-%{random_suffix}"
979+
source_disk = google_compute_disk.src_disk-kms.self_link
980+
zone = "us-central1-a"
981+
982+
snapshot_encryption_key {
983+
kms_key_self_link = "%{kms_key_self_link}"
984+
}
985+
}
986+
987+
resource "google_compute_snapshot" "src-snapshot-raw" {
988+
name = "tf-test-src-snapshot-raw-%{random_suffix}"
989+
source_disk = google_compute_disk.src_disk-raw.self_link
990+
zone = "us-central1-a"
991+
992+
snapshot_encryption_key {
993+
raw_key = "%{raw_key}"
994+
}
995+
996+
source_disk_encryption_key {
997+
raw_key = "%{raw_key}"
998+
}
999+
}
1000+
1001+
resource "google_compute_snapshot" "src-snapshot-rsa" {
1002+
name = "tf-test-src-snapshot-rsa-%{random_suffix}"
1003+
source_disk = google_compute_disk.src_disk-rsa.self_link
1004+
zone = "us-central1-a"
1005+
1006+
snapshot_encryption_key {
1007+
rsa_encrypted_key = "%{rsa_encrypted_key}"
1008+
}
1009+
1010+
source_disk_encryption_key {
1011+
rsa_encrypted_key = "%{rsa_encrypted_key}"
1012+
}
1013+
}
1014+
1015+
resource "google_compute_image" "foobar-kms" {
1016+
name = "tf-test-image-kms-%{random_suffix}"
1017+
source_snapshot = google_compute_snapshot.src-snapshot-kms.self_link
1018+
source_snapshot_encryption_key {
1019+
kms_key_self_link = "%{kms_key_self_link}"
1020+
}
1021+
}
1022+
1023+
resource "google_compute_image" "foobar-raw" {
1024+
name = "tf-test-image-raw-%{random_suffix}"
1025+
source_snapshot = google_compute_snapshot.src-snapshot-raw.self_link
1026+
source_snapshot_encryption_key {
1027+
raw_key = "%{raw_key}"
1028+
}
1029+
}
1030+
1031+
resource "google_compute_image" "foobar-rsa" {
1032+
name = "tf-test-image-rsa-%{random_suffix}"
1033+
source_snapshot = google_compute_snapshot.src-snapshot-rsa.self_link
1034+
source_snapshot_encryption_key {
1035+
rsa_encrypted_key = "%{rsa_encrypted_key}"
1036+
kms_key_service_account = data.google_compute_default_service_account.default.email
1037+
}
1038+
}
1039+
1040+
data "google_compute_default_service_account" "default" {
1041+
}
1042+
`, context)
1043+
}
1044+
7221045
func testAccComputeImage_imageEncryptionKey(kmsRingName, kmsKeyName, suffix string) string {
7231046
return fmt.Sprintf(`
7241047
data "google_kms_key_ring" "ring" {

0 commit comments

Comments
 (0)