Skip to content

Commit

Permalink
validate examples and compatibility with TF modules using local chang…
Browse files Browse the repository at this point in the history
…es (#334)

* validate examples using local changes

* run tf plan to ensure modules stay compatible

* fmt

* echo things

* check git cli works

* check git cli

* git r u there?

* gh workflow does not fetch tags

* echo stuff

* fmt

* test new echo

* bad substitution

* new print

* use bash

* validate examples in PR

* api tf var

* ensure GKE compatible

* diff ids wip

* aks compatibility test

* see what's up with aks

* missing tf var

* finalize pr

---------

Co-authored-by: Furkhat Kasymov Genii Uulu <[email protected]>
  • Loading branch information
furkhat and Furkhat Kasymov Genii Uulu authored Jun 18, 2024
1 parent 3990f92 commit 4f5d23b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
40 changes: 37 additions & 3 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: Terraform Examples Validation
on:
pull_request:
branches: [ '*' ]
paths:
- '**.md'
- 'examples/**'
paths-ignore:
- '**.md.tmpl'
jobs:
terraform_validation:
strategy:
Expand All @@ -27,3 +26,38 @@ jobs:
- name: Validate Terraform examples
id: validate_examples
run: make validate-terraform-examples

- name: Ensure EKS module compatible
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_TF_ACCEPTANCE_TEST_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_TF_ACCEPTANCE_TEST_SECRET_KEY_ID }}
TF_VAR_cluster_name: gh-eks
TF_VAR_cluster_region: us-east-1
TF_VAR_castai_api_token: ${{ secrets.CASTAI_TOKEN }}
TF_VAR_castai_api_url: ${{ secrets.CASTAI_URL }}
id: eks_plan_examples
run: cd examples/eks/eks_clusters && terraform plan 1> /dev/null

- name: Ensure GKE module compatible
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_TF_ACCEPTANCE_TEST_CREDENTIALS }}
GOOGLE_PROJECT_ID: ${{ secrets.GOOGLE_TF_ACCEPTANCE_PROJECT_ID }}
TF_VAR_project_id: ${{ secrets.GOOGLE_TF_ACCEPTANCE_PROJECT_ID }}
TF_VAR_cluster_name: gh-gke
TF_VAR_castai_api_token: ${{ secrets.CASTAI_TOKEN }}
TF_VAR_castai_api_url: ${{ secrets.CASTAI_URL }}
id: gke_plan_examples
run: cd examples/gke/gke_castai_iam && terraform plan 1> /dev/null

- name: Ensure AKS module compatible
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TF_ACCEPTANCE_TEST_ARM_TENANT_ID }}
TF_VAR_cluster_name: gh-aks
TF_VAR_castai_api_token: ${{ secrets.CASTAI_TOKEN }}
TF_VAR_castai_api_url: ${{ secrets.CASTAI_URL }}
TF_VAR_cluster_region: "germanywestcentral"
id: aks_plan_examples
run: cd examples/aks/aks_cluster && terraform plan 1> /dev/null
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
SHELL := /bin/bash

default: build

.PHONY: init-examples
init-examples:
@echo "==> Creating symlinks for example/ projects to terraform-provider-castai binary"; \
TF_PROVIDER_FILENAME=terraform-provider-castai; \
GOOS=`go tool dist env | awk -F'=' '/^GOOS/ { print $$2}' | tr -d '";'`; \
GOARCH=`go tool dist env | awk -F'=' '/^GOARCH/ { print $$2}' | tr -d '";'`; \
GOOS=`go env GOOS`; \
GOARCH=`go env GOARCH`; \
git fetch --tags > /dev/null; \
NEXT_MINOR=`git tag --list 'v*'|sort|tail -n 1| awk -F. -v OFS=. '{$$NF += 1 ; print}'`; \
echo "using next possible minor version without 'v' prefix: $${NEXT_MINOR:1}"; \
for examples in examples/eks examples/gke examples/aks ; do \
for tfproject in $$examples/* ; do \
TF_PROJECT_PLUGIN_PATH="$${tfproject}/terraform.d/plugins/registry.terraform.io/castai/castai/0.0.0-local/$${GOOS}_$${GOARCH}"; \
TF_PROJECT_PLUGIN_PATH="$${tfproject}/terraform.d/plugins/registry.terraform.io/castai/castai/$${NEXT_MINOR:1}/$${GOOS}_$${GOARCH}"; \
echo "creating $${TF_PROVIDER_FILENAME} symlink to $${TF_PROJECT_PLUGIN_PATH}/$${TF_PROVIDER_FILENAME}"; \
mkdir -p "${PWD}/$${TF_PROJECT_PLUGIN_PATH}"; \
ln -sf "${PWD}/terraform-provider-castai" "$${TF_PROJECT_PLUGIN_PATH}"; \
Expand Down

0 comments on commit 4f5d23b

Please sign in to comment.