Gitlab CI/CD and terraform to deploy AWS resources (EC2/VPC/peering/subnets)
In this article, we will deploy the same AWS infrastructure as in the Github article.
We will use the same main.tf
file, we’ve changed the name of the .tfstate
terraform state file in the S3 bucket.
The .gitlab-ci.yml
file in the root of the project contains the 3 stages, plan/apply and destroy. The plan/apply stages are triggered by any changes committed to the main.tf
terraform file. They can also be run manually, from the Build/pipelines
section, where 3 checkmarks will appear under the Stages
header, for the pipeline. The destroy
stage can be invoked manually by clicking on the last checkmark and on the run
button at the end.
The AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
variables need to be added manually to the Settings > CI/CD
section. Choose Visibility > Masked
and Protect variable
.