Kerim Satirli
(He/Him)
Developer Advocate at HashiCorp
Slide 3
Slide 3 text
@ksatirli
on GitHub and Twitter
Developer Advocate at HashiCorp
Slide 4
Slide 4 text
Agenda Introducing Terraform
basic concepts
Managing Docker with Terraform
provisioning Images, Containers and Networks
Building out
expanding your knowledge
Slide 5
Slide 5 text
Introducing Terraform
Slide 6
Slide 6 text
Terraform 125+
Official Providers
Azure, GCP, Docker, etc.
175+
Community Providers
Auth0, Sentry, Unifi, etc.
Slide 7
Slide 7 text
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
}
Command: terraform init
TERMINAL
> terraform init
Initializing the backend...
Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "docker" (terraform-providers/docker) 2.7.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.
Slide 10
Slide 10 text
Docker Container
CODE EDITOR
resource "docker_image" "minecraft" {
name = "hashicraft/minecraft:v1.12.2"
}
variable "image_tag" {
type = string
description = "Tag of Docker Image to pull"
default = "v1.12.2"
}
Slide 11
Slide 11 text
Docker Container
CODE EDITOR
resource "docker_image" "minecraft" {
name = "hashicraft/minecraft:${var.image_tag}"
}
variable "image_tag" {
type = string
description = "Tag of Docker Image to pull"
default = "v1.12.2"
}
Slide 12
Slide 12 text
Command: terraform plan
TERMINAL
> terraform plan -out="docker.tfplan"
Slide 13
Slide 13 text
Command: terraform plan
TERMINAL
> terraform plan -out="docker.tfplan"
Terraform will perform the following actions:
# docker_image.minecraft will be created
+ resource "docker_image" "minecraft" {
+ id = (known after apply)
+ latest = (known after apply)
+ name = "hashicraft/minecraft:v1.12.2"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Command: terraform apply
TERMINAL
docker_image.minecraft: Creating...
docker_image.minecraft: Still creating...
docker_image.minecraft: Creation complete after 5s
Apply complete!
Resources: 1 added, 0 changed, 0 destroyed.
The state of your infrastructure has been saved to the
path below. This state is required to modify and
destroy your infrastructure, so keep it safe.
State path: terraform.tfstate
Slide 16
Slide 16 text
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
Command: terraform apply
TERMINAL
Apply complete! Resources: 1 added, 0 changed, 0
destroyed.
The state of your infrastructure has been saved to the
path below. This state is required to modify and
destroy your infrastructure, so keep it safe. To
inspect the complete state use the `terraform show`
command.
State path: terraform.tfstate