Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Command Line Interface
- ```
- terraform init
- terraform plan
- terraform plan -destroy
- terraform plan -var 'access_key=foo' -var 'secret_key=bar'
- terraform plan -var-file="secret.tfvars" -var-file="production.tfvars"
- terraform plan -var 'amis={ us-east-1 = "foo", us-west-2 = "bar" }'
- terraform apply
- terraform output <output-variable-named>
- terraform show
- terraform get
- terraform destroy
- ```
- ### Provider eg. digitalocean, aws (write on <filename>.tf file eg. main.tf)
- ```
- provider "digitalocean" {
- token = "${var.token}"
- }
- provider "aws" {
- access_key = "${var.access_key}"
- secret_key = "${var.secret_key}"
- region = "${var.region}"
- }
- ```
- ### Variable Defined (write on <filename>.tf file eg. variables.tf)
- ```
- variable "token" {}
- # implicitly by using brackets [...]
- variable "cidrs" { default = [] }
- # explicitly
- variable "cidrs" { type = "list" }
- ```
- ### Maps
- ```
- # Maps are a way to create variables that are lookup tables.
- variable "amis" {
- type = "map"
- default = {
- "us-east-1" = "ami-b374d5a5"
- "us-west-2" = "ami-4b32be2b"
- }
- }
- # Using Maps Lookup
- ami = "${lookup(var.amis, var.region)}"
- ```
- ### terraform.tfvars
- ```
- token = ""
- cidrs = ["10.0.0.0/16", "10.1.0.0/16"]
- amis = {
- "us-east-1" = "ami-abc123"
- "us-west-2" = "ami-def456"
- }
- ```
- ### Output Variables (write on .tf file eg. output.tf)
- ```
- output "ip" {
- value = "${aws_eip.ip.public_ip}"
- }
- output "consul_address" {
- value = "${module.consul.server_address}"
- }
- ```
- ### Provisioner
- ```
- provisioner "local-exec" {
- command = "echo ${aws_instance.web.ipv4_address} > ip_address.txt"
- }
- provisioner "remote-exec" {
- scripts = [
- "${path.module}/../shared/scripts/install.sh",
- ]
- }
- ```
Add Comment
Please, Sign In to add comment