Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding Infrastructure as Code with Terraform

Understanding Infrastructure as Code with Terraform

Taylor Dolezal

July 20, 2020
Tweet

More Decks by Taylor Dolezal

Other Decks in Technology

Transcript

  1. Agenda Infrastructure as Code what is it? Introduction to Terraform

    putting the pieces together Terraform Lifecycle and State expanding your knowledge
  2. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } }
  3. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } }
  4. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } }
  5. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } }
  6. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } }
  7. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } } variable "port" { }
  8. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } } variable "port" { description = "Port for web_proxy" default = 8080 }
  9. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } } variable "port" { description = "Port for web_proxy" default = 8080 }
  10. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } } variable "port" { description = "Port for web_proxy" default = 8080 }
  11. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } } variable "port" { description = "Port for web_proxy" default = 8080 }
  12. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:8080" process "server" { command = ["proxy-app", "server"] } } variable "port" { description = "Port for web_proxy" default = 8080 }
  13. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:${var.port}" process "server" { command = ["proxy-app", "server"] } } variable "port" { description = "Port for web_proxy" default = 8080 }
  14. HashiCorp Configuration Language CODE EDITOR service "http" "web_proxy" { listen_addr

    = "127.0.0.1:${var.port}" process "server" { command = ["proxy-app", "server"] } } variable "port" { description = "Port for web_proxy" default = 8080 }
  15. Command: terraform init TERMINAL > terraform init Initializing the backend...

    Initializing provider plugins... - Checking for available provider plugins... - Downloading plugin for provider "aws" (terraform-providers/aws) 2.65.0...
  16. Command: terraform init TERMINAL > terraform init Initializing the backend...

    Initializing provider plugins... - Checking for available provider plugins... - Downloading plugin for provider "aws" (terraform-providers/aws) 2.65.0... Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.
  17. Command: terraform plan TERMINAL > terraform plan -out="aws.tfplan" Terraform will

    perform the following actions: # aws_instance.open_nebula will be created + resource "aws_instance" "open_nebula" Plan: 1 to add, 0 to change, 0 to destroy. This plan was saved to: aws.tfplan
  18. Command: terraform plan TERMINAL > terraform plan -out="aws.tfplan" Terraform will

    perform the following actions: # aws_instance.open_nebula will be created + resource "aws_instance" "open_nebula" Plan: 1 to add, 0 to change, 0 to destroy. This plan was saved to: aws.tfplan
  19. Command: terraform apply TERMINAL > terraform apply "aws.tfplan" aws_instance.open_nebula: Creating...

    aws_instance.open_nebula: Still creating... [10s elapsed] aws_instance.open_nebula: Still creating... [20s elapsed] aws_instance.open_nebula: Creation complete after 22s Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
  20. Command: terraform destroy TERMINAL > terraform apply "aws.tfplan" aws_ebs_volume.open_nebula: Destroying...

    aws_instance.open_nebula: Destroying... aws_volume_attachment.open_nebula: Destroying…
  21. Command: terraform destroy TERMINAL > terraform apply "aws.tfplan" aws_ebs_volume.open_nebula: Destroying...

    aws_instance.open_nebula: Destroying... aws_volume_attachment.open_nebula: Destroying… Apply complete! Resources: 0 added, 0 changed, 3 destroyed.
  22. Command: terraform validate TERMINAL > terraform fmt main.tf > terraform

    validate Success! The configuration is valid.
  23. Command: terraform validate TERMINAL > terraform fmt main.tf > terraform

    validate Success! The configuration is valid.
  24. Command: terraform help TERMINAL > terraform help Usage: terraform [-version]

    [-help] <command> [args] The available commands for execution are listed below. The most common, useful commands are shown first, followed by less common or more advanced commands. Common commands: apply Builds or changes infrastructure destroy Destroy Terraform-managed infrastructure fmt Rewrites config files to canonical format output Read an output from a state file
  25. Terraform lifecycle ▪ terraform init ▪ terraform fmt ▪ terraform

    validate ▪ terraform plan -out=“aws.tfplan"
  26. Terraform lifecycle ▪ terraform init ▪ terraform fmt ▪ terraform

    validate ▪ terraform plan -out=“aws.tfplan" ▪ terraform apply "aws.tfplan"
  27. Terraform lifecycle ▪ terraform init ▪ terraform fmt ▪ terraform

    validate ▪ terraform plan -out="aws.tfplan" ▪ terraform apply “aws.tfplan" ▪ terraform plan -destroy
  28. Terraform State ▪ maps real-world resources to your configuration ▪

    keeps track of (resource) metadata ▪ improves performance for large infrastructures
  29. Terraform State ▪ maps real-world resources to your configuration ▪

    keeps track of (resource) metadata ▪ improves performance for large infrastructures ▪ stored locally (by default), can be stored remotely
  30. Terraform State ▪ maps real-world resources to your configuration ▪

    keeps track of (resource) metadata ▪ improves performance for large infrastructures ▪ stored locally (by default), can be stored remotely