This sample repository details the steps necessary to get started with Terraform on Codeship Pro.
It is in an experimental state right now and might not work for every setup.
The repository contains a very basic Terraform configuration. It is configured with remote state and state locking based on AWS S3 and AWS DynamoDB. The configuration itself takes care of configuring the remote state backend (via the 00_terraform.tf
file) as well as configuring the required ressources on AWS (via the 01_aws.tf
file).
All required credentials are provided via environment variables, see the env.example
file for a sample version).
The repository contains a simple Dockerfile
based on the hashicorp/terraform:light image. It configures a working directory and copies all required files into the Docker image.
The codeship-services.yml
configures a service based on that image. It additionally mounts the ./tmp
directory into the container to allow steps to share data (mainly required for sharing the computed tfplan
file from the plan
step to the apply
step). It also configures the container to use an encrypted environment file (defaulting to env.encrypted
) to provide the container with access to AWS.
The codeship-steps.yml
configures the following 4 steps:
version
: which simply prints the current Terraform version informationinit
: required to initizalize the remote state backendplan
: to compute a Terraform plan of any required changes. The generated plan is shared with theapply
step via a volume to ensure that only those changes are made.apply
: (limited to themaster
branch) to actually make the requested changes. This step reuses the plan computed in step 3.
Please see the Terraform documentation for more information on the individual commands, their usage and available options.