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.
Command: terraform validate
TERMINAL
> terraform fmt
main.tf
> terraform validate
Success! The configuration is valid.
Slide 17
Slide 17 text
Command: terraform help
TERMINAL
> terraform help
Usage: terraform [-version] [-help] [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
Slide 18
Slide 18 text
Command: terraform plan
TERMINAL
> terraform plan -out="docker.tfplan"
Terraform will perform the following actions:
# docker_image.hello_world will be created
+ resource "docker_image" "hello_world" {
+ id = (known after apply)
+ latest = (known after apply)
+ name = "hello-world:latest"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Command: terraform apply
TERMINAL
docker_image.hello_world: Creating...
docker_image.hello_world: Still creating...
docker_image.hello_world: 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 21
Slide 21 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
Slide 22
Slide 22 text
Docker Container
CODE EDITOR
resource "docker_image" "hello_world" {
name = "hello-world:${var.image_version}"
}
variable "image_version" {
type = string
description = "version of Docker Image to pull"
default = "latest"
}
Slide 23
Slide 23 text
Command: terraform plan
TERMINAL
> terraform plan -out="docker.tfplan"
var.image_version
version of Docker Image to pull
Enter a value: latest
Slide 24
Slide 24 text
Command: terraform plan
TERMINAL
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this
plan, but will not be persisted to local or remote
state storage.
No changes. Infrastructure is up-to-date.
This means that Terraform did not detect any
differences between your configuration and real
physical resources that exist. As a result, no
actions need to be performed.
Command: terraform apply
TERMINAL
docker_container.hello_world: Creating...
docker_container.hello_world: Creation complete after
0s [id=3d5...966]
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.
Slide 29
Slide 29 text
Managing AWS with Terraform
Slide 30
Slide 30 text
AWS Provider for Terraform
hashi.co/tf-aws-provider-changelog
EC2 Instance
TERMINAL
> terraform plan -out="aws.tfplan"
Terraform will perform the following actions:
# aws_instance.hug_demo will be created
+ resource "aws_instance" "hug_demo"
Plan: 1 to add, 0 to change, 0 to destroy.
This plan was saved to: aws.tfplan