Skip to content

Commit a996653

Browse files
committed
Use OpenTofu to create GCP infrastructure
1 parent 2c11513 commit a996653

20 files changed

+418
-229
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ trim_trailing_whitespace = true
88
indent_size = 4
99
indent_style = tab
1010

11-
[*.{md,yml,yaml}]
11+
[*.{md,yml,yaml,tf}]
1212
indent_size = 2
1313
indent_style = space

.github/workflows/nfr.yml

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -87,43 +87,35 @@ jobs:
8787
project_id: ${{ secrets.GCP_PROJECT_ID }}
8888
install_components: kubectl
8989

90+
91+
- name: Setup OpenTofu
92+
uses: opentofu/setup-opentofu@592200bd4b9bbf4772ace78f887668b1aee8f716 # v1.0.5
93+
with:
94+
tofu_version: 1.8.7 # renovate: datasource=github-tags depName=opentofu/opentofu
95+
9096
- name: Setup dotenv file
9197
working-directory: ./tests/scripts
9298
run: |
93-
echo "RESOURCE_NAME=nfr-tests-${{ github.run_id }}-${{ matrix.type }}" >> vars.env
9499
echo "TAG=${{ needs.vars.outputs.image_tag }}" >> vars.env
95100
echo "PREFIX=ghcr.io/nginxinc/nginx-gateway-fabric" >> vars.env
96101
echo "NGINX_PREFIX=ghcr.io/nginxinc/nginx-gateway-fabric/nginx" >> vars.env
97102
echo "NGINX_PLUS_PREFIX=us-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/nginx-gateway-fabric/nginx-plus" >> vars.env
98-
echo "GKE_CLUSTER_NAME=nfr-tests-${{ github.run_id }}-${{ matrix.type }}" >> vars.env
99-
echo "GKE_CLUSTER_ZONE=us-west1-b" >> vars.env
100-
echo "GKE_CLUSTER_REGION=us-west1" >> vars.env
101-
echo "GKE_PROJECT=${{ secrets.GCP_PROJECT_ID }}" >> vars.env
102-
echo "GKE_SVC_ACCOUNT=${{ secrets.GCP_SERVICE_ACCOUNT }}" >> vars.env
103-
echo "GKE_NODES_SERVICE_ACCOUNT=${{ secrets.GKE_NODES_SERVICE_ACCOUNT }}" >> vars.env
104-
echo "NETWORK_TAGS=nfr-tests-${{ github.run_id }}-${{ matrix.type }}" >> vars.env
105-
echo "NGF_BRANCH=${{ github.ref_name }}" >> vars.env
106-
echo "SOURCE_IP_RANGE=$(curl -sS -4 icanhazip.com)/32" >> vars.env
107-
echo "ADD_VM_IP_AUTH_NETWORKS=true" >> vars.env
108103
echo "PLUS_ENABLED=${{ matrix.type == 'plus' }}" >> vars.env
109104
echo "GINKGO_LABEL=" >> vars.env
110105
echo "NGF_VERSION=${{ needs.vars.outputs.version }}" >> vars.env
111-
echo "GKE_NUM_NODES=12" >> vars.env
112-
echo "GKE_MACHINE_TYPE=n2d-standard-16" >> vars.env
113-
114-
- name: Setup license file for plus
115-
if: matrix.type == 'plus'
116-
env:
117-
PLUS_LICENSE: ${{ secrets.JWT_PLUS_REGISTRY }}
118-
run: echo "${PLUS_LICENSE}" > license.jwt
119106
120-
- name: Create GKE cluster
121-
working-directory: ./tests
122-
run: make create-gke-cluster CI=true
123-
124-
- name: Create and setup VM
125-
working-directory: ./tests
126-
run: make create-and-setup-vm
107+
- name: Create GKE cluster and VM
108+
working-directory: ./tests/tofu
109+
run: |
110+
tofu apply --auto-approve \
111+
-var="project_id=${{ secrets.GCP_PROJECT_ID }}" \
112+
-var="gke_cluster_name=nfr-tests-${{ github.run_id }}-${{ matrix.type }}" \
113+
-var="vm_service_account=${{ secrets.GCP_SERVICE_ACCOUNT }}"
114+
-var="gke_nodes_service_account=${{ secrets.GKE_NODES_SERVICE_ACCOUNT }}" \
115+
-var="gke_num_nodes=12" \
116+
-var="gke_machine_type=n2d-standard-16" \
117+
-var="gke_project=${{ secrets.GCP_PROJECT_ID }}" \
118+
-var="ngf_branch=${{ github.ref_name }}"
127119
128120
- name: Run Tests
129121
working-directory: ./tests

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,32 @@ internal/mode/static/nginx/modules/coverage
6161
# temporary files used for manifest generation
6262
config/base/deploy.yaml
6363
config/base/deploy.yaml.bak
64+
65+
# Local .terraform directories
66+
**/.terraform/*
67+
68+
# .tfstate files
69+
*.tfstate
70+
*.tfstate.*
71+
72+
# Crash log files
73+
crash.log
74+
crash.*.log
75+
76+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
77+
# password, private keys, and other secrets. These should not be part of version
78+
# control as they are data points which are potentially sensitive and subject
79+
# to change depending on the environment.
80+
*.tfvars
81+
*.tfvars.json
82+
83+
# Ignore override files as they are usually used to override resources locally and so
84+
# are not checked in
85+
override.tf
86+
override.tf.json
87+
*_override.tf
88+
*_override.tf.json
89+
90+
# Ignore CLI configuration files
91+
.terraformrc
92+
terraform.rc

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ repos:
9595
- "--skip-auto-generation=required,additionalProperties"
9696
- --append-newline
9797

98+
- repo: https://github.com/tofuutils/pre-commit-opentofu
99+
rev: v2.1.0
100+
hooks:
101+
- id: tofu_fmt
102+
# - id: tofu_docs
103+
98104
ci:
99105
skip: [golangci-lint-full, prettier, markdownlint-cli2, yamllint]
100106
autofix_prs: false

tests/Makefile

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,11 @@ ifeq ($(PLUS_ENABLED),true)
9090
endif
9191

9292
.PHONY: setup-gcp-and-run-nfr-tests
93-
setup-gcp-and-run-nfr-tests: create-gke-router create-and-setup-vm nfr-test ## Create and setup a GKE router and GCP VM for tests and run the NFR tests
93+
setup-gcp-and-run-nfr-tests: create-gcp-resources nfr-test ## Create and setup a GKE router and GCP VM for tests and run the NFR tests
9494

9595
.PHONY: create-gke-cluster
96-
create-gke-cluster: ## Create a GKE cluster
97-
./scripts/create-gke-cluster.sh $(CI)
98-
99-
.PHONY: create-and-setup-vm
100-
create-and-setup-vm: ## Create and setup a GCP VM for tests
101-
./scripts/create-and-setup-gcp-vm.sh
102-
103-
.PHONY: create-gke-router
104-
create-gke-router: ## Create a GKE router to allow egress traffic from private nodes (allows for external image pulls)
105-
./scripts/create-gke-router.sh
96+
create-gcp-resources: ## Create a GKE cluster and a GCP VM for tests
97+
tofu -chdir=tofu apply
10698

10799
.PHONY: sync-files-to-vm
108100
sync-files-to-vm: ## Syncs your local NGF files with the NGF repo on the VM
@@ -150,23 +142,8 @@ test-with-plus: PLUS_ENABLED=true
150142
test-with-plus: test ## Runs the functional tests for NGF with NGINX Plus on your default k8s cluster
151143

152144
.PHONY: cleanup-gcp
153-
cleanup-gcp: cleanup-router cleanup-vm delete-gke-cluster ## Cleanup all GCP resources
154-
155-
.PHONY: cleanup-router
156-
cleanup-router: ## Delete the GKE router
157-
./scripts/cleanup-router.sh
158-
159-
.PHONY: cleanup-vm
160-
cleanup-vm: ## Delete the test GCP VM and delete the firewall rule
161-
./scripts/cleanup-vm.sh
162-
163-
.PHONY: delete-gke-cluster
164-
delete-gke-cluster: ## Delete the GKE cluster
165-
./scripts/delete-gke-cluster.sh
166-
167-
.PHONY: add-local-ip-to-cluster
168-
add-local-ip-to-cluster: ## Add local IP to the GKE cluster master-authorized-networks
169-
./scripts/add-local-ip-auth-networks.sh
145+
cleanup-gcp: ## Cleanup all GCP resources
146+
tofu -chdir=tofu destroy
170147

171148
HELM_PARAMETERS += --set nameOverride=nginx-gateway --set nginxGateway.kind=skip --set service.create=false --skip-schema-validation
172149

tests/scripts/add-local-ip-auth-networks.sh

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

tests/scripts/cleanup-router.sh

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

tests/scripts/cleanup-vm.sh

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

tests/scripts/create-and-setup-gcp-vm.sh

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

tests/scripts/create-gke-cluster.sh

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

0 commit comments

Comments
 (0)