Skip to content

Instantly share code, notes, and snippets.

@avcaliani
Last active January 31, 2023 23:30
Show Gist options
  • Save avcaliani/4a68c1fdfe5132288ebea1819bdfa23f to your computer and use it in GitHub Desktop.
Save avcaliani/4a68c1fdfe5132288ebea1819bdfa23f to your computer and use it in GitHub Desktop.
🌳 Terraform 4 Noobs

Terraform

This is a "quick and simple guide" about how to use Terraform in your projects 🤓

First Steps

First, install Terraform following their installation guide.
Then check your installation...

terraform --version

Now, go to the terraform directory.

cd <your_project_directory>/terraform

Finally, initialize your working directory.

terraform init

Well done! Now, let's see what we can do with Terraform

Terraform interactive shell, it looks like a "playground".

terraform console

Terraform workspace, it is a kind of "project" a way that Terraform uses to organize different environments.

terraform workspace list            # List available workspaces
terraform workspace new <NAME>      # Create a brand new workspace
terraform workspace select <NAME>   # Select an existent workspace

Terraform format, this command will format your your Terraform code.

terraform fmt

Terraform validate, this command will check if your stack looks ok.

terraform validate

Terraform plan, this command will show you a stack creation "preview".
This command can anso "output" an execution plan that you can specify at terraform apply, if you want.

terraform plan

Terraform apply, this command will create all resources from your stack.
If you don't specify a plan file Terraform will create a plan in runtime and ask you to proceed.

terraform apply

Terraform destroy, this command will delete all resources created based on your stack.

terraform destroy

That's all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment