We are migrating our infrastructure automation from Jenkins + CloudFormation to GitLab CI/CD + Terraform and need guidance on the best approach.
Current Setup:
- A GitLab CI/CD pipeline (
gitlab-ci.yml
) acts as a parent pipeline with five manually triggered stages (Application, DB, S3, Undeploy, Fallover). - Each stage triggers a child pipeline that executes shell scripts stored in a
helper-scripts
folder. - These scripts reference CloudFormation templates (
cloudformation
folder) and parameter files (cf-parameters
folder).
Migration Goals:
- Convert CloudFormation templates to Terraform while maintaining modularity and reusability.
- Refactor the GitLab pipeline structure to align with Terraform best practices.
- Manage input parameters and state files efficiently.
Questions:
- How should we structure Terraform files and modules for this transition? Should we keep a similar directory hierarchy or reorganize it?
- What’s the best way to pass parameters dynamically from GitLab CI/CD to Terraform (similar to our current JSON parameter files)?
- How should we handle Terraform state when multiple pipelines (child jobs) need to update the infrastructure?
- Are there any best practices or pitfalls we should be aware of in this migration?
We’d appreciate any guidance, best practices, or examples from similar migrations.