Course outlines for learning terraform.
expected time | requirements |
---|---|
45 minutes | A computer with Terraform installed, terraform knowledge. |
Goal: Use Templates to customize your usage of Terraform.
Sometimes, you want Terraform to save a file with details from a Terraform run, such as an IP address. Terraform offers many functions one of which is the templatefile function.
These templates can be used in (for example) remote_file or local_file.
Here is an example to store an IP address of hosts managed by Terraform:
inventory.tf
:
resource "local_file" "inventory" {
content = templatefile("templates/inventory.tpl", { ip = data.azurerm_public_ip.ipaddress.ip_address })
filename = "${path.module}/inventory"
}
templates/inventory.tpl
:
${ip}
Have a look here.
You can start using this Terraform configuration. (Remember: az login
, terraform init
)
Host ${ip}
User ${username}
A GCP example to get you started.
local_file
?local_file
be remove when running terraform destroy
?You can use generated content or input variables to create file, both locally and remote.