Configuration
Using Workpaces
In this tutorial we will be using a repository in order to configure a terraform pipeline https://github.com/diggerhq/digger demo workspaces. In order to use Terraform workspaces with Digger we follow the steps below.
This is about Terraform CLI Workspaces - not Terraform Cloud Workspaces. Those are different things for historic reasons. Hashicorp article
Let’s create our first pull request with a change and see this in action
-
Fork the demo repository
-
Enable Actions (by default workflows won’t trigger in a fork)
- In your repository settings > Actions ensure that the Workflow Read and Write permissions are assigned - This will allow the workflow to post comments on your PRs
- Add environment variables into your Github Action Secrets (cloud keys are a requirement since digger needs to connect to your account for coordinating locks). In this case we are setting AWS keys for this demo but you can follow GCP or Azure steps as seen fit.
- make a change in
main.tf
and create a PR -you can just rename an existing null resource to test it. Notice that we have digger.yml where we have two workspaces defined: one for dev and the other for prod. Therefore Digger will create two plans for us:
- Lets apply the PR and merge it to unlock the flow for our colleagues. We can do this by commenting
digger apply
Conclusion
In this tutorial we created a workspace enabled example with terraform and workspaces to provision two environments with independent states.