stages:
- init
- validate
- plan
- deploy
.driftctl:
image:
name: cloudskiff/driftctl
entrypoint: [""]
script:
- driftctl scan
driftctl:scheduled:
extends: .driftctl
only:
- schedules
stage: validate
variables:
AWS_DEFAULT_REGION: us-east-1
DCTL_FILTER: "Type=='aws_s3_bucket'"
.tfcache: &tfcache
cache:
key: ${CI_PIPELINE_ID}
paths:
- .terraform
.terraform: &terraform
image:
name: hashicorp/terraform:0.14.4
entrypoint: [""]
terraform/init:
<<: *terraform
<<: *tfcache
stage: init
except:
- schedules
script:
- terraform init
driftctl:
extends: .driftctl
except:
- schedules
stage: validate
variables:
AWS_DEFAULT_REGION: us-east-1
DCTL_FILTER: "Type=='aws_s3_bucket'"
terraform/fmt:
<<: *terraform
stage: validate
except:
- schedules
script:
- terraform fmt -check -diff
terraform/validate:
<<: *terraform
<<: *tfcache
stage: validate
except:
- schedules
script:
- terraform validate
terraform/plan:
<<: *terraform
<<: *tfcache
stage: plan
except:
- schedules
artifacts:
name: plan
expire_in: 1 day
paths:
- "plan.out"
script:
- terraform plan -out=plan.out
terraform/apply:
<<: *terraform
<<: *tfcache
stage: deploy
when: manual
dependencies:
- terraform/plan
except:
- schedules
script:
- terraform apply plan.out