providers contains the domain specific knowledg eneeded to provision
resources (e.g., aws, azure, vmware, etc.)
provisioners allow you to perform DSR after the resource is provisioned
- local-exec runs a command on the local machine
Variables
- Simple variable types: string number bool Example variable definition:
variable "my-var" {
type = string
}
-
Complex variable types: list set map object * tuple
-
Use "${var.WS_ACCESS_KEY} to refer to a variable
Organization
- provider.tf contains provider specific info vars.tf contains the variable defintions terraform.tfvars contains variable assignments
Functions
- Allow you to retrieve and manipulate data Samples: lookup() extracts variable values based on a key
Getting output from a terraform apply
- Output can be used to display variable
output "ip" {
value = "${aws_instance.aws-ec2.public_ip}"
}
Remote state
- Terraform stores its state in the terraform.tfstate file Storing state locally can lead to conflicts The state file can be stored remoetly using a different backed. Back-ends available: Consul S3 w/ dynamodb locking Terraform Enterprise * Steps to configure remote state:
terraform {
backend "consul" {
address = "demo.consul.io"
path = "terraform/hermanwebapp"
}
}
terraform {
backend "s3" {
bucket = "mattys-bucket"
key = "terraform/hemanwebapp"
region = "us-east-1"
}
}
- You cannot use variables in your backend stanzas * S3 and consul backends support locking