>_ IzzyLab

Hands-on task

This task is step 1 of the course “Terraform and Ansible”

Terraform without the cloud

medium~10 min

Prove that Terraform is just a state machine and you don't need AWS: in /root/tf write a config with the local provider that creates the file /opt/tf/hello.txt with text containing provisioned by terraform. Run init and apply. There's no internet in the sandbox: only the hashicorp/local provider is available (it sits in a local mirror, terraform init will find it on its own). Write the config in the Editor tab (the /root/tf directory is already created) and run terraform in the terminal.

What you'll practise:
  • terraform
  • iac
  • local provider
  • local_file
  • init/apply

Topic breakdown

Terraform is a state engine: it compares what's described in the config against reality and reconciles them, and a cloud isn't required for that. The local provider works with the local filesystem and supports the local_file resource with filename and content arguments. The working cycle is: initialize the directory, then apply with auto-approve; the result is recorded in terraform.tfstate, and terraform state list shows the list of resources.

What's checked

  1. file /opt/tf/hello.txt created
  2. local_file resource in terraform state
  3. infrastructure matches the config (plan shows no changes)

What it looks like