@@ -23,6 +23,74 @@ import (
2323 compute "google.golang.org/api/compute/v0.beta"
2424)
2525
26+ func TestMinCpuPlatformDiffSuppress (t * testing.T ) {
27+ cases := map [string ]struct {
28+ Old , New string
29+ ExpectDiffSuppress bool
30+ }{
31+ "state: empty, conf: AUTOMATIC" : {
32+ Old : "" ,
33+ New : "AUTOMATIC" ,
34+ ExpectDiffSuppress : true ,
35+ },
36+ "state: empty, conf: automatic" : {
37+ Old : "" ,
38+ New : "automatic" ,
39+ ExpectDiffSuppress : true ,
40+ },
41+ "state: empty, conf: AuToMaTiC" : {
42+ Old : "" ,
43+ New : "AuToMaTiC" ,
44+ ExpectDiffSuppress : true ,
45+ },
46+ "state: empty, conf: Intel Haswell" : {
47+ Old : "" ,
48+ New : "Intel Haswell" ,
49+ ExpectDiffSuppress : false ,
50+ },
51+ // This case should never happen due to the field being
52+ // Optional + Computed; however, including for completeness.
53+ "state: Intel Haswell, conf: empty" : {
54+ Old : "Intel Haswell" ,
55+ New : "" ,
56+ ExpectDiffSuppress : false ,
57+ },
58+ // These cases should never happen given current API behavior; testing
59+ // in case API behavior changes in the future.
60+ "state: AUTOMATIC, conf: Intel Haswell" : {
61+ Old : "AUTOMATIC" ,
62+ New : "Intel Haswell" ,
63+ ExpectDiffSuppress : false ,
64+ },
65+ "state: Intel Haswell, conf: AUTOMATIC" : {
66+ Old : "Intel Haswell" ,
67+ New : "AUTOMATIC" ,
68+ ExpectDiffSuppress : false ,
69+ },
70+ "state: AUTOMATIC, conf: empty" : {
71+ Old : "AUTOMATIC" ,
72+ New : "" ,
73+ ExpectDiffSuppress : true ,
74+ },
75+ "state: automatic, conf: empty" : {
76+ Old : "automatic" ,
77+ New : "" ,
78+ ExpectDiffSuppress : true ,
79+ },
80+ "state: AuToMaTiC, conf: empty" : {
81+ Old : "AuToMaTiC" ,
82+ New : "" ,
83+ ExpectDiffSuppress : true ,
84+ },
85+ }
86+
87+ for tn , tc := range cases {
88+ if tpgcompute .ComputeInstanceMinCpuPlatformEmptyOrAutomaticDiffSuppress ("min_cpu_platform" , tc .Old , tc .New , nil ) != tc .ExpectDiffSuppress {
89+ t .Errorf ("bad: %s, %q => %q expect DiffSuppress to return %t" , tn , tc .Old , tc .New , tc .ExpectDiffSuppress )
90+ }
91+ }
92+ }
93+
2694func computeInstanceImportStep (zone , instanceName string , additionalImportIgnores []string ) resource.TestStep {
2795 // metadata is only read into state if set in the config
2896 // importing doesn't know whether metadata.startup_script vs metadata_startup_script is set in the config,
@@ -1431,7 +1499,15 @@ func TestAccComputeInstance_minCpuPlatform(t *testing.T) {
14311499 testAccCheckComputeInstanceHasMinCpuPlatform (& instance , "Intel Haswell" ),
14321500 ),
14331501 },
1434- computeInstanceImportStep ("us-east1-d" , instanceName , []string {}),
1502+ computeInstanceImportStep ("us-east1-d" , instanceName , []string {"allow_stopping_for_update" }),
1503+ {
1504+ Config : testAccComputeInstance_minCpuPlatform_remove (instanceName ),
1505+ Check : resource .ComposeTestCheckFunc (
1506+ testAccCheckComputeInstanceExists (t , "google_compute_instance.foobar" , & instance ),
1507+ testAccCheckComputeInstanceHasMinCpuPlatform (& instance , "" ),
1508+ ),
1509+ },
1510+ computeInstanceImportStep ("us-east1-d" , instanceName , []string {"allow_stopping_for_update" }),
14351511 },
14361512 })
14371513}
@@ -5294,6 +5370,35 @@ resource "google_compute_instance" "foobar" {
52945370 }
52955371
52965372 min_cpu_platform = "Intel Haswell"
5373+ allow_stopping_for_update = true
5374+ }
5375+ ` , instance )
5376+ }
5377+
5378+ func testAccComputeInstance_minCpuPlatform_remove (instance string ) string {
5379+ return fmt .Sprintf (`
5380+ data "google_compute_image" "my_image" {
5381+ family = "debian-11"
5382+ project = "debian-cloud"
5383+ }
5384+
5385+ resource "google_compute_instance" "foobar" {
5386+ name = "%s"
5387+ machine_type = "e2-micro"
5388+ zone = "us-east1-d"
5389+
5390+ boot_disk {
5391+ initialize_params {
5392+ image = data.google_compute_image.my_image.self_link
5393+ }
5394+ }
5395+
5396+ network_interface {
5397+ network = "default"
5398+ }
5399+
5400+ min_cpu_platform = "AuToMaTiC"
5401+ allow_stopping_for_update = true
52975402}
52985403` , instance )
52995404}
0 commit comments