@@ -316,6 +316,72 @@ func TestAccComputeImage_imageEncryptionKey(t *testing.T) {
316
316
})
317
317
}
318
318
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
+
319
385
func testAccCheckComputeImageResolution (t * testing.T , n string ) resource.TestCheckFunc {
320
386
return func (s * terraform.State ) error {
321
387
config := acctest .GoogleProviderConfig (t )
@@ -719,6 +785,263 @@ resource "google_compute_image" "foobar" {
719
785
` , diskName , snapshotName , imageName )
720
786
}
721
787
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
+
722
1045
func testAccComputeImage_imageEncryptionKey (kmsRingName , kmsKeyName , suffix string ) string {
723
1046
return fmt .Sprintf (`
724
1047
data "google_kms_key_ring" "ring" {
0 commit comments