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.
Slide 16
Slide 16 text
EC2 Instance
CODE EDITOR
variable "ami_id" {
type = string
description = "AMI ID to use"
default = "ami-09d95fab7fff3776c"
}
variable "instance_type" {
type = string
description = "Instance type to use"
default = "t2.micro"
}
Command: terraform plan
TERMINAL
> terraform plan -out="aws.tfplan"
Terraform will perform the following actions:
# aws_instance.hack_the_ne will be created
+ resource "aws_instance" "hack_the_ne"
Plan: 1 to add, 0 to change, 0 to destroy.
This plan was saved to: aws.tfplan
Command: terraform validate
TERMINAL
> terraform fmt
main.tf
> terraform validate
Success! The configuration is valid.
Slide 30
Slide 30 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
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 34
Slide 34 text
Security Groups
CODE EDITOR
service "aws_security_group_rule" "allow_from_self" {
description = "Allow all inbound access from local"
type = "ingress"
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["${chomp(data.http.icanhazip.body)}/32"]
}
Slide 35
Slide 35 text
Review
▪ Infrastructure as Code
▪ Introduction to Terraform
▪ Deployed Resources