Skip to content

Instantly share code, notes, and snippets.

@theCaptN21
Last active February 25, 2023 15:55
Show Gist options
  • Save theCaptN21/9df58c65fe9abe0d7968f75791d44696 to your computer and use it in GitHub Desktop.
Save theCaptN21/9df58c65fe9abe0d7968f75791d44696 to your computer and use it in GitHub Desktop.
GitLab Template
# This file is a template, and might need editing before it works on your project.
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
image:
name: hashicorp/terraform:light
entrypoint: [""]
variables:
TF_VAR_gitlab_token: ${GITLAB_ACCESS_TOKEN}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY}
AWS_SECRET_ACCESS_KEY : ${AWS_SECRET_KEY}
AWS_DEFAULT_REGION: "us-east-1"
cache:
paths:
- .terraform
before_script:
- terraform --version
- export GITLAB_ACCESS_TOKEN=$TOKEN
- cd ${TF_DIR}
- terraform init -reconfigure -backend-config="address=${ADDRESS}" -backend-config="lock_address=${ADDRESS}/lock" -backend-config="unlock_address=${ADDRESS}/lock" -backend-config="username=<UseName>" -backend-config="password=$GITLAB_ACCESS_TOKEN" -backend-config="lock_method=POST" -backend-config="unlock_method=DELETE" -backend-config="retry_wait_min=5"
stages:
- validate
- plan
- build
- apply
- destroy
validate:
stage: validate
script:
- terraform validate
plan:
stage: plan
script:
- terraform plan -out="planfile"
dependencies:
- validate
artifacts:
paths:
- planfile
build:
extends: .terraform:build
environment:
name: $ECS_Dev
action: prepare
dependencies:
- plan
apply:
stage: apply
script:
- terraform apply --auto-approve
dependencies:
- build
environment:
name: $ECS_Dev
destroy:
stage: destroy
script:
- terraform destroy --auto-approve
dependencies:
- apply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment