@@ -759,6 +759,33 @@ func TestAccComputeInstanceTemplate_soleTenantNodeAffinities(t *testing.T) {
759759 })
760760}
761761
762+ func TestAccComputeInstanceTemplate_instanceResourcePolicies (t * testing.T ) {
763+ t .Parallel ()
764+
765+ var template compute.InstanceTemplate
766+ var policyName = "tf-test-policy-" + randString (t , 10 )
767+
768+ vcrTest (t , resource.TestCase {
769+ PreCheck : func () { testAccPreCheck (t ) },
770+ Providers : testAccProviders ,
771+ CheckDestroy : testAccCheckComputeInstanceTemplateDestroyProducer (t ),
772+ Steps : []resource.TestStep {
773+ {
774+ Config : testAccComputeInstanceTemplate_instanceResourcePolicyCollocated (randString (t , 10 ), policyName ),
775+ Check : resource .ComposeTestCheckFunc (
776+ testAccCheckComputeInstanceTemplateExists (t , "google_compute_instance_template.foobar" , & template ),
777+ testAccCheckComputeInstanceTemplateHasInstanceResourcePolicies (& template , policyName ),
778+ ),
779+ },
780+ {
781+ ResourceName : "google_compute_instance_template.foobar" ,
782+ ImportState : true ,
783+ ImportStateVerify : true ,
784+ },
785+ },
786+ })
787+ }
788+
762789func TestAccComputeInstanceTemplate_reservationAffinities (t * testing.T ) {
763790 t .Parallel ()
764791
@@ -994,7 +1021,7 @@ func TestAccComputeInstanceTemplate_imageResourceTest(t *testing.T) {
9941021 })
9951022}
9961023
997- func TestAccComputeInstanceTemplate_resourcePolicies (t * testing.T ) {
1024+ func TestAccComputeInstanceTemplate_diskResourcePolicies (t * testing.T ) {
9981025 t .Parallel ()
9991026
10001027 var instanceTemplate compute.InstanceTemplate
@@ -1006,7 +1033,7 @@ func TestAccComputeInstanceTemplate_resourcePolicies(t *testing.T) {
10061033 CheckDestroy : testAccCheckComputeInstanceTemplateDestroyProducer (t ),
10071034 Steps : []resource.TestStep {
10081035 {
1009- Config : testAccComputeInstanceTemplate_resourcePolicies (randString (t , 10 ), policyName ),
1036+ Config : testAccComputeInstanceTemplate_diskResourcePolicies (randString (t , 10 ), policyName ),
10101037 Check : resource .ComposeTestCheckFunc (
10111038 testAccCheckComputeInstanceTemplateExists (t , "google_compute_instance_template.foobar" , & instanceTemplate ),
10121039 testAccCheckComputeInstanceTemplateHasDiskResourcePolicy (& instanceTemplate , policyName ),
@@ -1521,6 +1548,18 @@ func testAccCheckComputeInstanceTemplateHasMinCpuPlatform(instanceTemplate *comp
15211548 }
15221549}
15231550
1551+ func testAccCheckComputeInstanceTemplateHasInstanceResourcePolicies (instanceTemplate * compute.InstanceTemplate , resourcePolicy string ) resource.TestCheckFunc {
1552+ return func (s * terraform.State ) error {
1553+ resourcePolicyActual := instanceTemplate .Properties .ResourcePolicies [0 ]
1554+ if resourcePolicyActual != resourcePolicy {
1555+ return fmt .Errorf ("Wrong instance resource policy: expected %s, got %s" , resourcePolicy , resourcePolicyActual )
1556+ }
1557+
1558+ return nil
1559+ }
1560+
1561+ }
1562+
15241563func testAccCheckComputeInstanceTemplateHasReservationAffinity (instanceTemplate * compute.InstanceTemplate , consumeReservationType string , specificReservationNames ... string ) resource.TestCheckFunc {
15251564 if len (specificReservationNames ) > 1 {
15261565 panic ("too many specificReservationNames in test" )
@@ -2479,6 +2518,50 @@ resource "google_compute_instance_template" "foobar" {
24792518` , suffix )
24802519}
24812520
2521+ func testAccComputeInstanceTemplate_instanceResourcePolicyCollocated (suffix string , policyName string ) string {
2522+ return fmt .Sprintf (`
2523+ resource "google_compute_resource_policy" "foo" {
2524+ name = "%s"
2525+ region = "us-central1"
2526+ group_placement_policy {
2527+ vm_count = 2
2528+ collocation = "COLLOCATED"
2529+ }
2530+ }
2531+
2532+ data "google_compute_image" "my_image" {
2533+ family = "debian-11"
2534+ project = "debian-cloud"
2535+ }
2536+
2537+ resource "google_compute_instance_template" "foobar" {
2538+ name = "tf-test-instance-template-%s"
2539+ machine_type = "e2-standard-4"
2540+
2541+ disk {
2542+ source_image = data.google_compute_image.my_image.self_link
2543+ auto_delete = true
2544+ boot = true
2545+ }
2546+
2547+ network_interface {
2548+ network = "default"
2549+ }
2550+
2551+ scheduling {
2552+ preemptible = false
2553+ automatic_restart = false
2554+ }
2555+
2556+ resource_policies = [google_compute_resource_policy.foo.self_link]
2557+
2558+ service_account {
2559+ scopes = ["userinfo-email", "compute-ro", "storage-ro"]
2560+ }
2561+ }
2562+ ` , policyName , suffix )
2563+ }
2564+
24822565func testAccComputeInstanceTemplate_reservationAffinityInstanceTemplate_nonSpecificReservation (templateName , consumeReservationType string ) string {
24832566 return fmt .Sprintf (`
24842567data "google_compute_image" "my_image" {
@@ -2734,7 +2817,7 @@ resource "google_compute_instance_template" "foobar" {
27342817` , diskName , imageName , imageDescription )
27352818}
27362819
2737- func testAccComputeInstanceTemplate_resourcePolicies (suffix string , policyName string ) string {
2820+ func testAccComputeInstanceTemplate_diskResourcePolicies (suffix string , policyName string ) string {
27382821 return fmt .Sprintf (`
27392822data "google_compute_image" "my_image" {
27402823 family = "debian-11"
0 commit comments