Terraform Exploration
Terraform allows you to write infrastructure as code. This is my exploration of terraform. Follow this getting started guide for AWS.
- Follow instructions on Sage jumpcloud to access the
aws cli
. Must set up a profile in~/.aws/credentials
. -
Initialize terraform
terraform init
-
Terraform has an auto formatter that will automatically format the code and you can validate the structure as well.
terraform fmt terraform validate
-
Create instance
cd learn-terraform-aws-instance terrafrom apply
Terraform stores the state either locally or remotely. By default, it is stored locally in a file but the state can actually be stored in terraform cloud or terraform enterprise.
-
Remove instance
terraform destroy
-
Terraform configuration can be split into different files
- main.tf: Houses the resources to spin up
- provider.tf: Determines what provider to use (GCP, AWS…)
- backend.tf: Determines what backend to use (local, remote)
- variable.tf: Resources can take variables
- outputs.tf: Resources can have outputs
Terraform cloud
Followed instructions here to get started.
- When using terraform cloud, you can’t have a local
terraform.tfstate
- Two options to run terraform:
- Change the settings to run the applies locally, to only have workspaces save the state.
- Provide env variables to allow terraform cloud to access AWS account. (Don’t like this)