Guest User

Untitled

a guest
Oct 17th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. ### Command Line Interface
  2. ```
  3. terraform init
  4. terraform plan
  5. terraform plan -destroy
  6. terraform plan -var 'access_key=foo' -var 'secret_key=bar'
  7. terraform plan -var-file="secret.tfvars" -var-file="production.tfvars"
  8. terraform plan -var 'amis={ us-east-1 = "foo", us-west-2 = "bar" }'
  9. terraform apply
  10. terraform output <output-variable-named>
  11. terraform show
  12. terraform get
  13. terraform destroy
  14. ```
  15.  
  16. ### Provider eg. digitalocean, aws (write on <filename>.tf file eg. main.tf)
  17. ```
  18. provider "digitalocean" {
  19. token = "${var.token}"
  20. }
  21. provider "aws" {
  22. access_key = "${var.access_key}"
  23. secret_key = "${var.secret_key}"
  24. region = "${var.region}"
  25. }
  26. ```
  27.  
  28. ### Variable Defined (write on <filename>.tf file eg. variables.tf)
  29. ```
  30. variable "token" {}
  31.  
  32. # implicitly by using brackets [...]
  33. variable "cidrs" { default = [] }
  34.  
  35. # explicitly
  36. variable "cidrs" { type = "list" }
  37. ```
  38.  
  39. ### Maps
  40. ```
  41. # Maps are a way to create variables that are lookup tables.
  42. variable "amis" {
  43. type = "map"
  44. default = {
  45. "us-east-1" = "ami-b374d5a5"
  46. "us-west-2" = "ami-4b32be2b"
  47. }
  48. }
  49.  
  50. # Using Maps Lookup
  51. ami = "${lookup(var.amis, var.region)}"
  52. ```
  53.  
  54. ### terraform.tfvars
  55. ```
  56. token = ""
  57. cidrs = ["10.0.0.0/16", "10.1.0.0/16"]
  58. amis = {
  59. "us-east-1" = "ami-abc123"
  60. "us-west-2" = "ami-def456"
  61. }
  62. ```
  63.  
  64. ### Output Variables (write on .tf file eg. output.tf)
  65. ```
  66. output "ip" {
  67. value = "${aws_eip.ip.public_ip}"
  68. }
  69. output "consul_address" {
  70. value = "${module.consul.server_address}"
  71. }
  72. ```
  73.  
  74. ### Provisioner
  75. ```
  76. provisioner "local-exec" {
  77. command = "echo ${aws_instance.web.ipv4_address} > ip_address.txt"
  78. }
  79. provisioner "remote-exec" {
  80. scripts = [
  81. "${path.module}/../shared/scripts/install.sh",
  82. ]
  83. }
  84. ```
Add Comment
Please, Sign In to add comment