This is a short example of what has to be added to repo in order to have workable terraform in GitLab ci with state kept in GitLab. Full doc is here.
Files are located in the sandbox folder.
For AWS credentials are stored in CI variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_DEFAULT_REGION (optionally).
This allows to maintain state in GitLab:
terraform {
backend "http" {
}
}
The following templates do the magic (IaC security scan and gitlab's TF image to exec tf commands)
include:
- template: Terraform/Base.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Terraform/Base.gitlab-ci.yml
- template: Jobs/SAST-IaC.gitlab-ci.yml # https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Jobs/SAST-IaC.gitlab-ci.yml
That's it!
