Using CodePipeline and CodeBuild to build clusters
We have done the deployment manually so far by running the Terraform plan
and apply
commands. CodeBuild is an AWS service that acts as a CI build server but also deploys our Terraform configuration. CodePipeline automates the end-to-end release pipeline and sequences build, test, and deploy phases, based on commits to a repository such as CodeCommit.
The first thing we need to do is adjust our Terraform code to support the storage of state in an S3 bucket. This is necessary, as by default, Terraform will use local storage for its state, and as CodeBuild is a transient environment, that state will be lost between builds. Terraform relies on a state file to determine what needs adding, changing, or removing. We will simply add the backend configuration code shown next to the providers.tf
file we created previously. We don’t need to specify any details, as this will be configured dynamically during the Terraform init
phase: