@@ -162,6 +162,38 @@ func TestAccComputeInstanceFromTemplateWithOverride_localSsdRecoveryTimeout(t *t
162
162
})
163
163
}
164
164
165
+ func TestAccComputeInstanceFromTemplate_diskResourcePolicies (t * testing.T ) {
166
+ t .Parallel ()
167
+
168
+ var instance compute.Instance
169
+ templateName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
170
+ suffix := acctest .RandString (t , 10 )
171
+
172
+ acctest .VcrTest (t , resource.TestCase {
173
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
174
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
175
+ CheckDestroy : testAccCheckComputeInstanceFromTemplateDestroyProducer (t ),
176
+ Steps : []resource.TestStep {
177
+ {
178
+ Config : testAccComputeInstanceFromTemplate_diskResourcePoliciesCreate (suffix , templateName ),
179
+ Check : resource .ComposeTestCheckFunc (
180
+ testAccCheckComputeInstanceExists (t , "google_compute_instance_from_template.foobar" , & instance ),
181
+ ),
182
+ },
183
+ {
184
+ Config : testAccComputeInstanceFromTemplate_diskResourcePoliciesUpdate (suffix , templateName ),
185
+ Check : resource .ComposeTestCheckFunc (
186
+ testAccCheckComputeInstanceExists (t , "google_compute_instance_from_template.foobar" , & instance ),
187
+ ),
188
+ },
189
+ {
190
+ Config : testAccComputeInstanceFromTemplate_diskResourcePoliciesTwoPolicies (suffix , templateName ),
191
+ ExpectError : regexp .MustCompile ("Too many list items" ),
192
+ },
193
+ },
194
+ })
195
+ }
196
+
165
197
func TestAccComputeInstanceFromTemplate_partnerMetadata (t * testing.T ) {
166
198
t .Parallel ()
167
199
@@ -1834,3 +1866,159 @@ resource "google_compute_instance_from_template" "foobar" {
1834
1866
}
1835
1867
` , template , instance , template , instance )
1836
1868
}
1869
+
1870
+ func testAccComputeInstanceFromTemplate_diskResourcePoliciesCreate (suffix , template string ) string {
1871
+ return fmt .Sprintf (`
1872
+ resource "google_compute_resource_policy" "test-snapshot-policy" {
1873
+ name = "test-policy-%s"
1874
+ snapshot_schedule_policy {
1875
+ schedule {
1876
+ hourly_schedule {
1877
+ hours_in_cycle = 1
1878
+ start_time = "11:00"
1879
+ }
1880
+ }
1881
+ }
1882
+ }
1883
+
1884
+ resource "google_compute_resource_policy" "test-snapshot-policy2" {
1885
+ name = "test-policy2-%s"
1886
+ snapshot_schedule_policy {
1887
+ schedule {
1888
+ hourly_schedule {
1889
+ hours_in_cycle = 1
1890
+ start_time = "22:00"
1891
+ }
1892
+ }
1893
+ }
1894
+ }
1895
+
1896
+ data "google_compute_image" "my_image" {
1897
+ family = "debian-11"
1898
+ project = "debian-cloud"
1899
+ }
1900
+
1901
+ resource "google_compute_region_instance_template" "foobar" {
1902
+ name = "%s"
1903
+ region = "us-central1"
1904
+ machine_type = "n1-standard-1"
1905
+ disk {
1906
+ resource_policies = [ google_compute_resource_policy.test-snapshot-policy.name ]
1907
+ source_image = data.google_compute_image.my_image.self_link
1908
+ }
1909
+ network_interface {
1910
+ network = "default"
1911
+ }
1912
+ }
1913
+
1914
+ resource "google_compute_instance_from_template" "foobar" {
1915
+ name = "%s"
1916
+ zone = "us-central1-a"
1917
+ source_instance_template = google_compute_region_instance_template.foobar.id
1918
+ }
1919
+ ` , suffix , suffix , template , template )
1920
+ }
1921
+
1922
+ func testAccComputeInstanceFromTemplate_diskResourcePoliciesUpdate (suffix , template string ) string {
1923
+ return fmt .Sprintf (`
1924
+ resource "google_compute_resource_policy" "test-snapshot-policy" {
1925
+ name = "test-policy-%s"
1926
+ snapshot_schedule_policy {
1927
+ schedule {
1928
+ hourly_schedule {
1929
+ hours_in_cycle = 1
1930
+ start_time = "11:00"
1931
+ }
1932
+ }
1933
+ }
1934
+ }
1935
+
1936
+ resource "google_compute_resource_policy" "test-snapshot-policy2" {
1937
+ name = "test-policy2-%s"
1938
+ snapshot_schedule_policy {
1939
+ schedule {
1940
+ hourly_schedule {
1941
+ hours_in_cycle = 1
1942
+ start_time = "22:00"
1943
+ }
1944
+ }
1945
+ }
1946
+ }
1947
+
1948
+ data "google_compute_image" "my_image" {
1949
+ family = "debian-11"
1950
+ project = "debian-cloud"
1951
+ }
1952
+
1953
+ resource "google_compute_region_instance_template" "foobar" {
1954
+ name = "%s"
1955
+ region = "us-central1"
1956
+ machine_type = "n1-standard-1"
1957
+ disk {
1958
+ resource_policies = [ google_compute_resource_policy.test-snapshot-policy2.name ]
1959
+ source_image = data.google_compute_image.my_image.self_link
1960
+ }
1961
+ network_interface {
1962
+ network = "default"
1963
+ }
1964
+ }
1965
+
1966
+ resource "google_compute_instance_from_template" "foobar" {
1967
+ name = "%s"
1968
+ zone = "us-central1-a"
1969
+ source_instance_template = google_compute_region_instance_template.foobar.id
1970
+ }
1971
+ ` , suffix , suffix , template , template )
1972
+ }
1973
+
1974
+ func testAccComputeInstanceFromTemplate_diskResourcePoliciesTwoPolicies (suffix , template string ) string {
1975
+ return fmt .Sprintf (`
1976
+ resource "google_compute_resource_policy" "test-snapshot-policy" {
1977
+ name = "test-policy-%s"
1978
+ snapshot_schedule_policy {
1979
+ schedule {
1980
+ hourly_schedule {
1981
+ hours_in_cycle = 1
1982
+ start_time = "11:00"
1983
+ }
1984
+ }
1985
+ }
1986
+ }
1987
+
1988
+ resource "google_compute_resource_policy" "test-snapshot-policy2" {
1989
+ name = "test-policy2-%s"
1990
+ snapshot_schedule_policy {
1991
+ schedule {
1992
+ hourly_schedule {
1993
+ hours_in_cycle = 1
1994
+ start_time = "22:00"
1995
+ }
1996
+ }
1997
+ }
1998
+ }
1999
+
2000
+ data "google_compute_image" "my_image" {
2001
+ family = "debian-11"
2002
+ project = "debian-cloud"
2003
+ }
2004
+
2005
+ resource "google_compute_region_instance_template" "foobar" {
2006
+ name = "%s"
2007
+ region = "us-central1"
2008
+ machine_type = "n1-standard-1"
2009
+ disk {
2010
+ resource_policies = [ google_compute_resource_policy.test-snapshot-policy.name, google_compute_resource_policy.test-snapshot-policy2.name ]
2011
+ source_image = data.google_compute_image.my_image.self_link
2012
+ }
2013
+ network_interface {
2014
+ network = "default"
2015
+ }
2016
+ }
2017
+
2018
+ resource "google_compute_instance_from_template" "foobar" {
2019
+ name = "%s"
2020
+ zone = "us-central1-a"
2021
+ source_instance_template = google_compute_region_instance_template.foobar.id
2022
+ }
2023
+ ` , suffix , suffix , template , template )
2024
+ }
0 commit comments