I have terraform scripts that creates resources. Each script is in different folder for the separation of concern. When I manually apply these script, I navigate to each folder and then use terraform apply.
1>cd c:\tf\kms\terraform apply
2>cd c:\tf\roles\terraform apply
3>cd c:\tf\lambda\terraform apply
for each apply I review the plan and then type yes to apply changes.
Now I have to make this part of GitLab CI/CD. But what I am missing here, in pipeline how do I apply changes? because apply will need manual interaction to type yes
Terraform has -auto-approve flag but I think that is very dangerous.
UPDATE1
Since the resources are organized in multiple folders in the same repository and they all need to be created using same pipeline, How do I arrange the plan out
Will the following pipeline create 3 plans inside planoutput folder in artifacts?
stages:
- plan
image: "docker/mycompany/terraform"
plan:
stage: plan
script:
- chmod +x ./scripts/dev.sh
- ./scripts/dev.sh
artifacts:
paths:
- planoutput
and then in scripts/dev.sh
#!/bin/bash
cd ${CI_PROJECT_DIR}/tf/kms/
terraform init
terraform validate
terraform plan -out=kms.tfplan
cd ${CI_PROJECT_DIR}/tf/roles/
terraform init
terraform validate
terraform plan -out=roles.tfplan
cd ${CI_PROJECT_DIR}/tf/lambda/
terraform init
terraform validate
terraform plan -out=lambda.tfplan