Skip to content

Simple pipeline to deploy your terraform code in an automated manner

Notifications You must be signed in to change notification settings

Filip3Kx/terraform-gitlab-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitLab CI with Terraform

Simple pipeline to deploy your terraform code in an automated manner

image

Pipeline

Here is a rundown of what the pipeline does before applying the terraform configuration to your infrastracture.

1. Formatting check

Performs a terraform fmt command and fails if the formating is not valid when commiting.

2. Terraform Validate

Performs a terraform validate command and fails if the configuration is not valid and raises any errors.

3. Terraform Plan

Prepares a terraform plan that's displayed in the job logs as well as being saved in json format in the job artifacts and reports.

4. Terraform Apply

terraform apply job only goes through after a manual start if everything seems right in the previous jobs.


Docker Image

Using the official docker image from gitlab.org registry but creating a custom version from it.

Here is how to create a version you need

git clone https://gitlab.com/gitlab-org/terraform-images

#this will create a new repo and start a pipeline creating the images in the GitLab container registry
git push --set-upstream [email protected]:{your_username}/{new_repo_name}

To build the versions of terraform binary you need into the image you need to change the .gitlab-ci.yml matrix that stores all the versions built

Example:

.terraform-versions:
  parallel:
    matrix:
      - TERRAFORM_BINARY_VERSION: "1.4.7"
        TERRAFORM_VERSION: "1.4"

Authentication

The pipeline uses a Service Account JSON key to authenticate to GCP in my case and it also supports impersonation for not automated testing

All you need to do is set a variable in your GitLab project that stores the key and retrives it during the job. In my example it's called $GOOGLE_TF_SA_KEY

image

About

Simple pipeline to deploy your terraform code in an automated manner

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages