Terraform 7 of 10: Terraform Core Workflow and Subcommands using AWS Cloud9


This tutorial deals with Terraform Core Workflow and Subcommands. AWS Cloud9 is the environment.

1 of 18. Open documentation for "Terraform Core Workflow" aand "Debugging Terraform"

The Core Terraform Workflow

Debugging Terraform

2 of 18. Open your AWS Cloud9 environment

Creating An Integrated Developer Environment (IDE) in the Cloud in Two Minutes!: AWS Cloud9(Step-by-Step)

3 of 18. "terraform -h"

Check terraform help. It leads with the "Main commands", but then shows "All other commands"

terraform -h | -help

4 of 18. "terraform init"

Initialize the directories and backend

terraform init

5 of 18. Enable tracing for troubleshooting

Enabling tracing for troubleshooting: export TF_LOG=TRACE terraform init

6 of 18. Set tracing to go to a log file.

Open the file to view the trace ouput.

export TF_LOG_PATH=terraform.log terraform init

7 of 18. Clear trace variables

echo $TF_LOG echo $TF_LOG_PATH unset TF_LOG unset TF_LOG_PATH echo $TF_LOG echo $TF_LOG_PATH

8 of 18. "terraform providers"

Self explanatory output

terraform providers

9 of 18. "terraform fmt"

This fixes the format of terraform files. There will be no output if all files are properly formatted.

terraform fmt terraform fmt

10 of 18. "terraform validate"

Checks that the configuration is valid. To test this, intentionally put an error in your resources.tf, such as missing an "=" sign, then run the validate.

terraform validate

11 of 18. "terraform plan"

This creates an execution plan, of what would happen, if applied.

terraform plan

12 of 18. "terraform apply"

This will execute the actions of a plan. By default, this command requires an approval action to proceed. You can override this behavior, with the "auto-approve" switch.

terraform apply terraform apply -auto-approve

13 of 18. "terraform output"

Use this to query output.

terraform output

14 of 18. "terraform show"

Provides human readable output from a state file or plan. If a file is not specified, it defaults to the state file.

terraform show

15 of 18. Update "variables.tf" and "resources.tf"

Update the "variables.tf" to include a "special" variable. Update the "resources.tf" to include the "override_special" that refers to the "special" variable. "override_special" will let you choose which characters are "special".

variable "special" { default = "#" } resource "random_password" "password" { length = 8 special = true override_special = var.special }

16 of 18. "terraform console"

The "terraform console" can be used to interact with variables.

terraform console var.special

17 of 18. Try other interactive examples from within the terraform console

Note that in this case, the request was for a variable that did not exist. "Max" finds the largest value. "cidrnetmask" displays a subnet mask. "timestamp()" gives a Date and time stamp. "join" can concatente, with a specified joining character.

var.random_separator max(875,458,212) cidrnetmask("") timestamp() join("-",["TCB","DevOps"]) join("-",["TCB","Devops","Bootcamp"])
​ ​

18 of 18. Cleanup

Exit the console, then destroy the resources.

exit terraform destroy


Creating An Integrated Developer Environment (IDE) in the Cloud in Two Minutes!: AWS Cloud9(Step-by-Step)

The Core Terraform Workflow

Debugging Terraform

Basic CLI Features

Command: fmt

Command: validate

Command: plan

Command: apply

Command: show

Command: output

Query outputs

random_password (Resource)

Command: console


Command: destroy


Popular posts from this blog

Orphaned No More: Adopting AWS Lambda

Containing the Chaos! | A Three-Part Series Demonstrating the Usefulness of Containerization to HumanGov