84 lines
3.6 KiB
YAML
84 lines
3.6 KiB
YAML
.terraform_fmt:
|
|
script:
|
|
# Begin of cd-workdir.sh
|
|
- |
|
|
#change directory
|
|
cd $WORKDIR
|
|
# End of cd-workdir.sh
|
|
|
|
# Begin of fmt.sh
|
|
- |
|
|
#Terraform fmt
|
|
terraform fmt -diff -check -write=false
|
|
# End of fmt.sh
|
|
.terraform_validate:
|
|
script:
|
|
# Begin of cd-workdir.sh
|
|
- |
|
|
#change directory
|
|
cd $WORKDIR
|
|
# End of cd-workdir.sh
|
|
|
|
# Begin of init.sh
|
|
- "#Terraform init \nterraform init -reconfigure -backend-config=\"address=${GITLAB_TF_ADDRESS}\" -backend-config=\"lock_address=${GITLAB_TF_ADDRESS}/lock\" -backend-config=\"unlock_address=${GITLAB_TF_ADDRESS}/lock\" -backend-config=\"username=gitlab-ci-token\" -backend-config=\"password=${CI_JOB_TOKEN}\" -backend-config=\"lock_method=POST\" -backend-config=\"unlock_method=DELETE\" -backend-config=\"retry_wait_min=5\" \n"
|
|
# End of init.sh
|
|
|
|
# Begin of validate.sh
|
|
- "#Terraform validate\nterraform validate \n"
|
|
# End of validate.sh
|
|
.terraform_plan:
|
|
variables:
|
|
PLAN: plan.tfplan
|
|
JSON_PLAN_FILE: tfplan.json
|
|
script:
|
|
# Begin of cd-workdir.sh
|
|
- |
|
|
#change directory
|
|
cd $WORKDIR
|
|
# End of cd-workdir.sh
|
|
|
|
# Begin of init.sh
|
|
- "#Terraform init \nterraform init -reconfigure -backend-config=\"address=${GITLAB_TF_ADDRESS}\" -backend-config=\"lock_address=${GITLAB_TF_ADDRESS}/lock\" -backend-config=\"unlock_address=${GITLAB_TF_ADDRESS}/lock\" -backend-config=\"username=gitlab-ci-token\" -backend-config=\"password=${CI_JOB_TOKEN}\" -backend-config=\"lock_method=POST\" -backend-config=\"unlock_method=DELETE\" -backend-config=\"retry_wait_min=5\" \n"
|
|
# End of init.sh
|
|
|
|
# Begin of plan.sh
|
|
- "#Terraform plan \napk add --update curl jq\nalias convert_report=\"jq -r '([.resource_changes[].change.actions?]|flatten)|{\\\"create\\\":(map(select(.==\\\"create\\\"))|length),\\\"update\\\":(map(select(.==\\\"update\\\"))|length),\\\"delete\\\":(map(select(.==\\\"delete\\\"))|length)}'\"\nterraform plan -out=$PLAN $ARGUMENTS\nterraform show --json $PLAN | convert_report > $JSON_PLAN_FILE\n"
|
|
# End of plan.sh
|
|
artifacts:
|
|
reports:
|
|
terraform: $WORKDIR/$JSON_PLAN_FILE
|
|
.terraform_apply:
|
|
script:
|
|
# Begin of cd-workdir.sh
|
|
- |
|
|
#change directory
|
|
cd $WORKDIR
|
|
# End of cd-workdir.sh
|
|
|
|
# Begin of init.sh
|
|
- "#Terraform init \nterraform init -reconfigure -backend-config=\"address=${GITLAB_TF_ADDRESS}\" -backend-config=\"lock_address=${GITLAB_TF_ADDRESS}/lock\" -backend-config=\"unlock_address=${GITLAB_TF_ADDRESS}/lock\" -backend-config=\"username=gitlab-ci-token\" -backend-config=\"password=${CI_JOB_TOKEN}\" -backend-config=\"lock_method=POST\" -backend-config=\"unlock_method=DELETE\" -backend-config=\"retry_wait_min=5\" \n"
|
|
# End of init.sh
|
|
|
|
# Begin of apply.sh
|
|
- |
|
|
#Terraform validate
|
|
terraform apply -auto-approve $ARGUMENTS
|
|
# End of apply.sh
|
|
.terraform_destroy:
|
|
script:
|
|
# Begin of cd-workdir.sh
|
|
- |
|
|
#change directory
|
|
cd $WORKDIR
|
|
# End of cd-workdir.sh
|
|
|
|
# Begin of init.sh
|
|
- "#Terraform init \nterraform init -reconfigure -backend-config=\"address=${GITLAB_TF_ADDRESS}\" -backend-config=\"lock_address=${GITLAB_TF_ADDRESS}/lock\" -backend-config=\"unlock_address=${GITLAB_TF_ADDRESS}/lock\" -backend-config=\"username=gitlab-ci-token\" -backend-config=\"password=${CI_JOB_TOKEN}\" -backend-config=\"lock_method=POST\" -backend-config=\"unlock_method=DELETE\" -backend-config=\"retry_wait_min=5\" \n"
|
|
# End of init.sh
|
|
|
|
# Begin of destroy.sh
|
|
- |
|
|
#Terraform validate
|
|
terraform destroy -auto-approve $ARGUMENTS
|
|
# End of destroy.sh
|