Skip to content

Commit f4be578

Browse files
committed
chore(CI): migrate tests to CFT
1 parent 0ebdfda commit f4be578

File tree

12 files changed

+174
-223
lines changed

12 files changed

+174
-223
lines changed

.kitchen.yml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,6 @@ suites:
159159
systems:
160160
- name: stub_domains_upstream_nameservers
161161
backend: local
162-
- name: "workload_identity"
163-
transport:
164-
root_module_directory: test/fixtures/workload_identity
165-
verifier:
166-
systems:
167-
- name: gcloud
168-
backend: local
169-
controls:
170-
- gcloud
171-
- name: gcp
172-
backend: gcp
173-
controls:
174-
- gcp
175162
- name: "workload_metadata_config"
176163
transport:
177164
root_module_directory: test/fixtures/workload_metadata_config
@@ -202,30 +189,13 @@ suites:
202189
controls:
203190
- gcloud
204191
- kubectl
205-
- name: "node_pool"
206-
transport:
207-
root_module_directory: test/fixtures/node_pool
208-
verifier:
209-
systems:
210-
- name: node_pool
211-
backend: local
212-
controls:
213-
- gcloud
214-
- kubectl
215192
- name: "sandbox_enabled"
216193
transport:
217194
root_module_directory: test/fixtures/sandbox_enabled
218195
verifier:
219196
systems:
220197
- name: sandbox_enabled
221198
backend: local
222-
- name: "safer_cluster_iap_bastion"
223-
transport:
224-
root_module_directory: test/fixtures/safer_cluster_iap_bastion
225-
verifier:
226-
systems:
227-
- name: safer_cluster_iap_bastion
228-
backend: local
229199
- name: "simple_zonal_with_asm"
230200
transport:
231201
root_module_directory: test/fixtures/simple_zonal_with_asm

build/int.cloudbuild.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,17 @@ steps:
369369
waitFor:
370370
- create-all
371371
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
372-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge node-pool-local']
372+
args: ['/bin/bash', '-c', 'cft test run TestNodePool --stage apply --verbose']
373373
- id: verify node-pool-local
374374
waitFor:
375375
- converge node-pool-local
376376
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
377-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify node-pool-local']
377+
args: ['/bin/bash', '-c', 'cft test run TestNodePool --stage verify --verbose']
378378
- id: destroy node-pool-local
379379
waitFor:
380380
- verify node-pool-local
381381
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
382-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy node-pool-local']
382+
args: ['/bin/bash', '-c', 'cft test run TestNodePool --stage destroy --verbose']
383383
- id: init sandbox-enabled-local
384384
waitFor:
385385
- create-all
@@ -404,32 +404,32 @@ steps:
404404
waitFor:
405405
- create-all
406406
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
407-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge workload-identity-local']
407+
args: ['/bin/bash', '-c', 'cft test run TestWorkloadIdentity --stage apply --verbose']
408408
- id: verify workload-identity-local
409409
waitFor:
410410
- converge workload-identity-local
411411
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
412-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify workload-identity-local']
412+
args: ['/bin/bash', '-c', 'cft test run TestWorkloadIdentity --stage verify --verbose']
413413
- id: destroy workload-identity-local
414414
waitFor:
415415
- verify workload-identity-local
416416
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
417-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy workload-identity-local']
417+
args: ['/bin/bash', '-c', 'cft test run TestWorkloadIdentity --stage destroy --verbose']
418418
- id: converge safer-cluster-iap-bastion-local
419419
waitFor:
420420
- create-all
421421
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
422-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge safer-cluster-iap-bastion-local']
422+
args: ['/bin/bash', '-c', 'cft test run TestSaferClusterIapBastion --stage apply --verbose']
423423
- id: verify safer-cluster-iap-bastion-local
424424
waitFor:
425425
- converge safer-cluster-iap-bastion-local
426426
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
427-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify safer-cluster-iap-bastion-local']
427+
args: ['/bin/bash', '-c', 'cft test run TestSaferClusterIapBastion --stage verify --verbose']
428428
- id: destroy safer-cluster-iap-bastion-local
429429
waitFor:
430430
- verify safer-cluster-iap-bastion-local
431431
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
432-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy safer-cluster-iap-bastion-local']
432+
args: ['/bin/bash', '-c', 'cft test run TestSaferClusterIapBastion --stage teardown --verbose']
433433
- id: init simple-zonal-with-asm-local
434434
waitFor:
435435
- create-all

examples/node_pool/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module "gke" {
4343
disable_legacy_metadata_endpoints = false
4444
cluster_autoscaling = var.cluster_autoscaling
4545
deletion_protection = false
46+
service_account = "default"
4647

4748
node_pools = [
4849
{

examples/workload_identity/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2018-2024 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,10 @@ provider "kubernetes" {
2424
host = "https://${module.gke.endpoint}"
2525
token = data.google_client_config.default.access_token
2626
cluster_ca_certificate = base64decode(module.gke.ca_certificate)
27+
28+
ignore_annotations = [
29+
"^iam.gke.io\\/.*"
30+
]
2731
}
2832

2933
module "gke" {

test/fixtures/safer_cluster_iap_bastion/example.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
locals {
18-
test_command = "gcloud beta compute ssh ${module.example.bastion_name} --tunnel-through-iap --verbosity=error --project ${var.project_ids[1]} --zone ${module.example.bastion_zone} --ssh-flag=\"-T\" -q -- curl -sS https://${module.example.endpoint}/version -k"
18+
test_command = "gcloud beta compute ssh ${module.example.bastion_name} --tunnel-through-iap --verbosity=error --project ${var.project_ids[1]} --zone ${module.example.bastion_zone} --ssh-flag='-T' -q -- curl -sS https://${module.example.endpoint}/version -k"
1919
}
2020

2121
module "example" {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2022-2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package node_pool
15+
16+
import (
17+
"fmt"
18+
"testing"
19+
"time"
20+
21+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
22+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
23+
"github.com/stretchr/testify/assert"
24+
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
25+
gkeutils "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/utils"
26+
)
27+
28+
func TestNodePool(t *testing.T) {
29+
bpt := tft.NewTFBlueprintTest(t,
30+
tft.WithRetryableTerraformErrors(testutils.RetryableTransientErrors, 3, 2*time.Minute),
31+
)
32+
33+
bpt.DefineVerify(func(assert *assert.Assertions) {
34+
//Skipping Default Verify as the Verify Stage fails due to change in Client Cert Token
35+
// bpt.DefaultVerify(assert)
36+
gkeutils.TGKEVerify(t, bpt, assert) // Verify Resources
37+
38+
projectId := bpt.GetStringOutput("project_id")
39+
location := bpt.GetStringOutput("location")
40+
clusterName := bpt.GetStringOutput("cluster_name")
41+
42+
op := gcloud.Runf(t, "container clusters describe %s --zone %s --project %s", clusterName, location, projectId)
43+
assert.Contains([]string{"RUNNING", "RECONCILING"}, op.Get("status").String(), "Cluster is Running")
44+
45+
46+
for _, np := range op.Get("nodePools").Array() {
47+
npName := np.Get("name").String()
48+
switch npName {
49+
50+
//TODO
51+
52+
case "pool-03":
53+
assert.JSONEq(fmt.Sprintf(`["%s-b", "%s-c"]`, location, location) , np.Get("locations").String())
54+
}
55+
}
56+
57+
})
58+
59+
bpt.Test()
60+
}

test/integration/safer_cluster_iap_bastion/controls/e2e.rb

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/integration/safer_cluster_iap_bastion/inspec.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2022-2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package safer_cluster_iap_bastion
15+
16+
import (
17+
"strings"
18+
"testing"
19+
"time"
20+
21+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
22+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
23+
"github.com/stretchr/testify/assert"
24+
"github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/testutils"
25+
gkeutils "github.com/terraform-google-modules/terraform-google-kubernetes-engine/test/integration/utils"
26+
)
27+
28+
func TestSaferClusterIapBastion(t *testing.T) {
29+
bpt := tft.NewTFBlueprintTest(t,
30+
tft.WithRetryableTerraformErrors(testutils.RetryableTransientErrors, 3, 2*time.Minute),
31+
)
32+
33+
bpt.DefineVerify(func(assert *assert.Assertions) {
34+
//Skipping Default Verify as the Verify Stage fails due to change in Client Cert Token
35+
// bpt.DefaultVerify(assert)
36+
gkeutils.TGKEVerify(t, bpt, assert) // Verify Resources
37+
38+
test_command, _ := strings.CutPrefix(bpt.GetStringOutput("test_command"), "gcloud ")
39+
cluster_version := bpt.GetStringOutput("cluster_version")
40+
41+
op := gcloud.Runf(t, test_command,
42+
gcloud.WithCommonArgs([]string{""}),
43+
)
44+
45+
assert.Equal(cluster_version, op.Get("gitVersion").String(), "SSH into VM and verify connectivity to GKE")
46+
})
47+
48+
bpt.Test()
49+
}

test/integration/workload_identity/controls/gcloud.rb

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)