Local Development
Introduction
This page helps to start the local development on a Terraform project.
Preparation
To start the development, we need the local project connected to a Terraform workspace. With that we can set all needed variable sets in Terraform Cloud and also see the progress of every Terraform plan and apply.
Install terraform
Make sure you have terraform
installed:
brew install terraform
Pull repository
Clone desired project with git clone
.
Adjust Terraform configuration
Open the main Terraform file (often main.tf
) in the root of the project.
Add the following lines to the beginning of the file:
terraform {
cloud {
hostname = "app.terraform.io"
organization = "ambimax"
workspaces {
tags = ["development", "local"]
}
}
}
If there already is a terraform { ... }
block in the Terraform file, just add the cloud { ... }
to it.
Create and connect Terraform workspace
Initiate the project with:
terraform init
This command will ask you for input. Create a new Terraform workspace in Terraform Cloud and name it as followed:
$ALIAS-$REPOSITORY
Where $ALIAS
is your shorthand alias in Ambimax, like "dw" or "jb" and $REPOSITORY
is the name of the project
repository like "terraform-kubernetes". With this definition you get a name like "dw-terraform-kubernetes".
After the command has finished you can see your Terraform workspace in the Terraform workspace overview.
Set all needed variables
Move to your newly created Terraform workspace in Terraform Cloud and go to "Variables". Now there you have to add all variables, the project requires.
Development
Now you can start to develop on the project. Use terraform plan
and terraform apply
to deploy your previously
implemented infrastructure.
If you are done and want to reset everything, remove the link to your Terraform workspace and delete it:
rm .terraform/environment # removes all links to your Terraform workspaces
terraform workspace delete $ALIAS-$REPOSITORY # deletes the desired Terraform workspace in Terraform Cloud