Skip to content

Commit 0019b00

Browse files
authoredSep 2, 2022
fix: VPC Flow Logs constraint issue + Adding gcloud terraform vet usage to test (#779)
* Adding new strategy to deal with both flowlogs parameters * Adding line that insert terraform vet test setup * changing from relative to absolute path for policy libraries folder * Adding the PL setup to testable object * Removing back the terrafor vet usage * removing terraform vet * Adding gcloud beta terraform vet to tests * Adding project parameter to policyLibrary test definition + Bumping cft version
1 parent b5f0481 commit 0019b00

File tree

11 files changed

+21
-5
lines changed

11 files changed

+21
-5
lines changed
 

‎policy-library/policies/templates/gcp_network_enable_flow_logs_v1.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ spec:
5959
asset.asset_type == "compute.googleapis.com/Subnetwork"
6060
6161
network := asset.resource.data
62-
enable_flow_logs := lib.get_default(network, "enableFlowLogs", false)
63-
enable_flow_logs == false
62+
legacy_enable_flow_logs := lib.get_default(network, "enableFlowLogs", false)
63+
log_config := lib.get_default(network, "logConfig", {})
64+
log_config_enable_flow_logs := lib.get_default(log_config, "enable", false)
65+
66+
log_config_enable_flow_logs != true
67+
legacy_enable_flow_logs != true
6468
6569
message := sprintf("Flow logs are disabled in subnetwork %v.", [asset.name])
6670
metadata := {"resource": asset.name}

‎test/integration/app-infra/app_infra_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func TestAppInfra(t *testing.T) {
4343

4444
appInfra := tft.NewTFBlueprintTest(t,
4545
tft.WithTFDir(fmt.Sprintf("../../../5-app-infra/business_unit_1/%s", envName)),
46+
tft.WithPolicyLibraryPath("/workspace/policy-library", projects.GetStringOutput("base_shared_vpc_project")),
4647
tft.WithVars(vars),
4748
)
4849

‎test/integration/bootstrap/bootstrap_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ func TestBootstrap(t *testing.T) {
5050
"bucket_force_destroy": true,
5151
}
5252

53+
temp := tft.NewTFBlueprintTest(t,
54+
tft.WithTFDir("../../../0-bootstrap"),
55+
)
56+
5357
bootstrap := tft.NewTFBlueprintTest(t,
5458
tft.WithTFDir("../../../0-bootstrap"),
5559
tft.WithVars(vars),
60+
tft.WithPolicyLibraryPath("/workspace/policy-library", temp.GetTFSetupStringOutput("project_id")),
5661
)
5762

5863
cloudSourceRepos := []string{

‎test/integration/envs/envs_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestEnvs(t *testing.T) {
5656
t.Run(envName, func(t *testing.T) {
5757
envs := tft.NewTFBlueprintTest(t,
5858
tft.WithTFDir(fmt.Sprintf("../../../2-environments/envs/%s", envName)),
59+
tft.WithPolicyLibraryPath("/workspace/policy-library", bootstrap.GetTFSetupStringOutput("project_id")),
5960
tft.WithVars(vars),
6061
tft.WithBackendConfig(backendConfig),
6162
)

‎test/integration/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/terraform-google-modules/terraform-example-foundation/test/int
33
go 1.17
44

55
require (
6-
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.1.1-0.20220802155302-a13ee7fb1c62
6+
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.2.1-0.20220822233358-4e9b833071f9
77
github.com/gruntwork-io/terratest v0.40.7
88
github.com/stretchr/testify v1.7.1
99
github.com/tidwall/gjson v1.12.1

‎test/integration/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZ
6565
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
6666
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
6767
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
68-
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.1.1-0.20220802155302-a13ee7fb1c62 h1:uDiVwwTc7caRf6k2+MBKf3Ia+Z9nWu9diaJQUN3oGdA=
69-
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.1.1-0.20220802155302-a13ee7fb1c62/go.mod h1:E655Ka0BfIYALBmqU9ZbemLk/nutxw4vU6wkLEjshSA=
68+
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.2.1-0.20220822233358-4e9b833071f9 h1:sU9+r4cUupqDkfcWYjMRAf/fTFx7bQWUrO/aCMWNwko=
69+
github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test v0.2.1-0.20220822233358-4e9b833071f9/go.mod h1:E655Ka0BfIYALBmqU9ZbemLk/nutxw4vU6wkLEjshSA=
7070
github.com/GoogleContainerTools/kpt-functions-sdk/go v0.0.0-20220301220754-6964a09d6cd2/go.mod h1:lJYiqfBOl6AOiefK9kmkhinbffIysu+nnclOBwKEPlQ=
7171
github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
7272
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=

‎test/integration/networks/networks_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func TestNetworks(t *testing.T) {
145145
networks := tft.NewTFBlueprintTest(t,
146146
tft.WithTFDir(fmt.Sprintf(tfdDir, envName)),
147147
tft.WithVars(vars),
148+
tft.WithPolicyLibraryPath("/workspace/policy-library", bootstrap.GetTFSetupStringOutput("project_id")),
148149
tft.WithBackendConfig(backendConfig),
149150
)
150151
networks.DefineVerify(

‎test/integration/org/org_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestOrg(t *testing.T) {
5656
org := tft.NewTFBlueprintTest(t,
5757
tft.WithTFDir("../../../1-org/envs/shared"),
5858
tft.WithVars(vars),
59+
tft.WithPolicyLibraryPath("/workspace/policy-library", bootstrap.GetTFSetupStringOutput("project_id")),
5960
tft.WithBackendConfig(backendConfig),
6061
)
6162

‎test/integration/projects-shared/projects_shared_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func TestProjectsShared(t *testing.T) {
7171
tft.WithTFDir(tts.tfDir),
7272
tft.WithVars(sharedVars),
7373
tft.WithBackendConfig(backendConfig),
74+
tft.WithPolicyLibraryPath("/workspace/policy-library", bootstrap.GetTFSetupStringOutput("project_id")),
7475
)
7576

7677
shared.DefineVerify(

‎test/integration/projects/projects_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func TestProjects(t *testing.T) {
141141
tft.WithTFDir(fmt.Sprintf(tt.baseDir, env)),
142142
tft.WithVars(vars),
143143
tft.WithBackendConfig(backendConfig),
144+
tft.WithPolicyLibraryPath("/workspace/policy-library", bootstrap.GetTFSetupStringOutput("project_id")),
144145
)
145146

146147
projects.DefineVerify(

‎test/integration/shared/shared_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func TestShared(t *testing.T) {
7272
shared := tft.NewTFBlueprintTest(t,
7373
tft.WithTFDir(tfdDir),
7474
tft.WithVars(vars),
75+
tft.WithPolicyLibraryPath("/workspace/policy-library", bootstrap.GetTFSetupStringOutput("project_id")),
7576
tft.WithBackendConfig(backendConfig),
7677
)
7778
shared.DefineVerify(

0 commit comments

Comments
 (0)
Please sign in to comment.