1515package utils
1616
1717import (
18+ "slices"
19+ "strings"
1820 "testing"
1921 "time"
2022
2123 "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
24+ tfjson "github.com/hashicorp/terraform-json"
25+ "github.com/stretchr/testify/assert"
2226 "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
2327)
2428
@@ -32,3 +36,22 @@ func GetTestProjectFromSetup(t *testing.T, idx int) string {
3236 }
3337 return projectIDs [idx ]
3438}
39+
40+ // TGKEVerify asserts no resource changes exist after apply.
41+ func TGKEVerify (t * testing.T , b * tft.TFBlueprintTest , assert * assert.Assertions ) {
42+ TGKEVerifyExemptResources (t , b , assert , []string {})
43+ }
44+
45+ // TGKEVerifyExemptResources asserts no resource changes exist after apply except exempt resources: e.g. google_container_cluster.primary
46+ func TGKEVerifyExemptResources (t * testing.T , b * tft.TFBlueprintTest , assert * assert.Assertions , verifyExemptResources []string ) {
47+ _ , ps := b .PlanAndShow ()
48+ for _ , r := range ps .ResourceChangesMap {
49+ if slices .ContainsFunc (verifyExemptResources , func (str string ) bool {
50+ return strings .HasSuffix (r .Address , str )
51+ }) {
52+ t .Logf ("Exempt plan address: %s" , r .Address )
53+ continue
54+ }
55+ assert .Equal (tfjson.Actions {tfjson .ActionNoop }, r .Change .Actions , "Plan must be no-op for resource: %s" , r .Address )
56+ }
57+ }
0 commit comments