You can now provision infrastructure using Terraform through Shippable builds without having to worry about merge conflicts in state files. If you aren't familiar with it, Terraform is a tool for building, changing and versioning infrastructure safely and efficiently. It can manage existing and popular service providers as well as a part of a custom in-house solution. You can now use Terraform to provision your infrastructure in Shippable. Here's how to get started:
Step 1: Create Terraform project
Create a Terraform project with the required infrastructure configuration. You can clone our sample Terraform project from GitHub to get started. In addition, your project should also have a shippable.yml file. Here is a sample shippable.yml file as a starting point:
```
language: none
env:
global:
- FOO=”bar”
- secure: <encrypted output>
infra:
pre_prov:
- cp -vr /shippableci/shippable/provision/terraform.tfstate .
prov:
- terraform apply
post_prov:
on_success:
- cp -fvr terraform.tfstate /shippableci/shippable/provision
on_failure:
integrations:
deploy:
hub:
notifications:
key:
```
Here is a guide key components of the sample shippable.yml file:- The `pre_prov` section has script(s) that you want to execute before provisioning (eg. `terraform plan` or copying file from `/shippableci/shippable/provision` to project directory).
- The `prov` section has script(s) for provisioning infrastructure. If this section is not present in shippable.yml, `terraform apply` will be executed by default.
- The `post_prov` section has script(s) that you would like to run after provisioning (eg. copying new state file from project directory to `/shippableci/shippable/provision`).
- You can encrypt your secure environment variables and use them in env tag. (Instructions for doing this can be found in the Shippable documentation.)
Step 2: Add project on Shippable
- Push this project to your GitHub or Bitbucket private repository.
- Login to Shippable, go to `Account Settings`, and sync your account by click on `Sync`.
- Go to your subscription, Click on `Infra` tab and click on `Enable Project`
4. Find your terraform project in the list and click on `Enable` button.
5. Your project will now show up in the `Infra` tab. Click on the `Provision` button to start provisioning your infrastructure.
6. Once the build completes infrastructure will be provisioned:
NOTE: '/shippableci/shippable/provision' is a generic folder to save and restore all files. You should put new files back in this folder to be saved for next provision in the `on_success` section of the 'infra' tag. Let us know if you want Shippable to support your favorite provisioning tools!