skip to Main Content

I’ve built a full infrastructure for our team using Terraform which is working well. The solution is based on terraform modules, this is our structure at the moment

modules
  eks
    eks.tf
    variables.tf
  lambda
    lambda.tf
    variables.tf
  s3
    s3.tf
    variables.tf
staging
  eks
    eks.tf
  lambda
    lambda.tf
  s3
    s3.tf
    ...

Basically what we do is we get for each service what we have defined under modules and then we reference said module under example staging/s3/s3.tf and we deploy the service from there.

What I want to achieve is we’re using gitlab and I want to have a CI/CD process for this because right now I’m just running infra changes from locally.

The idea would be to deploy each service for staging separately via CI/CD so I would have to change directory and go into staging/eks for example before deploying changes. I just have no idea how to do that right now. I’m looking for pointers to where should I even start.

At the moment what I do is I cd into staging/lambda for example. I run terraform init, I run terraform plan and then I do terraform apply which deploys if there’s changes. I’m just looking to replicate this to gitlab ci/cd

2

Answers


  1. I would suggest you use Terragrunt for building infrastructure for multiple environments. You can find more details here:
    https://blog.gruntwork.io/how-to-manage-multiple-environments-with-terraform-using-terragrunt-2c3e32fc60a8

    This can be achieved without terragrunt as well, but requires a bit more effort in setting up and providing inputs.

    Login or Signup to reply.
  2. Depending on which ci/cd you are using, you can configure the dev branch to run staging and the main branch to run production.

    For GitLab you can try this

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search