ci: add .gitlab-ci.yml
This commit is contained in:
parent
0bce025c3f
commit
cab6fe0052
1 changed files with 66 additions and 0 deletions
66
.gitlab-ci.yml
Normal file
66
.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
default:
|
||||
image: ghcr.io/vojtechmares/container-images/tfenv:latest
|
||||
cache:
|
||||
key: dot-terraform
|
||||
paths:
|
||||
- .terraform
|
||||
|
||||
stages:
|
||||
- init
|
||||
- format
|
||||
- validate
|
||||
- plan
|
||||
- apply
|
||||
|
||||
variables:
|
||||
PLAN: plan.cache
|
||||
PLAN_JSON: plan.json
|
||||
|
||||
init:
|
||||
stage: init
|
||||
script:
|
||||
- terraform init
|
||||
|
||||
format:
|
||||
stage: format
|
||||
script:
|
||||
- terraform fmt -check -recursive -diff
|
||||
|
||||
validate:
|
||||
stage: validate
|
||||
script:
|
||||
- terraform validate
|
||||
|
||||
plan:
|
||||
stage: plan
|
||||
variables:
|
||||
TF_VAR_cloudflare_email: $CLOUDFLARE_EMAIL
|
||||
TF_VAR_cloudflare_api_key: $CLOUDFLARE_API_KEY
|
||||
TF_VAR_hcloud_token: $HCLOUD_TOKEN
|
||||
before_script:
|
||||
- apt-get update && apt-get install -y jq
|
||||
- shopt -s expand_aliases
|
||||
- alias convert_report="jq -r '([.resource_changes[]?.change.actions?]|flatten)|{\"create\":(map(select(.==\"create\"))|length),\"update\":(map(select(.==\"update\"))|length),\"delete\":(map(select(.==\"delete\"))|length)}'"
|
||||
script:
|
||||
- terraform plan -out=$PLAN
|
||||
- terraform show --json $PLAN | convert_report > $PLAN_JSON
|
||||
artifacts:
|
||||
name: plan
|
||||
paths:
|
||||
- plan.cache
|
||||
reports:
|
||||
terraform: $PLAN_JSON
|
||||
|
||||
apply:
|
||||
stage: apply
|
||||
variables:
|
||||
TF_VAR_cloudflare_email: $CLOUDFLARE_EMAIL
|
||||
TF_VAR_cloudflare_api_key: $CLOUDFLARE_API_KEY
|
||||
TF_VAR_hcloud_token: $HCLOUD_TOKEN
|
||||
script:
|
||||
- terraform apply -auto-approve
|
||||
dependencies:
|
||||
- plan
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == 'main'
|
||||
when: manual
|
||||
Reference in a new issue