terraform intro

To build something in Terraform, you need to create modules, which are folders with a set of configuration files that can gather information and execute the action you need to complete. Terraform files always end in the file extension .tf. Start with one main.tf file, such as:

Ssa$ ~/terraform_doc$ touch main.tf


You also need to know some basic Terraform commands and requirements before you can start making anything within the cluster:

  • terraform init: Initializes a Terraform working directory
    – It must be within the same directory as the 
    .tf files or nothing will happen.
  • terraform validate: Confirms the Terraform file's syntax is correct
    – Always run this to confirm the code is built correctly and will not have errors.
  • terraform plan: Generates and shows what will change when you run terraform apply
    – Run this before apply to confirm the results are as you intend.
  • terraform apply: Builds or changes infrastructure
    – It will show the execution plan and requires a yes or no to execute unless you use the 
    --auto-approve flag, which will make it execute automatically.
  • Terraform refresh: Updates the local state file against real resources
    – This ensures Terraform has an accurate view of what is in the current environment.
  • terraform destroy: Deletes and removes Terraform-managed infrastructure
    – This will permanently remove anything created and stored in the state file from the cluster.

For the configuration in this example, everything controlled by Terraform is held in a local state file. According to Terraform's docs:

Comments

Popular Posts