@@ -767,16 +767,31 @@ func TestAccComputeInstanceTemplate_ConfidentialInstanceConfigMain(t *testing.T)
767767
768768 var instanceTemplate compute.InstanceTemplate
769769
770+ var instanceTemplate2 compute.InstanceTemplate
771+
770772 acctest .VcrTest (t , resource.TestCase {
771773 PreCheck : func () { acctest .AccTestPreCheck (t ) },
772774 ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
773775 CheckDestroy : testAccCheckComputeInstanceTemplateDestroyProducer (t ),
774776 Steps : []resource.TestStep {
775777 {
776- Config : testAccComputeInstanceTemplateConfidentialInstanceConfig (acctest .RandString (t , 10 ), true ),
778+ Config : testAccComputeInstanceTemplateConfidentialInstanceConfigEnable (acctest .RandString (t , 10 ), "SEV" ),
777779 Check : resource .ComposeTestCheckFunc (
778780 testAccCheckComputeInstanceTemplateExists (t , "google_compute_instance_template.foobar" , & instanceTemplate ),
779- testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig (& instanceTemplate , true ),
781+ testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig (& instanceTemplate , true , "SEV" ),
782+
783+ testAccCheckComputeInstanceTemplateExists (t , "google_compute_instance_template.foobar2" , & instanceTemplate2 ),
784+ testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig (& instanceTemplate2 , true , "" ),
785+ ),
786+ },
787+
788+ {
789+ Config : testAccComputeInstanceTemplateConfidentialInstanceConfigNoEnable (acctest .RandString (t , 10 ), "AMD Milan" , "SEV_SNP" ),
790+ Check : resource .ComposeTestCheckFunc (
791+ testAccCheckComputeInstanceTemplateExists (t , "google_compute_instance_template.foobar3" , & instanceTemplate ),
792+ testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig (& instanceTemplate , false , "SEV_SNP" ),
793+ testAccCheckComputeInstanceTemplateExists (t , "google_compute_instance_template.foobar4" , & instanceTemplate2 ),
794+ testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig (& instanceTemplate2 , false , "SEV_SNP" ),
780795 ),
781796 },
782797 },
@@ -1754,13 +1769,17 @@ func testAccCheckComputeInstanceTemplateHasShieldedVmConfig(instanceTemplate *co
17541769 }
17551770}
17561771
1757- func testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig (instanceTemplate * compute.InstanceTemplate , EnableConfidentialCompute bool ) resource.TestCheckFunc {
1772+ func testAccCheckComputeInstanceTemplateHasConfidentialInstanceConfig (instanceTemplate * compute.InstanceTemplate , EnableConfidentialCompute bool , ConfidentialInstanceType string ) resource.TestCheckFunc {
17581773
17591774 return func (s * terraform.State ) error {
17601775 if instanceTemplate .Properties .ConfidentialInstanceConfig .EnableConfidentialCompute != EnableConfidentialCompute {
17611776 return fmt .Errorf ("Wrong ConfidentialInstanceConfig EnableConfidentialCompute: expected %t, got, %t" , EnableConfidentialCompute , instanceTemplate .Properties .ConfidentialInstanceConfig .EnableConfidentialCompute )
17621777 }
17631778
1779+ if instanceTemplate .Properties .ConfidentialInstanceConfig .ConfidentialInstanceType != ConfidentialInstanceType {
1780+ return fmt .Errorf ("Wrong ConfidentialInstanceConfig ConfidentialInstanceType: expected %s, got, %s" , ConfidentialInstanceType , instanceTemplate .Properties .ConfidentialInstanceConfig .ConfidentialInstanceType )
1781+ }
1782+
17641783 return nil
17651784 }
17661785}
@@ -3055,7 +3074,7 @@ resource "google_compute_instance_template" "foobar" {
30553074` , suffix , enableSecureBoot , enableVtpm , enableIntegrityMonitoring )
30563075}
30573076
3058- func testAccComputeInstanceTemplateConfidentialInstanceConfig (suffix string , enableConfidentialCompute bool ) string {
3077+ func testAccComputeInstanceTemplateConfidentialInstanceConfigEnable (suffix string , confidentialInstanceType string ) string {
30593078 return fmt .Sprintf (`
30603079data "google_compute_image" "my_image" {
30613080 family = "ubuntu-2004-lts"
@@ -3068,7 +3087,7 @@ resource "google_compute_instance_template" "foobar" {
30683087
30693088 disk {
30703089 source_image = data.google_compute_image.my_image.self_link
3071- auto_delete = true
3090+ auto_delete = true
30723091 boot = true
30733092 }
30743093
@@ -3077,15 +3096,106 @@ resource "google_compute_instance_template" "foobar" {
30773096 }
30783097
30793098 confidential_instance_config {
3080- enable_confidential_compute = %t
3099+ enable_confidential_compute = true
3100+
3101+ confidential_instance_type = %q
3102+
30813103 }
30823104
30833105 scheduling {
3084- on_host_maintenance = "TERMINATE"
3106+ on_host_maintenance = "TERMINATE"
3107+ }
3108+
3109+ }
3110+
3111+ resource "google_compute_instance_template" "foobar2" {
3112+ name = "tf-test-instance2-template-%s"
3113+ machine_type = "n2d-standard-2"
3114+
3115+ disk {
3116+ source_image = data.google_compute_image.my_image.self_link
3117+ auto_delete = true
3118+ boot = true
3119+ }
3120+
3121+ network_interface {
3122+ network = "default"
3123+ }
3124+
3125+ confidential_instance_config {
3126+ enable_confidential_compute = true
3127+ }
3128+
3129+ scheduling {
3130+ on_host_maintenance = "TERMINATE"
3131+ }
3132+
3133+ }
3134+
3135+
3136+ ` , suffix , confidentialInstanceType , suffix )
3137+
3138+ }
3139+
3140+ func testAccComputeInstanceTemplateConfidentialInstanceConfigNoEnable (suffix string , minCpuPlatform , confidentialInstanceType string ) string {
3141+ return fmt .Sprintf (`
3142+ data "google_compute_image" "my_image2" {
3143+ family = "ubuntu-2004-lts"
3144+ project = "ubuntu-os-cloud"
3145+ }
3146+
3147+ resource "google_compute_instance_template" "foobar3" {
3148+ name = "tf-test-instance3-template-%s"
3149+ machine_type = "n2d-standard-2"
3150+
3151+ disk {
3152+ source_image = data.google_compute_image.my_image2.self_link
3153+ auto_delete = true
3154+ boot = true
3155+ }
3156+
3157+ network_interface {
3158+ network = "default"
3159+ }
3160+
3161+ min_cpu_platform = %q
3162+
3163+ confidential_instance_config {
3164+ enable_confidential_compute = false
3165+ confidential_instance_type = %q
3166+ }
3167+
3168+ scheduling {
3169+ on_host_maintenance = "TERMINATE"
3170+ }
3171+
3172+ }
3173+ resource "google_compute_instance_template" "foobar4" {
3174+ name = "tf-test-instance4-template-%s"
3175+ machine_type = "n2d-standard-2"
3176+
3177+ disk {
3178+ source_image = data.google_compute_image.my_image2.self_link
3179+ auto_delete = true
3180+ boot = true
3181+ }
3182+
3183+ network_interface {
3184+ network = "default"
3185+ }
3186+
3187+ min_cpu_platform = %q
3188+
3189+ confidential_instance_config {
3190+ confidential_instance_type = %q
3191+ }
3192+
3193+ scheduling {
3194+ on_host_maintenance = "TERMINATE"
30853195 }
30863196
30873197}
3088- ` , suffix , enableConfidentialCompute )
3198+ ` , suffix , minCpuPlatform , confidentialInstanceType , suffix , minCpuPlatform , confidentialInstanceType )
30893199}
30903200
30913201func testAccComputeInstanceTemplateAdvancedMachineFeatures (suffix string ) string {
0 commit comments