Skip to content

Commit 434c433

Browse files
chore: update integration tests (terraform-google-modules#169)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
1 parent b6230c7 commit 434c433

File tree

15 files changed

+267
-321
lines changed

15 files changed

+267
-321
lines changed

build/int.cloudbuild.yaml

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,59 @@ steps:
2424
- 'TF_VAR_org_id=$_ORG_ID'
2525
- 'TF_VAR_folder_id=$_FOLDER_ID'
2626
- 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
27-
- id: create
27+
- id: init-all
2828
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
29-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create']
30-
- id: converge
29+
args: ['/bin/bash', '-c', 'cft test run all --stage init --verbose']
30+
waitFor:
31+
- prepare
32+
# test/fixtures/gh-runner-mig-container-vm
33+
- id: apply-gh-runner-mig-container-vm
34+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
35+
args: ['/bin/bash', '-c', 'cft test run TestGHRunnerMIGContainerVM --stage apply --verbose']
36+
waitFor:
37+
- init-all
38+
- id: verify-gh-runner-mig-container-vm
3139
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
32-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do converge']
33-
- id: verify
40+
args: ['/bin/bash', '-c', 'cft test run TestGHRunnerMIGContainerVM --stage verify --verbose']
41+
waitFor:
42+
- apply-gh-runner-mig-container-vm
43+
- id: destroy-gh-runner-mig-container-vm
3444
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
35-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do verify']
36-
- id: destroy
45+
args: ['/bin/bash', '-c', 'cft test run TestGHRunnerMIGContainerVM --stage destroy --verbose']
46+
waitFor:
47+
- verify-gh-runner-mig-container-vm
48+
# test/fixtures/gh-runner-gke
49+
- id: apply-gh-runner-gke
50+
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
51+
args: ['/bin/bash', '-c', 'cft test run TestGHRunnerGKE --stage apply --verbose']
52+
waitFor:
53+
- init-all
54+
- id: verify-gh-runner-gke
3755
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
38-
args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do destroy']
39-
- id: create-oidc
56+
args: ['/bin/bash', '-c', 'cft test run TestGHRunnerGKE --stage verify --verbose']
4057
waitFor:
41-
- destroy
58+
- apply-gh-runner-gke
59+
- id: destroy-gh-runner-gke
4260
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
43-
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=init go test -v -run TestOIDCSimple ./... -p 1']
44-
- id: converge-oidc
61+
args: ['/bin/bash', '-c', 'cft test run TestGHRunnerGKE --stage destroy --verbose']
4562
waitFor:
46-
- create-oidc
63+
- verify-gh-runner-gke
64+
# examples/oidc-simple
65+
- id: apply-oidc
4766
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
4867
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=apply go test -v -run TestOIDCSimple ./... -p 1']
49-
- id: verify-oidc
5068
waitFor:
51-
- converge-oidc
69+
- init-all
70+
- id: verify-oidc
5271
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
5372
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=verify go test -v -run TestOIDCSimple ./... -p 1']
54-
- id: destroy-oidc
5573
waitFor:
56-
- verify-oidc
74+
- apply-oidc
75+
- id: destroy-oidc
5776
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
5877
args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=teardown go test -v -run TestOIDCSimple ./... -p 1']
78+
waitFor:
79+
- verify-oidc
5980
tags:
6081
- 'ci'
6182
- 'integration'

examples/gh-runner-gke-simple/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ data "google_client_config" "default" {
2121
}
2222

2323
provider "kubernetes" {
24-
host = module.runner-gke.kubernetes_endpoint
24+
host = "https://${module.runner-gke.kubernetes_endpoint}"
2525
token = data.google_client_config.default.access_token
2626
cluster_ca_certificate = base64decode(module.runner-gke.ca_certificate)
2727
}

kitchen.yml

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

modules/gh-runner-gke/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module "runner-cluster" {
6565
monitoring_service = "monitoring.googleapis.com/kubernetes"
6666
remove_default_node_pool = true
6767
service_account = local.service_account
68+
gce_pd_csi_driver = true
6869
node_pools = [
6970
{
7071
name = "runner-pool"

test/fixtures/gh-runner-gke/outputs.tf

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
output "kubernetes_endpoint" {
18-
description = "The cluster endpoint"
19-
sensitive = true
20-
value = module.example_gke_runner.kubernetes_endpoint
21-
}
22-
23-
output "client_token" {
24-
description = "The bearer token for auth"
25-
sensitive = true
26-
value = module.example_gke_runner.client_token
27-
}
28-
29-
output "ca_certificate" {
30-
description = "The cluster ca certificate (base64 encoded)"
31-
sensitive = true
32-
value = module.example_gke_runner.ca_certificate
33-
}
34-
3517
output "service_account" {
3618
description = "The default service account used for running nodes."
3719
value = module.example_gke_runner.service_account

test/integration/discover_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2022 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+
15+
package test
16+
17+
import (
18+
"testing"
19+
20+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
21+
)
22+
23+
func TestAll(t *testing.T) {
24+
tft.AutoDiscoverAndTest(t)
25+
}

test/integration/gh-runner-gke/controls/gcloud.rb

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

test/integration/gh-runner-gke/controls/kubectl.rb

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2021 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+
15+
package gh_runner_gke
16+
17+
import (
18+
"testing"
19+
20+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/gcloud"
21+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
22+
"github.com/gruntwork-io/terratest/modules/k8s"
23+
"github.com/stretchr/testify/assert"
24+
)
25+
26+
func TestGHRunnerGKE(t *testing.T) {
27+
bpt := tft.NewTFBlueprintTest(t)
28+
bpt.DefineVerify(func(assert *assert.Assertions) {
29+
bpt.DefaultVerify(assert)
30+
31+
// get outputs
32+
projectId := bpt.GetStringOutput("project_id")
33+
location := bpt.GetStringOutput("location")
34+
clusterName := bpt.GetStringOutput("cluster_name")
35+
36+
// Check cluster is running
37+
cluster := gcloud.Runf(t, "container clusters describe %s --location %s --project %s", clusterName, location, projectId)
38+
assert.Contains([]string{"RUNNING"}, cluster.Get("status").String())
39+
40+
// Get cluster credentials
41+
gcloud.Runf(t, "container clusters get-credentials %s --location %s --project %s", clusterName, location, projectId)
42+
k8sOpts := k8s.KubectlOptions{}
43+
44+
// Check the "runner-k8s-config" secret exists
45+
secret, err := k8s.RunKubectlAndGetOutputE(t, &k8sOpts, "get", "secret", "runner-k8s-config", "-o", "json")
46+
if err != nil {
47+
t.Fatalf("Error getting secret: %s", err)
48+
}
49+
50+
assert.NotNil(t, secret, "The secret 'runner-k8s-config' should exist and have data")
51+
})
52+
53+
bpt.Test()
54+
}

test/integration/gh-runner-gke/inspec.yml

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

0 commit comments

Comments
 (0)